From 7c03c73419b5bc02db6a0489ad89c9429ea63805 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Fri, 30 Jul 2021 18:48:07 +0430 Subject: [PATCH] convert EditTextPreference to json successfully --- .../main/java/androidx/preference/Preference.java | 11 +++++++++-- build.gradle.kts | 3 +++ .../kotlin/suwayomi/tachidesk/manga/impl/Source.kt | 12 ++++++++++-- .../suwayomi/tachidesk/server/JavalinSetup.kt | 14 +++++++------- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/AndroidCompat/src/main/java/androidx/preference/Preference.java b/AndroidCompat/src/main/java/androidx/preference/Preference.java index 7029b703..9a619dd1 100644 --- a/AndroidCompat/src/main/java/androidx/preference/Preference.java +++ b/AndroidCompat/src/main/java/androidx/preference/Preference.java @@ -8,18 +8,22 @@ package androidx.preference; * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import android.content.Context; +import com.fasterxml.jackson.annotation.JsonIgnore; /** A minimal implementation of androidx.preference.Preference */ public class Preference { // reference: https://android.googlesource.com/platform/frameworks/support/+/996971f962fcd554339a7cb2859cef9ca89dbcb7/preference/preference/src/main/java/androidx/preference/Preference.java // Note: `Preference` doesn't actually hold or persist the value, `OnPreferenceChangeListener` is called and it's up to the extension to persist it. + @JsonIgnore protected Context context; private String key; private CharSequence title; private Object defaultValue; - private OnPreferenceChangeListener onChangeListener; + + @JsonIgnore + public OnPreferenceChangeListener onChangeListener; public Preference(Context context) { this.context = context; @@ -29,7 +33,6 @@ public class Preference { return context; } - public String getKey() { return key; } @@ -54,6 +57,10 @@ public class Preference { return onChangeListener == null || onChangeListener.onPreferenceChange(this, newValue); } + public Object getDefaultValue() { + return defaultValue; + } + public interface OnPreferenceChangeListener { boolean onPreferenceChange(Preference preference, Object newValue); } diff --git a/build.gradle.kts b/build.gradle.kts index be658d61..9697908b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -84,5 +84,8 @@ configure(projects) { // APK parser implementation("net.dongliu:apk-parser:2.6.10") + + // Jackson + implementation("com.fasterxml.jackson.core:jackson-annotations:2.10.3") } } \ No newline at end of file diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt index 1d0948b8..58f8db3c 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt @@ -58,7 +58,12 @@ object Source { private val context by DI.global.instance() - fun getSourcePreferences(sourceId: Long) { + data class PreferenceObject( + val type: String, + val props: Any + ) + + fun getSourcePreferences(sourceId: Long): List { val source = getHttpSource(sourceId) if (source is ConfigurableSource) { @@ -66,7 +71,10 @@ object Source { source.setupPreferenceScreen(screen) - screen.preferences.forEach { println(it) } + return screen.preferences.map { + PreferenceObject(it::class.java.name, it) + } } + return emptyList() } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt index abe53b60..1a6ca2e8 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt @@ -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 {}