From bb84698b08a3f62328f5e863ff6836dd9a558ddc Mon Sep 17 00:00:00 2001 From: IndusAryan Date: Wed, 3 Apr 2024 18:14:28 +0530 Subject: [PATCH] redirection logic --- .idea/gradle.xml | 4 +- .../lagradost/cloudstream3/MainActivity.kt | 5 +-- .../ui/account/AccountSelectActivity.kt | 3 +- .../ui/settings/SettingsAccount.kt | 4 +- .../settings/extensions/ExtensionsFragment.kt | 4 +- .../ui/setup/SetupFragmentExtensions.kt | 2 - .../lagradost/cloudstream3/utils/AppUtils.kt | 39 ++++++++++++++----- .../utils/BiometricAuthenticator.kt | 10 ++--- .../main/res/navigation/mobile_navigation.xml | 20 ++++++++++ app/src/main/res/values/strings.xml | 10 +++-- 10 files changed, 71 insertions(+), 30 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index c5c0ff3b..cb865f69 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,9 +4,6 @@ diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 7baac71c..1f3baa8a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -134,7 +134,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.BackupUtils.backup import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup -import com.lagradost.cloudstream3.utils.BiometricAuthenticator +import com.lagradost.cloudstream3.utils.BiometricAuthenticator.BiometricCallback import com.lagradost.cloudstream3.utils.BiometricAuthenticator.biometricPrompt import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock import com.lagradost.cloudstream3.utils.BiometricAuthenticator.isAuthEnabled @@ -294,8 +294,7 @@ var app = Requests(responseParser = object : ResponseParser { defaultHeaders = mapOf("user-agent" to USER_AGENT) } -class MainActivity : AppCompatActivity(), ColorPickerDialogListener, - BiometricAuthenticator.BiometricAuthCallback { +class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCallback { companion object { const val TAG = "MAINACT" const val ANIMATED_OUTLINE: Boolean = false diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt index 0b0d83db..0da69f9c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt @@ -23,6 +23,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.PHONE import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.utils.BiometricAuthenticator +import com.lagradost.cloudstream3.utils.BiometricAuthenticator.BiometricCallback import com.lagradost.cloudstream3.utils.BiometricAuthenticator.biometricPrompt import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock import com.lagradost.cloudstream3.utils.BiometricAuthenticator.isAuthEnabled @@ -33,7 +34,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.selectedKeyIndex import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute -class AccountSelectActivity : AppCompatActivity(), BiometricAuthenticator.BiometricAuthCallback { +class AccountSelectActivity : AppCompatActivity(), BiometricCallback { lateinit var viewModel: AccountViewModel diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt index f0d402da..4e597c21 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt @@ -40,7 +40,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setTool import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.utils.AppUtils.html import com.lagradost.cloudstream3.utils.BackupUtils -import com.lagradost.cloudstream3.utils.BiometricAuthenticator +import com.lagradost.cloudstream3.utils.BiometricAuthenticator.BiometricCallback import com.lagradost.cloudstream3.utils.BiometricAuthenticator.authCallback import com.lagradost.cloudstream3.utils.BiometricAuthenticator.biometricPrompt import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock @@ -53,7 +53,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.setImage -class SettingsAccount : PreferenceFragmentCompat(), BiometricAuthenticator.BiometricAuthCallback { +class SettingsAccount : PreferenceFragmentCompat(), BiometricCallback { companion object { /** Used by nginx plugin too */ fun showLoginInfo( diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt index f2f8bb11..0cfe1236 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt @@ -273,7 +273,9 @@ class ExtensionsFragment : Fragment() { if (plugins.isNullOrEmpty()) { showToast(R.string.no_plugins_found_error, Toast.LENGTH_LONG) } else { - this@ExtensionsFragment.activity?.addRepositoryDialog(fixedName) + this@ExtensionsFragment.activity?.addRepositoryDialog( + fixedName, true + ) } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt index 4369b22f..f91da6d0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt @@ -123,6 +123,4 @@ class SetupFragmentExtensions : Fragment() { } } } - - } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt index a5fe158d..da3604ad 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt @@ -62,6 +62,9 @@ import com.lagradost.cloudstream3.syncproviders.providers.Kitsu import com.lagradost.cloudstream3.ui.WebviewFragment import com.lagradost.cloudstream3.ui.result.ResultFragment import com.lagradost.cloudstream3.ui.settings.Globals +import com.lagradost.cloudstream3.ui.settings.SettingsFragment +import com.lagradost.cloudstream3.ui.settings.extensions.ExtensionsFragment +import com.lagradost.cloudstream3.ui.settings.extensions.PluginsFragment import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.main @@ -385,7 +388,7 @@ object AppUtils { ) } afterRepositoryLoadedEvent.invoke(true) - addRepositoryDialog(repo.name) + addRepositoryDialog(repo.name, false) } } @@ -428,18 +431,36 @@ object AppUtils { } } - fun Activity.addRepositoryDialog(repositoryName: String) { + fun Activity.addRepositoryDialog(repositoryName: String, isExtensionsFragment: Boolean) { val message = String.format(resources.getString( R.string.download_all_plugins_from_repo), repositoryName) + val repos = RepositoryManager.getRepositories() + + // navigate to newly added repository on pressing OK + fun openAddedRepo() { + // don't redirect if user is adding from add repo button + if (!isExtensionsFragment && repos.isNotEmpty()) { + normalSafeApiCall { navigate( + R.id.navigation_home_to_navigation_settings_plugins, + PluginsFragment.newInstance( + repositoryName, + repos.last().url, + false)) + } + } + } runOnUiThread { - val builder: AlertDialog.Builder = AlertDialog.Builder(this) - - builder.setTitle(repositoryName) - builder.setMessage(message) - builder.setPositiveButton(R.string.ok, null) - builder.setCancelable(false) - builder.show().setDefaultFocus() + val builder : AlertDialog.Builder = AlertDialog.Builder(this) + builder.apply { + setTitle(repositoryName) + setMessage(message) + setPositiveButton(R.string.ok) { _, _ -> + openAddedRepo() + } + setCancelable(false) + show().setDefaultFocus() + } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BiometricAuthenticator.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BiometricAuthenticator.kt index c57600ee..45acbab4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BiometricAuthenticator.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BiometricAuthenticator.kt @@ -26,7 +26,7 @@ object BiometricAuthenticator { private var biometricManager: BiometricManager? = null var biometricPrompt: BiometricPrompt? = null var promptInfo: BiometricPrompt.PromptInfo? = null - var authCallback: BiometricAuthCallback? = null // listen to authentication success + var authCallback: BiometricCallback? = null // listen to authentication success private fun initializeBiometrics(activity: Activity) { val executor = ContextCompat.getMainExecutor(activity) @@ -141,14 +141,14 @@ object BiometricAuthenticator { // function to start authentication in any fragment or activity fun startBiometricAuthentication(activity: Activity, title: Int, setDeviceCred: Boolean) { initializeBiometrics(activity) - authCallback = activity as? BiometricAuthCallback + authCallback = activity as? BiometricCallback if (isBiometricHardWareAvailable()) { - authCallback = activity as? BiometricAuthCallback + authCallback = activity as? BiometricCallback authenticationDialog(activity, title, setDeviceCred) promptInfo?.let { biometricPrompt?.authenticate(it) } } else { if (deviceHasPasswordPinLock(activity)) { - authCallback = activity as? BiometricAuthCallback + authCallback = activity as? BiometricCallback authenticationDialog(activity, R.string.password_pin_authentication_title, true) promptInfo?.let { biometricPrompt?.authenticate(it) } @@ -165,7 +165,7 @@ object BiometricAuthenticator { } } - interface BiometricAuthCallback { + interface BiometricCallback { fun onAuthenticationSuccess() fun onAuthenticationError() } diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index d0df339b..40d443af 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -273,6 +273,26 @@ app:exitAnim="@anim/exit_anim" app:popEnterAnim="@anim/enter_anim" app:popExitAnim="@anim/exit_anim" /> + + + + + Livestreams NSFW Others + Movie Series @@ -348,6 +349,9 @@ Livestream NSFW Video + Music + Audio Book + Media Source error Remote error Renderer error @@ -763,9 +767,7 @@ Password/PIN Authentication Biometric authentication is not supported on this device Unlock the app with Fingerprint, Face ID, PIN, Pattern and Password. - This screen was closed due to multiple failed attempts. Please restart the application. + After a few failed attempts, the prompt will close. Simply restart the app to try again. Your CloudStream data has been backed up now. Although the possibility of this is very low, all devices can behave differently. In the rare case, that you get locked out from accessing the app, clear the app data completely and restore from a backup. We are very sorry for any inconvenience arising from this. - Music - Audio Book - Media +