Fix text views, update queue time

main
h4h13 2019-09-03 23:24:14 +05:30
parent 887b6a4d36
commit 671728b315
22 changed files with 367 additions and 196 deletions

View File

@ -27,14 +27,21 @@ class PlayingQueueActivity : AbsMusicServiceActivity() {
private var playingQueueAdapter: PlayingQueueAdapter? = null
private lateinit var linearLayoutManager: LinearLayoutManager
private val upNextAndQueueTime: String
get() = resources.getString(R.string.up_next) + "" + MusicUtil.getReadableDurationString(MusicPlayerRemote.getQueueDurationMillis(MusicPlayerRemote.position))
protected fun getUpNextAndQueueTime(): String {
val duration = MusicPlayerRemote.getQueueDurationMillis(MusicPlayerRemote.position)
return MusicUtil.buildInfoString(
resources.getString(R.string.up_next),
MusicUtil.getReadableDurationString(duration)
)
}
override fun onCreate(
savedInstanceState: Bundle?
) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_playing_queue)
setContentView(code.name.monkey.retromusic.R.layout.activity_playing_queue)
setStatusbarColorAuto()
setNavigationbarColorAuto()
@ -67,7 +74,7 @@ class PlayingQueueActivity : AbsMusicServiceActivity() {
this,
MusicPlayerRemote.playingQueue,
MusicPlayerRemote.position,
R.layout.item_queue)
code.name.monkey.retromusic.R.layout.item_queue)
wrappedAdapter = recyclerViewDragDropManager!!.createWrappedAdapter(playingQueueAdapter!!)
linearLayoutManager = LinearLayoutManager(this)
@ -107,7 +114,9 @@ class PlayingQueueActivity : AbsMusicServiceActivity() {
updateCurrentSong()
}
private fun updateCurrentSong() {}
private fun updateCurrentSong() {
playerQueueSubHeader.text = getUpNextAndQueueTime()
}
override fun onPlayingMetaChanged() {
updateQueuePosition()
@ -116,6 +125,7 @@ class PlayingQueueActivity : AbsMusicServiceActivity() {
private fun updateQueuePosition() {
playingQueueAdapter!!.setCurrent(MusicPlayerRemote.position)
resetToCurrentPosition()
playerQueueSubHeader.text = getUpNextAndQueueTime()
}
private fun updateQueue() {
@ -141,8 +151,6 @@ class PlayingQueueActivity : AbsMusicServiceActivity() {
recyclerViewDragDropManager = null
}
if (wrappedAdapter != null) {
WrapperAdapterUtils.releaseAll(wrappedAdapter)
wrappedAdapter = null
@ -152,7 +160,7 @@ class PlayingQueueActivity : AbsMusicServiceActivity() {
}
private fun setupToolbar() {
playerQueueSubHeader.text = upNextAndQueueTime
playerQueueSubHeader.text = getUpNextAndQueueTime()
playerQueueSubHeader.setTextColor(ThemeStore.accentColor(this))
applyToolbar(toolbar)

View File

@ -22,9 +22,9 @@ import android.widget.Toast
import androidx.fragment.app.DialogFragment
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat
import code.name.monkey.retromusic.preferences.*
import code.name.monkey.retromusic.util.NavigationUtil
@ -32,7 +32,7 @@ import code.name.monkey.retromusic.util.NavigationUtil
* @author Hemanth S (h4h13).
*/
abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
internal fun showProToastAndNavigate(message: String) {
Toast.makeText(requireContext(), "$message is Pro version feature.", Toast.LENGTH_SHORT).show()
@ -67,7 +67,7 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
invalidateSettings()
}
override fun onDisplayPreferenceDialog(preference: Preference) {
/*override fun onDisplayPreferenceDialog(preference: Preference) {
var dialogFragment: DialogFragment? = null// Dialog creation could not be handled here. Try with the super method.
// The dialog was created (it was one of our custom Preferences), show the dialog for it
when (preference) {
@ -89,5 +89,18 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
// Dialog creation could not be handled here. Try with the super method.
super.onDisplayPreferenceDialog(preference);
}
}*/
override fun onCreatePreferenceDialog(preference: Preference): DialogFragment? {
return when (preference) {
is LibraryPreference -> LibraryPreferenceDialog.newInstance(preference.key)
is NowPlayingScreenPreference -> NowPlayingScreenPreferenceDialog.newInstance(preference.key)
is AlbumCoverStylePreference -> AlbumCoverStylePreferenceDialog.newInstance(preference.key)
is MaterialListPreference -> {
preference.entries
MaterialListPreferenceDialog.newInstance(preference)
}
is BlacklistPreference -> BlacklistPreferenceDialog.newInstance()
else -> super.onCreatePreferenceDialog(preference)
}
}
}

View File

@ -15,15 +15,15 @@
package code.name.monkey.retromusic.fragments.settings
import android.graphics.Color
import android.graphics.Color.BLUE
import android.os.Build
import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.preference.Preference
import androidx.preference.TwoStatePreference
import code.name.monkey.appthemehelper.*
import code.name.monkey.appthemehelper.ACCENT_COLORS
import code.name.monkey.appthemehelper.ACCENT_COLORS_SUB
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.App
@ -49,45 +49,7 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
override fun invalidateSettings() {
val categoryColor: ATEPreferenceCategory? = findPreference("category_color")
val primaryColorPref = ATEColorPreference(preferenceScreen.context)
val primaryColor = ThemeStore.primaryColor(requireContext())
primaryColorPref.apply {
key = "primary_color"
isPersistent = false
setSummary(R.string.primary_color_desc)
setTitle(R.string.primary_color)
isCopyingEnabled = true
setIcon(R.drawable.ic_colorize_white_24dp)
setColor(primaryColor, ColorUtil.darkenColor(primaryColor))
setOnPreferenceClickListener {
materialDialog = MaterialDialog(requireContext(), BottomSheet()).show {
title(R.string.primary_color)
positiveButton(R.string.set)
colorChooser(initialSelection = BLUE,
allowCustomArgb = true,
colors = PRIMARY_COLORS,
subColors = PRIMARY_COLORS_SUB) { _, color ->
val theme = if (ColorUtil.isColorLight(color))
PreferenceUtil.getThemeResFromPrefValue("light")
else
PreferenceUtil.getThemeResFromPrefValue("dark")
ThemeStore.editTheme(requireContext()).activityTheme(theme).primaryColor(color).commit()
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(context).updateDynamicShortcuts()
requireActivity().recreate()
}
}
true
}
}
val generalTheme: Preference? = findPreference("general_theme")
generalTheme?.let {
setSummary(it)
it.setOnPreferenceChangeListener { _, newValue ->
@ -100,17 +62,20 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
setSummary(generalTheme, newValue)
when (theme) {
"light" -> ThemeStore.editTheme(requireContext()).primaryColor(Color.WHITE).commit()
"black" -> ThemeStore.editTheme(requireContext()).primaryColor(Color.BLACK).commit()
"dark" -> ThemeStore.editTheme(requireContext()).primaryColor(ContextCompat.getColor(requireContext(), R.color.md_grey_900)).commit()
"color" -> ThemeStore.editTheme(requireContext()).primaryColor(ContextCompat.getColor(requireContext(), R.color.md_blue_grey_800)).commit()
val color = when (theme) {
"light" -> Color.WHITE
"black" -> Color.BLACK
"dark" -> ContextCompat.getColor(requireContext(), R.color.md_grey_900)
else -> Color.WHITE
}
ThemeStore.editTheme(requireContext())
.activityTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
.primaryColor(color)
.commit()
ThemeStore.markChanged(requireContext())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
requireActivity().setTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
@ -129,10 +94,6 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
title(R.string.accent_color)
positiveButton(R.string.set)
colorChooser(colors = ACCENT_COLORS, allowCustomArgb = true, subColors = ACCENT_COLORS_SUB) { _, color ->
/*var colorFinal = Color.BLACK;
if (!ColorUtil.isColorSaturated(color)) {
colorFinal = color
}*/
ThemeStore.editTheme(requireContext()).accentColor(color).commit()
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
@ -154,10 +115,6 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
true
}
}
if (PreferenceUtil.getInstance().generalTheme == R.style.Theme_RetroMusic_Color && App.isProVersion) {
categoryColor?.addPreference(primaryColorPref)
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

View File

@ -78,20 +78,23 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
val entries = arguments?.getStringArrayList(EXTRA_ENTRIES)
val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES)
materialDialog = MaterialDialog(activity!!, BottomSheet())
.show {
title(text = materialListPreference.title.toString())
positiveButton(R.string.set)
listItemsSingleChoice(items = entries, initialSelection = position, waitForPositiveButton = true) { _, index, _ ->
materialListPreference.callChangeListener(entriesValues!![index])
materialListPreference.setCustomValue(entriesValues[index])
materialListPreference.summary = entries!![index]
dismiss()
}
materialDialog = MaterialDialog(requireContext(), BottomSheet())
.title(text = materialListPreference.title.toString())
.positiveButton(R.string.set)
.listItemsSingleChoice(items = entries, initialSelection = position, waitForPositiveButton = true) { _, index, _ ->
materialListPreference.callChangeListener(entriesValues!![index])
materialListPreference.setCustomValue(entriesValues[index])
materialListPreference.summary = entries!![index]
dismiss()
}
return materialDialog
}
override fun onDestroyView() {
super.onDestroyView()
materialDialog.dismiss()
}
private lateinit var materialDialog: MaterialDialog
override fun onDialogClosed(positiveResult: Boolean) {

View File

@ -150,16 +150,12 @@ public final class PreferenceUtil {
}
@StyleRes
public static int getThemeResFromPrefValue(String themePrefValue) {
public static int getThemeResFromPrefValue(@NonNull String themePrefValue) {
switch (themePrefValue) {
case "light":
return R.style.Theme_RetroMusic_Light;
case "color":
return R.style.Theme_RetroMusic_Color;
case "black":
return R.style.Theme_RetroMusic_Black;
case "daynight":
return R.style.Theme_RetroMusic_DayNight;
case "dark":
default:
return R.style.Theme_RetroMusic;

View File

@ -37,7 +37,7 @@ import code.name.monkey.retromusic.R;
public class RetroColorUtil {
public static int toolbarColor(@NonNull Context context) {
int color = ThemeStore.Companion.primaryColor(context);
if (ATHUtil.INSTANCE.isWindowBackgroundDark(context) && PreferenceUtil.getInstance().getGeneralTheme() != R.style.Theme_RetroMusic_Color) {
if (ATHUtil.INSTANCE.isWindowBackgroundDark(context)) {
return ATHUtil.INSTANCE.resolveColor(context, R.attr.cardBackgroundColor);
} else {
return color;

0
app/src/main/res/font/circular_std_black.otf Executable file → Normal file
View File

0
app/src/main/res/font/circular_std_book.otf Executable file → Normal file
View File

0
app/src/main/res/font/circular_std_medium.otf Executable file → Normal file
View File

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.RetroMusic.DayNight" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="md_corner_radius">16dp</item>
<item name="md_font_title">@font/circular</item>
<item name="md_font_body">@font/circular</item>
<item name="md_font_button">@font/circular</item>
<item name="md_color_button_text">@color/md_white_1000</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="roundSelector">@drawable/round_selector_dark</item>
<item name="rectSelector">@drawable/rect_selector_dark</item>
<item name="rectSelectorStrong">@drawable/rect_selector_strong_dark</item>
<item name="cardBackgroundColor">@color/md_grey_800</item>
<item name="defaultFooterColor">@color/md_grey_800</item>
<item name="dividerColor">@color/md_grey_800</item>
<item name="iconColor">@color/ate_secondary_text_dark</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item>
<!-- just in case-->
<item name="android:windowBackground">@color/md_grey_900</item>
<item name="colorAccent">@android:color/white</item>
<item name="colorPrimary">@color/md_grey_900</item>
<!-- necessary to find the overflow button later in the layout-->
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="bottomSheetDialogTheme">@style/BottomSheetDialog</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowExitTransition">@transition/grid_exit</item>
<item name="android:windowEnterTransition">@transition/grid_exit</item>
<item name="android:windowSharedElementEnterTransition">@transition/grid_exit</item>
<item name="android:windowSharedElementExitTransition">@transition/grid_exit</item>
<item name="android:fontFamily">@font/circular</item>
<item name="android:textColorPrimary">@color/md_white_1000</item>
</style>
</resources>

View File

@ -44,7 +44,6 @@
<item>@string/light_theme_name</item>
<item>@string/dark_theme_name</item>
<item>@string/black_theme_name</item>
<item>@string/color_theme_name</item>
</string-array>
<string-array name="pref_grid_style_list_titles">
@ -96,7 +95,6 @@
<item>light</item>
<item>dark</item>
<item>black</item>
<item>color</item>
</string-array>
<array name="pref_auto_download_images_values">

View File

@ -6,8 +6,6 @@
<style name="Theme.RetroMusic.Black" parent="Theme.RetroMusic.Base.Black" />
<style name="Theme.RetroMusic.Color" parent="Theme.RetroMusic.Base.Color" />
<style name="Theme.RetroMusic.Notification" parent="@android:style/TextAppearance.StatusBar.EventContent" />
<style name="Theme.RetroMusic.Notification.Title" parent="@android:style/TextAppearance.StatusBar.EventContent.Title" />

View File

@ -51,17 +51,6 @@
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
</style>
<style name="Theme.RetroMusic.Base.Color" parent="@style/Theme.RetroMusic.Base">
<item name="colorPrimary">@color/md_deep_purple_A400</item>
<item name="android:colorPrimary">?colorPrimary</item>
<item name="android:windowBackground">?colorPrimary</item>
<item name="md_color_button_text">@color/md_white_1000</item>
<item name="windowActionBar">false</item>
</style>
<style name="Theme.RetroMusic.Base.Black" parent="@style/Theme.RetroMusic.Base">
<item name="dividerColor">@color/dark_color</item>

View File

@ -2,7 +2,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_general">
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
<code.name.monkey.retromusic.preferences.MaterialListPreference
android:defaultValue="dark"
android:entries="@array/pref_general_theme_list_titles"
android:entryValues="@array/pref_general_theme_list_values"

View File

@ -0,0 +1,51 @@
/*
* 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.ListPreference;
import code.name.monkey.appthemehelper.R;
public class ATEListPreference extends ListPreference {
public ATEListPreference(Context context) {
super(context);
init(context, null);
}
public ATEListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
if (getSummary() == null || getSummary().toString().trim().isEmpty())
setSummary("%s");
}
}

View File

@ -1,38 +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.graphics.PorterDuff
import android.util.AttributeSet
import androidx.preference.ListPreference
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
class ATEListPreference @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : ListPreference(context, attrs, defStyleAttr, defStyleRes) {
init {
icon?.setColorFilter(ThemeStore.textColorSecondary(context), PorterDuff.Mode.SRC_IN)
layoutResource = R.layout.ate_preference_custom_support
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty())
summary = "%s"
}
}

View File

@ -0,0 +1,61 @@
/*
* 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 PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
(callbackFragment as PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
return
}
if (activity is PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
(activity as PreferenceFragmentCompat.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
}
}

View File

@ -0,0 +1,86 @@
/*
* 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.dialogs;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.preference.ListPreference;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference;
/**
* Created by hemanths on 2019-09-03.
*/
public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment {
private int mClickedDialogEntryIndex;
@NonNull
public static ATEListPreferenceDialogFragmentCompat newInstance(@NonNull String key) {
final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
private ATEListPreference getListPreference() {
return (ATEListPreference) getPreference();
}
@Override
protected void onPrepareDialogBuilder(@NonNull MaterialAlertDialogBuilder builder) {
super.onPrepareDialogBuilder(builder);
final ListPreference preference = getListPreference();
if (preference.getEntries() == null || preference.getEntryValues() == null) {
throw new IllegalStateException(
"ListPreference requires an entries array and an entryValues array.");
}
mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue());
builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialogInterface, i) -> {
mClickedDialogEntryIndex = i;
});
builder.setPositiveButton("Ok", null);
builder.setNegativeButton("", null);
builder.setNeutralButton("", null);
}
@Override
public void onDialogClosed(boolean positiveResult) {
final ListPreference preference = getListPreference();
if (positiveResult && mClickedDialogEntryIndex >= 0 &&
preference.getEntryValues() != null) {
String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
if (preference.callChangeListener(value)) {
preference.setValue(value);
}
}
}
/* @Override
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
mClickedDialogEntryIndex = which;
onClick(dialog, DialogAction.POSITIVE);
dismiss();
return true;
}*/
}

View File

@ -0,0 +1,99 @@
/*
* 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.dialogs;
import android.app.Dialog;
import android.os.Bundle;
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.preference.DialogPreference;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class ATEPreferenceDialogFragment extends DialogFragment {
protected static final String ARG_KEY = "key";
private DialogPreference mPreference;
public static ATEPreferenceDialogFragment newInstance(String key) {
ATEPreferenceDialogFragment fragment = new ATEPreferenceDialogFragment();
Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fragment rawFragment = this.getTargetFragment();
if (!(rawFragment instanceof DialogPreference.TargetFragment)) {
throw new IllegalStateException("Target fragment must implement TargetFragment interface");
} else {
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;
String key = this.getArguments().getString(ARG_KEY);
this.mPreference = (DialogPreference) fragment.findPreference(key);
}
}
@NonNull
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
MaterialAlertDialogBuilder materialDialog = new MaterialAlertDialogBuilder(requireActivity())
.setTitle(mPreference.getTitle())
.setIcon(mPreference.getIcon())
.setMessage(mPreference.getDialogMessage())
.setPositiveButton(mPreference.getPositiveButtonText(), (dialogInterface, i) -> {
onDialogClosed(true);
})
.setNegativeButton(mPreference.getNegativeButtonText(), (dialogInterface, i) -> {
onDialogClosed(false);
});
this.onPrepareDialogBuilder(materialDialog);
AlertDialog dialog = materialDialog.create();
if (this.needInputMethod()) {
this.requestInputMethod(dialog);
}
return dialog;
}
public DialogPreference getPreference() {
return this.mPreference;
}
protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
}
protected boolean needInputMethod() {
return false;
}
private void requestInputMethod(Dialog dialog) {
Window window = dialog.getWindow();
window.setSoftInputMode(5);
}
public void onDialogClosed(boolean positiveResult) {
}
}

View File

@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:baselineAligned="false"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
@ -35,13 +34,13 @@
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
android:id="@android:id/title"
style="@style/TextViewSubtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:singleLine="true"
tools:text="Title" />
@ -54,7 +53,7 @@
android:layout_alignLeft="@android:id/title"
android:layout_marginTop="2dp"
android:maxLines="4"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:textAppearance="@style/TextViewBody2"
tools:text="Summary" />
</RelativeLayout>

View File

@ -54,8 +54,8 @@
android:layout_alignLeft="@android:id/title"
android:layout_marginTop="2dp"
android:maxLines="4"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
tools:text="Summary" />
android:textAppearance="@style/TextViewBody2"
tools:text="I have one solution for you.you can change font size for specific preference by managing layout file." />
</RelativeLayout>

View File

@ -24,18 +24,18 @@
android:orientation="vertical"
android:padding="0dip">
<TextView
<com.google.android.material.textview.MaterialTextView
android:id="@+id/custom_list_view_row_text_view"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="fill_parent"
android:layout_height="22dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textAppearance="@style/TextViewSubtitle1"
android:textColor="#000000" />
<TextView
<code.name.monkey.appthemehelper.common.views.ATESecondaryTextView
android:id="@+id/custom_list_view_row_subtext_view"
android:layout_width="fill_parent"
android:layout_height="18dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="12sp" />