diff options
author | Thomas <tschneider.ac@gmail.com> | 2024-01-29 15:02:56 +0100 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2024-01-29 15:02:56 +0100 |
commit | 1ad956e9655a4baea7e847dd025a7edde5295f69 (patch) | |
tree | be3e05cb6439741cbffb9dc7c29631be28994604 | |
parent | 1274d83ee1cbf97cd0cad46a73e2e9f3be6a1b00 (diff) |
change currentAccount with a getter
65 files changed, 349 insertions, 398 deletions
diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 68170ca85..3a7b5b734 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -213,7 +213,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt public static boolean filterFetched; public static boolean show_boosts, show_replies, show_dms, show_art_nsfw, show_self_boosts, show_self_replies, show_my_messages; public static String regex_home, regex_local, regex_public; - public static BaseAccount currentAccount; public static iconLauncher mLauncher = iconLauncher.BUBBLES; public static boolean headerMenuOpen; public static int currentNightMode; @@ -226,7 +225,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Bundle args = intent.getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(BaseMainActivity.this).getBundle(bundleId, currentAccount, bundle -> { + new CachedBundle(BaseMainActivity.this).getBundle(bundleId, Helper.getCurrentAccount(BaseMainActivity.this), bundle -> { if (bundle.getBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, false)) { String errorMessage = bundle.getString(Helper.RECEIVE_ERROR_MESSAGE); StatusDraft statusDraft = (StatusDraft) bundle.getSerializable(Helper.ARG_STATUS_DRAFT); @@ -239,7 +238,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intentCompose = new Intent(context, ComposeActivity.class); Bundle args2 = new Bundle(); args2.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft); - new CachedBundle(BaseMainActivity.this).insertBundle(args2, currentAccount, bundleId2 -> { + new CachedBundle(BaseMainActivity.this).insertBundle(args2, Helper.getCurrentAccount(BaseMainActivity.this), bundleId2 -> { Bundle bundle2 = new Bundle(); bundle2.putLong(Helper.ARG_INTENT_ID, bundleId2); intentCompose.putExtras(bundle2); @@ -262,13 +261,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Bundle args = intent.getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(BaseMainActivity.this).getBundle(bundleId, currentAccount, bundle -> { + new CachedBundle(BaseMainActivity.this).getBundle(bundleId, Helper.getCurrentAccount(BaseMainActivity.this), bundle -> { if (bundle.getBoolean(Helper.RECEIVE_REDRAW_TOPBAR, false)) { List<MastodonList> mastodonLists = (List<MastodonList>) bundle.getSerializable(Helper.RECEIVE_MASTODON_LIST); redrawPinned(mastodonLists); } if (bundle.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) { - bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView); + bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(Helper.getCurrentAccount(BaseMainActivity.this), binding.bottomNavView); if (bottomMenu != null) { //ManageClick on bottom menu items if (binding.bottomNavView.findViewById(R.id.nav_home) != null) { @@ -321,7 +320,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class); Bundle args2 = new Bundle(); args2.putSerializable(Helper.ARG_STATUS, statusSent); - new CachedBundle(BaseMainActivity.this).insertBundle(args2, currentAccount, bundleId2 -> { + new CachedBundle(BaseMainActivity.this).insertBundle(args2, Helper.getCurrentAccount(BaseMainActivity.this), bundleId2 -> { Bundle bundle2 = new Bundle(); bundle2.putLong(Helper.ARG_INTENT_ID, bundleId2); intentContext.putExtras(bundle2); @@ -360,18 +359,18 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt //Fetch some db values to initialize data new Thread(() -> { try { - if (currentAccount == null) { + if (Helper.getCurrentAccount(activity) == null) { if (currentToken == null || currentToken.trim().isEmpty()) { currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } try { - currentAccount = new Account(activity).getConnectedAccount(); + Helper.setCurrentAccount(new Account(activity).getConnectedAccount()); } catch (DBException e) { e.printStackTrace(); } } - if (currentAccount != null) { - MutedAccounts mutedAccounts = new MutedAccounts(activity).getMutedAccount(currentAccount); + if (Helper.getCurrentAccount(activity) != null) { + MutedAccounts mutedAccounts = new MutedAccounts(activity).getMutedAccount(Helper.getCurrentAccount(activity)); if (mutedAccounts != null && mutedAccounts.accounts != null) { filteredAccounts = mutedAccounts.accounts; } @@ -620,9 +619,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt }).start(); } else { navigationView.getMenu().clear(); - if (MainActivity.currentAccount.mastodon_account != null) { + if (Helper.getCurrentAccount(activity).mastodon_account != null) { navigationView.inflateMenu(R.menu.activity_main_drawer); - } else if (MainActivity.currentAccount.peertube_account != null) { + } else if (Helper.getCurrentAccount(activity).peertube_account != null) { navigationView.inflateMenu(R.menu.activity_main_drawer_peertube); } headerMainBinding.ownerAccounts.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24); @@ -640,10 +639,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (itemId == R.id.action_logout_account) { AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(activity); alt_bld.setTitle(R.string.action_logout); - if (currentAccount.mastodon_account != null && currentAccount.instance != null) { - alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.username, currentAccount.instance)); - } else if (currentAccount.peertube_account != null && currentAccount.instance != null) { - alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, currentAccount.peertube_account.getUsername(), currentAccount.instance)); + if (Helper.getCurrentAccount(activity).mastodon_account != null && Helper.getCurrentAccount(activity).instance != null) { + alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, Helper.getCurrentAccount(activity).mastodon_account.username, Helper.getCurrentAccount(activity).instance)); + } else if (Helper.getCurrentAccount(activity).peertube_account != null && Helper.getCurrentAccount(activity).instance != null) { + alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, Helper.getCurrentAccount(activity).peertube_account.getUsername(), Helper.getCurrentAccount(activity).instance)); } else { alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, "", "")); } @@ -677,14 +676,14 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (intent != null && intent.getExtras() != null) { Bundle args = intent.getExtras(); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(activity).getBundle(bundleId, currentAccount, bundle -> { + new CachedBundle(activity).getBundle(bundleId, Helper.getCurrentAccount(activity), bundle -> { app.fedilab.android.mastodon.client.entities.api.Account account = (app.fedilab.android.mastodon.client.entities.api.Account) bundle.getSerializable(Helper.INTENT_TARGETED_ACCOUNT); Status status = (Status) bundle.getSerializable(Helper.INTENT_TARGETED_STATUS); if (account != null) { Intent intentAccount = new Intent(activity, ProfileActivity.class); Bundle args2 = new Bundle(); args2.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(activity).insertBundle(args2, currentAccount, bundleId2 -> { + new CachedBundle(activity).insertBundle(args2, Helper.getCurrentAccount(activity), bundleId2 -> { Bundle bundleCached = new Bundle(); bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId2); intentAccount.putExtras(bundleCached); @@ -695,7 +694,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intentContext = new Intent(activity, ContextActivity.class); Bundle args2 = new Bundle(); args2.putSerializable(Helper.ARG_STATUS, status); - new CachedBundle(activity).insertBundle(args2, currentAccount, bundleId2 -> { + new CachedBundle(activity).insertBundle(args2, Helper.getCurrentAccount(activity), bundleId2 -> { Bundle bundleCached = new Bundle(); bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId2); intentContext.putExtras(bundleCached); @@ -731,7 +730,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt args.putBoolean(ARG_REFRESH_NOTFICATION, true); Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION); intentBC.setPackage(BuildConfig.APPLICATION_ID); - new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(activity).insertBundle(args, Helper.getCurrentAccount(activity), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intentBC.putExtras(bundle); @@ -808,14 +807,14 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_NOTIFICATION) { openNotifications(activity, intent); } else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_WITH_ANOTHER_ACCOUNT) { - CrossActionHelper.fetchRemoteStatus(activity, MainActivity.currentAccount, urlOfMessage, new CrossActionHelper.Callback() { + CrossActionHelper.fetchRemoteStatus(activity, Helper.getCurrentAccount(activity), urlOfMessage, new CrossActionHelper.Callback() { @Override public void federatedStatus(Status status) { if (status != null) { Intent intent = new Intent(activity, ContextActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_STATUS, status); - new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(activity).insertBundle(args, Helper.getCurrentAccount(activity), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -1041,26 +1040,26 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Matcher matcherLink; matcherLink = link.matcher(url); if (matcherLink.find()) { - if (currentAccount == null) { + if (Helper.getCurrentAccount(activity) == null) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); if (currentToken == null || currentToken.trim().isEmpty()) { currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } try { - currentAccount = new Account(activity).getConnectedAccount(); + Helper.setCurrentAccount(new Account(activity).getConnectedAccount()); } catch (DBException e) { e.printStackTrace(); } } if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot - CrossActionHelper.fetchRemoteStatus(activity, currentAccount, url, new CrossActionHelper.Callback() { + CrossActionHelper.fetchRemoteStatus(activity, Helper.getCurrentAccount(activity), url, new CrossActionHelper.Callback() { @Override public void federatedStatus(Status status) { if (status != null) { Intent intent = new Intent(activity, ContextActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_STATUS, status); - new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(activity).insertBundle(args, Helper.getCurrentAccount(activity), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -1077,7 +1076,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } }); } else {//It's an account - CrossActionHelper.fetchRemoteAccount(activity, currentAccount, matcherLink.group(2) + "@" + matcherLink.group(1), new CrossActionHelper.Callback() { + CrossActionHelper.fetchRemoteAccount(activity, Helper.getCurrentAccount(activity), matcherLink.group(2) + "@" + matcherLink.group(1), new CrossActionHelper.Callback() { @Override public void federatedStatus(Status status) { } @@ -1088,7 +1087,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intent = new Intent(activity, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(activity).insertBundle(args, Helper.getCurrentAccount(activity), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -1148,27 +1147,26 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS); } NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater()); - currentAccount = null; //Update account details new Thread(() -> { try { if (currentToken == null) { currentToken = sharedpreferences.getString(PREF_USER_TOKEN, null); } - currentAccount = new Account(BaseMainActivity.this).getConnectedAccount(); + Helper.setCurrentAccount(new Account(BaseMainActivity.this).getConnectedAccount()); } catch (DBException e) { e.printStackTrace(); } //Apply the custom theme - if (currentAccount != null && currentInstance == null) { - currentInstance = currentAccount.instance; - currentUserID = currentAccount.user_id; + if (Helper.getCurrentAccount(BaseMainActivity.this) != null && currentInstance == nul |