From 387b31193f9b3c9b0d2c851789b1b4603fa43cd4 Mon Sep 17 00:00:00 2001 From: sk Date: Thu, 19 Oct 2023 21:42:17 +0200 Subject: [PATCH 01/19] hopefully unfuck removing statuses and reblogs --- .../android/fragments/StatusListFragment.java | 96 ++++++++++++------- .../joinmastodon/android/model/Status.java | 4 + .../ui/displayitems/StatusDisplayItem.java | 2 +- .../android/ui/utils/UiUtils.java | 3 - 4 files changed, 65 insertions(+), 40 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java index 8e0e2cc5e1..2175c9abed 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java @@ -9,6 +9,7 @@ import org.joinmastodon.android.E; import org.joinmastodon.android.GlobalUserPreferences; +import org.joinmastodon.android.api.CacheController; import org.joinmastodon.android.api.session.AccountLocalPreferences; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.EmojiReactionsUpdatedEvent; @@ -31,6 +32,10 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.function.BiPredicate; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -176,56 +181,71 @@ protected void onRemoveAccountPostsEvent(RemoveAccountPostsEvent ev){ } } - private void iterateRemoveStatus(List l, String id){ - Iterator it=l.iterator(); - while(it.hasNext()){ - if(it.next().getContentStatus().id.equals(id)){ - it.remove(); - } - } - } - - private void removeStatusDisplayItems(Status status, int index, int ancestorFirstIndex, int ancestorLastIndex, boolean deleteContent){ + private boolean removeStatusDisplayItems(String parentID, int firstIndex, int ancestorFirstIndex, int ancestorLastIndex){ // did we find an ancestor that is also the status' neighbor? - if(ancestorFirstIndex>=0 && ancestorLastIndex==index-1){ - for(int i=ancestorFirstIndex; i<=ancestorLastIndex; i++){ - StatusDisplayItem item=displayItems.get(i); - String id=deleteContent ? item.getContentID() : item.parentID; - // update ancestor to have no descendant anymore - if(id.equals(status.inReplyToId)) item.hasDescendantNeighbor=false; - } + if(ancestorFirstIndex>=0 && ancestorLastIndex==firstIndex-1){ + // update ancestor to have no descendant anymore + displayItems.subList(ancestorFirstIndex, ancestorLastIndex+1).forEach(i->i.hasDescendantNeighbor=false); adapter.notifyItemRangeChanged(ancestorFirstIndex, ancestorLastIndex-ancestorFirstIndex+1); } - if(index==-1) return; - int lastIndex; - for(lastIndex=index;lastIndex isToBeRemovedReblog=item->item!=null && item.reblog!=null + && item.reblog.id.equals(status.reblog.id) + && asm.isSelf(accountID, item.account); + final BiPredicate> isToBeRemovedContent=(parentId, contentIdSupplier)-> + parentId.equals(status.id) || contentIdSupplier.get().equals(status.id); + int ancestorFirstIndex=-1, ancestorLastIndex=-1; for(int i=0;i> removeStatusFromData=(list)->{ + Iterator it=list.iterator(); + while(it.hasNext()){ + Status s=it.next(); + if(unReblogging + ? isToBeRemovedReblog.test(s) + : isToBeRemovedContent.test(s.id, s::getContentStatusID)){ + it.remove(); + cache.deleteStatus(s.id); + } + } + }; + removeStatusFromData.accept(data); + removeStatusFromData.accept(preloadedData); } @Override @@ -296,10 +316,14 @@ public void onStatusDeleted(StatusDeletedEvent ev){ @Subscribe public void onReblogDeleted(ReblogDeletedEvent ev){ + AccountSessionManager asm=AccountSessionManager.getInstance(); if(!ev.accountID.equals(accountID)) return; for(Status item : data){ - if(item.getContentStatus().id.equals(ev.statusID) && item.reblog!=null){ + boolean itemIsOwnReblog=item.reblog!=null + && item.getContentStatusID().equals(ev.statusID) + && asm.isSelf(accountID, item.account); + if(itemIsOwnReblog){ removeStatus(item); break; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Status.java b/mastodon/src/main/java/org/joinmastodon/android/model/Status.java index 1a67ad6597..eb13a43fcd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Status.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Status.java @@ -195,6 +195,10 @@ public Status getContentStatus(){ return reblog!=null ? reblog : this; } + public String getContentStatusID(){ + return getContentStatus().id; + } + public String getStrippedText(){ if(strippedText==null) strippedText=HtmlParser.strip(content); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 31f3b84258..71bfdf54f8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -89,7 +89,7 @@ public StatusDisplayItem(String parentID, BaseStatusListFragment parentFragme } @NonNull - public String getContentID(){ + public String getContentStatusID(){ if(parentFragment instanceof StatusListFragment slf){ Status s=slf.getContentStatusByID(parentID); return s!=null ? s.id : parentID; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index 29210f2f37..325618145c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -638,11 +638,8 @@ public static void confirmDeletePost(Activity activity, String accountID, Status @Override public void onSuccess(Status result) { resultCallback.accept(result); - CacheController cache=AccountSessionManager.get(accountID).getCacheController(); - cache.deleteStatus(s.id); E.post(new StatusDeletedEvent(s.id, accountID)); if(status!=s){ - cache.deleteStatus(status.id); E.post(new StatusDeletedEvent(status.id, accountID)); } } From ef0fbb26a4709e51b0a7f6ca8da6a7b7d6a67ef5 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 20 Oct 2023 10:33:45 +0200 Subject: [PATCH 02/19] don't return before refreshDone --- .../joinmastodon/android/fragments/HomeTimelineFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8cc030c07e..8c00be2284 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -136,6 +136,7 @@ private void loadNewPosts(){ public void onSuccess(List result){ currentRequest=null; dataLoading=false; + refreshDone(); if(result.isEmpty() || getActivity()==null) return; Status last=result.get(result.size()-1); @@ -157,7 +158,6 @@ public void onSuccess(List result){ prependItems(toAdd, true); if(parent != null && GlobalUserPreferences.showNewPostsButton) parent.showNewPostsButton(); } - refreshDone(); } @Override From 59026286a129355550a4cf9dc50368db7d31047f Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 20 Oct 2023 10:46:56 +0200 Subject: [PATCH 03/19] don't cache as many posts --- .../main/java/org/joinmastodon/android/api/CacheController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java b/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java index 832fdcb402..12725fe0c7 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java @@ -121,7 +121,7 @@ public void putHomeTimeline(List posts, boolean clear){ db.insertWithOnConflict("home_timeline", null, values, SQLiteDatabase.CONFLICT_REPLACE); } if(!clear) - db.delete("home_timeline", "`id` NOT IN (SELECT `id` FROM `home_timeline` ORDER BY `time` DESC LIMIT ?)", new String[]{"1000"}); + db.delete("home_timeline", "`id` NOT IN (SELECT `id` FROM `home_timeline` ORDER BY `time` DESC LIMIT ?)", new String[]{"100"}); }); } From b5eae13a16c20da4fd3aeb2fca5a1a3822aec809 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 20 Oct 2023 11:43:15 +0200 Subject: [PATCH 04/19] introduce separate tonal selector backgrounds --- .../fragments/report/ReportDoneFragment.java | 1 - .../main/res/drawable/bg_button_m3_tonal.xml | 10 ++---- .../drawable/bg_button_m3_tonal_circle.xml | 10 ++---- .../bg_button_m3_tonal_circle_selector.xml | 32 +++++++++++++++++++ .../drawable/bg_button_m3_tonal_selector.xml | 32 +++++++++++++++++++ .../layout/display_item_emoji_reactions.xml | 2 +- .../src/main/res/layout/edit_timeline.xml | 2 +- .../src/main/res/layout/fragment_compose.xml | 1 + .../src/main/res/layout/fragment_profile.xml | 2 +- .../main/res/layout/item_emoji_reaction.xml | 2 +- 10 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 mastodon/src/main/res/drawable/bg_button_m3_tonal_circle_selector.xml create mode 100644 mastodon/src/main/res/drawable/bg_button_m3_tonal_selector.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java index 2dda2d609b..1b7e9f01cf 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java @@ -34,7 +34,6 @@ import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.imageloader.ViewImageLoader; import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; -import me.grishka.appkit.utils.CubicBezierInterpolator; import me.grishka.appkit.utils.V; public class ReportDoneFragment extends MastodonToolbarFragment{ diff --git a/mastodon/src/main/res/drawable/bg_button_m3_tonal.xml b/mastodon/src/main/res/drawable/bg_button_m3_tonal.xml index e529cc6a61..4d731c481a 100644 --- a/mastodon/src/main/res/drawable/bg_button_m3_tonal.xml +++ b/mastodon/src/main/res/drawable/bg_button_m3_tonal.xml @@ -3,19 +3,13 @@ android:color="@color/m3_primary_overlay"> - + - - - - - - - + diff --git a/mastodon/src/main/res/drawable/bg_button_m3_tonal_circle.xml b/mastodon/src/main/res/drawable/bg_button_m3_tonal_circle.xml index 82140c91fe..ac0c9dbe2c 100644 --- a/mastodon/src/main/res/drawable/bg_button_m3_tonal_circle.xml +++ b/mastodon/src/main/res/drawable/bg_button_m3_tonal_circle.xml @@ -3,19 +3,13 @@ android:color="@color/m3_primary_overlay"> - + - - - - - - - + diff --git a/mastodon/src/main/res/drawable/bg_button_m3_tonal_circle_selector.xml b/mastodon/src/main/res/drawable/bg_button_m3_tonal_circle_selector.xml new file mode 100644 index 0000000000..82140c91fe --- /dev/null +++ b/mastodon/src/main/res/drawable/bg_button_m3_tonal_circle_selector.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mastodon/src/main/res/drawable/bg_button_m3_tonal_selector.xml b/mastodon/src/main/res/drawable/bg_button_m3_tonal_selector.xml new file mode 100644 index 0000000000..e529cc6a61 --- /dev/null +++ b/mastodon/src/main/res/drawable/bg_button_m3_tonal_selector.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mastodon/src/main/res/layout/display_item_emoji_reactions.xml b/mastodon/src/main/res/layout/display_item_emoji_reactions.xml index a6627ba8ce..3479357d55 100644 --- a/mastodon/src/main/res/layout/display_item_emoji_reactions.xml +++ b/mastodon/src/main/res/layout/display_item_emoji_reactions.xml @@ -30,7 +30,7 @@ android:layout_height="wrap_content" android:minHeight="48dp" android:minWidth="48dp" - android:background="@drawable/bg_button_m3_tonal_circle" + android:background="@drawable/bg_button_m3_tonal_circle_selector" android:tooltipText="@string/sk_button_react" android:contentDescription="@string/sk_button_react" android:src="@drawable/ic_fluent_add_24_filled" /> diff --git a/mastodon/src/main/res/layout/edit_timeline.xml b/mastodon/src/main/res/layout/edit_timeline.xml index 31db6543df..d754d28e57 100644 --- a/mastodon/src/main/res/layout/edit_timeline.xml +++ b/mastodon/src/main/res/layout/edit_timeline.xml @@ -49,7 +49,7 @@