From 93624a551327c02f65d8769bb44806b9b1e3c072 Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 27 Nov 2023 22:41:31 +0100 Subject: [PATCH] merge --- .github/FUNDING.yml | 11 ------ .../android/GlobalUserPreferences.java | 38 +++++++++++++++++++ .../joinmastodon/android/MainActivity.java | 17 ++++++--- 3 files changed, 50 insertions(+), 16 deletions(-) delete mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 84d088a9a1..0000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,11 +0,0 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # mastodon -open_collective: # Replace with a single Open Collective username e.g., user1 -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username e.g., user1 -issuehunt: # Replace with a single IssueHunt username e.g., user1 -otechie: # Replace with a single Otechie username e.g., user1 -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 9a0f93b528..640d6ac99a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -14,6 +14,7 @@ import org.joinmastodon.android.api.session.AccountLocalPreferences.ColorPreference; import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; +import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.ContentType; import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.TimelineDefinition; @@ -66,6 +67,10 @@ private static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); } + private static SharedPreferences getPreReplyPrefs(){ + return MastodonApp.context.getSharedPreferences("pre_reply_sheets", Context.MODE_PRIVATE); + } + public static T fromJson(String json, Type type, T orElse){ if(json==null) return orElse; try{ @@ -182,12 +187,45 @@ public static void save(){ .apply(); } + public static boolean isOptedOutOfPreReplySheet(PreReplySheetType type, Account account, String accountID){ + if(getPreReplyPrefs().getBoolean("opt_out_"+type, false)) + return true; + if(account==null) + return false; + String accountKey=account.acct; + if(!accountKey.contains("@")) + accountKey+="@"+AccountSessionManager.get(accountID).domain; + return getPreReplyPrefs().getBoolean("opt_out_"+type+"_"+accountKey.toLowerCase(), false); + } + + public static void optOutOfPreReplySheet(PreReplySheetType type, Account account, String accountID){ + String key; + if(account==null){ + key="opt_out_"+type; + }else{ + String accountKey=account.acct; + if(!accountKey.contains("@")) + accountKey+="@"+AccountSessionManager.get(accountID).domain; + key="opt_out_"+type+"_"+accountKey.toLowerCase(); + } + getPreReplyPrefs().edit().putBoolean(key, true).apply(); + } + + public static void resetPreReplySheets(){ + getPreReplyPrefs().edit().clear().apply(); + } + public enum ThemePreference{ AUTO, LIGHT, DARK } + public enum PreReplySheetType{ + OLD_POST, + NON_MUTUAL + } + public enum AutoRevealMode { NEVER, THREADS, diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index 5050dcee1a..b48fc7be1b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.BadParcelableException; import android.os.Build; import android.os.Bundle; import android.util.Log; @@ -91,8 +92,14 @@ else if (intent.getBooleanExtra("fromNotification", false)) { return; } if(intent.hasExtra("notification")){ - Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification")); - showFragmentForNotification(notification, accountID); + // Parcelables might not be compatible across app versions so this protects against possible crashes + // when a notification was received, then the app was updated, and then the user opened the notification + try{ + Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification")); + showFragmentForNotification(notification, accountID); + }catch(BadParcelableException x){ + Log.w(TAG, x); + } }else{ AccountSessionManager.getInstance().setLastActiveAccountID(accountID); Bundle args=new Bundle(); @@ -123,11 +130,11 @@ public void handleURL(Uri uri, String accountID){ session=AccountSessionManager.get(accountID); if(session==null || !session.activated) return; - openSearchQuery(uri.toString(), session.getID(), R.string.opening_link, false); + openSearchQuery(uri.toString(), session.getID(), R.string.opening_link, false, null); } - public void openSearchQuery(String q, String accountID, int progressText, boolean fromSearch){ - new GetSearchResults(q, null, true, null, 0, 0) + public void openSearchQuery(String q, String accountID, int progressText, boolean fromSearch, GetSearchResults.Type type){ + new GetSearchResults(q, type, true, null, 0, 0) .setCallback(new Callback<>(){ @Override public void onSuccess(SearchResults result){