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;
/*
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.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
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.util.MusicUtil;
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
/**
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
*/
import java.util.ArrayList;
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
public static DeleteSongsDialog create(Song song) {
ArrayList<Song> list = new ArrayList<>();
list.add(song);
return create(list);
}
@BindView(R.id.action_delete)
TextView delete;
@BindView(R.id.title)
TextView title;
@BindView(R.id.action_cancel)
TextView cancel;
@NonNull
public static DeleteSongsDialog create(ArrayList<Song> songs) {
DeleteSongsDialog dialog = new DeleteSongsDialog();
Bundle args = new Bundle();
args.putParcelableArrayList("songs", songs);
dialog.setArguments(args);
return dialog;
}
@NonNull
public static DeleteSongsDialog create(Song song) {
ArrayList<Song> list = new ArrayList<>();
list.add(song);
return create(list);
}
@OnClick({R.id.action_cancel, R.id.action_delete})
void actions(View view) {
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
switch (view.getId()) {
case R.id.action_delete:
if (getActivity() == null)
return;
MusicUtil.deleteTracks(getActivity(), songs);
break;
default:
@NonNull
public static DeleteSongsDialog create(ArrayList<Song> songs) {
DeleteSongsDialog dialog = new DeleteSongsDialog();
Bundle args = new Bundle();
args.putParcelableArrayList("songs", songs);
dialog.setArguments(args);
return dialog;
}
@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();
}
@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));
if (songs != null) {
MusicUtil.deleteTracks(getActivity(), songs);
}
this.title.setText(title);
this.delete.setText(content);
break;
default:
}
dismiss();
}
@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;
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//noinspection unchecked,ConstantConditions
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
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.view.KeyEvent;
import android.view.View;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.retromusic.R;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public abstract class AbsBaseActivity extends AbsThemeActivity {
public static final int PERMISSION_REQUEST = 100;
private boolean hadPermissions;
private String[] permissions;
private String permissionDeniedMessage;
public static final int PERMISSION_REQUEST = 100;
private boolean hadPermissions;
private String[] permissions;
private String permissionDeniedMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
permissions = getPermissionsToRequest();
hadPermissions = hasPermissions();
permissions = getPermissionsToRequest();
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);
if (!hasPermissions()) {
requestPermissions();
}
protected void onHasPermissionsChanged(boolean hasPermissions) {
// implemented by sub classes
}
@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
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);
}
}
}
protected void onHasPermissionsChanged(boolean hasPermissions) {
// implemented by sub classes
}
@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
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);
@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);
}
}
}

View file

@ -11,10 +11,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.PathInterpolator;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
import butterknife.BindView;
import butterknife.ButterKnife;
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.ViewUtil;
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
SlidingUpPanelLayout.PanelSlideListener,
PlayerFragment.Callbacks {
SlidingUpPanelLayout.PanelSlideListener,
PlayerFragment.Callbacks {
public static final String TAG = AbsSlidingMusicPanelActivity.class.getSimpleName();
public static final String TAG = AbsSlidingMusicPanelActivity.class.getSimpleName();
@BindView(R.id.bottom_navigation)
BottomNavigationViewEx bottomNavigationView;
@BindView(R.id.sliding_layout)
SlidingUpPanelLayout slidingUpPanelLayout;
@BindView(R.id.bottom_navigation)
BottomNavigationViewEx bottomNavigationView;
@BindView(R.id.sliding_layout)
SlidingUpPanelLayout slidingUpPanelLayout;
private int navigationbarColor;
private int taskColor;
private boolean lightStatusBar;
private boolean lightNavigationBar;
private NowPlayingScreen currentNowPlayingScreen;
private AbsPlayerFragment playerFragment;
private MiniPlayerFragment miniPlayerFragment;
private ValueAnimator navigationBarColorAnimator;
private int navigationbarColor;
private int taskColor;
private boolean lightStatusBar;
private boolean lightNavigationBar;
private NowPlayingScreen currentNowPlayingScreen;
private AbsPlayerFragment playerFragment;
private MiniPlayerFragment miniPlayerFragment;
private ValueAnimator navigationBarColorAnimator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(createContentView());
ButterKnife.bind(this);
choosFragmentForTheme();
//noinspection ConstantConditions
miniPlayerFragment.getView().setOnClickListener(v -> expandPanel());
slidingUpPanelLayout.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(createContentView());
ButterKnife.bind(this);
choosFragmentForTheme();
//noinspection ConstantConditions
miniPlayerFragment.getView().setOnClickListener(v -> expandPanel());
slidingUpPanelLayout.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (getPanelState() == PanelState.EXPANDED) {
onPanelSlide(slidingUpPanelLayout, 1);
onPanelExpanded(slidingUpPanelLayout);
} else if (getPanelState() == PanelState.COLLAPSED) {
onPanelCollapsed(slidingUpPanelLayout);
} else {
playerFragment.onHide();
}
}
});
if (getPanelState() == PanelState.EXPANDED) {
onPanelSlide(slidingUpPanelLayout, 1);
onPanelExpanded(slidingUpPanelLayout);
} else if (getPanelState() == PanelState.COLLAPSED) {
onPanelCollapsed(slidingUpPanelLayout);
} else {
playerFragment.onHide();
}
}
});
setupBottomView();
slidingUpPanelLayout.addPanelSlideListener(this);
setupBottomView();
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() {
currentNowPlayingScreen = PreferenceUtil.getInstance(this).getNowPlayingScreen();
setLightStatusBar();
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;
playerFragment.setMenuVisibility(true);
playerFragment.setUserVisibleHint(true);
playerFragment.onShow();
}
case NORMAL:
default:
fragment = new PlayerFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.player_fragment_container, fragment)
.commit();
getSupportFragmentManager().executePendingTransactions();
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
|| currentNowPlayingScreen == NowPlayingScreen.MATERIAL));
}
playerFragment = (AbsPlayerFragment) getSupportFragmentManager()
.findFragmentById(R.id.player_fragment_container);
miniPlayerFragment = (MiniPlayerFragment) getSupportFragmentManager()
.findFragmentById(R.id.mini_player_fragment);
@Override
public void setLightStatusbar(boolean enabled) {
lightStatusBar = enabled;
if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setLightStatusbar(enabled);
}
}
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));
}
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;
@Override
public void setLightNavigationBar(boolean enabled) {
lightNavigationBar = enabled;
/*if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setLightNavigationBar(enabled);
}*/
}
@Override
public void setTaskDescriptionColor(@ColorInt int color) {
taskColor = color;
if (getPanelState() == null || getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setTaskDescriptionColor(color);
}
}
@Override
public void setTaskDescriptionColor(@ColorInt int color) {
taskColor = color;
if (getPanelState() == null || getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
super.setTaskDescriptionColor(color);
}
@Override
public void setNavigationbarColor(int color) {
navigationbarColor = color;
if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
if (navigationBarColorAnimator != null) {
navigationBarColorAnimator.cancel();
}
super.setNavigationbarColor(color);
}
}
@Override
public void setNavigationbarColor(int color) {
navigationbarColor = color;
if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
if (navigationBarColorAnimator != null) {
navigationBarColorAnimator.cancel();
}
super.setNavigationbarColor(color);
}
@Override
public void onPaletteColorChanged() {
int playerFragmentColor = playerFragment.getPaletteColor();
if (getPanelState() == PanelState.EXPANDED) {
super.setTaskDescriptionColor(playerFragmentColor);
if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
super.setNavigationbarColor(playerFragmentColor);
}
}
}
@Override
public void onPaletteColorChanged() {
int playerFragmentColor = playerFragment.getPaletteColor();
if (getPanelState() == PanelState.EXPANDED) {
super.setTaskDescriptionColor(playerFragmentColor);
if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
super.setNavigationbarColor(playerFragmentColor);
}
}
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);
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) {
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 setBottomBarVisibility(int gone) {
if (bottomNavigationView != null) {
//TransitionManager.beginDelayedTransition(bottomNavigationView);
bottomNavigationView.setVisibility(gone);
hideBottomBar(false);
}
}
public void setBottomBarVisibility(int gone) {
if (bottomNavigationView != null) {
//TransitionManager.beginDelayedTransition(bottomNavigationView);
bottomNavigationView.setVisibility(gone);
hideBottomBar(false);
}
protected View wrapSlidingMusicPanel(@LayoutRes int resId) {
@SuppressLint("InflateParams")
View slidingMusicPanelLayout = getLayoutInflater()
.inflate(R.layout.sliding_music_panel_layout, null);
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) {
@SuppressLint("InflateParams")
View slidingMusicPanelLayout = getLayoutInflater()
.inflate(R.layout.sliding_music_panel_layout, null);
ViewGroup contentContainer = slidingMusicPanelLayout.findViewById(R.id.content_container);
getLayoutInflater().inflate(resId, contentContainer);
return slidingMusicPanelLayout;
public boolean handleBackPress() {
if (slidingUpPanelLayout.getPanelHeight() != 0 && playerFragment.onBackPressed()) {
return true;
}
@Override
public void onBackPressed() {
if (!handleBackPress()) {
super.onBackPressed();
}
if (getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
collapsePanel();
return true;
}
return false;
}
public boolean handleBackPress() {
if (slidingUpPanelLayout.getPanelHeight() != 0 && playerFragment.onBackPressed()) {
return true;
}
if (getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
collapsePanel();
return true;
}
return false;
private void animateNavigationBarColor(int color) {
if (navigationBarColorAnimator != null) {
navigationBarColorAnimator.cancel();
}
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) {
if (navigationBarColorAnimator != null) {
navigationBarColorAnimator.cancel();
}
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);
miniPlayerFragment.setColor(playerFragmentColorDark);
AbsSlidingMusicPanelActivity.super.setNavigationbarColor(playerFragmentColorDark);
bottomNavigationView.setBackgroundColor(playerFragmentColorDark);
miniPlayerFragment.setColor(playerFragmentColorDark);
AbsSlidingMusicPanelActivity.super.setNavigationbarColor(playerFragmentColorDark);
View view = getWindow().getDecorView().getRootView();
view.setBackgroundColor(playerFragmentColorDark);
View view = getWindow().getDecorView().getRootView();
view.setBackgroundColor(playerFragmentColorDark);
if (view.findViewById(R.id.toolbar) != null) {
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) {
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();
}
@Override
protected View getSnackBarContainer() {
return findViewById(R.id.content_container);
}
@Override
protected View getSnackBarContainer() {
return findViewById(R.id.content_container);
}
public SlidingUpPanelLayout getSlidingUpPanelLayout() {
return slidingUpPanelLayout;
}
public SlidingUpPanelLayout getSlidingUpPanelLayout() {
return slidingUpPanelLayout;
}
public MiniPlayerFragment getMiniPlayerFragment() {
return miniPlayerFragment;
}
public MiniPlayerFragment getMiniPlayerFragment() {
return miniPlayerFragment;
}
public AbsPlayerFragment getPlayerFragment() {
return playerFragment;
}
public AbsPlayerFragment getPlayerFragment() {
return playerFragment;
}
public BottomNavigationViewEx getBottomNavigationView() {
return bottomNavigationView;
}
public BottomNavigationViewEx getBottomNavigationView() {
return bottomNavigationView;
}
public SlidingUpPanelLayout.PanelState getPanelState() {
return slidingUpPanelLayout == null ? null : slidingUpPanelLayout.getPanelState();
}
public SlidingUpPanelLayout.PanelState getPanelState() {
return slidingUpPanelLayout == null ? null : slidingUpPanelLayout.getPanelState();
}
public void collapsePanel() {
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
}
public void collapsePanel() {
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
}
public void expandPanel() {
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.widget.ImageView;
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.ButterKnife;
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.player.PlayerAlbumCoverFragment;
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;
/**
* @author Hemanth S (h4h13).
*/
public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbumCoverFragment.Callbacks {
@BindView(R.id.player_toolbar)
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;
public class BlurPlayerFragment extends AbsPlayerFragment implements
PlayerAlbumCoverFragment.Callbacks {
private int lastColor;
private BlurPlaybackControlsFragment playbackControlsFragment;
private Unbinder unbinder;
@BindView(R.id.player_toolbar)
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 RecyclerView.Adapter wrappedAdapter;
private RecyclerViewDragDropManager recyclerViewDragDropManager;
private PlayingQueueAdapter playingQueueAdapter;
private LinearLayoutManager layoutManager;
private int lastColor;
private BlurPlaybackControlsFragment playbackControlsFragment;
private Unbinder unbinder;
public static PlayerFragment newInstance() {
Bundle args = new Bundle();
PlayerFragment fragment = new PlayerFragment();
fragment.setArguments(args);
return fragment;
private RecyclerView.Adapter wrappedAdapter;
private RecyclerViewDragDropManager recyclerViewDragDropManager;
private PlayingQueueAdapter playingQueueAdapter;
private LinearLayoutManager layoutManager;
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
@ColorInt
public int getPaletteColor() {
return lastColor;
if (recyclerView != null) {
recyclerView.setItemAnimator(null);
recyclerView.setAdapter(null);
recyclerView = null;
}
@Override
public void onShow() {
playbackControlsFragment.show();
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);
//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
public void onHide() {
playbackControlsFragment.hide();
onBackPressed();
}
int blurAmount = PreferenceManager.getDefaultSharedPreferences(getContext())
.getInt("blur_amount", 25);
@Override
public boolean onBackPressed() {
return false;
}
colorBackground.clearColorFilter();
@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);
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
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;
}
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();
}
@Override
public void onPause() {
if (recyclerViewDragDropManager != null) {
recyclerViewDragDropManager.cancelDrag();
}
super.onPause();
}
}

View file

@ -1,5 +1,7 @@
package code.name.monkey.retromusic.util;
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
@ -10,7 +12,6 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.widget.Toast;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
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.LicenseActivity;
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.PlaylistDetailActivity;
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.UserInfoActivity;
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
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) {
Intent intent = new Intent(activity, ArtistDetailActivity.class);
intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i);
//noinspection unchecked
ActivityCompat.startActivity(activity, intent, null);
}
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 goToPlaylistNew(@NonNull Activity activity, Playlist playlist) {
Intent intent = new Intent(activity, PlaylistDetailActivity.class);
intent.putExtra(PlaylistDetailActivity.EXTRA_PLAYLIST, playlist);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToArtist(@NonNull Activity activity, int i,
@Nullable Pair... sharedElements) {
Intent intent = new Intent(activity, ArtistDetailActivity.class);
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) {
if (PreferenceUtil.getInstance(activity).getSelectedEqualizer().equals("system")) {
stockEqalizer(activity);
} else {
ActivityCompat.startActivity(activity, new Intent(activity, EqualizerActivity.class), null);
}
}
public static void goToPlaylistNew(@NonNull Activity activity, Playlist playlist) {
Intent intent = new Intent(activity, PlaylistDetailActivity.class);
intent.putExtra(PlaylistDetailActivity.EXTRA_PLAYLIST, playlist);
ActivityCompat.startActivity(activity, intent, null);
}
private static void stockEqalizer(@NonNull Activity activity) {
final int sessionId = MusicPlayerRemote.getAudioSessionId();
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 openEqualizer(@NonNull final Activity activity) {
if (PreferenceUtil.getInstance(activity).getSelectedEqualizer().equals("system")) {
stockEqalizer(activity);
} else {
ActivityCompat.startActivity(activity, new Intent(activity, EqualizerActivity.class), null);
}
}
public static void goToPlayingQueue(@NonNull Activity activity) {
Intent intent = new Intent(activity, PlayingQueueActivity.class);
ActivityCompat.startActivity(activity, intent, null);
private static void stockEqalizer(@NonNull Activity activity) {
final int sessionId = MusicPlayerRemote.getAudioSessionId();
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) {
Intent intent = new Intent(activity, LyricsActivity.class);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToPlayingQueue(@NonNull Activity activity) {
Intent intent = new Intent(activity, PlayingQueueActivity.class);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToGenre(@NonNull Activity activity, @NonNull Genre genre) {
Intent intent = new Intent(activity, GenreDetailsActivity.class);
intent.putExtra(EXTRA_GENRE_ID, genre);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToLyrics(@NonNull Activity activity) {
Intent intent = new Intent(activity, LyricsActivity.class);
ActivityCompat.startActivity(activity, intent, null);
}
public static void goToProVersion(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, ProVersionActivity.class), null);
}
public static void goToGenre(@NonNull Activity activity, @NonNull Genre genre) {
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) {
ActivityCompat.startActivity(activity, new Intent(activity, SettingsActivity.class), null);
}
public static void goToProVersion(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, ProVersionActivity.class), null);
}
public static void goToAbout(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, AboutActivity.class), null);
}
public static void goToSettings(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SettingsActivity.class), null);
}
public static void goToUserInfo(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, UserInfoActivity.class), null);
}
public static void goToAbout(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, AboutActivity.class), null);
}
public static void goToOpenSource(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, LicenseActivity.class), null);
}
public static void goToUserInfo(@NonNull Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, UserInfoActivity.class), null);
}
public static void goToSearch(Activity activity) {
ActivityCompat.startActivity(activity, new Intent(activity, SearchActivity.class), null);
}
public static void goToOpenSource(@NonNull Activity activity) {
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.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.ui.activities.base.AbsThemeActivity;
import code.name.monkey.retromusic.util.PreferenceUtil;
/**
@ -15,16 +15,25 @@ import code.name.monkey.retromusic.util.PreferenceUtil;
*/
@SuppressLint("RestrictedApi")
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
public Dialog onCreateDialog(Bundle savedInstanceState) {
//noinspection ConstantConditions
return new BottomSheetDialog(getContext(), getTheme());
@Override
public int getTheme() {
//noinspection ConstantConditions
return
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());
}
}