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.initAll
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
import com.lagradost.cloudstream3.AcraApplication.Companion.context
import com.lagradost.cloudstream3.CommonActivity.loadThemes
import com.lagradost.cloudstream3.CommonActivity.onColorSelectedEvent
import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent
@ -596,7 +597,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
apis = allProviders.distinctBy { it }
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 com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.AcraApplication.Companion.context
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
@ -111,8 +112,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
userAvatar = it.owner.userAvatar,
gistUrl = it.gistUrl
))
runOnMainThread {
FragmentActivity().restorePromptGithub()
ioSafe {
context?.restorePromptGithub()
}

View file

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