Replace if with switch
This commit is contained in:
parent
4fed3bd3a3
commit
bb9e3a506e
|
@ -173,15 +173,16 @@ public class EditPlayActionActivity extends SubsonicActivity {
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
cancel();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.menu_accept) {
|
||||
accept();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.menu_cancel) {
|
||||
cancel();
|
||||
return true;
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
cancel();
|
||||
return true;
|
||||
case R.id.menu_accept:
|
||||
accept();
|
||||
return true;
|
||||
case R.id.menu_cancel:
|
||||
cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -538,12 +538,13 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
|
|||
}
|
||||
|
||||
private SubsonicFragment getNewFragment(String fragmentType) {
|
||||
if ("Playlist".equals(fragmentType)) {
|
||||
return new SelectPlaylistFragment();
|
||||
} else if ("Download".equals(fragmentType)) {
|
||||
return new DownloadFragment();
|
||||
} else {
|
||||
return new SelectArtistFragment();
|
||||
switch (fragmentType) {
|
||||
case "Playlist":
|
||||
return new SelectPlaylistFragment();
|
||||
case "Download":
|
||||
return new DownloadFragment();
|
||||
default:
|
||||
return new SelectArtistFragment();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,12 +78,17 @@ public class SearchAdapter extends ExpandableSectionAdapter<Serializable> {
|
|||
@Override
|
||||
public UpdateView.UpdateViewHolder onCreateSectionViewHolder(int viewType) {
|
||||
UpdateView updateView = null;
|
||||
if (viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
|
||||
updateView = new AlbumView(context, viewType == VIEW_TYPE_ALBUM_CELL);
|
||||
} else if (viewType == VIEW_TYPE_SONG) {
|
||||
updateView = new SongView(context);
|
||||
} else if (viewType == VIEW_TYPE_ARTIST) {
|
||||
updateView = new ArtistView(context);
|
||||
switch (viewType) {
|
||||
case VIEW_TYPE_ALBUM_CELL:
|
||||
case VIEW_TYPE_ALBUM_LINE:
|
||||
updateView = new AlbumView(context, viewType == VIEW_TYPE_ALBUM_CELL);
|
||||
break;
|
||||
case VIEW_TYPE_SONG:
|
||||
updateView = new SongView(context);
|
||||
break;
|
||||
case VIEW_TYPE_ARTIST:
|
||||
updateView = new ArtistView(context);
|
||||
break;
|
||||
}
|
||||
|
||||
return new UpdateView.UpdateViewHolder(updateView);
|
||||
|
@ -92,14 +97,19 @@ public class SearchAdapter extends ExpandableSectionAdapter<Serializable> {
|
|||
@Override
|
||||
public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Serializable item, int viewType) {
|
||||
UpdateView view = holder.getUpdateView();
|
||||
if (viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
|
||||
AlbumView albumView = (AlbumView) view;
|
||||
albumView.setObject((Entry) item, imageLoader);
|
||||
} else if (viewType == VIEW_TYPE_SONG) {
|
||||
SongView songView = (SongView) view;
|
||||
songView.setObject((Entry) item, true);
|
||||
} else if (viewType == VIEW_TYPE_ARTIST) {
|
||||
view.setObject(item);
|
||||
switch (viewType) {
|
||||
case VIEW_TYPE_ALBUM_CELL:
|
||||
case VIEW_TYPE_ALBUM_LINE:
|
||||
AlbumView albumView = (AlbumView) view;
|
||||
albumView.setObject((Entry) item, imageLoader);
|
||||
break;
|
||||
case VIEW_TYPE_SONG:
|
||||
SongView songView = (SongView) view;
|
||||
songView.setObject((Entry) item, true);
|
||||
break;
|
||||
case VIEW_TYPE_ARTIST:
|
||||
view.setObject(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,53 +75,71 @@ public class MainFragment extends SelectRecyclerFragment<Integer> {
|
|||
}
|
||||
|
||||
private void showAlbumList(String type) {
|
||||
if ("genres".equals(type)) {
|
||||
SubsonicFragment fragment = new SelectGenreFragment();
|
||||
replaceFragment(fragment);
|
||||
} else if ("years".equals(type)) {
|
||||
SubsonicFragment fragment = new SelectYearFragment();
|
||||
replaceFragment(fragment);
|
||||
} else {
|
||||
// Clear out recently added count when viewing
|
||||
if ("newest".equals(type)) {
|
||||
SharedPreferences.Editor editor = Util.getPreferences(context).edit();
|
||||
editor.putInt(Constants.PREFERENCES_KEY_RECENT_COUNT + Util.getActiveServer(context), 0);
|
||||
editor.apply();
|
||||
switch (type) {
|
||||
case "genres": {
|
||||
SubsonicFragment fragment = new SelectGenreFragment();
|
||||
replaceFragment(fragment);
|
||||
break;
|
||||
}
|
||||
case "years": {
|
||||
SubsonicFragment fragment = new SelectYearFragment();
|
||||
replaceFragment(fragment);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// Clear out recently added count when viewing
|
||||
if ("newest".equals(type)) {
|
||||
SharedPreferences.Editor editor = Util.getPreferences(context).edit();
|
||||
editor.putInt(Constants.PREFERENCES_KEY_RECENT_COUNT + Util.getActiveServer(context), 0);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
SubsonicFragment fragment = new SelectDirectoryFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
|
||||
args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20);
|
||||
args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
|
||||
fragment.setArguments(args);
|
||||
SubsonicFragment fragment = new SelectDirectoryFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
|
||||
args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20);
|
||||
args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
|
||||
fragment.setArguments(args);
|
||||
|
||||
replaceFragment(fragment);
|
||||
replaceFragment(fragment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked(UpdateView<Integer> updateView, Integer item) {
|
||||
if (item == R.string.main_albums_random) {
|
||||
showAlbumList("random");
|
||||
} else if (item == R.string.main_albums_recent) {
|
||||
showAlbumList("recent");
|
||||
} else if (item == R.string.main_albums_frequent) {
|
||||
showAlbumList("frequent");
|
||||
} else if (item == R.string.main_albums_genres) {
|
||||
showAlbumList("genres");
|
||||
} else if (item == R.string.main_albums_year) {
|
||||
showAlbumList("years");
|
||||
} else if (item == R.string.main_albums_alphabetical) {
|
||||
showAlbumList("alphabeticalByName");
|
||||
} else if (item == R.string.main_songs_newest) {
|
||||
showAlbumList(SONGS_NEWEST);
|
||||
} else if (item == R.string.main_songs_top_played) {
|
||||
showAlbumList(SONGS_TOP_PLAYED);
|
||||
} else if (item == R.string.main_songs_recent) {
|
||||
showAlbumList(SONGS_RECENT);
|
||||
} else if (item == R.string.main_songs_frequent) {
|
||||
showAlbumList(SONGS_FREQUENT);
|
||||
switch (item) {
|
||||
case R.string.main_albums_random:
|
||||
showAlbumList("random");
|
||||
break;
|
||||
case R.string.main_albums_recent:
|
||||
showAlbumList("recent");
|
||||
break;
|
||||
case R.string.main_albums_frequent:
|
||||
showAlbumList("frequent");
|
||||
break;
|
||||
case R.string.main_albums_genres:
|
||||
showAlbumList("genres");
|
||||
break;
|
||||
case R.string.main_albums_year:
|
||||
showAlbumList("years");
|
||||
break;
|
||||
case R.string.main_albums_alphabetical:
|
||||
showAlbumList("alphabeticalByName");
|
||||
break;
|
||||
case R.string.main_songs_newest:
|
||||
showAlbumList(SONGS_NEWEST);
|
||||
break;
|
||||
case R.string.main_songs_top_played:
|
||||
showAlbumList(SONGS_TOP_PLAYED);
|
||||
break;
|
||||
case R.string.main_songs_recent:
|
||||
showAlbumList(SONGS_RECENT);
|
||||
break;
|
||||
case R.string.main_songs_frequent:
|
||||
showAlbumList(SONGS_FREQUENT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -315,25 +315,37 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section
|
|||
}
|
||||
|
||||
private void getAlbumList(final String albumListType, final int size, final boolean refresh) {
|
||||
if ("random".equals(albumListType)) {
|
||||
setTitle(R.string.main_albums_random);
|
||||
} else if ("recent".equals(albumListType)) {
|
||||
setTitle(R.string.main_albums_recent);
|
||||
} else if ("frequent".equals(albumListType)) {
|
||||
setTitle(R.string.main_albums_frequent);
|
||||
} else if ("genres".equals(albumListType) || "years".equals(albumListType)) {
|
||||
setTitle(albumListExtra);
|
||||
} else if ("alphabeticalByName".equals(albumListType)) {
|
||||
setTitle(R.string.main_albums_alphabetical);
|
||||
switch (albumListType) {
|
||||
case "random":
|
||||
setTitle(R.string.main_albums_random);
|
||||
break;
|
||||
case "recent":
|
||||
setTitle(R.string.main_albums_recent);
|
||||
break;
|
||||
case "frequent":
|
||||
setTitle(R.string.main_albums_frequent);
|
||||
break;
|
||||
case "genres":
|
||||
case "years":
|
||||
setTitle(albumListExtra);
|
||||
break;
|
||||
case "alphabeticalByName":
|
||||
setTitle(R.string.main_albums_alphabetical);
|
||||
break;
|
||||
}
|
||||
if (MainFragment.SONGS_NEWEST.equals(albumListType)) {
|
||||
setTitle(R.string.main_songs_newest);
|
||||
} else if (MainFragment.SONGS_TOP_PLAYED.equals(albumListType)) {
|
||||
setTitle(R.string.main_songs_top_played);
|
||||
} else if (MainFragment.SONGS_RECENT.equals(albumListType)) {
|
||||
setTitle(R.string.main_songs_recent);
|
||||
} else if (MainFragment.SONGS_FREQUENT.equals(albumListType)) {
|
||||
setTitle(R.string.main_songs_frequent);
|
||||
switch (albumListType) {
|
||||
case MainFragment.SONGS_NEWEST:
|
||||
setTitle(R.string.main_songs_newest);
|
||||
break;
|
||||
case MainFragment.SONGS_TOP_PLAYED:
|
||||
setTitle(R.string.main_songs_top_played);
|
||||
break;
|
||||
case MainFragment.SONGS_RECENT:
|
||||
setTitle(R.string.main_songs_recent);
|
||||
break;
|
||||
case MainFragment.SONGS_FREQUENT:
|
||||
setTitle(R.string.main_songs_frequent);
|
||||
break;
|
||||
}
|
||||
|
||||
new LoadTask() {
|
||||
|
|
|
@ -116,14 +116,19 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
|
|||
Bundle args = new Bundle();
|
||||
|
||||
int xml = 0;
|
||||
if ("appearance".equals(name)) {
|
||||
xml = R.xml.settings_appearance;
|
||||
} else if ("cache".equals(name)) {
|
||||
xml = R.xml.settings_cache;
|
||||
} else if ("playback".equals(name)) {
|
||||
xml = R.xml.settings_playback;
|
||||
} else if ("servers".equals(name)) {
|
||||
xml = R.xml.settings_servers;
|
||||
switch (name) {
|
||||
case "appearance":
|
||||
xml = R.xml.settings_appearance;
|
||||
break;
|
||||
case "cache":
|
||||
xml = R.xml.settings_cache;
|
||||
break;
|
||||
case "playback":
|
||||
xml = R.xml.settings_playback;
|
||||
break;
|
||||
case "servers":
|
||||
xml = R.xml.settings_servers;
|
||||
break;
|
||||
}
|
||||
|
||||
if (xml != 0) {
|
||||
|
@ -142,28 +147,37 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
|
|||
|
||||
update();
|
||||
|
||||
if (Constants.PREFERENCES_KEY_HIDE_MEDIA.equals(key)) {
|
||||
setHideMedia(sharedPreferences.getBoolean(key, true));
|
||||
} else if (Constants.PREFERENCES_KEY_MEDIA_BUTTONS.equals(key)) {
|
||||
setMediaButtonsEnabled(sharedPreferences.getBoolean(key, true));
|
||||
} else if (Constants.PREFERENCES_KEY_CACHE_LOCATION.equals(key)) {
|
||||
setCacheLocation(sharedPreferences.getString(key, ""));
|
||||
} else if (Constants.PREFERENCES_KEY_SYNC_MOST_RECENT.equals(key)) {
|
||||
SyncUtil.removeMostRecentSyncFiles(context);
|
||||
} else if (Constants.PREFERENCES_KEY_REPLAY_GAIN.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED.equals(key)) {
|
||||
DownloadService downloadService = DownloadService.getInstance();
|
||||
if (downloadService != null) {
|
||||
downloadService.reapplyVolume();
|
||||
}
|
||||
} else if (Constants.PREFERENCES_KEY_START_ON_HEADPHONES.equals(key)) {
|
||||
Intent serviceIntent = new Intent();
|
||||
serviceIntent.setClassName(context.getPackageName(), HeadphoneListenerService.class.getName());
|
||||
switch (key) {
|
||||
case Constants.PREFERENCES_KEY_HIDE_MEDIA:
|
||||
setHideMedia(sharedPreferences.getBoolean(key, true));
|
||||
break;
|
||||
case Constants.PREFERENCES_KEY_MEDIA_BUTTONS:
|
||||
setMediaButtonsEnabled(sharedPreferences.getBoolean(key, true));
|
||||
break;
|
||||
case Constants.PREFERENCES_KEY_CACHE_LOCATION:
|
||||
setCacheLocation(sharedPreferences.getString(key, ""));
|
||||
break;
|
||||
case Constants.PREFERENCES_KEY_SYNC_MOST_RECENT:
|
||||
SyncUtil.removeMostRecentSyncFiles(context);
|
||||
break;
|
||||
case Constants.PREFERENCES_KEY_REPLAY_GAIN:
|
||||
case Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP:
|
||||
case Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED:
|
||||
DownloadService downloadService = DownloadService.getInstance();
|
||||
if (downloadService != null) {
|
||||
downloadService.reapplyVolume();
|
||||
}
|
||||
break;
|
||||
case Constants.PREFERENCES_KEY_START_ON_HEADPHONES:
|
||||
Intent serviceIntent = new Intent();
|
||||
serviceIntent.setClassName(context.getPackageName(), HeadphoneListenerService.class.getName());
|
||||
|
||||
if (sharedPreferences.getBoolean(key, false)) {
|
||||
context.startService(serviceIntent);
|
||||
} else {
|
||||
context.stopService(serviceIntent);
|
||||
}
|
||||
if (sharedPreferences.getBoolean(key, false)) {
|
||||
context.startService(serviceIntent);
|
||||
} else {
|
||||
context.stopService(serviceIntent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
scheduleBackup();
|
||||
|
|
|
@ -884,13 +884,19 @@ public class DownloadService extends Service {
|
|||
* Plays or resumes the playback, depending on the current player state.
|
||||
*/
|
||||
public synchronized void togglePlayPause() {
|
||||
if (playerState == PAUSED || playerState == COMPLETED || playerState == STOPPED) {
|
||||
start();
|
||||
} else if (playerState == STOPPED || playerState == IDLE) {
|
||||
autoPlayStart = true;
|
||||
play();
|
||||
} else if (playerState == STARTED) {
|
||||
pause();
|
||||
switch (playerState) {
|
||||
case PAUSED:
|
||||
case COMPLETED:
|
||||
case STOPPED:
|
||||
start();
|
||||
break;
|
||||
case IDLE:
|
||||
autoPlayStart = true;
|
||||
play();
|
||||
break;
|
||||
case STARTED:
|
||||
pause();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,19 +71,26 @@ public class DownloadServiceLifecycleSupport {
|
|||
eventHandler.post(() -> {
|
||||
String action = intent.getAction();
|
||||
Log.i(TAG, "intentReceiver.onReceive: " + action);
|
||||
if (DownloadService.CMD_PLAY.equals(action)) {
|
||||
downloadService.play();
|
||||
} else if (DownloadService.CMD_NEXT.equals(action)) {
|
||||
downloadService.next();
|
||||
} else if (DownloadService.CMD_PREVIOUS.equals(action)) {
|
||||
downloadService.previous();
|
||||
} else if (DownloadService.CMD_TOGGLEPAUSE.equals(action)) {
|
||||
downloadService.togglePlayPause();
|
||||
} else if (DownloadService.CMD_PAUSE.equals(action)) {
|
||||
downloadService.pause();
|
||||
} else if (DownloadService.CMD_STOP.equals(action)) {
|
||||
downloadService.pause();
|
||||
downloadService.seekTo(0);
|
||||
switch (action) {
|
||||
case DownloadService.CMD_PLAY:
|
||||
downloadService.play();
|
||||
break;
|
||||
case DownloadService.CMD_NEXT:
|
||||
downloadService.next();
|
||||
break;
|
||||
case DownloadService.CMD_PREVIOUS:
|
||||
downloadService.previous();
|
||||
break;
|
||||
case DownloadService.CMD_TOGGLEPAUSE:
|
||||
downloadService.togglePlayPause();
|
||||
break;
|
||||
case DownloadService.CMD_PAUSE:
|
||||
downloadService.pause();
|
||||
break;
|
||||
case DownloadService.CMD_STOP:
|
||||
downloadService.pause();
|
||||
downloadService.seekTo(0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -44,17 +44,23 @@ public class EntryListParser extends MusicDirectoryEntryParser {
|
|||
eventType = nextParseEvent();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = getElementName();
|
||||
if ("album".equals(name)) {
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
if (get("isDir") == null) {
|
||||
entry.setDirectory(true);
|
||||
switch (name) {
|
||||
case "album": {
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
if (get("isDir") == null) {
|
||||
entry.setDirectory(true);
|
||||
}
|
||||
dir.addChild(entry);
|
||||
break;
|
||||
}
|
||||
dir.addChild(entry);
|
||||
} else if ("song".equals(name)) {
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
dir.addChild(entry);
|
||||
} else if ("error".equals(name)) {
|
||||
handleError();
|
||||
case "song": {
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
dir.addChild(entry);
|
||||
break;
|
||||
}
|
||||
case "error":
|
||||
handleError();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (eventType != XmlPullParser.END_DOCUMENT);
|
||||
|
|
|
@ -51,14 +51,18 @@ public class GenreParser extends AbstractParser {
|
|||
eventType = nextParseEvent();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = getElementName();
|
||||
if ("genre".equals(name)) {
|
||||
genre = new Genre();
|
||||
genre.setSongCount(getInteger("songCount"));
|
||||
genre.setAlbumCount(getInteger("albumCount"));
|
||||
} else if ("error".equals(name)) {
|
||||
handleError();
|
||||
} else {
|
||||
genre = null;
|
||||
switch (name) {
|
||||
case "genre":
|
||||
genre = new Genre();
|
||||
genre.setSongCount(getInteger("songCount"));
|
||||
genre.setAlbumCount(getInteger("albumCount"));
|
||||
break;
|
||||
case "error":
|
||||
handleError();
|
||||
break;
|
||||
default:
|
||||
genre = null;
|
||||
break;
|
||||
}
|
||||
} else if (eventType == XmlPullParser.TEXT) {
|
||||
if (genre != null) {
|
||||
|
|
|
@ -65,42 +65,50 @@ public class IndexesParser extends MusicDirectoryEntryParser {
|
|||
eventType = nextParseEvent();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = getElementName();
|
||||
if ("indexes".equals(name) || "artists".equals(name)) {
|
||||
changed = true;
|
||||
ignoredArticles = get("ignoredArticles");
|
||||
} else if ("index".equals(name)) {
|
||||
index = get("name");
|
||||
switch (name) {
|
||||
case "indexes":
|
||||
case "artists":
|
||||
changed = true;
|
||||
ignoredArticles = get("ignoredArticles");
|
||||
break;
|
||||
case "index":
|
||||
index = get("name");
|
||||
|
||||
} else if ("artist".equals(name)) {
|
||||
Artist artist = new Artist();
|
||||
artist.setId(get("id"));
|
||||
artist.setName(get("name"));
|
||||
artist.setIndex(index);
|
||||
break;
|
||||
case "artist":
|
||||
Artist artist = new Artist();
|
||||
artist.setId(get("id"));
|
||||
artist.setName(get("name"));
|
||||
artist.setIndex(index);
|
||||
|
||||
// Combine the id's for the two artists
|
||||
if (artistList.containsKey(artist.getName())) {
|
||||
Artist originalArtist = artistList.get(artist.getName());
|
||||
originalArtist.setId(originalArtist.getId() + ";" + artist.getId());
|
||||
} else {
|
||||
artistList.put(artist.getName(), artist);
|
||||
artists.add(artist);
|
||||
}
|
||||
// Combine the id's for the two artists
|
||||
if (artistList.containsKey(artist.getName())) {
|
||||
Artist originalArtist = artistList.get(artist.getName());
|
||||
originalArtist.setId(originalArtist.getId() + ";" + artist.getId());
|
||||
} else {
|
||||
artistList.put(artist.getName(), artist);
|
||||
artists.add(artist);
|
||||
}
|
||||
|
||||
if (artists.size() % 10 == 0) {
|
||||
String msg = getContext().getResources().getString(R.string.parser_artist_count, artists.size());
|
||||
updateProgress(progressListener, msg);
|
||||
}
|
||||
} else if ("shortcut".equals(name)) {
|
||||
Artist shortcut = new Artist();
|
||||
shortcut.setId(get("id"));
|
||||
shortcut.setName(get("name"));
|
||||
shortcut.setIndex("*");
|
||||
shortcuts.add(shortcut);
|
||||
} else if ("child".equals(name)) {
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
entries.add(entry);
|
||||
} else if ("error".equals(name)) {
|
||||
handleError();
|
||||
if (artists.size() % 10 == 0) {
|
||||
String msg = getContext().getResources().getString(R.string.parser_artist_count, artists.size());
|
||||
updateProgress(progressListener, msg);
|
||||
}
|
||||
break;
|
||||
case "shortcut":
|
||||
Artist shortcut = new Artist();
|
||||
shortcut.setId(get("id"));
|
||||
shortcut.setName(get("name"));
|
||||
shortcut.setIndex("*");
|
||||
shortcuts.add(shortcut);
|
||||
break;
|
||||
case "child":
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
entries.add(entry);
|
||||
break;
|
||||
case "error":
|
||||
handleError();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (eventType != XmlPullParser.END_DOCUMENT);
|
||||
|
|
|
@ -44,13 +44,17 @@ public class PlaylistParser extends MusicDirectoryEntryParser {
|
|||
eventType = nextParseEvent();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = getElementName();
|
||||
if ("entry".equals(name)) {
|
||||
dir.addChild(parseEntry(""));
|
||||
} else if ("error".equals(name)) {
|
||||
handleError();
|
||||
} else if ("playlist".equals(name)) {
|
||||
dir.setName(get("name"));
|
||||
dir.setId(get("id"));
|
||||
switch (name) {
|
||||
case "entry":
|
||||
dir.addChild(parseEntry(""));
|
||||
break;
|
||||
case "error":
|
||||
handleError();
|
||||
break;
|
||||
case "playlist":
|
||||
dir.setName(get("name"));
|
||||
dir.setId(get("id"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (eventType != XmlPullParser.END_DOCUMENT);
|
||||
|
|
|
@ -50,19 +50,24 @@ public class SearchResult2Parser extends MusicDirectoryEntryParser {
|
|||
eventType = nextParseEvent();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = getElementName();
|
||||
if ("artist".equals(name)) {
|
||||
Artist artist = new Artist();
|
||||
artist.setId(get("id"));
|
||||
artist.setName(get("name"));
|
||||
artists.add(artist);
|
||||
} else if ("album".equals(name)) {
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
entry.setDirectory(true);
|
||||
albums.add(entry);
|
||||
} else if ("song".equals(name)) {
|
||||
songs.add(parseEntry(""));
|
||||
} else if ("error".equals(name)) {
|
||||
handleError();
|
||||
switch (name) {
|
||||
case "artist":
|
||||
Artist artist = new Artist();
|
||||
artist.setId(get("id"));
|
||||
artist.setName(get("name"));
|
||||
artists.add(artist);
|
||||
break;
|
||||
case "album":
|
||||
MusicDirectory.Entry entry = parseEntry("");
|
||||
entry.setDirectory(true);
|
||||
albums.add(entry);
|
||||
break;
|
||||
case "song":
|
||||
songs.add(parseEntry(""));
|
||||
break;
|
||||
case "error":
|
||||
handleError();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (eventType != XmlPullParser.END_DOCUMENT);
|
||||
|
|
|
@ -60,29 +60,32 @@ public final class ThemeUtil {
|
|||
private static int getThemeRes(Context context, String theme) {
|
||||
if (context instanceof SubsonicFragmentActivity || context instanceof SettingsActivity) {
|
||||
if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
|
||||
if (THEME_DARK.equals(theme)) {
|
||||
return R.style.Theme_Audinaut_Dark_No_Actionbar;
|
||||
} else if (THEME_BLACK.equals(theme)) {
|
||||
return R.style.Theme_Audinaut_Black_No_Actionbar;
|
||||
} else {
|
||||
return R.style.Theme_Audinaut_Light_No_Actionbar;
|
||||
switch (theme) {
|
||||
case THEME_DARK:
|
||||
return R.style.Theme_Audinaut_Dark_No_Actionbar;
|
||||
case THEME_BLACK:
|
||||
return R.style.Theme_Audinaut_Black_No_Actionbar;
|
||||
default:
|
||||
return R.style.Theme_Audinaut_Light_No_Actionbar;
|
||||
}
|
||||
} else {
|
||||
if (THEME_DARK.equals(theme)) {
|
||||
return R.style.Theme_Audinaut_Dark_No_Color;
|
||||
} else if (THEME_BLACK.equals(theme)) {
|
||||
return R.style.Theme_Audinaut_Black_No_Color;
|
||||
} else {
|
||||
return R.style.Theme_Audinaut_Light_No_Color;
|
||||
switch (theme) {
|
||||
case THEME_DARK:
|
||||
return R.style.Theme_Audinaut_Dark_No_Color;
|
||||
case THEME_BLACK:
|
||||
return R.style.Theme_Audinaut_Black_No_Color;
|
||||
default:
|
||||
return R.style.Theme_Audinaut_Light_No_Color;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (THEME_DARK.equals(theme)) {
|
||||
return R.style.Theme_Audinaut_Dark;
|
||||
} else if (THEME_BLACK.equals(theme)) {
|
||||
return R.style.Theme_Audinaut_Black;
|
||||
} else {
|
||||
return R.style.Theme_Audinaut_Light;
|
||||
switch (theme) {
|
||||
case THEME_DARK:
|
||||
return R.style.Theme_Audinaut_Dark;
|
||||
case THEME_BLACK:
|
||||
return R.style.Theme_Audinaut_Black;
|
||||
default:
|
||||
return R.style.Theme_Audinaut_Light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -968,33 +968,38 @@ public final class Util {
|
|||
audioManager.requestAudioFocus(focusListener = new OnAudioFocusChangeListener() {
|
||||
public void onAudioFocusChange(int focusChange) {
|
||||
DownloadService downloadService = (DownloadService) context;
|
||||
if ((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK)) {
|
||||
if (downloadService.getPlayerState() == PlayerState.STARTED) {
|
||||
Log.i(TAG, "Temporary loss of focus");
|
||||
SharedPreferences prefs = getPreferences(context);
|
||||
int lossPref = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_TEMP_LOSS, "1"));
|
||||
if (lossPref == 2 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK)) {
|
||||
lowerFocus = true;
|
||||
downloadService.setVolume(0.1f);
|
||||
} else if (lossPref == 0 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT)) {
|
||||
pauseFocus = true;
|
||||
downloadService.pause(true);
|
||||
switch (focusChange) {
|
||||
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
||||
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
|
||||
if (downloadService.getPlayerState() == PlayerState.STARTED) {
|
||||
Log.i(TAG, "Temporary loss of focus");
|
||||
SharedPreferences prefs = getPreferences(context);
|
||||
int lossPref = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_TEMP_LOSS, "1"));
|
||||
if (lossPref == 2 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK)) {
|
||||
lowerFocus = true;
|
||||
downloadService.setVolume(0.1f);
|
||||
} else if (lossPref == 0 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT)) {
|
||||
pauseFocus = true;
|
||||
downloadService.pause(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
||||
if (pauseFocus) {
|
||||
pauseFocus = false;
|
||||
downloadService.start();
|
||||
}
|
||||
if (lowerFocus) {
|
||||
lowerFocus = false;
|
||||
downloadService.setVolume(1.0f);
|
||||
}
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
|
||||
Log.i(TAG, "Permanently lost focus");
|
||||
focusListener = null;
|
||||
downloadService.pause();
|
||||
audioManager.abandonAudioFocus(this);
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_GAIN:
|
||||
if (pauseFocus) {
|
||||
pauseFocus = false;
|
||||
downloadService.start();
|
||||
}
|
||||
if (lowerFocus) {
|
||||
lowerFocus = false;
|
||||
downloadService.setVolume(1.0f);
|
||||
}
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_LOSS:
|
||||
Log.i(TAG, "Permanently lost focus");
|
||||
focusListener = null;
|
||||
downloadService.pause();
|
||||
audioManager.abandonAudioFocus(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
||||
|
|
Loading…
Reference in New Issue