1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-28 17:31:33 +01:00

improved mark as read

This commit is contained in:
Mariotaku Lee 2015-05-05 01:36:46 +08:00
parent d88e4902c3
commit 50a106474c

View File

@ -78,7 +78,8 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
@Override @Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) { public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (newState == RecyclerView.SCROLL_STATE_IDLE) {
saveReadPosition(); final LinearLayoutManager layoutManager = getLayoutManager();
saveReadPosition(layoutManager.findFirstVisibleItemPosition());
} }
} }
}; };
@ -344,7 +345,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
public final boolean scrollToStart() { public final boolean scrollToStart() {
final boolean result = super.scrollToStart(); final boolean result = super.scrollToStart();
if (result) { if (result) {
saveReadPosition(); saveReadPosition(0);
} }
return result; return result;
} }
@ -393,11 +394,9 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
protected abstract void onLoadingFinished(); protected abstract void onLoadingFinished();
protected void saveReadPosition() { protected void saveReadPosition(int position) {
final String readPositionTag = getReadPositionTagWithAccounts(); final String readPositionTag = getReadPositionTagWithAccounts();
if (readPositionTag == null) return; if (readPositionTag == null) return;
final LinearLayoutManager layoutManager = getLayoutManager();
final int position = layoutManager.findFirstVisibleItemPosition();
if (position == RecyclerView.NO_POSITION) return; if (position == RecyclerView.NO_POSITION) return;
final AbsStatusesAdapter<Data> adapter = getAdapter(); final AbsStatusesAdapter<Data> adapter = getAdapter();
final ParcelableStatus status = adapter.getStatus(position); final ParcelableStatus status = adapter.getStatus(position);