mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Merge branch 'githubAccount' of https://github.com/antonydp/cloudstream into githubAccount
This commit is contained in:
commit
4dd205c549
5 changed files with 74 additions and 50 deletions
|
@ -60,6 +60,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStri
|
|||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringResumeWatching
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringSearch
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.githubApi
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringSearch
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.inAppAuths
|
||||
import com.lagradost.cloudstream3.ui.APIRepository
|
||||
import com.lagradost.cloudstream3.ui.WatchType
|
||||
|
@ -447,6 +448,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
//private var mCastSession: CastSession? = null
|
||||
lateinit var mSessionManager: SessionManager
|
||||
private val mSessionManagerListener: SessionManagerListener<Session> by lazy { SessionManagerListenerImpl() }
|
||||
private val accountsLoginLock = Mutex()
|
||||
|
||||
private inner class SessionManagerListenerImpl : SessionManagerListener<Session> {
|
||||
override fun onSessionStarting(session: Session) {
|
||||
|
@ -508,7 +510,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
logError(e)
|
||||
}
|
||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
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), true)) {
|
||||
this@MainActivity.backupGithub()
|
||||
}
|
||||
}
|
||||
|
@ -648,22 +650,22 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
}
|
||||
}
|
||||
|
||||
lateinit var viewModel: ResultViewModel2
|
||||
lateinit var viewModel: ResultViewModel2
|
||||
|
||||
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
|
||||
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
|
||||
viewModel =
|
||||
ViewModelProvider(this)[ResultViewModel2::class.java]
|
||||
|
||||
return super.onCreateView(name, context, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun hidePreviewPopupDialog() {
|
||||
private fun hidePreviewPopupDialog() {
|
||||
viewModel.clear()
|
||||
bottomPreviewPopup.dismissSafe(this)
|
||||
}
|
||||
}
|
||||
|
||||
var bottomPreviewPopup: BottomSheetDialog? = null
|
||||
private fun showPreviewPopupDialog(): BottomSheetDialog {
|
||||
var bottomPreviewPopup: BottomSheetDialog? = null
|
||||
private fun showPreviewPopupDialog(): BottomSheetDialog {
|
||||
val ret = (bottomPreviewPopup ?: run {
|
||||
val builder =
|
||||
BottomSheetDialog(this)
|
||||
|
@ -678,6 +680,21 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
})
|
||||
bottomPreviewPopup = ret
|
||||
return ret
|
||||
|
||||
override fun onStart() {
|
||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
super.onStart()
|
||||
ioSafe {
|
||||
accountsLoginLock.withLock {
|
||||
if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(
|
||||
getString(R.string.automatic_cloud_backups),
|
||||
true
|
||||
)
|
||||
) {
|
||||
context?.restorePromptGithub()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -853,6 +870,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
|
||||
// init accounts
|
||||
ioSafe {
|
||||
accountsLoginLock.withLock{
|
||||
for (api in accountManagers) {
|
||||
api.init()
|
||||
}
|
||||
|
@ -865,6 +883,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SearchResultBuilder.updateCache(this)
|
||||
|
||||
|
@ -872,10 +891,6 @@ 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)){
|
||||
context?.restorePromptGithub()
|
||||
}
|
||||
}
|
||||
|
||||
// val navView: BottomNavigationView = findViewById(R.id.nav_view)
|
||||
|
|
|
@ -84,7 +84,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
|||
|
||||
if (repo?.isEmpty() == true){
|
||||
val backupData = context?.getBackup()
|
||||
val gitresponse = app.post("https://api.github.com/gists",
|
||||
val gitResponse = app.post("https://api.github.com/gists",
|
||||
headers= mapOf(
|
||||
Pair("Accept" , "application/vnd.github+json"),
|
||||
Pair("Authorization", "token $githubToken"),
|
||||
|
@ -92,8 +92,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
|||
requestBody = GistRequestBody("Cloudstream private backup gist", false, FilesGist(ContentFilesGist(backupData?.toJson()))).toJson().toRequestBody(
|
||||
RequestBodyTypes.JSON.toMediaTypeOrNull()))
|
||||
|
||||
if (!gitresponse.isSuccessful) {return false}
|
||||
tryParseJson<GistsElements>(gitresponse.text).let {
|
||||
if (!gitResponse.isSuccessful) {return false}
|
||||
tryParseJson<GistsElements>(gitResponse.text).let {
|
||||
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
|
||||
token = githubToken,
|
||||
gistId = it?.gistId?: run {
|
||||
|
|
|
@ -93,6 +93,7 @@ class HomeFragment : Fragment() {
|
|||
val configEvent = Event<Int>()
|
||||
var currentSpan = 1
|
||||
val listHomepageItems = mutableListOf<SearchResponse>()
|
||||
val reloadStoredDataEvent = Event<Unit>()
|
||||
|
||||
private val errorProfilePics = listOf(
|
||||
R.drawable.monke_benene,
|
||||
|
@ -486,6 +487,10 @@ class HomeFragment : Fragment() {
|
|||
super.onStop()
|
||||
}
|
||||
|
||||
private fun reloadStoredEvent(input: Unit) {
|
||||
reloadStored()
|
||||
}
|
||||
|
||||
private fun reloadStored() {
|
||||
homeViewModel.loadResumeWatching()
|
||||
val list = EnumSet.noneOf(WatchType::class.java)
|
||||
|
|
|
@ -33,6 +33,7 @@ import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_T
|
|||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_UNIXTIME_KEY
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_USER_KEY
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.OpenSubtitlesApi.Companion.OPEN_SUBTITLES_USER_KEY
|
||||
import com.lagradost.cloudstream3.ui.home.HomeFragment
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||
|
||||
|
@ -83,7 +84,7 @@ object BackupUtils {
|
|||
|
||||
/** false if blacklisted key */
|
||||
private fun String.isTransferable(): Boolean {
|
||||
return !nonTransferableKeys.contains(this)
|
||||
return !nonTransferableKeys.contains(this) and !nonTransferableKeys.any { this.endsWith(it) }
|
||||
}
|
||||
|
||||
private var restoreFileSelector: ActivityResultLauncher<Array<String>>? = null
|
||||
|
@ -300,7 +301,7 @@ object BackupUtils {
|
|||
|
||||
|
||||
fun FragmentActivity.backupGithub(){
|
||||
val backup = this.getBackup()
|
||||
val backup = this.getBackup().toJson()
|
||||
|
||||
val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username")
|
||||
val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username")
|
||||
|
@ -314,7 +315,7 @@ object BackupUtils {
|
|||
requestBody = GithubApi.GistRequestBody(
|
||||
"Cloudstream private backup gist",
|
||||
false,
|
||||
GithubApi.FilesGist(GithubApi.ContentFilesGist(backup.toJson())))
|
||||
GithubApi.FilesGist(GithubApi.ContentFilesGist(backup)))
|
||||
.toJson()
|
||||
.toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull())
|
||||
)
|
||||
|
@ -327,15 +328,16 @@ object BackupUtils {
|
|||
}
|
||||
suspend fun Context.restorePromptGithub() {
|
||||
val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException()
|
||||
val jsondata = app.get(" https://api.github.com/gists/$gistId").text
|
||||
val dataraw =
|
||||
parseJson<GithubApi.GistsElements>(jsondata ?: "").files.values.first().dataRaw
|
||||
val jsonData = app.get("https://api.github.com/gists/$gistId").text
|
||||
val dataRaw =
|
||||
parseJson<GithubApi.GistsElements>(jsonData ?: "").files.values.first().dataRaw
|
||||
?: throw IllegalAccessException()
|
||||
val data = parseJson<BackupFile>(dataraw)
|
||||
val data = parseJson<BackupFile>(dataRaw)
|
||||
restore(
|
||||
data,
|
||||
restoreSettings = true,
|
||||
restoreDataStore = true
|
||||
)
|
||||
HomeFragment.reloadStoredDataEvent.invoke(Unit)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,6 +141,8 @@
|
|||
<!--<string name="episode_sync_settings">Update watch progress</string>-->
|
||||
<string name="episode_sync_settings_des">Sincronizza automaticamente gli episodi guardati</string>
|
||||
<string name="restore_settings">Ripristinare i dati da backup</string>
|
||||
<string name="automatic_restore_settings">Backup automatico su Github</string>
|
||||
|
||||
<string name="backup_settings">Backup data</string>
|
||||
<string name="restore_success">File di backup caricato</string>
|
||||
<string name="restore_failed_format" formatted="true">Impossibile ripristinare i dati dal file %s</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue