Removed butter knife
This commit is contained in:
parent
d5f63b91ac
commit
63e3276098
194 changed files with 5984 additions and 7491 deletions
|
@ -1,25 +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;
|
||||
|
||||
|
||||
public class AlbumCoverStylePreference extends ATEDialogPreference {
|
||||
public AlbumCoverStylePreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public AlbumCoverStylePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public AlbumCoverStylePreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public AlbumCoverStylePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package code.name.monkey.retromusic.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
|
||||
|
||||
|
||||
class AlbumCoverStylePreference : 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)
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
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.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
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;
|
||||
|
||||
|
||||
public class AlbumCoverStylePreferenceDialog extends DialogFragment implements
|
||||
ViewPager.OnPageChangeListener, MaterialDialog.SingleButtonCallback {
|
||||
public static final String TAG = AlbumCoverStylePreferenceDialog.class.getSimpleName();
|
||||
|
||||
private DialogAction whichButtonClicked;
|
||||
private int viewPagerPosition;
|
||||
|
||||
public static AlbumCoverStylePreferenceDialog newInstance() {
|
||||
return new AlbumCoverStylePreferenceDialog();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(getActivity()).inflate(R.layout.preference_dialog_now_playing_screen, null);
|
||||
ViewPager viewPager = view.findViewById(R.id.now_playing_screen_view_pager);
|
||||
viewPager.setAdapter(new AlbumCoverStyleAdapter(getActivity()));
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources()));
|
||||
viewPager.setCurrentItem(PreferenceUtil.getInstance().getAlbumCoverStyle().ordinal());
|
||||
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
.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
|
||||
public void onClick(@NonNull MaterialDialog dialog,
|
||||
@NonNull DialogAction which) {
|
||||
whichButtonClicked = which;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (whichButtonClicked == DialogAction.POSITIVE) {
|
||||
AlbumCoverStyle nowPlayingScreen = AlbumCoverStyle.values()[viewPagerPosition];
|
||||
PreferenceUtil.getInstance().setAlbumCoverStyle(nowPlayingScreen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
this.viewPagerPosition = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
private static class AlbumCoverStyleAdapter extends PagerAdapter {
|
||||
|
||||
private Context context;
|
||||
|
||||
AlbumCoverStyleAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(@NonNull ViewGroup collection, int position) {
|
||||
AlbumCoverStyle albumCoverStyle = AlbumCoverStyle.values()[position];
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.preference_now_playing_screen_item, collection, false);
|
||||
collection.addView(layout);
|
||||
|
||||
ImageView image = layout.findViewById(R.id.image);
|
||||
TextView title = layout.findViewById(R.id.title);
|
||||
Glide.with(context).load(albumCoverStyle.drawableResId).into(image);
|
||||
title.setText(albumCoverStyle.titleRes);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(@NonNull ViewGroup collection,
|
||||
int position,
|
||||
@NonNull Object view) {
|
||||
collection.removeView((View) view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return AlbumCoverStyle.values().length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return context.getString(AlbumCoverStyle.values()[position].titleRes);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
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.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.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.bumptech.glide.Glide
|
||||
|
||||
|
||||
class AlbumCoverStylePreferenceDialog : DialogFragment(), ViewPager.OnPageChangeListener, MaterialDialog.SingleButtonCallback {
|
||||
|
||||
private var whichButtonClicked: DialogAction? = null
|
||||
private var viewPagerPosition: Int = 0
|
||||
|
||||
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 = AlbumCoverStyleAdapter(activity!!)
|
||||
viewPager.addOnPageChangeListener(this)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
this.viewPagerPosition = position
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
|
||||
}
|
||||
|
||||
private class AlbumCoverStyleAdapter internal constructor(private val context: Context) : PagerAdapter() {
|
||||
|
||||
override fun instantiateItem(collection: ViewGroup, position: Int): Any {
|
||||
val albumCoverStyle = AlbumCoverStyle.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(albumCoverStyle.drawableResId).into(image)
|
||||
title.setText(albumCoverStyle.titleRes)
|
||||
|
||||
return layout
|
||||
}
|
||||
|
||||
override fun destroyItem(collection: ViewGroup,
|
||||
position: Int,
|
||||
view: Any) {
|
||||
collection.removeView(view as View)
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return AlbumCoverStyle.values().size
|
||||
}
|
||||
|
||||
override fun isViewFromObject(view: View, `object`: Any): Boolean {
|
||||
return view === `object`
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
return context.getString(AlbumCoverStyle.values()[position].titleRes)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String = AlbumCoverStylePreferenceDialog::class.java.simpleName
|
||||
|
||||
fun newInstance(): AlbumCoverStylePreferenceDialog {
|
||||
return AlbumCoverStylePreferenceDialog()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +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;
|
||||
|
||||
|
||||
public class BlacklistPreference extends ATEDialogPreference {
|
||||
public BlacklistPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public BlacklistPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public BlacklistPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public BlacklistPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
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)
|
||||
}
|
|
@ -1,25 +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;
|
||||
|
||||
|
||||
public class NowPlayingScreenPreference extends ATEDialogPreference {
|
||||
public NowPlayingScreenPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public NowPlayingScreenPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public NowPlayingScreenPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public NowPlayingScreenPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
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) {}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
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.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.App;
|
||||
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;
|
||||
|
||||
|
||||
public class NowPlayingScreenPreferenceDialog extends DialogFragment implements
|
||||
ViewPager.OnPageChangeListener, MaterialDialog.SingleButtonCallback {
|
||||
public static final String TAG = NowPlayingScreenPreferenceDialog.class.getSimpleName();
|
||||
|
||||
private DialogAction whichButtonClicked;
|
||||
private int viewPagerPosition;
|
||||
|
||||
public static NowPlayingScreenPreferenceDialog newInstance() {
|
||||
return new NowPlayingScreenPreferenceDialog();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(getActivity())
|
||||
.inflate(R.layout.preference_dialog_now_playing_screen, null);
|
||||
ViewPager viewPager = view.findViewById(R.id.now_playing_screen_view_pager);
|
||||
viewPager.setAdapter(new NowPlayingScreenAdapter(getActivity()));
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources()));
|
||||
viewPager.setCurrentItem(PreferenceUtil.getInstance().getNowPlayingScreen().ordinal());
|
||||
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
.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
|
||||
public void onClick(@NonNull MaterialDialog dialog,
|
||||
@NonNull DialogAction which) {
|
||||
whichButtonClicked = which;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (whichButtonClicked == DialogAction.POSITIVE) {
|
||||
NowPlayingScreen nowPlayingScreen = NowPlayingScreen.values()[viewPagerPosition];
|
||||
if (isNowPlayingThemes(nowPlayingScreen)) {
|
||||
String result = getString(nowPlayingScreen.titleRes) + " theme is Pro version feature.";
|
||||
Toast.makeText(getContext(), result, Toast.LENGTH_SHORT).show();
|
||||
NavigationUtil.goToProVersion(getActivity());
|
||||
} else {
|
||||
PreferenceUtil.getInstance().setNowPlayingScreen(nowPlayingScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNowPlayingThemes(NowPlayingScreen nowPlayingScreen) {
|
||||
|
||||
/*if (nowPlayingScreen.equals(NowPlayingScreen.BLUR_CARD)) {
|
||||
PreferenceUtil.getInstance().resetCarouselEffect();
|
||||
PreferenceUtil.getInstance().resetCircularAlbumArt();
|
||||
}*/
|
||||
|
||||
/* return (nowPlayingScreen.equals(NowPlayingScreen.FULL) ||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.CARD) ||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.PLAIN) ||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.BLUR) ||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.COLOR) ||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.SIMPLE) ||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.TINY) ||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.BLUR_CARD)||
|
||||
nowPlayingScreen.equals(NowPlayingScreen.ADAPTIVE))
|
||||
&& !App.Companion.isProVersion();*/
|
||||
return !App.Companion.isProVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
this.viewPagerPosition = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
private static class NowPlayingScreenAdapter extends PagerAdapter {
|
||||
|
||||
private Context context;
|
||||
|
||||
NowPlayingScreenAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(@NonNull ViewGroup collection, int position) {
|
||||
NowPlayingScreen nowPlayingScreen = NowPlayingScreen.values()[position];
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.preference_now_playing_screen_item, collection, false);
|
||||
collection.addView(layout);
|
||||
|
||||
ImageView image = layout.findViewById(R.id.image);
|
||||
TextView title = layout.findViewById(R.id.title);
|
||||
Glide.with(context).load(nowPlayingScreen.drawableResId).into(image);
|
||||
title.setText(nowPlayingScreen.titleRes);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(@NonNull ViewGroup collection,
|
||||
int position,
|
||||
@NonNull Object view) {
|
||||
collection.removeView((View) view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return NowPlayingScreen.values().length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return context.getString(NowPlayingScreen.values()[position].titleRes);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
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.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.viewpager.widget.PagerAdapter
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
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.bumptech.glide.Glide
|
||||
|
||||
|
||||
class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChangeListener, MaterialDialog.SingleButtonCallback {
|
||||
|
||||
private var whichButtonClicked: DialogAction? = null
|
||||
private var viewPagerPosition: Int = 0
|
||||
|
||||
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 onDismiss(dialog: DialogInterface?) {
|
||||
super.onDismiss(dialog)
|
||||
if (whichButtonClicked == DialogAction.POSITIVE) {
|
||||
val nowPlayingScreen = NowPlayingScreen.values()[viewPagerPosition]
|
||||
if (isNowPlayingThemes(nowPlayingScreen)) {
|
||||
val result = getString(nowPlayingScreen.titleRes) + " theme is Pro version feature."
|
||||
Toast.makeText(context, result, Toast.LENGTH_SHORT).show()
|
||||
NavigationUtil.goToProVersion(activity!!)
|
||||
} else {
|
||||
PreferenceUtil.getInstance().nowPlayingScreen = nowPlayingScreen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isNowPlayingThemes(nowPlayingScreen: NowPlayingScreen): Boolean {
|
||||
|
||||
if (nowPlayingScreen == NowPlayingScreen.BLUR_CARD) {
|
||||
PreferenceUtil.getInstance().resetCarouselEffect()
|
||||
PreferenceUtil.getInstance().resetCircularAlbumArt()
|
||||
}
|
||||
|
||||
return (nowPlayingScreen == NowPlayingScreen.FULL ||
|
||||
nowPlayingScreen == NowPlayingScreen.CARD ||
|
||||
nowPlayingScreen == NowPlayingScreen.PLAIN ||
|
||||
nowPlayingScreen == NowPlayingScreen.BLUR ||
|
||||
nowPlayingScreen == NowPlayingScreen.COLOR ||
|
||||
nowPlayingScreen == NowPlayingScreen.SIMPLE ||
|
||||
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
|
||||
|
||||
fun newInstance(): NowPlayingScreenPreferenceDialog {
|
||||
return NowPlayingScreenPreferenceDialog()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue