2017-01-20 09:09:10 +01:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This file is a part of Tusky.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 02:12:31 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-20 09:09:10 +01:00
|
|
|
|
2017-05-15 12:07:01 +02:00
|
|
|
package com.keylesspalace.tusky.view;
|
2017-01-03 00:30:27 +01:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import androidx.annotation.NonNull;
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2017-01-03 00:30:27 +01:00
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
public abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListener {
|
2017-02-22 20:13:51 +01:00
|
|
|
private static final int VISIBLE_THRESHOLD = 15;
|
|
|
|
private int previousTotalItemCount;
|
2017-01-03 00:30:27 +01:00
|
|
|
private LinearLayoutManager layoutManager;
|
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
public EndlessOnScrollListener(LinearLayoutManager layoutManager) {
|
2017-01-03 00:30:27 +01:00
|
|
|
this.layoutManager = layoutManager;
|
2017-02-22 20:13:51 +01:00
|
|
|
previousTotalItemCount = 0;
|
2017-01-03 00:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
public void onScrolled(@NonNull RecyclerView view, int dx, int dy) {
|
2017-01-03 00:30:27 +01:00
|
|
|
int totalItemCount = layoutManager.getItemCount();
|
|
|
|
int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
|
|
|
|
if (totalItemCount < previousTotalItemCount) {
|
|
|
|
previousTotalItemCount = totalItemCount;
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2017-01-03 00:30:27 +01:00
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
if (totalItemCount != previousTotalItemCount) {
|
2017-01-03 00:30:27 +01:00
|
|
|
previousTotalItemCount = totalItemCount;
|
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
|
|
|
|
if (lastVisibleItemPosition + VISIBLE_THRESHOLD > totalItemCount) {
|
|
|
|
onLoadMore(totalItemCount, view);
|
2017-01-03 00:30:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
public void reset() {
|
2017-01-03 00:30:27 +01:00
|
|
|
previousTotalItemCount = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
public abstract void onLoadMore(int totalItemsCount, RecyclerView view);
|
2017-01-03 00:30:27 +01:00
|
|
|
}
|