From 3bfda338efc219ba78e9903f0c7be1c1a14edd1a Mon Sep 17 00:00:00 2001 From: Jobobby04 Date: Sun, 10 May 2020 22:36:52 -0400 Subject: [PATCH] Add basic E/Ex-Hentai watched tag settings, possibly more to come --- .../data/preference/PreferenceKeys.kt | 4 + .../data/preference/PreferencesHelper.kt | 4 + .../ui/setting/SettingsEhController.kt | 94 +++++++++++++++++++ .../main/java/exh/uconfig/EhUConfigBuilder.kt | 13 +++ 4 files changed, 115 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index fb2c7f644..0a092a875 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -224,4 +224,8 @@ object PreferenceKeys { const val eh_hl_useHighQualityThumbs = "eh_hl_hq_thumbs" const val eh_preload_size = "eh_preload_size" + + const val eh_tag_filtering_value = "eh_tag_filtering_value" + + const val eh_tag_watching_value = "eh_tag_watching_value" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index e630f1dce..f0657b74c 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -270,6 +270,10 @@ class PreferencesHelper(val context: Context) { fun eh_useOriginalImages() = flowPrefs.getBoolean(Keys.eh_useOrigImages, false) + fun ehTagFilterValue() = flowPrefs.getInt(Keys.eh_tag_filtering_value, 0) + + fun ehTagWatchingValue() = flowPrefs.getInt(Keys.eh_tag_watching_value, 0) + fun ehSearchSize() = flowPrefs.getString("ex_search_size", "rc_0") fun thumbnailRows() = flowPrefs.getString("ex_thumb_rows", "tr_2") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt index 763e1965b..ffe4e2895 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt @@ -1,9 +1,14 @@ package eu.kanade.tachiyomi.ui.setting import android.os.Handler +import android.text.InputType import android.widget.Toast import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.WhichButton +import com.afollestad.materialdialogs.actions.setActionButtonEnabled +import com.afollestad.materialdialogs.input.getInputField +import com.afollestad.materialdialogs.input.input import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.github.salomonbrys.kotson.fromJson @@ -15,6 +20,7 @@ import com.tfcporciuncula.flow.Preference import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.preference.PreferenceKeys +import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.preference.defaultValue import eu.kanade.tachiyomi.util.preference.entriesRes import eu.kanade.tachiyomi.util.preference.intListPreference @@ -135,6 +141,94 @@ class SettingsEhController : SettingsController() { onChange { preferences.eh_useOriginalImages().reconfigure() } }.dependency = PreferenceKeys.eh_enableExHentai + preference { + title = "Watched Tags" + summary = "Opens a webview to your E/ExHentai watched tags page" + onClick { + val intent = if (preferences.enableExhentai().get()) { + WebViewActivity.newIntent(activity!!, url = "https://exhentai.org/mytags", title = "ExHentai Watched Tags") + } else { + WebViewActivity.newIntent(activity!!, url = "https://e-hentai.org/mytags", title = "E-Hentai Watched Tags") + } + startActivity(intent) + } + }.dependency = PreferenceKeys.eh_enableExHentai + + preference { + title = "Tag Filtering Threshold" + key = PreferenceKeys.eh_tag_filtering_value + defaultValue = 0 + + var value = preferences.ehTagFilterValue().get() + + summary = "You can soft filter tags by adding them to the \"My Tags\" E/ExHentai page with a negative weight. If a gallery has tags that add up to weight below this value, it is filtered from view. This threshold can be set between -9999 and 0. Currently: $value" + + onClick { + MaterialDialog(activity!!) + .title(text = "Tag Filtering Threshold") + .input( + inputType = InputType.TYPE_NUMBER_FLAG_SIGNED, + waitForPositiveButton = false, + allowEmpty = false + ) { dialog, number -> + val inputField = dialog.getInputField() + val tempValue = number.toString().toIntOrNull() + + if (tempValue != null && tempValue in -9999..0) { + inputField.error = null + value = tempValue + } else { + inputField.error = "Must be between -9999 and 0!" + } + dialog.setActionButtonEnabled(WhichButton.POSITIVE, value in -9999..0) + } + .positiveButton(android.R.string.ok) { + preferences.ehTagFilterValue().set(value) + summary = "You can soft filter tags by adding them to the \"My Tags\" E/ExHentai page with a negative weight. If a gallery has tags that add up to weight below this value, it is filtered from view. This threshold can be set between 0 and -9999. Currently: $value" + preferences.ehTagFilterValue().reconfigure() + } + .show() + } + }.dependency = PreferenceKeys.eh_enableExHentai + + preference { + title = "Tag Watching Threshold" + key = PreferenceKeys.eh_tag_watching_value + defaultValue = 0 + + var value = preferences.ehTagWatchingValue().get() + + summary = "Recently uploaded galleries will be included on the watched screen if it has at least one watched tag with positive weight, and the sum of weights on its watched tags add up to this value or higher. This threshold can be set between 0 and 9999. Currently: $value" + + onClick { + MaterialDialog(activity!!) + .title(text = "Tag Watching Threshold") + .input( + inputType = InputType.TYPE_NUMBER_FLAG_SIGNED, + maxLength = 4, + waitForPositiveButton = false, + allowEmpty = false + ) { dialog, number -> + val inputField = dialog.getInputField() + val tempValue = number.toString().toIntOrNull() + + if (tempValue != null && tempValue in 0..9999) { + inputField.error = null + value = tempValue + } else { + inputField.error = "Must be between 0 and 9999!" + } + dialog.setActionButtonEnabled(WhichButton.POSITIVE, value in 0..9999) + } + .positiveButton(android.R.string.ok) { + preferences.ehTagWatchingValue().set(value) + summary = "Recently uploaded galleries will be included on the watched screen if it has at least one watched tag with positive weight, and the sum of weights on its watched tags add up to this value or higher. This threshold can be set between 0 and 9999. Currently: $value" + preferences.ehTagWatchingValue().reconfigure() + } + .show() + } + }.dependency = PreferenceKeys.eh_enableExHentai + switchPreference { defaultValue = true key = "secure_exh" diff --git a/app/src/main/java/exh/uconfig/EhUConfigBuilder.kt b/app/src/main/java/exh/uconfig/EhUConfigBuilder.kt index 45d624a78..446f51d30 100644 --- a/app/src/main/java/exh/uconfig/EhUConfigBuilder.kt +++ b/app/src/main/java/exh/uconfig/EhUConfigBuilder.kt @@ -60,6 +60,9 @@ class EhUConfigBuilder { configItems += Entry.UseMPV() configItems += Entry.ShowPopularRightNowPane() + configItems += Entry.TagFilteringThreshold(prefs.ehTagFilterValue().get()) + configItems += Entry.TagWatchingThreshold(prefs.ehTagWatchingValue().get()) + // Actually build form body val formBody = FormBody.Builder() configItems.forEach { @@ -138,6 +141,16 @@ object Entry { override val key = "pp" override val value = "1" } + + class TagFilteringThreshold(value: Int) : ConfigItem { + override val key = "tf" + override val value = "$value" + } + + class TagWatchingThreshold(value: Int) : ConfigItem { + override val key = "wt" + override val value = "$value" + } } interface ConfigItem {