diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index cd320060..face4fae 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -50,6 +50,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2A import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo +import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.githubApi import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.inAppAuths import com.lagradost.cloudstream3.ui.APIRepository import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO @@ -64,6 +65,8 @@ import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable import com.lagradost.cloudstream3.utils.AppUtils.loadCache import com.lagradost.cloudstream3.utils.AppUtils.loadRepository import com.lagradost.cloudstream3.utils.AppUtils.loadResult +import com.lagradost.cloudstream3.utils.BackupUtils.backupGithub +import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getKey @@ -399,8 +402,14 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { override fun onDestroy() { val broadcastIntent = Intent() + val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) broadcastIntent.action = "restart_service" broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java) + + if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)) { + this@MainActivity.backupGithub() + } + this.sendBroadcast(broadcastIntent) afterPluginsLoadedEvent -= ::onAllPluginsLoaded super.onDestroy() @@ -585,6 +594,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { initAll() // No duplicates (which can happen by registerMainAPI) apis = allProviders.distinctBy { it } + + if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)){ + this@MainActivity.restorePromptGithub() + } } // val navView: BottomNavigationView = findViewById(R.id.nav_view) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 53669aca..f03804cc 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -1,5 +1,6 @@ package com.lagradost.cloudstream3.syncproviders.providers +import androidx.fragment.app.FragmentActivity import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.AcraApplication.Companion.getKey @@ -12,7 +13,9 @@ import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson +import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.Coroutines.ioSafe +import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread import com.lagradost.nicehttp.RequestBodyTypes import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody @@ -108,6 +111,11 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ userAvatar = it.owner.userAvatar, gistUrl = it.gistUrl )) + runOnMainThread { + FragmentActivity().restorePromptGithub() + } + + return true } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index 3e9a5a57..e95d7117 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -17,6 +17,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPadd import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.utils.BackupUtils.backup import com.lagradost.cloudstream3.utils.BackupUtils.restorePrompt +import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe @@ -52,7 +53,7 @@ class SettingsUpdates : PreferenceFragmentCompat() { } getPref(R.string.restore_key)?.setOnPreferenceClickListener { - activity?.restorePrompt() + activity?.restorePromptGithub() return@setOnPreferenceClickListener true } getPref(R.string.show_logcat_key)?.setOnPreferenceClickListener { pref -> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8f1f23f3..511ab7ee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,6 +56,7 @@ filter_sub_lang_key pref_filter_search_quality_key enable_nsfw_on_providers_key + automatic_cloud_backups %d %s | %s @@ -244,6 +245,10 @@ Automatically sync your current episode progress Restore data from backup + Automatic backup from Github + + Cloud Backup deactivated + Cloud Backup enabled Backup data Loaded backup file diff --git a/app/src/main/res/xml/settings_updates.xml b/app/src/main/res/xml/settings_updates.xml index eaceb785..f24cc7ca 100644 --- a/app/src/main/res/xml/settings_updates.xml +++ b/app/src/main/res/xml/settings_updates.xml @@ -17,6 +17,14 @@ android:key="@string/restore_key" android:title="@string/restore_settings" /> + +