Skip to content

Commit

Permalink
new color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Dec 10, 2023
1 parent 0a2ecdd commit 6c31071
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
60 changes: 32 additions & 28 deletions app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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.*
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
Expand All @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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<com.skydoves.colorpickerview.ColorPickerView>(R.id.colorPickerView)
colorPickerView.setColorListener(ColorListener { color, fromUser ->
val linearLayout = dialogView.findViewById<LinearLayout>(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<Int>("settings_def_anime_source_s")?.let { if (it >= AnimeSources.names.size) 0 else it } ?: 0
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/res/layout/dialog_color_picker.xml

This file was deleted.

0 comments on commit 6c31071

Please sign in to comment.