From 6e718d6765405012134d74ca3f3fc8edfd4d2486 Mon Sep 17 00:00:00 2001 From: Grishka Date: Wed, 18 Jan 2023 20:29:49 +0300 Subject: [PATCH] Save last seen home timeline post via markers API --- mastodon/build.gradle | 2 +- .../fragments/HomeTimelineFragment.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 1f27990b7..b25d6fb87 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -9,7 +9,7 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 33 - versionCode 46 + versionCode 47 versionName "1.1.5" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" resConfigs "ar-rSA", "be-rBY", "bn-rBD", "bs-rBA", "ca-rES", "cs-rCZ", "de-rDE", "el-rGR", "es-rES", "eu-rES", "fi-rFI", "fil-rPH", "fr-rFR", "ga-rIE", "gd-rGB", "gl-rES", "hi-rIN", "hr-rHR", "hu-rHU", "hy-rAM", "in-rID", "is-rIS", "it-rIT", "iw-rIL", "ja-rJP", "kab", "ko-rKR", "nl-rNL", "oc-rFR", "pl-rPL", "pt-rBR", "pt-rPT", "ro-rRO", "ru-rRU", "si-rLK", "sl-rSI", "sv-rSE", "th-rTH", "tr-rTR", "uk-rUA", "vi-rVN", "zh-rCN", "zh-rTW" diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index b7895ba87..6571307a6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -25,6 +25,7 @@ import com.squareup.otto.Subscribe; import org.joinmastodon.android.E; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.markers.SaveMarkers; import org.joinmastodon.android.api.requests.timelines.GetHomeTimeline; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.SelfUpdateStateChangedEvent; @@ -61,6 +62,7 @@ public class HomeTimelineFragment extends StatusListFragment{ private AnimatorSet currentNewPostsAnim; private String maxID; + private String lastSavedMarkerID; public HomeTimelineFragment(){ setListLayoutId(R.layout.recycler_fragment_with_fab); @@ -142,6 +144,29 @@ public class HomeTimelineFragment extends StatusListFragment{ } } + @Override + protected void onHidden(){ + super.onHidden(); + if(!data.isEmpty()){ + String topPostID=displayItems.get(list.getChildAdapterPosition(list.getChildAt(0))-getMainAdapterOffset()).parentID; + if(!topPostID.equals(lastSavedMarkerID)){ + lastSavedMarkerID=topPostID; + new SaveMarkers(topPostID, null) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(SaveMarkers.Response result){ + } + + @Override + public void onError(ErrorResponse error){ + lastSavedMarkerID=null; + } + }) + .exec(accountID); + } + } + } + public void onStatusCreated(StatusCreatedEvent ev){ prependItems(Collections.singletonList(ev.status), true); }