diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index be0682bb..9f6fea70 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -623,11 +623,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt BaseMainActivity.currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } String software = sharedpreferences.getString(PREF_USER_SOFTWARE, null); - if (software != null && software.equalsIgnoreCase("peertube")) { - startActivity(new Intent(this, PeertubeMainActivity.class)); - finish(); - return; - } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { ActivityResultLauncher permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { @@ -649,6 +645,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } catch (DBException e) { e.printStackTrace(); } + if (currentAccount != null && currentAccount.peertube_account != null) { + //It is a peertube user + Intent myIntent = new Intent(this, PeertubeMainActivity.class); + startActivity(myIntent); + finish(); + return; + } //If the attached account is null, the app will fetch remote instance to get up-to-date values if (currentAccount != null && currentAccount.mastodon_account == null && currentAccount.peertube_account == null) { OkHttpClient okHttpClient = new OkHttpClient.Builder() diff --git a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java index 7b5662da..d4423010 100644 --- a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.activities; * see . */ +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; + import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; @@ -70,6 +72,7 @@ public class LoginActivity extends BaseActivity { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.PREF_USER_TOKEN, account.token); + editor.putString(PREF_USER_SOFTWARE, BaseMainActivity.api.name()); editor.commit(); //The user is now authenticated, it will be redirected to MainActivity Runnable myRunnable = () -> { diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index 59d4fe99..16cda221 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -905,7 +905,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_SOFTWARE, null); editor.putString(PREF_USER_ID, null); editor.commit(); Intent loginActivity = new Intent(activity, LoginActivity.class); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java index 3a15b2d7..f6bd26c2 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java @@ -72,6 +72,7 @@ import java.util.regex.Pattern; import app.fedilab.android.BuildConfig; import app.fedilab.android.R; import app.fedilab.android.activities.AboutActivity; +import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.PeertubeBaseMainActivity; import app.fedilab.android.databinding.ActivityMainPeertubeBinding; import app.fedilab.android.databinding.NavHeaderMainBinding; @@ -203,9 +204,16 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { } catch (DBException e) { e.printStackTrace(); } + if (currentAccount != null && currentAccount.mastodon_account != null) { + //It is a Mastodon User + Intent myIntent = new Intent(PeertubeMainActivity.this, MainActivity.class); + startActivity(myIntent); + finish(); + return; + } //If the attached account is null, the app will fetch remote instance to get up-to-date values - if (currentAccount != null && currentAccount.mastodon_account == null && currentAccount.peertube_account == null) { + if (currentAccount != null && currentAccount.peertube_account == null) { try { userMe = new RetrofitPeertubeAPI(PeertubeMainActivity.this, currentInstance, currentToken).verifyCredentials(); currentAccount.peertube_account = userMe.getAccount(); @@ -213,6 +221,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { e.printStackTrace(); } } + Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.peertube_account.getUsername(), currentAccount.instance)); diff --git a/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java b/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java index bcc1b686..caf1b631 100644 --- a/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java @@ -17,6 +17,7 @@ package app.fedilab.android.peertube.helper; import static android.content.Context.DOWNLOAD_SERVICE; 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.dialogStyle; import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection; @@ -575,7 +576,7 @@ public class Helper { editor.putString(CLIENT_SECRET, null); editor.putString(PREF_USER_ID, null); editor.putString(PREF_USER_INSTANCE, null); - // editor.putString(PREF_USER_SOFTWARE, null); + editor.putString(PREF_USER_SOFTWARE, null); editor.apply(); Intent loginActivity = new Intent(activity, PeertubeMainActivity.class); activity.startActivity(loginActivity); diff --git a/src/fdroid/fastlane/metadata/android/en/changelogs/472.txt b/src/fdroid/fastlane/metadata/android/en/changelogs/472.txt new file mode 100644 index 00000000..4d5420e3 --- /dev/null +++ b/src/fdroid/fastlane/metadata/android/en/changelogs/472.txt @@ -0,0 +1,9 @@ +Changed: +- Peertube support + +Changed: +- Cross actions with two accounts display a dialog + +Fixed: + +- Fix crashes \ No newline at end of file