Revamped Dialog
This commit is contained in:
parent
6fd4033431
commit
b9a4c01a91
41 changed files with 539 additions and 547 deletions
|
@ -31,9 +31,8 @@ dependencies {
|
|||
implementation 'androidx.preference:preference:1.1.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
// Used for the list preference classes
|
||||
implementation 'com.afollestad.material-dialogs:core:3.1.1'
|
||||
implementation 'com.afollestad.material-dialogs:input:3.1.1'
|
||||
implementation 'com.afollestad.material-dialogs:color:3.1.1'
|
||||
implementation 'com.afollestad.material-dialogs:bottomsheets:3.1.1'
|
||||
def material_dialog_version = "0.9.6.0"
|
||||
implementation "com.afollestad.material-dialogs:core:$material_dialog_version"
|
||||
implementation "com.afollestad.material-dialogs:commons:$material_dialog_version"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
}
|
||||
|
|
|
@ -4,16 +4,14 @@ import android.annotation.SuppressLint
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Color
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.CheckResult
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.*
|
||||
import androidx.annotation.IntRange
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
@ -183,7 +181,10 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
|
|||
|
||||
@CheckResult
|
||||
fun prefs(context: Context): SharedPreferences {
|
||||
return context.getSharedPreferences(ThemeStorePrefKeys.CONFIG_PREFS_KEY_DEFAULT, Context.MODE_PRIVATE)
|
||||
return context.getSharedPreferences(
|
||||
ThemeStorePrefKeys.CONFIG_PREFS_KEY_DEFAULT,
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
}
|
||||
|
||||
fun markChanged(context: Context) {
|
||||
|
@ -224,12 +225,18 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
|
|||
fun navigationBarColor(context: Context): Int {
|
||||
return if (!coloredNavigationBar(context)) {
|
||||
Color.BLACK
|
||||
} else prefs(context).getInt(ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR, primaryColor(context))
|
||||
} else prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR,
|
||||
primaryColor(context)
|
||||
)
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
fun coloredStatusBar(context: Context): Boolean {
|
||||
return prefs(context).getBoolean(ThemeStorePrefKeys.KEY_APPLY_PRIMARYDARK_STATUSBAR, true)
|
||||
return prefs(context).getBoolean(
|
||||
ThemeStorePrefKeys.KEY_APPLY_PRIMARYDARK_STATUSBAR,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
|
@ -247,6 +254,42 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
|
|||
return prefs(context).getBoolean(ThemeStorePrefKeys.IS_CONFIGURED_KEY, false)
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
@ColorInt
|
||||
fun textColorPrimary(context: Context): Int {
|
||||
return prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY,
|
||||
resolveColor(context, android.R.attr.textColorPrimary)
|
||||
)
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
@ColorInt
|
||||
fun textColorPrimaryInverse(context: Context): Int {
|
||||
return prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY_INVERSE,
|
||||
resolveColor(context, android.R.attr.textColorPrimaryInverse)
|
||||
)
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
@ColorInt
|
||||
fun textColorSecondary(context: Context): Int {
|
||||
return prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY,
|
||||
resolveColor(context, android.R.attr.textColorSecondary)
|
||||
)
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
@ColorInt
|
||||
fun textColorSecondaryInverse(context: Context): Int {
|
||||
return prefs(context).getInt(
|
||||
ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY_INVERSE,
|
||||
resolveColor(context, android.R.attr.textColorSecondaryInverse)
|
||||
)
|
||||
}
|
||||
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
fun isConfigured(
|
||||
context: Context, @IntRange(
|
||||
|
|
|
@ -36,7 +36,6 @@ class ATEColorPreference @JvmOverloads constructor(
|
|||
private var border: Int = 0
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.ate_preference_custom_support
|
||||
widgetLayoutResource = R.layout.ate_preference_color
|
||||
isPersistent = false
|
||||
|
||||
|
|
|
@ -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.prefs.supportv7
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.EditTextPreference
|
||||
import code.name.monkey.appthemehelper.R
|
||||
|
||||
class ATEEditTextPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0,
|
||||
defStyleRes: Int = 0
|
||||
) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.ate_preference_custom_support
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@ package code.name.monkey.appthemehelper.common.prefs.supportv7
|
|||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.ListPreference
|
||||
import code.name.monkey.appthemehelper.R.layout
|
||||
|
||||
class ATEListPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -26,7 +25,6 @@ class ATEListPreference @JvmOverloads constructor(
|
|||
) : ListPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
init {
|
||||
layoutResource = layout.ate_preference_custom_support
|
||||
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty()) {
|
||||
summary = "%s"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package code.name.monkey.appthemehelper.common.prefs.supportv7;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat;
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment;
|
||||
|
||||
import static androidx.preference.PreferenceFragmentCompat.*;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class ATEPreferenceFragmentCompat extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onDisplayPreferenceDialog(Preference preference) {
|
||||
if (getCallbackFragment() instanceof OnPreferenceDisplayDialogCallback) {
|
||||
((OnPreferenceDisplayDialogCallback) getCallbackFragment()).onPreferenceDisplayDialog(this, preference);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getActivity() instanceof OnPreferenceDisplayDialogCallback) {
|
||||
((OnPreferenceDisplayDialogCallback) this.getActivity()).onPreferenceDisplayDialog(this, preference);
|
||||
return;
|
||||
}
|
||||
|
||||
if (getFragmentManager().findFragmentByTag("androidx.preference.PreferenceFragment.DIALOG") == null) {
|
||||
DialogFragment dialogFragment = onCreatePreferenceDialog(preference);
|
||||
|
||||
if (dialogFragment != null) {
|
||||
dialogFragment.setTargetFragment(this, 0);
|
||||
dialogFragment.show(this.getFragmentManager(), "androidx.preference.PreferenceFragment.DIALOG");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.onDisplayPreferenceDialog(preference);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DialogFragment onCreatePreferenceDialog(Preference preference) {
|
||||
if (preference instanceof ATEListPreference) {
|
||||
return ATEListPreferenceDialogFragmentCompat.newInstance(preference.getKey());
|
||||
} else if (preference instanceof ATEDialogPreference) {
|
||||
return ATEPreferenceDialogFragment.newInstance(preference.getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,60 +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.prefs.supportv7
|
||||
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() {
|
||||
|
||||
override fun onDisplayPreferenceDialog(preference: Preference) {
|
||||
if (callbackFragment is OnPreferenceDisplayDialogCallback) {
|
||||
(callbackFragment as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
||||
return
|
||||
}
|
||||
|
||||
if (activity is OnPreferenceDisplayDialogCallback) {
|
||||
(activity as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
||||
return
|
||||
}
|
||||
|
||||
if (fragmentManager?.findFragmentByTag("android.support.v7.preference.PreferenceFragment.DIALOG") == null) {
|
||||
val dialogFragment = onCreatePreferenceDialog(preference)
|
||||
|
||||
if (dialogFragment != null) {
|
||||
dialogFragment.setTargetFragment(this, 0)
|
||||
dialogFragment.show(fragmentManager!!, "android.support.v7.preference.PreferenceFragment.DIALOG")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
super.onDisplayPreferenceDialog(preference)
|
||||
}
|
||||
|
||||
open fun onCreatePreferenceDialog(preference: Preference): DialogFragment? {
|
||||
if (preference is ATEListPreference) {
|
||||
return ATEListPreferenceDialogFragmentCompat.newInstance(preference.getKey())
|
||||
} else if (preference is ATEDialogPreference) {
|
||||
return ATEPreferenceDialogFragment.newInstance(preference.getKey())
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
|
||||
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.ListPreference;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
@ -25,13 +25,13 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference;
|
||||
|
||||
/**
|
||||
* Created by hemanths on 2019-09-03.
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment {
|
||||
private static final String TAG = "ATEPreferenceDialog";
|
||||
private int mClickedDialogEntryIndex;
|
||||
|
||||
@NonNull
|
||||
public static ATEListPreferenceDialogFragmentCompat newInstance(@NonNull String key) {
|
||||
public static ATEListPreferenceDialogFragmentCompat newInstance(String key) {
|
||||
final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat();
|
||||
final Bundle b = new Bundle(1);
|
||||
b.putString(ARG_KEY, key);
|
||||
|
@ -44,7 +44,7 @@ public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFr
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(@NonNull MaterialAlertDialogBuilder builder) {
|
||||
protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
|
||||
final ListPreference preference = getListPreference();
|
||||
|
@ -55,24 +55,41 @@ public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFr
|
|||
}
|
||||
|
||||
mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue());
|
||||
builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialogInterface, i) -> {
|
||||
mClickedDialogEntryIndex = i;
|
||||
builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialog, which) -> {
|
||||
mClickedDialogEntryIndex = which;
|
||||
onClick(dialog, which);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
builder.setPositiveButton("Ok", null);
|
||||
builder.setNegativeButton("", null);
|
||||
builder.setNeutralButton("", null);
|
||||
/*
|
||||
* The typical interaction for list-based dialogs is to have
|
||||
* click-on-an-item dismiss the dialog instead of the user having to
|
||||
* press 'Ok'.
|
||||
*/
|
||||
builder.setPositiveButton(null, null);
|
||||
builder.setNegativeButton(null, null);
|
||||
builder.setNeutralButton(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
final ListPreference preference = getListPreference();
|
||||
Log.i(TAG, "onDialogClosed: " + positiveResult);
|
||||
if (positiveResult && mClickedDialogEntryIndex >= 0 &&
|
||||
preference.getEntryValues() != null) {
|
||||
String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
|
||||
Log.i(TAG, "onDialogClosed: value " + value);
|
||||
if (preference.callChangeListener(value)) {
|
||||
preference.setValue(value);
|
||||
Log.i(TAG, "onDialogClosed: set value ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.i(TAG, "onClick: " + which);
|
||||
mClickedDialogEntryIndex = which;
|
||||
super.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||
}
|
||||
}
|
|
@ -14,16 +14,17 @@
|
|||
|
||||
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Window;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.DialogPreference;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
@ -33,10 +34,10 @@ import code.name.monkey.appthemehelper.R;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ATEPreferenceDialogFragment extends DialogFragment {
|
||||
|
||||
static final String ARG_KEY = "key";
|
||||
|
||||
public class ATEPreferenceDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
|
||||
protected static final String ARG_KEY = "key";
|
||||
private static final String TAG = "ATEPreferenceDialog";
|
||||
private int mWhichButtonClicked;
|
||||
private DialogPreference mPreference;
|
||||
|
||||
public static ATEPreferenceDialogFragment newInstance(String key) {
|
||||
|
@ -59,34 +60,27 @@ public class ATEPreferenceDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public DialogPreference getPreference() {
|
||||
return this.mPreference;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
MaterialAlertDialogBuilder materialDialog = new MaterialAlertDialogBuilder(requireActivity(),
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
FragmentActivity context = this.getActivity();
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context,
|
||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert)
|
||||
.setTitle(mPreference.getTitle())
|
||||
.setIcon(mPreference.getIcon())
|
||||
.setMessage(mPreference.getDialogMessage())
|
||||
.setPositiveButton(mPreference.getPositiveButtonText(), (dialogInterface, i) -> {
|
||||
onDialogClosed(true);
|
||||
})
|
||||
.setNegativeButton(mPreference.getNegativeButtonText(), (dialogInterface, i) -> {
|
||||
onDialogClosed(false);
|
||||
});
|
||||
.setTitle(this.mPreference.getDialogTitle())
|
||||
.setIcon(this.mPreference.getDialogIcon())
|
||||
.setMessage(this.mPreference.getDialogMessage())
|
||||
.setPositiveButton(this.mPreference.getPositiveButtonText(), this)
|
||||
.setNegativeButton(this.mPreference.getNegativeButtonText(), this);
|
||||
|
||||
//this.onPrepareDialogBuilder(materialDialog);
|
||||
AlertDialog dialog = materialDialog.create();
|
||||
this.onPrepareDialogBuilder(builder);
|
||||
AlertDialog dialog = builder.create();
|
||||
if (this.needInputMethod()) {
|
||||
this.requestInputMethod(dialog);
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
|
||||
public DialogPreference getPreference() {
|
||||
return this.mPreference;
|
||||
}
|
||||
|
||||
protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
|
||||
|
@ -100,4 +94,22 @@ public class ATEPreferenceDialogFragment extends DialogFragment {
|
|||
Window window = dialog.getWindow();
|
||||
window.setSoftInputMode(5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
Log.i(TAG, "onDismiss: " + mWhichButtonClicked);
|
||||
onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE);
|
||||
}
|
||||
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.i(TAG, "onClick: " + which);
|
||||
mWhichButtonClicked = which;
|
||||
onDialogClosed(which == DialogInterface.BUTTON_POSITIVE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package code.name.monkey.appthemehelper.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark
|
||||
import com.afollestad.materialdialogs.internal.ThemeSingleton
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
object MaterialDialogsUtil {
|
||||
fun updateMaterialDialogsThemeSingleton(context: Context) {
|
||||
val md = ThemeSingleton.get()
|
||||
md.titleColor = ThemeStore.textColorPrimary(context)
|
||||
md.contentColor = ThemeStore.textColorSecondary(context)
|
||||
md.itemColor = md.titleColor
|
||||
md.widgetColor = ThemeStore.accentColor(context)
|
||||
md.linkColor = ColorStateList.valueOf(md.widgetColor)
|
||||
md.positiveColor = ColorStateList.valueOf(md.widgetColor)
|
||||
md.neutralColor = ColorStateList.valueOf(md.widgetColor)
|
||||
md.negativeColor = ColorStateList.valueOf(md.widgetColor)
|
||||
md.darkTheme = isWindowBackgroundDark(context)
|
||||
}
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
package code.name.monkey.appthemehelper.util
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import com.afollestad.materialdialogs.internal.button.DialogActionButton
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
|
||||
|
@ -54,30 +52,4 @@ object MaterialUtil {
|
|||
textInputLayout.isHintAnimationEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
fun setTint(
|
||||
button: DialogActionButton,
|
||||
color: Int = ThemeStore.accentColor(button.context),
|
||||
background: Boolean = true
|
||||
) {
|
||||
val temp = button as AppCompatButton
|
||||
val context = temp.context
|
||||
val colorState = ColorStateList.valueOf(color)
|
||||
val textColor =
|
||||
ColorStateList.valueOf(
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
context,
|
||||
ColorUtil.isColorLight(color)
|
||||
)
|
||||
)
|
||||
|
||||
if (background) {
|
||||
temp.backgroundTintList = colorState
|
||||
temp.setTextColor(textColor)
|
||||
} else {
|
||||
temp.setTextColor(colorState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue