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:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$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:core:$material_dialog_version"
implementation "com.afollestad.material-dialogs:input:$material_dialog_version" implementation "com.afollestad.material-dialogs:commons:$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-cab:0.1.12' implementation 'com.afollestad:material-cab:0.1.12'
implementation 'com.github.bumptech.glide:glide:3.8.0' 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 = shuffleAction, color = buttonColor)
MaterialUtil.setTint(button = playAction, color = buttonColor) MaterialUtil.setTint(button = playAction, color = buttonColor)
toolbar.setBackgroundColor(surfaceColor()) toolbar.setBackgroundColor(surfaceColor())
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.title = null supportActionBar?.title = null

View file

@ -6,7 +6,6 @@ import android.content.res.ColorStateList
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.InputType
import android.text.TextUtils import android.text.TextUtils
import android.view.* import android.view.*
import androidx.annotation.StringRes import androidx.annotation.StringRes
@ -16,12 +15,14 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import code.name.monkey.appthemehelper.ThemeStore 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.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.App
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity 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.surfaceColor
import code.name.monkey.retromusic.extensions.textColorSecondary import code.name.monkey.retromusic.extensions.textColorSecondary
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment 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.LyricUtil
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.PreferenceUtilKT 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.activity_lyrics.*
import kotlinx.android.synthetic.main.fragment_lyrics.* import kotlinx.android.synthetic.main.fragment_lyrics.*
import kotlinx.android.synthetic.main.fragment_synced.* import kotlinx.android.synthetic.main.fragment_synced.*
import org.jaudiotagger.tag.FieldKey
import java.io.File import java.io.File
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.set
class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
ViewPager.OnPageChangeListener { ViewPager.OnPageChangeListener {
@ -170,7 +163,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
e.printStackTrace() e.printStackTrace()
} }
val materialDialog = MaterialDialog(this) /*val materialDialog = MaterialDialog(this)
.show { .show {
title(R.string.add_time_framed_lryics) title(R.string.add_time_framed_lryics)
negativeButton(R.string.action_search) { 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() { private fun updateSong() {
@ -206,7 +199,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
lyricsString!! lyricsString!!
} }
val materialDialog = MaterialDialog( /*val materialDialog = MaterialDialog(
this this
).show { ).show {
@ -231,7 +224,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
updateSong() updateSong()
} }
} }
MaterialUtil.setTint(materialDialog.getInputLayout(), false) MaterialUtil.setTint(materialDialog.getInputLayout(), false)*/
} }
private fun getSongPaths(song: Song): ArrayList<String> { 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)) menu.add(0, R.id.action_search, 0, getString(R.string.action_search))
.setIcon(R.drawable.ic_search_white_24dp) .setIcon(R.drawable.ic_search_white_24dp)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS) .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS)
ToolbarContentTintHelper.handleOnCreateOptionsMenu(
this,
toolbar,
menu,
getToolbarBackgroundColor(toolbar)
)
return super.onCreateOptionsMenu(menu) return super.onCreateOptionsMenu(menu)
} }

View file

@ -4,13 +4,17 @@ import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.fragment.app.Fragment 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.R
import code.name.monkey.retromusic.activities.base.AbsBaseActivity 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.extensions.applyToolbar
import code.name.monkey.retromusic.fragments.settings.MainSettingsFragment import code.name.monkey.retromusic.fragments.settings.MainSettingsFragment
import com.afollestad.materialdialogs.color.ColorChooserDialog
import kotlinx.android.synthetic.main.activity_settings.* import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : AbsBaseActivity() { class SettingsActivity : AbsBaseActivity(), ColorChooserDialog.ColorCallback {
private val fragmentManager = supportFragmentManager private val fragmentManager = supportFragmentManager
@ -69,4 +73,19 @@ class SettingsActivity : AbsBaseActivity() {
companion object { companion object {
const val TAG: String = "SettingsActivity" 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.common.ATHToolbarActivity
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil 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.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.LanguageContextWrapper import code.name.monkey.retromusic.LanguageContextWrapper
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
@ -33,6 +34,7 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
setImmersiveFullscreen() setImmersiveFullscreen()
registerSystemUiVisibility() registerSystemUiVisibility()
toggleScreenOn() 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.GithubLogin
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget
import code.name.monkey.retromusic.misc.DialogAsyncTask import code.name.monkey.retromusic.misc.DialogAsyncTask
import com.afollestad.materialdialogs.MaterialDialog import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.afollestad.materialdialogs.callbacks.onCancel
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.activity_bug_report.* import kotlinx.android.synthetic.main.activity_bug_report.*
@ -278,27 +277,25 @@ open class BugReportActivity : AbsThemeActivity() {
when (result) { when (result) {
RESULT_SUCCESS -> tryToFinishActivity() RESULT_SUCCESS -> tryToFinishActivity()
RESULT_BAD_CREDENTIALS -> MaterialDialog(context).show { RESULT_BAD_CREDENTIALS -> MaterialAlertDialogBuilder(context)
title(R.string.bug_report_failed) .setTitle(R.string.bug_report_failed)
message(R.string.bug_report_failed_wrong_credentials) .setMessage(R.string.bug_report_failed_wrong_credentials)
positiveButton(android.R.string.ok) .setPositiveButton(android.R.string.ok, null)
} .show()
RESULT_INVALID_TOKEN -> MaterialDialog(context).show { RESULT_INVALID_TOKEN -> MaterialAlertDialogBuilder(context)
title(R.string.bug_report_failed) .setTitle(R.string.bug_report_failed)
message(R.string.bug_report_failed_invalid_token) .setMessage(R.string.bug_report_failed_invalid_token)
positiveButton(android.R.string.ok) .setPositiveButton(android.R.string.ok, null).show()
} RESULT_ISSUES_NOT_ENABLED -> MaterialAlertDialogBuilder(context)
RESULT_ISSUES_NOT_ENABLED -> MaterialDialog(context).show { .setTitle(R.string.bug_report_failed)
title(R.string.bug_report_failed) .setMessage(R.string.bug_report_failed_issues_not_available)
message(R.string.bug_report_failed_issues_not_available) .setPositiveButton(android.R.string.ok, null)
positiveButton(android.R.string.ok)
} else -> MaterialAlertDialogBuilder(context)
else -> MaterialDialog(context).show { .setTitle(R.string.bug_report_failed)
title(R.string.bug_report_failed) .setMessage(R.string.bug_report_failed_unknown)
message(R.string.bug_report_failed_unknown) .setPositiveButton(android.R.string.ok) { _, _ -> tryToFinishActivity() }
positiveButton(android.R.string.ok) { tryToFinishActivity() } .setNegativeButton(android.R.string.cancel) { _, _ -> { tryToFinishActivity() } }
onCancel { tryToFinishActivity() }
}
} }
} }
@ -309,6 +306,7 @@ open class BugReportActivity : AbsThemeActivity() {
} }
} }
companion object { companion object {
fun report( fun report(

View file

@ -13,6 +13,7 @@ import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.animation.OvershootInterpolator import android.view.animation.OvershootInterpolator
import androidx.appcompat.app.AlertDialog
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil 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.activities.saf.SAFGuideActivity
import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.RetroUtil
import code.name.monkey.retromusic.util.SAFUtil 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.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_album_tag_editor.* import kotlinx.android.synthetic.main.activity_album_tag_editor.*
import org.jaudiotagger.audio.AudioFile import org.jaudiotagger.audio.AudioFile
import org.jaudiotagger.audio.AudioFileIO import org.jaudiotagger.audio.AudioFileIO
@ -48,17 +48,18 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() {
private var savedTags: Map<FieldKey, String>? = null private var savedTags: Map<FieldKey, String>? = null
private var savedArtworkInfo: ArtworkInfo? = null private var savedArtworkInfo: ArtworkInfo? = null
protected val show: MaterialDialog protected val show: AlertDialog
get() = MaterialDialog(this).show { get() =
title(R.string.update_image) MaterialAlertDialogBuilder(this)
listItems(items = items) { _, position, _ -> .setTitle(R.string.update_image)
.setItems(items.toTypedArray()) { _, position ->
when (position) { when (position) {
0 -> startImagePicker() 0 -> startImagePicker()
1 -> searchImageOnWeb() 1 -> searchImageOnWeb()
2 -> deleteImage() 2 -> deleteImage()
} }
} }
} .show()
protected abstract val contentViewLayout: Int protected abstract val contentViewLayout: Int
internal val albumArtist: String? 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_PENDING_QUIT
import code.name.monkey.retromusic.service.MusicService.ACTION_QUIT import code.name.monkey.retromusic.service.MusicService.ACTION_QUIT
import code.name.monkey.retromusic.util.PreferenceUtilKT import code.name.monkey.retromusic.util.PreferenceUtilKT
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
class SleepTimerDialog : DialogFragment() { class SleepTimerDialog : DialogFragment() {
@ -153,10 +152,10 @@ class SleepTimerDialog : DialogFragment() {
private fun updateCancelButton() { private fun updateCancelButton() {
val musicService = MusicPlayerRemote.musicService val musicService = MusicPlayerRemote.musicService
if (musicService != null && musicService.pendingQuit) { if (musicService != null && musicService.pendingQuit) {
materialDialog.getActionButton(WhichButton.NEGATIVE).text = materialDialog.getActionButton(DialogAction.NEUTRAL).text =
materialDialog.context.getString(R.string.cancel_current_timer) materialDialog.context.getString(R.string.cancel_current_timer)
} else { } 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 android.widget.Toast
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.preferences.* import code.name.monkey.retromusic.preferences.*
@ -32,7 +32,7 @@ import code.name.monkey.retromusic.util.NavigationUtil
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
*/ */
abstract class AbsSettingsFragment : PreferenceFragmentCompat() { abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
internal fun showProToastAndNavigate(message: String) { internal fun showProToastAndNavigate(message: String) {
Toast.makeText(requireContext(), "$message is Pro version feature.", Toast.LENGTH_SHORT) Toast.makeText(requireContext(), "$message is Pro version feature.", Toast.LENGTH_SHORT)

View file

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

View file

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

View file

@ -17,9 +17,8 @@ package code.name.monkey.retromusic.fragments.settings
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.preference.Preference import androidx.preference.Preference
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.preferences.MaterialListPreference
/** /**
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
@ -27,8 +26,8 @@ import code.name.monkey.retromusic.preferences.MaterialListPreference
class OtherSettingsFragment : AbsSettingsFragment() { class OtherSettingsFragment : AbsSettingsFragment() {
override fun invalidateSettings() { override fun invalidateSettings() {
val languagePreference: MaterialListPreference = findPreference("language_name")!! val languagePreference: ATEListPreference? = findPreference("language_name")
languagePreference.setOnPreferenceChangeListener { _, _ -> languagePreference?.setOnPreferenceChangeListener { _, _ ->
requireActivity().recreate() requireActivity().recreate()
return@setOnPreferenceChangeListener true return@setOnPreferenceChangeListener true
} }
@ -40,9 +39,15 @@ class OtherSettingsFragment : AbsSettingsFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val preference: Preference = findPreference("last_added_interval")!! val preference: Preference? = findPreference("last_added_interval")
setSummary(preference) preference?.setOnPreferenceChangeListener { lastAdded, newValue ->
val languagePreference: Preference = findPreference("language_name")!! setSummary(lastAdded, newValue)
setSummary(languagePreference) 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 package code.name.monkey.retromusic.fragments.settings
import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.preference.Preference
import androidx.preference.TwoStatePreference 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.R
import code.name.monkey.retromusic.util.PreferenceUtilKT class PersonalizeSettingsFragment : AbsSettingsFragment() {
class PersonalizeSettingsFragment : AbsSettingsFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun invalidateSettings() { override fun invalidateSettings() {
val toggleFullScreen: TwoStatePreference = findPreference("toggle_full_screen")!! val toggleFullScreen: TwoStatePreference = findPreference("toggle_full_screen")!!
toggleFullScreen.setOnPreferenceChangeListener { _, _ -> toggleFullScreen.setOnPreferenceChangeListener { _, _ ->
requireActivity().recreate() requireActivity().recreate()
@ -42,22 +36,15 @@ class PersonalizeSettingsFragment : AbsSettingsFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
PreferenceUtilKT.registerOnSharedPreferenceChangedListener(this) val homeArtistStyle: ATEListPreference? = findPreference("home_artist_grid_style")
homeArtistStyle?.setOnPreferenceChangeListener { preference, newValue ->
var preference: Preference? = findPreference("home_artist_grid_style") setSummary(preference, newValue)
setSummary(preference!!) true
preference = findPreference("tab_text_mode")
setSummary(preference!!)
} }
val tabTextMode: ATEListPreference? = findPreference("tab_text_mode")
override fun onDestroyView() { tabTextMode?.setOnPreferenceChangeListener { prefs, newValue ->
super.onDestroyView() setSummary(prefs, newValue)
PreferenceUtilKT.unregisterOnSharedPreferenceChangedListener(this) true
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when (key) {
CAROUSEL_EFFECT -> invalidateSettings()
} }
} }
} }

View file

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

View file

@ -16,7 +16,6 @@ package code.name.monkey.retromusic.preferences
import android.app.Dialog import android.app.Dialog
import android.content.Context import android.content.Context
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
import androidx.core.graphics.BlendModeColorFilterCompat 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.core.graphics.BlendModeCompat.SRC_IN
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.PreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.colorControlNormal import code.name.monkey.retromusic.extensions.colorControlNormal
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.afollestad.materialdialogs.actions.getActionButton
import com.afollestad.materialdialogs.list.listItemsSingleChoice
class MaterialListPreference @JvmOverloads constructor( class MaterialListPreference @JvmOverloads constructor(
context: Context, context: Context,
@ -72,7 +69,7 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
val entries = arguments?.getStringArrayList(EXTRA_ENTRIES) val entries = arguments?.getStringArrayList(EXTRA_ENTRIES)
val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES) val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES)
val position: Int = arguments?.getInt(EXTRA_POSITION) ?: 0 val position: Int = arguments?.getInt(EXTRA_POSITION) ?: 0
materialDialog = MaterialDialog(requireContext()) /* materialDialog = MaterialDialog(requireContext())
.title(text = materialListPreference.title.toString()) .title(text = materialListPreference.title.toString())
.positiveButton(R.string.set) .positiveButton(R.string.set)
.listItemsSingleChoice( .listItemsSingleChoice(
@ -95,7 +92,8 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
} }
materialDialog.getActionButton(WhichButton.POSITIVE) materialDialog.getActionButton(WhichButton.POSITIVE)
.updateTextColor(ThemeStore.accentColor(requireContext())) .updateTextColor(ThemeStore.accentColor(requireContext()))
return materialDialog return materialDialog*/
return MaterialAlertDialogBuilder(requireContext()).create()
} }
override fun onDestroyView() { override fun onDestroyView() {

View file

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

View file

@ -23,10 +23,11 @@ import android.provider.BaseColumns
import android.provider.MediaStore import android.provider.MediaStore
import android.provider.Settings import android.provider.Settings
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil.getSongFileUri 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) { class RingtoneManager(val context: Context) {
fun setRingtone(song: Song) { fun setRingtone(song: Song) {
@ -72,17 +73,17 @@ class RingtoneManager(val context: Context) {
return false return false
} }
fun getDialog(context: Context): MaterialDialog { fun getDialog(context: Context): AlertDialog {
return MaterialDialog(context).show { return MaterialAlertDialogBuilder(context)
title(R.string.dialog_title_set_ringtone) .setTitle(R.string.dialog_title_set_ringtone)
message(R.string.dialog_message_set_ringtone) .setMessage(R.string.dialog_message_set_ringtone)
positiveButton(android.R.string.ok) { .setPositiveButton(android.R.string.ok) { _, _ ->
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS) val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
intent.data = Uri.parse("package:" + context.applicationContext.packageName) intent.data = Uri.parse("package:" + context.applicationContext.packageName)
context.startActivity(intent) 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:paddingTop="16dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:textAppearance="@style/TextViewOverline" android:textAppearance="@style/TextViewOverline"
tools:text="@string/about_settings_summary" /> tools:text="@tools:sample/full_names" />
</LinearLayout> </LinearLayout>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@
android:title="@string/pref_title_ignore_media_store_artwork" android:title="@string/pref_title_ignore_media_store_artwork"
app:icon="@drawable/ic_image_white_24dp" /> 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:defaultValue="only_wifi"
android:entries="@array/pref_auto_download_images_titles" android:entries="@array/pref_auto_download_images_titles"
android:entryValues="@array/pref_auto_download_images_values" android:entryValues="@array/pref_auto_download_images_values"

View file

@ -25,7 +25,7 @@
android:title="@string/pref_title_album_cover_style" android:title="@string/pref_title_album_cover_style"
app:icon="@drawable/ic_image_white_24dp" /> 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:defaultValue="0"
android:entries="@array/pref_album_cover_transform_entities" android:entries="@array/pref_album_cover_transform_entities"
android:entryValues="@array/pref_album_cover_transform_values" android:entryValues="@array/pref_album_cover_transform_values"

View file

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

View file

@ -31,9 +31,8 @@ dependencies {
implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.preference:preference:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
// Used for the list preference classes // Used for the list preference classes
implementation 'com.afollestad.material-dialogs:core:3.1.1' def material_dialog_version = "0.9.6.0"
implementation 'com.afollestad.material-dialogs:input:3.1.1' implementation "com.afollestad.material-dialogs:core:$material_dialog_version"
implementation 'com.afollestad.material-dialogs:color:3.1.1' implementation "com.afollestad.material-dialogs:commons:$material_dialog_version"
implementation 'com.afollestad.material-dialogs:bottomsheets:3.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_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.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.graphics.Color import android.graphics.Color
import androidx.annotation.AttrRes import androidx.annotation.*
import androidx.annotation.CheckResult
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.IntRange import androidx.annotation.IntRange
import androidx.annotation.StyleRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor
import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.ColorUtil
/** /**
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
*/ */
@ -183,7 +181,10 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
@CheckResult @CheckResult
fun prefs(context: Context): SharedPreferences { 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) { fun markChanged(context: Context) {
@ -224,12 +225,18 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun navigationBarColor(context: Context): Int { fun navigationBarColor(context: Context): Int {
return if (!coloredNavigationBar(context)) { return if (!coloredNavigationBar(context)) {
Color.BLACK 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 @CheckResult
fun coloredStatusBar(context: Context): Boolean { 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 @CheckResult
@ -247,6 +254,42 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
return prefs(context).getBoolean(ThemeStorePrefKeys.IS_CONFIGURED_KEY, false) 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") @SuppressLint("CommitPrefEdits")
fun isConfigured( fun isConfigured(
context: Context, @IntRange( context: Context, @IntRange(

View file

@ -36,7 +36,6 @@ class ATEColorPreference @JvmOverloads constructor(
private var border: Int = 0 private var border: Int = 0
init { init {
layoutResource = R.layout.ate_preference_custom_support
widgetLayoutResource = R.layout.ate_preference_color widgetLayoutResource = R.layout.ate_preference_color
isPersistent = false 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.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.preference.ListPreference import androidx.preference.ListPreference
import code.name.monkey.appthemehelper.R.layout
class ATEListPreference @JvmOverloads constructor( class ATEListPreference @JvmOverloads constructor(
context: Context, context: Context,
@ -26,7 +25,6 @@ class ATEListPreference @JvmOverloads constructor(
) : ListPreference(context, attrs, defStyleAttr, defStyleRes) { ) : ListPreference(context, attrs, defStyleAttr, defStyleRes) {
init { init {
layoutResource = layout.ate_preference_custom_support
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty()) { if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty()) {
summary = "%s" 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; package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; 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; 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 { public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment {
private static final String TAG = "ATEPreferenceDialog";
private int mClickedDialogEntryIndex; private int mClickedDialogEntryIndex;
@NonNull public static ATEListPreferenceDialogFragmentCompat newInstance(String key) {
public static ATEListPreferenceDialogFragmentCompat newInstance(@NonNull String key) {
final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat(); final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1); final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key); b.putString(ARG_KEY, key);
@ -44,7 +44,7 @@ public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFr
} }
@Override @Override
protected void onPrepareDialogBuilder(@NonNull MaterialAlertDialogBuilder builder) { protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
super.onPrepareDialogBuilder(builder); super.onPrepareDialogBuilder(builder);
final ListPreference preference = getListPreference(); final ListPreference preference = getListPreference();
@ -55,24 +55,41 @@ public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFr
} }
mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue()); mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue());
builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialogInterface, i) -> { builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialog, which) -> {
mClickedDialogEntryIndex = i; mClickedDialogEntryIndex = which;
onClick(dialog, which);
dismiss();
}); });
builder.setPositiveButton("Ok", null); /*
builder.setNegativeButton("", null); * The typical interaction for list-based dialogs is to have
builder.setNeutralButton("", null); * 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 @Override
public void onDialogClosed(boolean positiveResult) { public void onDialogClosed(boolean positiveResult) {
final ListPreference preference = getListPreference(); final ListPreference preference = getListPreference();
Log.i(TAG, "onDialogClosed: " + positiveResult);
if (positiveResult && mClickedDialogEntryIndex >= 0 && if (positiveResult && mClickedDialogEntryIndex >= 0 &&
preference.getEntryValues() != null) { preference.getEntryValues() != null) {
String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString(); String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
Log.i(TAG, "onDialogClosed: value " + value);
if (preference.callChangeListener(value)) { if (preference.callChangeListener(value)) {
preference.setValue(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; package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Window; import android.view.Window;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.DialogPreference; import androidx.preference.DialogPreference;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -33,10 +34,10 @@ import code.name.monkey.appthemehelper.R;
/** /**
* @author Karim Abou Zeid (kabouzeid) * @author Karim Abou Zeid (kabouzeid)
*/ */
public class ATEPreferenceDialogFragment extends DialogFragment { public class ATEPreferenceDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
protected static final String ARG_KEY = "key";
static final String ARG_KEY = "key"; private static final String TAG = "ATEPreferenceDialog";
private int mWhichButtonClicked;
private DialogPreference mPreference; private DialogPreference mPreference;
public static ATEPreferenceDialogFragment newInstance(String key) { public static ATEPreferenceDialogFragment newInstance(String key) {
@ -59,34 +60,27 @@ public class ATEPreferenceDialogFragment extends DialogFragment {
} }
} }
public DialogPreference getPreference() {
return this.mPreference;
}
@NonNull @NonNull
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
MaterialAlertDialogBuilder materialDialog = new MaterialAlertDialogBuilder(requireActivity(), FragmentActivity context = this.getActivity();
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context,
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert) R.style.ThemeOverlay_MaterialComponents_Dialog_Alert)
.setTitle(mPreference.getTitle()) .setTitle(this.mPreference.getDialogTitle())
.setIcon(mPreference.getIcon()) .setIcon(this.mPreference.getDialogIcon())
.setMessage(mPreference.getDialogMessage()) .setMessage(this.mPreference.getDialogMessage())
.setPositiveButton(mPreference.getPositiveButtonText(), (dialogInterface, i) -> { .setPositiveButton(this.mPreference.getPositiveButtonText(), this)
onDialogClosed(true); .setNegativeButton(this.mPreference.getNegativeButtonText(), this);
})
.setNegativeButton(mPreference.getNegativeButtonText(), (dialogInterface, i) -> {
onDialogClosed(false);
});
//this.onPrepareDialogBuilder(materialDialog); this.onPrepareDialogBuilder(builder);
AlertDialog dialog = materialDialog.create(); AlertDialog dialog = builder.create();
if (this.needInputMethod()) { if (this.needInputMethod()) {
this.requestInputMethod(dialog); this.requestInputMethod(dialog);
} }
return dialog; return dialog;
} }
public void onDialogClosed(boolean positiveResult) { public DialogPreference getPreference() {
return this.mPreference;
} }
protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) { protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
@ -100,4 +94,22 @@ public class ATEPreferenceDialogFragment extends DialogFragment {
Window window = dialog.getWindow(); Window window = dialog.getWindow();
window.setSoftInputMode(5); 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 package code.name.monkey.appthemehelper.util
import android.content.res.ColorStateList import android.content.res.ColorStateList
import androidx.appcompat.widget.AppCompatButton
import code.name.monkey.appthemehelper.ThemeStore 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.button.MaterialButton
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
@ -54,30 +52,4 @@ object MaterialUtil {
textInputLayout.isHintAnimationEnabled = true 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)
}
}
} }