diff --git a/mastodon/build.gradle b/mastodon/build.gradle index cd0a6f70..1b2e4ecd 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -13,8 +13,8 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 34 - versionCode 128 - versionName "2.9.0" + versionCode 129 + versionName "2.9.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 3949c678..3229eae9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -50,6 +50,7 @@ import android.widget.Toolbar; import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.MastodonAPIRequest; import org.joinmastodon.android.api.requests.accounts.GetAccountByID; import org.joinmastodon.android.api.requests.accounts.GetAccountFamiliarFollowers; import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; @@ -95,6 +96,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -104,6 +106,7 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager2.widget.ViewPager2; import me.grishka.appkit.Nav; +import me.grishka.appkit.api.APIRequest; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; @@ -172,6 +175,7 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, private MenuItem editSaveMenuItem; private boolean savingEdits; private Runnable editModeBackCallback=this::onEditModeBackCallback; + private HashSet> relationshipRequests=new HashSet<>(); @Override public void onCreate(Bundle savedInstanceState){ @@ -200,6 +204,14 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, setHasOptionsMenu(true); } + @Override + public void onDestroy(){ + super.onDestroy(); + for(APIRequest req:relationshipRequests) + req.cancel(); + relationshipRequests.clear(); + } + @Override public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View content=inflater.inflate(R.layout.fragment_profile, container, false); @@ -801,10 +813,13 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, } private void loadRelationship(){ - new GetAccountRelationships(Collections.singletonList(account.id)) - .setCallback(new Callback<>(){ + MastodonAPIRequest> relReq=new GetAccountRelationships(Collections.singletonList(account.id)); + relReq.setCallback(new Callback<>(){ @Override public void onSuccess(List result){ + relationshipRequests.remove(relReq); + if(getActivity()==null) + return; if(!result.isEmpty()){ relationship=result.get(0); updateRelationship(); @@ -813,14 +828,17 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, @Override public void onError(ErrorResponse error){ - + relationshipRequests.remove(relReq); } }) .exec(accountID); - new GetAccountFamiliarFollowers(Set.of(account.id)) - .setCallback(new Callback<>(){ + MastodonAPIRequest> followersReq=new GetAccountFamiliarFollowers(Set.of(account.id)); + followersReq.setCallback(new Callback<>(){ @Override public void onSuccess(List result){ + relationshipRequests.remove(followersReq); + if(getActivity()==null) + return; for(FamiliarFollowers ff:result){ if(ff.id.equals(account.id)){ familiarFollowers=ff.accounts; @@ -832,10 +850,12 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, @Override public void onError(ErrorResponse error){ - + relationshipRequests.remove(followersReq); } }) .exec(accountID); + relationshipRequests.add(relReq); + relationshipRequests.add(followersReq); } private void updateRelationship(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java index c0d70e0a..b7a56c6d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java @@ -90,8 +90,8 @@ public class HtmlParser{ Map idsByUrl=mentions.stream().distinct().collect(Collectors.toMap(m->m.url, m->m.id)); // Hashtags in remote posts have remote URLs, these have local URLs so they don't match. // Map tagsByUrl=tags.stream().collect(Collectors.toMap(t->t.url, t->t.name)); - Map tagsByTag=tags.stream().distinct().collect(Collectors.toMap(t->t.name.toLowerCase(), Function.identity())); - Map mentionsByID=mentions.stream().distinct().collect(Collectors.toMap(m->m.id, Function.identity())); + Map tagsByTag=tags.stream().distinct().collect(Collectors.toMap(t->t.name.toLowerCase(), Function.identity(), (a, b)->a)); + Map mentionsByID=mentions.stream().distinct().collect(Collectors.toMap(m->m.id, Function.identity(), (a, b)->a)); source=source.replaceAll("[\u2028\u2029]", "
"); final SpannableStringBuilder ssb=new SpannableStringBuilder();