aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-12 13:23:50 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-12 13:23:50 -0700
commit1bce73fa27683972021150de93ca7a5b66652e79 (patch)
tree8c31fbc39e909a11c67fd98a37a18f72aaebe682 /src
parent5abe274a3572e08149fa10481bf552ab4ceda9c0 (diff)
parent9ac927c4c812149802fccdeb42dd66573c2c5281 (diff)
downloaddsub-1bce73fa27683972021150de93ca7a5b66652e79.tar.gz
dsub-1bce73fa27683972021150de93ca7a5b66652e79.tar.bz2
dsub-1bce73fa27683972021150de93ca7a5b66652e79.zip
Merge branch 'master' of https://github.com/daneren2005/Subsonic into MediaStore
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java5
-rw-r--r--src/github/daneren2005/dsub/domain/MusicDirectory.java37
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java59
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java30
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java4
-rw-r--r--src/github/daneren2005/dsub/service/OfflineMusicService.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java4
-rw-r--r--src/github/daneren2005/dsub/util/Notifications.java23
-rw-r--r--src/github/daneren2005/dsub/view/SongView.java5
9 files changed, 112 insertions, 57 deletions
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 395a347e..92775f3e 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -494,7 +494,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
public boolean onBackPressedSupport() {
- if(backStack.size() > 0) {
+ if(drawerOpen) {
+ drawer.closeDrawers();
+ return false;
+ } else if(backStack.size() > 0) {
removeCurrent();
return false;
} else {
diff --git a/src/github/daneren2005/dsub/domain/MusicDirectory.java b/src/github/daneren2005/dsub/domain/MusicDirectory.java
index c284ba00..492726f9 100644
--- a/src/github/daneren2005/dsub/domain/MusicDirectory.java
+++ b/src/github/daneren2005/dsub/domain/MusicDirectory.java
@@ -102,8 +102,8 @@ public class MusicDirectory implements Serializable {
return children.size();
}
- public void sortChildren() {
- EntryComparator.sort(children);
+ public void sortChildren(boolean byYear) {
+ EntryComparator.sort(children, byYear);
}
public static class Entry implements Serializable {
@@ -422,23 +422,31 @@ public class MusicDirectory implements Serializable {
}
public static class EntryComparator implements Comparator<Entry> {
+ private boolean byYear;
+
+ public EntryComparator(boolean byYear) {
+ this.byYear = byYear;
+ }
+
public int compare(Entry lhs, Entry rhs) {
if(lhs.isDirectory() && !rhs.isDirectory()) {
return -1;
} else if(!lhs.isDirectory() && rhs.isDirectory()) {
return 1;
} else if(lhs.isDirectory() && rhs.isDirectory()) {
- Integer lhsYear = lhs.getYear();
- Integer rhsYear = rhs.getYear();
- if(lhsYear != null && rhsYear != null) {
- return lhsYear.compareTo(rhsYear);
- } else if(lhsYear != null) {
- return -1;
- } else if(rhsYear != null) {
- return 1;
- } else {
- return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
+ if(byYear) {
+ Integer lhsYear = lhs.getYear();
+ Integer rhsYear = rhs.getYear();
+ if(lhsYear != null && rhsYear != null) {
+ return lhsYear.compareTo(rhsYear);
+ } else if(lhsYear != null) {
+ return -1;
+ } else if(rhsYear != null) {
+ return 1;
+ }
}
+
+ return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
}
Integer lhsDisc = lhs.getDiscNumber();
@@ -466,8 +474,11 @@ public class MusicDirectory implements Serializable {
}
public static void sort(List<Entry> entries) {
+ sort(entries, true);
+ }
+ public static void sort(List<Entry> entries, boolean byYear) {
try {
- Collections.sort(entries, new EntryComparator());
+ Collections.sort(entries, new EntryComparator(byYear));
} catch (Exception e) {
Log.w(TAG, "Failed to sort MusicDirectory");
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index d40f8fad..fea3d44c 100644
--- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -164,28 +164,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
setupScrollList(albumList);
}
- albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position);
- SubsonicFragment fragment = new SelectDirectoryFragment();
- Bundle args = new Bundle();
- args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId());
- args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
- if ("newest".equals(albumListType)) {
- args.putBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS, true);
- }
- if(entry.getArtist() == null && entry.getParent() == null) {
- args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
- }
- fragment.setArguments(args);
-
- replaceFragment(fragment, true);
- }
- });
-
registerForContextMenu(entryList);
- registerForContextMenu(albumList);
+ setupAlbumList();
if(entries == null) {
if(primaryFragment || secondaryFragment) {
@@ -662,7 +642,17 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
// Needs to be added here, GB crashes if you to try to remove the header view before adapter is set
if(addAlbumHeader) {
- entryList.addHeaderView(albumList);
+ if(entries.size() > 0) {
+ entryList.addHeaderView(albumList);
+ } else {
+ ViewGroup rootGroup = (ViewGroup) rootView.findViewById(R.id.select_album_layout);
+ albumList = (GridView) context.getLayoutInflater().inflate(R.layout.grid_view, rootGroup, false);
+ rootGroup.removeView(entryList);
+ rootGroup.addView(albumList);
+
+ setupScrollList(albumList);
+ setupAlbumList();
+ }
addAlbumHeader = false;
}
@@ -718,6 +708,31 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
}
+ private void setupAlbumList() {
+ albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position);
+ SubsonicFragment fragment = new SelectDirectoryFragment();
+ Bundle args = new Bundle();
+ args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId());
+ args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
+ if ("newest".equals(albumListType)) {
+ args.putBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS, true);
+ }
+ if(entry.getArtist() == null && entry.getParent() == null) {
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
+ }
+ fragment.setArguments(args);
+
+ replaceFragment(fragment, true);
+ }
+ });
+
+ registerForContextMenu(entryList);
+ registerForContextMenu(albumList);
+ }
+
private void playNow(final boolean shuffle, final boolean append) {
playNow(shuffle, append, false);
}
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index f28c38dc..f458379d 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -700,6 +700,7 @@ public class DownloadService extends Service {
nextPlayingTask = new CheckCompletionTask(nextPlaying);
nextPlayingTask.execute();
} else {
+ resetNext();
nextPlaying = null;
}
}
@@ -934,6 +935,8 @@ public class DownloadService extends Service {
mediaPlayer.pause();
}
setPlayerState(temp ? PAUSED_TEMP : PAUSED);
+ } else if(playerState == PAUSED_TEMP) {
+ setPlayerState(temp ? PAUSED_TEMP : PAUSED);
}
} catch (Exception x) {
handleError(x);
@@ -994,6 +997,25 @@ public class DownloadService extends Service {
}
}
+ public synchronized void resetNext() {
+ try {
+ if (nextMediaPlayer != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && nextSetup) {
+ mediaPlayer.setNextMediaPlayer(null);
+ nextSetup = false;
+ }
+
+ nextMediaPlayer.setOnCompletionListener(null);
+ nextMediaPlayer.setOnErrorListener(null);
+ nextMediaPlayer.reset();
+ nextMediaPlayer.release();
+ nextMediaPlayer = null;
+ }
+ } catch (Exception e) {
+ Log.w(TAG, "Failed to reset next media player");
+ }
+ }
+
public int getPlayerPosition() {
try {
if (playerState == IDLE || playerState == DOWNLOADING || playerState == PREPARING) {
@@ -1395,13 +1417,7 @@ public class DownloadService extends Service {
private synchronized void setupNext(final DownloadFile downloadFile) {
try {
final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile();
- if(nextMediaPlayer != null) {
- nextMediaPlayer.setOnCompletionListener(null);
- nextMediaPlayer.setOnErrorListener(null);
- nextMediaPlayer.reset();
- nextMediaPlayer.release();
- nextMediaPlayer = null;
- }
+ resetNext();
// Exit when using remote controllers
if(remoteState != RemoteControlState.LOCAL) {
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 76c9abeb..18502846 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -332,7 +332,9 @@ public class DownloadServiceLifecycleSupport {
case TelephonyManager.CALL_STATE_IDLE:
if (resumeAfterCall) {
resumeAfterCall = false;
- downloadService.start();
+ if(downloadService.getPlayerState() == PlayerState.PAUSED_TEMP) {
+ downloadService.start();
+ }
}
break;
default:
diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java
index a92e41d1..04955cc3 100644
--- a/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -134,7 +134,7 @@ public class OfflineMusicService extends RESTMusicService {
result.addChild(createEntry(context, file, name, true, isPodcast));
}
}
- result.sortChildren();
+ result.sortChildren(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_CUSTOM_SORT_ENABLED, true));
return result;
}
diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
index e705c54d..95ee1744 100644
--- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
+++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
@@ -97,8 +97,8 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser {
validate();
// Only apply sorting on server version 4.7 and greater, where disc is supported
- if(Util.checkServerVersion(context, "1.8.0") && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_CUSTOM_SORT_ENABLED, true)) {
- dir.sortChildren();
+ if(Util.checkServerVersion(context, "1.8.0")) {
+ dir.sortChildren(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_CUSTOM_SORT_ENABLED, true));
}
return dir;
diff --git a/src/github/daneren2005/dsub/util/Notifications.java b/src/github/daneren2005/dsub/util/Notifications.java
index de4129e9..75c69d9e 100644
--- a/src/github/daneren2005/dsub/util/Notifications.java
+++ b/src/github/daneren2005/dsub/util/Notifications.java
@@ -65,13 +65,13 @@ public final class Notifications {
boolean remote = downloadService.isRemoteEnabled();
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN){
RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
- setupViews(expandedContentView,context,song, playing, remote);
+ setupViews(expandedContentView ,context, song, true, playing, remote);
notification.bigContentView = expandedContentView;
notification.priority = Notification.PRIORITY_HIGH;
}
RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
- setupViews(smallContentView, context, song, playing, remote);
+ setupViews(smallContentView, context, song, false, playing, remote);
notification.contentView = smallContentView;
Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
@@ -103,7 +103,7 @@ public final class Notifications {
DSubWidgetProvider.notifyInstances(context, downloadService, playing);
}
- private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing, boolean remote){
+ private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote){
// Use the same text for the ticker and the expanded notification
String title = song.getTitle();
@@ -141,16 +141,21 @@ public final class Notifications {
rv.setTextColor(R.id.notification_artist, colors.getSecond());
}
- if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)) {
- rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_play);
- rv.setImageViewResource(R.id.control_pause, R.drawable.notification_next);
- rv.setImageViewResource(R.id.control_next, R.drawable.notification_close);
+ boolean persistent = Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false);
+ if(persistent) {
+ if(expanded) {
+ rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_play);
+ } else {
+ rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_play);
+ rv.setImageViewResource(R.id.control_pause, R.drawable.notification_next);
+ rv.setImageViewResource(R.id.control_next, R.drawable.notification_close);
+ }
}
// Create actions for media buttons
PendingIntent pendingIntent;
int previous = 0, pause = 0, next = 0, close = 0;
- if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)) {
+ if(persistent && !expanded) {
pause = R.id.control_previous;
next = R.id.control_pause;
close = R.id.control_next;
@@ -160,7 +165,7 @@ public final class Notifications {
next = R.id.control_next;
}
- if(remote && close == 0) {
+ if((remote || persistent) && close == 0) {
close = R.id.notification_close;
rv.setViewVisibility(close, View.VISIBLE);
}
diff --git a/src/github/daneren2005/dsub/view/SongView.java b/src/github/daneren2005/dsub/view/SongView.java
index 3e423877..e6156ceb 100644
--- a/src/github/daneren2005/dsub/view/SongView.java
+++ b/src/github/daneren2005/dsub/view/SongView.java
@@ -48,6 +48,7 @@ public class SongView extends UpdateView implements Checkable {
private TextView durationTextView;
private TextView statusTextView;
private ImageView statusImageView;
+ private View bottomRowView;
private DownloadService downloadService;
private long revision = -1;
@@ -80,6 +81,7 @@ public class SongView extends UpdateView implements Checkable {
v.showContextMenu();
}
});
+ bottomRowView = findViewById(R.id.song_bottom);
}
public void setObjectImpl(Object obj1, Object obj2) {
@@ -120,8 +122,9 @@ public class SongView extends UpdateView implements Checkable {
}
durationTextView.setText(Util.formatDuration(song.getDuration()));
+ bottomRowView.setVisibility(View.VISIBLE);
} else {
- findViewById(R.id.song_bottom).setVisibility(View.GONE);
+ bottomRowView.setVisibility(View.GONE);
statusTextView.setText(Util.formatDuration(song.getDuration()));
}