onCreate, onDestroy

This commit is contained in:
Antony 2022-10-01 18:37:16 +02:00
parent 100ff87b43
commit 7ef9b18e00
5 changed files with 36 additions and 1 deletions

View file

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

View file

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

View file

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

View file

@ -56,6 +56,7 @@
<string name="filter_sub_lang_key" translatable="false">filter_sub_lang_key</string>
<string name="pref_filter_search_quality_key" translatable="false">pref_filter_search_quality_key</string>
<string name="enable_nsfw_on_providers_key" translatable="false">enable_nsfw_on_providers_key</string>
<string name="automatic_cloud_backups" translatable="false">automatic_cloud_backups</string>
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
<string name="extra_info_format" formatted="true" translatable="false">%d %s | %s</string>
@ -244,6 +245,10 @@
<string name="episode_sync_settings_des">Automatically sync your current episode progress</string>
<string name="restore_settings">Restore data from backup</string>
<string name="automatic_restore_settings">Automatic backup from Github</string>
<string name="cloud_backups_off">Cloud Backup deactivated</string>
<string name="cloud_backups_on">Cloud Backup enabled</string>
<string name="backup_settings">Backup data</string>
<string name="restore_success">Loaded backup file</string>

View file

@ -17,6 +17,14 @@
android:key="@string/restore_key"
android:title="@string/restore_settings" />
<SwitchPreference
android:defaultValue="true"
android:icon="@drawable/baseline_restore_page_24"
android:key="@string/automatic_cloud_backups"
android:summaryOff="@string/cloud_backups_off"
android:summaryOn="@string/cloud_backups_on"
android:title="@string/automatic_restore_settings" />
<Preference
android:icon="@drawable/baseline_description_24"
android:key="@string/show_logcat_key"