diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 8fc1e4288..f98860b45 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -811,10 +811,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt String action = intent.getAction(); String type = intent.getType(); Bundle extras = intent.getExtras(); - String userIdIntent, instanceIntent; + String userIdIntent, instanceIntent, urlOfMessage; if (extras != null && extras.containsKey(Helper.INTENT_ACTION)) { userIdIntent = extras.getString(Helper.PREF_KEY_ID); //Id of the account in the intent instanceIntent = extras.getString(Helper.PREF_INSTANCE); + urlOfMessage = extras.getString(Helper.PREF_MESSAGE_URL); if (extras.getInt(Helper.INTENT_ACTION) == Helper.NOTIFICATION_INTENT) { if (userIdIntent != null && instanceIntent != null && userIdIntent.equals(currentUserID) && instanceIntent.equals(currentInstance)) { openNotifications(intent); @@ -840,6 +841,23 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } } else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_NOTIFICATION) { openNotifications(intent); + } else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_WITH_ANOTHER_ACCOUNT) { + CrossActionHelper.fetchRemoteStatus(BaseMainActivity.this, MainActivity.currentAccount, urlOfMessage, new CrossActionHelper.Callback() { + @Override + public void federatedStatus(Status status) { + if (status != null) { + Intent intent = new Intent(BaseMainActivity.this, ContextActivity.class); + intent.putExtra(Helper.ARG_STATUS, status); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + } + + @Override + public void federatedAccount(app.fedilab.android.client.entities.api.Account account) { + + } + }); } } else if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 3c2ecf296..c644a779c 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -302,12 +302,14 @@ public class Helper { public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR"; public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR"; public static final String PREF_KEY_ID = "PREF_KEY_ID"; + public static final String PREF_MESSAGE_URL = "PREF_MESSAGE_URL"; public static final String PREF_INSTANCE = "PREF_INSTANCE"; public static final String SET_SECURITY_PROVIDER = "SET_SECURITY_PROVIDER"; public static final int NOTIFICATION_INTENT = 1; public static final int OPEN_NOTIFICATION = 2; + public static final int OPEN_WITH_ANOTHER_ACCOUNT = 3; public static final String INTENT_TARGETED_ACCOUNT = "INTENT_TARGETED_ACCOUNT"; public static final String INTENT_SEND_MODIFIED_IMAGE = "INTENT_SEND_MODIFIED_IMAGE"; public static final String INTENT_COMPOSE_ERROR_MESSAGE = "INTENT_COMPOSE_ERROR_MESSAGE"; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 75c5f8535..af62860f7 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -24,6 +24,7 @@ import static app.fedilab.android.BaseMainActivity.regex_public; import static app.fedilab.android.BaseMainActivity.show_boosts; import static app.fedilab.android.BaseMainActivity.show_replies; import static app.fedilab.android.activities.ContextActivity.expand; +import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN; import android.annotation.SuppressLint; import android.app.Activity; @@ -38,6 +39,8 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; +import android.os.Handler; +import android.os.Looper; import android.text.Html; import android.text.SpannableString; import android.text.Spanned; @@ -103,6 +106,7 @@ import app.fedilab.android.R; import app.fedilab.android.activities.ComposeActivity; import app.fedilab.android.activities.ContextActivity; import app.fedilab.android.activities.CustomSharingActivity; +import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MediaActivity; import app.fedilab.android.activities.ProfileActivity; import app.fedilab.android.activities.ReportActivity; @@ -114,6 +118,7 @@ import app.fedilab.android.client.entities.api.Poll; import app.fedilab.android.client.entities.api.Reaction; import app.fedilab.android.client.entities.api.Status; import app.fedilab.android.client.entities.app.Account; +import app.fedilab.android.client.entities.app.BaseAccount; import app.fedilab.android.client.entities.app.StatusCache; import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.client.entities.app.Timeline; @@ -2011,6 +2016,54 @@ public class StatusAdapter extends RecyclerView.Adapter b.putSerializable(Helper.ARG_STATUS_MENTION, statusToDeal); intent.putExtras(b); context.startActivity(intent); + } else if (itemId == R.id.action_open_with) { + new Thread(() -> { + try { + List accounts = new Account(context).getCrossAccounts(); + if (accounts.size() > 1) { + List accountList = new ArrayList<>(); + for (BaseAccount account : accounts) { + accountList.add(account.mastodon_account); + } + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> { + AlertDialog.Builder builderSingle = new AlertDialog.Builder(context, Helper.dialogStyle()); + builderSingle.setTitle(context.getString(R.string.choose_accounts)); + final AccountsSearchAdapter accountsSearchAdapter = new AccountsSearchAdapter(context, accountList); + final BaseAccount[] accountArray = new BaseAccount[accounts.size()]; + int i = 0; + for (BaseAccount account : accounts) { + accountArray[i] = account; + i++; + } + builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderSingle.setAdapter(accountsSearchAdapter, (dialog, which) -> { + BaseAccount account = accountArray[which]; + + Toasty.info(context, context.getString(R.string.toast_account_changed, "@" + account.mastodon_account.acct + "@" + account.instance), Toasty.LENGTH_LONG).show(); + BaseMainActivity.currentToken = account.token; + BaseMainActivity.currentUserID = account.user_id; + BaseMainActivity.currentInstance = account.instance; + MainActivity.currentAccount = account; + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(PREF_USER_TOKEN, account.token); + editor.commit(); + Intent mainActivity = new Intent(context, MainActivity.class); + mainActivity.putExtra(Helper.INTENT_ACTION, Helper.OPEN_WITH_ANOTHER_ACCOUNT); + mainActivity.putExtra(Helper.PREF_MESSAGE_URL, statusToDeal.url); + context.startActivity(mainActivity); + ((Activity) context).finish(); + dialog.dismiss(); + }); + builderSingle.show(); + }; + mainHandler.post(myRunnable); + } + + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); } return true; }); diff --git a/app/src/main/res/menu/option_toot.xml b/app/src/main/res/menu/option_toot.xml index bb67f1336..a4393cc91 100644 --- a/app/src/main/res/menu/option_toot.xml +++ b/app/src/main/res/menu/option_toot.xml @@ -83,5 +83,8 @@ android:id="@+id/action_mention" android:title="@string/more_action_7" app:showAsAction="never" /> - + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4f71fbf3..4a05fa198 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1930,4 +1930,5 @@ Notify for updates New sign-up (moderators) New report (moderators) + Open with another account \ No newline at end of file