code refactor

This commit is contained in:
h4h13 2018-07-30 22:54:37 +05:30
parent 8a731b5073
commit f386a2cf07
7 changed files with 1529 additions and 1478 deletions

View file

@ -1,36 +1,13 @@
package code.name.monkey.retromusic.dialogs; package code.name.monkey.retromusic.dialogs;
/*
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.text.Html;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import code.name.monkey.retromusic.model.Song;
import java.util.ArrayList;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.util.MusicUtil;
*/
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.text.Html; import android.text.Html;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
@ -38,75 +15,78 @@ import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.model.Song; import code.name.monkey.retromusic.model.Song;
import code.name.monkey.retromusic.util.MusicUtil; import code.name.monkey.retromusic.util.MusicUtil;
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment; import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
import java.util.ArrayList;
/**
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
*/
public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment { public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
@BindView(R.id.action_delete)
TextView delete;
@BindView(R.id.title)
TextView title;
@BindView(R.id.action_cancel)
TextView cancel;
@NonNull @BindView(R.id.action_delete)
public static DeleteSongsDialog create(Song song) { TextView delete;
ArrayList<Song> list = new ArrayList<>(); @BindView(R.id.title)
list.add(song); TextView title;
return create(list); @BindView(R.id.action_cancel)
} TextView cancel;
@NonNull @NonNull
public static DeleteSongsDialog create(ArrayList<Song> songs) { public static DeleteSongsDialog create(Song song) {
DeleteSongsDialog dialog = new DeleteSongsDialog(); ArrayList<Song> list = new ArrayList<>();
Bundle args = new Bundle(); list.add(song);
args.putParcelableArrayList("songs", songs); return create(list);
dialog.setArguments(args); }
return dialog;
}
@OnClick({R.id.action_cancel, R.id.action_delete}) @NonNull
void actions(View view) { public static DeleteSongsDialog create(ArrayList<Song> songs) {
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs"); DeleteSongsDialog dialog = new DeleteSongsDialog();
switch (view.getId()) { Bundle args = new Bundle();
case R.id.action_delete: args.putParcelableArrayList("songs", songs);
if (getActivity() == null) dialog.setArguments(args);
return; return dialog;
MusicUtil.deleteTracks(getActivity(), songs); }
break;
default: @OnClick({R.id.action_cancel, R.id.action_delete})
void actions(View view) {
//noinspection ConstantConditions
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
switch (view.getId()) {
case R.id.action_delete:
if (getActivity() == null) {
return;
} }
dismiss(); if (songs != null) {
} MusicUtil.deleteTracks(getActivity(), songs);
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//noinspection unchecked
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
int title;
CharSequence content;
if (songs != null && songs.size() > 1) {
title = R.string.delete_songs_title;
content = Html.fromHtml(getString(R.string.delete_x_songs, songs.size()));
} else {
title = R.string.delete_song_title;
content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).title));
} }
break;
this.title.setText(title); default:
this.delete.setText(content);
} }
dismiss();
}
@Nullable @Override
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState);
View layout = inflater.inflate(R.layout.dialog_delete_songs, container, false); //noinspection unchecked,ConstantConditions
ButterKnife.bind(this, layout); final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
return layout; int title;
CharSequence content;
if (songs != null) {
if (songs.size() > 1) {
title = R.string.delete_songs_title;
content = Html.fromHtml(getString(R.string.delete_x_songs, songs.size()));
} else {
title = R.string.delete_song_title;
content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).title));
}
this.title.setText(title);
this.delete.setText(content);
} }
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.dialog_delete_songs, container, false);
ButterKnife.bind(this, layout);
return layout;
}
} }

View file

@ -15,142 +15,143 @@ import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import code.name.monkey.appthemehelper.ThemeStore; import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public abstract class AbsBaseActivity extends AbsThemeActivity { public abstract class AbsBaseActivity extends AbsThemeActivity {
public static final int PERMISSION_REQUEST = 100;
private boolean hadPermissions; public static final int PERMISSION_REQUEST = 100;
private String[] permissions; private boolean hadPermissions;
private String permissionDeniedMessage; private String[] permissions;
private String permissionDeniedMessage;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setVolumeControlStream(AudioManager.STREAM_MUSIC); setVolumeControlStream(AudioManager.STREAM_MUSIC);
permissions = getPermissionsToRequest(); permissions = getPermissionsToRequest();
hadPermissions = hasPermissions(); hadPermissions = hasPermissions();
setPermissionDeniedMessage(null); setPermissionDeniedMessage(null);
}
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
if (!hasPermissions()) {
requestPermissions();
}
}
@Override
protected void onResume() {
super.onResume();
final boolean hasPermissions = hasPermissions();
if (hasPermissions != hadPermissions) {
hadPermissions = hasPermissions;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
onHasPermissionsChanged(hasPermissions);
}
} }
@Override }
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); protected void onHasPermissionsChanged(boolean hasPermissions) {
if (!hasPermissions()) { // implemented by sub classes
requestPermissions(); }
@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) {
showOverflowMenu();
return true;
}
return super.dispatchKeyEvent(event);
}
protected void showOverflowMenu() {
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
@Nullable
protected String[] getPermissionsToRequest() {
return null;
}
protected View getSnackBarContainer() {
return getWindow().getDecorView();
}
private String getPermissionDeniedMessage() {
return permissionDeniedMessage == null ? getString(R.string.permissions_denied)
: permissionDeniedMessage;
}
protected void setPermissionDeniedMessage(String message) {
permissionDeniedMessage = message;
}
protected void requestPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) {
requestPermissions(permissions, PERMISSION_REQUEST);
}
}
protected boolean hasPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) {
for (String permission : permissions) {
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
return false;
} }
}
} }
return true;
}
@Override @Override
protected void onResume() { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
super.onResume(); @NonNull int[] grantResults) {
final boolean hasPermissions = hasPermissions(); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (hasPermissions != hadPermissions) { if (requestCode == PERMISSION_REQUEST) {
hadPermissions = hasPermissions; for (int grantResult : grantResults) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (grantResult != PackageManager.PERMISSION_GRANTED) {
onHasPermissionsChanged(hasPermissions); if (ActivityCompat.shouldShowRequestPermissionRationale(AbsBaseActivity.this,
} Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
} //User has deny from permission dialog
Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
} Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.action_grant, view -> requestPermissions())
protected void onHasPermissionsChanged(boolean hasPermissions) { .setActionTextColor(ThemeStore.accentColor(this))
// implemented by sub classes .show();
} } else {
// User has deny permission and checked never show permission dialog so you can redirect to Application settings page
@Override Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
public boolean dispatchKeyEvent(@NonNull KeyEvent event) { Snackbar.LENGTH_INDEFINITE)
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) { .setAction(R.string.action_settings, view -> {
showOverflowMenu(); Intent intent = new Intent();
return true; intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
} Uri uri = Uri.fromParts("package", AbsBaseActivity.this.getPackageName(), null);
return super.dispatchKeyEvent(event); intent.setData(uri);
} startActivity(intent);
})
protected void showOverflowMenu() { .setActionTextColor(ThemeStore.accentColor(this))
.show();
} }
return;
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
@Nullable
protected String[] getPermissionsToRequest() {
return null;
}
protected View getSnackBarContainer() {
return getWindow().getDecorView();
}
private String getPermissionDeniedMessage() {
return permissionDeniedMessage == null ? getString(R.string.permissions_denied) : permissionDeniedMessage;
}
protected void setPermissionDeniedMessage(String message) {
permissionDeniedMessage = message;
}
protected void requestPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) {
requestPermissions(permissions, PERMISSION_REQUEST);
}
}
protected boolean hasPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) {
for (String permission : permissions) {
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST) {
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(AbsBaseActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
//User has deny from permission dialog
Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.action_grant, view -> requestPermissions())
.setActionTextColor(ThemeStore.accentColor(this))
.show();
} else {
// User has deny permission and checked never show permission dialog so you can redirect to Application settings page
Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.action_settings, view -> {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", AbsBaseActivity.this.getPackageName(), null);
intent.setData(uri);
startActivity(intent);
})
.setActionTextColor(ThemeStore.accentColor(this))
.show();
}
return;
}
}
hadPermissions = true;
onHasPermissionsChanged(true);
} }
}
hadPermissions = true;
onHasPermissionsChanged(true);
} }
}
} }

View file

@ -11,10 +11,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.animation.PathInterpolator; import android.view.animation.PathInterpolator;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import code.name.monkey.appthemehelper.ThemeStore; import code.name.monkey.appthemehelper.ThemeStore;
@ -39,396 +35,399 @@ import code.name.monkey.retromusic.ui.fragments.player.simple.SimplePlayerFragme
import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.PreferenceUtil;
import code.name.monkey.retromusic.util.ViewUtil; import code.name.monkey.retromusic.util.ViewUtil;
import code.name.monkey.retromusic.views.BottomNavigationViewEx; import code.name.monkey.retromusic.views.BottomNavigationViewEx;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity implements public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity implements
SlidingUpPanelLayout.PanelSlideListener, SlidingUpPanelLayout.PanelSlideListener,
PlayerFragment.Callbacks { PlayerFragment.Callbacks {
public static final String TAG = AbsSlidingMusicPanelActivity.class.getSimpleName(); public static final String TAG = AbsSlidingMusicPanelActivity.class.getSimpleName();
@BindView(R.id.bottom_navigation) @BindView(R.id.bottom_navigation)
BottomNavigationViewEx bottomNavigationView; BottomNavigationViewEx bottomNavigationView;
@BindView(R.id.sliding_layout) @BindView(R.id.sliding_layout)
SlidingUpPanelLayout slidingUpPanelLayout; SlidingUpPanelLayout slidingUpPanelLayout;
private int navigationbarColor; private int navigationbarColor;
private int taskColor; private int taskColor;
private boolean lightStatusBar; private boolean lightStatusBar;
private boolean lightNavigationBar; private boolean lightNavigationBar;
private NowPlayingScreen currentNowPlayingScreen; private NowPlayingScreen currentNowPlayingScreen;
private AbsPlayerFragment playerFragment; private AbsPlayerFragment playerFragment;
private MiniPlayerFragment miniPlayerFragment; private MiniPlayerFragment miniPlayerFragment;
private ValueAnimator navigationBarColorAnimator; private ValueAnimator navigationBarColorAnimator;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(createContentView()); setContentView(createContentView());
ButterKnife.bind(this); ButterKnife.bind(this);
choosFragmentForTheme(); choosFragmentForTheme();
//noinspection ConstantConditions //noinspection ConstantConditions
miniPlayerFragment.getView().setOnClickListener(v -> expandPanel()); miniPlayerFragment.getView().setOnClickListener(v -> expandPanel());
slidingUpPanelLayout.getViewTreeObserver() slidingUpPanelLayout.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {
slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (getPanelState() == PanelState.EXPANDED) { if (getPanelState() == PanelState.EXPANDED) {
onPanelSlide(slidingUpPanelLayout, 1); onPanelSlide(slidingUpPanelLayout, 1);
onPanelExpanded(slidingUpPanelLayout); onPanelExpanded(slidingUpPanelLayout);
} else if (getPanelState() == PanelState.COLLAPSED) { } else if (getPanelState() == PanelState.COLLAPSED) {
onPanelCollapsed(slidingUpPanelLayout); onPanelCollapsed(slidingUpPanelLayout);
} else { } else {
playerFragment.onHide(); playerFragment.onHide();
} }
} }
}); });
setupBottomView(); setupBottomView();
slidingUpPanelLayout.addPanelSlideListener(this); slidingUpPanelLayout.addPanelSlideListener(this);
}
private void choosFragmentForTheme() {
currentNowPlayingScreen = PreferenceUtil.getInstance(this).getNowPlayingScreen();
Fragment fragment; // must implement AbsPlayerFragment
switch (currentNowPlayingScreen) {
case MATERIAL:
fragment = new MaterialFragment();
break;
case BLUR:
fragment = new BlurPlayerFragment();
break;
case FLAT:
fragment = new FlatPlayerFragment();
break;
case PLAIN:
fragment = new PlainPlayerFragment();
break;
case FULL:
fragment = new FullPlayerFragment();
break;
case COLOR:
fragment = new ColorFragment();
break;
case CARD:
fragment = new CardFragment();
break;
case SIMPLE:
fragment = new SimplePlayerFragment();
break;
case TINY:
fragment = new HmmPlayerFragment();
break;
case BLUR_CARD:
fragment = new CardBlurFragment();
break;
case ADAPTIVE:
fragment = new AdaptiveFragment();
break;
case NORMAL:
default:
fragment = new PlayerFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.player_fragment_container, fragment)
.commit();
getSupportFragmentManager().executePendingTransactions();
playerFragment = (AbsPlayerFragment) getSupportFragmentManager()
.findFragmentById(R.id.player_fragment_container);
miniPlayerFragment = (MiniPlayerFragment) getSupportFragmentManager()
.findFragmentById(R.id.mini_player_fragment);
}
private void setupBottomView() {
bottomNavigationView.setSelectedItemId(PreferenceUtil.getInstance(this).getLastPage());
bottomNavigationView.setBackgroundColor(ThemeStore.primaryColor(this));
bottomNavigationView.enableAnimation(false);
bottomNavigationView.enableItemShiftingMode(false);
bottomNavigationView.enableShiftingMode(false);
bottomNavigationView.setTextSize(10f);
bottomNavigationView.setTextVisibility(PreferenceUtil.getInstance(this).tabTitles());
}
@Override
protected void onResume() {
super.onResume();
if (currentNowPlayingScreen != PreferenceUtil.getInstance(this).getNowPlayingScreen()) {
postRecreate();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (navigationBarColorAnimator != null) {
navigationBarColorAnimator.cancel(); // just in case
}
}
protected abstract View createContentView();
@Override
public void onServiceConnected() {
super.onServiceConnected();
if (!MusicPlayerRemote.getPlayingQueue().isEmpty()) {
slidingUpPanelLayout.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
hideBottomBar(false);
}
});
}// don't call hideBottomBar(true) here as it causes a bug with the SlidingUpPanelLayout
}
@Override
public void onQueueChanged() {
super.onQueueChanged();
hideBottomBar(MusicPlayerRemote.getPlayingQueue().isEmpty());
}
@Override
public void onPanelSlide(View panel, @FloatRange(from = 0, to = 1) float slideOffset) {
bottomNavigationView.setTranslationY(slideOffset * 400);
setMiniPlayerAlphaProgress(slideOffset);
//findViewById(R.id.player_fragment_container).setAlpha(slideOffset);
}
@Override
public void onPanelStateChanged(View panel, PanelState previousState, PanelState newState) {
switch (newState) {
case COLLAPSED:
onPanelCollapsed(panel);
break;
case EXPANDED:
onPanelExpanded(panel);
break;
case ANCHORED:
collapsePanel(); // this fixes a bug where the panel would get stuck for some reason
break;
}
}
public void onPanelCollapsed(View panel) {
// restore values
super.setLightStatusbar(lightStatusBar);
super.setTaskDescriptionColor(taskColor);
super.setNavigationbarColor(navigationbarColor);
super.setLightNavigationBar(lightNavigationBar);
playerFragment.setMenuVisibility(false);
playerFragment.setUserVisibleHint(false);
playerFragment.onHide();
}
public void onPanelExpanded(View panel) {
// setting fragments values
int playerFragmentColor = playerFragment.getPaletteColor();
super.setTaskDescriptionColor(playerFragmentColor);
if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
super.setNavigationbarColor(playerFragmentColor);
} else {
super.setNavigationbarColor(ThemeStore.primaryColor(this));
} }
private void choosFragmentForTheme() { setLightStatusBar();
currentNowPlayingScreen = PreferenceUtil.getInstance(this).getNowPlayingScreen();
Fragment fragment; // must implement AbsPlayerFragment playerFragment.setMenuVisibility(true);
switch (currentNowPlayingScreen) { playerFragment.setUserVisibleHint(true);
case MATERIAL: playerFragment.onShow();
fragment = new MaterialFragment(); }
break;
case BLUR:
fragment = new BlurPlayerFragment();
break;
case FLAT:
fragment = new FlatPlayerFragment();
break;
case PLAIN:
fragment = new PlainPlayerFragment();
break;
case FULL:
fragment = new FullPlayerFragment();
break;
case COLOR:
fragment = new ColorFragment();
break;
case CARD:
fragment = new CardFragment();
break;
case SIMPLE:
fragment = new SimplePlayerFragment();
break;
case TINY:
fragment = new HmmPlayerFragment();
break;
case BLUR_CARD:
fragment = new CardBlurFragment();
break;
case ADAPTIVE:
fragment = new AdaptiveFragment();
break;
case NORMAL: private void setLightStatusBar() {
default: super.setLightStatusbar(!PreferenceUtil.getInstance(this).getAdaptiveColor() &&
fragment = new PlayerFragment(); ColorUtil.isColorLight(ThemeStore.primaryColor(this)) && (
break; currentNowPlayingScreen == NowPlayingScreen.FLAT
} || currentNowPlayingScreen == NowPlayingScreen.PLAIN
getSupportFragmentManager().beginTransaction().replace(R.id.player_fragment_container, fragment) || currentNowPlayingScreen == NowPlayingScreen.SIMPLE
.commit(); || currentNowPlayingScreen == NowPlayingScreen.NORMAL
getSupportFragmentManager().executePendingTransactions(); || currentNowPlayingScreen == NowPlayingScreen.ADAPTIVE
|| currentNowPlayingScreen == NowPlayingScreen.TINY
|| currentNowPlayingScreen == NowPlayingScreen.MATERIAL));
}
playerFragment = (AbsPlayerFragment) getSupportFragmentManager() @Override
.findFragmentById(R.id.player_fragment_container); public void setLightStatusbar(boolean enabled) {
miniPlayerFragment = (MiniPlayerFragment) getSupportFragmentManager() lightStatusBar = enabled;
.findFragmentById(R.id.mini_player_fragment); if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setLightStatusbar(enabled);
} }
}
private void setupBottomView() { @Override
bottomNavigationView.setSelectedItemId(PreferenceUtil.getInstance(this).getLastPage()); public void setLightNavigationBar(boolean enabled) {
bottomNavigationView.setBackgroundColor(ThemeStore.primaryColor(this)); lightNavigationBar = enabled;
bottomNavigationView.enableAnimation(false);
bottomNavigationView.enableItemShiftingMode(false);
bottomNavigationView.enableShiftingMode(false);
bottomNavigationView.setTextSize(10f);
bottomNavigationView.setTextVisibility(PreferenceUtil.getInstance(this).tabTitles());
}
@Override
protected void onResume() {
super.onResume();
if (currentNowPlayingScreen != PreferenceUtil.getInstance(this).getNowPlayingScreen()) {
postRecreate();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (navigationBarColorAnimator != null) {
navigationBarColorAnimator.cancel(); // just in case
}
}
protected abstract View createContentView();
@Override
public void onServiceConnected() {
super.onServiceConnected();
if (!MusicPlayerRemote.getPlayingQueue().isEmpty()) {
slidingUpPanelLayout.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
hideBottomBar(false);
}
});
}// don't call hideBottomBar(true) here as it causes a bug with the SlidingUpPanelLayout
}
@Override
public void onQueueChanged() {
super.onQueueChanged();
hideBottomBar(MusicPlayerRemote.getPlayingQueue().isEmpty());
}
@Override
public void onPanelSlide(View panel, @FloatRange(from = 0, to = 1) float slideOffset) {
bottomNavigationView.setTranslationY(slideOffset * 400);
setMiniPlayerAlphaProgress(slideOffset);
//findViewById(R.id.player_fragment_container).setAlpha(slideOffset);
}
@Override
public void onPanelStateChanged(View panel, PanelState previousState, PanelState newState) {
switch (newState) {
case COLLAPSED:
onPanelCollapsed(panel);
break;
case EXPANDED:
onPanelExpanded(panel);
break;
case ANCHORED:
collapsePanel(); // this fixes a bug where the panel would get stuck for some reason
break;
}
}
public void onPanelCollapsed(View panel) {
// restore values
super.setLightStatusbar(lightStatusBar);
super.setTaskDescriptionColor(taskColor);
super.setNavigationbarColor(navigationbarColor);
super.setLightNavigationBar(lightNavigationBar);
playerFragment.setMenuVisibility(false);
playerFragment.setUserVisibleHint(false);
playerFragment.onHide();
}
public void onPanelExpanded(View panel) {
// setting fragments values
int playerFragmentColor = playerFragment.getPaletteColor();
super.setTaskDescriptionColor(playerFragmentColor);
if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
super.setNavigationbarColor(playerFragmentColor);
} else {
super.setNavigationbarColor(ThemeStore.primaryColor(this));
}
setLightStatusBar();
playerFragment.setMenuVisibility(true);
playerFragment.setUserVisibleHint(true);
playerFragment.onShow();
}
private void setLightStatusBar() {
super.setLightStatusbar(!PreferenceUtil.getInstance(this).getAdaptiveColor() &&
ColorUtil.isColorLight(ThemeStore.primaryColor(this)) && (
currentNowPlayingScreen == NowPlayingScreen.FLAT
|| currentNowPlayingScreen == NowPlayingScreen.PLAIN
|| currentNowPlayingScreen == NowPlayingScreen.SIMPLE
|| currentNowPlayingScreen == NowPlayingScreen.NORMAL
|| currentNowPlayingScreen == NowPlayingScreen.ADAPTIVE)
|| currentNowPlayingScreen == NowPlayingScreen.TINY);
}
@Override
public void setLightStatusbar(boolean enabled) {
lightStatusBar = enabled;
if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setLightStatusbar(enabled);
}
}
@Override
public void setLightNavigationBar(boolean enabled) {
lightNavigationBar = enabled;
/*if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) { /*if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setLightNavigationBar(enabled); super.setLightNavigationBar(enabled);
}*/ }*/
}
@Override
public void setTaskDescriptionColor(@ColorInt int color) {
taskColor = color;
if (getPanelState() == null || getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setTaskDescriptionColor(color);
} }
}
@Override @Override
public void setTaskDescriptionColor(@ColorInt int color) { public void setNavigationbarColor(int color) {
taskColor = color; navigationbarColor = color;
if (getPanelState() == null || getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) { if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setTaskDescriptionColor(color); if (navigationBarColorAnimator != null) {
} navigationBarColorAnimator.cancel();
}
super.setNavigationbarColor(color);
} }
}
@Override @Override
public void setNavigationbarColor(int color) { public void onPaletteColorChanged() {
navigationbarColor = color; int playerFragmentColor = playerFragment.getPaletteColor();
if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
if (navigationBarColorAnimator != null) { if (getPanelState() == PanelState.EXPANDED) {
navigationBarColorAnimator.cancel(); super.setTaskDescriptionColor(playerFragmentColor);
} if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
super.setNavigationbarColor(color); super.setNavigationbarColor(playerFragmentColor);
} }
} }
}
@Override private void setMiniPlayerAlphaProgress(@FloatRange(from = 0, to = 1) float progress) {
public void onPaletteColorChanged() { if (miniPlayerFragment == null) {
int playerFragmentColor = playerFragment.getPaletteColor(); return;
if (getPanelState() == PanelState.EXPANDED) {
super.setTaskDescriptionColor(playerFragmentColor);
if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
super.setNavigationbarColor(playerFragmentColor);
}
}
} }
float alpha = 1 - progress;
miniPlayerFragment.getView().setAlpha(alpha);
// necessary to make the views below clickable
miniPlayerFragment.getView().setVisibility(alpha == 0 ? View.GONE : View.VISIBLE);
private void setMiniPlayerAlphaProgress(@FloatRange(from = 0, to = 1) float progress) { }
if (miniPlayerFragment == null) {
return;
}
float alpha = 1 - progress;
miniPlayerFragment.getView().setAlpha(alpha);
// necessary to make the views below clickable
miniPlayerFragment.getView().setVisibility(alpha == 0 ? View.GONE : View.VISIBLE);
public void hideBottomBar(final boolean hide) {
int heightOfBar =
getResources().getDimensionPixelSize(R.dimen.mini_player_height);
int heightOfBarWithTabs =
getResources().getDimensionPixelSize(R.dimen.mini_player_height_expanded);
if (hide) {
slidingUpPanelLayout.setPanelHeight(0);
collapsePanel();
} else {
if (!MusicPlayerRemote.getPlayingQueue().isEmpty()) {
slidingUpPanelLayout.setPanelHeight(bottomNavigationView.getVisibility() == View.VISIBLE ?
heightOfBarWithTabs : heightOfBar);
}
} }
}
public void hideBottomBar(final boolean hide) { public void setBottomBarVisibility(int gone) {
if (bottomNavigationView != null) {
int heightOfBar = //TransitionManager.beginDelayedTransition(bottomNavigationView);
getResources().getDimensionPixelSize(R.dimen.mini_player_height); bottomNavigationView.setVisibility(gone);
int heightOfBarWithTabs = hideBottomBar(false);
getResources().getDimensionPixelSize(R.dimen.mini_player_height_expanded);
if (hide) {
slidingUpPanelLayout.setPanelHeight(0);
collapsePanel();
} else {
if (!MusicPlayerRemote.getPlayingQueue().isEmpty()) {
slidingUpPanelLayout.setPanelHeight(bottomNavigationView.getVisibility() == View.VISIBLE ?
heightOfBarWithTabs : heightOfBar);
}
}
} }
}
public void setBottomBarVisibility(int gone) { protected View wrapSlidingMusicPanel(@LayoutRes int resId) {
if (bottomNavigationView != null) { @SuppressLint("InflateParams")
//TransitionManager.beginDelayedTransition(bottomNavigationView); View slidingMusicPanelLayout = getLayoutInflater()
bottomNavigationView.setVisibility(gone); .inflate(R.layout.sliding_music_panel_layout, null);
hideBottomBar(false); ViewGroup contentContainer = slidingMusicPanelLayout.findViewById(R.id.content_container);
} getLayoutInflater().inflate(resId, contentContainer);
return slidingMusicPanelLayout;
}
@Override
public void onBackPressed() {
if (!handleBackPress()) {
super.onBackPressed();
} }
}
protected View wrapSlidingMusicPanel(@LayoutRes int resId) { public boolean handleBackPress() {
@SuppressLint("InflateParams") if (slidingUpPanelLayout.getPanelHeight() != 0 && playerFragment.onBackPressed()) {
View slidingMusicPanelLayout = getLayoutInflater() return true;
.inflate(R.layout.sliding_music_panel_layout, null);
ViewGroup contentContainer = slidingMusicPanelLayout.findViewById(R.id.content_container);
getLayoutInflater().inflate(resId, contentContainer);
return slidingMusicPanelLayout;
} }
if (getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
@Override collapsePanel();
public void onBackPressed() { return true;
if (!handleBackPress()) {
super.onBackPressed();
}
} }
return false;
}
public boolean handleBackPress() { private void animateNavigationBarColor(int color) {
if (slidingUpPanelLayout.getPanelHeight() != 0 && playerFragment.onBackPressed()) { if (navigationBarColorAnimator != null) {
return true; navigationBarColorAnimator.cancel();
}
if (getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
collapsePanel();
return true;
}
return false;
} }
navigationBarColorAnimator = ValueAnimator.ofArgb(getWindow().getNavigationBarColor(), color)
.setDuration(ViewUtil.RETRO_MUSIC_ANIM_TIME);
navigationBarColorAnimator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
navigationBarColorAnimator.addUpdateListener(animation -> {
int playerFragmentColorDark = ColorUtil.darkenColor((Integer) animation.getAnimatedValue());
private void animateNavigationBarColor(int color) { bottomNavigationView.setBackgroundColor(playerFragmentColorDark);
if (navigationBarColorAnimator != null) { miniPlayerFragment.setColor(playerFragmentColorDark);
navigationBarColorAnimator.cancel(); AbsSlidingMusicPanelActivity.super.setNavigationbarColor(playerFragmentColorDark);
}
navigationBarColorAnimator = ValueAnimator.ofArgb(getWindow().getNavigationBarColor(), color)
.setDuration(ViewUtil.RETRO_MUSIC_ANIM_TIME);
navigationBarColorAnimator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
navigationBarColorAnimator.addUpdateListener(animation -> {
int playerFragmentColorDark = ColorUtil.darkenColor((Integer) animation.getAnimatedValue());
bottomNavigationView.setBackgroundColor(playerFragmentColorDark); View view = getWindow().getDecorView().getRootView();
miniPlayerFragment.setColor(playerFragmentColorDark); view.setBackgroundColor(playerFragmentColorDark);
AbsSlidingMusicPanelActivity.super.setNavigationbarColor(playerFragmentColorDark);
View view = getWindow().getDecorView().getRootView(); if (view.findViewById(R.id.toolbar) != null) {
view.setBackgroundColor(playerFragmentColorDark); view.findViewById(R.id.toolbar).setBackgroundColor(playerFragmentColorDark);
}
if (view.findViewById(R.id.appbar) != null) {
view.findViewById(R.id.appbar).setBackgroundColor(playerFragmentColorDark);
}
if (view.findViewById(R.id.status_bar) != null) {
view.findViewById(R.id.status_bar)
.setBackgroundColor(ColorUtil.darkenColor(playerFragmentColorDark));
}
});
navigationBarColorAnimator.start();
}
if (view.findViewById(R.id.toolbar) != null) { @Override
view.findViewById(R.id.toolbar).setBackgroundColor(playerFragmentColorDark); protected View getSnackBarContainer() {
} return findViewById(R.id.content_container);
if (view.findViewById(R.id.appbar) != null) { }
view.findViewById(R.id.appbar).setBackgroundColor(playerFragmentColorDark);
}
if (view.findViewById(R.id.status_bar) != null) {
view.findViewById(R.id.status_bar)
.setBackgroundColor(ColorUtil.darkenColor(playerFragmentColorDark));
}
});
navigationBarColorAnimator.start();
}
@Override public SlidingUpPanelLayout getSlidingUpPanelLayout() {
protected View getSnackBarContainer() { return slidingUpPanelLayout;
return findViewById(R.id.content_container); }
}
public SlidingUpPanelLayout getSlidingUpPanelLayout() { public MiniPlayerFragment getMiniPlayerFragment() {
return slidingUpPanelLayout; return miniPlayerFragment;
} }
public MiniPlayerFragment getMiniPlayerFragment() { public AbsPlayerFragment getPlayerFragment() {
return miniPlayerFragment; return playerFragment;
} }
public AbsPlayerFragment getPlayerFragment() { public BottomNavigationViewEx getBottomNavigationView() {
return playerFragment; return bottomNavigationView;
} }
public BottomNavigationViewEx getBottomNavigationView() { public SlidingUpPanelLayout.PanelState getPanelState() {
return bottomNavigationView; return slidingUpPanelLayout == null ? null : slidingUpPanelLayout.getPanelState();
} }
public SlidingUpPanelLayout.PanelState getPanelState() { public void collapsePanel() {
return slidingUpPanelLayout == null ? null : slidingUpPanelLayout.getPanelState(); slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
} }
public void collapsePanel() { public void expandPanel() {
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
} }
public void expandPanel() {
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}
} }

View file

@ -16,13 +16,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.Unbinder; import butterknife.Unbinder;
@ -37,279 +30,288 @@ import code.name.monkey.retromusic.ui.adapter.song.PlayingQueueAdapter;
import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment; import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment;
import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment; import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment;
import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment; import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment;
import com.bumptech.glide.Glide;
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
/** /**
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
*/ */
public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbumCoverFragment.Callbacks { public class BlurPlayerFragment extends AbsPlayerFragment implements
@BindView(R.id.player_toolbar) PlayerAlbumCoverFragment.Callbacks {
Toolbar toolbar;
@BindView(R.id.toolbar_container)
View toolbarContainer;
@BindView(R.id.gradient_background)
ImageView colorBackground;
@BindView(R.id.status_bar)
View statusBar;
@Nullable
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@Nullable
@BindView(R.id.title)
TextView title;
private int lastColor; @BindView(R.id.player_toolbar)
private BlurPlaybackControlsFragment playbackControlsFragment; Toolbar toolbar;
private Unbinder unbinder; @BindView(R.id.toolbar_container)
View toolbarContainer;
@BindView(R.id.gradient_background)
ImageView colorBackground;
@BindView(R.id.status_bar)
View statusBar;
@Nullable
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@Nullable
@BindView(R.id.title)
TextView title;
private RecyclerView.Adapter wrappedAdapter; private int lastColor;
private RecyclerViewDragDropManager recyclerViewDragDropManager; private BlurPlaybackControlsFragment playbackControlsFragment;
private PlayingQueueAdapter playingQueueAdapter; private Unbinder unbinder;
private LinearLayoutManager layoutManager;
public static PlayerFragment newInstance() { private RecyclerView.Adapter wrappedAdapter;
Bundle args = new Bundle(); private RecyclerViewDragDropManager recyclerViewDragDropManager;
PlayerFragment fragment = new PlayerFragment(); private PlayingQueueAdapter playingQueueAdapter;
fragment.setArguments(args); private LinearLayoutManager layoutManager;
return fragment;
public static PlayerFragment newInstance() {
Bundle args = new Bundle();
PlayerFragment fragment = new PlayerFragment();
fragment.setArguments(args);
return fragment;
}
@Override
@ColorInt
public int getPaletteColor() {
return lastColor;
}
@Override
public void onShow() {
playbackControlsFragment.show();
}
@Override
public void onHide() {
playbackControlsFragment.hide();
onBackPressed();
}
@Override
public boolean onBackPressed() {
return false;
}
@Override
public Toolbar getToolbar() {
return toolbar;
}
@Override
public int toolbarIconColor() {
return Color.WHITE;
}
@Override
public void onColorChanged(int color) {
playbackControlsFragment.setDark(color);
lastColor = color;
getCallbacks().onPaletteColorChanged();
ToolbarContentTintHelper.colorizeToolbar(toolbar, Color.WHITE, getActivity());
if (title != null && playingQueueAdapter != null) {
if (ColorUtil.isColorLight(color)) {
title.setTextColor(Color.BLACK);
playingQueueAdapter.usePalette(false);
} else {
title.setTextColor(Color.WHITE);
playingQueueAdapter.usePalette(true);
}
}
}
@Override
protected void toggleFavorite(Song song) {
super.toggleFavorite(song);
if (song.id == MusicPlayerRemote.getCurrentSong().id) {
updateIsFavorite();
}
}
@Override
public void onFavoriteToggled() {
toggleFavorite(MusicPlayerRemote.getCurrentSong());
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (recyclerViewDragDropManager != null) {
recyclerViewDragDropManager.release();
recyclerViewDragDropManager = null;
} }
@Override if (recyclerView != null) {
@ColorInt recyclerView.setItemAnimator(null);
public int getPaletteColor() { recyclerView.setAdapter(null);
return lastColor; recyclerView = null;
} }
@Override if (wrappedAdapter != null) {
public void onShow() { WrapperAdapterUtils.releaseAll(wrappedAdapter);
playbackControlsFragment.show(); wrappedAdapter = null;
}
playingQueueAdapter = null;
layoutManager = null;
super.onDestroyView();
unbinder.unbind();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_blur, container, false);
unbinder = ButterKnife.bind(this, view);
return view;
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toggleStatusBar(statusBar);
setUpSubFragments();
setUpPlayerToolbar();
}
private void setUpSubFragments() {
playbackControlsFragment = (BlurPlaybackControlsFragment) getChildFragmentManager()
.findFragmentById(R.id.playback_controls_fragment);
PlayerAlbumCoverFragment playerAlbumCoverFragment =
(PlayerAlbumCoverFragment) getChildFragmentManager()
.findFragmentById(R.id.player_album_cover_fragment);
playerAlbumCoverFragment.setCallbacks(this);
}
private void setUpPlayerToolbar() {
toolbar.inflateMenu(R.menu.menu_player);
//noinspection ConstantConditions
toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
toolbar.setOnMenuItemClickListener(this);
ToolbarContentTintHelper.colorizeToolbar(toolbar, Color.WHITE, getActivity());
}
private void updateBlur() {
Activity activity = getActivity();
if (activity == null) {
return;
} }
@Override int blurAmount = PreferenceManager.getDefaultSharedPreferences(getContext())
public void onHide() { .getInt("blur_amount", 25);
playbackControlsFragment.hide();
onBackPressed();
}
@Override colorBackground.clearColorFilter();
public boolean onBackPressed() {
return false;
}
@Override SongGlideRequest.Builder.from(Glide.with(activity), MusicPlayerRemote.getCurrentSong())
public Toolbar getToolbar() { .checkIgnoreMediaStore(activity)
return toolbar; .generatePalette(activity)
} .build()
.override(320, 480)
@Override .transform(new BlurTransformation(getActivity(), blurAmount))
public int toolbarIconColor() { .into(new RetroMusicColoredTarget(colorBackground) {
return Color.WHITE; @Override
} public void onColorReady(int color) {
if (color == getDefaultFooterColor()) {
@Override colorBackground.setColorFilter(color);
public void onColorChanged(int color) {
playbackControlsFragment.setDark(color);
lastColor = color;
getCallbacks().onPaletteColorChanged();
ToolbarContentTintHelper.colorizeToolbar(toolbar, Color.WHITE, getActivity());
if (title != null && playingQueueAdapter != null) {
if (ColorUtil.isColorLight(color)) {
title.setTextColor(Color.BLACK);
playingQueueAdapter.usePalette(false);
} else {
title.setTextColor(Color.WHITE);
playingQueueAdapter.usePalette(true);
} }
} }
});
}
@Override
public void onServiceConnected() {
updateIsFavorite();
updateBlur();
setUpRecyclerView();
}
@Override
public void onPlayingMetaChanged() {
updateIsFavorite();
updateBlur();
updateQueuePosition();
}
private void setUpRecyclerView() {
if (recyclerView != null) {
recyclerViewDragDropManager = new RecyclerViewDragDropManager();
final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();
playingQueueAdapter = new PlayingQueueAdapter(
(AppCompatActivity) getActivity(),
MusicPlayerRemote.getPlayingQueue(),
MusicPlayerRemote.getPosition(),
R.layout.item_song,
false,
null);
wrappedAdapter = recyclerViewDragDropManager.createWrappedAdapter(playingQueueAdapter);
layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(wrappedAdapter);
recyclerView.setItemAnimator(animator);
recyclerViewDragDropManager.attachRecyclerView(recyclerView);
layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
}
}
@Override
public void onQueueChanged() {
updateQueue();
updateCurrentSong();
}
@Override
public void onMediaStoreChanged() {
updateQueue();
updateCurrentSong();
}
@SuppressWarnings("ConstantConditions")
private void updateCurrentSong() {
}
private void updateQueuePosition() {
if (playingQueueAdapter != null) {
playingQueueAdapter.setCurrent(MusicPlayerRemote.getPosition());
// if (slidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
resetToCurrentPosition();
//}
}
}
private void updateQueue() {
if (playingQueueAdapter != null) {
playingQueueAdapter
.swapDataSet(MusicPlayerRemote.getPlayingQueue(), MusicPlayerRemote.getPosition());
resetToCurrentPosition();
}
}
private void resetToCurrentPosition() {
if (recyclerView != null) {
recyclerView.stopScroll();
layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
} }
@Override }
protected void toggleFavorite(Song song) {
super.toggleFavorite(song); @Override
if (song.id == MusicPlayerRemote.getCurrentSong().id) { public void onPause() {
updateIsFavorite(); if (recyclerViewDragDropManager != null) {
} recyclerViewDragDropManager.cancelDrag();
}
@Override
public void onFavoriteToggled() {
toggleFavorite(MusicPlayerRemote.getCurrentSong());
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (recyclerViewDragDropManager != null) {
recyclerViewDragDropManager.release();
recyclerViewDragDropManager = null;
}
if (recyclerView != null) {
recyclerView.setItemAnimator(null);
recyclerView.setAdapter(null);
recyclerView = null;
}
if (wrappedAdapter != null) {
WrapperAdapterUtils.releaseAll(wrappedAdapter);
wrappedAdapter = null;
}
playingQueueAdapter = null;
layoutManager = null;
super.onDestroyView();
unbinder.unbind();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_blur, container, false);
unbinder = ButterKnife.bind(this, view);
return view;
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toggleStatusBar(statusBar);
setUpSubFragments();
setUpPlayerToolbar();
}
private void setUpSubFragments() {
playbackControlsFragment = (BlurPlaybackControlsFragment) getChildFragmentManager()
.findFragmentById(R.id.playback_controls_fragment);
PlayerAlbumCoverFragment playerAlbumCoverFragment =
(PlayerAlbumCoverFragment) getChildFragmentManager()
.findFragmentById(R.id.player_album_cover_fragment);
playerAlbumCoverFragment.setCallbacks(this);
}
private void setUpPlayerToolbar() {
toolbar.inflateMenu(R.menu.menu_player);
toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
toolbar.setOnMenuItemClickListener(this);
ToolbarContentTintHelper.colorizeToolbar(toolbar, Color.WHITE, getActivity());
}
private void updateBlur() {
Activity activity = getActivity();
if (activity == null) {
return;
}
int blurAmount = PreferenceManager.getDefaultSharedPreferences(getContext()).getInt("blur_amount", 25);
colorBackground.clearColorFilter();
SongGlideRequest.Builder.from(Glide.with(activity), MusicPlayerRemote.getCurrentSong())
.checkIgnoreMediaStore(activity)
.generatePalette(activity)
.build()
.override(320, 480)
.transform(new BlurTransformation(getActivity(), blurAmount))
.into(new RetroMusicColoredTarget(colorBackground) {
@Override
public void onColorReady(int color) {
if (color == getDefaultFooterColor()) {
colorBackground.setColorFilter(color);
}
}
});
}
@Override
public void onServiceConnected() {
updateIsFavorite();
updateBlur();
setUpRecyclerView();
}
@Override
public void onPlayingMetaChanged() {
updateIsFavorite();
updateBlur();
updateQueuePosition();
}
private void setUpRecyclerView() {
if (recyclerView != null) {
recyclerViewDragDropManager = new RecyclerViewDragDropManager();
final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();
playingQueueAdapter = new PlayingQueueAdapter(
(AppCompatActivity) getActivity(),
MusicPlayerRemote.getPlayingQueue(),
MusicPlayerRemote.getPosition(),
R.layout.item_song,
false,
null);
wrappedAdapter = recyclerViewDragDropManager.createWrappedAdapter(playingQueueAdapter);
layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(wrappedAdapter);
recyclerView.setItemAnimator(animator);
recyclerViewDragDropManager.attachRecyclerView(recyclerView);
layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
}
}
@Override
public void onQueueChanged() {
updateQueue();
updateCurrentSong();
}
@Override
public void onMediaStoreChanged() {
updateQueue();
updateCurrentSong();
}
@SuppressWarnings("ConstantConditions")
private void updateCurrentSong() {
}
private void updateQueuePosition() {
if (playingQueueAdapter != null) {
playingQueueAdapter.setCurrent(MusicPlayerRemote.getPosition());
// if (slidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
resetToCurrentPosition();
//}
}
}
private void updateQueue() {
if (playingQueueAdapter != null) {
playingQueueAdapter.swapDataSet(MusicPlayerRemote.getPlayingQueue(), MusicPlayerRemote.getPosition());
resetToCurrentPosition();
}
}
private void resetToCurrentPosition() {
if (recyclerView != null) {
recyclerView.stopScroll();
layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
}
}
@Override
public void onPause() {
if (recyclerViewDragDropManager != null) {
recyclerViewDragDropManager.cancelDrag();
}
super.onPause();
} }
super.onPause();
}
} }

View file

@ -1,5 +1,7 @@
package code.name.monkey.retromusic.util; package code.name.monkey.retromusic.util;
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
@ -10,7 +12,6 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat; import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.widget.Toast; import android.widget.Toast;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.MusicPlayerRemote;
import code.name.monkey.retromusic.model.Genre; import code.name.monkey.retromusic.model.Genre;
@ -22,7 +23,6 @@ import code.name.monkey.retromusic.ui.activities.EqualizerActivity;
import code.name.monkey.retromusic.ui.activities.GenreDetailsActivity; import code.name.monkey.retromusic.ui.activities.GenreDetailsActivity;
import code.name.monkey.retromusic.ui.activities.LicenseActivity; import code.name.monkey.retromusic.ui.activities.LicenseActivity;
import code.name.monkey.retromusic.ui.activities.LyricsActivity; import code.name.monkey.retromusic.ui.activities.LyricsActivity;
import code.name.monkey.retromusic.ui.activities.MainActivity;
import code.name.monkey.retromusic.ui.activities.PlayingQueueActivity; import code.name.monkey.retromusic.ui.activities.PlayingQueueActivity;
import code.name.monkey.retromusic.ui.activities.PlaylistDetailActivity; import code.name.monkey.retromusic.ui.activities.PlaylistDetailActivity;
import code.name.monkey.retromusic.ui.activities.ProVersionActivity; import code.name.monkey.retromusic.ui.activities.ProVersionActivity;
@ -30,91 +30,95 @@ import code.name.monkey.retromusic.ui.activities.SearchActivity;
import code.name.monkey.retromusic.ui.activities.SettingsActivity; import code.name.monkey.retromusic.ui.activities.SettingsActivity;
import code.name.monkey.retromusic.ui.activities.UserInfoActivity; import code.name.monkey.retromusic.ui.activities.UserInfoActivity;
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
public class NavigationUtil { public class NavigationUtil {
public static void goToAlbum(@NonNull Activity activity, int i, @Nullable Pair... sharedElements) {
Intent intent = new Intent(activity, AlbumDetailsActivity.class);
intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, i);
//noinspection unchecked
ActivityCompat.startActivity(activity, intent,
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements).toBundle());
}
public static void goToArtist(@NonNull Activity activity, int i, @Nullable Pair... sharedElements) { public static void goToAlbum(@NonNull Activity activity, int i,
Intent intent = new Intent(activity, ArtistDetailActivity.class); @Nullable Pair... sharedElements) {
intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i); Intent intent = new Intent(activity, AlbumDetailsActivity.class);
//noinspection unchecked intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, i);
ActivityCompat.startActivity(activity, intent, null); //noinspection unchecked
} ActivityCompat.startActivity(activity, intent,
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements).toBundle());
}
public static void goToPlaylistNew(@NonNull Activity activity, Playlist playlist) { public static void goToArtist(@NonNull Activity activity, int i,
Intent intent = new Intent(activity, PlaylistDetailActivity.class); @Nullable Pair... sharedElements) {
intent.putExtra(PlaylistDetailActivity.EXTRA_PLAYLIST, playlist); Intent intent = new Intent(activity, ArtistDetailActivity.class);
ActivityCompat.startActivity(activity, intent, null); intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i);
} //noinspection unchecked
ActivityCompat.startActivity(activity, intent,
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements).toBundle());
}
public static void openEqualizer(@NonNull final Activity activity) { public static void goToPlaylistNew(@NonNull Activity activity, Playlist playlist) {
if (PreferenceUtil.getInstance(activity).getSelectedEqualizer().equals("system")) { Intent intent = new Intent(activity, PlaylistDetailActivity.class);
stockEqalizer(activity); intent.putExtra(PlaylistDetailActivity.EXTRA_PLAYLIST, playlist);
} else { ActivityCompat.startActivity(activity, intent, null);
ActivityCompat.startActivity(activity, new Intent(activity, EqualizerActivity.class), null); }
}
}
private static void stockEqalizer(@NonNull Activity activity) { public static void openEqualizer(@NonNull final Activity activity) {
final int sessionId = MusicPlayerRemote.getAudioSessionId(); if (PreferenceUtil.getInstance(activity).getSelectedEqualizer().equals("system")) {
if (sessionId == AudioEffect.ERROR_BAD_VALUE) { stockEqalizer(activity);
Toast.makeText(activity, activity.getResources().getString(R.string.no_audio_ID), Toast.LENGTH_LONG).show(); } else {
} else { ActivityCompat.startActivity(activity, new Intent(activity, EqualizerActivity.class), null);
try {
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
activity.startActivityForResult(effects, 0);
} catch (@NonNull final ActivityNotFoundException notFound) {
Toast.makeText(activity, activity.getResources().getString(R.string.no_equalizer), Toast.LENGTH_SHORT).show();
}
}
} }
}
public static void goToPlayingQueue(@NonNull Activity activity) { private static void stockEqalizer(@NonNull Activity activity) {
Intent intent = new Intent(activity, PlayingQueueActivity.class); final int sessionId = MusicPlayerRemote.getAudioSessionId();
ActivityCompat.startActivity(activity, intent, null); if (sessionId == AudioEffect.ERROR_BAD_VALUE) {
Toast.makeText(activity, activity.getResources().getString(R.string.no_audio_ID),
Toast.LENGTH_LONG).show();
} else {
try {
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
activity.startActivityForResult(effects, 0);
} catch (@NonNull final ActivityNotFoundException notFound) {
Toast.makeText(activity, activity.getResources().getString(R.string.no_equalizer),
Toast.LENGTH_SHORT).show();
}
} }
}
public static void goToLyrics(@NonNull Activity activity) { public static void goToPlayingQueue(@NonNull Activity activity) {
Intent intent = new Intent(activity, LyricsActivity.class); Intent intent = new Intent(activity, PlayingQueueActivity.class);
ActivityCompat.startActivity(activity, intent, null); ActivityCompat.startActivity(activity, intent, null);
} }
public static void goToGenre(@NonNull Activity activity, @NonNull Genre genre) { public static void goToLyrics(@NonNull Activity activity) {
Intent intent = new Intent(activity, GenreDetailsActivity.class); Intent intent = new Intent(activity, LyricsActivity.class);
intent.putExtra(EXTRA_GENRE_ID, genre); ActivityCompat.startActivity(activity, intent, null);
ActivityCompat.startActivity(activity, intent, null); }
}
public static void goToProVersion(@NonNull Activity activity) { public static void goToGenre(@NonNull Activity activity, @NonNull Genre genre) {
ActivityCompat.startActivity(activity, new Intent(activity, ProVersionActivity.class), null); Intent intent = new Intent(activity, GenreDetailsActivity.class);
} intent.putExtra(EXTRA_GENRE_ID, genre);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToSettings(@NonNull Activity activity) { public static void goToProVersion(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SettingsActivity.class), null); ActivityCompat.startActivity(activity, new Intent(activity, ProVersionActivity.class), null);
} }
public static void goToAbout(@NonNull Activity activity) { public static void goToSettings(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, AboutActivity.class), null); ActivityCompat.startActivity(activity, new Intent(activity, SettingsActivity.class), null);
} }
public static void goToUserInfo(@NonNull Activity activity) { public static void goToAbout(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, UserInfoActivity.class), null); ActivityCompat.startActivity(activity, new Intent(activity, AboutActivity.class), null);
} }
public static void goToOpenSource(@NonNull Activity activity) { public static void goToUserInfo(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, LicenseActivity.class), null); ActivityCompat.startActivity(activity, new Intent(activity, UserInfoActivity.class), null);
} }
public static void goToSearch(Activity activity) { public static void goToOpenSource(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SearchActivity.class), null); ActivityCompat.startActivity(activity, new Intent(activity, LicenseActivity.class), null);
} }
public static void goToSearch(Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SearchActivity.class), null);
}
} }

View file

@ -6,8 +6,8 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog; import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment; import android.support.design.widget.BottomSheetDialogFragment;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.ui.activities.base.AbsThemeActivity;
import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.PreferenceUtil;
/** /**
@ -15,16 +15,25 @@ import code.name.monkey.retromusic.util.PreferenceUtil;
*/ */
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
public class RoundedBottomSheetDialogFragment extends BottomSheetDialogFragment { public class RoundedBottomSheetDialogFragment extends BottomSheetDialogFragment {
@Override
public int getTheme() {
//noinspection ConstantConditions
return PreferenceUtil.getInstance(getContext()).getGeneralTheme() == R.style.Theme_RetroMusic_Light ? R.style.BottomSheetDialogTheme : R.style.BottomSheetDialogThemeDark;
}
@NonNull @Override
@Override public int getTheme() {
public Dialog onCreateDialog(Bundle savedInstanceState) { //noinspection ConstantConditions
//noinspection ConstantConditions return
return new BottomSheetDialog(getContext(), getTheme()); PreferenceUtil.getInstance(getContext()).getGeneralTheme() == R.style.Theme_RetroMusic_Light
? R.style.BottomSheetDialogTheme : R.style.BottomSheetDialogThemeDark;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AbsThemeActivity absThemeActivity = (AbsThemeActivity) getActivity();
if (absThemeActivity != null) {
absThemeActivity.setLightNavigationBar(true);
Dialog dialog = new BottomSheetDialog(getContext(), getTheme());
} }
//noinspection ConstantConditions
return new BottomSheetDialog(getContext(), getTheme());
}
} }