Initial commit retro music app
This commit is contained in:
parent
ab332473bc
commit
fe890632fd
932 changed files with 83126 additions and 0 deletions
|
@ -0,0 +1,25 @@
|
|||
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,124 @@
|
|||
package code.name.monkey.retromusic.preferences;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
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,165 @@
|
|||
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.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
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 code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.RetroApplication;
|
||||
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(getActivity()).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(getActivity()).setNowPlayingScreen(nowPlayingScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNowPlayingThemes(NowPlayingScreen nowPlayingScreen) {
|
||||
|
||||
if (nowPlayingScreen.equals(NowPlayingScreen.BLUR_CARD)) {
|
||||
PreferenceUtil.getInstance(getContext()).resetCarouselEffect();
|
||||
PreferenceUtil.getInstance(getContext()).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))
|
||||
&& !RetroApplication.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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue