aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-11-23 15:13:32 -0800
committerScott Jackson <daneren2005@gmail.com>2013-11-23 15:13:32 -0800
commite7039a7e10c3efcb5d637bbbaa0111b092a4e214 (patch)
tree24adffc215af1adea16b5cefe84c40c5967fb126 /src
parent22a88ac31554301346ac20223bc22b949b1c344e (diff)
parentb5f029b6ec6a22b4c8e6d1e7d61b77affb483a77 (diff)
downloaddsub-e7039a7e10c3efcb5d637bbbaa0111b092a4e214.tar.gz
dsub-e7039a7e10c3efcb5d637bbbaa0111b092a4e214.tar.bz2
dsub-e7039a7e10c3efcb5d637bbbaa0111b092a4e214.zip
Merge branch 'master' of https://github.com/daneren2005/Subsonic into SyncAdapter
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java7
-rw-r--r--src/github/daneren2005/dsub/domain/Version.java2
-rw-r--r--src/github/daneren2005/dsub/fragments/DownloadFragment.java28
-rw-r--r--src/github/daneren2005/dsub/fragments/SearchFragment.java14
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java4
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java13
-rw-r--r--src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java6
-rw-r--r--src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java2
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--src/github/daneren2005/dsub/util/ShufflePlayBuffer.java33
10 files changed, 90 insertions, 20 deletions
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 83baeb6a..c475d321 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -368,7 +368,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
onSearchRequested();
}
}
- } else if(intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
+ } else if(currentFragment != null && intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
setIntent(intent);
SearchFragment fragment = new SearchFragment();
@@ -511,6 +511,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
// Only move right to left if replaceCurrent is false
if(!replaceCurrent) {
SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2);
+ oldLeftFragment.setSecondaryFragment(false);
int leftId = oldLeftFragment.getRootId();
// Make sure remove is finished before adding
@@ -539,7 +540,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
Fragment oldFrag = (Fragment)currentFragment;
currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1);
- currentFragment.setPrimaryFragment(true);
+ currentFragment.setPrimaryFragment(true, false);
supportInvalidateOptionsMenu();
if(secondaryContainer == null) {
@@ -563,6 +564,8 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
trans = getSupportFragmentManager().beginTransaction();
trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + "");
+
+ backStack.get(backStack.size() - 1).setSecondaryFragment(true);
} else {
secondaryContainer.setVisibility(View.GONE);
}
diff --git a/src/github/daneren2005/dsub/domain/Version.java b/src/github/daneren2005/dsub/domain/Version.java
index 40edf563..8cf338f1 100644
--- a/src/github/daneren2005/dsub/domain/Version.java
+++ b/src/github/daneren2005/dsub/domain/Version.java
@@ -80,6 +80,8 @@ public class Version implements Comparable<Version> {
return "4.7";
case 9:
return "4.8";
+ case 10:
+ return "4.9";
}
}
return "";
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
index d46fbec6..fb1979b5 100644
--- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java
+++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
@@ -103,12 +103,14 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
private VisualizerView visualizerView;
private boolean nowPlaying = true;
private ScheduledFuture<?> hideControlsFuture;
+ private List<DownloadFile> songList;
private SongListAdapter songListAdapter;
private SilentBackgroundTask<Void> onProgressChangedTask;
private SilentBackgroundTask<Void> onCurrentChangedTask;
private SilentBackgroundTask<Void> onDownloadListChangedTask;
private boolean seekInProgress = false;
private boolean startFlipped = false;
+ private boolean scrollWhenLoaded = false;
/**
* Called when the activity is first created.
@@ -506,7 +508,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
menu.findItem(R.id.menu_toggle_timer).setTitle(R.string.download_stop_timer);
}
}
- if(downloadService != null && downloadService.getKeepScreenOn()) {
+ if(downloadService != null && downloadService.getKeepScreenOn() && nowPlaying) {
menu.findItem(R.id.menu_screen_on_off).setTitle(R.string.download_menu_screen_off);
}
}
@@ -740,6 +742,10 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
}
updateButtons();
+
+ if(currentPlaying == null && downloadService != null && currentPlaying == downloadService.getCurrentPlaying()) {
+ getImageLoader().loadImage(albumArtImageView, null, true, false);
+ }
}
@Override
@@ -828,6 +834,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
// Scroll to current playing/downloading.
private void scrollToCurrent() {
if (getDownloadService() == null || songListAdapter == null) {
+ scrollWhenLoaded = true;
return;
}
@@ -860,8 +867,8 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
}
if(startFlipped) {
- scrollToCurrent();
startFlipped = false;
+ scrollToCurrent();
}
onProgressChanged();
@@ -942,6 +949,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
protected Void doInBackground() throws Throwable {
currentPlayingIndex = downloadService.getCurrentPlayingIndex() + 1;
size = downloadService.size();
+
return null;
}
@@ -954,19 +962,24 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
else {
list = downloadService.getBackgroundDownloads();
}
-
+
if(downloadService.isShufflePlayEnabled()) {
emptyTextView.setText(R.string.download_shuffle_loading);
}
else {
emptyTextView.setText(R.string.download_empty);
}
-
+
if(songListAdapter == null || refresh) {
- playlistView.setAdapter(songListAdapter = new SongListAdapter(list));
+ songList = new ArrayList<DownloadFile>();
+ songList.addAll(list);
+ playlistView.setAdapter(songListAdapter = new SongListAdapter(songList));
} else {
+ songList.clear();
+ songList.addAll(list);
songListAdapter.notifyDataSetChanged();
}
+
emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
currentRevision = downloadService.getDownloadListUpdateRevision();
@@ -987,6 +1000,11 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
default:
break;
}
+
+ if(scrollWhenLoaded) {
+ scrollToCurrent();
+ scrollWhenLoaded = false;
+ }
setSubtitle(context.getResources().getString(R.string.download_playing_out_of, currentPlayingIndex, size));
onDownloadListChangedTask = null;
diff --git a/src/github/daneren2005/dsub/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java
index 900872da..81d2f29f 100644
--- a/src/github/daneren2005/dsub/fragments/SearchFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java
@@ -108,7 +108,7 @@ public class SearchFragment extends SubsonicFragment {
} else {
Object item = parent.getItemAtPosition(position);
if (item instanceof Artist) {
- onArtistSelected((Artist) item);
+ onArtistSelected((Artist) item, false);
} else if (item instanceof MusicDirectory.Entry) {
MusicDirectory.Entry entry = (MusicDirectory.Entry) item;
if (entry.isDirectory()) {
@@ -208,7 +208,7 @@ public class SearchFragment extends SubsonicFragment {
searchResult = result;
populateList();
if (autoplay) {
- autoplay();
+ autoplay(query);
}
}
@@ -289,11 +289,14 @@ public class SearchFragment extends SubsonicFragment {
mergeAdapter.notifyDataSetChanged();
}
- private void onArtistSelected(Artist artist) {
+ private void onArtistSelected(Artist artist, boolean autoplay) {
SubsonicFragment fragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
+ if(autoplay) {
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
+ }
fragment.setArguments(args);
replaceFragment(fragment, R.id.fragment_list_layout);
@@ -317,6 +320,9 @@ public class SearchFragment extends SubsonicFragment {
args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ID, album.getId());
args.putString(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle());
+ if(autoplay) {
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
+ }
fragment.setArguments(args);
replaceFragment(fragment, id);
@@ -345,7 +351,7 @@ public class SearchFragment extends SubsonicFragment {
startActivity(intent);
}
- private void autoplay() {
+ private void autoplay(String query) {
if (!searchResult.getSongs().isEmpty()) {
onSongSelected(searchResult.getSongs().get(0), false, false, true, false);
} else if (!searchResult.getAlbums().isEmpty()) {
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 0081f881..137564ee 100644
--- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -288,7 +288,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position);
if (entry.isDirectory()) {
int fragId = rootId;
- if(albumListType != null && entry.getParent() != null) {
+ /*if(albumListType != null && entry.getParent() != null) {
SubsonicFragment parentFragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getParent());
@@ -300,7 +300,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
replaceFragment(parentFragment, fragId);
fragId = parentFragment.getRootId();
- }
+ }*/
SubsonicFragment fragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index d33c1b96..bec0be05 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -187,13 +187,20 @@ public class SubsonicFragment extends Fragment {
}
}
} else if(selected instanceof Artist) {
+ Artist artist = (Artist) selected;
if(Util.isOffline(context)) {
inflater.inflate(R.menu.select_artist_context_offline, menu);
}
else {
inflater.inflate(R.menu.select_artist_context, menu);
+
+ menu.findItem(R.id.artist_menu_star).setTitle(artist.isStarred() ? R.string.common_unstar : R.string.common_star);
}
}
+
+ if(!Util.checkServerVersion(context, "1.10.1")) {
+ menu.setGroupVisible(R.id.server_1_10, false);
+ }
}
public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) {
@@ -221,6 +228,9 @@ public class SubsonicFragment extends Fragment {
case R.id.artist_menu_delete:
deleteRecursively(artist);
break;
+ case R.id.artist_menu_star:
+ toggleStarred(artist);
+ break;
case R.id.album_menu_play_now:
downloadRecursively(entry.getId(), false, false, true, false, false);
break;
@@ -329,6 +339,9 @@ public class SubsonicFragment extends Fragment {
setPrimaryFragment(primary);
secondaryFragment = secondary;
}
+ public void setSecondaryFragment(boolean secondary) {
+ secondaryFragment = secondary;
+ }
public void invalidate() {
if(primaryFragment) {
diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
index 17b09805..7a49cfa5 100644
--- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
+++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
@@ -22,7 +22,7 @@ import android.content.Context;
import android.util.Log;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.domain.Version;
+import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.Util;
import org.xmlpull.v1.XmlPullParser;
@@ -71,7 +71,7 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser {
updateProgress(progressListener, R.string.parser_reading_done);
// Only apply sorting on server version 4.7 and greater, where disc is supported
- if(Util.checkServerVersion(context, "1.8.0")) {
+ if(Util.checkServerVersion(context, "1.8.0") && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_CUSTOM_SORT_ENABLED, true)) {
dir.sortChildren();
}
@@ -80,4 +80,4 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser {
return dir;
}
-} \ No newline at end of file
+}
diff --git a/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java b/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java
index 585b3057..58b1432b 100644
--- a/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java
+++ b/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java
@@ -88,7 +88,7 @@ public class PodcastEntryParser extends AbstractParser {
episode.setPath(episode.getPath().substring("Podcasts/".length()));
}
- if("error".equals(episode.getStatus()) || "skipped".equals(episode.getStatus())) {
+ if(episode.getId() == null) {
episode.setId(String.valueOf(bogusId));
bogusId--;
}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index 9940c3be..16fe51e5 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -125,6 +125,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_HIDE_WIDGET = "hideWidget";
public static final String PREFERENCES_KEY_PODCASTS_ENABLED = "podcastsEnabled";
public static final String PREFERENCES_KEY_BOOKMARKS_ENABLED = "bookmarksEnabled";
+ public static final String PREFERENCES_KEY_CUSTOM_SORT_ENABLED = "customSortEnabled";
public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount";
public static final String OFFLINE_SCROBBLE_ID = "scrobbleID";
diff --git a/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java b/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java
index 195fe913..b92945c4 100644
--- a/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java
+++ b/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java
@@ -18,6 +18,7 @@
*/
package github.daneren2005.dsub.util;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
@@ -30,6 +31,7 @@ import android.util.Log;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.util.FileUtil;
/**
* @author Sindre Mehus
@@ -38,11 +40,13 @@ import github.daneren2005.dsub.service.MusicServiceFactory;
public class ShufflePlayBuffer {
private static final String TAG = ShufflePlayBuffer.class.getSimpleName();
+ private static final String CACHE_FILENAME = "shuffleBuffer.ser";
private static final int CAPACITY = 50;
private static final int REFILL_THRESHOLD = 40;
private final ScheduledExecutorService executorService;
- private final List<MusicDirectory.Entry> buffer = new ArrayList<MusicDirectory.Entry>();
+ private boolean firstRun = true;
+ private final ArrayList<MusicDirectory.Entry> buffer = new ArrayList<MusicDirectory.Entry>();
private int lastCount = -1;
private Context context;
private int currentServer;
@@ -53,7 +57,8 @@ public class ShufflePlayBuffer {
private String endYear = "";
public ShufflePlayBuffer(Context context) {
- this.context = context;
+ this.context = context;
+
executorService = Executors.newSingleThreadScheduledExecutor();
Runnable runnable = new Runnable() {
@Override
@@ -69,8 +74,15 @@ public class ShufflePlayBuffer {
List<MusicDirectory.Entry> result = new ArrayList<MusicDirectory.Entry>(size);
synchronized (buffer) {
+ boolean removed = false;
while (!buffer.isEmpty() && result.size() < size) {
result.add(buffer.remove(buffer.size() - 1));
+ removed = true;
+ }
+
+ // Re-cache if anything is taken out
+ if(removed) {
+ FileUtil.serialize(context, buffer, CACHE_FILENAME);
}
}
Log.i(TAG, "Taking " + result.size() + " songs from shuffle play buffer. " + buffer.size() + " remaining.");
@@ -86,7 +98,7 @@ public class ShufflePlayBuffer {
// Check if active server has changed.
clearBufferIfnecessary();
- if (buffer.size() > REFILL_THRESHOLD || (!Util.isNetworkConnected(context) && !Util.isOffline(context)) || lastCount == 0) {
+ if (buffer != null && (buffer.size() > REFILL_THRESHOLD || (!Util.isNetworkConnected(context) && !Util.isOffline(context)) || lastCount == 0)) {
return;
}
@@ -100,6 +112,9 @@ public class ShufflePlayBuffer {
buffer.addAll(songs.getChildren());
Log.i(TAG, "Refilled shuffle play buffer with " + songs.getChildrenSize() + " songs.");
lastCount = songs.getChildrenSize();
+
+ // Cache buffer
+ FileUtil.serialize(context, buffer, CACHE_FILENAME);
}
} catch (Exception x) {
Log.w(TAG, "Failed to refill shuffle play buffer.", x);
@@ -121,6 +136,18 @@ public class ShufflePlayBuffer {
startYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, "");
endYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, "");
buffer.clear();
+
+ if(firstRun) {
+ ArrayList cacheList = FileUtil.deserialize(context, CACHE_FILENAME, ArrayList.class);
+ if(cacheList != null) {
+ buffer.addAll(cacheList);
+ }
+ firstRun = false;
+ } else {
+ // Clear cache
+ File file = new File(context.getCacheDir(), CACHE_FILENAME);
+ file.delete();
+ }
}
}
}