Revamped Dialog

This commit is contained in:
Hemanth S 2020-05-24 23:34:50 +05:30
parent 6fd4033431
commit b9a4c01a91
41 changed files with 539 additions and 547 deletions

View file

@ -137,11 +137,9 @@ dependencies {
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
def material_dialog_version = "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:input:$material_dialog_version"
implementation "com.afollestad.material-dialogs:color:$material_dialog_version"
implementation "com.afollestad.material-dialogs:bottomsheets:$material_dialog_version"
implementation "com.afollestad.material-dialogs:commons:$material_dialog_version"
implementation 'com.afollestad:material-cab:0.1.12'
implementation 'com.github.bumptech.glide:glide:3.8.0'

View file

@ -277,7 +277,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
MaterialUtil.setTint(button = shuffleAction, color = buttonColor)
MaterialUtil.setTint(button = playAction, color = buttonColor)
toolbar.setBackgroundColor(surfaceColor())
setSupportActionBar(toolbar)
supportActionBar?.title = null

View file

@ -6,7 +6,6 @@ import android.content.res.ColorStateList
import android.os.AsyncTask
import android.os.Build
import android.os.Bundle
import android.text.InputType
import android.text.TextUtils
import android.view.*
import androidx.annotation.StringRes
@ -16,12 +15,14 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.*
import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
import code.name.monkey.retromusic.activities.tageditor.WriteTagsAsyncTask
import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.extensions.textColorSecondary
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
@ -34,18 +35,10 @@ import code.name.monkey.retromusic.model.lyrics.Lyrics
import code.name.monkey.retromusic.util.LyricUtil
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.PreferenceUtilKT
import code.name.monkey.retromusic.util.RetroUtil
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.input.getInputLayout
import com.afollestad.materialdialogs.input.input
import kotlinx.android.synthetic.main.activity_lyrics.*
import kotlinx.android.synthetic.main.fragment_lyrics.*
import kotlinx.android.synthetic.main.fragment_synced.*
import org.jaudiotagger.tag.FieldKey
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.set
class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
ViewPager.OnPageChangeListener {
@ -170,7 +163,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
e.printStackTrace()
}
val materialDialog = MaterialDialog(this)
/*val materialDialog = MaterialDialog(this)
.show {
title(R.string.add_time_framed_lryics)
negativeButton(R.string.action_search) {
@ -188,7 +181,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
}
}
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
MaterialUtil.setTint(materialDialog.getInputLayout(), false)*/
}
private fun updateSong() {
@ -206,7 +199,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
lyricsString!!
}
val materialDialog = MaterialDialog(
/*val materialDialog = MaterialDialog(
this
).show {
@ -231,7 +224,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
updateSong()
}
}
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
MaterialUtil.setTint(materialDialog.getInputLayout(), false)*/
}
private fun getSongPaths(song: Song): ArrayList<String> {

View file

@ -228,6 +228,12 @@ class MainActivity : AbsSlidingMusicPanelActivity(),
menu.add(0, R.id.action_search, 0, getString(R.string.action_search))
.setIcon(R.drawable.ic_search_white_24dp)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS)
ToolbarContentTintHelper.handleOnCreateOptionsMenu(
this,
toolbar,
menu,
getToolbarBackgroundColor(toolbar)
)
return super.onCreateOptionsMenu(menu)
}

View file

@ -4,13 +4,17 @@ import android.os.Bundle
import android.view.MenuItem
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
import code.name.monkey.retromusic.extensions.applyToolbar
import code.name.monkey.retromusic.fragments.settings.MainSettingsFragment
import com.afollestad.materialdialogs.color.ColorChooserDialog
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : AbsBaseActivity() {
class SettingsActivity : AbsBaseActivity(), ColorChooserDialog.ColorCallback {
private val fragmentManager = supportFragmentManager
@ -69,4 +73,19 @@ class SettingsActivity : AbsBaseActivity() {
companion object {
const val TAG: String = "SettingsActivity"
}
override fun onColorSelection(dialog: ColorChooserDialog, selectedColor: Int) {
when (dialog.title) {
R.string.accent_color -> {
ThemeStore.editTheme(this).accentColor(selectedColor).commit()
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(this).updateDynamicShortcuts()
}
}
recreate()
}
override fun onColorChooserDismissed(dialog: ColorChooserDialog) {
}
}

View file

@ -14,6 +14,7 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialDialogsUtil
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.LanguageContextWrapper
import code.name.monkey.retromusic.R
@ -33,6 +34,7 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
setImmersiveFullscreen()
registerSystemUiVisibility()
toggleScreenOn()
MaterialDialogsUtil.updateMaterialDialogsThemeSingleton(this)
}

View file

@ -28,8 +28,7 @@ import code.name.monkey.retromusic.activities.bugreport.model.github.ExtraInfo
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubLogin
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget
import code.name.monkey.retromusic.misc.DialogAsyncTask
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onCancel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.activity_bug_report.*
@ -278,27 +277,25 @@ open class BugReportActivity : AbsThemeActivity() {
when (result) {
RESULT_SUCCESS -> tryToFinishActivity()
RESULT_BAD_CREDENTIALS -> MaterialDialog(context).show {
title(R.string.bug_report_failed)
message(R.string.bug_report_failed_wrong_credentials)
positiveButton(android.R.string.ok)
}
RESULT_INVALID_TOKEN -> MaterialDialog(context).show {
title(R.string.bug_report_failed)
message(R.string.bug_report_failed_invalid_token)
positiveButton(android.R.string.ok)
}
RESULT_ISSUES_NOT_ENABLED -> MaterialDialog(context).show {
title(R.string.bug_report_failed)
message(R.string.bug_report_failed_issues_not_available)
positiveButton(android.R.string.ok)
}
else -> MaterialDialog(context).show {
title(R.string.bug_report_failed)
message(R.string.bug_report_failed_unknown)
positiveButton(android.R.string.ok) { tryToFinishActivity() }
onCancel { tryToFinishActivity() }
}
RESULT_BAD_CREDENTIALS -> MaterialAlertDialogBuilder(context)
.setTitle(R.string.bug_report_failed)
.setMessage(R.string.bug_report_failed_wrong_credentials)
.setPositiveButton(android.R.string.ok, null)
.show()
RESULT_INVALID_TOKEN -> MaterialAlertDialogBuilder(context)
.setTitle(R.string.bug_report_failed)
.setMessage(R.string.bug_report_failed_invalid_token)
.setPositiveButton(android.R.string.ok, null).show()
RESULT_ISSUES_NOT_ENABLED -> MaterialAlertDialogBuilder(context)
.setTitle(R.string.bug_report_failed)
.setMessage(R.string.bug_report_failed_issues_not_available)
.setPositiveButton(android.R.string.ok, null)
else -> MaterialAlertDialogBuilder(context)
.setTitle(R.string.bug_report_failed)
.setMessage(R.string.bug_report_failed_unknown)
.setPositiveButton(android.R.string.ok) { _, _ -> tryToFinishActivity() }
.setNegativeButton(android.R.string.cancel) { _, _ -> { tryToFinishActivity() } }
}
}
@ -309,6 +306,7 @@ open class BugReportActivity : AbsThemeActivity() {
}
}
companion object {
fun report(

View file

@ -13,6 +13,7 @@ import android.util.Log
import android.view.MenuItem
import android.view.View
import android.view.animation.OvershootInterpolator
import androidx.appcompat.app.AlertDialog
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil
@ -24,9 +25,8 @@ import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.activities.saf.SAFGuideActivity
import code.name.monkey.retromusic.util.RetroUtil
import code.name.monkey.retromusic.util.SAFUtil
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_album_tag_editor.*
import org.jaudiotagger.audio.AudioFile
import org.jaudiotagger.audio.AudioFileIO
@ -48,17 +48,18 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() {
private var savedTags: Map<FieldKey, String>? = null
private var savedArtworkInfo: ArtworkInfo? = null
protected val show: MaterialDialog
get() = MaterialDialog(this).show {
title(R.string.update_image)
listItems(items = items) { _, position, _ ->
when (position) {
0 -> startImagePicker()
1 -> searchImageOnWeb()
2 -> deleteImage()
protected val show: AlertDialog
get() =
MaterialAlertDialogBuilder(this)
.setTitle(R.string.update_image)
.setItems(items.toTypedArray()) { _, position ->
when (position) {
0 -> startImagePicker()
1 -> searchImageOnWeb()
2 -> deleteImage()
}
}
}
}
.show()
protected abstract val contentViewLayout: Int
internal val albumArtist: String?

View file

@ -0,0 +1,157 @@
package code.name.monkey.retromusic.dialogs;
import android.Manifest;
import android.app.Dialog;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.DialogFragment;
import com.afollestad.materialdialogs.MaterialDialog;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import code.name.monkey.retromusic.R;
public class BlacklistFolderChooserDialog extends DialogFragment implements MaterialDialog.ListCallback {
String initialPath = Environment.getExternalStorageDirectory().getAbsolutePath();
private File parentFolder;
private File[] parentContents;
private boolean canGoUp = false;
private FolderCallback callback;
public static BlacklistFolderChooserDialog create() {
return new BlacklistFolderChooserDialog();
}
private String[] getContentsArray() {
if (parentContents == null) {
if (canGoUp) {
return new String[]{".."};
}
return new String[]{};
}
String[] results = new String[parentContents.length + (canGoUp ? 1 : 0)];
if (canGoUp) {
results[0] = "..";
}
for (int i = 0; i < parentContents.length; i++) {
results[canGoUp ? i + 1 : i] = parentContents[i].getName();
}
return results;
}
private File[] listFiles() {
File[] contents = parentFolder.listFiles();
List<File> results = new ArrayList<>();
if (contents != null) {
for (File fi : contents) {
if (fi.isDirectory()) {
results.add(fi);
}
}
Collections.sort(results, new FolderSorter());
return results.toArray(new File[results.size()]);
}
return null;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ActivityCompat.checkSelfPermission(
getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
return new MaterialDialog.Builder(getActivity())
.title(R.string.md_error_label)
.content(R.string.md_storage_perm_error)
.positiveText(android.R.string.ok)
.build();
}
if (savedInstanceState == null) {
savedInstanceState = new Bundle();
}
if (!savedInstanceState.containsKey("current_path")) {
savedInstanceState.putString("current_path", initialPath);
}
parentFolder = new File(savedInstanceState.getString("current_path", File.pathSeparator));
checkIfCanGoUp();
parentContents = listFiles();
MaterialDialog.Builder builder =
new MaterialDialog.Builder(getActivity())
.title(parentFolder.getAbsolutePath())
.items((CharSequence[]) getContentsArray())
.itemsCallback(this)
.autoDismiss(false)
.onPositive((dialog, which) -> {
dismiss();
callback.onFolderSelection(BlacklistFolderChooserDialog.this, parentFolder);
})
.onNegative((materialDialog, dialogAction) -> dismiss())
.positiveText(R.string.add_action)
.negativeText(android.R.string.cancel);
return builder.build();
}
@Override
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence s) {
if (canGoUp && i == 0) {
parentFolder = parentFolder.getParentFile();
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
parentFolder = parentFolder.getParentFile();
}
checkIfCanGoUp();
} else {
parentFolder = parentContents[canGoUp ? i - 1 : i];
canGoUp = true;
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
parentFolder = Environment.getExternalStorageDirectory();
}
}
reload();
}
private void checkIfCanGoUp() {
canGoUp = parentFolder.getParent() != null;
}
private void reload() {
parentContents = listFiles();
MaterialDialog dialog = (MaterialDialog) getDialog();
dialog.setTitle(parentFolder.getAbsolutePath());
dialog.setItems((CharSequence[]) getContentsArray());
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("current_path", parentFolder.getAbsolutePath());
}
public void setCallback(FolderCallback callback) {
this.callback = callback;
}
public interface FolderCallback {
void onFolderSelection(@NonNull BlacklistFolderChooserDialog dialog, @NonNull File folder);
}
private static class FolderSorter implements Comparator<File> {
@Override
public int compare(File lhs, File rhs) {
return lhs.getName().compareTo(rhs.getName());
}
}
}

View file

@ -1,180 +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.retromusic.dialogs
import android.Manifest
import android.app.Dialog
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Environment
import androidx.core.app.ActivityCompat
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
class BlacklistFolderChooserDialog : DialogFragment() {
private val initialPath = Environment.getExternalStorageDirectory().absolutePath
private var parentFolder: File? = null
private var parentContents: Array<File>? = null
private var canGoUp = false
private var callback: FolderCallback? = null
private fun contentsArray(): List<String> {
if (parentContents == null) {
return if (canGoUp) {
return listOf("..")
} else listOf()
}
val results = arrayOfNulls<String>(parentContents!!.size + if (canGoUp) 1 else 0)
if (canGoUp) {
results[0] = ".."
}
for (i in parentContents!!.indices) {
results[if (canGoUp) i + 1 else i] = parentContents!![i].name
}
val data = ArrayList<String>()
for (i in results) {
data.add(i!!)
}
return data
}
private fun listFiles(): Array<File>? {
val contents = parentFolder!!.listFiles()
val results = ArrayList<File>()
if (contents != null) {
for (fi in contents) {
if (fi.isDirectory) {
results.add(fi)
}
}
Collections.sort(results, FolderSorter())
return results.toTypedArray()
}
return null
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
var savedInstanceStateFinal = savedInstanceState
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
ActivityCompat.checkSelfPermission(
requireActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE
) != PackageManager.PERMISSION_GRANTED
) {
return MaterialDialog(requireActivity()).show {
title(R.string.md_error_label)
message(R.string.md_storage_perm_error)
positiveButton(android.R.string.ok)
}
}
if (savedInstanceStateFinal == null) {
savedInstanceStateFinal = Bundle()
}
if (!savedInstanceStateFinal.containsKey("current_path")) {
savedInstanceStateFinal.putString("current_path", initialPath)
}
parentFolder = File(savedInstanceStateFinal.getString("current_path", File.pathSeparator))
checkIfCanGoUp()
parentContents = listFiles()
return MaterialDialog(requireContext()).show {
title(text = parentFolder!!.absolutePath)
listItems(items = contentsArray(), waitForPositiveButton = false) { _, index, _ ->
onSelection(index)
}
noAutoDismiss()
positiveButton(R.string.add_action) {
dismiss()
callback!!.onFolderSelection(this@BlacklistFolderChooserDialog, parentFolder!!)
}
negativeButton(android.R.string.cancel) {
dismiss()
}
}
}
private fun onSelection(i: Int) {
if (canGoUp && i == 0) {
parentFolder = parentFolder!!.parentFile
if (parentFolder!!.absolutePath == "/storage/emulated") {
parentFolder = parentFolder!!.parentFile
}
checkIfCanGoUp()
} else {
parentFolder = parentContents!![if (canGoUp) i - 1 else i]
canGoUp = true
if (parentFolder!!.absolutePath == "/storage/emulated") {
parentFolder = Environment.getExternalStorageDirectory()
}
}
reload()
}
private fun checkIfCanGoUp() {
canGoUp = parentFolder!!.parent != null
}
private fun reload() {
parentContents = listFiles()
val dialog = dialog as MaterialDialog?
dialog?.apply {
setTitle(parentFolder!!.absolutePath)
listItems(items = contentsArray()) { _, index, _ ->
onSelection(index)
}
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString("current_path", parentFolder!!.absolutePath)
}
fun setCallback(callback: FolderCallback) {
this.callback = callback
}
interface FolderCallback {
fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File)
}
private class FolderSorter : Comparator<File> {
override fun compare(lhs: File, rhs: File): Int {
return lhs.name.compareTo(rhs.name)
}
}
companion object {
fun create(): BlacklistFolderChooserDialog {
return BlacklistFolderChooserDialog()
}
}
}

View file

@ -36,9 +36,8 @@ import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.service.MusicService.ACTION_PENDING_QUIT
import code.name.monkey.retromusic.service.MusicService.ACTION_QUIT
import code.name.monkey.retromusic.util.PreferenceUtilKT
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class SleepTimerDialog : DialogFragment() {
@ -153,10 +152,10 @@ class SleepTimerDialog : DialogFragment() {
private fun updateCancelButton() {
val musicService = MusicPlayerRemote.musicService
if (musicService != null && musicService.pendingQuit) {
materialDialog.getActionButton(WhichButton.NEGATIVE).text =
materialDialog.getActionButton(DialogAction.NEUTRAL).text =
materialDialog.context.getString(R.string.cancel_current_timer)
} else {
materialDialog.getActionButton(WhichButton.NEGATIVE).text = null
materialDialog.getActionButton(DialogAction.NEUTRAL).text = null
}
}

View file

@ -21,8 +21,8 @@ import android.view.View
import android.widget.Toast
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.preferences.*
@ -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)

View file

@ -31,7 +31,6 @@ class ImageSettingFragment : AbsSettingsFragment() {
setSummary(autoDownloadImagesPolicy, o)
true
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

View file

@ -48,20 +48,23 @@ class NowPlayingSettingsFragment : AbsSettingsFragment(),
}
private fun updateAlbumCoverStyleSummary() {
val preference: Preference = findPreference(ALBUM_COVER_STYLE)!!
preference.setSummary(PreferenceUtilKT.albumCoverStyle.titleRes)
val preference: Preference? = findPreference(ALBUM_COVER_STYLE)
preference?.setSummary(PreferenceUtilKT.albumCoverStyle.titleRes)
}
private fun updateNowPlayingScreenSummary() {
val preference: Preference = findPreference(NOW_PLAYING_SCREEN_ID)!!
preference.setSummary(PreferenceUtilKT.nowPlayingScreen.titleRes)
val preference: Preference? = findPreference(NOW_PLAYING_SCREEN_ID)
preference?.setSummary(PreferenceUtilKT.nowPlayingScreen.titleRes)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
PreferenceUtilKT.registerOnSharedPreferenceChangedListener(this)
val preference: Preference = findPreference("album_cover_transform")!!
setSummary(preference)
val preference: Preference? = findPreference("album_cover_transform")
preference?.setOnPreferenceChangeListener { albumPrefs, newValue ->
setSummary(albumPrefs, newValue)
true
}
}
override fun onDestroyView() {

View file

@ -17,9 +17,8 @@ package code.name.monkey.retromusic.fragments.settings
import android.os.Bundle
import android.view.View
import androidx.preference.Preference
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.preferences.MaterialListPreference
/**
* @author Hemanth S (h4h13).
@ -27,8 +26,8 @@ import code.name.monkey.retromusic.preferences.MaterialListPreference
class OtherSettingsFragment : AbsSettingsFragment() {
override fun invalidateSettings() {
val languagePreference: MaterialListPreference = findPreference("language_name")!!
languagePreference.setOnPreferenceChangeListener { _, _ ->
val languagePreference: ATEListPreference? = findPreference("language_name")
languagePreference?.setOnPreferenceChangeListener { _, _ ->
requireActivity().recreate()
return@setOnPreferenceChangeListener true
}
@ -40,9 +39,15 @@ class OtherSettingsFragment : AbsSettingsFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val preference: Preference = findPreference("last_added_interval")!!
setSummary(preference)
val languagePreference: Preference = findPreference("language_name")!!
setSummary(languagePreference)
val preference: Preference? = findPreference("last_added_interval")
preference?.setOnPreferenceChangeListener { lastAdded, newValue ->
setSummary(lastAdded, newValue)
true
}
val languagePreference: Preference? = findPreference("language_name")
languagePreference?.setOnPreferenceChangeListener { prefs, newValue ->
setSummary(prefs, newValue)
true
}
}
}

View file

@ -14,21 +14,15 @@
package code.name.monkey.retromusic.fragments.settings
import android.content.SharedPreferences
import android.os.Bundle
import android.view.View
import androidx.preference.Preference
import androidx.preference.TwoStatePreference
import code.name.monkey.retromusic.CAROUSEL_EFFECT
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.PreferenceUtilKT
class PersonalizeSettingsFragment : AbsSettingsFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
class PersonalizeSettingsFragment : AbsSettingsFragment() {
override fun invalidateSettings() {
val toggleFullScreen: TwoStatePreference = findPreference("toggle_full_screen")!!
toggleFullScreen.setOnPreferenceChangeListener { _, _ ->
requireActivity().recreate()
@ -42,22 +36,15 @@ class PersonalizeSettingsFragment : AbsSettingsFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
PreferenceUtilKT.registerOnSharedPreferenceChangedListener(this)
var preference: Preference? = findPreference("home_artist_grid_style")
setSummary(preference!!)
preference = findPreference("tab_text_mode")
setSummary(preference!!)
}
override fun onDestroyView() {
super.onDestroyView()
PreferenceUtilKT.unregisterOnSharedPreferenceChangedListener(this)
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when (key) {
CAROUSEL_EFFECT -> invalidateSettings()
val homeArtistStyle: ATEListPreference? = findPreference("home_artist_grid_style")
homeArtistStyle?.setOnPreferenceChangeListener { preference, newValue ->
setSummary(preference, newValue)
true
}
val tabTextMode: ATEListPreference? = findPreference("tab_text_mode")
tabTextMode?.setOnPreferenceChangeListener { prefs, newValue ->
setSummary(prefs, newValue)
true
}
}
}

View file

@ -18,8 +18,6 @@ import android.os.Build
import android.os.Bundle
import androidx.preference.Preference
import androidx.preference.TwoStatePreference
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.ATESwitchPreference
@ -30,9 +28,7 @@ import code.name.monkey.retromusic.DESATURATED_COLOR
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
import code.name.monkey.retromusic.util.PreferenceUtilKT
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.color.colorChooser
import com.afollestad.materialdialogs.color.ColorChooserDialog
/**
* @author Hemanth S (h4h13).
@ -62,21 +58,12 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor))
accentColorPref.setOnPreferenceClickListener {
MaterialDialog(requireActivity()).show {
title(R.string.accent_color)
positiveButton(R.string.set)
colorChooser(
colors = ACCENT_COLORS,
allowCustomArgb = true,
subColors = ACCENT_COLORS_SUB
) { _, color ->
ThemeStore.editTheme(requireContext()).accentColor(color).commit()
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
requireActivity().recreate()
}
}
ColorChooserDialog.Builder(requireContext(), R.string.accent_color)
.accentMode(true)
.allowUserColorInput(true)
.allowUserColorInputAlpha(false)
.preselect(accentColor)
.show(requireActivity())
return@setOnPreferenceClickListener true
}
val blackTheme: ATESwitchPreference? = findPreference("black_theme")

View file

@ -16,7 +16,6 @@ package code.name.monkey.retromusic.preferences
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.util.AttributeSet
import androidx.core.graphics.BlendModeColorFilterCompat

View file

@ -23,13 +23,10 @@ import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.preference.ListPreference
import androidx.preference.PreferenceDialogFragmentCompat
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.colorControlNormal
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class MaterialListPreference @JvmOverloads constructor(
context: Context,
@ -72,30 +69,31 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
val entries = arguments?.getStringArrayList(EXTRA_ENTRIES)
val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES)
val position: Int = arguments?.getInt(EXTRA_POSITION) ?: 0
materialDialog = MaterialDialog(requireContext())
.title(text = materialListPreference.title.toString())
.positiveButton(R.string.set)
.listItemsSingleChoice(
items = entries,
initialSelection = position,
waitForPositiveButton = true
) { _, index, _ ->
entriesValues?.let {
materialListPreference.callChangeListener(it[index])
materialListPreference.setCustomValue(it[index])
}
entries?.let {
materialListPreference.summary = it[index]
val value = materialListPreference.entryValues[index].toString()
if (materialListPreference.callChangeListener(value)) {
materialListPreference.value = value
}
}
dismiss()
}
materialDialog.getActionButton(WhichButton.POSITIVE)
.updateTextColor(ThemeStore.accentColor(requireContext()))
return materialDialog
/* materialDialog = MaterialDialog(requireContext())
.title(text = materialListPreference.title.toString())
.positiveButton(R.string.set)
.listItemsSingleChoice(
items = entries,
initialSelection = position,
waitForPositiveButton = true
) { _, index, _ ->
entriesValues?.let {
materialListPreference.callChangeListener(it[index])
materialListPreference.setCustomValue(it[index])
}
entries?.let {
materialListPreference.summary = it[index]
val value = materialListPreference.entryValues[index].toString()
if (materialListPreference.callChangeListener(value)) {
materialListPreference.value = value
}
}
dismiss()
}
materialDialog.getActionButton(WhichButton.POSITIVE)
.updateTextColor(ThemeStore.accentColor(requireContext()))
return materialDialog*/
return MaterialAlertDialogBuilder(requireContext()).create()
}
override fun onDestroyView() {

View file

@ -17,12 +17,9 @@ package code.name.monkey.retromusic.util
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.net.Uri
import code.name.monkey.retromusic.R
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
object AppRater {
private const val DO_NOT_SHOW_AGAIN = "do_not_show_again"// Package Name
@ -64,30 +61,24 @@ object AppRater {
}
private fun showRateDialog(context: Context, editor: SharedPreferences.Editor) {
MaterialDialog(context)
.show {
title(text = "Rate this App")
message(text = "If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!")
positiveButton(R.string.app_name) {
context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=${context.packageName}")
)
MaterialAlertDialogBuilder(context)
.setTitle("Rate this App")
.setMessage("If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!")
.setPositiveButton(R.string.app_name) { _, _ ->
context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=${context.packageName}")
)
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
dismiss()
}
negativeButton(text = "Later") {
dismiss()
}
neutralButton(text = " No thanks") {
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
dismiss()
}
getActionButton(WhichButton.POSITIVE).updateTextColor(Color.RED)
)
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
}
.setNeutralButton("Not now", null)
.setNegativeButton("No thanks") { _, _ ->
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
}
.show()
}
}

View file

@ -23,10 +23,11 @@ import android.provider.BaseColumns
import android.provider.MediaStore
import android.provider.Settings
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil.getSongFileUri
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class RingtoneManager(val context: Context) {
fun setRingtone(song: Song) {
@ -72,17 +73,17 @@ class RingtoneManager(val context: Context) {
return false
}
fun getDialog(context: Context): MaterialDialog {
return MaterialDialog(context).show {
title(R.string.dialog_title_set_ringtone)
message(R.string.dialog_message_set_ringtone)
positiveButton(android.R.string.ok) {
fun getDialog(context: Context): AlertDialog {
return MaterialAlertDialogBuilder(context)
.setTitle(R.string.dialog_title_set_ringtone)
.setMessage(R.string.dialog_message_set_ringtone)
.setPositiveButton(android.R.string.ok) { _, _ ->
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
intent.data = Uri.parse("package:" + context.applicationContext.packageName)
context.startActivity(intent)
}
negativeButton(android.R.string.cancel)
}
.setNegativeButton(android.R.string.cancel, null)
.create()
}
}
}

View file

@ -25,5 +25,5 @@
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:textAppearance="@style/TextViewOverline"
tools:text="@string/about_settings_summary" />
tools:text="@tools:sample/full_names" />
</LinearLayout>

View file

@ -32,7 +32,6 @@
</style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
<item name="md_color_button_text">@color/md_white_1000</item>
<item name="md_background_color">@color/darkColorPrimary</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActivityTransitions">true</item>
@ -53,7 +52,6 @@
</style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="md_color_button_text">@color/md_black_1000</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="roundSelector">@drawable/round_selector</item>

View file

@ -44,4 +44,11 @@
<color name="progress_gray">#FFD8D8D8</color>
<color name="progress_gray_dark">#FF383838</color>
<color name="default_blue_light">#ff33b5e5</color>
</resources>

View file

@ -16,7 +16,6 @@
</style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
<item name="md_color_button_text">@color/md_white_1000</item>
<item name="md_background_color">@color/darkColorSurface</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActivityTransitions">true</item>
@ -54,7 +53,6 @@
</style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="md_color_button_text">@color/md_black_1000</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="roundSelector">@drawable/round_selector</item>
@ -67,6 +65,7 @@
<item name="windowActionBar">false</item>
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
<item name="materialButtonStyle">@style/MaterialButtonTheme</item>
</style>

View file

@ -70,7 +70,7 @@
app:showSeekBarValue="true" />
</code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
<code.name.monkey.retromusic.preferences.MaterialListPreference
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="auto"
android:entries="@array/pref_language_names"
android:entryValues="@array/pref_language_codes"

View file

@ -5,12 +5,14 @@
android:layout="@layout/preference_category_title"
android:title="@string/pref_header_general">
<code.name.monkey.retromusic.preferences.MaterialListPreference
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="auto"
android:entries="@array/pref_general_theme_list_titles"
android:entryValues="@array/pref_general_theme_list_values"
android:key="general_theme"
android:layout="@layout/list_item_view"
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:title="@string/pref_title_general_theme"
app:icon="@drawable/ic_color_lens_white_24dp" />

View file

@ -10,7 +10,7 @@
android:title="@string/pref_title_ignore_media_store_artwork"
app:icon="@drawable/ic_image_white_24dp" />
<code.name.monkey.retromusic.preferences.MaterialListPreference
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="only_wifi"
android:entries="@array/pref_auto_download_images_titles"
android:entryValues="@array/pref_auto_download_images_values"

View file

@ -25,7 +25,7 @@
android:title="@string/pref_title_album_cover_style"
app:icon="@drawable/ic_image_white_24dp" />
<code.name.monkey.retromusic.preferences.MaterialListPreference
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="0"
android:entries="@array/pref_album_cover_transform_entities"
android:entryValues="@array/pref_album_cover_transform_values"

View file

@ -5,7 +5,7 @@
android:layout="@layout/preference_category_title"
app:title="@string/home">
<code.name.monkey.retromusic.preferences.MaterialListPreference
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="0"
android:entries="@array/pref_home_grid_style_list_titles"
android:entryValues="@array/pref_home_grid_style_list_values"
@ -36,7 +36,7 @@
android:title="@string/library_categories"
app:icon="@drawable/ic_library_music_white_24dp" />
<code.name.monkey.retromusic.preferences.MaterialListPreference
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="0"
android:entries="@array/pref_tab_text_mode_titles"
android:entryValues="@array/pref_tab_text_mode_values"

View file

@ -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"
}

View file

@ -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(

View file

@ -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

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.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
}
}

View file

@ -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"
}

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}
}