Dialog corner and Filter song duration

This commit is contained in:
h4h13 2019-02-19 16:08:51 +05:30
parent a5a27e62aa
commit fc868e1c2e
75 changed files with 1409 additions and 1294 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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<String>
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<String> 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();
}*/
}

View file

@ -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<String>
val entriesValues = listPreference.entryValues.toList() as ArrayList<String>
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
}
}
}

View file

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

View file

@ -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<ViewPager>(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<ViewPager>(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<ImageView>(R.id.image)
val title = layout.findViewById<TextView>(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<ImageView>(R.id.image)
val title = layout.findViewById<TextView>(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)
}
}