From 5f578c4f8c6b3d890a8f2351b4587388a2198af8 Mon Sep 17 00:00:00 2001 From: A117870935 Date: Wed, 30 Oct 2024 13:14:56 +0530 Subject: [PATCH 1/2] Fix: Launching LauncherActivity & FirstRunActivity Signed-off-by: A117870935 --- .../client/account/UserAccountManagerImpl.java | 8 +++++++- .../client/onboarding/OnboardingServiceImpl.kt | 3 ++- .../java/com/nmc/android/ui/LauncherActivity.kt | 5 ++++- .../authentication/AuthenticatorActivity.java | 7 +++---- .../owncloud/android/ui/activity/BaseActivity.java | 5 ++++- .../client/onboarding/OnboardingServiceTest.kt | 13 +++++++++---- 6 files changed, 29 insertions(+), 12 deletions(-) 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 1554e68e81..01cb329ace 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; @@ -397,6 +399,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 From 75ff52aa16aa1582cad185173258f45c69f6f158 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 5 Nov 2024 08:09:11 +0100 Subject: [PATCH 2/2] remove unused parameter Signed-off-by: tobiasKaminsky --- .../com/owncloud/android/ui/activity/SettingsActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 54eb81f2a7..f37d63634a 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -328,7 +328,7 @@ public class SettingsActivity extends PreferenceActivity viewThemeUtils.files.themePreferenceCategory(preferenceCategorySync); setupAutoUploadPreference(preferenceCategorySync); - setupInternalTwoWaySyncPreference(preferenceCategorySync); + setupInternalTwoWaySyncPreference(); } private void setupMoreCategory() { @@ -567,7 +567,7 @@ public class SettingsActivity extends PreferenceActivity } } - private void setupInternalTwoWaySyncPreference(PreferenceCategory preferenceCategorySync) { + private void setupInternalTwoWaySyncPreference() { Preference twoWaySync = findPreference("internal_two_way_sync"); twoWaySync.setOnPreferenceClickListener(preference -> {