move playback keys to preference utils

This commit is contained in:
dkanada 2020-09-25 16:20:30 +09:00
commit ad6aa91d74
7 changed files with 47 additions and 42 deletions

View file

@ -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")) {

View file

@ -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) {

View file

@ -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());

View file

@ -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();
}

View file

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">Gelli</string>
<string name="dkanada" translatable="false">dkanada</string>
<string name="aachen_germany" translatable="false">Aachen, Germany</string>
<string name="aidan_follestad" translatable="false">Aidan Follestad</string>
<string name="maarten_corpel" translatable="false">Maarten Corpel</string>
<string name="michael_cook" translatable="false">Michael Cook</string>
@ -10,8 +13,6 @@
<string name="eugene_cheung" translatable="false">Eugene Cheung</string>
<string name="adrian" translatable="false">Adrian</string>
<string name="aachen_germany" translatable="false">Aachen, Germany</string>
<string name="google_plus" translatable="false">Google Plus</string>
<string name="github" translatable="false">GitHub</string>
<string name="twitter" translatable="false">Twitter</string>

View file

@ -5,13 +5,13 @@
<string name="confirm_logout">Are you sure you want to logout?</string>
<string name="currently_listening_to_x_by_x">Currently listening to %1$s by %2$s.</string>
<string name="the_audio_file">The audio file</string>
<string name="unplayable_file">Couldn\u2019t play this song.</string>
<string name="unplayable_file">Couldn\'t play this song.</string>
<string name="audio_focus_denied">Audio focus denied.</string>
<string name="error_share_file">There was an error sharing the file.</string>
<string name="error_version">Please update your server to the latest version.</string>
<string name="action_share">Share</string>
<string name="action_settings">"Settings"</string>
<string name="action_settings">Settings</string>
<string name="action_grant">Grant</string>
<string name="action_about">About</string>
<string name="action_login">Login</string>
@ -29,8 +29,6 @@
<string name="action_details">Details</string>
<string name="action_rename">Rename</string>
<string name="action_delete">Delete</string>
<string name="action_sort_order">Sort order</string>
<string name="action_sort_method">Sort method</string>
<string name="action_go_to_artist">Go to artist</string>
<string name="action_go_to_album">Go to album</string>
<string name="action_remove_from_playlist">Remove from playlist</string>
@ -88,6 +86,10 @@
<string name="delete_playlists_title">Delete playlists</string>
<string name="select_all_title">Select all</string>
<string name="action_sort_order">Sort order</string>
<string name="action_sort_method">Sort method</string>
<string name="colored_footers">Colored footers</string>
<string name="light_theme_name">Light</string>
<string name="dark_theme_name">Dark</string>
<string name="black_theme_name">Black</string>
@ -108,7 +110,6 @@
<string name="library_categories">Categories</string>
<string name="primary_color">Primary Color</string>
<string name="accent_color">Accent Color</string>
<string name="colored_footers">Colored footers</string>
<string name="pref_title_general_theme">Theme</string>
<string name="pref_title_now_playing_screen_appearance">Appearance</string>
<string name="pref_title_app_shortcuts">Colored Shortcuts</string>
@ -125,6 +126,7 @@
<string name="pref_title_page_size">Page Size</string>
<string name="pref_title_images_cache_size">Cache Size</string>
<string name="pref_title_images_external_directory">External Directory</string>
<string name="pref_summary_images_external_directory">Store the image cache in an external directory to keep the files between installs.</string>
<string name="primary_color_desc">The primary theme color for control elements.</string>
<string name="accent_color_desc">An alternate color used to accent elements.</string>

View file

@ -28,6 +28,7 @@
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
<style name="Theme.Phonograph.Base.Light" parent="Theme.AppCompat.Light.NoActionBar">
@ -57,6 +58,7 @@
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="Theme.Phonograph.Base.Black" parent="@style/Theme.Phonograph.Base">
@ -84,4 +86,5 @@
<style name="Widget.ActionButton.Overflow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:contentDescription">@string/abc_action_menu_overflow_description</item>
</style>
</resources>
</resources>