Add "n new posts" snackbar

filtering
Floens 10 years ago
parent 17e747b2fc
commit 17705278ab
  1. 20
      Clover/app/src/main/java/org/floens/chan/core/presenter/ThreadPresenter.java
  2. 28
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java
  3. 18
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java
  4. 8
      Clover/app/src/main/res/values/strings.xml

@ -81,6 +81,7 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
private String searchQuery;
private PostFilter.Order order = PostFilter.Order.BUMP;
private boolean historyAdded = false;
private int notificationPostCount = -1;
public ThreadPresenter(ThreadPresenterCallback threadPresenterCallback) {
this.threadPresenterCallback = threadPresenterCallback;
@ -115,6 +116,7 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
chanLoader = null;
loadable = null;
historyAdded = false;
notificationPostCount = -1;
threadPresenterCallback.showLoading();
}
@ -216,6 +218,20 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
}
}
if (loadable.isThreadMode()) {
int postsSize = result.posts.size();
if (notificationPostCount < 0) {
notificationPostCount = postsSize;
} else {
if (postsSize > notificationPostCount) {
int more = postsSize - notificationPostCount;
notificationPostCount = postsSize;
threadPresenterCallback.showNewPostsNotification(true, more);
}
}
}
chanLoader.setAutoLoadMore(isWatching());
showPosts();
@ -251,6 +267,8 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
pin.onBottomPostViewed();
watchManager.updatePin(pin);
}
threadPresenterCallback.showNewPostsNotification(false, -1);
}
public void scrollTo(int position, boolean smooth) {
@ -626,5 +644,7 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
void hideDeleting(String message);
void hideThread(Post post);
void showNewPostsNotification(boolean show, int more);
}
}

@ -46,6 +46,7 @@ import com.android.volley.VolleyError;
import org.floens.chan.Chan;
import org.floens.chan.R;
import org.floens.chan.controller.Controller;
import org.floens.chan.core.database.DatabaseManager;
import org.floens.chan.core.model.ChanThread;
import org.floens.chan.core.model.Loadable;
import org.floens.chan.core.model.Post;
@ -54,7 +55,6 @@ import org.floens.chan.core.model.PostLinkable;
import org.floens.chan.core.model.ThreadHide;
import org.floens.chan.core.presenter.ThreadPresenter;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.core.database.DatabaseManager;
import org.floens.chan.ui.adapter.PostFilter;
import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.helper.PostPopupHelper;
@ -97,6 +97,7 @@ public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.T
private ProgressDialog deletingDialog;
private boolean refreshedFromSwipe;
private boolean showingReplyButton = false;
private Snackbar newPostsNotification;
public ThreadLayout(Context context) {
super(context);
@ -379,6 +380,30 @@ public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.T
fixSnackbarText(getContext(), snackbar);
}
@Override
public void showNewPostsNotification(boolean show, int more) {
if (show) {
if (!threadListLayout.scrolledToBottom()) {
String text = getContext().getString(R.string.thread_new_posts,
more, getContext().getResources().getQuantityString(R.plurals.posts, more, more));
newPostsNotification = Snackbar.make(this, text, Snackbar.LENGTH_LONG);
newPostsNotification.setAction(R.string.thread_new_posts_goto, new OnClickListener() {
@Override
public void onClick(View v) {
presenter.scrollTo(-1, false);
}
}).show();
fixSnackbarText(getContext(), newPostsNotification);
}
} else {
if (newPostsNotification != null) {
newPostsNotification.dismiss();
newPostsNotification = null;
}
}
}
public ThumbnailView getThumbnail(PostImage postImage) {
if (postPopupHelper.isOpen()) {
return postPopupHelper.getThumbnail(postImage);
@ -414,6 +439,7 @@ public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.T
postPopupHelper.popAll();
showSearch(false);
showReplyButton(false);
newPostsNotification = null;
break;
}
}

@ -248,7 +248,7 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL
if (query != null) {
int size = postAdapter.getDisplaySize();
searchStatus.setText(getContext().getString(R.string.search_results,
getContext().getResources().getQuantityString(R.plurals.posts, size, size), query));
size, getContext().getResources().getQuantityString(R.plurals.posts, size, size), query));
}
}
@ -274,6 +274,22 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL
return true;
}
public boolean scrolledToBottom() {
switch (postViewMode) {
case LIST:
if (((LinearLayoutManager) layoutManager).findLastVisibleItemPosition() == postAdapter.getItemCount() - 1) {
return true;
}
break;
case CARD:
if (((GridLayoutManager) layoutManager).findLastVisibleItemPosition() == postAdapter.getItemCount() - 1) {
return true;
}
break;
}
return false;
}
public void cleanup() {
/*if (ChanBuild.DEVELOPER_MODE) {
Pin pin = ChanApplication.getWatchManager().findPinByLoadable(showingThread.loadable);

@ -33,8 +33,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</plurals>
<plurals name="posts">
<item quantity="one">%d post</item>
<item quantity="other">%d posts</item>
<item quantity="one">post</item>
<item quantity="other">posts</item>
</plurals>
<plurals name="reply">
@ -71,7 +71,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="order_oldest">Oldest</string>
<string name="search_hint">Search</string>
<string name="search_results">Found %1$s for "%2$s"</string>
<string name="search_results">Found %1$d %2$s for "%3$s"</string>
<string name="search_empty">Search subjects, comments, names and filenames</string>
<string name="open_link_confirmation">Open link?</string>
@ -103,6 +103,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="thread_load_failed_retry">Retry</string>
<string name="thread_archived">Archived</string>
<string name="thread_closed">Closed</string>
<string name="thread_new_posts">%1$d new %2$s</string>
<string name="thread_new_posts_goto">View</string>
<string name="board_edit">Board editor</string>
<string name="board_edit_header">Add, remove and reorder your boards here.\nThe topmost board will be loaded automatically.</string>

Loading…
Cancel
Save