diff --git a/app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java b/app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java index 13f636f150..943fa2fa9e 100644 --- a/app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java +++ b/app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java @@ -1,7 +1,7 @@ /* * Nextcloud - Android Client * - * SPDX-FileCopyrightText: 2023 TSI-mc + * SPDX-FileCopyrightText: 2023-2024 TSI-mc * SPDX-FileCopyrightText: 2019 Chris Narkiewicz * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only */ @@ -19,8 +19,10 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.text.TextUtils; +import com.nextcloud.client.onboarding.FirstRunActivity; import com.nextcloud.common.NextcloudClient; import com.nextcloud.utils.extensions.AccountExtensionsKt; +import com.nmc.android.ui.LauncherActivity; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AuthenticatorActivity; @@ -398,6 +400,10 @@ public class UserAccountManagerImpl implements UserAccountManager { @Override public void startAccountCreation(final Activity activity) { + + // skipping AuthenticatorActivity redirection when user is on Launcher or FirstRun Activity + if (activity instanceof LauncherActivity || activity instanceof FirstRunActivity) return; + Intent intent = new Intent(context, AuthenticatorActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt index 10dc0d8f5c..95b9b677f7 100644 --- a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt +++ b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt @@ -2,6 +2,7 @@ * Nextcloud - Android Client * * SPDX-FileCopyrightText: 2019 Chris Narkiewicz + * SPDX-FileCopyrightText: 2024 TSI-mc * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only */ package com.nextcloud.client.onboarding @@ -42,7 +43,7 @@ internal class OnboardingServiceImpl constructor( override val isFirstRun: Boolean get() { - return accountProvider.currentAccount == null + return accountProvider.user.isAnonymous } override fun shouldShowWhatsNew(callingContext: Context): Boolean { diff --git a/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt b/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt index b4c1272a76..b3858c03d1 100644 --- a/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt +++ b/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt @@ -3,7 +3,7 @@ * * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-FileCopyrightText: 2023 Andy Scherzinger - * SPDX-FileCopyrightText: 2023 TSI-mc + * SPDX-FileCopyrightText: 2023-2024 TSI-mc * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only */ package com.nmc.android.ui @@ -18,6 +18,7 @@ import androidx.annotation.VisibleForTesting import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import com.nextcloud.client.preferences.AppPreferences import com.owncloud.android.R +import com.owncloud.android.authentication.AuthenticatorActivity import com.owncloud.android.databinding.ActivitySplashBinding import com.owncloud.android.ui.activity.BaseActivity import com.owncloud.android.ui.activity.FileDisplayActivity @@ -65,6 +66,8 @@ class LauncherActivity : BaseActivity() { Handler(Looper.getMainLooper()).postDelayed({ if (user.isPresent) { startActivity(Intent(this, FileDisplayActivity::class.java)) + } else { + startActivity(Intent(this, AuthenticatorActivity::class.java)) } finish() }, SPLASH_DURATION) diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index f68fb8e34e..2d127b3f03 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -1,7 +1,7 @@ /* * Nextcloud - Android Client * - * SPDX-FileCopyrightText: 2023 TSI-mc + * SPDX-FileCopyrightText: 2023-2024 TSI-mc * SPDX-FileCopyrightText: 2019-2021 Tobias Kaminsky * SPDX-FileCopyrightText: 2018 Andy Scherzinger * SPDX-FileCopyrightText: 2017 Mario Danic @@ -1364,14 +1364,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } private void endSuccess() { - if (onlyAdd) { - finish(); - } else { + if (!onlyAdd) { Intent i = new Intent(this, FileDisplayActivity.class); i.setAction(FileDisplayActivity.RESTART); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } + finish(); } private void getUserCapabilitiesAndFinish() { diff --git a/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java index 05ed0a9891..d154b2dccf 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java @@ -2,6 +2,7 @@ * Nextcloud - Android Client * * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2024 TSI-mc * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only */ package com.owncloud.android.ui.activity; @@ -115,7 +116,9 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab protected void onRestart() { Log_OC.v(TAG, "onRestart() start"); super.onRestart(); - mixinRegistry.onRestart(); + if (enableAccountHandling) { + mixinRegistry.onRestart(); + } } private void onThemeSettingsModeChanged() { diff --git a/app/src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt b/app/src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt index d03550b69a..de304f64c9 100644 --- a/app/src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt +++ b/app/src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt @@ -2,13 +2,15 @@ * Nextcloud - Android Client * * SPDX-FileCopyrightText: 2019 Chris Narkiewicz + * SPDX-FileCopyrightText: 2024 TSI-mc * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only */ package com.nextcloud.client.onboarding -import android.accounts.Account import android.content.res.Resources +import com.nextcloud.client.account.AnonymousUser import com.nextcloud.client.account.CurrentAccountProvider +import com.nextcloud.client.account.User import com.nextcloud.client.preferences.AppPreferences import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue @@ -30,7 +32,7 @@ class OnboardingServiceTest { private lateinit var currentAccountProvider: CurrentAccountProvider @Mock - private lateinit var account: Account + private lateinit var user: User private lateinit var onboardingService: OnboardingServiceImpl @@ -43,13 +45,16 @@ class OnboardingServiceTest { @Test fun `first run flag toggles with current current account`() { // GIVEN - // current account is not set + // current account is anonymous + whenever(currentAccountProvider.user).thenReturn(AnonymousUser("dummy")) + + // THEN // first run flag is true assertTrue(onboardingService.isFirstRun) // WHEN // current account is set - whenever(currentAccountProvider.currentAccount).thenReturn(account) + whenever(currentAccountProvider.user).thenReturn(user) // THEN // first run flag toggles