From 6c310713d684527bb88d1c04b2b66d7f8dd398dc Mon Sep 17 00:00:00 2001 From: Finnley Somdahl <87634197+rebelonion@users.noreply.github.com> Date: Sat, 9 Dec 2023 21:20:19 -0600 Subject: [PATCH] new color picker --- app/build.gradle | 2 +- .../ani/dantotsu/settings/SettingsActivity.kt | 60 ++++++++++--------- .../main/res/layout/dialog_color_picker.xml | 16 ----- 3 files changed, 33 insertions(+), 45 deletions(-) delete mode 100644 app/src/main/res/layout/dialog_color_picker.xml diff --git a/app/build.gradle b/app/build.gradle index 1cde5bdb..0f029289 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -100,7 +100,7 @@ dependencies { implementation 'com.alexvasilkov:gesture-views:2.8.3' implementation 'com.github.VipulOG:ebook-reader:0.1.6' implementation 'androidx.paging:paging-runtime-ktx:3.2.1' - implementation "com.github.skydoves:colorpickerview:2.3.0" + implementation 'com.github.eltos:simpledialogfragments:v3.7' // string matching implementation 'me.xdrop:fuzzywuzzy:1.4.0' diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt index 6d1e70df..0a42d553 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.app.AlertDialog import android.content.Context import android.content.Intent +import android.graphics.Color import android.graphics.drawable.Animatable import android.os.Build.* import android.os.Build.VERSION.* @@ -11,7 +12,6 @@ import android.os.Bundle import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter -import android.widget.LinearLayout import android.widget.TextView import android.widget.Toast import androidx.activity.OnBackPressedCallback @@ -37,7 +37,9 @@ import ani.dantotsu.subcriptions.Subscription.Companion.timeMinutes import ani.dantotsu.themes.ThemeManager import com.google.android.material.snackbar.Snackbar import com.google.android.material.textfield.TextInputEditText -import com.skydoves.colorpickerview.listeners.ColorListener +import eltos.simpledialogfragment.SimpleDialog +import eltos.simpledialogfragment.SimpleDialog.OnDialogResultListener.BUTTON_POSITIVE +import eltos.simpledialogfragment.color.SimpleColorDialog import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.network.NetworkPreferences import io.noties.markwon.Markwon @@ -50,7 +52,7 @@ import uy.kohesive.injekt.api.get import kotlin.random.Random -class SettingsActivity : AppCompatActivity() { +class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListener { private val restartMainActivity = object : OnBackPressedCallback(false) { override fun handleOnBackPressed() = startMainActivity(this@SettingsActivity) } @@ -176,31 +178,21 @@ class SettingsActivity : AppCompatActivity() { binding.customTheme.setOnClickListener { - var passedColor: Int = 0 - val dialogView = layoutInflater.inflate(R.layout.dialog_color_picker, null) - val alertDialog = AlertDialog.Builder(this, R.style.MyPopup) - .setTitle("Custom Theme") - .setView(dialogView) - .setPositiveButton("OK") { dialog, _ -> - getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() - .putInt("custom_theme_int", passedColor).apply() - logger("Custom Theme: $passedColor") - dialog.dismiss() - restartApp() - } - .setNegativeButton("Cancel") { dialog, _ -> - dialog.dismiss() - } - .create() - val colorPickerView = - dialogView.findViewById(R.id.colorPickerView) - colorPickerView.setColorListener(ColorListener { color, fromUser -> - val linearLayout = dialogView.findViewById(R.id.linear) - passedColor = color - linearLayout.setBackgroundColor(color) - }) - alertDialog.show() - alertDialog.window?.setDimAmount(0.8f) + val originalColor = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt( + "custom_theme_int", + Color.parseColor("#6200EE") + ) + val tag = "colorPicker" + SimpleColorDialog.build() + .title("Custom Theme") + .colorPreset(originalColor) + .colors(this, SimpleColorDialog.BEIGE_COLOR_PALLET) + .allowCustom(true) + .showOutline(0x46000000) + .gridNumColumn(5) + .choiceMode(SimpleColorDialog.SINGLE_CHOICE) + .neg() + .show(this, tag) } //val animeSource = loadData("settings_def_anime_source_s")?.let { if (it >= AnimeSources.names.size) 0 else it } ?: 0 @@ -770,6 +762,18 @@ class SettingsActivity : AppCompatActivity() { } } + override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean { + if (which == BUTTON_POSITIVE) { + if (dialogTag == "colorPicker") { + val color = extras.getInt(SimpleColorDialog.COLOR) + getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() + .putInt("custom_theme_int", color).apply() + logger("Custom Theme: $color") + } + } + return true + } + private fun restartApp() { Snackbar.make( binding.root, diff --git a/app/src/main/res/layout/dialog_color_picker.xml b/app/src/main/res/layout/dialog_color_picker.xml deleted file mode 100644 index f2bfb391..00000000 --- a/app/src/main/res/layout/dialog_color_picker.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - -