Loading app/src/main/AndroidManifest.xml +3 −1 Original line number Diff line number Diff line Loading @@ -358,7 +358,9 @@ <activity android:name=".peertube.activities.PeertubeMainActivity" android:configChanges="keyboardHidden|orientation|screenSize" /> <activity android:name=".peertube.activities.PeertubeMainActivity" android:configChanges="keyboardHidden|orientation|screenSize" /> <activity android:name=".peertube.activities.PeertubeActivity" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" Loading app/src/main/java/app/fedilab/android/BaseMainActivity.java +67 −22 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package app.fedilab.android; import static app.fedilab.android.BaseMainActivity.status.DISCONNECTED; import static app.fedilab.android.BaseMainActivity.status.UNKNOWN; import static app.fedilab.android.mastodon.helper.CacheHelper.deleteDir; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.mastodon.helper.Helper.TAG; import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded; Loading Loading @@ -108,7 +109,6 @@ import java.util.regex.Pattern; import app.fedilab.android.activities.AboutActivity; import app.fedilab.android.activities.LoginActivity; import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.PeertubeBaseMainActivity; import app.fedilab.android.databinding.ActivityMainBinding; import app.fedilab.android.databinding.NavHeaderMainBinding; import app.fedilab.android.mastodon.activities.ActionActivity; Loading Loading @@ -170,6 +170,7 @@ import app.fedilab.android.mastodon.viewmodel.mastodon.InstancesVM; import app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM; import app.fedilab.android.mastodon.viewmodel.mastodon.TimelinesVM; import app.fedilab.android.mastodon.viewmodel.mastodon.TopBarVM; import app.fedilab.android.peertube.activities.PeertubeMainActivity; import es.dmoral.toasty.Toasty; import okhttp3.Call; import okhttp3.Callback; Loading Loading @@ -328,6 +329,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } else { BaseMainActivity.currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } String software = sharedpreferences.getString(PREF_USER_SOFTWARE, null); Log.v(TAG, "software: " + software); if (software != null && software.equalsIgnoreCase("peertube")) { startActivity(new Intent(this, PeertubeMainActivity.class)); finish(); return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { ActivityResultLauncher<String> permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { Loading @@ -346,17 +354,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } currentAccount = new Account(BaseMainActivity.this).getConnectedAccount(); Log.v(TAG, "currentToken! " + currentToken); Log.v(TAG, "currentAccount! " + currentAccount); if (currentAccount != null && currentAccount.api == Account.API.PEERTUBE) { startActivity(new Intent(this, PeertubeBaseMainActivity.class)); finish(); } } catch (DBException e) { e.printStackTrace(); } //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 (currentAccount != null && currentAccount.mastodon_account == null && currentAccount.peertube_account == null) { OkHttpClient okHttpClient = new OkHttpClient.Builder() .readTimeout(60, TimeUnit.SECONDS) .connectTimeout(60, TimeUnit.SECONDS) Loading @@ -383,11 +385,22 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { if (currentAccount == null || currentAccount.mastodon_account == null) { if (currentAccount == null || (currentAccount.mastodon_account == null && currentAccount.peertube_account == null)) { //It is not, the user is redirected to the login page if (currentAccount != null) { try { Helper.removeAccount(BaseMainActivity.this); } catch (DBException e) { Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); startActivity(myIntent); finish(); e.printStackTrace(); } } else { Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); startActivity(myIntent); finish(); } return; } bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView); Loading Loading @@ -654,13 +667,25 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (currentSubmenu == null) { continue; } final MenuItem item = currentSubmenu.add("@" + account.mastodon_account.acct); item.setIcon(R.drawable.ic_person); String acct = ""; String url = ""; boolean disableGif = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_GIF), false); String url = !disableGif ? account.mastodon_account.avatar : account.mastodon_account.avatar_static; if (account.mastodon_account != null) { acct = account.mastodon_account.acct; url = !disableGif ? account.mastodon_account.avatar : account.mastodon_account.avatar_static; if (url != null && url.startsWith("/")) { url = "https://" + account.instance + account.mastodon_account.avatar; } } else if (account.peertube_account != null) { acct = account.peertube_account.getAcct(); url = account.peertube_account.getAvatar().getPath(); if (url != null && url.startsWith("/")) { url = "https://" + account.instance + account.peertube_account.getAvatar().getPath(); } } final MenuItem item = currentSubmenu.add("@" + acct); item.setIcon(R.drawable.ic_person); if (!this.isDestroyed() && !this.isFinishing() && url != null) { if (url.contains(".gif")) { Glide.with(BaseMainActivity.this) Loading Loading @@ -706,6 +731,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt api = account.api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 2: " + account.software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity Loading Loading @@ -908,10 +935,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt e.printStackTrace(); } } if (currentAccount != null) { MutedAccounts mutedAccounts = new MutedAccounts(BaseMainActivity.this).getMutedAccount(currentAccount); if (mutedAccounts != null && mutedAccounts.accounts != null) { filteredAccounts = mutedAccounts.accounts; } } //Delete cache older than 7 days new StatusCache(BaseMainActivity.this).deleteForAllAccountAfter7Days(); } catch (DBException e) { Loading @@ -930,12 +959,19 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.otherAccount1.setVisibility(View.VISIBLE); headerMainBinding.otherAccount1.setOnClickListener(v -> { headerMenuOpen = false; Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + accounts.get(0).mastodon_account.acct + "@" + accounts.get(0).instance), Toasty.LENGTH_LONG).show(); String account = ""; if (accounts.get(0).mastodon_account != null) { account = "@" + accounts.get(0).mastodon_account.acct + "@" + accounts.get(0).instance; } else if (accounts.get(0).peertube_account != null) { account = "@" + accounts.get(0).peertube_account.getAcct() + "@" + accounts.get(0).instance; } Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); BaseMainActivity.currentToken = accounts.get(0).token; BaseMainActivity.currentUserID = accounts.get(0).user_id; api = accounts.get(0).api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, accounts.get(0).token); editor.putString(PREF_USER_SOFTWARE, accounts.get(0).software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity Loading @@ -948,12 +984,19 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.otherAccount2.setVisibility(View.VISIBLE); headerMainBinding.otherAccount2.setOnClickListener(v -> { headerMenuOpen = false; Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + accounts.get(1).mastodon_account.acct + "@" + accounts.get(1).instance), Toasty.LENGTH_LONG).show(); String account = ""; if (accounts.get(1).mastodon_account != null) { account = "@" + accounts.get(1).mastodon_account.acct + "@" + accounts.get(1).instance; } else if (accounts.get(1).peertube_account != null) { account = "@" + accounts.get(1).peertube_account.getAcct() + "@" + accounts.get(1).instance; } Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); BaseMainActivity.currentToken = accounts.get(1).token; BaseMainActivity.currentUserID = accounts.get(1).user_id; api = accounts.get(1).api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, accounts.get(1).token); editor.putString(PREF_USER_SOFTWARE, accounts.get(1).software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity Loading Loading @@ -1034,6 +1077,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt api = account.api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 3: " + account.software); editor.commit(); Intent mainActivity = new Intent(this, MainActivity.class); mainActivity.putExtra(Helper.INTENT_ACTION, Helper.OPEN_NOTIFICATION); Loading app/src/main/java/app/fedilab/android/mastodon/client/entities/app/Account.java +8 −1 Original line number Diff line number Diff line Loading @@ -526,12 +526,19 @@ public class Account extends BaseAccount implements Serializable { case "PLEROMA": api = API.PLEROMA; break; case "PEERTUBE": api = API.PEERTUBE; break; default: api = API.UNKNOWN; break; } account.api = api; if (api != API.PEERTUBE) { account.mastodon_account = restoreAccountFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ACCOUNT))); } else { account.peertube_account = restorePeertubeAccountFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ACCOUNT))); } return account; } Loading app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +15 −1 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import android.provider.MediaStore; import android.provider.OpenableColumns; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; Loading Loading @@ -298,6 +299,7 @@ public class Helper { public static final String PREF_USER_TOKEN = "PREF_USER_TOKEN"; public static final String PREF_USER_ID = "PREF_USER_ID"; public static final String PREF_USER_INSTANCE = "PREF_USER_INSTANCE"; public static final String PREF_USER_SOFTWARE = "PREF_USER_SOFTWARE"; public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR"; public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR"; public static final String PREF_MESSAGE_URL = "PREF_MESSAGE_URL"; Loading Loading @@ -922,6 +924,7 @@ public class Helper { if (newAccount == null) { editor.putString(PREF_USER_TOKEN, null); editor.putString(PREF_USER_INSTANCE, null); // editor.putString(PREF_USER_SOFTWARE, null); editor.putString(PREF_USER_ID, null); editor.commit(); Intent loginActivity = new Intent(activity, LoginActivity.class); Loading @@ -930,6 +933,8 @@ public class Helper { } else { currentAccount = newAccount; editor.putString(PREF_USER_TOKEN, newAccount.token); editor.putString(PREF_USER_SOFTWARE, newAccount.software); Log.v(TAG, "put 4: " + newAccount.software); editor.putString(PREF_USER_INSTANCE, newAccount.instance); editor.putString(PREF_USER_ID, newAccount.user_id); BaseMainActivity.currentUserID = newAccount.user_id; Loading Loading @@ -1073,7 +1078,16 @@ public class Helper { public static void loadPP(Activity activity, ImageView view, BaseAccount account, boolean crop) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); boolean disableGif = sharedpreferences.getBoolean(activity.getString(R.string.SET_DISABLE_GIF), false); String targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; String targetedUrl = ""; if (account.mastodon_account != null) { targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; } else if (account.peertube_account != null) { targetedUrl = account.peertube_account.getAvatar().getPath(); if (targetedUrl != null && targetedUrl.startsWith("/")) { targetedUrl = "https://" + account.instance + account.peertube_account.getAvatar().getPath(); } } if (targetedUrl != null && Helper.isValidContextForGlide(activity)) { if (disableGif || (!targetedUrl.endsWith(".gif"))) { try { Loading app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +7 −0 Original line number Diff line number Diff line Loading @@ -28,7 +28,9 @@ import static app.fedilab.android.mastodon.activities.ContextActivity.expand; import static app.fedilab.android.mastodon.helper.Helper.ARG_TIMELINE_REFRESH_ALL; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.mastodon.helper.Helper.TAG; import android.annotation.SuppressLint; import android.app.Activity; Loading @@ -49,6 +51,7 @@ import android.os.Looper; import android.text.Html; import android.text.SpannableString; import android.text.TextUtils; import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; Loading Loading @@ -1995,6 +1998,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> currentAccount = account; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 5: " + account.software); editor.putString(PREF_USER_INSTANCE, account.instance); editor.putString(PREF_USER_ID, account.user_id); editor.commit(); Loading @@ -2020,6 +2025,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> currentAccount = account; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 6: " + account.software); editor.putString(PREF_USER_INSTANCE, account.instance); editor.putString(PREF_USER_ID, account.user_id); editor.commit(); Loading Loading
app/src/main/AndroidManifest.xml +3 −1 Original line number Diff line number Diff line Loading @@ -358,7 +358,9 @@ <activity android:name=".peertube.activities.PeertubeMainActivity" android:configChanges="keyboardHidden|orientation|screenSize" /> <activity android:name=".peertube.activities.PeertubeMainActivity" android:configChanges="keyboardHidden|orientation|screenSize" /> <activity android:name=".peertube.activities.PeertubeActivity" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" Loading
app/src/main/java/app/fedilab/android/BaseMainActivity.java +67 −22 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package app.fedilab.android; import static app.fedilab.android.BaseMainActivity.status.DISCONNECTED; import static app.fedilab.android.BaseMainActivity.status.UNKNOWN; import static app.fedilab.android.mastodon.helper.CacheHelper.deleteDir; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.mastodon.helper.Helper.TAG; import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded; Loading Loading @@ -108,7 +109,6 @@ import java.util.regex.Pattern; import app.fedilab.android.activities.AboutActivity; import app.fedilab.android.activities.LoginActivity; import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.PeertubeBaseMainActivity; import app.fedilab.android.databinding.ActivityMainBinding; import app.fedilab.android.databinding.NavHeaderMainBinding; import app.fedilab.android.mastodon.activities.ActionActivity; Loading Loading @@ -170,6 +170,7 @@ import app.fedilab.android.mastodon.viewmodel.mastodon.InstancesVM; import app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM; import app.fedilab.android.mastodon.viewmodel.mastodon.TimelinesVM; import app.fedilab.android.mastodon.viewmodel.mastodon.TopBarVM; import app.fedilab.android.peertube.activities.PeertubeMainActivity; import es.dmoral.toasty.Toasty; import okhttp3.Call; import okhttp3.Callback; Loading Loading @@ -328,6 +329,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } else { BaseMainActivity.currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } String software = sharedpreferences.getString(PREF_USER_SOFTWARE, null); Log.v(TAG, "software: " + software); if (software != null && software.equalsIgnoreCase("peertube")) { startActivity(new Intent(this, PeertubeMainActivity.class)); finish(); return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { ActivityResultLauncher<String> permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { Loading @@ -346,17 +354,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } currentAccount = new Account(BaseMainActivity.this).getConnectedAccount(); Log.v(TAG, "currentToken! " + currentToken); Log.v(TAG, "currentAccount! " + currentAccount); if (currentAccount != null && currentAccount.api == Account.API.PEERTUBE) { startActivity(new Intent(this, PeertubeBaseMainActivity.class)); finish(); } } catch (DBException e) { e.printStackTrace(); } //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 (currentAccount != null && currentAccount.mastodon_account == null && currentAccount.peertube_account == null) { OkHttpClient okHttpClient = new OkHttpClient.Builder() .readTimeout(60, TimeUnit.SECONDS) .connectTimeout(60, TimeUnit.SECONDS) Loading @@ -383,11 +385,22 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { if (currentAccount == null || currentAccount.mastodon_account == null) { if (currentAccount == null || (currentAccount.mastodon_account == null && currentAccount.peertube_account == null)) { //It is not, the user is redirected to the login page if (currentAccount != null) { try { Helper.removeAccount(BaseMainActivity.this); } catch (DBException e) { Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); startActivity(myIntent); finish(); e.printStackTrace(); } } else { Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); startActivity(myIntent); finish(); } return; } bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView); Loading Loading @@ -654,13 +667,25 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (currentSubmenu == null) { continue; } final MenuItem item = currentSubmenu.add("@" + account.mastodon_account.acct); item.setIcon(R.drawable.ic_person); String acct = ""; String url = ""; boolean disableGif = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_GIF), false); String url = !disableGif ? account.mastodon_account.avatar : account.mastodon_account.avatar_static; if (account.mastodon_account != null) { acct = account.mastodon_account.acct; url = !disableGif ? account.mastodon_account.avatar : account.mastodon_account.avatar_static; if (url != null && url.startsWith("/")) { url = "https://" + account.instance + account.mastodon_account.avatar; } } else if (account.peertube_account != null) { acct = account.peertube_account.getAcct(); url = account.peertube_account.getAvatar().getPath(); if (url != null && url.startsWith("/")) { url = "https://" + account.instance + account.peertube_account.getAvatar().getPath(); } } final MenuItem item = currentSubmenu.add("@" + acct); item.setIcon(R.drawable.ic_person); if (!this.isDestroyed() && !this.isFinishing() && url != null) { if (url.contains(".gif")) { Glide.with(BaseMainActivity.this) Loading Loading @@ -706,6 +731,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt api = account.api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 2: " + account.software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity Loading Loading @@ -908,10 +935,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt e.printStackTrace(); } } if (currentAccount != null) { MutedAccounts mutedAccounts = new MutedAccounts(BaseMainActivity.this).getMutedAccount(currentAccount); if (mutedAccounts != null && mutedAccounts.accounts != null) { filteredAccounts = mutedAccounts.accounts; } } //Delete cache older than 7 days new StatusCache(BaseMainActivity.this).deleteForAllAccountAfter7Days(); } catch (DBException e) { Loading @@ -930,12 +959,19 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.otherAccount1.setVisibility(View.VISIBLE); headerMainBinding.otherAccount1.setOnClickListener(v -> { headerMenuOpen = false; Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + accounts.get(0).mastodon_account.acct + "@" + accounts.get(0).instance), Toasty.LENGTH_LONG).show(); String account = ""; if (accounts.get(0).mastodon_account != null) { account = "@" + accounts.get(0).mastodon_account.acct + "@" + accounts.get(0).instance; } else if (accounts.get(0).peertube_account != null) { account = "@" + accounts.get(0).peertube_account.getAcct() + "@" + accounts.get(0).instance; } Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); BaseMainActivity.currentToken = accounts.get(0).token; BaseMainActivity.currentUserID = accounts.get(0).user_id; api = accounts.get(0).api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, accounts.get(0).token); editor.putString(PREF_USER_SOFTWARE, accounts.get(0).software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity Loading @@ -948,12 +984,19 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.otherAccount2.setVisibility(View.VISIBLE); headerMainBinding.otherAccount2.setOnClickListener(v -> { headerMenuOpen = false; Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + accounts.get(1).mastodon_account.acct + "@" + accounts.get(1).instance), Toasty.LENGTH_LONG).show(); String account = ""; if (accounts.get(1).mastodon_account != null) { account = "@" + accounts.get(1).mastodon_account.acct + "@" + accounts.get(1).instance; } else if (accounts.get(1).peertube_account != null) { account = "@" + accounts.get(1).peertube_account.getAcct() + "@" + accounts.get(1).instance; } Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); BaseMainActivity.currentToken = accounts.get(1).token; BaseMainActivity.currentUserID = accounts.get(1).user_id; api = accounts.get(1).api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, accounts.get(1).token); editor.putString(PREF_USER_SOFTWARE, accounts.get(1).software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity Loading Loading @@ -1034,6 +1077,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt api = account.api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 3: " + account.software); editor.commit(); Intent mainActivity = new Intent(this, MainActivity.class); mainActivity.putExtra(Helper.INTENT_ACTION, Helper.OPEN_NOTIFICATION); Loading
app/src/main/java/app/fedilab/android/mastodon/client/entities/app/Account.java +8 −1 Original line number Diff line number Diff line Loading @@ -526,12 +526,19 @@ public class Account extends BaseAccount implements Serializable { case "PLEROMA": api = API.PLEROMA; break; case "PEERTUBE": api = API.PEERTUBE; break; default: api = API.UNKNOWN; break; } account.api = api; if (api != API.PEERTUBE) { account.mastodon_account = restoreAccountFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ACCOUNT))); } else { account.peertube_account = restorePeertubeAccountFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ACCOUNT))); } return account; } Loading
app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +15 −1 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import android.provider.MediaStore; import android.provider.OpenableColumns; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; Loading Loading @@ -298,6 +299,7 @@ public class Helper { public static final String PREF_USER_TOKEN = "PREF_USER_TOKEN"; public static final String PREF_USER_ID = "PREF_USER_ID"; public static final String PREF_USER_INSTANCE = "PREF_USER_INSTANCE"; public static final String PREF_USER_SOFTWARE = "PREF_USER_SOFTWARE"; public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR"; public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR"; public static final String PREF_MESSAGE_URL = "PREF_MESSAGE_URL"; Loading Loading @@ -922,6 +924,7 @@ public class Helper { if (newAccount == null) { editor.putString(PREF_USER_TOKEN, null); editor.putString(PREF_USER_INSTANCE, null); // editor.putString(PREF_USER_SOFTWARE, null); editor.putString(PREF_USER_ID, null); editor.commit(); Intent loginActivity = new Intent(activity, LoginActivity.class); Loading @@ -930,6 +933,8 @@ public class Helper { } else { currentAccount = newAccount; editor.putString(PREF_USER_TOKEN, newAccount.token); editor.putString(PREF_USER_SOFTWARE, newAccount.software); Log.v(TAG, "put 4: " + newAccount.software); editor.putString(PREF_USER_INSTANCE, newAccount.instance); editor.putString(PREF_USER_ID, newAccount.user_id); BaseMainActivity.currentUserID = newAccount.user_id; Loading Loading @@ -1073,7 +1078,16 @@ public class Helper { public static void loadPP(Activity activity, ImageView view, BaseAccount account, boolean crop) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); boolean disableGif = sharedpreferences.getBoolean(activity.getString(R.string.SET_DISABLE_GIF), false); String targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; String targetedUrl = ""; if (account.mastodon_account != null) { targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; } else if (account.peertube_account != null) { targetedUrl = account.peertube_account.getAvatar().getPath(); if (targetedUrl != null && targetedUrl.startsWith("/")) { targetedUrl = "https://" + account.instance + account.peertube_account.getAvatar().getPath(); } } if (targetedUrl != null && Helper.isValidContextForGlide(activity)) { if (disableGif || (!targetedUrl.endsWith(".gif"))) { try { Loading
app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +7 −0 Original line number Diff line number Diff line Loading @@ -28,7 +28,9 @@ import static app.fedilab.android.mastodon.activities.ContextActivity.expand; import static app.fedilab.android.mastodon.helper.Helper.ARG_TIMELINE_REFRESH_ALL; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.mastodon.helper.Helper.TAG; import android.annotation.SuppressLint; import android.app.Activity; Loading @@ -49,6 +51,7 @@ import android.os.Looper; import android.text.Html; import android.text.SpannableString; import android.text.TextUtils; import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; Loading Loading @@ -1995,6 +1998,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> currentAccount = account; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 5: " + account.software); editor.putString(PREF_USER_INSTANCE, account.instance); editor.putString(PREF_USER_ID, account.user_id); editor.commit(); Loading @@ -2020,6 +2025,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> currentAccount = account; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); editor.putString(PREF_USER_SOFTWARE, account.software); Log.v(TAG, "put 6: " + account.software); editor.putString(PREF_USER_INSTANCE, account.instance); editor.putString(PREF_USER_ID, account.user_id); editor.commit(); Loading