mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-05-11 23:40:12 -05:00
comments: add scrolling
This commit is contained in:
@@ -160,13 +160,8 @@ public class MessagesListAdapter<MESSAGE extends IMessage>
|
||||
Wrapper<MESSAGE> element = new Wrapper<>(message);
|
||||
items.add(0, element);
|
||||
notifyItemRangeInserted(0, isNewMessageToday ? 2 : 1);
|
||||
//if (layoutManager != null && scroll) {
|
||||
// layoutManager.scrollToPosition(0);
|
||||
//}
|
||||
|
||||
if (layoutManager != null) {
|
||||
// TODO: Remember position when user performs manual scrolling
|
||||
layoutManager.scrollToPosition(scroll ? 0 : items.size() - 1);
|
||||
if (layoutManager != null && scroll) {
|
||||
layoutManager.scrollToPosition(0);
|
||||
}
|
||||
|
||||
trimEnd();
|
||||
@@ -364,6 +359,12 @@ public class MessagesListAdapter<MESSAGE extends IMessage>
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToTop() {
|
||||
if (layoutManager != null && !items.isEmpty()) {
|
||||
layoutManager.scrollToPosition(items.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToBottom() {
|
||||
if (layoutManager != null) {
|
||||
layoutManager.scrollToPosition(0);
|
||||
|
||||
+11
-5
@@ -60,8 +60,17 @@ public class CommentsManager extends PlayerEventListenerHelper implements Metada
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupEnd(CommentGroup commentGroup) {
|
||||
public void onLoadMore(String nextCommentsKey) {
|
||||
disposeActions();
|
||||
|
||||
mCommentsAction = mCommentsService.getCommentsObserve(nextCommentsKey)
|
||||
.subscribe(
|
||||
this::addCommentGroup,
|
||||
error -> {
|
||||
Log.e(TAG, error.getMessage());
|
||||
error.printStackTrace();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,9 +112,6 @@ public class CommentsManager extends PlayerEventListenerHelper implements Metada
|
||||
}
|
||||
|
||||
private void disposeActions() {
|
||||
if (RxUtils.isAnyActionRunning(mCommentsAction)) {
|
||||
RxUtils.disposeActions(mCommentsAction);
|
||||
getController().setChatReceiver(null);
|
||||
}
|
||||
RxUtils.disposeActions(mCommentsAction);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ public interface CommentsReceiver {
|
||||
}
|
||||
void addCommentGroup(CommentGroup commentGroup);
|
||||
void setCallback(Callback callback);
|
||||
void onGroupEnd(CommentGroup commentGroup);
|
||||
void onLoadMore(String nextCommentsKey);
|
||||
void onCommentClicked(CommentItem commentItem);
|
||||
}
|
||||
|
||||
+6
@@ -23,6 +23,7 @@ public class CommentsPreferenceDialogFragment extends LeanbackPreferenceDialogFr
|
||||
private boolean mIsTransparent;
|
||||
private CommentsReceiver mCommentsReceiver;
|
||||
private CharSequence mDialogTitle;
|
||||
private String mNextCommentsKey;
|
||||
|
||||
public static CommentsPreferenceDialogFragment newInstance(CommentsReceiver commentsReceiver, String key) {
|
||||
final Bundle args = new Bundle(1);
|
||||
@@ -65,6 +66,7 @@ public class CommentsPreferenceDialogFragment extends LeanbackPreferenceDialogFr
|
||||
.apply(ViewUtil.glideOptions())
|
||||
.circleCrop() // resize image
|
||||
.into(imageView));
|
||||
adapter.setLoadMoreListener((page, totalItemsCount) -> mCommentsReceiver.onLoadMore(mNextCommentsKey));
|
||||
messagesList.setAdapter(adapter);
|
||||
|
||||
if (mCommentsReceiver != null) {
|
||||
@@ -72,6 +74,10 @@ public class CommentsPreferenceDialogFragment extends LeanbackPreferenceDialogFr
|
||||
for (CommentItem commentItem : commentGroup.getComments()) {
|
||||
adapter.addToStart(ChatItemMessage.from(commentItem), false);
|
||||
}
|
||||
if (mNextCommentsKey == null) {
|
||||
adapter.scrollToTop();
|
||||
}
|
||||
mNextCommentsKey = commentGroup.getNextCommentsKey();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user