move playback keys to preference utils
This commit is contained in:
parent
f5fc92dec7
commit
ad6aa91d74
7 changed files with 47 additions and 42 deletions
|
|
@ -31,6 +31,7 @@ import okhttp3.Callback;
|
|||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.annotations.EverythingIsNonNull;
|
||||
|
||||
public class MultiPlayer implements Playback {
|
||||
public static final String TAG = MultiPlayer.class.getSimpleName();
|
||||
|
|
@ -50,23 +51,23 @@ public class MultiPlayer implements Playback {
|
|||
private ExoPlayer.EventListener eventListener = new ExoPlayer.EventListener() {
|
||||
@Override
|
||||
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
|
||||
Log.i(TAG,"onTracksChanged");
|
||||
Log.i(TAG, "onTracksChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingChanged(boolean isLoading) {
|
||||
Log.i(TAG,"onLoadingChanged: isLoading = " + isLoading);
|
||||
Log.i(TAG, "onLoadingChanged: " + isLoading);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
Log.i(TAG,"onPlayerStateChanged: playWhenReady = " + playWhenReady);
|
||||
Log.i(TAG,"onPlayerStateChanged: playbackState = " + playbackState);
|
||||
Log.i(TAG, "onPlayerStateChanged playWhenReady: " + playWhenReady);
|
||||
Log.i(TAG, "onPlayerStateChanged playbackState: " + playbackState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositionDiscontinuity(int reason) {
|
||||
Log.i(TAG,"onPositionDiscontinuity: reason = " + reason);
|
||||
Log.i(TAG, "onPositionDiscontinuity: " + reason);
|
||||
int windowIndex = exoPlayer.getCurrentWindowIndex();
|
||||
|
||||
if (windowIndex == 1) {
|
||||
|
|
@ -82,7 +83,7 @@ public class MultiPlayer implements Playback {
|
|||
|
||||
@Override
|
||||
public void onPlayerError(ExoPlaybackException error) {
|
||||
Log.i(TAG,"onPlaybackError: " + error.getMessage());
|
||||
Log.i(TAG, "onPlaybackError: " + error.getMessage());
|
||||
if (context != null) {
|
||||
Toast.makeText(context, context.getResources().getString(R.string.unplayable_file), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
|
@ -140,12 +141,14 @@ public class MultiPlayer implements Playback {
|
|||
DataSource.Factory dataSource = new DefaultHttpDataSourceFactory(Util.getUserAgent(context, this.getClass().getName()));
|
||||
httpClient.newCall(new Request.Builder().url(path).head().build()).enqueue(new Callback() {
|
||||
@Override
|
||||
@EverythingIsNonNull
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Toast.makeText(context, context.getResources().getString(R.string.unplayable_file), Toast.LENGTH_SHORT).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
@EverythingIsNonNull
|
||||
public void onResponse(Call call, Response response) {
|
||||
MediaSource source;
|
||||
if (response.header("Content-Type").equals("application/x-mpegURL")) {
|
||||
|
|
|
|||
|
|
@ -84,11 +84,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
public static final String REPEAT_MODE_CHANGED = PHONOGRAPH_PACKAGE_NAME + ".repeatmodechanged";
|
||||
public static final String SHUFFLE_MODE_CHANGED = PHONOGRAPH_PACKAGE_NAME + ".shufflemodechanged";
|
||||
|
||||
public static final String SAVED_POSITION = "POSITION";
|
||||
public static final String SAVED_POSITION_IN_TRACK = "POSITION_IN_TRACK";
|
||||
public static final String SAVED_SHUFFLE_MODE = "SHUFFLE_MODE";
|
||||
public static final String SAVED_REPEAT_MODE = "REPEAT_MODE";
|
||||
|
||||
public static final int RELEASE_WAKELOCK = 0;
|
||||
public static final int TRACK_ENDED = 1;
|
||||
public static final int TRACK_WENT_TO_NEXT = 2;
|
||||
|
|
@ -367,11 +362,11 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
}
|
||||
|
||||
private void savePosition() {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(SAVED_POSITION, getPosition()).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(PreferenceUtil.POSITION, getPosition()).apply();
|
||||
}
|
||||
|
||||
private void saveProgress() {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(SAVED_POSITION_IN_TRACK, getSongProgressMillis()).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(PreferenceUtil.PROGRESS, getSongProgressMillis()).apply();
|
||||
}
|
||||
|
||||
public void saveState() {
|
||||
|
|
@ -386,8 +381,8 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
}
|
||||
|
||||
private void restoreState() {
|
||||
shuffleMode = PreferenceManager.getDefaultSharedPreferences(this).getInt(SAVED_SHUFFLE_MODE, 0);
|
||||
repeatMode = PreferenceManager.getDefaultSharedPreferences(this).getInt(SAVED_REPEAT_MODE, 0);
|
||||
shuffleMode = PreferenceManager.getDefaultSharedPreferences(this).getInt(PreferenceUtil.SHUFFLE, 0);
|
||||
repeatMode = PreferenceManager.getDefaultSharedPreferences(this).getInt(PreferenceUtil.REPEAT, 0);
|
||||
|
||||
notifyChange(SHUFFLE_MODE_CHANGED);
|
||||
notifyChange(REPEAT_MODE_CHANGED);
|
||||
|
|
@ -401,8 +396,8 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
List<Song> restoredQueue = QueueStore.getInstance(this).getSavedPlayingQueue();
|
||||
List<Song> restoredOriginalQueue = QueueStore.getInstance(this).getSavedOriginalPlayingQueue();
|
||||
|
||||
int restoredPosition = PreferenceManager.getDefaultSharedPreferences(this).getInt(SAVED_POSITION, -1);
|
||||
int restoredPositionInTrack = PreferenceManager.getDefaultSharedPreferences(this).getInt(SAVED_POSITION_IN_TRACK, -1);
|
||||
int restoredPosition = PreferenceManager.getDefaultSharedPreferences(this).getInt(PreferenceUtil.POSITION, -1);
|
||||
int restoredPositionInTrack = PreferenceManager.getDefaultSharedPreferences(this).getInt(PreferenceUtil.PROGRESS, -1);
|
||||
|
||||
if (restoredQueue.size() > 0 && restoredQueue.size() == restoredOriginalQueue.size() && restoredPosition != -1) {
|
||||
this.originalPlayingQueue = restoredOriginalQueue;
|
||||
|
|
@ -653,7 +648,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
case REPEAT_MODE_THIS:
|
||||
this.repeatMode = repeatMode;
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||
.putInt(SAVED_REPEAT_MODE, repeatMode)
|
||||
.putInt(PreferenceUtil.REPEAT, repeatMode)
|
||||
.apply();
|
||||
prepareNext();
|
||||
notifyChange(REPEAT_MODE_CHANGED);
|
||||
|
|
@ -930,7 +925,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
|
||||
public void setShuffleMode(final int shuffleMode) {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||
.putInt(SAVED_SHUFFLE_MODE, shuffleMode)
|
||||
.putInt(PreferenceUtil.SHUFFLE, shuffleMode)
|
||||
.apply();
|
||||
|
||||
switch (shuffleMode) {
|
||||
|
|
|
|||
|
|
@ -180,10 +180,6 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
|
||||
|
||||
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
|
||||
if (Util.isLandscape(getResources())) {
|
||||
gridSizeItem.setTitle(R.string.action_grid_size_land);
|
||||
}
|
||||
|
||||
setUpGridSizeMenu(absLibraryRecyclerViewCustomGridSizeFragment, gridSizeItem.getSubMenu());
|
||||
|
||||
menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette());
|
||||
|
|
|
|||
|
|
@ -28,12 +28,15 @@ public final class PreferenceUtil {
|
|||
public static final String USER = "user";
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
public static final String CATEGORIES = "categories";
|
||||
public static final String PAGE_SIZE = "page_size";
|
||||
public static final String REMEMBER_LAST_TAB = "remember_last_tab";
|
||||
public static final String LAST_TAB = "last_tab";
|
||||
public static final String SHUFFLE = "shuffle";
|
||||
public static final String REPEAT = "repeat";
|
||||
public static final String POSITION = "position";
|
||||
public static final String PROGRESS = "progress";
|
||||
public static final String TAB = "tab";
|
||||
|
||||
public static final String NOW_PLAYING_SCREEN = "now_playing_screen";
|
||||
public static final String SLEEP_TIMER_LAST_VALUE = "sleep_timer_last_value";
|
||||
public static final String SLEEP_TIMER_ELAPSED_REALTIME = "sleep_timer_elapsed_real_time";
|
||||
public static final String SLEEP_TIMER_FINISH_SONG = "sleep_timer_finish_music";
|
||||
|
||||
public static final String ALBUM_SORT_METHOD = "album_sort_method";
|
||||
public static final String SONG_SORT_METHOD = "song_sort_method";
|
||||
|
|
@ -55,6 +58,10 @@ public final class PreferenceUtil {
|
|||
public static final String ARTIST_COLORED_FOOTERS = "artist_colored_footers";
|
||||
public static final String ALBUM_ARTIST_COLORED_FOOTERS = "album_artist_colored_footers";
|
||||
|
||||
public static final String CATEGORIES = "categories";
|
||||
public static final String PAGE_SIZE = "page_size";
|
||||
public static final String REMEMBER_LAST_TAB = "remember_last_tab";
|
||||
|
||||
public static final String GENERAL_THEME = "general_theme";
|
||||
public static final String PRIMARY_COLOR = "primary_color";
|
||||
public static final String ACCENT_COLOR = "accent_color";
|
||||
|
|
@ -63,6 +70,8 @@ public final class PreferenceUtil {
|
|||
public static final String CLASSIC_NOTIFICATION = "classic_notification";
|
||||
public static final String COLORED_NOTIFICATION = "colored_notification";
|
||||
|
||||
public static final String NOW_PLAYING_SCREEN = "now_playing_screen";
|
||||
|
||||
public static final String SHOW_ALBUM_COVER = "show_album_cover";
|
||||
public static final String BLUR_ALBUM_COVER = "blur_album_cover";
|
||||
|
||||
|
|
@ -76,10 +85,6 @@ public final class PreferenceUtil {
|
|||
public static final String CACHE_SIZE = "cache_size";
|
||||
public static final String EXTERNAL_DIRECTORY = "external_directory";
|
||||
|
||||
public static final String SLEEP_TIMER_LAST_VALUE = "sleep_timer_last_value";
|
||||
public static final String SLEEP_TIMER_ELAPSED_REALTIME = "sleep_timer_elapsed_real_time";
|
||||
public static final String SLEEP_TIMER_FINISH_SONG = "sleep_timer_finish_music";
|
||||
|
||||
private static PreferenceUtil sInstance;
|
||||
|
||||
private final SharedPreferences mPreferences;
|
||||
|
|
@ -131,12 +136,12 @@ public final class PreferenceUtil {
|
|||
}
|
||||
|
||||
public final int getLastTab() {
|
||||
return mPreferences.getInt(LAST_TAB, 0);
|
||||
return mPreferences.getInt(TAB, 0);
|
||||
}
|
||||
|
||||
public void setLastTab(final int value) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(LAST_TAB, value);
|
||||
editor.putInt(TAB, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue