From fc868e1c2e02fad3c87dacea2467dbd6671eea69 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Tue, 19 Feb 2019 16:08:51 +0530 Subject: [PATCH] Dialog corner and Filter song duration --- app/build.gradle | 5 +- app/src/main/assets/retro-changelog.html | 2 +- .../dialogs/BlacklistFolderChooserDialog.java | 157 -------------- .../dialogs/BlacklistFolderChooserDialog.kt | 162 ++++++++++++++ .../dialogs/ClearSmartPlaylistDialog.kt | 21 +- .../glide/RetroMusicColoredTarget.kt | 3 + .../monkey/retromusic/loaders/SongLoader.kt | 2 +- .../preferences/AlbumCoverStylePreference.kt | 16 -- .../AlbumCoverStylePreferenceDialog.kt | 67 +++--- .../preferences/BlacklistPreference.kt | 17 -- .../BlacklistPreferenceDialog.java | 124 ----------- .../preferences/BlacklistPreferenceDialog.kt | 198 ++++++++++++++++++ .../preferences/MaterialListPreference.kt | 90 ++++++++ .../preferences/NowPlayingScreenPreference.kt | 17 -- .../NowPlayingScreenPreferenceDialog.kt | 171 ++++++++------- .../retromusic/ui/activities/AboutActivity.kt | 21 +- .../ui/activities/LyricsActivity.kt | 51 ++--- .../retromusic/ui/activities/MainActivity.kt | 25 ++- .../ui/activities/SettingsActivity.kt | 12 +- .../ui/activities/UserInfoActivity.kt | 40 ++-- .../ui/activities/WhatsNewActivity.java | 8 +- .../ui/activities/base/AbsThemeActivity.kt | 2 +- .../activities/bugreport/BugReportActivity.kt | 51 +++-- .../tageditor/AbsTagEditorActivity.kt | 24 +-- .../tageditor/WriteTagsAsyncTask.java | 16 +- .../mainactivity/folders/FoldersFragment.java | 14 +- .../fragments/player/color/ColorFragment.kt | 20 ++ .../settings/AbsSettingsFragment.java | 78 ------- .../fragments/settings/AbsSettingsFragment.kt | 80 +++++++ .../settings/ImageSettingFragment.kt | 9 +- .../settings/NowPlayingSettingsFragment.kt | 29 ++- .../settings/OtherSettingsFragment.kt | 7 + .../settings/PersonaizeSettingsFragment.kt | 13 +- .../settings/ThemeSettingsFragment.kt | 55 +++-- .../monkey/retromusic/util/ColorUtils.java | 64 ------ .../retromusic/util/PreferenceUtil.java | 16 +- .../retromusic/util/RetroColorUtil.java | 2 +- .../retromusic/views/ColorIconsImageView.kt | 18 +- app/src/main/res/layout/abs_playlists.xml | 28 +-- app/src/main/res/layout/app_widget_small.xml | 2 +- app/src/main/res/values/strings.xml | 5 + app/src/main/res/values/styles_parents.xml | 148 +++++++------ app/src/main/res/xml/pref_advanced.xml | 12 +- app/src/main/res/xml/pref_audio.xml | 2 +- app/src/main/res/xml/pref_extras.xml | 2 +- app/src/main/res/xml/pref_general.xml | 2 +- app/src/main/res/xml/pref_images.xml | 2 +- .../main/res/xml/pref_now_playing_screen.xml | 4 +- app/src/main/res/xml/pref_playlists.xml | 2 +- app/src/main/res/xml/pref_ui.xml | 8 +- appthemehelper/build.gradle | 6 +- .../monkey/appthemehelper/ColorPalette.kt | 189 +++++++++++++++++ .../common/prefs/ATEDialogPreference.kt | 35 ---- .../common/prefs/ATEEditTextPreference.kt | 4 +- .../common/prefs/ATEListPreference.kt | 7 +- .../common/prefs/ATEMultiSelectPreference.kt | 4 +- .../common/prefs/ATESwitchPreference.kt | 2 +- .../prefs/supportv7/ATECheckBoxPreference.kt | 34 --- .../prefs/supportv7/ATEListPreference.kt | 3 +- .../supportv7/ATEPreferenceFragmentCompat.kt | 52 ----- ...EEditTextPreferenceDialogFragmentCompat.kt | 50 ----- .../ATEListPreferenceDialogFragmentCompat.kt | 73 ------- .../dialogs/ATEPreferenceDialogFragment.kt | 85 -------- .../monkey/appthemehelper/util/ColorUtil.kt | 63 ++++++ .../util/MaterialDialogsUtil.kt | 24 --- .../res/layout/ate_preference_category.xml | 8 +- .../res/layout/ate_preference_checkbox.xml | 6 +- .../main/res/layout/ate_preference_custom.xml | 34 +-- .../layout/ate_preference_custom_support.xml | 22 +- .../main/res/layout/ate_preference_list.xml | 23 ++ .../main/res/layout/ate_preference_switch.xml | 3 +- .../layout/ate_preference_switch_support.xml | 3 +- .../layout/two_lines_list_preference_row.xml | 42 ++++ appthemehelper/src/main/res/values/attrs.xml | 3 - build.gradle | 4 +- 75 files changed, 1409 insertions(+), 1294 deletions(-) delete mode 100644 app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreference.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreference.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreference.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.java create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.kt delete mode 100755 app/src/main/java/code/name/monkey/retromusic/util/ColorUtils.java create mode 100644 appthemehelper/src/main/java/code/name/monkey/appthemehelper/ColorPalette.kt delete mode 100644 appthemehelper/src/main/java/code/name/monkey/appthemehelper/common/prefs/ATEDialogPreference.kt delete mode 100755 appthemehelper/src/main/java/code/name/monkey/appthemehelper/common/prefs/supportv7/ATECheckBoxPreference.kt delete mode 100644 appthemehelper/src/main/java/code/name/monkey/appthemehelper/common/prefs/supportv7/ATEPreferenceFragmentCompat.kt delete mode 100644 appthemehelper/src/main/java/code/name/monkey/appthemehelper/common/prefs/supportv7/dialogs/ATEEditTextPreferenceDialogFragmentCompat.kt delete mode 100644 appthemehelper/src/main/java/code/name/monkey/appthemehelper/common/prefs/supportv7/dialogs/ATEListPreferenceDialogFragmentCompat.kt delete mode 100644 appthemehelper/src/main/java/code/name/monkey/appthemehelper/common/prefs/supportv7/dialogs/ATEPreferenceDialogFragment.kt delete mode 100644 appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/MaterialDialogsUtil.kt create mode 100644 appthemehelper/src/main/res/layout/ate_preference_list.xml create mode 100644 appthemehelper/src/main/res/layout/two_lines_list_preference_row.xml diff --git a/app/build.gradle b/app/build.gradle index f6878f76..42625a14 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -129,13 +129,16 @@ dependencies { implementation "androidx.legacy:legacy-support-v13:$supportLibVersion" implementation "androidx.legacy:legacy-preference-v14:$supportLibVersion" implementation "com.google.android.material:material:$supportLibVersion" + implementation "androidx.palette:palette-ktx:1.0.0" implementation "com.squareup.retrofit2:retrofit:2.5.0" implementation "com.squareup.retrofit2:converter-gson:2.5.0" implementation "com.squareup.retrofit2:adapter-rxjava2:2.5.0" implementation "com.afollestad.material-dialogs:core:$materialDialog" - implementation "com.afollestad.material-dialogs:commons:$materialDialog" + implementation "com.afollestad.material-dialogs:core:$materialDialog" + implementation 'com.afollestad.material-dialogs:input:2.0.0' + implementation 'com.afollestad.material-dialogs:color:2.0.0' implementation 'com.afollestad:material-cab:0.1.12' implementation 'com.github.bumptech.glide:glide:4.8.0' diff --git a/app/src/main/assets/retro-changelog.html b/app/src/main/assets/retro-changelog.html index 742deeac..c11a922c 100644 --- a/app/src/main/assets/retro-changelog.html +++ b/app/src/main/assets/retro-changelog.html @@ -1 +1 @@ -

v3.0.570

If you see entire app white or dark or black select same theme in settings to fix

FAQ's

*If you face any UI related issues you clear app data and cache, if its not working try to uninstall and install again.

\ No newline at end of file +

v3.1.00

v3.0.570

If you see entire app white or dark or black select same theme in settings to fix

FAQ's

*If you face any UI related issues you clear app data and cache, if its not working try to uninstall and install again.

\ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.java b/app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.java deleted file mode 100644 index f3283f65..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.java +++ /dev/null @@ -1,157 +0,0 @@ -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 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 androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; -import androidx.fragment.app.DialogFragment; -import code.name.monkey.retromusic.R; - -/** - * @author Aidan Follestad (afollestad), modified by Karim Abou Zeid - */ -public class BlacklistFolderChooserDialog extends DialogFragment /*implements MaterialDialog.ListCallback */{ - - private 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 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 { - - @Override - public int compare(File lhs, File rhs) { - return lhs.getName().compareTo(rhs.getName()); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.kt new file mode 100644 index 00000000..7bdc80f4 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/BlacklistFolderChooserDialog.kt @@ -0,0 +1,162 @@ +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 + +/** + * @author Aidan Follestad (afollestad), modified by Karim Abou Zeid + */ +class BlacklistFolderChooserDialog : DialogFragment() { + + private val initialPath = Environment.getExternalStorageDirectory().absolutePath + private var parentFolder: File? = null + private var parentContents: Array? = null + private var canGoUp = false + private var callback: FolderCallback? = null + + + private fun contentsArray(): List { + if (parentContents == null) { + return if (canGoUp) { + return listOf("..") + } else listOf() + } + + val results = arrayOfNulls(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() + for (i in results) { + data.add(i!!) + } + return data + } + + private fun listFiles(): Array? { + val contents = parentFolder!!.listFiles() + val results = ArrayList() + 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(activity!!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + return MaterialDialog(activity!!).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(activity!!).show { + title(text = parentFolder!!.absolutePath) + listItems(items = contentsArray(), waitForPositiveButton = false) { dialog, index, text -> + onSelection(dialog, index, text) + } + noAutoDismiss() + positiveButton(R.string.add_action) { + dismiss() + callback!!.onFolderSelection(this@BlacklistFolderChooserDialog, parentFolder!!) + } + negativeButton(android.R.string.cancel) { + dismiss() + } + } + } + + private fun onSelection(materialDialog: MaterialDialog, i: Int, s: String) { + 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()) { dialog, index, text -> + onSelection(dialog, index, text) + } + } + } + + 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 { + + override fun compare(lhs: File, rhs: File): Int { + return lhs.name.compareTo(rhs.name) + } + } + + companion object { + + fun create(): BlacklistFolderChooserDialog { + return BlacklistFolderChooserDialog() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt index 500d95dc..0770440f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/ClearSmartPlaylistDialog.kt @@ -18,18 +18,17 @@ class ClearSmartPlaylistDialog : DialogFragment() { val content = Html.fromHtml(getString(R.string.clear_playlist_x, playlist!!.name)) - return MaterialDialog.Builder(activity!!) - .title(title) - .content(content) - .positiveText(R.string.clear_action) - .negativeText(android.R.string.cancel) - .onPositive { _, _ -> - if (activity == null) { - return@onPositive - } - playlist.clear(activity) + return MaterialDialog(activity!!).show { + title(title) + message(text = content) + positiveButton(R.string.clear_action) { + if (activity == null) { + return@positiveButton } - .build() + playlist.clear(activity) + } + negativeButton { (android.R.string.cancel) } + } } companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt b/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt index 14d75d67..2a36ac32 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt +++ b/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt @@ -2,6 +2,7 @@ package code.name.monkey.retromusic.glide import android.graphics.drawable.Drawable import android.widget.ImageView +import androidx.palette.graphics.Palette import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.retromusic.R import code.name.monkey.retromusic.glide.palette.BitmapPaletteTarget @@ -28,6 +29,8 @@ abstract class RetroMusicColoredTarget(view: ImageView) : BitmapPaletteTarget(vi override fun onResourceReady(resource: BitmapPaletteWrapper, glideAnimation: Transition?) { super.onResourceReady(resource, glideAnimation) + + val defaultColor = defaultFooterColor val primaryColor = getColor(resource.palette, defaultColor) diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt index 26a4c9c5..34651232 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/SongLoader.kt @@ -82,7 +82,7 @@ object SongLoader { try { return context.contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, - BASE_PROJECTION, selectionFinal, selectionValuesFinal, sortOrder) + BASE_PROJECTION, selectionFinal + " AND " + MediaStore.Audio.Media.DURATION + ">= " + (PreferenceUtil.getInstance().filterLength * 1000), selectionValuesFinal, sortOrder) } catch (e: SecurityException) { return null } diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreference.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreference.kt deleted file mode 100644 index 7d2a2e59..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreference.kt +++ /dev/null @@ -1,16 +0,0 @@ -package code.name.monkey.retromusic.preferences - -import android.content.Context -import android.util.AttributeSet -import androidx.preference.DialogPreference - - -class AlbumCoverStylePreference : DialogPreference { - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreferenceDialog.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreferenceDialog.kt index ec2aa7a4..534fe258 100644 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreferenceDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/preferences/AlbumCoverStylePreferenceDialog.kt @@ -3,28 +3,50 @@ package code.name.monkey.retromusic.preferences import android.annotation.SuppressLint import android.app.Dialog import android.content.Context -import android.content.DialogInterface import android.os.Bundle +import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView -import androidx.fragment.app.DialogFragment +import androidx.preference.DialogPreference +import androidx.preference.PreferenceDialogFragmentCompat import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.ViewPager import code.name.monkey.retromusic.R import code.name.monkey.retromusic.ui.fragments.AlbumCoverStyle import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import com.afollestad.materialdialogs.DialogAction import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import com.bumptech.glide.Glide -class AlbumCoverStylePreferenceDialog : DialogFragment(), ViewPager.OnPageChangeListener, MaterialDialog.SingleButtonCallback { +class AlbumCoverStylePreference : DialogPreference { + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) + + private val mLayoutRes = R.layout.preference_dialog_now_playing_screen + + override fun getDialogLayoutResource(): Int { + return mLayoutRes; + } +} + +class AlbumCoverStylePreferenceDialog : PreferenceDialogFragmentCompat(), ViewPager.OnPageChangeListener { + override fun onDialogClosed(positiveResult: Boolean) { + if (positiveResult) { + val nowPlayingScreen = AlbumCoverStyle.values()[viewPagerPosition] + PreferenceUtil.getInstance().albumCoverStyle = nowPlayingScreen + } + } - private var whichButtonClicked: DialogAction? = null private var viewPagerPosition: Int = 0 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { @@ -35,29 +57,14 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(), ViewPager.OnPageChange viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt() viewPager.currentItem = PreferenceUtil.getInstance().albumCoverStyle.ordinal - return MaterialDialog.Builder(activity!!) - .title(R.string.pref_title_album_cover_style) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .onAny(this) - .customView(view, false) - .build() - } - - override fun onClick(dialog: MaterialDialog, - which: DialogAction) { - whichButtonClicked = which - } - - override fun onDismiss(dialog: DialogInterface?) { - super.onDismiss(dialog) - if (whichButtonClicked == DialogAction.POSITIVE) { - val nowPlayingScreen = AlbumCoverStyle.values()[viewPagerPosition] - PreferenceUtil.getInstance().albumCoverStyle = nowPlayingScreen + return MaterialDialog(activity!!).show { + title(R.string.pref_title_album_cover_style) + positiveButton(android.R.string.ok) + negativeButton(android.R.string.cancel) + customView(view = view, scrollable = false, noVerticalPadding = false) } } - override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { } @@ -109,8 +116,14 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(), ViewPager.OnPageChange companion object { val TAG: String = AlbumCoverStylePreferenceDialog::class.java.simpleName - fun newInstance(): AlbumCoverStylePreferenceDialog { - return AlbumCoverStylePreferenceDialog() + private const val EXTRA_KEY = "key" + + fun newInstance(key: String): AlbumCoverStylePreferenceDialog { + val args = Bundle() + args.putString(EXTRA_KEY, key) + val fragment = AlbumCoverStylePreferenceDialog() + fragment.arguments = args + return fragment } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreference.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreference.kt deleted file mode 100644 index cea074c8..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreference.kt +++ /dev/null @@ -1,17 +0,0 @@ -package code.name.monkey.retromusic.preferences - -import android.content.Context -import android.util.AttributeSet - -import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference - - -class BlacklistPreference : ATEDialogPreference { - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.java b/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.java deleted file mode 100644 index 495da2e4..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.java +++ /dev/null @@ -1,124 +0,0 @@ -package code.name.monkey.retromusic.preferences; - -import android.app.Dialog; -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.fragment.app.DialogFragment; -import android.text.Html; -import android.view.View; -import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog; -import code.name.monkey.retromusic.providers.BlacklistStore; -import com.afollestad.materialdialogs.DialogAction; -import com.afollestad.materialdialogs.MaterialDialog; -import java.io.File; -import java.util.ArrayList; - - -public class BlacklistPreferenceDialog extends DialogFragment implements - BlacklistFolderChooserDialog.FolderCallback { - - public static final String TAG = BlacklistPreferenceDialog.class.getSimpleName(); - - private ArrayList paths; - - public static BlacklistPreferenceDialog newInstance() { - return new BlacklistPreferenceDialog(); - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - BlacklistFolderChooserDialog blacklistFolderChooserDialog = (BlacklistFolderChooserDialog) getChildFragmentManager() - .findFragmentByTag("FOLDER_CHOOSER"); - if (blacklistFolderChooserDialog != null) { - blacklistFolderChooserDialog.setCallback(this); - } - - refreshBlacklistData(); - return new MaterialDialog.Builder(getContext()) - .title(R.string.blacklist) - .positiveText(android.R.string.ok) - .neutralText(R.string.clear_action) - .negativeText(R.string.add_action) - .items(paths) - .autoDismiss(false) - .itemsCallback(new MaterialDialog.ListCallback() { - @Override - public void onSelection(MaterialDialog materialDialog, View view, int i, - final CharSequence charSequence) { - new MaterialDialog.Builder(getContext()) - .title(R.string.remove_from_blacklist) - .content(Html.fromHtml( - getString(R.string.do_you_want_to_remove_from_the_blacklist, charSequence))) - .positiveText(R.string.remove_action) - .negativeText(android.R.string.cancel) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, - @NonNull DialogAction dialogAction) { - BlacklistStore.getInstance(getContext()) - .removePath(new File(charSequence.toString())); - refreshBlacklistData(); - } - }).show(); - } - }) - // clear - .onNeutral(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, - @NonNull DialogAction dialogAction) { - new MaterialDialog.Builder(getContext()) - .title(R.string.clear_blacklist) - .content(R.string.do_you_want_to_clear_the_blacklist) - .positiveText(R.string.clear_action) - .negativeText(android.R.string.cancel) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, - @NonNull DialogAction dialogAction) { - BlacklistStore.getInstance(getContext()).clear(); - refreshBlacklistData(); - } - }).show(); - } - }) - // add - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, - @NonNull DialogAction dialogAction) { - BlacklistFolderChooserDialog dialog = BlacklistFolderChooserDialog.create(); - dialog.setCallback(BlacklistPreferenceDialog.this); - dialog.show(getChildFragmentManager(), "FOLDER_CHOOSER"); - } - }) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, - @NonNull DialogAction dialogAction) { - dismiss(); - } - }) - .build(); - } - - private void refreshBlacklistData() { - paths = BlacklistStore.getInstance(getContext()).getPaths(); - - MaterialDialog dialog = (MaterialDialog) getDialog(); - if (dialog != null) { - String[] pathArray = new String[paths.size()]; - pathArray = paths.toArray(pathArray); - dialog.setItems((CharSequence[]) pathArray); - } - } - - @Override - public void onFolderSelection(@NonNull BlacklistFolderChooserDialog folderChooserDialog, - @NonNull File file) { - BlacklistStore.getInstance(getContext()).addPath(file); - refreshBlacklistData(); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt new file mode 100644 index 00000000..028a0dc6 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt @@ -0,0 +1,198 @@ +package code.name.monkey.retromusic.preferences + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import android.text.Html +import android.util.AttributeSet +import androidx.fragment.app.DialogFragment +import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference +import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog +import code.name.monkey.retromusic.providers.BlacklistStore +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItems +import java.io.File +import java.util.* + + +class BlacklistPreference : ATEDialogPreference { + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) +} + +class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog.FolderCallback { + companion object { + private const val EXTRA_KEY = "key" + + fun newInstance(key: String): BlacklistPreferenceDialog { + val args = Bundle() + args.putString(EXTRA_KEY, key) + val fragment = BlacklistPreferenceDialog() + fragment.arguments = args + return fragment + } + } + + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val blacklistFolderChooserDialog = childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog? + blacklistFolderChooserDialog?.setCallback(this) + refreshBlacklistData() + return MaterialDialog(context!!).show { + title(code.name.monkey.retromusic.R.string.blacklist) + positiveButton(android.R.string.ok) { + dismiss(); + } + neutralButton(code.name.monkey.retromusic.R.string.clear_action) { + MaterialDialog(context).show { + title(code.name.monkey.retromusic.R.string.clear_blacklist) + message(code.name.monkey.retromusic.R.string.do_you_want_to_clear_the_blacklist) + positiveButton(code.name.monkey.retromusic.R.string.clear_action) { + BlacklistStore.getInstance(context).clear(); + refreshBlacklistData(); + } + negativeButton(android.R.string.cancel) + } + } + negativeButton(code.name.monkey.retromusic.R.string.add_action) { + val dialog = BlacklistFolderChooserDialog.create() + dialog.setCallback(this@BlacklistPreferenceDialog) + dialog.show(childFragmentManager, "FOLDER_CHOOSER"); + } + listItems(items = paths) { dialog, index, text -> + MaterialDialog(context).show { + title(code.name.monkey.retromusic.R.string.remove_from_blacklist) + message(text = Html.fromHtml(getString(code.name.monkey.retromusic.R.string.do_you_want_to_remove_from_the_blacklist, text))) + positiveButton(code.name.monkey.retromusic.R.string.remove_action) { + BlacklistStore.getInstance(context).removePath(File(text)); + refreshBlacklistData(); + } + negativeButton(android.R.string.cancel) + } + } + noAutoDismiss() + } + } + + private lateinit var paths: ArrayList + + private fun refreshBlacklistData() { + this.paths = BlacklistStore.getInstance(context!!).paths + val dialog: MaterialDialog? = dialog as MaterialDialog? + dialog?.listItems(items = paths) + } + + override fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File) { + BlacklistStore.getInstance(context!!).addPath(folder); + refreshBlacklistData(); + } + + /*public static final String TAG = BlacklistPreferenceDialog.class.getSimpleName(); + + private ArrayList paths; + + public static BlacklistPreferenceDialog newInstance() { + return new BlacklistPreferenceDialog(); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + BlacklistFolderChooserDialog blacklistFolderChooserDialog = (BlacklistFolderChooserDialog) getChildFragmentManager() + .findFragmentByTag("FOLDER_CHOOSER"); + if (blacklistFolderChooserDialog != null) { + blacklistFolderChooserDialog.setCallback(this); + } + + refreshBlacklistData(); + return new MaterialDialog.Builder(getContext()) + .title(R.string.blacklist) + .positiveText(android.R.string.ok) + .neutralText(R.string.clear_action) + .negativeText(R.string.add_action) + .items(paths) + .autoDismiss(false) + .itemsCallback(new MaterialDialog.ListCallback() { + @Override + public void onSelection(MaterialDialog materialDialog, View view, int i, + final CharSequence charSequence) { + new MaterialDialog.Builder(getContext()) + .title(R.string.remove_from_blacklist) + .content(Html.fromHtml( + getString(R.string.do_you_want_to_remove_from_the_blacklist, charSequence))) + .positiveText(R.string.remove_action) + .negativeText(android.R.string.cancel) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog materialDialog, + @NonNull DialogAction dialogAction) { + BlacklistStore.getInstance(getContext()) + .removePath(new File(charSequence.toString())); + refreshBlacklistData(); + } + }).show(); + } + }) + // clear + .onNeutral(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog materialDialog, + @NonNull DialogAction dialogAction) { + new MaterialDialog.Builder(getContext()) + .title(R.string.clear_blacklist) + .content(R.string.do_you_want_to_clear_the_blacklist) + .positiveText(R.string.clear_action) + .negativeText(android.R.string.cancel) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog materialDialog, + @NonNull DialogAction dialogAction) { + BlacklistStore.getInstance(getContext()).clear(); + refreshBlacklistData(); + } + }).show(); + } + }) + // add + .onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog materialDialog, + @NonNull DialogAction dialogAction) { + BlacklistFolderChooserDialog dialog = BlacklistFolderChooserDialog.create(); + dialog.setCallback(BlacklistPreferenceDialog.this); + dialog.show(getChildFragmentManager(), "FOLDER_CHOOSER"); + } + }) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog materialDialog, + @NonNull DialogAction dialogAction) { + dismiss(); + } + }) + .build(); + } + + private void refreshBlacklistData() { + paths = BlacklistStore.getInstance(getContext()).getPaths(); + + MaterialDialog dialog = (MaterialDialog) getDialog(); + if (dialog != null) { + String[] pathArray = new String[paths.size()]; + pathArray = paths.toArray(pathArray); + dialog.setItems((CharSequence[]) pathArray); + } + } + + @Override + public void onFolderSelection(@NonNull BlacklistFolderChooserDialog folderChooserDialog, + @NonNull File file) { + BlacklistStore.getInstance(getContext()).addPath(file); + refreshBlacklistData(); + }*/ +} diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt new file mode 100644 index 00000000..9e906f16 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt @@ -0,0 +1,90 @@ +package code.name.monkey.retromusic.preferences + +import android.app.Dialog +import android.content.Context +import android.content.res.TypedArray +import android.os.Bundle +import android.util.AttributeSet +import androidx.preference.ListPreference +import androidx.preference.PreferenceDialogFragmentCompat +import code.name.monkey.retromusic.R +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsSingleChoice + + +class MaterialListPreference : ListPreference { + private val mLayoutRes = code.name.monkey.retromusic.R.layout.ate_preference_list + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) + + override fun getDialogLayoutResource(): Int { + return mLayoutRes; + } + + override fun onGetDefaultValue(a: TypedArray, index: Int): Any { + // Default value from attribute. Fallback value is set to 0. + return a.getString(index) + } + + fun setCustomValue(any: Any) { + when (any) { + is String -> persistString(any) + is Int -> persistInt(any) + is Boolean -> persistBoolean(any) + } + } +} + +class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() { + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val materialListPreference = preference as MaterialListPreference + position = materialListPreference.findIndexOfValue(materialListPreference.value) + + val entries = arguments?.getStringArrayList(EXTRA_ENTRIES) + val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES) + return MaterialDialog(activity!!).show { + title(text = materialListPreference.title.toString()) + positiveButton(R.string.set) + listItemsSingleChoice(items = entries, initialSelection = position) { dialog, index, text -> + materialListPreference.callChangeListener(entriesValues!![index]) + materialListPreference.setCustomValue(entriesValues[index]) + materialListPreference.summary = entries!![index] + dismiss() + } + } + } + + override fun onDialogClosed(positiveResult: Boolean) { + if (positiveResult) { + dismiss() + } + } + + companion object { + var position = 0 + private const val EXTRA_KEY = "key" + private const val EXTRA_TITLE = "title" + private const val EXTRA_ENTRIES = "extra_entries" + private const val EXTRA_ENTRIES_VALUES = "extra_entries_values" + + fun newInstance(listPreference: ListPreference): MaterialListPreferenceDialog { + val entries = listPreference.entries.toList() as ArrayList + val entriesValues = listPreference.entryValues.toList() as ArrayList + val args = Bundle() + args.putString(EXTRA_KEY, listPreference.key) + args.putString(EXTRA_TITLE, listPreference.title.toString()) + args.putStringArrayList(EXTRA_ENTRIES, entries) + args.putStringArrayList(EXTRA_ENTRIES_VALUES, entriesValues) + val fragment = MaterialListPreferenceDialog() + fragment.arguments = args + return fragment + } + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreference.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreference.kt deleted file mode 100644 index ee1f85a2..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreference.kt +++ /dev/null @@ -1,17 +0,0 @@ -package code.name.monkey.retromusic.preferences - -import android.content.Context -import android.util.AttributeSet - -import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference - - -class NowPlayingScreenPreference : ATEDialogPreference { - constructor(context: Context) : super(context) {} - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {} - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {} - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {} -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreferenceDialog.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreferenceDialog.kt index b0373fe1..91021d22 100644 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreferenceDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/preferences/NowPlayingScreenPreferenceDialog.kt @@ -1,17 +1,17 @@ package code.name.monkey.retromusic.preferences -import android.annotation.SuppressLint import android.app.Dialog import android.content.Context -import android.content.DialogInterface import android.os.Bundle +import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import android.widget.Toast -import androidx.fragment.app.DialogFragment +import androidx.preference.DialogPreference +import androidx.preference.PreferenceDialogFragmentCompat import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.ViewPager import code.name.monkey.retromusic.App @@ -20,42 +20,43 @@ import code.name.monkey.retromusic.ui.fragments.NowPlayingScreen import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import com.afollestad.materialdialogs.DialogAction import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import com.bumptech.glide.Glide +class NowPlayingScreenPreference : DialogPreference { -class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChangeListener, MaterialDialog.SingleButtonCallback { + constructor(context: Context) : super(context) {} - private var whichButtonClicked: DialogAction? = null + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {} + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {} + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {} + + private val mLayoutRes = R.layout.preference_dialog_now_playing_screen + + override fun getDialogLayoutResource(): Int { + return mLayoutRes; + } +} + +class NowPlayingScreenPreferenceDialog : PreferenceDialogFragmentCompat(), ViewPager.OnPageChangeListener { private var viewPagerPosition: Int = 0 + override fun onPageScrollStateChanged(state: Int) { - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - @SuppressLint("InflateParams") val view = LayoutInflater.from(activity) - .inflate(R.layout.preference_dialog_now_playing_screen, null) - val viewPager = view.findViewById(R.id.now_playing_screen_view_pager) - viewPager.adapter = NowPlayingScreenAdapter(activity!!) - viewPager.addOnPageChangeListener(this) - viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt() - viewPager.currentItem = PreferenceUtil.getInstance().nowPlayingScreen.ordinal - - return MaterialDialog.Builder(activity!!) - .title(R.string.pref_title_now_playing_screen_appearance) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .onAny(this) - .customView(view, false) - .build() } - override fun onClick(dialog: MaterialDialog, - which: DialogAction) { - whichButtonClicked = which + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { + } - override fun onDismiss(dialog: DialogInterface?) { - super.onDismiss(dialog) - if (whichButtonClicked == DialogAction.POSITIVE) { + override fun onPageSelected(position: Int) { + this.viewPagerPosition = position + } + + override fun onDialogClosed(positiveResult: Boolean) { + if (positiveResult) { val nowPlayingScreen = NowPlayingScreen.values()[viewPagerPosition] if (isNowPlayingThemes(nowPlayingScreen)) { val result = getString(nowPlayingScreen.titleRes) + " theme is Pro version feature." @@ -67,8 +68,25 @@ class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChang } } - private fun isNowPlayingThemes(nowPlayingScreen: NowPlayingScreen): Boolean { + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val view = LayoutInflater.from(activity).inflate(R.layout.preference_dialog_now_playing_screen, null) + val viewPager = view.findViewById(R.id.now_playing_screen_view_pager) + ?: throw IllegalStateException("Dialog view must contain a ViewPager with id 'now_playing_screen_view_pager'") + viewPager.adapter = NowPlayingScreenAdapter(activity!!) + viewPager.addOnPageChangeListener(this) + viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt() + viewPager.currentItem = PreferenceUtil.getInstance().nowPlayingScreen.ordinal + + return MaterialDialog(activity!!).show { + title(R.string.pref_title_album_cover_style) + positiveButton(android.R.string.ok) + negativeButton(android.R.string.cancel) + customView(view = view, scrollable = false, noVerticalPadding = false) + } + } + + private fun isNowPlayingThemes(nowPlayingScreen: NowPlayingScreen): Boolean { if (nowPlayingScreen == NowPlayingScreen.BLUR_CARD) { PreferenceUtil.getInstance().resetCarouselEffect() PreferenceUtil.getInstance().resetCircularAlbumArt() @@ -83,62 +101,53 @@ class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChang nowPlayingScreen == NowPlayingScreen.BLUR_CARD || nowPlayingScreen == NowPlayingScreen.ADAPTIVE) && !App.isProVersion - - } - - override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { - - } - - override fun onPageSelected(position: Int) { - this.viewPagerPosition = position - } - - override fun onPageScrollStateChanged(state: Int) { - - } - - private class NowPlayingScreenAdapter internal constructor(private val context: Context) : PagerAdapter() { - - override fun instantiateItem(collection: ViewGroup, position: Int): Any { - val nowPlayingScreen = NowPlayingScreen.values()[position] - - val inflater = LayoutInflater.from(context) - val layout = inflater.inflate(R.layout.preference_now_playing_screen_item, collection, false) as ViewGroup - collection.addView(layout) - - val image = layout.findViewById(R.id.image) - val title = layout.findViewById(R.id.title) - Glide.with(context).load(nowPlayingScreen.drawableResId).into(image) - title.setText(nowPlayingScreen.titleRes) - - return layout - } - - override fun destroyItem(collection: ViewGroup, - position: Int, - view: Any) { - collection.removeView(view as View) - } - - override fun getCount(): Int { - return NowPlayingScreen.values().size - } - - override fun isViewFromObject(view: View, `object`: Any): Boolean { - return view === `object` - } - - override fun getPageTitle(position: Int): CharSequence? { - return context.getString(NowPlayingScreen.values()[position].titleRes) - } } companion object { - val TAG: String = NowPlayingScreenPreferenceDialog::class.java.simpleName + private const val EXTRA_KEY = "key" - fun newInstance(): NowPlayingScreenPreferenceDialog { - return NowPlayingScreenPreferenceDialog() + fun newInstance(key: String): NowPlayingScreenPreferenceDialog { + val args = Bundle() + args.putString(EXTRA_KEY, key) + val fragment = NowPlayingScreenPreferenceDialog() + fragment.arguments = args + return fragment } } } + +private class NowPlayingScreenAdapter internal constructor(private val context: Context) : PagerAdapter() { + + override fun instantiateItem(collection: ViewGroup, position: Int): Any { + val nowPlayingScreen = NowPlayingScreen.values()[position] + + val inflater = LayoutInflater.from(context) + val layout = inflater.inflate(R.layout.preference_now_playing_screen_item, collection, false) as ViewGroup + collection.addView(layout) + + val image = layout.findViewById(R.id.image) + val title = layout.findViewById(R.id.title) + Glide.with(context).load(nowPlayingScreen.drawableResId).into(image) + title.setText(nowPlayingScreen.titleRes) + + return layout + } + + override fun destroyItem(collection: ViewGroup, + position: Int, + view: Any) { + collection.removeView(view as View) + } + + override fun getCount(): Int { + return NowPlayingScreen.values().size + } + + override fun isViewFromObject(view: View, `object`: Any): Boolean { + return view === `object` + } + + override fun getPageTitle(position: Int): CharSequence? { + return context.getString(NowPlayingScreen.values()[position].titleRes) + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/AboutActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/AboutActivity.kt index 538046cd..e9346333 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/AboutActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/AboutActivity.kt @@ -28,6 +28,7 @@ import code.name.monkey.retromusic.ui.activities.base.AbsBaseActivity import code.name.monkey.retromusic.ui.adapter.ContributorAdapter import code.name.monkey.retromusic.util.NavigationUtil import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItems import com.google.gson.Gson import com.google.gson.reflect.TypeToken import kotlinx.android.synthetic.main.activity_about.* @@ -117,7 +118,7 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener { override fun onClick(view: View) { when (view.id) { - R.id.pinterestLink->openUrl(PINTEREST) + R.id.pinterestLink -> openUrl(PINTEREST) R.id.faqLink -> openUrl(FAQ_LINK) R.id.telegramLink -> openUrl(APP_TELEGRAM_LINK) R.id.discordLink -> openUrl(DISCORD_LINK) @@ -135,17 +136,15 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener { } private fun showChangeLogOptions() { - MaterialDialog.Builder(this) - .items("Telegram Channel", "App") - .itemsCallback { _, _, position, _ -> - if (position == 0) { - openUrl(TELEGRAM_CHANGE_LOG) - } else { - NavigationUtil.gotoWhatNews(this@AboutActivity) - } + MaterialDialog(this).show { + listItems(items = listOf("Telegram Channel", "App")) { _, position, _ -> + if (position == 0) { + openUrl(TELEGRAM_CHANGE_LOG) + } else { + NavigationUtil.gotoWhatNews(this@AboutActivity) } - .build() - .show() + } + } } private fun getAppVersion(): String { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt index 7d942b24..3725d963 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/LyricsActivity.kt @@ -27,6 +27,7 @@ import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.RetroUtil import com.afollestad.materialdialogs.MaterialDialog +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.* @@ -133,19 +134,18 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage e.printStackTrace() } - MaterialDialog.Builder(this) - .title("Add lyrics") - .neutralText("Search") - .content("Add time frame lyrics") - .negativeText("Delete") - .onNegative { _, _ -> - LyricUtil.deleteLrcFile(song.title, song.artistName) - } - .onNeutral { _, _ -> RetroUtil.openUrl(this@LyricsActivity, googleSearchLrcUrl) } - .inputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) - .input("Paste lyrics here", content) { _, input -> - LyricUtil.writeLrcToLoc(song.title, song.artistName, input.toString()) - }.show() + MaterialDialog(this).show { + title(text = "Add lyrics") + neutralButton(text = "Search") { RetroUtil.openUrl(this@LyricsActivity, googleSearchLrcUrl) } + message(text = "Add time frame lyrics") + negativeButton(text = "Delete") { LyricUtil.deleteLrcFile(song.title, song.artistName) } + input(hint = "Paste lyrics here", + prefill = content, + inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) { _, input -> + LyricUtil.writeLrcToLoc(song.title, song.artistName, input.toString()) + } + positiveButton(android.R.string.ok) + } } private fun showLyricsSaveDialog() { @@ -154,17 +154,20 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage } else { lyricsString!! } - MaterialDialog.Builder(this) - .title("Add lyrics") - .neutralText("Search") - .onNeutral { _, _ -> RetroUtil.openUrl(this@LyricsActivity, getGoogleSearchUrl(song.title, song.artistName)) } - .inputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) - .input("Paste lyrics here", content) { _, input -> - val fieldKeyValueMap = EnumMap(FieldKey::class.java) - fieldKeyValueMap[FieldKey.LYRICS] = input.toString() - WriteTagsAsyncTask(this@LyricsActivity).execute(WriteTagsAsyncTask.LoadingInfo(getSongPaths(song), fieldKeyValueMap, null)) - } - .show() + + MaterialDialog(this).show { + title(text = "Add lyrics") + neutralButton(text = "Search") { RetroUtil.openUrl(this@LyricsActivity, googleSearchLrcUrl) } + negativeButton(text = "Delete") { LyricUtil.deleteLrcFile(song.title, song.artistName) } + input(hint = "Paste lyrics here", + prefill = content, + inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) { _, input -> + val fieldKeyValueMap = EnumMap(FieldKey::class.java) + fieldKeyValueMap[FieldKey.LYRICS] = input.toString() + WriteTagsAsyncTask(this@LyricsActivity).execute(WriteTagsAsyncTask.LoadingInfo(getSongPaths(song), fieldKeyValueMap, null)) + } + positiveButton(android.R.string.ok) + } } private fun getSongPaths(song: Song): ArrayList { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/MainActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/MainActivity.kt index 5bad4115..fecca802 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/MainActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/MainActivity.kt @@ -12,7 +12,6 @@ import android.view.View import android.view.ViewGroup import androidx.core.app.ActivityCompat import androidx.fragment.app.Fragment -import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.SearchQueryHelper @@ -27,6 +26,7 @@ import code.name.monkey.retromusic.ui.fragments.mainactivity.home.BannerHomeFrag import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.callbacks.onDismiss import io.reactivex.disposables.CompositeDisposable import java.util.* @@ -262,18 +262,17 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP } private fun showPromotionalOffer() { - MaterialDialog.Builder(this) - .positiveText("Buy") - .onPositive { _, _ -> startActivity(Intent(this@MainActivity, PurchaseActivity::class.java)) } - .negativeText(android.R.string.cancel) - .customView(R.layout.dialog_promotional_offer, false) - .dismissListener { - PreferenceManager.getDefaultSharedPreferences(this@MainActivity) - .edit() - .putBoolean("shown", true) - .apply() - } - .show() + /*MaterialDialog(this).show { + positiveButton(text = "Buy") { startActivity(Intent(this@MainActivity, PurchaseActivity::class.java)) } + negativeButton(android.R.string.cancel) + customView(R.layout.dialog_promotional_offer) + onDismiss { + PreferenceManager.getDefaultSharedPreferences(this@MainActivity) + .edit() + .putBoolean("shown", true) + .apply() + } + }*/ } private fun selectedFragment(itemId: Int) { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/SettingsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/SettingsActivity.kt index fc5ae950..cf5524ba 100755 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/SettingsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/SettingsActivity.kt @@ -3,28 +3,22 @@ package code.name.monkey.retromusic.ui.activities import android.content.SharedPreferences import android.os.Bundle import android.view.MenuItem -import androidx.annotation.ColorInt import androidx.annotation.StringRes import androidx.fragment.app.Fragment import code.name.monkey.appthemehelper.ThemeStore -import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper -import code.name.monkey.appthemehelper.util.VersionUtils -import code.name.monkey.retromusic.App.Companion.context import code.name.monkey.retromusic.R -import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager import code.name.monkey.retromusic.ui.activities.base.AbsBaseActivity import code.name.monkey.retromusic.ui.fragments.settings.MainSettingsFragment import code.name.monkey.retromusic.util.PreferenceUtil -import com.afollestad.materialdialogs.color.ColorChooserDialog import kotlinx.android.synthetic.main.activity_settings.* -class SettingsActivity : AbsBaseActivity(), ColorChooserDialog.ColorCallback, SharedPreferences.OnSharedPreferenceChangeListener { +class SettingsActivity : AbsBaseActivity(), /*ColorChooserDialog.ColorCallback,*/ SharedPreferences.OnSharedPreferenceChangeListener { private val fragmentManager = supportFragmentManager - override fun onColorSelection(dialog: ColorChooserDialog, @ColorInt selectedColor: Int) { + /* override fun onColorSelection(dialog: ColorChooserDialog, @ColorInt selectedColor: Int) { when (dialog.title) { R.string.primary_color -> { val theme = if (ColorUtil.isColorLight(selectedColor)) @@ -43,7 +37,7 @@ class SettingsActivity : AbsBaseActivity(), ColorChooserDialog.ColorCallback, Sh override fun onColorChooserDismissed(dialog: ColorChooserDialog) { - } + }*/ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/UserInfoActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/UserInfoActivity.kt index db235ef3..6f480d00 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/UserInfoActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/UserInfoActivity.kt @@ -22,6 +22,7 @@ import code.name.monkey.retromusic.util.Compressor import code.name.monkey.retromusic.util.ImageUtil import code.name.monkey.retromusic.util.PreferenceUtil import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItems import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers @@ -29,7 +30,6 @@ import kotlinx.android.synthetic.main.activity_user_info.* import java.io.File import java.io.FileOutputStream import java.io.IOException -import java.util.* class UserInfoActivity : AbsBaseActivity() { @@ -56,15 +56,15 @@ class UserInfoActivity : AbsBaseActivity() { loadBannerFromStorage(PreferenceUtil.getInstance().bannerImage) } userImage.setOnClickListener { - MaterialDialog.Builder(this) - .title("Set a profile photo") - .items(Arrays.asList(getString(R.string.new_profile_photo), getString(R.string.remove_profile_photo))) - .itemsCallback { _, _, position, _ -> - when (position) { - 0 -> pickNewPhoto() - 1 -> PreferenceUtil.getInstance().saveProfileImage("") - } - }.show() + MaterialDialog(this).show { + title(text = "Set a profile photo") + listItems(items = listOf(getString(R.string.new_profile_photo), getString(R.string.remove_profile_photo))) { _, position, _ -> + when (position) { + 0 -> pickNewPhoto() + 1 -> PreferenceUtil.getInstance().saveProfileImage("") + } + } + } } bannerSelect.setOnClickListener { showBannerOptions() @@ -103,16 +103,16 @@ class UserInfoActivity : AbsBaseActivity() { private fun showBannerOptions() { - MaterialDialog.Builder(this) - .title(R.string.select_banner_photo) - .items(Arrays.asList(getString(R.string.new_banner_photo), - getString(R.string.remove_banner_photo))) - .itemsCallback { _, _, position, _ -> - when (position) { - 0 -> selectBannerImage() - 1 -> PreferenceUtil.getInstance().setBannerImagePath("") - } - }.show() + MaterialDialog(this).show { + title(R.string.select_banner_photo) + listItems(items = listOf(getString(R.string.new_banner_photo), getString(R.string.remove_banner_photo))) + { _, position, _ -> + when (position) { + 0 -> selectBannerImage() + 1 -> PreferenceUtil.getInstance().setBannerImagePath("") + } + } + } } private fun selectBannerImage() { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/WhatsNewActivity.java b/app/src/main/java/code/name/monkey/retromusic/ui/activities/WhatsNewActivity.java index f19de472..b9be6386 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/WhatsNewActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/WhatsNewActivity.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.webkit.WebView; import android.widget.TextView; -import com.afollestad.materialdialogs.internal.ThemeSingleton; import com.google.android.material.appbar.AppBarLayout; import java.io.BufferedReader; @@ -17,6 +16,7 @@ import java.io.InputStreamReader; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import code.name.monkey.appthemehelper.ThemeStore; +import code.name.monkey.appthemehelper.util.ATHUtil; import code.name.monkey.appthemehelper.util.ColorUtil; import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; import code.name.monkey.retromusic.R; @@ -79,12 +79,12 @@ public class WhatsNewActivity extends AbsBaseActivity { // Inject color values for WebView body background and links final String backgroundColor = colorToHex(ThemeStore.Companion.primaryColor(this)); - final String contentColor = ThemeSingleton.get().darkTheme ? "#ffffff" : "#000000"; + final String contentColor = ATHUtil.INSTANCE.isWindowBackgroundDark(this) ? "#ffffff" : "#000000"; webView.loadData(buf.toString() .replace("{style-placeholder}", String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor)) - .replace("{link-color}", colorToHex(ThemeSingleton.get().positiveColor.getDefaultColor())) - .replace("{link-color-active}", colorToHex(ColorUtil.INSTANCE.lightenColor(ThemeSingleton.get().positiveColor.getDefaultColor()))) + .replace("{link-color}", colorToHex(ThemeStore.Companion.accentColor(this))) + .replace("{link-color-active}", colorToHex(ColorUtil.INSTANCE.lightenColor(ThemeStore.Companion.accentColor(this)))) , "text/html", "UTF-8"); } catch (Throwable e) { webView.loadData("

Unable to load

" + e.getLocalizedMessage() + "

", "text/html", "UTF-8"); diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsThemeActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsThemeActivity.kt index c8e57945..6948b909 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsThemeActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsThemeActivity.kt @@ -24,7 +24,7 @@ abstract class AbsThemeActivity : AbsCrashCollector(), Runnable { setTheme(PreferenceUtil.getInstance().generalTheme) hideStatusBar() super.onCreate(savedInstanceState) - MaterialDialogsUtil.updateMaterialDialogsThemeSingleton(this) + //MaterialDialogsUtil.updateMaterialDialogsThemeSingleton(this) changeBackgroundShape() setImmersiveFullscreen() diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/bugreport/BugReportActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/bugreport/BugReportActivity.kt index e1e2f98f..1b99d30c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/bugreport/BugReportActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/bugreport/BugReportActivity.kt @@ -14,6 +14,7 @@ import android.view.inputmethod.EditorInfo import android.widget.Toast import androidx.annotation.StringDef import androidx.annotation.StringRes +import androidx.appcompat.app.AlertDialog import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R @@ -25,6 +26,7 @@ import code.name.monkey.retromusic.ui.activities.bugreport.model.github.ExtraInf import code.name.monkey.retromusic.ui.activities.bugreport.model.github.GithubLogin import code.name.monkey.retromusic.ui.activities.bugreport.model.github.GithubTarget import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.callbacks.onCancel import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.textfield.TextInputLayout import kotlinx.android.synthetic.main.activity_bug_report.* @@ -223,12 +225,8 @@ open class BugReportActivity : AbsThemeActivity() { private class ReportIssueAsyncTask private constructor(activity: Activity, private val report: Report, private val target: GithubTarget, private val login: GithubLogin) : DialogAsyncTask(activity) { - override fun createDialog(context: Context): Dialog { - return MaterialDialog.Builder(context) - .progress(true, 0) - .progressIndeterminateStyle(true) - .title(R.string.bug_report_uploading) + return AlertDialog.Builder(context) .show() } @@ -269,28 +267,27 @@ open class BugReportActivity : AbsThemeActivity() { when (result) { RESULT_SUCCESS -> tryToFinishActivity() - RESULT_BAD_CREDENTIALS -> MaterialDialog.Builder(context) - .title(R.string.bug_report_failed) - .content(R.string.bug_report_failed_wrong_credentials) - .positiveText(android.R.string.ok) - .show() - RESULT_INVALID_TOKEN -> MaterialDialog.Builder(context) - .title(R.string.bug_report_failed) - .content(R.string.bug_report_failed_invalid_token) - .positiveText(android.R.string.ok) - .show() - RESULT_ISSUES_NOT_ENABLED -> MaterialDialog.Builder(context) - .title(R.string.bug_report_failed) - .content(R.string.bug_report_failed_issues_not_available) - .positiveText(android.R.string.ok) - .show() - else -> MaterialDialog.Builder(context) - .title(R.string.bug_report_failed) - .content(R.string.bug_report_failed_unknown) - .positiveText(android.R.string.ok) - .onPositive { _, _ -> tryToFinishActivity() } - .cancelListener { tryToFinishActivity() } - .show() + 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() } + } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/AbsTagEditorActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/AbsTagEditorActivity.kt index a03c110b..fb9ff813 100755 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/AbsTagEditorActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/AbsTagEditorActivity.kt @@ -17,6 +17,7 @@ import code.name.monkey.retromusic.R import code.name.monkey.retromusic.ui.activities.base.AbsBaseActivity import code.name.monkey.retromusic.util.RetroUtil import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItems import kotlinx.android.synthetic.main.activity_album_tag_editor.* import org.jaudiotagger.audio.AudioFile import org.jaudiotagger.audio.AudioFileIO @@ -34,18 +35,17 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() { private var songPaths: List? = null protected val show: MaterialDialog - get() = MaterialDialog.Builder(this@AbsTagEditorActivity) - .title(R.string.update_image) - .items(*items) - .itemsCallback { _, _, position, _ -> - when (position) { - 0 -> getImageFromLastFM() - 1 -> startImagePicker() - 2 -> searchImageOnWeb() - 3 -> deleteImage() - } - }.show() - + get() = MaterialDialog(this@AbsTagEditorActivity).show { + title(R.string.update_image) + listItems(items = items as List) { _, position, _ -> + when (position) { + 0 -> getImageFromLastFM() + 1 -> startImagePicker() + 2 -> searchImageOnWeb() + 3 -> deleteImage() + } + } + } protected abstract val contentViewLayout: Int internal val albumArtist: String? diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/WriteTagsAsyncTask.java b/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/WriteTagsAsyncTask.java index d8ad8d64..40b8edaa 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/WriteTagsAsyncTask.java +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/tageditor/WriteTagsAsyncTask.java @@ -5,8 +5,6 @@ import android.app.Dialog; import android.content.Context; import android.graphics.Bitmap; import android.media.MediaScannerConnection; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import com.afollestad.materialdialogs.MaterialDialog; @@ -28,6 +26,8 @@ import java.io.IOException; import java.util.Collection; import java.util.Map; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.misc.DialogAsyncTask; import code.name.monkey.retromusic.misc.UpdateToastMediaScannerCompletionListener; @@ -134,18 +134,16 @@ public class WriteTagsAsyncTask extends @Override protected Dialog createDialog(@NonNull Context context) { - return new MaterialDialog.Builder(context) - .title(R.string.saving_changes) - .cancelable(false) - .progress(false, 0) - .build(); + return new MaterialDialog(context) + .title(R.string.saving_changes, "") + .cancelable(false); } @Override protected void onProgressUpdate(@NonNull Dialog dialog, Integer... values) { super.onProgressUpdate(dialog, values); - ((MaterialDialog) dialog).setMaxProgress(values[1]); - ((MaterialDialog) dialog).setProgress(values[0]); + //((MaterialDialog) dialog).setMaxProgress(values[1]); + //((MaterialDialog) dialog).setProgress(values[0]); } public static class LoadingInfo { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java index 01f25f74..d0a72eda 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/mainactivity/folders/FoldersFragment.java @@ -543,8 +543,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements } } - private static class ListSongsAsyncTask extends - ListingFilesDialogAsyncTask> { + private static class ListSongsAsyncTask extends ListingFilesDialogAsyncTask> { private final Object extra; private WeakReference contextWeakReference; @@ -738,15 +737,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements @Override protected Dialog createDialog(@NonNull Context context) { - return new MaterialDialog.Builder(context) - .title(R.string.listing_files) - .progress(true, 0) - .progressIndeterminateStyle(true) - .cancelListener(dialog -> cancel(false)) - .dismissListener(dialog -> cancel(false)) - .negativeText(android.R.string.cancel) - .onNegative((dialog, which) -> cancel(false)) - .show(); + return new MaterialDialog(context) + .title(R.string.listing_files,""); } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt index 17035e2d..578ec7bd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt @@ -4,6 +4,7 @@ import android.animation.ArgbEvaluator import android.animation.ValueAnimator import android.annotation.SuppressLint import android.content.Intent +import android.graphics.Color import android.graphics.drawable.Drawable import android.os.AsyncTask import android.os.Bundle @@ -12,6 +13,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar +import androidx.palette.graphics.Palette import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper @@ -142,6 +144,10 @@ class ColorFragment : AbsPlayerFragment() { override fun onResourceReady(resource: BitmapPaletteWrapper, glideAnimation: Transition?) { super.onResourceReady(resource, glideAnimation) + + val background = resource.palette.getColor() + val accentColor = resource.palette.getContrastColor(background) + val palette = resource.palette val swatch = RetroColorUtil.getSwatch(palette) @@ -298,3 +304,17 @@ class ColorFragment : AbsPlayerFragment() { } } } + +private fun Palette.getContrastColor(background: Int): Int { + + return 0 +} + +private fun Palette.getColor(): Int { + return when { + darkMutedSwatch != null -> darkMutedSwatch!!.rgb + mutedSwatch != null -> mutedSwatch!!.rgb + lightMutedSwatch != null -> lightMutedSwatch!!.rgb + else -> Palette.Swatch(Color.BLACK, 1).rgb + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.java b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.java deleted file mode 100644 index 88f24588..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.java +++ /dev/null @@ -1,78 +0,0 @@ -package code.name.monkey.retromusic.ui.fragments.settings; - -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.os.Bundle; -import android.view.View; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; -import androidx.preference.ListPreference; -import androidx.preference.Preference; -import androidx.preference.PreferenceManager; -import code.name.monkey.appthemehelper.ThemeStore; -import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat; -import code.name.monkey.retromusic.preferences.AlbumCoverStylePreference; -import code.name.monkey.retromusic.preferences.AlbumCoverStylePreferenceDialog; -import code.name.monkey.retromusic.preferences.BlacklistPreference; -import code.name.monkey.retromusic.preferences.BlacklistPreferenceDialog; -import code.name.monkey.retromusic.preferences.NowPlayingScreenPreference; -import code.name.monkey.retromusic.preferences.NowPlayingScreenPreferenceDialog; -import code.name.monkey.retromusic.util.NavigationUtil; - -/** - * @author Hemanth S (h4h13). - */ - -public abstract class AbsSettingsFragment extends ATEPreferenceFragmentCompat { - void showProToastAndNavigate(String message) { - Toast.makeText(getContext(), message + " is Pro version feature.", Toast.LENGTH_SHORT).show(); - //noinspection ConstantConditions - NavigationUtil.goToProVersion(getActivity()); - } - - protected void setSummary(@NonNull Preference preference) { - setSummary(preference, PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } - - void setSummary(Preference preference, @NonNull Object value) { - String stringValue = value.toString(); - if (preference instanceof ListPreference) { - ListPreference listPreference = (ListPreference) preference; - int index = listPreference.findIndexOfValue(stringValue); - preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); - } else { - preference.setSummary(stringValue); - } - } - - public abstract void invalidateSettings(); - - @Override - public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - setDivider(new ColorDrawable(Color.TRANSPARENT)); - getListView().setBackgroundColor(ThemeStore.Companion.primaryColor(getContext())); - getListView().setOverScrollMode(View.OVER_SCROLL_NEVER); - getListView().setPadding(0, 0, 0, 0); - getListView().setPaddingRelative(0, 0, 0, 0); - invalidateSettings(); - } - - @Nullable - @Override - public DialogFragment onCreatePreferenceDialog(Preference preference) { - if (preference instanceof NowPlayingScreenPreference) { - return NowPlayingScreenPreferenceDialog.Companion.newInstance(); - } else if (preference instanceof BlacklistPreference) { - return BlacklistPreferenceDialog.newInstance(); - } else if (preference instanceof AlbumCoverStylePreference) { - return AlbumCoverStylePreferenceDialog.Companion.newInstance(); - } - return super.onCreatePreferenceDialog(preference); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.kt new file mode 100644 index 00000000..48a930d2 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/AbsSettingsFragment.kt @@ -0,0 +1,80 @@ +package code.name.monkey.retromusic.ui.fragments.settings + +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.os.Bundle +import android.view.View +import android.widget.Toast +import androidx.fragment.app.DialogFragment +import androidx.preference.ListPreference +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import androidx.preference.PreferenceManager +import code.name.monkey.appthemehelper.ThemeStore +import code.name.monkey.retromusic.preferences.* +import code.name.monkey.retromusic.util.NavigationUtil + +/** + * @author Hemanth S (h4h13). + */ + +abstract class AbsSettingsFragment : PreferenceFragmentCompat() { + internal fun showProToastAndNavigate(message: String) { + Toast.makeText(context, "$message is Pro version feature.", Toast.LENGTH_SHORT).show() + + NavigationUtil.goToProVersion(activity!!) + } + + protected fun setSummary(preference: Preference) { + setSummary(preference, PreferenceManager + .getDefaultSharedPreferences(preference.context) + .getString(preference.key, "")!!) + } + + internal fun setSummary(preference: Preference, value: Any) { + val stringValue = value.toString() + if (preference is ListPreference) { + val index = preference.findIndexOfValue(stringValue) + preference.setSummary(if (index >= 0) preference.entries[index] else null) + } else { + preference.summary = stringValue + } + } + + abstract fun invalidateSettings() + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setDivider(ColorDrawable(Color.TRANSPARENT)) + listView.setBackgroundColor(ThemeStore.primaryColor(context!!)) + listView.overScrollMode = View.OVER_SCROLL_NEVER + listView.setPadding(0, 0, 0, 0) + listView.setPaddingRelative(0, 0, 0, 0) + invalidateSettings() + } + + override fun onDisplayPreferenceDialog(preference: Preference) { + var dialogFragment: DialogFragment? = null + if (preference is NowPlayingScreenPreference) { + dialogFragment = NowPlayingScreenPreferenceDialog.newInstance(preference.key); + } else if (preference is AlbumCoverStylePreference) { + dialogFragment = AlbumCoverStylePreferenceDialog.newInstance(preference.key); + } + if (preference is MaterialListPreference) { + val entries = preference.entries + + dialogFragment = MaterialListPreferenceDialog.newInstance(preference) + } + if (preference is BlacklistPreference) { + dialogFragment = BlacklistPreferenceDialog.newInstance(preference.key) + } + if (dialogFragment != null) { + // The dialog was created (it was one of our custom Preferences), show the dialog for it + dialogFragment.setTargetFragment(this, 0); + dialogFragment.show(this.fragmentManager, "android.support.v7.preference.PreferenceFragment.DIALOG"); + } else { + // Dialog creation could not be handled here. Try with the super method. + super.onDisplayPreferenceDialog(preference); + } + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ImageSettingFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ImageSettingFragment.kt index 9e2c71cd..ca871d74 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ImageSettingFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ImageSettingFragment.kt @@ -1,8 +1,7 @@ package code.name.monkey.retromusic.ui.fragments.settings import android.os.Bundle -import androidx.preference.Preference - +import android.view.View import code.name.monkey.retromusic.R /** @@ -23,4 +22,10 @@ class ImageSettingFragment : AbsSettingsFragment() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_images) } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val preference = findPreference("auto_download_images_policy") + setSummary(preference) + } } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/NowPlayingSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/NowPlayingSettingsFragment.kt index 3471b5ba..d353055d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/NowPlayingSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/NowPlayingSettingsFragment.kt @@ -4,9 +4,10 @@ import android.content.SharedPreferences import android.os.Bundle import android.view.View import androidx.preference.TwoStatePreference -import code.name.monkey.retromusic.R import code.name.monkey.retromusic.App +import code.name.monkey.retromusic.R import code.name.monkey.retromusic.util.PreferenceUtil +import code.name.monkey.retromusic.util.PreferenceUtil.* /** * @author Hemanth S (h4h13). @@ -26,39 +27,37 @@ class NowPlayingSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSh } true } - } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_now_playing_screen) } - private fun updateNowPlayingScreenSummary() { + private fun updateAlbumCoverStyleSummary() { + findPreference(ALBUM_COVER_STYLE).setSummary(getInstance().albumCoverStyle.titleRes) + } - findPreference("now_playing_screen_id").setSummary(PreferenceUtil.getInstance().nowPlayingScreen.titleRes) + private fun updateNowPlayingScreenSummary() { + findPreference(NOW_PLAYING_SCREEN_ID).setSummary(getInstance().nowPlayingScreen.titleRes) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - - PreferenceUtil.getInstance().registerOnSharedPreferenceChangedListener(this) + getInstance().registerOnSharedPreferenceChangedListener(this) + val preference = findPreference("album_cover_transform") + setSummary(preference) } override fun onDestroyView() { super.onDestroyView() - - PreferenceUtil.getInstance().unregisterOnSharedPreferenceChangedListener(this) + getInstance().unregisterOnSharedPreferenceChangedListener(this) } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { when (key) { - PreferenceUtil.NOW_PLAYING_SCREEN_ID -> updateNowPlayingScreenSummary() - PreferenceUtil.ALBUM_COVER_STYLE -> updateAlbumCoverStyleSummary() - PreferenceUtil.CIRCULAR_ALBUM_ART, PreferenceUtil.CAROUSEL_EFFECT -> invalidateSettings() + NOW_PLAYING_SCREEN_ID -> updateNowPlayingScreenSummary() + ALBUM_COVER_STYLE -> updateAlbumCoverStyleSummary() + CIRCULAR_ALBUM_ART, CAROUSEL_EFFECT -> invalidateSettings() } } - - private fun updateAlbumCoverStyleSummary() { - findPreference("album_cover_style_id").setSummary(PreferenceUtil.getInstance().albumCoverStyle.titleRes) - } } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/OtherSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/OtherSettingsFragment.kt index 160785e0..2bda1f00 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/OtherSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/OtherSettingsFragment.kt @@ -1,6 +1,7 @@ package code.name.monkey.retromusic.ui.fragments.settings import android.os.Bundle +import android.view.View import code.name.monkey.retromusic.R @@ -18,4 +19,10 @@ class OtherSettingsFragment : AbsSettingsFragment() { addPreferencesFromResource(R.xml.pref_playlists) addPreferencesFromResource(R.xml.pref_advanced) } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val preference = findPreference("last_added_interval") + setSummary(preference) + } } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/PersonaizeSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/PersonaizeSettingsFragment.kt index a5346510..a97beecc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/PersonaizeSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/PersonaizeSettingsFragment.kt @@ -28,8 +28,6 @@ class PersonaizeSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSh activity!!.recreate() true } - - } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -41,11 +39,19 @@ class PersonaizeSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSh override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) PreferenceUtil.getInstance().registerOnSharedPreferenceChangedListener(this) + + var preference = findPreference("album_grid_style") + setSummary(preference) + preference = findPreference("artist_grid_style") + setSummary(preference) + preference = findPreference("home_artist_grid_style") + setSummary(preference) + preference = findPreference("tab_text_mode") + setSummary(preference) } override fun onDestroyView() { super.onDestroyView() - PreferenceUtil.getInstance().unregisterOnSharedPreferenceChangedListener(this) } @@ -54,5 +60,4 @@ class PersonaizeSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSh PreferenceUtil.CAROUSEL_EFFECT -> invalidateSettings() } } - } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ThemeSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ThemeSettingsFragment.kt index 38ca63be..06a599de 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ThemeSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/settings/ThemeSettingsFragment.kt @@ -1,11 +1,12 @@ package code.name.monkey.retromusic.ui.fragments.settings import android.graphics.Color +import android.graphics.Color.BLUE import android.os.Build import android.os.Bundle import androidx.core.content.ContextCompat import androidx.preference.TwoStatePreference -import code.name.monkey.appthemehelper.ThemeStore +import code.name.monkey.appthemehelper.* import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.VersionUtils @@ -13,7 +14,9 @@ import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager import code.name.monkey.retromusic.util.PreferenceUtil -import com.afollestad.materialdialogs.color.ColorChooserDialog +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.color.colorChooser + /** * @author Hemanth S (h4h13). @@ -23,16 +26,26 @@ class ThemeSettingsFragment : AbsSettingsFragment() { override fun invalidateSettings() { val primaryColorPref = findPreference("primary_color") as ATEColorPreference - primaryColorPref.isVisible = PreferenceUtil.getInstance().generalTheme == R.style.Theme_RetroMusic_Color + primaryColorPref.isVisible = PreferenceUtil.getInstance().generalTheme == code.name.monkey.retromusic.R.style.Theme_RetroMusic_Color val primaryColor = ThemeStore.primaryColor(activity!!) primaryColorPref.setColor(primaryColor, ColorUtil.darkenColor(primaryColor)) primaryColorPref.setOnPreferenceClickListener { - ColorChooserDialog.Builder(activity!!, R.string.primary_color) - .accentMode(false) - .allowUserColorInput(true) - .allowUserColorInputAlpha(false) - .preselect(primaryColor) - .show(activity!!) + MaterialDialog(activity!!).show { + title(code.name.monkey.retromusic.R.string.primary_color) + positiveButton(R.string.set) + colorChooser(initialSelection = BLUE, allowCustomArgb = true, colors = PRIMARY_COLORS, subColors = PRIMARY_COLORS_SUB) { _, color -> + val theme = if (ColorUtil.isColorLight(color)) + PreferenceUtil.getThemeResFromPrefValue("light") + else + PreferenceUtil.getThemeResFromPrefValue("dark") + + ThemeStore.editTheme(context).activityTheme(theme).primaryColor(color).commit() + + if (VersionUtils.hasNougatMR()) + DynamicShortcutManager(context).updateDynamicShortcuts() + activity!!.recreate() + } + } true } @@ -55,8 +68,8 @@ class ThemeSettingsFragment : AbsSettingsFragment() { when (theme) { "light" -> ThemeStore.editTheme(context!!).primaryColor(Color.WHITE).commit() "black" -> ThemeStore.editTheme(context!!).primaryColor(Color.BLACK).commit() - "dark" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, R.color.md_grey_900)).commit() - "color" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, R.color.md_blue_grey_800)).commit() + "dark" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, code.name.monkey.retromusic.R.color.md_grey_900)).commit() + "color" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, code.name.monkey.retromusic.R.color.md_blue_grey_800)).commit() } ThemeStore.editTheme(activity!!) @@ -77,13 +90,17 @@ class ThemeSettingsFragment : AbsSettingsFragment() { accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor)) accentColorPref.setOnPreferenceClickListener { - ColorChooserDialog.Builder(context!!, R.string.accent_color) - .accentMode(true) - .allowUserColorInput(true) - .allowUserColorInputAlpha(false) - .preselect(accentColor) - .show(activity!!) - true + MaterialDialog(activity!!).show { + title(code.name.monkey.retromusic.R.string.primary_color) + positiveButton(R.string.set) + colorChooser(colors = ACCENT_COLORS, subColors = ACCENT_COLORS_SUB) { _, color -> + ThemeStore.editTheme(context).accentColor(color).commit() + if (VersionUtils.hasNougatMR()) + DynamicShortcutManager(context).updateDynamicShortcuts() + activity!!.recreate() + } + } + return@setOnPreferenceClickListener true } val colorAppShortcuts = findPreference("should_color_app_shortcuts") as TwoStatePreference @@ -102,6 +119,6 @@ class ThemeSettingsFragment : AbsSettingsFragment() { } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.pref_general) + addPreferencesFromResource( R.xml.pref_general) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/ColorUtils.java b/app/src/main/java/code/name/monkey/retromusic/util/ColorUtils.java deleted file mode 100755 index 2e5cf1e9..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/util/ColorUtils.java +++ /dev/null @@ -1,64 +0,0 @@ -package code.name.monkey.retromusic.util; - -import android.graphics.Color; -import androidx.annotation.ColorInt; - -public class ColorUtils { - - public static boolean isColorLight(@ColorInt int color) { - return getColorDarkness(color) < 0.5; - } - - private static double getColorDarkness(@ColorInt int color) { - if (color == Color.BLACK) - return 1.0; - else if (color == Color.WHITE || color == Color.TRANSPARENT) - return 0.0; - else - return (1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255); - } - - @ColorInt - public static int getInverseColor(@ColorInt int color) { - return (0xFFFFFF - color) | 0xFFFFFFFF; - } - - public static boolean isColorSaturated(@ColorInt int color) { - double max = Math.max(0.299 * Color.red(color), Math.max(0.587 * Color.green(color), 0.114 * Color.blue(color))); - double min = Math.min(0.299 * Color.red(color), Math.min(0.587 * Color.green(color), 0.114 * Color.blue(color))); - double diff = Math.abs(max - min); - return diff > 20; - } - - @ColorInt - public static int getMixedColor(@ColorInt int color1, @ColorInt int color2) { - return Color.rgb( - (Color.red(color1) + Color.red(color2)) / 2, - (Color.green(color1) + Color.green(color2)) / 2, - (Color.blue(color1) + Color.blue(color2)) / 2 - ); - } - - public static double getDifference(@ColorInt int color1, @ColorInt int color2) { - double diff = Math.abs(0.299 * (Color.red(color1) - Color.red(color2))); - diff += Math.abs(0.587 * (Color.green(color1) - Color.green(color2))); - diff += Math.abs(0.114 * (Color.blue(color1) - Color.blue(color2))); - return diff; - } - - @ColorInt - public static int getReadableText(@ColorInt int textColor, @ColorInt int backgroundColor) { - return getReadableText(textColor, backgroundColor, 100); - } - - @ColorInt - public static int getReadableText(@ColorInt int textColor, @ColorInt int backgroundColor, int difference) { - boolean isLight = isColorLight(backgroundColor); - for (int i = 0; getDifference(textColor, backgroundColor) < difference && i < 100; i++) { - textColor = getMixedColor(textColor, isLight ? Color.BLACK : Color.WHITE); - } - - return textColor; - } - -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java index f8693d81..a8772f89 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java @@ -7,16 +7,15 @@ import android.content.SharedPreferences.Editor; import android.content.res.TypedArray; import android.preference.PreferenceManager; -import androidx.annotation.LayoutRes; -import androidx.annotation.NonNull; -import androidx.annotation.StyleRes; -import androidx.viewpager.widget.ViewPager; - import com.google.android.material.bottomnavigation.LabelVisibilityMode; import java.io.File; import java.util.Objects; +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.annotation.StyleRes; +import androidx.viewpager.widget.ViewPager; import code.name.monkey.retromusic.App; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.helper.SortOrder; @@ -61,7 +60,7 @@ public final class PreferenceUtil { public static final String HOME_ARTIST_GRID_STYLE = "home_artist_grid_style"; public static final String ARTIST_GRID_STYLE = "artist_grid_style"; public static final String TOGGLE_ADD_CONTROLS = "toggle_add_controls"; - public static final String ALBUM_COVER_STYLE = "album_cover_style"; + public static final String ALBUM_COVER_STYLE = "album_cover_style_id"; public static final String ALBUM_COVER_TRANSFORM = "album_cover_transform"; public static final String TAB_TEXT_MODE = "tab_text_mode"; private static final String GENRE_SORT_ORDER = "genre_sort_order"; @@ -109,6 +108,7 @@ public final class PreferenceUtil { private static final String PAUSE_ON_ZERO_VOLUME = "pause_on_zero_volume"; private static final String NOW_PLAYING_SCREEN = "now_playing_screen"; private static final String SNOW_FALL_EFFECT = "snow_fall_effect"; + private static final String FILTER_SONG = "filter_song"; private static PreferenceUtil sInstance; private final SharedPreferences mPreferences; @@ -140,6 +140,10 @@ public final class PreferenceUtil { } } + public int getFilterLength() { + return mPreferences.getInt(FILTER_SONG, 20); + } + public boolean isSnowFall() { return mPreferences.getBoolean(SNOW_FALL_EFFECT, false); } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java index c1a9325e..ce896450 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java @@ -40,7 +40,7 @@ public class RetroColorUtil { int background = getSwatch(palette).getRgb(); if (inverse != -1) { - return ColorUtils.getReadableText(inverse, background, 150); + return ColorUtil.INSTANCE.getReadableText(inverse, background, 150); } return ColorUtil.INSTANCE.stripAlpha(getSwatch(palette).getTitleTextColor()); } diff --git a/app/src/main/java/code/name/monkey/retromusic/views/ColorIconsImageView.kt b/app/src/main/java/code/name/monkey/retromusic/views/ColorIconsImageView.kt index 32e7bb14..4cd21442 100644 --- a/app/src/main/java/code/name/monkey/retromusic/views/ColorIconsImageView.kt +++ b/app/src/main/java/code/name/monkey/retromusic/views/ColorIconsImageView.kt @@ -5,6 +5,8 @@ import android.content.res.ColorStateList import android.graphics.Color import android.util.AttributeSet import androidx.appcompat.widget.AppCompatImageView +import code.name.monkey.appthemehelper.ThemeStore +import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.retromusic.R @@ -31,8 +33,20 @@ class ColorIconsImageView : AppCompatImageView { private fun setIconBackgroundColor(color: Int) { setBackgroundResource(R.drawable.color_circle_gradient) - backgroundTintList = ColorStateList.valueOf(ColorUtil.adjustAlpha(color, 0.3f)) - imageTintList = ColorStateList.valueOf(color) + + val alpha = if (ATHUtil.isWindowBackgroundDark(context)) { + 1.0f + } else { + 0.28f + } + val filterColor = if (ATHUtil.isWindowBackgroundDark(context)) { + ThemeStore.textColorPrimary(context) + } else { + color + } + + backgroundTintList = ColorStateList.valueOf(ColorUtil.adjustAlpha(color, alpha)) + imageTintList = ColorStateList.valueOf(filterColor) requestLayout() invalidate() } diff --git a/app/src/main/res/layout/abs_playlists.xml b/app/src/main/res/layout/abs_playlists.xml index 0188a6d1..cd360fae 100644 --- a/app/src/main/res/layout/abs_playlists.xml +++ b/app/src/main/res/layout/abs_playlists.xml @@ -7,8 +7,8 @@ + android:text="@string/for_you" + android:textStyle="bold" /> - + app:iconBackgroundColor="@color/md_blue_A700" + app:srcCompat="@drawable/ic_access_time_white_24dp" /> - + app:iconBackgroundColor="@color/md_red_A700" + app:srcCompat="@drawable/ic_library_add_white_24dp" /> - + app:iconBackgroundColor="@color/md_deep_purple_A700" + app:srcCompat="@drawable/ic_trending_up_white_24dp" /> - + app:iconBackgroundColor="@color/md_green_A700" + app:srcCompat="@drawable/ic_shuffle_white_24dp" /> Scan Scan directory Search + Set Start Set as ringtone Set as start directory @@ -593,4 +594,8 @@ Send crash log Pinterest Hmm + Filter song length + Error + Permission error + diff --git a/app/src/main/res/values/styles_parents.xml b/app/src/main/res/values/styles_parents.xml index 3db3151e..498f10e2 100644 --- a/app/src/main/res/values/styles_parents.xml +++ b/app/src/main/res/values/styles_parents.xml @@ -1,79 +1,16 @@ - - - - + + + + +