mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Some fixes
This commit is contained in:
		
							parent
							
								
									a09c882b75
								
							
						
					
					
						commit
						0f372ccde0
					
				
					 27 changed files with 189 additions and 204 deletions
				
			
		|  | @ -18,7 +18,6 @@ import static app.fedilab.android.BaseMainActivity.status.DISCONNECTED; | |||
| import static app.fedilab.android.BaseMainActivity.status.UNKNOWN; | ||||
| import static app.fedilab.android.helper.CacheHelper.deleteDir; | ||||
| import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN; | ||||
| import static app.fedilab.android.helper.Helper.getCurrentAccount; | ||||
| 
 | ||||
| import android.annotation.SuppressLint; | ||||
| import android.content.BroadcastReceiver; | ||||
|  | @ -141,13 +140,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|     public static boolean filterFetched; | ||||
|     public static boolean show_boosts, show_replies, show_art_nsfw; | ||||
|     public static String regex_home, regex_local, regex_public; | ||||
|     public static BaseAccount currentAccount; | ||||
|     Fragment currentFragment; | ||||
|     private BaseAccount account; | ||||
|     private AppBarConfiguration mAppBarConfiguration; | ||||
|     private ActivityMainBinding binding; | ||||
|     private Pinned pinned; | ||||
|     private BottomMenu bottomMenu; | ||||
| 
 | ||||
|     private final BroadcastReceiver broadcast_data = new BroadcastReceiver() { | ||||
|         @Override | ||||
|         public void onReceive(Context context, Intent intent) { | ||||
|  | @ -158,7 +156,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|                     redrawPinned(mastodonLists); | ||||
|                 } | ||||
|                 if (b.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) { | ||||
|                     bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(account, binding.bottomNavView); | ||||
|                     bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView); | ||||
|                     if (bottomMenu != null) { | ||||
|                         //ManageClick on bottom menu items | ||||
|                         if (binding.bottomNavView.findViewById(R.id.nav_home) != null) { | ||||
|  | @ -366,7 +364,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|         headerMainBinding.accountProfilePicture.setOnClickListener(v -> { | ||||
|             Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class); | ||||
|             Bundle b = new Bundle(); | ||||
|             b.putSerializable(Helper.ARG_ACCOUNT, account.mastodon_account); | ||||
|             b.putSerializable(Helper.ARG_ACCOUNT, currentAccount.mastodon_account); | ||||
|             intent.putExtras(b); | ||||
|             ActivityOptionsCompat options = ActivityOptionsCompat | ||||
|                     .makeSceneTransitionAnimation(BaseMainActivity.this, headerMainBinding.instanceInfoContainer, getString(R.string.activity_porfile_pp)); | ||||
|  | @ -500,17 +498,17 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|                 if (itemId == R.id.action_logout_account) { | ||||
|                     AlertDialog.Builder alt_bld = new AlertDialog.Builder(BaseMainActivity.this, Helper.dialogStyle()); | ||||
|                     alt_bld.setTitle(R.string.action_logout); | ||||
|                     if (account.mastodon_account != null && account.mastodon_account.username != null && account.instance != null) { | ||||
|                         alt_bld.setMessage(getString(R.string.logout_account_confirmation, account.mastodon_account.username, account.instance)); | ||||
|                     } else if (account.mastodon_account != null && account.mastodon_account.acct != null) { | ||||
|                         alt_bld.setMessage(getString(R.string.logout_account_confirmation, account.mastodon_account.acct, "")); | ||||
|                     if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.username != null && currentAccount.instance != null) { | ||||
|                         alt_bld.setMessage(getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.username, currentAccount.instance)); | ||||
|                     } else if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.acct != null) { | ||||
|                         alt_bld.setMessage(getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.acct, "")); | ||||
|                     } else { | ||||
|                         alt_bld.setMessage(getString(R.string.logout_account_confirmation, "", "")); | ||||
|                     } | ||||
|                     alt_bld.setPositiveButton(R.string.action_logout, (dialog, id) -> { | ||||
|                         dialog.dismiss(); | ||||
|                         try { | ||||
|                             Helper.removeAccount(BaseMainActivity.this, null); | ||||
|                             Helper.removeAccount(BaseMainActivity.this); | ||||
|                         } catch (DBException e) { | ||||
|                             e.printStackTrace(); | ||||
|                         } | ||||
|  | @ -536,28 +534,28 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|             }); | ||||
|             popup.show(); | ||||
|         }); | ||||
|         account = null; | ||||
|         currentAccount = null; | ||||
|         //Update account details | ||||
|         new Thread(() -> { | ||||
|             try { | ||||
|                 account = new Account(BaseMainActivity.this).getConnectedAccount(); | ||||
|                 currentAccount = new Account(BaseMainActivity.this).getConnectedAccount(); | ||||
|             } catch (DBException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|             Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||
|             Runnable myRunnable = () -> { | ||||
|                 if (account == null) { | ||||
|                 if (currentAccount == null) { | ||||
|                     //It is not, the user is redirected to the login page | ||||
|                     Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); | ||||
|                     startActivity(myIntent); | ||||
|                     finish(); | ||||
|                     return; | ||||
|                 } | ||||
|                 bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(account, binding.bottomNavView); | ||||
|                 if (account.mastodon_account.locked) { | ||||
|                 bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView); | ||||
|                 if (currentAccount.mastodon_account.locked) { | ||||
|                     binding.navView.getMenu().findItem(R.id.nav_follow_requests).setVisible(true); | ||||
|                 } | ||||
|                 if (account.admin) { | ||||
|                 if (currentAccount.admin) { | ||||
|                     binding.navView.getMenu().findItem(R.id.nav_administration).setVisible(true); | ||||
|                 } | ||||
|                 if (bottomMenu != null) { | ||||
|  | @ -603,8 +601,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|                     }); | ||||
|                 } | ||||
| 
 | ||||
|                 currentInstance = account.instance; | ||||
|                 currentUserID = account.user_id; | ||||
|                 currentInstance = currentAccount.instance; | ||||
|                 currentUserID = currentAccount.user_id; | ||||
|                 show_boosts = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_BOOSTS) + currentUserID + currentInstance, true); | ||||
|                 show_replies = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_REPLIES) + currentUserID + currentInstance, true); | ||||
|                 regex_home = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_HOME) + currentUserID + currentInstance, null); | ||||
|  | @ -612,14 +610,14 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|                 regex_public = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null); | ||||
|                 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(binding.profilePicture, account); | ||||
|                 headerMainBinding.accountAcc.setText(String.format("%s@%s", account.mastodon_account.username, account.instance)); | ||||
|                 if (account.mastodon_account.display_name.isEmpty()) { | ||||
|                     account.mastodon_account.display_name = account.mastodon_account.acct; | ||||
|                 Helper.loadPP(binding.profilePicture, currentAccount); | ||||
|                 headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance)); | ||||
|                 if (currentAccount.mastodon_account.display_name.isEmpty()) { | ||||
|                     currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct; | ||||
|                 } | ||||
|                 headerMainBinding.accountName.setText(account.mastodon_account.display_name); | ||||
|                 Helper.loadPP(headerMainBinding.accountProfilePicture, account); | ||||
|                 MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, account.mastodon_account, MastodonHelper.MediaAccountType.HEADER); | ||||
|                 headerMainBinding.accountName.setText(currentAccount.mastodon_account.display_name); | ||||
|                 Helper.loadPP(headerMainBinding.accountProfilePicture, currentAccount); | ||||
|                 MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER); | ||||
|                 /* | ||||
|                  * Some general data are loaded when the app starts such; | ||||
|                  *  - Instance info (for limits) | ||||
|  | @ -637,14 +635,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | |||
|                 new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getFilters(currentInstance, currentToken) | ||||
|                         .observe(BaseMainActivity.this, filters -> mainFilters = filters); | ||||
|                 new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getConnectedAccount(currentInstance, currentToken) | ||||
|                         .observe(BaseMainActivity.this, account1 -> { | ||||
|                         .observe(BaseMainActivity.this, mastodonAccount -> { | ||||
|                             //Initialize static var | ||||
|                             getCurrentAccount(BaseMainActivity.this); | ||||
|                             currentAccount.mastodon_account = mastodonAccount; | ||||
|                             new Thread(() -> { | ||||
|                                 try { | ||||
|                                     //Update account in db | ||||
|                                     new Account(BaseMainActivity.this).insertOrUpdate(getCurrentAccount(BaseMainActivity.this)); | ||||
|                                     getCurrentAccount(BaseMainActivity.this); | ||||
|                                     new Account(BaseMainActivity.this).insertOrUpdate(currentAccount); | ||||
|                                 } catch (DBException e) { | ||||
|                                     e.printStackTrace(); | ||||
|                                 } | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ package app.fedilab.android.activities; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.BaseMainActivity.currentInstance; | ||||
| import static app.fedilab.android.BaseMainActivity.emojis; | ||||
| import static app.fedilab.android.ui.drawer.ComposeAdapter.prepareDraft; | ||||
|  | @ -190,7 +191,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana | |||
|             statusDraft.statusDraftList = statuses; | ||||
|         } | ||||
|         if (account == null) { | ||||
|             account = Helper.getCurrentAccount(ComposeActivity.this); | ||||
|             account = currentAccount; | ||||
|         } | ||||
|         if (account == null) { | ||||
|             Toasty.error(ComposeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); | ||||
|  | @ -268,7 +269,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana | |||
|                     //We change order for mentions | ||||
|                     //At first place the account that has been mentioned if it's not our | ||||
|                     statusDraftList.get(0).mentions = new ArrayList<>(); | ||||
|                     if (!statusReply.account.acct.equalsIgnoreCase(Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.acct)) { | ||||
|                     if (!statusReply.account.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) { | ||||
|                         Mention mention = new Mention(); | ||||
|                         mention.acct = "@" + statusReply.account.acct; | ||||
|                         mention.url = statusReply.account.url; | ||||
|  | @ -279,7 +280,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana | |||
|                     //There are other mentions to | ||||
|                     if (statusReply.mentions != null && statusReply.mentions.size() > 0) { | ||||
|                         for (Mention mentionTmp : statusReply.mentions) { | ||||
|                             if (!mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && !mentionTmp.acct.equalsIgnoreCase(Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.acct)) { | ||||
|                             if (!mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && !mentionTmp.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) { | ||||
|                                 statusDraftList.get(0).mentions.add(mentionTmp); | ||||
|                             } | ||||
|                         } | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ package app.fedilab.android.activities; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction; | ||||
| 
 | ||||
| import android.content.SharedPreferences; | ||||
|  | @ -84,7 +85,7 @@ public class ContextActivity extends BaseActivity { | |||
|             finish(); | ||||
|             return; | ||||
|         } | ||||
|         MastodonHelper.loadPPMastodon(binding.profilePicture, Helper.getCurrentAccount(ContextActivity.this).mastodon_account); | ||||
|         MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); | ||||
|         Bundle bundle = new Bundle(); | ||||
|         new Thread(() -> { | ||||
|             focusedStatus = SpannableHelper.convertStatus(getApplication().getApplicationContext(), focusedStatus); | ||||
|  | @ -107,7 +108,7 @@ public class ContextActivity extends BaseActivity { | |||
|                 new Thread(() -> { | ||||
|                     try { | ||||
|                         new StatusCache(getApplication()).updateIfExists(statusCache); | ||||
|                         new QuickLoad(getApplication().getApplicationContext()).updateStatus(Helper.getCurrentAccount(ContextActivity.this), status); | ||||
|                         new QuickLoad(getApplication().getApplicationContext()).updateStatus(currentAccount, status); | ||||
|                         Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||
|                         //Update UI | ||||
|                         Runnable myRunnable = () -> sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null); | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ package app.fedilab.android.activities; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.content.SharedPreferences; | ||||
| import android.graphics.drawable.ColorDrawable; | ||||
| import android.net.Uri; | ||||
|  | @ -99,7 +101,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari | |||
|             bundle_thumbnailurl = status.account.avatar; | ||||
|         } | ||||
|         if (!bundle_creator.contains("@")) { | ||||
|             bundle_creator = bundle_creator + "@" + Helper.getCurrentAccount(CustomSharingActivity.this).instance; | ||||
|             bundle_creator = bundle_creator + "@" + currentAccount.instance; | ||||
|         } | ||||
| 
 | ||||
|         binding.setCustomSharingTitle.setEllipsize(TextUtils.TruncateAt.END); | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ package app.fedilab.android.activities; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.graphics.drawable.ColorDrawable; | ||||
| import android.os.Bundle; | ||||
| import android.os.Handler; | ||||
|  | @ -80,7 +82,7 @@ public class DraftActivity extends BaseActivity implements StatusDraftAdapter.Dr | |||
|             getSupportActionBar().setDisplayShowHomeEnabled(true); | ||||
|         } | ||||
|         timelinesVM = new ViewModelProvider(DraftActivity.this).get(TimelinesVM.class); | ||||
|         timelinesVM.getDrafts(Helper.getCurrentAccount(DraftActivity.this)) | ||||
|         timelinesVM.getDrafts(currentAccount) | ||||
|                 .observe(DraftActivity.this, this::initializeDraftView); | ||||
|     } | ||||
| 
 | ||||
|  | @ -176,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(Helper.getCurrentAccount(DraftActivity.this)) | ||||
|             timelinesVM.getDrafts(currentAccount) | ||||
|                     .observe(DraftActivity.this, this::updateDrafts); | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ package app.fedilab.android.activities; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.BaseMainActivity.instanceInfo; | ||||
| 
 | ||||
| import android.content.Intent; | ||||
|  | @ -74,7 +75,7 @@ public class EditProfileActivity extends BaseActivity { | |||
|         new ViewModelProvider(EditProfileActivity.this).get(AccountsVM.class).getConnectedAccount(BaseMainActivity.currentInstance, BaseMainActivity.currentToken) | ||||
|                 .observe(EditProfileActivity.this, account -> { | ||||
|                     if (account != null) { | ||||
|                         Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; | ||||
|                         currentAccount.mastodon_account = account; | ||||
|                         initializeView(); | ||||
|                     } else { | ||||
|                         Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error)); | ||||
|  | @ -86,19 +87,19 @@ public class EditProfileActivity extends BaseActivity { | |||
|     @SuppressWarnings("deprecation") | ||||
|     private void initializeView() { | ||||
|         //Hydrate values | ||||
|         MastodonHelper.loadProfileMediaMastodon(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)); | ||||
|         MastodonHelper.loadProfileMediaMastodon(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)); | ||||
|         String bio; | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) | ||||
|             bio = Html.fromHtml(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.note, Html.FROM_HTML_MODE_LEGACY).toString(); | ||||
|             bio = Html.fromHtml(currentAccount.mastodon_account.note, Html.FROM_HTML_MODE_LEGACY).toString(); | ||||
|         else | ||||
|             bio = Html.fromHtml(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.note).toString(); | ||||
|             bio = Html.fromHtml(currentAccount.mastodon_account.note).toString(); | ||||
|         binding.bio.setText(bio); | ||||
|         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) { | ||||
|         if (currentAccount.mastodon_account.source != null) { | ||||
|             binding.sensitive.setChecked(currentAccount.mastodon_account.source.sensitive); | ||||
|             switch (currentAccount.mastodon_account.source.privacy) { | ||||
|                 case "public": | ||||
|                     binding.visibilityPublic.setChecked(true); | ||||
|                     break; | ||||
|  | @ -117,15 +118,15 @@ public class EditProfileActivity extends BaseActivity { | |||
|             binding.visibilityGroup.setVisibility(View.GONE); | ||||
|         } | ||||
| 
 | ||||
|         binding.bot.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.bot); | ||||
|         binding.discoverable.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.discoverable); | ||||
|         binding.bot.setChecked(currentAccount.mastodon_account.bot); | ||||
|         binding.discoverable.setChecked(currentAccount.mastodon_account.discoverable); | ||||
| 
 | ||||
|         if (Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.locked) { | ||||
|         if (currentAccount.mastodon_account.locked) { | ||||
|             binding.locked.setChecked(true); | ||||
|         } else { | ||||
|             binding.unlocked.setChecked(true); | ||||
|         } | ||||
|         List<Field> fields = Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.fields; | ||||
|         List<Field> fields = currentAccount.mastodon_account.fields; | ||||
|         if (fields != null && fields.size() > 0) { | ||||
|             for (Field field : fields) { | ||||
|                 AccountFieldItemBinding fieldItemBinding = AccountFieldItemBinding.inflate(getLayoutInflater()); | ||||
|  | @ -201,11 +202,11 @@ public class EditProfileActivity extends BaseActivity { | |||
|                         if (account != null) { | ||||
|                             sendBroadCast(account); | ||||
|                             binding.avatarProgress.setVisibility(View.GONE); | ||||
|                             Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; | ||||
|                             currentAccount.mastodon_account = account; | ||||
|                             Helper.recreateMainActivity(EditProfileActivity.this); | ||||
|                             new Thread(() -> { | ||||
|                                 try { | ||||
|                                     new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); | ||||
|                                     new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount); | ||||
|                                 } catch (DBException e) { | ||||
|                                     e.printStackTrace(); | ||||
|                                 } | ||||
|  | @ -226,10 +227,10 @@ public class EditProfileActivity extends BaseActivity { | |||
|                         if (account != null) { | ||||
|                             sendBroadCast(account); | ||||
|                             binding.headerProgress.setVisibility(View.GONE); | ||||
|                             Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; | ||||
|                             currentAccount.mastodon_account = account; | ||||
|                             new Thread(() -> { | ||||
|                                 try { | ||||
|                                     new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); | ||||
|                                     new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount); | ||||
|                                 } catch (DBException e) { | ||||
|                                     e.printStackTrace(); | ||||
|                                 } | ||||
|  | @ -320,10 +321,10 @@ public class EditProfileActivity extends BaseActivity { | |||
|             ) | ||||
|                     .observe(EditProfileActivity.this, account -> { | ||||
|                         if (account != null) { | ||||
|                             Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; | ||||
|                             currentAccount.mastodon_account = account; | ||||
|                             new Thread(() -> { | ||||
|                                 try { | ||||
|                                     new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); | ||||
|                                     new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount); | ||||
|                                     sendBroadCast(account); | ||||
|                                 } catch (DBException e) { | ||||
|                                     e.printStackTrace(); | ||||
|  |  | |||
|  | @ -15,6 +15,8 @@ package app.fedilab.android.activities; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.content.Intent; | ||||
| import android.graphics.drawable.ColorDrawable; | ||||
| import android.os.Bundle; | ||||
|  | @ -107,7 +109,7 @@ public class HashTagActivity extends BaseActivity { | |||
|         } else if (item.getItemId() == R.id.action_add_timeline) { | ||||
|             new Thread(() -> { | ||||
|                 try { | ||||
|                     Pinned pinned = new Pinned(HashTagActivity.this).getPinned(Helper.getCurrentAccount(HashTagActivity.this)); | ||||
|                     Pinned pinned = new Pinned(HashTagActivity.this).getPinned(currentAccount); | ||||
|                     boolean canBeAdded = true; | ||||
|                     boolean update = true; | ||||
|                     if (pinned == null) { | ||||
|  |  | |||
|  | @ -46,10 +46,10 @@ import es.dmoral.toasty.Toasty; | |||
| public class LoginActivity extends BaseActivity { | ||||
| 
 | ||||
| 
 | ||||
|     private final int PICK_IMPORT = 5557; | ||||
|     private boolean requestedAdmin; | ||||
|     public static Account.API apiLogin; | ||||
|     public static String currentInstanceLogin, client_idLogin, client_secretLogin, softwareLogin; | ||||
|     private final int PICK_IMPORT = 5557; | ||||
|     private boolean requestedAdmin; | ||||
| 
 | ||||
|     private void manageItent(Intent intent) { | ||||
|         if (intent != null && intent.getData() != null && intent.getData().toString().contains(REDIRECT_CONTENT_WEB + "?code=")) { | ||||
|  |  | |||
|  | @ -15,6 +15,8 @@ package app.fedilab.android.activities; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.content.BroadcastReceiver; | ||||
| import android.content.ClipData; | ||||
| import android.content.ClipboardManager; | ||||
|  | @ -541,7 +543,7 @@ public class ProfileActivity extends BaseActivity { | |||
|     private void updateAccount() { | ||||
| 
 | ||||
|         //The value for account is from same server so id can be used | ||||
|         if (account.id.equals(Helper.getCurrentAccount(ProfileActivity.this).user_id)) { | ||||
|         if (account.id.equals(currentAccount.user_id)) { | ||||
|             binding.accountFollow.setVisibility(View.GONE); | ||||
|             binding.headerEditProfile.setVisibility(View.VISIBLE); | ||||
|             binding.headerEditProfile.bringToFront(); | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ package app.fedilab.android.activities; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.graphics.drawable.ColorDrawable; | ||||
| import android.os.Bundle; | ||||
| import android.view.MenuItem; | ||||
|  | @ -26,7 +28,6 @@ import com.google.android.material.tabs.TabLayout; | |||
| 
 | ||||
| import app.fedilab.android.R; | ||||
| import app.fedilab.android.databinding.ActivityScheduledBinding; | ||||
| import app.fedilab.android.helper.Helper; | ||||
| import app.fedilab.android.helper.MastodonHelper; | ||||
| import app.fedilab.android.helper.ThemeHelper; | ||||
| import app.fedilab.android.ui.pageadapter.FedilabScheduledPageAdapter; | ||||
|  | @ -53,7 +54,7 @@ public class ScheduledActivity extends BaseActivity { | |||
|             getSupportActionBar().setDisplayShowHomeEnabled(true); | ||||
|         } | ||||
| 
 | ||||
|         MastodonHelper.loadPPMastodon(binding.profilePicture, Helper.getCurrentAccount(ScheduledActivity.this).mastodon_account); | ||||
|         MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); | ||||
|         binding.title.setText(R.string.scheduled); | ||||
|         binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_server))); | ||||
|         binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_client))); | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ package app.fedilab.android.activities; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.graphics.drawable.ColorDrawable; | ||||
| import android.os.Bundle; | ||||
| import android.view.MenuItem; | ||||
|  | @ -31,7 +33,6 @@ import java.util.Locale; | |||
| 
 | ||||
| import app.fedilab.android.R; | ||||
| import app.fedilab.android.databinding.ActivitySettingsBinding; | ||||
| import app.fedilab.android.helper.Helper; | ||||
| import app.fedilab.android.helper.ThemeHelper; | ||||
| import app.fedilab.android.ui.fragment.settings.FragmentComposeSettings; | ||||
| import app.fedilab.android.ui.fragment.settings.FragmentInterfaceSettings; | ||||
|  | @ -69,7 +70,7 @@ public class SettingsActivity extends BaseActivity { | |||
|         binding.setTheming.setOnClickListener(v -> displaySettings(SettingsEnum.THEMING)); | ||||
|         binding.setAdministration.setOnClickListener(v -> displaySettings(SettingsEnum.ADMINISTRATION)); | ||||
|         binding.setLanguage.setOnClickListener(v -> displaySettings(SettingsEnum.LANGUAGE)); | ||||
|         if (Helper.getCurrentAccount(SettingsActivity.this).admin) { | ||||
|         if (currentAccount.admin) { | ||||
|             binding.setAdministration.setVisibility(View.VISIBLE); | ||||
|         } else { | ||||
|             binding.setAdministration.setVisibility(View.GONE); | ||||
|  |  | |||
|  | @ -105,6 +105,7 @@ public class Status implements Serializable, Cloneable { | |||
|     public transient boolean setCursorToEnd = false; | ||||
|     public transient int cursorPosition = 0; | ||||
|     public transient boolean submitted = false; | ||||
| 
 | ||||
|     @NonNull | ||||
|     public Object clone() throws CloneNotSupportedException { | ||||
|         return super.clone(); | ||||
|  |  | |||
|  | @ -51,13 +51,12 @@ public class QuickLoad { | |||
|     @SerializedName("notifications") | ||||
|     public List<Notification> notifications; | ||||
|     private Context _mContext; | ||||
|     private type typeOfFetch; | ||||
| 
 | ||||
|     public QuickLoad() { | ||||
|         db = null; | ||||
|     } | ||||
| 
 | ||||
|     private type typeOfFetch; | ||||
| 
 | ||||
|     public QuickLoad(Context context) { | ||||
|         //Creation of the DB with tables | ||||
|         this.db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); | ||||
|  | @ -72,6 +71,16 @@ public class QuickLoad { | |||
|         this.typeOfFetch = type; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check if the current timeline can be stored | ||||
|      * | ||||
|      * @param timeLineType - Timeline.TimeLineEnum | ||||
|      * @return boolean | ||||
|      */ | ||||
|     private static boolean cannotBeStored(Timeline.TimeLineEnum timeLineType) { | ||||
|         return timeLineType != Timeline.TimeLineEnum.HOME && timeLineType != Timeline.TimeLineEnum.LOCAL && timeLineType != Timeline.TimeLineEnum.PUBLIC && timeLineType != Timeline.TimeLineEnum.REMOTE && timeLineType != Timeline.TimeLineEnum.LIST && timeLineType != Timeline.TimeLineEnum.TAG; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Update a QuickLoad in db | ||||
|      * | ||||
|  | @ -99,16 +108,6 @@ public class QuickLoad { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check if the current timeline can be stored | ||||
|      * | ||||
|      * @param timeLineType - Timeline.TimeLineEnum | ||||
|      * @return boolean | ||||
|      */ | ||||
|     private static boolean cannotBeStored(Timeline.TimeLineEnum timeLineType) { | ||||
|         return timeLineType != Timeline.TimeLineEnum.HOME && timeLineType != Timeline.TimeLineEnum.LOCAL && timeLineType != Timeline.TimeLineEnum.PUBLIC && timeLineType != Timeline.TimeLineEnum.REMOTE && timeLineType != Timeline.TimeLineEnum.LIST && timeLineType != Timeline.TimeLineEnum.TAG; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Insert or update a QuickLoad | ||||
|      * | ||||
|  |  | |||
|  | @ -109,16 +109,6 @@ public class CacheHelper { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public interface Callback { | ||||
|         void getCacheSize(float size); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public interface CallbackAccount { | ||||
|         void getcount(List<Integer> countStatuses); | ||||
|     } | ||||
| 
 | ||||
|     public static void clearCache(Context context, boolean clearFiles, List<CacheAccount> cacheAccounts, CallbackClear callbackClear) { | ||||
|         new Thread(() -> { | ||||
|             if (clearFiles) { | ||||
|  | @ -157,6 +147,15 @@ public class CacheHelper { | |||
|         }).start(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public interface Callback { | ||||
|         void getCacheSize(float size); | ||||
|     } | ||||
| 
 | ||||
|     public interface CallbackAccount { | ||||
|         void getcount(List<Integer> countStatuses); | ||||
|     } | ||||
| 
 | ||||
|     public interface CallbackClear { | ||||
|         void onCleared(); | ||||
|     } | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ package app.fedilab.android.helper; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static android.content.Context.DOWNLOAD_SERVICE; | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.webview.ProxyHelper.setProxy; | ||||
| 
 | ||||
| import android.annotation.SuppressLint; | ||||
|  | @ -588,7 +589,6 @@ public class Helper { | |||
|         return date; | ||||
|     } | ||||
| 
 | ||||
|     private static BaseAccount currentAccount; | ||||
| 
 | ||||
|     /** | ||||
|      * Converts dp to pixel | ||||
|  | @ -847,58 +847,40 @@ public class Helper { | |||
|      * Log out the authenticated user by removing its token | ||||
|      * | ||||
|      * @param activity Activity | ||||
|      * @param account  {@link Account} | ||||
|      * @throws DBException Exception | ||||
|      */ | ||||
|     public static void removeAccount(Activity activity, BaseAccount account) throws DBException { | ||||
|     public static void removeAccount(Activity activity) throws DBException { | ||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); | ||||
|         //Current user | ||||
|         String userId = sharedpreferences.getString(PREF_USER_ID, null); | ||||
|         String instance = sharedpreferences.getString(PREF_USER_INSTANCE, null); | ||||
|         Account accountDB = new Account(activity); | ||||
|         boolean accountRemovedIsLogged = false; | ||||
|         //Remove the current account | ||||
|         if (account == null) { | ||||
|             account = accountDB.getUniqAccount(userId, instance); | ||||
|             accountRemovedIsLogged = true; | ||||
|         } | ||||
|         if (account != null) { | ||||
|             BaseAccount finalAccount = account; | ||||
|             OauthVM oauthVM = new ViewModelProvider((ViewModelStoreOwner) activity).get(OauthVM.class); | ||||
|             //Revoke the token | ||||
|             oauthVM.revokeToken(account.instance, account.token, account.client_id, account.client_secret); | ||||
|             //Revoke token and remove user | ||||
|             new Thread(() -> { | ||||
|                 try { | ||||
|                     accountDB.removeUser(finalAccount); | ||||
|                 } catch (DBException e) { | ||||
|                     e.printStackTrace(); | ||||
|                 } | ||||
|             }).start(); | ||||
|         } | ||||
|         //If the account removed is not the logged one, no need to log out the current user | ||||
|         if (!accountRemovedIsLogged) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         OauthVM oauthVM = new ViewModelProvider((ViewModelStoreOwner) activity).get(OauthVM.class); | ||||
| 
 | ||||
|         //Revoke the token | ||||
|         oauthVM.revokeToken(currentAccount.instance, currentAccount.token, currentAccount.client_id, currentAccount.client_secret); | ||||
|         //Log out the current user | ||||
|         accountDB.removeUser(currentAccount); | ||||
|         BaseAccount newAccount = accountDB.getLastUsedAccount(); | ||||
|         SharedPreferences.Editor editor = sharedpreferences.edit(); | ||||
|         if (newAccount == null) { | ||||
|             editor.putString(PREF_USER_TOKEN, null); | ||||
|             editor.putString(PREF_USER_INSTANCE, null); | ||||
|             editor.putString(PREF_USER_ID, null); | ||||
|             editor.apply(); | ||||
|             editor.commit(); | ||||
|             Intent loginActivity = new Intent(activity, LoginActivity.class); | ||||
|             activity.startActivity(loginActivity); | ||||
|             activity.finish(); | ||||
|         } else { | ||||
|             currentAccount = newAccount; | ||||
|             editor.putString(PREF_USER_TOKEN, newAccount.token); | ||||
|             editor.putString(PREF_USER_INSTANCE, newAccount.instance); | ||||
|             editor.putString(PREF_USER_ID, newAccount.user_id); | ||||
|             BaseMainActivity.currentUserID = newAccount.user_id; | ||||
|             BaseMainActivity.currentToken = newAccount.token; | ||||
|             BaseMainActivity.currentInstance = newAccount.instance; | ||||
|             editor.apply(); | ||||
|             editor.commit(); | ||||
|             Intent changeAccount = new Intent(activity, MainActivity.class); | ||||
|             changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); | ||||
|             activity.startActivity(changeAccount); | ||||
|  | @ -1325,31 +1307,6 @@ public class Helper { | |||
|         imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); | ||||
|     } | ||||
| 
 | ||||
|     //Enum that described actions to replace inside a toot content | ||||
|     public enum PatternType { | ||||
|         MENTION, | ||||
|         MENTION_LONG, | ||||
|         TAG, | ||||
|         GROUP | ||||
|     } | ||||
| 
 | ||||
|     public enum NotifType { | ||||
|         FOLLLOW, | ||||
|         MENTION, | ||||
|         BOOST, | ||||
|         FAV, | ||||
|         POLL, | ||||
|         STATUS, | ||||
|         BACKUP, | ||||
|         STORE, | ||||
|         TOOT | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public interface OnAttachmentCopied { | ||||
|         void onAttachmentCopied(Attachment attachment); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sends notification with intent | ||||
|      * | ||||
|  | @ -1501,7 +1458,6 @@ public class Helper { | |||
|         notificationManager.notify(notificationId, summaryNotification); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public static void transfertIfExist(Context context) { | ||||
|         File dbFile = context.getDatabasePath(OLD_DB_NAME); | ||||
|         if (!dbFile.exists()) { | ||||
|  | @ -1525,7 +1481,6 @@ public class Helper { | |||
|         context.deleteDatabase(OLD_DB_NAME); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public static String dateDiffFull(Date dateToot) { | ||||
|         SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault()); | ||||
|         try { | ||||
|  | @ -1566,16 +1521,29 @@ public class Helper { | |||
|         return "@fedilab_fetch_more_" + uuid; | ||||
|     } | ||||
| 
 | ||||
|     public static BaseAccount getCurrentAccount(Context context) { | ||||
|         if (currentAccount == null) { | ||||
|             try { | ||||
|                 currentAccount = new Account(context).getUniqAccount(MainActivity.currentUserID, MainActivity.currentInstance); | ||||
|             } catch (DBException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|         } | ||||
|         return currentAccount; | ||||
| 
 | ||||
|     //Enum that described actions to replace inside a toot content | ||||
|     public enum PatternType { | ||||
|         MENTION, | ||||
|         MENTION_LONG, | ||||
|         TAG, | ||||
|         GROUP | ||||
|     } | ||||
| 
 | ||||
|     public enum NotifType { | ||||
|         FOLLLOW, | ||||
|         MENTION, | ||||
|         BOOST, | ||||
|         FAV, | ||||
|         POLL, | ||||
|         STATUS, | ||||
|         BACKUP, | ||||
|         STORE, | ||||
|         TOOT | ||||
|     } | ||||
| 
 | ||||
|     public interface OnAttachmentCopied { | ||||
|         void onAttachmentCopied(Attachment attachment); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ package app.fedilab.android.helper; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static android.content.Context.DOWNLOAD_SERVICE; | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.helper.Helper.notify_user; | ||||
| 
 | ||||
| import android.app.Activity; | ||||
|  | @ -162,7 +163,7 @@ public class MediaHelper { | |||
|                             Uri uri = Uri.fromFile(backupFile); | ||||
|                             intent.setDataAndType(uri, mime); | ||||
|                             if (!share) { | ||||
|                                 notify_user(context, Helper.NOTIFICATION_MEDIA, Helper.getCurrentAccount(context), intent, BitmapFactory.decodeResource(context.getResources(), | ||||
|                                 notify_user(context, Helper.NOTIFICATION_MEDIA, currentAccount, intent, BitmapFactory.decodeResource(context.getResources(), | ||||
|                                         R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); | ||||
|                                 Toasty.success(context, context.getString(R.string.save_over), Toasty.LENGTH_LONG).show(); | ||||
|                             } else { | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ package app.fedilab.android.helper; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.ui.pageadapter.FedilabPageAdapter.BOTTOM_TIMELINE_COUNT; | ||||
| 
 | ||||
| import android.content.Context; | ||||
|  | @ -261,7 +262,7 @@ public class PinnedTimelineHelper { | |||
|         int toRemove = 0; | ||||
|         try { | ||||
|             //If some menu items have been hidden we should not create tab for them | ||||
|             bottomMenuDb = new BottomMenu(context).getAllBottomMenu(Helper.getCurrentAccount(context)); | ||||
|             bottomMenuDb = new BottomMenu(context).getAllBottomMenu(currentAccount); | ||||
|             if (bottomMenuDb != null) { | ||||
|                 List<BottomMenu.MenuItem> menuItemList = bottomMenuDb.bottom_menu; | ||||
|                 if (menuItemList != null) { | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ package app.fedilab.android.helper; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.helper.Helper.USER_AGENT; | ||||
| import static app.fedilab.android.helper.Helper.convertDpToPixel; | ||||
| import static app.fedilab.android.helper.Helper.urlPattern; | ||||
|  | @ -379,7 +380,7 @@ public class SpannableHelper { | |||
|                         Matcher matcherLink = link.matcher(url); | ||||
|                         if (matcherLink.find() && !url.contains("medium.com")) { | ||||
|                             if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot | ||||
|                                 CrossActionHelper.fetchRemoteStatus(context, Helper.getCurrentAccount(context), url, new CrossActionHelper.Callback() { | ||||
|                                 CrossActionHelper.fetchRemoteStatus(context, currentAccount, url, new CrossActionHelper.Callback() { | ||||
|                                     @Override | ||||
|                                     public void federatedStatus(Status status) { | ||||
|                                         Intent intent = new Intent(context, ContextActivity.class); | ||||
|  | @ -394,7 +395,7 @@ public class SpannableHelper { | |||
|                                     } | ||||
|                                 }); | ||||
|                             } else {//It's an account | ||||
|                                 CrossActionHelper.fetchRemoteAccount(context, Helper.getCurrentAccount(context), status.account, new CrossActionHelper.Callback() { | ||||
|                                 CrossActionHelper.fetchRemoteAccount(context, currentAccount, status.account, new CrossActionHelper.Callback() { | ||||
|                                     @Override | ||||
|                                     public void federatedStatus(Status status) { | ||||
| 
 | ||||
|  | @ -843,7 +844,7 @@ public class SpannableHelper { | |||
|                         Matcher matcherLink = link.matcher(url); | ||||
|                         if (matcherLink.find() && !url.contains("medium.com")) { | ||||
|                             if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot | ||||
|                                 CrossActionHelper.fetchRemoteStatus(context, Helper.getCurrentAccount(context), url, new CrossActionHelper.Callback() { | ||||
|                                 CrossActionHelper.fetchRemoteStatus(context, currentAccount, url, new CrossActionHelper.Callback() { | ||||
|                                     @Override | ||||
|                                     public void federatedStatus(Status status) { | ||||
|                                         Intent intent = new Intent(context, ContextActivity.class); | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ package app.fedilab.android.ui.drawer; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| import static app.fedilab.android.BaseMainActivity.emojis; | ||||
| import static app.fedilab.android.BaseMainActivity.instanceInfo; | ||||
| import static app.fedilab.android.activities.ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE; | ||||
|  | @ -421,8 +422,8 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder | |||
|             List<Attachment> attachmentList = statusList.get(position).media_attachments; | ||||
|             if (attachmentList != null && attachmentList.size() > 0) { | ||||
|                 holder.binding.sensitiveMedia.setVisibility(View.VISIBLE); | ||||
|                 holder.binding.sensitiveMedia.setChecked(Helper.getCurrentAccount(context).mastodon_account.source.sensitive); | ||||
|                 statusList.get(position).sensitive = Helper.getCurrentAccount(context).mastodon_account.source.sensitive; | ||||
|                 holder.binding.sensitiveMedia.setChecked(currentAccount.mastodon_account.source.sensitive); | ||||
|                 statusList.get(position).sensitive = currentAccount.mastodon_account.source.sensitive; | ||||
|                 holder.binding.sensitiveMedia.setOnCheckedChangeListener((buttonView, isChecked) -> statusList.get(position).sensitive = isChecked); | ||||
|                 int mediaPosition = 0; | ||||
|                 for (Attachment attachment : attachmentList) { | ||||
|  | @ -1070,8 +1071,8 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder | |||
|             if (statusDraft.visibility == null) { | ||||
|                 if (position > 0) { | ||||
|                     statusDraft.visibility = statusList.get(position - 1).visibility; | ||||
|                 } else if (Helper.getCurrentAccount(context).mastodon_account != null && Helper.getCurrentAccount(context).mastodon_account.source != null) { | ||||
|                     statusDraft.visibility = Helper.getCurrentAccount(context).mastodon_account.source.privacy; | ||||
|                 } else if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.source != null) { | ||||
|                     statusDraft.visibility = currentAccount.mastodon_account.source.privacy; | ||||
|                 } else { | ||||
|                     statusDraft.visibility = "public"; | ||||
|                 } | ||||
|  |  | |||
|  | @ -58,8 +58,8 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH | |||
|     private final int TYPE_POLL = 5; | ||||
|     private final int TYPE_STATUS = 6; | ||||
|     private final int NOTIFICATION_FETCH_MORE = 7; | ||||
|     private Context context; | ||||
|     public FetchMoreCallBack fetchMoreCallBack; | ||||
|     private Context context; | ||||
| 
 | ||||
|     public NotificationAdapter(List<Notification> notificationList) { | ||||
|         this.notificationList = notificationList; | ||||
|  | @ -254,11 +254,6 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public interface FetchMoreCallBack { | ||||
|         void onClick(String min_id, String fetchmoreId); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public long getItemId(int position) { | ||||
|         return position; | ||||
|     } | ||||
|  | @ -268,6 +263,9 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH | |||
|         return notificationList.size(); | ||||
|     } | ||||
| 
 | ||||
|     public interface FetchMoreCallBack { | ||||
|         void onClick(String min_id, String fetchmoreId); | ||||
|     } | ||||
| 
 | ||||
|     static class ViewHolderFollow extends RecyclerView.ViewHolder { | ||||
|         DrawerFollowBinding binding; | ||||
|  |  | |||
|  | @ -139,8 +139,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> | |||
|     private final List<Status> statusList; | ||||
|     private final boolean minified; | ||||
|     private final Timeline.TimeLineEnum timelineType; | ||||
|     private Context context; | ||||
|     public FetchMoreCallBack fetchMoreCallBack; | ||||
|     private Context context; | ||||
| 
 | ||||
|     public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified) { | ||||
|         this.statusList = statuses; | ||||
|  | @ -1818,10 +1818,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public interface FetchMoreCallBack { | ||||
|         void onClick(String min_id, String fetchmoreId); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int getItemCount() { | ||||
|         return statusList.size(); | ||||
|  | @ -1838,6 +1834,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public interface FetchMoreCallBack { | ||||
|         void onClick(String min_id, String fetchmoreId); | ||||
|     } | ||||
| 
 | ||||
|     public static class StatusViewHolder extends RecyclerView.ViewHolder { | ||||
|         DrawerStatusBinding binding; | ||||
|         DrawerStatusHiddenBinding bindingHidden; | ||||
|  |  | |||
|  | @ -28,13 +28,14 @@ import es.dmoral.toasty.Toasty; | |||
| 
 | ||||
| public class FragmentInterfaceSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { | ||||
| 
 | ||||
|     boolean recreate; | ||||
| 
 | ||||
|     @Override | ||||
|     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||||
|         addPreferencesFromResource(R.xml.pref_interface); | ||||
|         createPref(); | ||||
|     } | ||||
| 
 | ||||
|     boolean recreate; | ||||
|     private void createPref() { | ||||
|         getPreferenceScreen().removeAll(); | ||||
|         addPreferencesFromResource(R.xml.pref_interface); | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ package app.fedilab.android.ui.fragment.settings; | |||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static android.app.Activity.RESULT_OK; | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.Manifest; | ||||
| import android.annotation.SuppressLint; | ||||
|  | @ -570,7 +571,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements | |||
|             Uri uri = Uri.parse("file://" + fullPath); | ||||
|             intentOpen.setDataAndType(uri, "text/csv"); | ||||
|             String title = getString(R.string.data_export_theme); | ||||
|             Helper.notify_user(getActivity(), Helper.NOTIFICATION_THEMING, Helper.getCurrentAccount(requireActivity()), intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(), | ||||
|             Helper.notify_user(getActivity(), Helper.NOTIFICATION_THEMING, currentAccount, intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(), | ||||
|                     R.mipmap.ic_launcher), Helper.NotifType.BACKUP, title, message); | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|  |  | |||
|  | @ -60,11 +60,11 @@ import app.fedilab.android.viewmodel.mastodon.NotificationsVM; | |||
| public class FragmentMastodonNotification extends Fragment implements NotificationAdapter.FetchMoreCallBack { | ||||
| 
 | ||||
| 
 | ||||
|     private static final int NOTIFICATION_PRESENT = -1; | ||||
|     private static final int NOTIFICATION__AT_THE_BOTTOM = -2; | ||||
|     private FragmentPaginationBinding binding; | ||||
|     private NotificationsVM notificationsVM; | ||||
|     private boolean flagLoading; | ||||
|     private static final int NOTIFICATION_PRESENT = -1; | ||||
|     private static final int NOTIFICATION__AT_THE_BOTTOM = -2; | ||||
|     private List<Notification> notificationList; | ||||
|     private NotificationAdapter notificationAdapter; | ||||
|     private final BroadcastReceiver receive_action = new BroadcastReceiver() { | ||||
|  | @ -177,7 +177,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati | |||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public void onResume() { | ||||
|         super.onResume(); | ||||
|  | @ -510,6 +509,26 @@ public class FragmentMastodonNotification extends Fragment implements Notificati | |||
|         super.onPause(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onClick(String min_id, String id) { | ||||
|         //Fetch more has been pressed | ||||
|         min_id_fetch_more = min_id; | ||||
|         Notification notification = null; | ||||
|         int position = 0; | ||||
|         for (Notification currentNotification : this.notificationList) { | ||||
|             if (currentNotification.id.compareTo(id) == 0) { | ||||
|                 notification = currentNotification; | ||||
|                 break; | ||||
|             } | ||||
|             position++; | ||||
|         } | ||||
|         if (notification != null) { | ||||
|             this.notificationList.remove(position); | ||||
|             notificationAdapter.notifyItemRemoved(position); | ||||
|         } | ||||
|         route(FragmentMastodonTimeline.DIRECTION.TOP, true); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public enum NotificationTypeEnum { | ||||
|         @SerializedName("ALL") | ||||
|  | @ -537,25 +556,4 @@ public class FragmentMastodonNotification extends Fragment implements Notificati | |||
|             return value; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public void onClick(String min_id, String id) { | ||||
|         //Fetch more has been pressed | ||||
|         min_id_fetch_more = min_id; | ||||
|         Notification notification = null; | ||||
|         int position = 0; | ||||
|         for (Notification currentNotification : this.notificationList) { | ||||
|             if (currentNotification.id.compareTo(id) == 0) { | ||||
|                 notification = currentNotification; | ||||
|                 break; | ||||
|             } | ||||
|             position++; | ||||
|         } | ||||
|         if (notification != null) { | ||||
|             this.notificationList.remove(position); | ||||
|             notificationAdapter.notifyItemRemoved(position); | ||||
|         } | ||||
|         route(FragmentMastodonTimeline.DIRECTION.TOP, true); | ||||
|     } | ||||
| } | ||||
|  | @ -14,6 +14,8 @@ package app.fedilab.android.ui.fragment.timeline; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.os.Bundle; | ||||
| import android.os.Handler; | ||||
| import android.os.Looper; | ||||
|  | @ -80,7 +82,7 @@ public class FragmentScheduled extends Fragment implements StatusScheduledAdapte | |||
|         } else if (type == Timeline.TimeLineEnum.SCHEDULED_TOOT_CLIENT) { | ||||
|             new Thread(() -> { | ||||
|                 try { | ||||
|                     List<StatusDraft> scheduledDrafts = new StatusDraft(requireActivity()).geStatusDraftScheduledList(Helper.getCurrentAccount(requireActivity())); | ||||
|                     List<StatusDraft> scheduledDrafts = new StatusDraft(requireActivity()).geStatusDraftScheduledList(currentAccount); | ||||
|                     Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||
|                     binding.loader.setVisibility(View.GONE); | ||||
|                     Runnable myRunnable = () -> { | ||||
|  | @ -105,7 +107,7 @@ public class FragmentScheduled extends Fragment implements StatusScheduledAdapte | |||
|         } else if (type == Timeline.TimeLineEnum.SCHEDULED_BOOST) { | ||||
|             new Thread(() -> { | ||||
|                 try { | ||||
|                     List<ScheduledBoost> scheduledBoosts = new ScheduledBoost(requireActivity()).getScheduled(Helper.getCurrentAccount(requireActivity())); | ||||
|                     List<ScheduledBoost> scheduledBoosts = new ScheduledBoost(requireActivity()).getScheduled(currentAccount); | ||||
|                     Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||
|                     Runnable myRunnable = () -> { | ||||
|                         binding.loader.setVisibility(View.GONE); | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ package app.fedilab.android.viewmodel.mastodon; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.app.Application; | ||||
| import android.os.Handler; | ||||
| import android.os.Looper; | ||||
|  | @ -68,7 +70,7 @@ public class ReorderVM extends AndroidViewModel { | |||
|         new Thread(() -> { | ||||
|             Pinned pinned = null; | ||||
|             try { | ||||
|                 pinned = new Pinned(getApplication().getApplicationContext()).getAllPinned(Helper.getCurrentAccount(getApplication().getApplicationContext())); | ||||
|                 pinned = new Pinned(getApplication().getApplicationContext()).getAllPinned(currentAccount); | ||||
|             } catch (DBException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|  | @ -86,7 +88,7 @@ public class ReorderVM extends AndroidViewModel { | |||
|         new Thread(() -> { | ||||
|             BottomMenu bottomMenu = null; | ||||
|             try { | ||||
|                 bottomMenu = new BottomMenu(getApplication().getApplicationContext()).getAllBottomMenu(Helper.getCurrentAccount(getApplication().getApplicationContext())); | ||||
|                 bottomMenu = new BottomMenu(getApplication().getApplicationContext()).getAllBottomMenu(currentAccount); | ||||
|             } catch (DBException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ package app.fedilab.android.viewmodel.mastodon; | |||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
| 
 | ||||
| import static app.fedilab.android.BaseMainActivity.currentAccount; | ||||
| 
 | ||||
| import android.app.Application; | ||||
| import android.os.Handler; | ||||
| import android.os.Looper; | ||||
|  | @ -25,7 +27,7 @@ import androidx.lifecycle.MutableLiveData; | |||
| 
 | ||||
| import app.fedilab.android.client.entities.app.Pinned; | ||||
| import app.fedilab.android.exception.DBException; | ||||
| import app.fedilab.android.helper.Helper; | ||||
| 
 | ||||
| 
 | ||||
| public class TopBarVM extends AndroidViewModel { | ||||
| 
 | ||||
|  | @ -42,7 +44,7 @@ public class TopBarVM extends AndroidViewModel { | |||
|             Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||
|             Pinned pinnedTimeline = null; | ||||
|             try { | ||||
|                 pinnedTimeline = pinned.getPinned(Helper.getCurrentAccount(getApplication().getApplicationContext())); | ||||
|                 pinnedTimeline = pinned.getPinned(currentAccount); | ||||
|             } catch (DBException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue