From 6ae76509bb3a633e06bb000251db4c34dfcafd04 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Thu, 2 Nov 2017 15:01:56 +0800 Subject: [PATCH] improved timeline load more --- .../activities/AbsActivitiesFragment.kt | 42 ++++++++++++------- .../InteractionsActivitiesFragment.kt | 4 ++ .../fragment/timeline/AbsTimelineFragment.kt | 18 ++++---- .../fragment/timeline/HomeTimelineFragment.kt | 1 + 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/activities/AbsActivitiesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/activities/AbsActivitiesFragment.kt index 73f4e850e..c7390cd56 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/activities/AbsActivitiesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/activities/AbsActivitiesFragment.kt @@ -57,6 +57,7 @@ import org.mariotaku.twidere.constant.newDocumentApiKey import org.mariotaku.twidere.constant.readFromBottomKey import org.mariotaku.twidere.data.CursorObjectLivePagedListProvider import org.mariotaku.twidere.data.CursorObjectLivePagedListProvider.CursorObjectProcessor +import org.mariotaku.twidere.data.ExtendedPagedListProvider import org.mariotaku.twidere.extension.model.activityStatus import org.mariotaku.twidere.extension.model.getAccountType import org.mariotaku.twidere.extension.queryOne @@ -109,8 +110,11 @@ abstract class AbsActivitiesFragment : AbsContentRecyclerViewFragment?> - private set + protected var activities: LiveData?>? = null + private set(value) { + field?.removeObservers(this) + field = value + } protected val accountKeys: Array get() = Utils.getAccountKeys(context, arguments) ?: if (isStandalone) { @@ -121,16 +125,18 @@ abstract class AbsActivitiesFragment : AbsContentRecyclerViewFragment - private fun createLiveData(): LiveData?> { - return if (isStandalone) onCreateStandaloneLiveData() else onCreateDatabaseLiveData() + private fun setupLiveData() { + activities = if (isStandalone) onCreateStandaloneLiveData() else onCreateDatabaseLiveData() + activities?.observe(this, Observer { onDataLoaded(it) }) } private fun onCreateStandaloneLiveData(): LiveData?> { @@ -368,6 +377,7 @@ abstract class AbsActivitiesFragment : AbsContentRecyclerViewFragment - ld.observe(this, Observer { onDataLoaded(it) }) - } + statuses = if (isStandalone) onCreateStandaloneLiveData() else onCreateDatabaseLiveData() + statuses?.observe(this, Observer { onDataLoaded(it) }) } private fun onCreateStandaloneLiveData(): LiveData?> { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/timeline/HomeTimelineFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/timeline/HomeTimelineFragment.kt index 377a5fef8..68b2ef099 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/timeline/HomeTimelineFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/timeline/HomeTimelineFragment.kt @@ -36,6 +36,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Statuses import java.util.* class HomeTimelineFragment : AbsTimelineFragment() { + override val filterScope: Int = FilterScope.HOME override val contentUri: Uri = Statuses.HomeTimeline.CONTENT_URI