fix restore crash
This commit is contained in:
parent
76394309fd
commit
21cff1eb69
6 changed files with 35 additions and 25 deletions
|
|
@ -139,7 +139,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs_nio:2.1.4"
|
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs_nio:2.1.5"
|
||||||
// implementation "com.github.yausername.youtubedl-android:library:$youtubedlAndroidVer"
|
// implementation "com.github.yausername.youtubedl-android:library:$youtubedlAndroidVer"
|
||||||
// implementation "com.github.yausername.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
|
// implementation "com.github.yausername.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
|
||||||
// implementation "com.github.yausername.youtubedl-android:aria2c:$youtubedlAndroidVer"
|
// implementation "com.github.yausername.youtubedl-android:aria2c:$youtubedlAndroidVer"
|
||||||
|
|
@ -150,7 +150,7 @@ dependencies {
|
||||||
implementation "io.github.junkfood02.youtubedl-android:aria2c:0.17.2"
|
implementation "io.github.junkfood02.youtubedl-android:aria2c:0.17.2"
|
||||||
|
|
||||||
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
||||||
implementation "androidx.constraintlayout:constraintlayout:2.2.0"
|
implementation "androidx.constraintlayout:constraintlayout:2.2.1"
|
||||||
implementation 'com.google.android.material:material:1.10.0'
|
implementation 'com.google.android.material:material:1.10.0'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.4.0'
|
implementation 'androidx.recyclerview:recyclerview:1.4.0'
|
||||||
|
|
@ -159,7 +159,7 @@ dependencies {
|
||||||
implementation "androidx.navigation:navigation-ui-ktx:$navVer"
|
implementation "androidx.navigation:navigation-ui-ktx:$navVer"
|
||||||
implementation 'androidx.core:core-ktx:1.15.0'
|
implementation 'androidx.core:core-ktx:1.15.0'
|
||||||
implementation 'androidx.test.ext:junit-ktx:1.2.1'
|
implementation 'androidx.test.ext:junit-ktx:1.2.1'
|
||||||
implementation 'androidx.compose.ui:ui-android:1.7.7'
|
implementation 'androidx.compose.ui:ui-android:1.7.8'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
testImplementation "junit:junit:$junitVer"
|
testImplementation "junit:junit:$junitVer"
|
||||||
androidTestImplementation "junit:junit:$junitVer"
|
androidTestImplementation "junit:junit:$junitVer"
|
||||||
|
|
@ -173,7 +173,7 @@ dependencies {
|
||||||
implementation("com.squareup.picasso:picasso:2.71828")
|
implementation("com.squareup.picasso:picasso:2.71828")
|
||||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||||
|
|
||||||
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
|
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.3.0'
|
||||||
implementation 'com.facebook.shimmer:shimmer:0.5.0'
|
implementation 'com.facebook.shimmer:shimmer:0.5.0'
|
||||||
|
|
||||||
implementation "androidx.work:work-runtime-ktx:$workVer"
|
implementation "androidx.work:work-runtime-ktx:$workVer"
|
||||||
|
|
@ -181,7 +181,7 @@ dependencies {
|
||||||
implementation "androidx.room:room-runtime:$roomVer"
|
implementation "androidx.room:room-runtime:$roomVer"
|
||||||
implementation "androidx.room:room-ktx:$roomVer"
|
implementation "androidx.room:room-ktx:$roomVer"
|
||||||
ksp "androidx.room:room-compiler:$roomVer"
|
ksp "androidx.room:room-compiler:$roomVer"
|
||||||
implementation 'androidx.paging:paging-runtime-ktx:3.3.2'
|
implementation 'androidx.paging:paging-runtime-ktx:3.3.6'
|
||||||
implementation "androidx.room:room-paging:$roomVer"
|
implementation "androidx.room:room-paging:$roomVer"
|
||||||
androidTestImplementation "androidx.room:room-testing:$roomVer"
|
androidTestImplementation "androidx.room:room-testing:$roomVer"
|
||||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7'
|
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7'
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.deniscerri.ytdl.database.models.observeSources.ObserveSourcesItem
|
||||||
import com.google.gson.JsonArray
|
import com.google.gson.JsonArray
|
||||||
|
|
||||||
data class RestoreAppDataItem(
|
data class RestoreAppDataItem(
|
||||||
var settings : JsonArray? = null,
|
var settings : List<BackupSettingsItem>? = null,
|
||||||
var downloads: List<HistoryItem>? = null,
|
var downloads: List<HistoryItem>? = null,
|
||||||
var queued: List<DownloadItem>? = null,
|
var queued: List<DownloadItem>? = null,
|
||||||
var scheduled: List<DownloadItem>? = null,
|
var scheduled: List<DownloadItem>? = null,
|
||||||
|
|
@ -16,4 +16,10 @@ data class RestoreAppDataItem(
|
||||||
var shortcuts: List<TemplateShortcut>? = null,
|
var shortcuts: List<TemplateShortcut>? = null,
|
||||||
var searchHistory: List<SearchHistoryItem>? = null,
|
var searchHistory: List<SearchHistoryItem>? = null,
|
||||||
var observeSources: List<ObserveSourcesItem>? = null,
|
var observeSources: List<ObserveSourcesItem>? = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class BackupSettingsItem(
|
||||||
|
var key: String,
|
||||||
|
var value: String,
|
||||||
|
var type: String?
|
||||||
)
|
)
|
||||||
|
|
@ -23,6 +23,7 @@ import com.deniscerri.ytdl.database.repository.ObserveSourcesRepository
|
||||||
import com.deniscerri.ytdl.database.repository.SearchHistoryRepository
|
import com.deniscerri.ytdl.database.repository.SearchHistoryRepository
|
||||||
import com.deniscerri.ytdl.util.BackupSettingsUtil
|
import com.deniscerri.ytdl.util.BackupSettingsUtil
|
||||||
import com.deniscerri.ytdl.util.FileUtil
|
import com.deniscerri.ytdl.util.FileUtil
|
||||||
|
import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
@ -110,24 +111,19 @@ class SettingsViewModel(private val application: Application) : AndroidViewModel
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit(commit = true){
|
PreferenceManager.getDefaultSharedPreferences(context).edit(commit = true){
|
||||||
clear()
|
clear()
|
||||||
prefs.forEach {
|
prefs.forEach {
|
||||||
val key : String = it.asJsonObject.get("key").toString().replace("\"", "")
|
val key = it.key
|
||||||
when(it.asJsonObject.get("type").toString().replace("\"", "")){
|
when(it.type){
|
||||||
"String" -> {
|
"String" -> {
|
||||||
val value = it.asJsonObject.get("value").toString().replace("\"", "")
|
putString(key, it.value)
|
||||||
putString(key, value)
|
|
||||||
}
|
}
|
||||||
"Boolean" -> {
|
"Boolean" -> {
|
||||||
val value = it.asJsonObject.get("value").toString().replace("\"", "").toBoolean()
|
putBoolean(key, it.value.toBoolean())
|
||||||
Log.e("REST", value.toString())
|
|
||||||
Log.e("REST", key)
|
|
||||||
putBoolean(key, value)
|
|
||||||
}
|
}
|
||||||
"Int" -> {
|
"Int" -> {
|
||||||
val value = it.asJsonObject.get("value").toString().replace("\"", "").toInt()
|
putInt(key, it.value.toInt())
|
||||||
putInt(key, value)
|
|
||||||
}
|
}
|
||||||
"HashSet" -> {
|
"HashSet" -> {
|
||||||
val value = it.asJsonObject.get("value").toString().replace("(\")|(\\[)|(])|([ \\t])".toRegex(), "").split(",")
|
val value = it.value.replace("(\")|(\\[)|(])|([ \\t])".toRegex(), "").split(",")
|
||||||
putStringSet(key, value.toHashSet())
|
putStringSet(key, value.toHashSet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import androidx.work.WorkManager
|
||||||
import com.deniscerri.ytdl.BuildConfig
|
import com.deniscerri.ytdl.BuildConfig
|
||||||
import com.deniscerri.ytdl.MainActivity
|
import com.deniscerri.ytdl.MainActivity
|
||||||
import com.deniscerri.ytdl.R
|
import com.deniscerri.ytdl.R
|
||||||
|
import com.deniscerri.ytdl.database.models.BackupSettingsItem
|
||||||
import com.deniscerri.ytdl.database.models.CommandTemplate
|
import com.deniscerri.ytdl.database.models.CommandTemplate
|
||||||
import com.deniscerri.ytdl.database.models.CookieItem
|
import com.deniscerri.ytdl.database.models.CookieItem
|
||||||
import com.deniscerri.ytdl.database.models.DownloadItem
|
import com.deniscerri.ytdl.database.models.DownloadItem
|
||||||
|
|
@ -289,8 +290,10 @@ class MainSettingsFragment : PreferenceFragmentCompat() {
|
||||||
val parsedDataMessage = StringBuilder()
|
val parsedDataMessage = StringBuilder()
|
||||||
|
|
||||||
if (json.has("settings")) {
|
if (json.has("settings")) {
|
||||||
restoreData.settings = json.getAsJsonArray("settings")
|
restoreData.settings = json.getAsJsonArray("settings").map {
|
||||||
parsedDataMessage.appendLine("${getString(R.string.settings)}: ${restoreData.settings!!.size()}")
|
Gson().fromJson(it.toString().replace("^\"|\"$", ""), BackupSettingsItem::class.java)
|
||||||
|
}
|
||||||
|
parsedDataMessage.appendLine("${getString(R.string.settings)}: ${restoreData.settings!!.size}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.has("downloads")) {
|
if (json.has("downloads")) {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.services.youtube.PoTokenProvider
|
||||||
import org.schabi.newpipe.extractor.services.youtube.PoTokenResult
|
import org.schabi.newpipe.extractor.services.youtube.PoTokenResult
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
|
||||||
|
|
||||||
|
//for newpipe
|
||||||
class PoTokenGenerator : PoTokenProvider {
|
class PoTokenGenerator : PoTokenProvider {
|
||||||
val TAG = PoTokenGenerator::class.simpleName
|
val TAG = PoTokenGenerator::class.simpleName
|
||||||
private val supportsWebView by lazy { runCatching { CookieManager.getInstance() }.isSuccess }
|
private val supportsWebView by lazy { runCatching { CookieManager.getInstance() }.isSuccess }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.deniscerri.ytdl.util
|
package com.deniscerri.ytdl.util
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import com.deniscerri.ytdl.database.models.BackupSettingsItem
|
||||||
import com.deniscerri.ytdl.database.repository.CommandTemplateRepository
|
import com.deniscerri.ytdl.database.repository.CommandTemplateRepository
|
||||||
import com.deniscerri.ytdl.database.repository.CookieRepository
|
import com.deniscerri.ytdl.database.repository.CookieRepository
|
||||||
import com.deniscerri.ytdl.database.repository.DownloadRepository
|
import com.deniscerri.ytdl.database.repository.DownloadRepository
|
||||||
|
|
@ -19,13 +20,16 @@ object BackupSettingsUtil {
|
||||||
runCatching {
|
runCatching {
|
||||||
val prefs = preferences.all
|
val prefs = preferences.all
|
||||||
prefs.remove("app_language")
|
prefs.remove("app_language")
|
||||||
|
|
||||||
|
val res = prefs.map { BackupSettingsItem(
|
||||||
|
key = it.key,
|
||||||
|
value = it.value.toString(),
|
||||||
|
type = it.value!!::class.simpleName
|
||||||
|
) }
|
||||||
|
|
||||||
val arr = JsonArray()
|
val arr = JsonArray()
|
||||||
prefs.forEach {
|
res.forEach {
|
||||||
val obj = JsonObject()
|
arr.add(JsonParser.parseString(Gson().toJson(it)).asJsonObject)
|
||||||
obj.addProperty("key", it.key)
|
|
||||||
obj.addProperty("value", it.value.toString())
|
|
||||||
obj.addProperty("type", it.value!!::class.simpleName)
|
|
||||||
arr.add(obj)
|
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue