redirection logic

This commit is contained in:
IndusAryan 2024-04-03 18:14:28 +05:30
parent cb5fb03aa5
commit bb84698b08
10 changed files with 71 additions and 30 deletions

4
.idea/gradle.xml generated
View file

@ -4,9 +4,6 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">
@ -15,6 +12,7 @@
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveExternalAnnotations" value="false" />
</GradleProjectSettings>
</option>
</component>

View file

@ -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

View file

@ -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

View file

@ -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(

View file

@ -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
)
}
}
}

View file

@ -123,6 +123,4 @@ class SetupFragmentExtensions : Fragment() {
}
}
}
}

View file

@ -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()
}
}
}

View file

@ -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()
}

View file

@ -273,6 +273,26 @@
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim" />
<action
android:id="@+id/navigation_home_to_navigation_settings_plugins"
app:destination="@id/navigation_settings_plugins"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim">
<argument
android:name="name"
android:defaultValue="@null"
app:argType="string" />
<argument
android:name="url"
android:defaultValue="@null"
app:argType="string" />
<argument
android:name="isLocal"
android:defaultValue="false"
app:argType="boolean" />
</action>
</fragment>
<fragment

View file

@ -336,6 +336,7 @@
<string name="livestreams">Livestreams</string>
<string name="nsfw">NSFW</string>
<string name="others">Others</string>
<!--singular-->
<string name="movies_singular">Movie</string>
<string name="tv_series_singular">Series</string>
@ -348,6 +349,9 @@
<string name="live_singular">Livestream</string>
<string name="nsfw_singular">NSFW</string>
<string name="other_singular">Video</string>
<string name="music_singlar">Music</string>
<string name="audio_book_singular">Audio Book</string>
<string name="custom_media_singluar">Media</string>
<string name="source_error">Source error</string>
<string name="remote_error">Remote error</string>
<string name="render_error">Renderer error</string>
@ -763,9 +767,7 @@
<string name="password_pin_authentication_title">Password/PIN Authentication</string>
<string name="biometric_unsupported">Biometric authentication is not supported on this device</string>
<string name="biometric_setting_summary">Unlock the app with Fingerprint, Face ID, PIN, Pattern and Password.</string>
<string name="biometric_prompt_description">This screen was closed due to multiple failed attempts. Please restart the application.</string>
<string name="biometric_prompt_description">After a few failed attempts, the prompt will close. Simply restart the app to try again.</string>
<string name="biometric_warning">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.</string>
<string name="music_singlar">Music</string>
<string name="audio_book_singular">Audio Book</string>
<string name="custom_media_singluar">Media</string>
</resources>