feat(ui): new dialog on adding repository and auto redirection (#1025)

This commit is contained in:
IndusAryan 2024-06-19 20:06:40 +05:30 committed by GitHub
parent afa178a63a
commit c71d5d8add
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 84 additions and 41 deletions

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.AppUtils.setDefaultFocus
import com.lagradost.cloudstream3.utils.BackupUtils.backup import com.lagradost.cloudstream3.utils.BackupUtils.backup
import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup 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.biometricPrompt
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.isAuthEnabled import com.lagradost.cloudstream3.utils.BiometricAuthenticator.isAuthEnabled
@ -186,8 +186,7 @@ import kotlin.system.exitProcess
//https://github.com/jellyfin/jellyfin-android/blob/6cbf0edf84a3da82347c8d59b5d5590749da81a9/app/src/main/java/org/jellyfin/mobile/bridge/ExternalPlayer.kt#L225 //https://github.com/jellyfin/jellyfin-android/blob/6cbf0edf84a3da82347c8d59b5d5590749da81a9/app/src/main/java/org/jellyfin/mobile/bridge/ExternalPlayer.kt#L225
class MainActivity : AppCompatActivity(), ColorPickerDialogListener, class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCallback {
BiometricAuthenticator.BiometricAuthCallback {
companion object { companion object {
const val VLC_PACKAGE = "org.videolan.vlc" const val VLC_PACKAGE = "org.videolan.vlc"
const val MPV_PACKAGE = "is.xyz.mpv" const val MPV_PACKAGE = "is.xyz.mpv"

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.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.utils.BiometricAuthenticator 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.biometricPrompt
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.isAuthEnabled 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.DataStoreHelper.setAccount
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
class AccountSelectActivity : AppCompatActivity(), BiometricAuthenticator.BiometricAuthCallback { class AccountSelectActivity : AppCompatActivity(), BiometricCallback {
lateinit var viewModel: AccountViewModel lateinit var viewModel: AccountViewModel

View file

@ -51,7 +51,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setTool
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
import com.lagradost.cloudstream3.utils.AppUtils.html import com.lagradost.cloudstream3.utils.AppUtils.html
import com.lagradost.cloudstream3.utils.BackupUtils 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.authCallback
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.biometricPrompt import com.lagradost.cloudstream3.utils.BiometricAuthenticator.biometricPrompt
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock
@ -68,7 +68,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.toPx
import qrcode.QRCode import qrcode.QRCode
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
class SettingsAccount : PreferenceFragmentCompat(), BiometricAuthenticator.BiometricAuthCallback { class SettingsAccount : PreferenceFragmentCompat(), BiometricCallback {
companion object { companion object {
/** Used by nginx plugin too */ /** Used by nginx plugin too */
fun showLoginInfo( fun showLoginInfo(

View file

@ -33,7 +33,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
import com.lagradost.cloudstream3.utils.AppUtils.downloadAllPluginsDialog import com.lagradost.cloudstream3.utils.AppUtils.addRepositoryDialog
import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
@ -273,9 +273,9 @@ class ExtensionsFragment : Fragment() {
if (plugins.isNullOrEmpty()) { if (plugins.isNullOrEmpty()) {
showToast(R.string.no_plugins_found_error, Toast.LENGTH_LONG) showToast(R.string.no_plugins_found_error, Toast.LENGTH_LONG)
} else { } else {
this@ExtensionsFragment.activity?.downloadAllPluginsDialog( this@ExtensionsFragment.activity?.addRepositoryDialog(
fixedName,
url, url,
fixedName
) )
} }
} }

View file

@ -10,6 +10,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
import com.lagradost.cloudstream3.AllLanguagesName import com.lagradost.cloudstream3.AllLanguagesName
import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.databinding.FragmentPluginsBinding import com.lagradost.cloudstream3.databinding.FragmentPluginsBinding
@ -70,6 +71,8 @@ class PluginsFragment : Fragment() {
val name = arguments?.getString(PLUGINS_BUNDLE_NAME) val name = arguments?.getString(PLUGINS_BUNDLE_NAME)
val url = arguments?.getString(PLUGINS_BUNDLE_URL) val url = arguments?.getString(PLUGINS_BUNDLE_URL)
val isLocal = arguments?.getBoolean(PLUGINS_BUNDLE_LOCAL) == true val isLocal = arguments?.getBoolean(PLUGINS_BUNDLE_LOCAL) == true
// download all extensions button
val downloadAllButton = binding?.settingsToolbar?.menu?.findItem(R.id.download_all)
if (url == null || name == null) { if (url == null || name == null) {
activity?.onBackPressedDispatcher?.onBackPressed() activity?.onBackPressedDispatcher?.onBackPressed()
@ -171,7 +174,7 @@ class PluginsFragment : Fragment() {
if (isLocal) { if (isLocal) {
// No download button and no categories on local // No download button and no categories on local
binding?.settingsToolbar?.menu?.findItem(R.id.download_all)?.isVisible = false downloadAllButton?.isVisible = false
binding?.settingsToolbar?.menu?.findItem(R.id.lang_filter)?.isVisible = false binding?.settingsToolbar?.menu?.findItem(R.id.lang_filter)?.isVisible = false
pluginViewModel.updatePluginListLocal() pluginViewModel.updatePluginListLocal()
@ -179,6 +182,10 @@ class PluginsFragment : Fragment() {
} else { } else {
pluginViewModel.updatePluginList(context, url) pluginViewModel.updatePluginList(context, url)
binding?.tvtypesChipsScroll?.root?.isVisible = true binding?.tvtypesChipsScroll?.root?.isVisible = true
// not needed for users but may be useful for devs
downloadAllButton?.isVisible = BuildConfig.DEBUG
bindChips( bindChips(
binding?.tvtypesChipsScroll?.tvtypesChips, binding?.tvtypesChipsScroll?.tvtypesChips,

View file

@ -62,7 +62,8 @@ import com.lagradost.cloudstream3.syncproviders.providers.Kitsu
import com.lagradost.cloudstream3.ui.WebviewFragment import com.lagradost.cloudstream3.ui.WebviewFragment
import com.lagradost.cloudstream3.ui.result.ResultFragment import com.lagradost.cloudstream3.ui.result.ResultFragment
import com.lagradost.cloudstream3.ui.settings.Globals import com.lagradost.cloudstream3.ui.settings.Globals
import com.lagradost.cloudstream3.ui.settings.extensions.PluginsViewModel.Companion.downloadAll 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.ui.settings.extensions.RepositoryData
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
@ -386,7 +387,7 @@ object AppUtils {
) )
} }
afterRepositoryLoadedEvent.invoke(true) afterRepositoryLoadedEvent.invoke(true)
downloadAllPluginsDialog(url, repo.name) addRepositoryDialog(repo.name, url)
} }
} }
@ -429,25 +430,36 @@ object AppUtils {
} }
} }
fun Activity.addRepositoryDialog(
repositoryName: String,
repositoryURL: String,
) {
val repos = RepositoryManager.getRepositories()
// navigate to newly added repository on pressing Open Repository
fun openAddedRepo() {
if (repos.isNotEmpty()) {
navigate(
R.id.global_to_navigation_settings_plugins,
PluginsFragment.newInstance(
repositoryName,
repositoryURL,
false,
)
)
}
}
fun Activity.downloadAllPluginsDialog(repositoryUrl: String, repositoryName: String) {
runOnUiThread { runOnUiThread {
val context = this AlertDialog.Builder(this).apply {
val builder: AlertDialog.Builder = AlertDialog.Builder(this) setTitle(repositoryName)
builder.setTitle( setMessage(R.string.download_all_plugins_from_repo)
repositoryName setPositiveButton(R.string.open_downloaded_repo) { _, _ ->
) openAddedRepo()
builder.setMessage(
R.string.download_all_plugins_from_repo
)
builder.apply {
setPositiveButton(R.string.download) { _, _ ->
downloadAll(context, repositoryUrl, null)
} }
setNegativeButton(R.string.dismiss, null)
setNegativeButton(R.string.no) { _, _ -> } show().setDefaultFocus()
} }
builder.show().setDefaultFocus()
} }
} }

View file

@ -26,7 +26,7 @@ object BiometricAuthenticator {
private var biometricManager: BiometricManager? = null private var biometricManager: BiometricManager? = null
var biometricPrompt: BiometricPrompt? = null var biometricPrompt: BiometricPrompt? = null
var promptInfo: BiometricPrompt.PromptInfo? = 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) { private fun initializeBiometrics(activity: Activity) {
val executor = ContextCompat.getMainExecutor(activity) val executor = ContextCompat.getMainExecutor(activity)
@ -141,14 +141,14 @@ object BiometricAuthenticator {
// function to start authentication in any fragment or activity // function to start authentication in any fragment or activity
fun startBiometricAuthentication(activity: Activity, title: Int, setDeviceCred: Boolean) { fun startBiometricAuthentication(activity: Activity, title: Int, setDeviceCred: Boolean) {
initializeBiometrics(activity) initializeBiometrics(activity)
authCallback = activity as? BiometricAuthCallback authCallback = activity as? BiometricCallback
if (isBiometricHardWareAvailable()) { if (isBiometricHardWareAvailable()) {
authCallback = activity as? BiometricAuthCallback authCallback = activity as? BiometricCallback
authenticationDialog(activity, title, setDeviceCred) authenticationDialog(activity, title, setDeviceCred)
promptInfo?.let { biometricPrompt?.authenticate(it) } promptInfo?.let { biometricPrompt?.authenticate(it) }
} else { } else {
if (deviceHasPasswordPinLock(activity)) { if (deviceHasPasswordPinLock(activity)) {
authCallback = activity as? BiometricAuthCallback authCallback = activity as? BiometricCallback
authenticationDialog(activity, R.string.password_pin_authentication_title, true) authenticationDialog(activity, R.string.password_pin_authentication_title, true)
promptInfo?.let { biometricPrompt?.authenticate(it) } promptInfo?.let { biometricPrompt?.authenticate(it) }
@ -165,7 +165,7 @@ object BiometricAuthenticator {
} }
} }
interface BiometricAuthCallback { interface BiometricCallback {
fun onAuthenticationSuccess() fun onAuthenticationSuccess()
fun onAuthenticationError() fun onAuthenticationError()
} }

View file

@ -21,5 +21,6 @@
android:id="@+id/download_all" android:id="@+id/download_all"
android:icon="@drawable/netflix_download" android:icon="@drawable/netflix_download"
android:title="@string/batch_download" android:title="@string/batch_download"
app:showAsAction="collapseActionView|ifRoom" /> app:showAsAction="collapseActionView|ifRoom"
android:visible="false"/>
</menu> </menu>

View file

@ -111,6 +111,27 @@
app:argType="boolean" /> app:argType="boolean" />
</action> </action>
<action
android:id="@+id/global_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
android:id="@+id/navigation_settings_player" android:id="@+id/navigation_settings_player"
android:name="com.lagradost.cloudstream3.ui.settings.SettingsPlayer" android:name="com.lagradost.cloudstream3.ui.settings.SettingsPlayer"

View file

@ -350,6 +350,9 @@
<string name="live_singular">Livestream</string> <string name="live_singular">Livestream</string>
<string name="nsfw_singular">NSFW</string> <string name="nsfw_singular">NSFW</string>
<string name="other_singular">Video</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="source_error">Source error</string>
<string name="remote_error">Remote error</string> <string name="remote_error">Remote error</string>
<string name="render_error">Renderer error</string> <string name="render_error">Renderer error</string>
@ -617,7 +620,7 @@
<string name="view_public_repositories_button">View community repositories</string> <string name="view_public_repositories_button">View community repositories</string>
<string name="view_public_repositories_button_short">Public list</string> <string name="view_public_repositories_button_short">Public list</string>
<string name="uppercase_all_subtitles">Uppercase all subtitles</string> <string name="uppercase_all_subtitles">Uppercase all subtitles</string>
<string name="download_all_plugins_from_repo">Download all plugins from this repository?</string> <string name="download_all_plugins_from_repo">Warning: CloudStream 3 does not take any responsibility for using third-party extensions and does not provide any support for them!</string>
<string name="single_plugin_disabled" formatted="true">%s (Disabled)</string> <string name="single_plugin_disabled" formatted="true">%s (Disabled)</string>
<string name="tracks">Tracks</string> <string name="tracks">Tracks</string>
<string name="audio_tracks">Audio tracks</string> <string name="audio_tracks">Audio tracks</string>
@ -668,6 +671,8 @@
<string name="yes">Yes</string> <string name="yes">Yes</string>
<string name="no">No</string> <string name="no">No</string>
<string name="ok">OK</string> <string name="ok">OK</string>
<string name="dismiss">Dismiss</string>
<string name="open_downloaded_repo">Open repository</string>
<string name="battery_dialog_title">Disable Battery optimization</string> <string name="battery_dialog_title">Disable Battery optimization</string>
<string name="battery_dialog_message">To ensure uninterrupted downloads and notifications for subscribed <string name="battery_dialog_message">To ensure uninterrupted downloads and notifications for subscribed
TV shows, CloudStream needs permission to run in background. By pressing "OK", you\'ll be directed to App info. TV shows, CloudStream needs permission to run in background. By pressing "OK", you\'ll be directed to App info.
@ -775,11 +780,8 @@
<string name="password_pin_authentication_title">Password/PIN Authentication</string> <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_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_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="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>
<string name="reset_btn">Reset</string> <string name="reset_btn">Reset</string>
<string name="cs3wiki">CloudStream Wiki</string> <string name="cs3wiki">CloudStream Wiki</string>
<string name="device_pin_url_message">Visit <b>%s</b> on your smartphone or computer and enter the above code</string> <string name="device_pin_url_message">Visit <b>%s</b> on your smartphone or computer and enter the above code</string>

View file

@ -1,6 +1,6 @@
#Fri Apr 30 17:11:15 CEST 2021 #Fri Apr 30 17:11:15 CEST 2021
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME