Code refactor

This commit is contained in:
h4h13 2020-01-28 23:17:48 +05:30
parent fdb2ab300e
commit 08033d6a16
31 changed files with 196 additions and 147 deletions

View file

@ -151,7 +151,7 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:3.8.0' implementation 'com.github.bumptech.glide:glide:3.8.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:1.5.0' implementation 'com.github.bumptech.glide:okhttp3-integration:1.5.0'
debugImplementation 'com.squareup.okhttp3:logging-interceptor:3.6.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
implementation('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar') { implementation('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar') {
transitive = true transitive = true

View file

@ -145,7 +145,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
} }
private fun setupToolbar() { private fun setupToolbar() {
toolbar.apply { toolbar.apply {
backgroundTintList = ColorStateList.valueOf(ATHUtil.resolveColor(requireContext(), R.attr.colorSurface)) backgroundTintList = ColorStateList.valueOf(ATHUtil.resolveColor(requireContext(), R.attr.colorSurface))
setNavigationIcon(R.drawable.ic_menu_white_24dp) setNavigationIcon(R.drawable.ic_menu_white_24dp)

View file

@ -32,7 +32,7 @@ import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.list.listItems import com.afollestad.materialdialogs.list.listItems
import java.io.File import java.io.File
import java.util.* import java.util.ArrayList
class BlacklistPreference : ATEDialogPreference { class BlacklistPreference : ATEDialogPreference {
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@ -67,7 +67,7 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
dismiss() dismiss()
} }
neutralButton(text = getString(R.string.clear_action)) { neutralButton(text = getString(R.string.clear_action)) {
MaterialDialog(context, BottomSheet(LayoutMode.WRAP_CONTENT)).show { MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT)).show {
title(code.name.monkey.retromusic.R.string.clear_blacklist) title(code.name.monkey.retromusic.R.string.clear_blacklist)
message(code.name.monkey.retromusic.R.string.do_you_want_to_clear_the_blacklist) message(code.name.monkey.retromusic.R.string.do_you_want_to_clear_the_blacklist)
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner) cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)

View file

@ -47,8 +47,10 @@
android:id="@+id/toolbarContainer" android:id="@+id/toolbarContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardBackgroundColor="?colorSurface"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true" app:cardUseCompatPadding="true"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"> app:layout_scrollFlags="scroll|enterAlways">
<FrameLayout <FrameLayout

View file

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/rectSelector"
android:minHeight="72dp"
android:orientation="horizontal"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="PrivateResource">
<androidx.appcompat.widget.AppCompatImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?attr/colorControlNormal"
tools:srcCompat="@drawable/ic_telegram_white" />
<com.google.android.material.textview.MaterialTextView
android:id="@android:id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="@style/TextViewSubtitle1"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toStartOf="@android:id/widget_frame"
app:layout_constraintStart_toStartOf="@+id/guideline_front_margin"
app:layout_constraintTop_toTopOf="parent"
tools:maxLines="@string/grid_size_1"
tools:text="@tools:sample/lorem" />
<code.name.monkey.retromusic.views.BaselineGridTextView
android:id="@android:id/summary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textColor="?android:attr/textColorSecondary"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toStartOf="@android:id/widget_frame"
app:layout_constraintStart_toStartOf="@+id/guideline_front_margin"
app:layout_constraintTop_toBottomOf="@android:id/title"
app:lineHeightHint="20sp"
tools:maxLines="2"
tools:text="@tools:sample/lorem/random" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_front_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="52dp" />
<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end|center_vertical"
android:gravity="center_vertical"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -21,7 +21,7 @@
android:id="@android:id/title" android:id="@android:id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="72dp" android:paddingStart="70dp"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:textAppearance="@style/TextViewOverline" android:textAppearance="@style/TextViewOverline"

View file

@ -27,7 +27,7 @@
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference
android:key="accent_color" android:key="accent_color"
android:layout="@layout/list_item_view" android:layout="@layout/list_item_color_view"
android:persistent="false" android:persistent="false"
android:summary="@string/accent_color_desc" android:summary="@string/accent_color_desc"
android:title="@string/accent_color" android:title="@string/accent_color"

View file

@ -23,8 +23,6 @@
android:summary="@string/pref_summary_home_banner" android:summary="@string/pref_summary_home_banner"
android:title="@string/pref_title_home_banner" /> android:title="@string/pref_title_home_banner" />
</code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory> </code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory

View file

@ -21,10 +21,10 @@ import android.view.View
import code.name.monkey.appthemehelper.R import code.name.monkey.appthemehelper.R
class ATEColorPreference @JvmOverloads constructor( class ATEColorPreference @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0, defStyleAttr: Int = 0,
defStyleRes: Int = 0 defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes) { ) : Preference(context, attrs, defStyleAttr, defStyleRes) {
private var mView: View? = null private var mView: View? = null

View file

@ -7,14 +7,17 @@ import android.graphics.Paint
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.R import code.name.monkey.appthemehelper.R
import kotlin.math.min
class BorderCircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) { class BorderCircleView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
private val mCheck: Drawable? = ContextCompat.getDrawable(context, R.drawable.ate_check) private val mCheck: Drawable? = ContextCompat.getDrawable(context, R.drawable.ate_check)
private val paint: Paint = Paint() private val paint: Paint = Paint()
@ -49,14 +52,14 @@ class BorderCircleView @JvmOverloads constructor(context: Context, attrs: Attrib
} }
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val widthMode = View.MeasureSpec.getMode(widthMeasureSpec) val widthMode = MeasureSpec.getMode(widthMeasureSpec)
val heightMode = View.MeasureSpec.getMode(heightMeasureSpec) val heightMode = MeasureSpec.getMode(heightMeasureSpec)
if (widthMode == View.MeasureSpec.EXACTLY && heightMode != View.MeasureSpec.EXACTLY) { if (widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) {
val width = View.MeasureSpec.getSize(widthMeasureSpec) val width = MeasureSpec.getSize(widthMeasureSpec)
var height = width var height = width
if (heightMode == View.MeasureSpec.AT_MOST) { if (heightMode == MeasureSpec.AT_MOST) {
height = Math.min(height, View.MeasureSpec.getSize(heightMeasureSpec)) height = min(height, MeasureSpec.getSize(heightMeasureSpec))
} }
setMeasuredDimension(width, height) setMeasuredDimension(width, height)
} else { } else {
@ -73,8 +76,18 @@ class BorderCircleView @JvmOverloads constructor(context: Context, attrs: Attrib
} }
val circleCenter = (canvasSize - borderWidth * 2) / 2 val circleCenter = (canvasSize - borderWidth * 2) / 2
canvas.drawCircle((circleCenter + borderWidth).toFloat(), (circleCenter + borderWidth).toFloat(), (canvasSize - borderWidth * 2) / 2 + borderWidth - 4.0f, paintBorder) canvas.drawCircle(
canvas.drawCircle((circleCenter + borderWidth).toFloat(), (circleCenter + borderWidth).toFloat(), (canvasSize - borderWidth * 2) / 2 - 4.0f, paint) (circleCenter + borderWidth).toFloat(),
(circleCenter + borderWidth).toFloat(),
(canvasSize - borderWidth * 2) / 2 + borderWidth - 4.0f,
paintBorder
)
canvas.drawCircle(
(circleCenter + borderWidth).toFloat(),
(circleCenter + borderWidth).toFloat(),
(canvasSize - borderWidth * 2) / 2 - 4.0f,
paint
)
if (isActivated) { if (isActivated) {
val offset = canvasSize / 2 - mCheck!!.intrinsicWidth / 2 val offset = canvasSize / 2 - mCheck!!.intrinsicWidth / 2

View file

@ -25,9 +25,9 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.prefs.BorderCircleView import code.name.monkey.appthemehelper.common.prefs.BorderCircleView
class ATEColorPreference @JvmOverloads constructor( class ATEColorPreference @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : Preference(context, attrs, defStyleAttr) { ) : Preference(context, attrs, defStyleAttr) {
private var mView: View? = null private var mView: View? = null

View file

@ -19,12 +19,7 @@ import android.util.AttributeSet
import androidx.preference.DialogPreference import androidx.preference.DialogPreference
open class ATEDialogPreference @JvmOverloads constructor( open class ATEDialogPreference @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0, defStyleRes: Int = 0 defStyleAttr: Int = 0, defStyleRes: Int = 0
) : DialogPreference(context, attrs, defStyleAttr, defStyleRes) { ) : DialogPreference(context, attrs, defStyleAttr, defStyleRes)
init {
}
}

View file

@ -20,10 +20,10 @@ import androidx.preference.EditTextPreference
import code.name.monkey.appthemehelper.R import code.name.monkey.appthemehelper.R
class ATEEditTextPreference @JvmOverloads constructor( class ATEEditTextPreference @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0, defStyleAttr: Int = 0,
defStyleRes: Int = 0 defStyleRes: Int = 0
) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) { ) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
init { init {

View file

@ -16,9 +16,7 @@ package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import code.name.monkey.appthemehelper.R; import code.name.monkey.appthemehelper.R;
public class ATEListPreference extends ListPreference { public class ATEListPreference extends ListPreference {
@ -45,7 +43,8 @@ public class ATEListPreference extends ListPreference {
private void init(Context context, AttributeSet attrs) { private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support); setLayoutResource(R.layout.ate_preference_custom_support);
if (getSummary() == null || getSummary().toString().trim().isEmpty()) if (getSummary() == null || getSummary().toString().trim().isEmpty()) {
setSummary("%s"); setSummary("%s");
}
} }
} }

View file

@ -21,14 +21,13 @@ import androidx.preference.Preference
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
class ATEPreference @JvmOverloads constructor( class ATEPreference @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0, defStyleAttr: Int = 0,
defStyleRes: Int = 0 defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes) { ) : Preference(context, attrs, defStyleAttr, defStyleRes) {
init { init {
icon?.setColorFilter(ThemeStore.textColorSecondary(context), PorterDuff.Mode.SRC_IN) icon?.setColorFilter(ThemeStore.textColorSecondary(context), PorterDuff.Mode.SRC_IN)
} }
} }

View file

@ -22,11 +22,12 @@ import androidx.preference.PreferenceViewHolder
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
class ATEPreferenceCategory @JvmOverloads constructor( class ATEPreferenceCategory @JvmOverloads constructor(
context: Context?, context: Context?,
attrs: AttributeSet?, attrs: AttributeSet?,
defStyleAttr: Int = -1, defStyleAttr: Int = -1,
defStyleRes: Int = -1 defStyleRes: Int = -1
) : PreferenceCategory(context, attrs, defStyleAttr, defStyleRes) { ) : PreferenceCategory(context, attrs, defStyleAttr, defStyleRes) {
override fun onBindViewHolder(holder: PreferenceViewHolder) { override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder) super.onBindViewHolder(holder)
val title = holder.itemView.findViewById<TextView>(android.R.id.title) val title = holder.itemView.findViewById<TextView>(android.R.id.title)

View file

@ -14,18 +14,17 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7 package code.name.monkey.appthemehelper.common.prefs.supportv7
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment
/** /**
* @author Karim Abou Zeid (kabouzeid) * @author Karim Abou Zeid (kabouzeid)
*/ */
abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() { abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() {
override fun onDisplayPreferenceDialog(preference: Preference) { override fun onDisplayPreferenceDialog(preference: Preference) {
if (callbackFragment is OnPreferenceDisplayDialogCallback) { if (callbackFragment is OnPreferenceDisplayDialogCallback) {
(callbackFragment as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference) (callbackFragment as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)

View file

@ -23,7 +23,12 @@ class ATESeekBarPreference : SeekBarPreference {
init() init()
} }
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(
context,
attrs,
defStyleAttr,
defStyleRes
) {
init() init()
} }

View file

@ -21,9 +21,9 @@ import androidx.appcompat.widget.AppCompatTextView
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
class ATEAccentTextView @JvmOverloads constructor( class ATEAccentTextView @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr) { ) : AppCompatTextView(context, attrs, defStyleAttr) {
init { init {

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.appthemehelper.common.views
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatCheckBox
import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.ThemeStore
class ATECheckBox @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatCheckBox(context, attrs, defStyleAttr) {
init {
ATH.setTint(this, ThemeStore.accentColor(context))
}
}

View file

@ -16,14 +16,13 @@ package code.name.monkey.appthemehelper.common.views
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
class ATEPrimaryTextView @JvmOverloads constructor( class ATEPrimaryTextView @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : MaterialTextView(context, attrs, defStyleAttr) { ) : MaterialTextView(context, attrs, defStyleAttr) {
init { init {

View file

@ -20,9 +20,9 @@ import code.name.monkey.appthemehelper.ThemeStore
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
class ATESecondaryTextView @JvmOverloads constructor( class ATESecondaryTextView @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : MaterialTextView(context, attrs, defStyleAttr) { ) : MaterialTextView(context, attrs, defStyleAttr) {
init { init {

View file

@ -7,7 +7,6 @@ import androidx.appcompat.widget.SwitchCompat
import code.name.monkey.appthemehelper.ATH import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
*/ */

View file

@ -26,8 +26,12 @@ object ATHUtil {
try { try {
return Class.forName(clsName) return Class.forName(clsName)
} catch (t: Throwable) { } catch (t: Throwable) {
throw IllegalStateException(String.format("%s is not in your class path! You must include the associated library.", clsName)) throw IllegalStateException(
String.format(
"%s is not in your class path! You must include the associated library.",
clsName
)
)
} }
} }
} }

View file

@ -4,7 +4,6 @@ import android.graphics.Color
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.FloatRange import androidx.annotation.FloatRange
object ColorUtil { object ColorUtil {
fun desaturateColor(color: Int, ratio: Float): Int { fun desaturateColor(color: Int, ratio: Float): Int {
val hsv = FloatArray(3) val hsv = FloatArray(3)
@ -14,6 +13,7 @@ object ColorUtil {
return Color.HSVToColor(hsv) return Color.HSVToColor(hsv)
} }
fun stripAlpha(@ColorInt color: Int): Int { fun stripAlpha(@ColorInt color: Int): Int {
return -0x1000000 or color return -0x1000000 or color
} }
@ -79,7 +79,6 @@ object ColorUtil {
return Color.argb(a.toInt(), r.toInt(), g.toInt(), b.toInt()) return Color.argb(a.toInt(), r.toInt(), g.toInt(), b.toInt())
} }
private fun getColorDarkness(@ColorInt color: Int): Double { private fun getColorDarkness(@ColorInt color: Int): Double {
return if (color == Color.BLACK) return if (color == Color.BLACK)
1.0 1.0
@ -104,9 +103,9 @@ object ColorUtil {
@ColorInt @ColorInt
fun getMixedColor(@ColorInt color1: Int, @ColorInt color2: Int): Int { fun getMixedColor(@ColorInt color1: Int, @ColorInt color2: Int): Int {
return Color.rgb( return Color.rgb(
(Color.red(color1) + Color.red(color2)) / 2, (Color.red(color1) + Color.red(color2)) / 2,
(Color.green(color1) + Color.green(color2)) / 2, (Color.green(color1) + Color.green(color2)) / 2,
(Color.blue(color1) + Color.blue(color2)) / 2 (Color.blue(color1) + Color.blue(color2)) / 2
) )
} }

View file

@ -5,7 +5,6 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.TransitionDrawable import android.graphics.drawable.TransitionDrawable
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
object DrawableUtil { object DrawableUtil {
fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable { fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable {

View file

@ -7,17 +7,19 @@ import com.afollestad.materialdialogs.internal.button.DialogActionButton
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
object MaterialUtil { object MaterialUtil {
@JvmOverloads @JvmOverloads
fun setTint(button: MaterialButton, background: Boolean = true, fun setTint(
color: Int = ThemeStore.accentColor(button.context)) { button: MaterialButton, background: Boolean = true,
color: Int = ThemeStore.accentColor(button.context)
) {
button.isAllCaps = false button.isAllCaps = false
val context = button.context val context = button.context
val colorState = ColorStateList.valueOf(color) val colorState = ColorStateList.valueOf(color)
val textColor = ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color))) val textColor =
ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color)))
if (background) { if (background) {
@ -28,7 +30,6 @@ object MaterialUtil {
button.setTextColor(colorState) button.setTextColor(colorState)
button.iconTint = colorState button.iconTint = colorState
} }
} }
fun setTint(textInputLayout: TextInputLayout, background: Boolean = true) { fun setTint(textInputLayout: TextInputLayout, background: Boolean = true) {
@ -44,14 +45,18 @@ object MaterialUtil {
textInputLayout.defaultHintTextColor = colorState textInputLayout.defaultHintTextColor = colorState
textInputLayout.isHintAnimationEnabled = true textInputLayout.isHintAnimationEnabled = true
} }
} }
fun setTint(button: DialogActionButton, color: Int = ThemeStore.accentColor(button.context), background: Boolean = true) { fun setTint(
button: DialogActionButton,
color: Int = ThemeStore.accentColor(button.context),
background: Boolean = true
) {
val temp = button as AppCompatButton val temp = button as AppCompatButton
val context = temp.context val context = temp.context
val colorState = ColorStateList.valueOf(color) val colorState = ColorStateList.valueOf(color)
val textColor = ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color))) val textColor =
ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color)))
if (background) { if (background) {
temp.backgroundTintList = colorState temp.backgroundTintList = colorState

View file

@ -7,7 +7,6 @@ import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.R import code.name.monkey.appthemehelper.R
object MaterialValueHelper { object MaterialValueHelper {
@SuppressLint("PrivateResource") @SuppressLint("PrivateResource")

View file

@ -12,30 +12,41 @@ import com.google.android.material.navigation.NavigationView
object NavigationViewUtil { object NavigationViewUtil {
fun setItemIconColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) { fun setItemIconColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val iconSl = ColorStateList(arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)), intArrayOf(normalColor, selectedColor)) val iconSl = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
), intArrayOf(normalColor, selectedColor)
)
navigationView.itemIconTintList = iconSl navigationView.itemIconTintList = iconSl
val drawable = navigationView.itemBackground val drawable = navigationView.itemBackground
navigationView.itemBackground = TintHelper.createTintedDrawable(drawable, ColorUtil.withAlpha(ThemeStore.accentColor(navigationView.context), 0.2f)) navigationView.itemBackground = TintHelper.createTintedDrawable(
drawable,
ColorUtil.withAlpha(ThemeStore.accentColor(navigationView.context), 0.2f)
)
} }
fun setItemTextColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) { fun setItemTextColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val textSl = ColorStateList( val textSl = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)), arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)),
intArrayOf(normalColor, selectedColor)) intArrayOf(normalColor, selectedColor)
)
navigationView.itemTextColor = textSl navigationView.itemTextColor = textSl
} }
fun setItemIconColors(bottomNavigationView: BottomNavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) { fun setItemIconColors(bottomNavigationView: BottomNavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val iconSl = ColorStateList( val iconSl = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)), arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)),
intArrayOf(normalColor, selectedColor)) intArrayOf(normalColor, selectedColor)
)
bottomNavigationView.itemIconTintList = iconSl bottomNavigationView.itemIconTintList = iconSl
} }
fun setItemTextColors(bottomNavigationView: BottomNavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) { fun setItemTextColors(bottomNavigationView: BottomNavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val textSl = ColorStateList( val textSl = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)), arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)),
intArrayOf(normalColor, selectedColor)) intArrayOf(normalColor, selectedColor)
)
bottomNavigationView.itemTextColor = textSl bottomNavigationView.itemTextColor = textSl
} }
} }

View file

@ -1,23 +0,0 @@
package code.name.monkey.appthemehelper.util
import android.content.res.ColorStateList
import androidx.annotation.ColorInt
import com.google.android.material.tabs.TabLayout
object TabLayoutUtil {
fun setTabIconColors(tabLayout: TabLayout?, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
if (tabLayout == null)
return
val sl = ColorStateList(arrayOf(intArrayOf(-android.R.attr.state_selected), intArrayOf(android.R.attr.state_selected)),
intArrayOf(normalColor, selectedColor))
for (i in 0 until tabLayout.tabCount) {
val tab = tabLayout.getTabAt(i)
if (tab != null && tab.icon != null) {
tab.icon = TintHelper.createTintedDrawable(tab.icon, sl)
}
}
}
}

View file

@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
object ViewUtil { object ViewUtil {
fun removeOnGlobalLayoutListener(v: View, listener: ViewTreeObserver.OnGlobalLayoutListener) { fun removeOnGlobalLayoutListener(v: View, listener: ViewTreeObserver.OnGlobalLayoutListener) {
v.viewTreeObserver.removeOnGlobalLayoutListener(listener) v.viewTreeObserver.removeOnGlobalLayoutListener(listener)