From 3feacb59c84a50186e37dac697c8fa8fb0cbaccd Mon Sep 17 00:00:00 2001
From: FineFindus <63370021+FineFindus@users.noreply.github.com>
Date: Thu, 16 Mar 2023 15:38:35 +0100
Subject: [PATCH 01/18] feat(external-share): use transparent background
---
mastodon/src/main/AndroidManifest.xml | 3 ++-
.../joinmastodon/android/ExternalShareActivity.java | 2 --
mastodon/src/main/res/values/styles.xml | 10 ++++++++++
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/mastodon/src/main/AndroidManifest.xml b/mastodon/src/main/AndroidManifest.xml
index 69e170179..d7c114c33 100644
--- a/mastodon/src/main/AndroidManifest.xml
+++ b/mastodon/src/main/AndroidManifest.xml
@@ -62,7 +62,8 @@
-
+
diff --git a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
index 38893027f..c65ec98cf 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
@@ -3,7 +3,6 @@ package org.joinmastodon.android;
import android.app.Fragment;
import android.content.ClipData;
import android.content.Intent;
-import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
@@ -35,7 +34,6 @@ public class ExternalShareActivity extends FragmentStackActivity{
}else if(sessions.size()==1){
openComposeFragment(sessions.get(0).getID());
}else{
- getWindow().setBackgroundDrawable(new ColorDrawable(0xff000000));
UiUtils.pickAccount(this, null, R.string.choose_account, 0,
session -> openComposeFragment(session.getID()),
b -> b.setOnCancelListener(d -> finish())
diff --git a/mastodon/src/main/res/values/styles.xml b/mastodon/src/main/res/values/styles.xml
index 2657ebc75..d44c60df1 100644
--- a/mastodon/src/main/res/values/styles.xml
+++ b/mastodon/src/main/res/values/styles.xml
@@ -1,5 +1,15 @@
+
+
+
From f9dd78700934cccc264c8ca58dfd245010385e16 Mon Sep 17 00:00:00 2001
From: sk
Date: Wed, 31 May 2023 00:19:38 +0200
Subject: [PATCH 11/18] fix rules crashing the app
closes sk22#535
---
.../joinmastodon/android/fragments/SettingsFragment.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java
index 0804404b6..12f82c510 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java
@@ -326,11 +326,11 @@ public class SettingsFragment extends MastodonToolbarFragment{
items.add(new TextItem(R.string.sk_settings_auth, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/auth/edit"), R.drawable.ic_fluent_open_24_regular));
items.add(new HeaderItem(instanceName));
- items.add(new TextItem(R.string.sk_settings_rules, ()->{
- Bundle args=new Bundle();
- args.putParcelable("instance", Parcels.wrap(instance));
+ items.add(new TextItem(R.string.sk_settings_rules, instance.map(i -> () -> {
+ Bundle args = new Bundle();
+ args.putParcelable("instance", Parcels.wrap(i));
Nav.go(getActivity(), InstanceRulesFragment.class, args);
- }, R.drawable.ic_fluent_task_list_ltr_24_regular));
+ }).orElse(null), R.drawable.ic_fluent_task_list_ltr_24_regular));
items.add(new TextItem(R.string.sk_settings_about_instance , ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/about"), R.drawable.ic_fluent_info_24_regular));
items.add(new TextItem(R.string.settings_tos, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/terms"), R.drawable.ic_fluent_open_24_regular));
items.add(new TextItem(R.string.settings_privacy_policy, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/terms"), R.drawable.ic_fluent_open_24_regular));
From bb8027c7efc90c36e263cca0d0c850381743119e Mon Sep 17 00:00:00 2001
From: sk
Date: Wed, 31 May 2023 01:44:00 +0200
Subject: [PATCH 12/18] open externally opened content in main activity
closes sk22#533
---
.../android/ExternalShareActivity.java | 12 +++++-
.../joinmastodon/android/MainActivity.java | 39 +++++++++++++++----
.../android/ui/utils/UiUtils.java | 26 +++++++++----
3 files changed, 60 insertions(+), 17 deletions(-)
diff --git a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
index a862c61bd..0c770762a 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
@@ -42,7 +42,17 @@ public class ExternalShareActivity extends FragmentStackActivity{
new AccountSwitcherSheet(this, null, true, isMastodonURL, (accountId, open) -> {
AccountSessionManager.getInstance().setLastActiveAccountID(accountId);
if (open) {
- UiUtils.openURL(this, AccountSessionManager.getInstance().getLastActiveAccountID(), text, false);
+ UiUtils.lookupURL(this, accountId, text, false, (clazz, args) -> {
+ if (clazz == null) {
+ finish();
+ return;
+ }
+ args.putString("fromExternalShare", clazz.getSimpleName());
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.putExtras(args);
+ finish();
+ startActivity(intent);
+ });
} else {
openComposeFragment(accountId);
}
diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java
index ddfb01371..d21bf6d36 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java
@@ -39,6 +39,10 @@ public class MainActivity extends FragmentStackActivity{
AccountSession session;
Bundle args=new Bundle();
Intent intent=getIntent();
+ if(intent.hasExtra("fromExternalShare")) {
+ showFragmentForExternalShare(intent.getExtras());
+ return;
+ }
boolean fromNotification = intent.getBooleanExtra("fromNotification", false);
boolean hasNotification = intent.hasExtra("notification");
if(fromNotification){
@@ -75,7 +79,8 @@ public class MainActivity extends FragmentStackActivity{
@Override
protected void onNewIntent(Intent intent){
super.onNewIntent(intent);
- if(intent.getBooleanExtra("fromNotification", false)){
+ if(intent.hasExtra("fromExternalShare")) showFragmentForExternalShare(intent.getExtras());
+ else if(intent.getBooleanExtra("fromNotification", false)){
String accountID=intent.getStringExtra("accountID");
AccountSession accountSession;
try{
@@ -124,6 +129,19 @@ public class MainActivity extends FragmentStackActivity{
showFragment(fragment);
}
+ private void showFragmentForExternalShare(Bundle args) {
+ String clazz = args.getString("fromExternalShare");
+ Fragment fragment = switch (clazz) {
+ case "ThreadFragment" -> new ThreadFragment();
+ case "ProfileFragment" -> new ProfileFragment();
+ default -> null;
+ };
+ if (fragment == null) return;
+ args.putBoolean("_can_go_back", true);
+ fragment.setArguments(args);
+ showFragment(fragment);
+ }
+
private void showCompose(){
AccountSession session=AccountSessionManager.getInstance().getLastActiveAccount();
if(session==null || !session.activated)
@@ -153,18 +171,23 @@ public class MainActivity extends FragmentStackActivity{
(fragmentContainers.get(fragmentContainers.size() - 1)).getId()
);
Bundle currentArgs = currentFragment.getArguments();
- if (this.fragmentContainers.size() == 1
- && currentArgs != null
- && currentArgs.getBoolean("_can_go_back", false)
- && currentArgs.containsKey("account")) {
+ if (fragmentContainers.size() != 1
+ || currentArgs == null
+ || !currentArgs.getBoolean("_can_go_back", false)) {
+ super.onBackPressed();
+ return;
+ }
+ if (currentArgs.getBoolean("_finish_on_back", false)) {
+ finish();
+ } else if (currentArgs.containsKey("account")) {
Bundle args = new Bundle();
args.putString("account", currentArgs.getString("account"));
- args.putString("tab", "notifications");
+ if (getIntent().getBooleanExtra("fromNotification", false)) {
+ args.putString("tab", "notifications");
+ }
Fragment fragment=new HomeFragment();
fragment.setArguments(args);
showFragmentClearingBackStack(fragment);
- } else {
- super.onBackPressed();
}
}
}
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 fce5be674..f2b3f1287 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
@@ -7,6 +7,7 @@ import static org.joinmastodon.android.GlobalUserPreferences.trueBlackTheme;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
@@ -110,6 +111,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -1080,6 +1082,13 @@ public class UiUtils {
}
public static void openURL(Context context, String accountID, String url, boolean launchBrowser) {
+ lookupURL(context, accountID, url, launchBrowser, (clazz, args) -> {
+ if (clazz == null) return;
+ Nav.go((Activity) context, clazz, args);
+ });
+ }
+
+ public static void lookupURL(Context context, String accountID, String url, boolean launchBrowser, BiConsumer, Bundle> go) {
Uri uri = Uri.parse(url);
List path = uri.getPathSegments();
if (accountID != null && "https".equals(uri.getScheme())) {
@@ -1091,13 +1100,14 @@ public class UiUtils {
Bundle args = new Bundle();
args.putString("account", accountID);
args.putParcelable("status", Parcels.wrap(result));
- Nav.go((Activity) context, ThreadFragment.class, args);
+ go.accept(ThreadFragment.class, args);
}
@Override
public void onError(ErrorResponse error) {
error.showToast(context);
if (launchBrowser) launchWebBrowser(context, url);
+ go.accept(null, null);
}
})
.wrapProgress((Activity) context, R.string.loading, true,
@@ -1113,27 +1123,26 @@ public class UiUtils {
args.putString("account", accountID);
if (!results.statuses.isEmpty()) {
args.putParcelable("status", Parcels.wrap(results.statuses.get(0)));
- Nav.go((Activity) context, ThreadFragment.class, args);
+ go.accept(ThreadFragment.class, args);
return;
}
Optional account = results.accounts.stream()
.filter(a -> uri.equals(Uri.parse(a.url))).findAny();
if (account.isPresent()) {
args.putParcelable("profileAccount", Parcels.wrap(account.get()));
- Nav.go((Activity) context, ProfileFragment.class, args);
- return;
- }
- if (launchBrowser) {
- launchWebBrowser(context, url);
+ go.accept(ProfileFragment.class, args);
return;
}
+ if (launchBrowser) launchWebBrowser(context, url);
Toast.makeText(context, R.string.sk_resource_not_found, Toast.LENGTH_SHORT).show();
+ go.accept(null, null);
}
@Override
public void onError(ErrorResponse error) {
error.showToast(context);
if (launchBrowser) launchWebBrowser(context, url);
+ go.accept(null, null);
}
})
.wrapProgress((Activity) context, R.string.loading, true,
@@ -1142,7 +1151,8 @@ public class UiUtils {
return;
}
}
- launchWebBrowser(context, url);
+ if (launchBrowser) launchWebBrowser(context, url);
+ go.accept(null, null);
}
public static void copyText(View v, String text) {
From 357104efa92cc1bed6f4e3d01a290ab436cd0971 Mon Sep 17 00:00:00 2001
From: sk
Date: Wed, 31 May 2023 09:42:29 +0200
Subject: [PATCH 13/18] set checked on basis of fragment's account id
closes sk22#538
---
.../org/joinmastodon/android/ui/AccountSwitcherSheet.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java
index 04f44dc9b..9911e7305 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java
@@ -279,10 +279,15 @@ public class AccountSwitcherSheet extends BottomSheet{
public void onBind(AccountSession item){
name.setText(item.self.displayName);
username.setText(item.getFullUsername());
- view.setChecked(AccountSessionManager.getInstance().getLastActiveAccountID().equals(item.getID()));
radioButton.setVisibility(externalShare ? View.GONE : View.VISIBLE);
extraBtnWrap.setVisibility(externalShare && openInApp ? View.VISIBLE : View.GONE);
if (externalShare) view.setCheckable(false);
+ else {
+ String accountId = fragment != null
+ ? fragment.getAccountID()
+ : AccountSessionManager.getInstance().getLastActiveAccountID();
+ view.setChecked(accountId.equals(item.getID()));
+ }
}
@Override
From 2858aeb55e5954a97c78111031fe5a5f5872f773 Mon Sep 17 00:00:00 2001
From: sk
Date: Wed, 31 May 2023 09:45:24 +0200
Subject: [PATCH 14/18] only set last account id if creating new activity
---
.../java/org/joinmastodon/android/ExternalShareActivity.java | 1 -
.../src/main/java/org/joinmastodon/android/MainActivity.java | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
index 0c770762a..405a3e171 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java
@@ -40,7 +40,6 @@ public class ExternalShareActivity extends FragmentStackActivity{
openComposeFragment(sessions.get(0).getID());
}else{
new AccountSwitcherSheet(this, null, true, isMastodonURL, (accountId, open) -> {
- AccountSessionManager.getInstance().setLastActiveAccountID(accountId);
if (open) {
UiUtils.lookupURL(this, accountId, text, false, (clazz, args) -> {
if (clazz == null) {
diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java
index d21bf6d36..bbef4dd47 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java
@@ -40,6 +40,7 @@ public class MainActivity extends FragmentStackActivity{
Bundle args=new Bundle();
Intent intent=getIntent();
if(intent.hasExtra("fromExternalShare")) {
+ AccountSessionManager.getInstance().setLastActiveAccountID(intent.getStringExtra("account"));
showFragmentForExternalShare(intent.getExtras());
return;
}
From 5e7a00de3e4ed77b02bf40d7f9cbc5ff6cb9dbd3 Mon Sep 17 00:00:00 2001
From: sk
Date: Wed, 31 May 2023 10:05:31 +0200
Subject: [PATCH 15/18] fix crash when logging out active account
---
.../joinmastodon/android/ui/AccountSwitcherSheet.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java
index 9911e7305..6c5cac475 100644
--- a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java
+++ b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java
@@ -194,7 +194,15 @@ public class AccountSwitcherSheet extends BottomSheet{
private void onLoggedOut(String accountID){
AccountSessionManager.getInstance().removeAccount(accountID);
- dismiss();
+ String activeAccountID = fragment != null
+ ? fragment.getAccountID()
+ : AccountSessionManager.getInstance().getLastActiveAccountID();
+ if (accountID.equals(activeAccountID)) {
+ activity.finish();
+ activity.startActivity(new Intent(activity, MainActivity.class));
+ } else {
+ dismiss();
+ }
}
@Override
From de3a25288468b4a4da9c1fd9f97a5b81d86e04ff Mon Sep 17 00:00:00 2001
From: sk
Date: Wed, 31 May 2023 10:06:06 +0200
Subject: [PATCH 16/18] not as huge share sheet heading
---
mastodon/src/main/res/layout/item_external_share_heading.xml | 5 ++---
mastodon/src/main/res/values/styles.xml | 5 +++++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/mastodon/src/main/res/layout/item_external_share_heading.xml b/mastodon/src/main/res/layout/item_external_share_heading.xml
index b5d4a5a15..3086dee74 100644
--- a/mastodon/src/main/res/layout/item_external_share_heading.xml
+++ b/mastodon/src/main/res/layout/item_external_share_heading.xml
@@ -20,12 +20,11 @@
tools:ignore="RtlSymmetry" />
+ android:textColor="?colorM3OnSurface" />
\ No newline at end of file
diff --git a/mastodon/src/main/res/values/styles.xml b/mastodon/src/main/res/values/styles.xml
index 89935eb60..c29fc5452 100644
--- a/mastodon/src/main/res/values/styles.xml
+++ b/mastodon/src/main/res/values/styles.xml
@@ -458,6 +458,11 @@
- center_vertical
+
+