Added logic to switch between now playing screens.
This commit is contained in:
parent
ea69dcde9c
commit
ea3f95d401
15 changed files with 333 additions and 18 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.kabouzeid.gramophone.ui.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.media.audiofx.AudioEffect;
|
||||
|
|
@ -9,6 +10,7 @@ import android.os.Bundle;
|
|||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
|
|
@ -23,6 +25,8 @@ import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEColorPreference;
|
|||
import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat;
|
||||
import com.kabouzeid.appthemehelper.util.ColorUtil;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.preferences.NowPlayingScreenPreference;
|
||||
import com.kabouzeid.gramophone.preferences.NowPlayingScreenPreferenceDialog;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
|
@ -86,7 +90,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends ATEPreferenceFragmentCompat {
|
||||
public static class SettingsFragment extends ATEPreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static void setSummary(@NonNull Preference preference) {
|
||||
setSummary(preference, PreferenceManager
|
||||
|
|
@ -119,11 +123,27 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
addPreferencesFromResource(R.xml.pref_audio);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DialogFragment onCreatePreferenceDialog(Preference preference) {
|
||||
if (preference instanceof NowPlayingScreenPreference) {
|
||||
return NowPlayingScreenPreferenceDialog.newInstance();
|
||||
}
|
||||
return super.onCreatePreferenceDialog(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
getListView().setPadding(0, 0, 0, 0);
|
||||
invalidateSettings();
|
||||
PreferenceUtil.getInstance(getActivity()).registerOnSharedPreferenceChangedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
PreferenceUtil.getInstance(getActivity()).unregisterOnSharedPreferenceChangedListener(this);
|
||||
}
|
||||
|
||||
private void invalidateSettings() {
|
||||
|
|
@ -223,6 +243,8 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
updateNowPlayingScreenSummary();
|
||||
}
|
||||
|
||||
private boolean hasEqualizer() {
|
||||
|
|
@ -231,5 +253,18 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
ResolveInfo ri = pm.resolveActivity(effects, 0);
|
||||
return ri != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case PreferenceUtil.NOW_PLAYING_SCREEN_ID:
|
||||
updateNowPlayingScreenSummary();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNowPlayingScreenSummary() {
|
||||
findPreference("now_playing_screen_id").setSummary(PreferenceUtil.getInstance(getActivity()).getNowPlayingScreen().titleRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.os.Bundle;
|
|||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
|
@ -18,7 +19,10 @@ import com.kabouzeid.gramophone.R;
|
|||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.ui.fragments.player.AbsPlayerFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.player.MiniPlayerFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.player.NowPlayingScreen;
|
||||
import com.kabouzeid.gramophone.ui.fragments.player.card.CardPlayerFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.player.flat.FlatPlayerFragment;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
|
||||
|
||||
|
|
@ -41,6 +45,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
private int taskColor;
|
||||
private boolean lightStatusbar;
|
||||
|
||||
private NowPlayingScreen currentNowPlayingScreen;
|
||||
private AbsPlayerFragment playerFragment;
|
||||
private MiniPlayerFragment miniPlayerFragment;
|
||||
|
||||
|
|
@ -53,7 +58,21 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
setContentView(createContentView());
|
||||
ButterKnife.bind(this);
|
||||
|
||||
playerFragment = (AbsPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.player_fragment);
|
||||
currentNowPlayingScreen = PreferenceUtil.getInstance(this).getNowPlayingScreen();
|
||||
Fragment fragment; // must implement AbsPlayerFragment
|
||||
switch (currentNowPlayingScreen) {
|
||||
case FLAT:
|
||||
fragment = new FlatPlayerFragment();
|
||||
break;
|
||||
case CARD:
|
||||
default:
|
||||
fragment = new CardPlayerFragment();
|
||||
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);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
|
|
@ -74,12 +93,20 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
onPanelExpanded(slidingUpPanelLayout);
|
||||
} else if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
onPanelCollapsed(slidingUpPanelLayout);
|
||||
} else {
|
||||
playerFragment.onHide();
|
||||
}
|
||||
}
|
||||
});
|
||||
slidingUpPanelLayout.addPanelSlideListener(this);
|
||||
}
|
||||
|
||||
playerFragment.onHide();
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (currentNowPlayingScreen != PreferenceUtil.getInstance(this).getNowPlayingScreen()) {
|
||||
postRecreate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAntiDragView(View antiDragView) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.player;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
||||
public enum NowPlayingScreen {
|
||||
CARD(R.string.card, R.drawable.np_card, 0),
|
||||
FLAT(R.string.flat, R.drawable.np_flat, 1);
|
||||
|
||||
@StringRes
|
||||
public final int titleRes;
|
||||
@DrawableRes
|
||||
public final int drawableResId;
|
||||
public final int id;
|
||||
|
||||
NowPlayingScreen(@StringRes int titleRes, @DrawableRes int drawableResId, int id) {
|
||||
this.titleRes = titleRes;
|
||||
this.drawableResId = drawableResId;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue