ConfigurableExtension(PreferenceScreen) support (#163)

* initial PreferenceScreen support, works with 'NeoXXX Scans' (pt-br)

* convert EditTextPreference to json successfully

* commit what I've got

* bring back the old SharedPreferences for CustomContext, implement Toast

* put back syer's implementation
This commit is contained in:
Aria Moradi
2021-07-31 03:53:28 +04:30
committed by GitHub
parent 29a79ab079
commit 2494d0821d
14 changed files with 302 additions and 16 deletions
@@ -30,6 +30,7 @@ import suwayomi.tachidesk.manga.impl.Search.sourceGlobalSearch
import suwayomi.tachidesk.manga.impl.Search.sourceSearch
import suwayomi.tachidesk.manga.impl.Source.getSource
import suwayomi.tachidesk.manga.impl.Source.getSourceList
import suwayomi.tachidesk.manga.impl.Source.getSourcePreferences
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
import suwayomi.tachidesk.manga.impl.backup.legacy.LegacyBackupExport.createLegacyBackup
import suwayomi.tachidesk.manga.impl.backup.legacy.LegacyBackupImport.restoreLegacyBackup
@@ -109,6 +110,12 @@ object TachideskAPI {
ctx.json(getSource(sourceId))
}
// fetch preferences of source with id `sourceId`
app.get("/api/v1/source/:sourceId/preference-screen") { ctx ->
val sourceId = ctx.pathParam("sourceId").toLong()
ctx.json(getSourcePreferences(sourceId))
}
// popular mangas from source with id `sourceId`
app.get("/api/v1/source/:sourceId/popular/:pageNum") { ctx ->
val sourceId = ctx.pathParam("sourceId").toLong()
@@ -7,15 +7,21 @@ package suwayomi.tachidesk.manga.impl
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.source.ConfigurableSource
import mu.KotlinLogging
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
import suwayomi.tachidesk.manga.impl.extension.Extension.getExtensionIconUrl
import suwayomi.tachidesk.manga.impl.util.GetHttpSource.getHttpSource
import suwayomi.tachidesk.manga.model.dataclass.SourceDataClass
import suwayomi.tachidesk.manga.model.table.ExtensionTable
import suwayomi.tachidesk.manga.model.table.SourceTable
import xyz.nulldev.androidcompat.androidimpl.CustomContext
object Source {
private val logger = KotlinLogging.logger {}
@@ -28,7 +34,8 @@ object Source {
it[SourceTable.name],
it[SourceTable.lang],
getExtensionIconUrl(ExtensionTable.select { ExtensionTable.id eq it[SourceTable.extension] }.first()[ExtensionTable.apkName]),
getHttpSource(it[SourceTable.id].value).supportsLatest
getHttpSource(it[SourceTable.id].value).supportsLatest,
getHttpSource(it[SourceTable.id].value) is ConfigurableSource
)
}
}
@@ -43,8 +50,36 @@ object Source {
source?.get(SourceTable.name),
source?.get(SourceTable.lang),
source?.let { ExtensionTable.select { ExtensionTable.id eq source[SourceTable.extension] }.first()[ExtensionTable.iconUrl] },
source?.let { getHttpSource(sourceId).supportsLatest }
source?.let { getHttpSource(sourceId).supportsLatest },
source?.let { getHttpSource(sourceId) is ConfigurableSource },
)
}
}
private val context by DI.global.instance<CustomContext>()
data class PreferenceObject(
val type: String,
val props: Any
)
var lastPreferenceScreen: PreferenceScreen? = null
fun getSourcePreferences(sourceId: Long): List<PreferenceObject> {
val source = getHttpSource(sourceId)
if (source is ConfigurableSource) {
val screen = PreferenceScreen(context)
lastPreferenceScreen = screen
source.setupPreferenceScreen(screen)
screen.preferences.first().callChangeListener("yo")
return screen.preferences.map {
PreferenceObject(it::class.java.name, it)
}
}
return emptyList()
}
}
@@ -12,5 +12,6 @@ data class SourceDataClass(
val name: String?,
val lang: String?,
val iconUrl: String?,
val supportsLatest: Boolean?
val supportsLatest: Boolean?,
val isConfigurable: Boolean?
)
@@ -1,5 +1,12 @@
package suwayomi.tachidesk.server
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import io.javalin.Javalin
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -13,13 +20,6 @@ import java.io.IOException
import java.util.concurrent.CompletableFuture
import kotlin.concurrent.thread
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
object JavalinSetup {
private val logger = KotlinLogging.logger {}