From 1ad956e9655a4baea7e847dd025a7edde5295f69 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 29 Jan 2024 15:02:56 +0100 Subject: change currentAccount with a getter --- .../java/app/fedilab/android/BaseMainActivity.java | 108 ++++++++++----------- .../fedilab/android/activities/AboutActivity.java | 4 +- .../mastodon/activities/AccountReportActivity.java | 4 +- .../activities/CheckHomeCacheActivity.java | 8 +- .../mastodon/activities/ComposeActivity.java | 13 ++- .../mastodon/activities/ContextActivity.java | 15 ++- .../mastodon/activities/CustomSharingActivity.java | 5 +- .../mastodon/activities/DirectMessageActivity.java | 9 +- .../android/mastodon/activities/DraftActivity.java | 6 +- .../mastodon/activities/EditProfileActivity.java | 44 ++++----- .../mastodon/activities/HashTagActivity.java | 12 +-- .../mastodon/activities/MastodonListActivity.java | 10 +- .../android/mastodon/activities/MediaActivity.java | 5 +- .../mastodon/activities/PartnerShipActivity.java | 4 +- .../mastodon/activities/ProfileActivity.java | 30 +++--- .../activities/ReorderTimelinesActivity.java | 8 +- .../mastodon/activities/ReportActivity.java | 7 +- .../mastodon/activities/ScheduledActivity.java | 4 +- .../mastodon/activities/StatusInfoActivity.java | 3 +- .../mastodon/activities/TimelineActivity.java | 5 +- .../activities/admin/AdminAccountActivity.java | 6 +- .../activities/admin/AdminActionActivity.java | 4 +- .../activities/admin/AdminDomainBlockActivity.java | 6 +- .../activities/admin/AdminReportActivity.java | 6 +- .../mastodon/client/entities/app/CachedBundle.java | 1 - .../android/mastodon/helper/CrossActionHelper.java | 7 +- .../fedilab/android/mastodon/helper/Helper.java | 52 +++++++--- .../android/mastodon/helper/MediaHelper.java | 3 +- .../mastodon/helper/PinnedTimelineHelper.java | 7 +- .../android/mastodon/helper/SpannableHelper.java | 31 +++--- .../fedilab/android/mastodon/helper/ZipHelper.java | 3 +- .../mastodon/imageeditor/EditImageActivity.java | 4 +- .../android/mastodon/ui/drawer/AccountAdapter.java | 10 +- .../ui/drawer/AccountFollowRequestAdapter.java | 3 +- .../mastodon/ui/drawer/AccountsSearchAdapter.java | 6 +- .../ui/drawer/AccountsSearchTopBarAdapter.java | 3 +- .../android/mastodon/ui/drawer/ComposeAdapter.java | 25 +++-- .../mastodon/ui/drawer/ConversationAdapter.java | 5 +- .../android/mastodon/ui/drawer/ImageAdapter.java | 5 +- .../mastodon/ui/drawer/NotificationAdapter.java | 11 +-- .../android/mastodon/ui/drawer/SliderAdapter.java | 3 +- .../android/mastodon/ui/drawer/StatusAdapter.java | 79 ++++++++------- .../ui/drawer/StatusDirectMessageAdapter.java | 5 +- .../mastodon/ui/drawer/StatusDraftAdapter.java | 4 +- .../mastodon/ui/drawer/StatusScheduledAdapter.java | 3 +- .../mastodon/ui/drawer/SuggestionAdapter.java | 4 +- .../android/mastodon/ui/drawer/TagAdapter.java | 3 +- .../ui/drawer/admin/AdminAccountAdapter.java | 4 +- .../ui/fragment/media/FragmentMediaProfile.java | 5 +- .../settings/FragmentHomeCacheSettings.java | 4 +- .../fragment/timeline/FragmentMastodonAccount.java | 7 +- .../fragment/timeline/FragmentMastodonContext.java | 6 +- .../timeline/FragmentMastodonConversation.java | 6 +- .../timeline/FragmentMastodonDirectMessage.java | 10 +- .../timeline/FragmentMastodonNotification.java | 7 +- .../timeline/FragmentMastodonTimeline.java | 15 ++- .../timeline/FragmentNotificationContainer.java | 5 +- .../fragment/timeline/FragmentProfileTimeline.java | 5 +- .../ui/fragment/timeline/FragmentScheduled.java | 5 +- .../mastodon/viewmodel/mastodon/AccountsVM.java | 5 +- .../mastodon/viewmodel/mastodon/ReorderVM.java | 7 +- .../mastodon/viewmodel/mastodon/TopBarVM.java | 4 +- .../peertube/activities/PeertubeActivity.java | 5 +- .../peertube/activities/PeertubeMainActivity.java | 40 ++++---- .../FragmentLoginPickInstanceMastodon.java | 4 +- 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 mastodonLists = (List) 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 == null) { + currentInstance = Helper.getCurrentAccount(BaseMainActivity.this).instance; + currentUserID = Helper.getCurrentAccount(BaseMainActivity.this).user_id; Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = this::recreate; mainHandler.post(myRunnable); } - if (currentAccount != null && currentAccount.peertube_account != null) { + if (Helper.getCurrentAccount(BaseMainActivity.this) != null && Helper.getCurrentAccount(BaseMainActivity.this).peertube_account != null) { //It is a peertube user Intent intent = getIntent(); Intent myIntent = new Intent(this, PeertubeMainActivity.class); @@ -1189,7 +1187,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt return; } //If the attached account is null, the app will fetch remote instance to get up-to-date values - if (currentAccount != null && currentAccount.mastodon_account == null) { + if (Helper.getCurrentAccount(BaseMainActivity.this) != null && Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account == null) { OkHttpClient okHttpClient = Helper.myOkHttpClient(getApplication().getApplicationContext()); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://" + (MainActivity.currentInstance != null ? IDN.toASCII(MainActivity.currentInstance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/") @@ -1202,7 +1200,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt try { retrofit2.Response accountResponse = accountCall.execute(); if (accountResponse.isSuccessful()) { - currentAccount.mastodon_account = accountResponse.body(); + Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account = accountResponse.body(); } } catch (Exception e) { e.printStackTrace(); @@ -1211,9 +1209,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { - if (currentAccount == null || (currentAccount.mastodon_account == null && currentAccount.peertube_account == null)) { + if (Helper.getCurrentAccount(BaseMainActivity.this) == null || (Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account == null && Helper.getCurrentAccount(BaseMainActivity.this).peertube_account == null)) { //It is not, the user is redirected to the login page - if (currentAccount != null) { + if (Helper.getCurrentAccount(BaseMainActivity.this) != null) { try { Helper.removeAccount(BaseMainActivity.this); } catch (DBException e) { @@ -1229,11 +1227,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } return; } - bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView); - if (currentAccount.mastodon_account.locked) { + bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(Helper.getCurrentAccount(BaseMainActivity.this), binding.bottomNavView); + if (Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.locked) { binding.navView.getMenu().findItem(R.id.nav_follow_requests).setVisible(true); } - if (currentAccount.admin) { + if (Helper.getCurrentAccount(BaseMainActivity.this).admin) { binding.navView.getMenu().findItem(R.id.nav_administration).setVisible(true); } if (bottomMenu != null) { @@ -1280,8 +1278,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt }); } - currentInstance = currentAccount.instance; - currentUserID = currentAccount.user_id; + currentInstance = Helper.getCurrentAccount(BaseMainActivity.this).instance; + currentUserID = Helper.getCurrentAccount(BaseMainActivity.this).user_id; show_boosts = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_BOOSTS) + currentUserID + currentInstance, true); show_my_messages = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_MY_MESSAGES) + currentUserID + currentInstance, true); @@ -1295,22 +1293,22 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false); binding.profilePicture.setOnClickListener(v -> binding.drawerLayout.openDrawer(GravityCompat.START)); - Helper.loadPP(BaseMainActivity.this, binding.profilePicture, currentAccount); - headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance)); - if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) { - currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct; + Helper.loadPP(BaseMainActivity.this, binding.profilePicture, Helper.getCurrentAccount(BaseMainActivity.this)); + headerMainBinding.accountAcc.setText(String.format("%s@%s", Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.username, Helper.getCurrentAccount(BaseMainActivity.this).instance)); + if (Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.display_name == null || Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.display_name.isEmpty()) { + Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.display_name = Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.acct; } if (!isFinishing()) { headerMainBinding.accountName.setText( - currentAccount.mastodon_account.getSpanDisplayNameEmoji(BaseMainActivity.this, + Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.getSpanDisplayNameEmoji(BaseMainActivity.this, new WeakReference<>(headerMainBinding.accountName)), TextView.BufferType.SPANNABLE); } float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f); headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); - Helper.loadPP(BaseMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false); - MastodonHelper.loadProfileMediaMastodon(BaseMainActivity.this, headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER); + Helper.loadPP(BaseMainActivity.this, headerMainBinding.accountProfilePicture, Helper.getCurrentAccount(BaseMainActivity.this), false); + MastodonHelper.loadProfileMediaMastodon(BaseMainActivity.this, headerMainBinding.backgroundImage, Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account, MastodonHelper.MediaAccountType.HEADER); headerMainBinding.backgroundImage.setAlpha(0.5f); /* * Some general data are loaded when the app starts such; @@ -1351,13 +1349,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getConnectedAccount(currentInstance, currentToken) .observe(BaseMainActivity.this, mastodonAccount -> { //Initialize static var - if (mastodonAccount != null && currentAccount != null) { - currentAccount.mastodon_account = mastodonAccount; + if (mastodonAccount != null && Helper.getCurrentAccount(BaseMainActivity.this) != null) { + Helper.setCurrentAccountMastodonAccount(BaseMainActivity.this, mastodonAccount); displayReleaseNotesIfNeeded(BaseMainActivity.this, false); new Thread(() -> { try { //Update account in db - new Account(BaseMainActivity.this).insertOrUpdate(currentAccount); + new Account(BaseMainActivity.this).insertOrUpdate(Helper.getCurrentAccount(BaseMainActivity.this)); } catch (DBException e) { e.printStackTrace(); } @@ -1475,8 +1473,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.accountProfilePicture.setOnClickListener(v -> { Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class); Bundle args = new Bundle(); - args.putSerializable(Helper.ARG_ACCOUNT, currentAccount.mastodon_account); - new CachedBundle(BaseMainActivity.this).insertBundle(args, currentAccount, bundleId -> { + args.putSerializable(Helper.ARG_ACCOUNT, Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account); + new CachedBundle(BaseMainActivity.this).insertBundle(args, Helper.getCurrentAccount(BaseMainActivity.this), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/activities/AboutActivity.java b/app/src/main/java/app/fedilab/android/activities/AboutActivity.java index 7e7841f56..41b1a65d6 100644 --- a/app/src/main/java/app/fedilab/android/activities/AboutActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AboutActivity.java @@ -15,8 +15,6 @@ package app.fedilab.android.activities; * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; - import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -123,7 +121,7 @@ public class AboutActivity extends BaseBarActivity { Intent intent = new Intent(AboutActivity.this, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(AboutActivity.this).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(AboutActivity.this).insertBundle(args, Helper.getCurrentAccount(AboutActivity.this), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java index 84c454baf..657c1e574 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java @@ -15,8 +15,6 @@ package app.fedilab.android.mastodon.activities; * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; - import android.app.Activity; import android.graphics.PorterDuff; import android.os.Bundle; @@ -69,7 +67,7 @@ public class AccountReportActivity extends BaseBarActivity { Bundle args = getIntent().getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(AccountReportActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + new CachedBundle(AccountReportActivity.this).getBundle(bundleId, Helper.getCurrentAccount(AccountReportActivity.this), this::initializeAfterBundle); } else { initializeAfterBundle(null); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/CheckHomeCacheActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/CheckHomeCacheActivity.java index e4516a002..5fdd7255d 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/CheckHomeCacheActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/CheckHomeCacheActivity.java @@ -54,12 +54,12 @@ import java.util.List; import java.util.Locale; import app.fedilab.android.R; -import app.fedilab.android.activities.MainActivity; import app.fedilab.android.databinding.ActivityCheckHomeCachetBinding; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.StatusCache; import app.fedilab.android.mastodon.client.entities.app.TimelineCacheLogs; import app.fedilab.android.mastodon.exception.DBException; +import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; import es.dmoral.toasty.Toasty; @@ -88,7 +88,7 @@ public class CheckHomeCacheActivity extends BaseBarActivity { if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } - if (MainActivity.currentAccount == null || MainActivity.currentAccount.mastodon_account == null) { + if (Helper.getCurrentAccount(CheckHomeCacheActivity.this) == null || Helper.getCurrentAccount(CheckHomeCacheActivity.this).mastodon_account == null) { finish(); return; } @@ -107,7 +107,7 @@ public class CheckHomeCacheActivity extends BaseBarActivity { try { if (myRange == range.ALL) { if (statuses == null) { - statuses = new StatusCache(this).getHome(MainActivity.currentAccount); + statuses = new StatusCache(this).getHome(Helper.getCurrentAccount(CheckHomeCacheActivity.this)); sortAsc(statuses); } } else if (myRange == range.DAY) { @@ -247,7 +247,7 @@ public class CheckHomeCacheActivity extends BaseBarActivity { try { if (myRange == range.ALL) { if (timelineCacheLogsList == null) { - timelineCacheLogsList = new TimelineCacheLogs(this).getHome(MainActivity.currentAccount); + timelineCacheLogsList = new TimelineCacheLogs(this).getHome(Helper.getCurrentAccount(CheckHomeCacheActivity.this)); } } else if (myRange == range.DAY) { if (timelineCacheLogsDayList == null && timelineCacheLogsList != null) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java index 1664337d4..20f562c95 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java @@ -15,7 +15,6 @@ package app.fedilab.android.mastodon.activities; * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentInstance; import static app.fedilab.android.BaseMainActivity.emojis; @@ -123,7 +122,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana Bundle args = intent.getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(ComposeActivity.this).getBundle(bundleId, currentAccount, bundle -> { + new CachedBundle(ComposeActivity.this).getBundle(bundleId, Helper.getCurrentAccount(ComposeActivity.this), bundle -> { String imgpath = bundle.getString("imgpath"); float focusX = bundle.getFloat("focusX", -2); float focusY = bundle.getFloat("focusY", -2); @@ -492,7 +491,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana if (b != null) { long bundleId = b.getLong(Helper.ARG_INTENT_ID, -1); if (bundleId != -1) { - new CachedBundle(ComposeActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + new CachedBundle(ComposeActivity.this).getBundle(bundleId, Helper.getCurrentAccount(ComposeActivity.this), this::initializeAfterBundle); } else { initializeAfterBundle(b); } @@ -513,7 +512,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana statusMention = (Status) b.getSerializable(Helper.ARG_STATUS_MENTION); account = (BaseAccount) b.getSerializable(Helper.ARG_ACCOUNT); if (account == null) { - account = currentAccount; + account = Helper.getCurrentAccount(ComposeActivity.this); } editMessageId = b.getString(Helper.ARG_EDIT_STATUS_ID, null); instance = b.getString(Helper.ARG_INSTANCE, null); @@ -521,8 +520,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana visibility = b.getString(Helper.ARG_VISIBILITY, null); if (visibility == null && statusReply != null) { visibility = getVisibility(account, statusReply.visibility); - } else if (visibility == null && currentAccount != null && currentAccount.mastodon_account != null && currentAccount.mastodon_account.source != null) { - visibility = currentAccount.mastodon_account.source.privacy; + } else if (visibility == null && Helper.getCurrentAccount(ComposeActivity.this) != null && Helper.getCurrentAccount(ComposeActivity.this).mastodon_account != null && Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.source != null) { + visibility = Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.source.privacy; } mentionBooster = (Account) b.getSerializable(Helper.ARG_MENTION_BOOSTER); accountMention = (Account) b.getSerializable(Helper.ARG_ACCOUNT_MENTION); @@ -569,7 +568,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana statusDraft.statusDraftList = statuses; } if (account == null) { - account = currentAccount; + account = Helper.getCurrentAccount(ComposeActivity.this); } if (account == null) { Toasty.error(ComposeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java index 8f6e21611..973fd0701 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java @@ -15,7 +15,6 @@ package app.fedilab.android.mastodon.activities; * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentInstance; import android.content.Intent; @@ -99,7 +98,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon Bundle args = getIntent().getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(ContextActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + new CachedBundle(ContextActivity.this).getBundle(bundleId, Helper.getCurrentAccount(ContextActivity.this), this::initializeAfterBundle); } else { initializeAfterBundle(null); } @@ -111,7 +110,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null); focusedStatusURI = bundle.getString(Helper.ARG_FOCUSED_STATUS_URI, null); } - if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) { + if (focusedStatus == null || Helper.getCurrentAccount(ContextActivity.this) == null || Helper.getCurrentAccount(ContextActivity.this).mastodon_account == null) { finish(); return; } @@ -127,8 +126,8 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon loadRemotelyConversation(true); invalidateOptionsMenu(); } - if (currentAccount != null) { - MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); + if (Helper.getCurrentAccount(ContextActivity.this) != null) { + MastodonHelper.loadPPMastodon(binding.profilePicture, Helper.getCurrentAccount(ContextActivity.this).mastodon_account); } } @@ -159,7 +158,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon Bundle args = new Bundle(); args.putSerializable(Helper.ARG_STATUS, focusedStatus); args.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance); - new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(ContextActivity.this).insertBundle(args, Helper.getCurrentAccount(ContextActivity.this), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); @@ -289,7 +288,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon args.putSerializable(Helper.ARG_STATUS, status); args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance); args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); - new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(ContextActivity.this).insertBundle(args, Helper.getCurrentAccount(ContextActivity.this), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); @@ -341,7 +340,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon args.putSerializable(Helper.ARG_STATUS, status); args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance); - new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(ContextActivity.this).insertBundle(args, Helper.getCurrentAccount(ContextActivity.this), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intentContext.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java index ee3cf8b85..174e9b075 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java @@ -14,7 +14,6 @@ package app.fedilab.android.mastodon.activities; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; import android.content.SharedPreferences; import android.net.Uri; @@ -77,7 +76,7 @@ public class CustomSharingActivity extends BaseBarActivity implements OnCustomSh status = null; if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(CustomSharingActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + new CachedBundle(CustomSharingActivity.this).getBundle(bundleId, Helper.getCurrentAccount(CustomSharingActivity.this), this::initializeAfterBundle); } else { initializeAfterBundle(null); } @@ -110,7 +109,7 @@ public class CustomSharingActivity extends BaseBarActivity implements OnCustomSh bundle_thumbnailurl = status.account.avatar; } if (!bundle_creator.contains("@")) { - bundle_creator = bundle_creator + "@" + currentAccount.instance; + bundle_creator = bundle_creator + "@" + Helper.getCurrentAccount(CustomSharingActivity.this).instance; } binding.setCustomSharingTitle.setEllipsize(TextUtils.TruncateAt.END); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java index 8994618f0..98e5d6dc2 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java @@ -15,7 +15,6 @@ package app.fedilab.android.mastodon.activities; * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.mastodon.activities.ComposeActivity.PICK_MEDIA; import android.content.ClipData; @@ -72,7 +71,7 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f); binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); - MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); + MastodonHelper.loadPPMastodon(binding.profilePicture, Helper.getCurrentAccount(DirectMessageActivity.this).mastodon_account); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); @@ -82,7 +81,7 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(DirectMessageActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + new CachedBundle(DirectMessageActivity.this).getBundle(bundleId, Helper.getCurrentAccount(DirectMessageActivity.this), this::initializeAfterBundle); } else { initializeAfterBundle(null); } @@ -97,7 +96,7 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null); } - if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) { + if (focusedStatus == null || Helper.getCurrentAccount(DirectMessageActivity.this) == null || Helper.getCurrentAccount(DirectMessageActivity.this).mastodon_account == null) { finish(); return; } @@ -106,7 +105,7 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto args.putSerializable(Helper.ARG_STATUS, focusedStatus); args.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance); Status finalFocusedStatus = focusedStatus; - new CachedBundle(DirectMessageActivity.this).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(DirectMessageActivity.this).insertBundle(args, Helper.getCurrentAccount(DirectMessageActivity.this), bundleId -> { Bundle args2 = new Bundle(); args2.putLong(Helper.ARG_INTENT_ID, bundleId); FragmentMastodonDirectMessage FragmentMastodonDirectMessage = new FragmentMastodonDirectMessage(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/DraftActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/DraftActivity.java index 243be81ee..8429a63a3 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/DraftActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/DraftActivity.java @@ -14,7 +14,6 @@ package app.fedilab.android.mastodon.activities; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; import android.content.SharedPreferences; import android.os.Bundle; @@ -45,6 +44,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.StatusDraft; import app.fedilab.android.mastodon.exception.DBException; +import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.ui.drawer.StatusDraftAdapter; import app.fedilab.android.mastodon.viewmodel.mastodon.TimelinesVM; @@ -82,7 +82,7 @@ public class DraftActivity extends BaseActivity implements StatusDraftAdapter.Dr getSupportActionBar().setDisplayShowHomeEnabled(true); } timelinesVM = new ViewModelProvider(DraftActivity.this).get(TimelinesVM.class); - timelinesVM.getDrafts(currentAccount) + timelinesVM.getDrafts(Helper.getCurrentAccount(DraftActivity.this)) .observe(DraftActivity.this, this::initializeDraftView); } @@ -178,7 +178,7 @@ public class DraftActivity extends BaseActivity implements StatusDraftAdapter.Dr super.onResume(); //We need to check if drafts changed (ie when coming back from the compose activity) if (statusDrafts != null && timelinesVM != null) { - timelinesVM.getDrafts(currentAccount) + timelinesVM.getDrafts(Helper.getCurrentAccount(DraftActivity.this)) .observe(DraftActivity.this, this::updateDrafts); } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java index 8d5a49f53..e180f8752 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java @@ -14,7 +14,7 @@ package app.fedilab.android.mastodon.activities; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; + import static app.fedilab.android.BaseMainActivity.instanceInfo; import android.annotation.SuppressLint; @@ -91,7 +91,7 @@ public class EditProfileActivity extends BaseBarActivity { new ViewModelProvider(EditProfileActivity.this).get(AccountsVM.class).getConnectedAccount(BaseMainActivity.currentInstance, BaseMainActivity.currentToken) .observe(EditProfileActivity.this, account -> { if (account != null) { - currentAccount.mastodon_account = account; + Helper.setCurrentAccountMastodonAccount(EditProfileActivity.this, account); initializeView(); } else { Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error)); @@ -103,19 +103,19 @@ public class EditProfileActivity extends BaseBarActivity { @SuppressWarnings("deprecation") private void initializeView() { //Hydrate values - MastodonHelper.loadProfileMediaMastodon(EditProfileActivity.this, binding.bannerPp, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER); - MastodonHelper.loadPPMastodon(binding.accountPp, currentAccount.mastodon_account); - binding.displayName.setText(currentAccount.mastodon_account.display_name); - binding.acct.setText(String.format(Locale.getDefault(), "%s@%s", currentAccount.mastodon_account.acct, BaseMainActivity.currentInstance)); + MastodonHelper.loadProfileMediaMastodon(EditProfileActivity.this, binding.bannerPp, Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account, MastodonHelper.MediaAccountType.HEADER); + MastodonHelper.loadPPMastodon(binding.accountPp, Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account); + binding.displayName.setText(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.display_name); + binding.acct.setText(String.format(Locale.getDefault(), "%s@%s", Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.acct, BaseMainActivity.currentInstance)); String bio; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - bio = Html.fromHtml(currentAccount.mastodon_account.note, Html.FROM_HTML_MODE_LEGACY).toString(); + bio = Html.fromHtml(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.note, Html.FROM_HTML_MODE_LEGACY).toString(); else - bio = Html.fromHtml(currentAccount.mastodon_account.note).toString(); + bio = Html.fromHtml(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.note).toString(); binding.bio.setText(bio); - if (currentAccount.mastodon_account.source != null) { - binding.sensitive.setChecked(currentAccount.mastodon_account.source.sensitive); - switch (currentAccount.mastodon_account.source.privacy) { + if (Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.source != null) { + binding.sensitive.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.source.sensitive); + switch (Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.source.privacy) { case "public" -> binding.visibilityPublic.setChecked(true); case "unlisted" -> binding.visibilityUnlisted.setChecked(true); case "private" -> binding.visibilityPrivate.setChecked(true); @@ -126,15 +126,15 @@ public class EditProfileActivity extends BaseBarActivity { binding.visibilityGroup.setVisibility(View.GONE); } - binding.bot.setChecked(currentAccount.mastodon_account.bot); - binding.discoverable.setChecked(currentAccount.mastodon_account.discoverable); + binding.bot.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.bot); + binding.discoverable.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.discoverable); - if (currentAccount.mastodon_account.locked) { + if (Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.locked) { binding.locked.setChecked(true); } else { binding.unlocked.setChecked(true); } - List fields = currentAccount.mastodon_account.fields; + List fields = Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.fields; if (fields != null && fields.size() > 0) { for (Field field : fields) { AccountFieldItemBinding fieldItemBinding = AccountFieldItemBinding.inflate(getLayoutInflater()); @@ -214,11 +214,11 @@ public class EditProfileActivity extends BaseBarActivity { if (account != null) { sendBroadCast(account); binding.avatarProgress.setVisibility(View.GONE); - currentAccount.mastodon_account = account; + Helper.setCurrentAccountMastodonAccount(EditProfileActivity.this, account); Helper.recreateMainActivity(EditProfileActivity.this); new Thread(() -> { try { - new app.fedilab.android.mastodon.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount); + new app.fedilab.android.mastodon.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); } catch (DBException e) { e.printStackTrace(); } @@ -242,10 +242,10 @@ public class EditProfileActivity extends BaseBarActivity { if (account != null) { sendBroadCast(account); binding.headerProgress.setVisibility(View.GONE); - currentAccount.mastodon_account = account; + Helper.setCurrentAccountMastodonAccount(EditProfileActivity.this, account); new Thread(() -> { try { - new app.fedilab.android.mastodon.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount); + new app.fedilab.android.mastodon.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); } catch (DBException e) { e.printStackTrace(); } @@ -262,7 +262,7 @@ public class EditProfileActivity extends BaseBarActivity { Bundle args = new Bundle(); args.putBoolean(Helper.RECEIVE_REDRAW_PROFILE, true); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(EditProfileActivity.this).insertBundle(args, currentAccount, bundleId -> { + new CachedBundle(EditProfileActivity.this).insertBundle(args, Helper.getCurrentAccount(EditProfileActivity.this), bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); Intent intentBD = new Intent(Helper.BROADCAST_DATA); @@ -342,10 +342,10 @@ public class EditProfileActivity extends BaseBarActivity { ) .observe(EditProfileActivity.this, account -> { if (account != null) { - currentAccount.mastodon_account = account; + Helper.setCurrentAccountMastodonAccount(EditProfileActivity.this, account); new Thread(() -> { try { - new app.fedilab.android.mastodon.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount); + new app.fedilab.android.mastodon.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); sendBroadCast(account); } catch (DBException e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java index c87ee4c13..c11159d29 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java @@ -15,8 +15,6 @@ package app.fedilab.android.mastodon.activities; * see . */ -import static app.fedilab.android.BaseMainActivity.currentAccount; - import android.content.Intent; import android.os.Bundle; import android.os.Handler; @@ -81,7 +79,7 @@ public class HashTagActivity extends BaseActivity { Bundle args = getIntent().getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(HashTagActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + new CachedBundle(HashTagActivity.this).getBundle(bundleId, Helper.getCurrentAccount(HashTagActivity.this), this::initializeAfterBundle); } else { initializeAfterBundle(null);