onCreate, onDestroy fix

This commit is contained in:
Antony 2022-10-01 18:57:48 +02:00
parent 7ef9b18e00
commit fcff6de838
3 changed files with 18 additions and 16 deletions

View file

@ -35,6 +35,7 @@ import com.lagradost.cloudstream3.APIHolder.apis
import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings
import com.lagradost.cloudstream3.APIHolder.initAll import com.lagradost.cloudstream3.APIHolder.initAll
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
import com.lagradost.cloudstream3.AcraApplication.Companion.context
import com.lagradost.cloudstream3.CommonActivity.loadThemes import com.lagradost.cloudstream3.CommonActivity.loadThemes
import com.lagradost.cloudstream3.CommonActivity.onColorSelectedEvent import com.lagradost.cloudstream3.CommonActivity.onColorSelectedEvent
import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent
@ -596,7 +597,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
apis = allProviders.distinctBy { it } apis = allProviders.distinctBy { it }
if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)){ if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)){
this@MainActivity.restorePromptGithub() context?.restorePromptGithub()
} }
} }

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.syncproviders.providers
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.AcraApplication.Companion.context
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
@ -111,8 +112,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
userAvatar = it.owner.userAvatar, userAvatar = it.owner.userAvatar,
gistUrl = it.gistUrl gistUrl = it.gistUrl
)) ))
runOnMainThread { ioSafe {
FragmentActivity().restorePromptGithub() context?.restorePromptGithub()
} }

View file

@ -335,18 +335,18 @@ object BackupUtils {
Toast.LENGTH_LONG Toast.LENGTH_LONG
) )
} }
suspend fun Context.restorePromptGithub() {
fun FragmentActivity.restorePromptGithub() = val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException()
ioSafe { val jsondata = app.get(gistUrl).text
val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() val dataraw =
val jsondata = app.get(gistUrl).text parseJson<GithubApi.gistsElements>(jsondata ?: "").files.values.first().dataRaw
val dataraw = parseJson<GithubApi.gistsElements>(jsondata ?: "").files.values.first().dataRaw?: throw IllegalAccessException() ?: throw IllegalAccessException()
val data = parseJson<BackupFile>(dataraw) val data = parseJson<BackupFile>(dataraw)
this@restorePromptGithub.restore( restore(
data, data,
restoreSettings = true, restoreSettings = true,
restoreDataStore = true restoreDataStore = true
) )
} }
} }