aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/fragments/DownloadFragment.java24
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceImpl.java2
-rw-r--r--src/github/daneren2005/dsub/service/OfflineMusicService.java88
-rw-r--r--src/github/daneren2005/dsub/service/parser/AbstractParser.java3
-rw-r--r--src/github/daneren2005/dsub/util/Util.java51
5 files changed, 99 insertions, 69 deletions
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
index de721f7d..f345334f 100644
--- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java
+++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
@@ -178,17 +178,21 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
toggleListButton =rootView.findViewById(R.id.download_toggle_list);
starButton = (ImageButton)rootView.findViewById(R.id.download_star);
- starButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
- if (currentDownload != null) {
- MusicDirectory.Entry currentSong = currentDownload.getSong();
- toggleStarred(currentSong);
- starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) {
+ starButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
+ if (currentDownload != null) {
+ MusicDirectory.Entry currentSong = currentDownload.getSong();
+ toggleStarred(currentSong);
+ starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ }
}
- }
- });
+ });
+ } else {
+ starButton.setVisibility(View.GONE);
+ }
View.OnTouchListener touchListener = new View.OnTouchListener() {
@Override
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 30a230ac..2f3dce53 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -952,7 +952,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
boolean show = playerState == PlayerState.STARTED;
boolean pause = playerState == PlayerState.PAUSED;
boolean hide = playerState == PlayerState.STOPPED;
- Util.broadcastPlaybackStatusChange(this, playerState);
+ Util.broadcastPlaybackStatusChange(this, (currentPlaying != null) ? currentPlaying.getSong() : null, playerState);
this.playerState = playerState;
diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java
index 80ad375a..fdeb373c 100644
--- a/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -37,6 +37,7 @@ import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.Indexes;
+import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.domain.RemoteStatus;
import github.daneren2005.dsub.domain.Lyrics;
import github.daneren2005.dsub.domain.MusicDirectory;
@@ -116,22 +117,25 @@ public class OfflineMusicService extends RESTMusicService {
@Override
public MusicDirectory getMusicDirectory(String id, String artistName, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
- File dir = new File(id);
- MusicDirectory result = new MusicDirectory();
- result.setName(dir.getName());
-
- Set<String> names = new HashSet<String>();
-
- for (File file : FileUtil.listMediaFiles(dir)) {
- String name = getName(file);
- if (name != null & !names.contains(name)) {
- names.add(name);
- result.addChild(createEntry(context, file, name));
- }
- }
- result.sortChildren();
- return result;
+ return getMusicDirectory(id, artistName, refresh, context, progressListener, false);
}
+ private MusicDirectory getMusicDirectory(String id, String artistName, boolean refresh, Context context, ProgressListener progressListener, boolean isPodcast) throws Exception {
+ File dir = new File(id);
+ MusicDirectory result = new MusicDirectory();
+ result.setName(dir.getName());
+
+ Set<String> names = new HashSet<String>();
+
+ for (File file : FileUtil.listMediaFiles(dir)) {
+ String name = getName(file);
+ if (name != null & !names.contains(name)) {
+ names.add(name);
+ result.addChild(createEntry(context, file, name, true, isPodcast));
+ }
+ }
+ result.sortChildren();
+ return result;
+ }
private String getName(File file) {
String name = file.getName();
@@ -151,18 +155,28 @@ public class OfflineMusicService extends RESTMusicService {
return createEntry(context, file, name, true);
}
private MusicDirectory.Entry createEntry(Context context, File file, String name, boolean load) {
- MusicDirectory.Entry entry = new MusicDirectory.Entry();
- entry.setDirectory(file.isDirectory());
- entry.setId(file.getPath());
- entry.setParent(file.getParent());
- entry.setSize(file.length());
- String root = FileUtil.getMusicDirectory(context).getPath();
+ return createEntry(context, file, name, load, false);
+ }
+ private MusicDirectory.Entry createEntry(Context context, File file, String name, boolean load, boolean isPodcast) {
+ MusicDirectory.Entry entry;
+ if(isPodcast) {
+ PodcastEpisode episode = new PodcastEpisode();
+ episode.setStatus("completed");
+ entry = episode;
+ } else {
+ entry = new MusicDirectory.Entry();
+ }
+ entry.setDirectory(file.isDirectory());
+ entry.setId(file.getPath());
+ entry.setParent(file.getParent());
+ entry.setSize(file.length());
+ String root = FileUtil.getMusicDirectory(context).getPath();
if(!file.getParentFile().getParentFile().getPath().equals(root)) {
entry.setGrandParent(file.getParentFile().getParent());
}
- entry.setPath(file.getPath().replaceFirst("^" + root + "/" , ""));
+ entry.setPath(file.getPath().replaceFirst("^" + root + "/" , ""));
String title = name;
- if (file.isFile()) {
+ if (file.isFile()) {
File artistFolder = file.getParentFile().getParentFile();
File albumFolder = file.getParentFile();
if(artistFolder.getPath().equals(root)) {
@@ -170,8 +184,8 @@ public class OfflineMusicService extends RESTMusicService {
} else {
entry.setArtist(artistFolder.getName());
}
- entry.setAlbum(albumFolder.getName());
-
+ entry.setAlbum(albumFolder.getName());
+
int index = name.indexOf('-');
if(index != -1) {
try {
@@ -181,24 +195,24 @@ public class OfflineMusicService extends RESTMusicService {
// Failed parseInt, just means track filled out
}
}
-
+
if(load) {
entry.loadMetadata(file);
}
- }
-
- entry.setTitle(title);
- entry.setSuffix(FileUtil.getExtension(file.getName().replace(".complete", "")));
+ }
- File albumArt = FileUtil.getAlbumArtFile(context, entry);
- if (albumArt.exists()) {
- entry.setCoverArt(albumArt.getPath());
- }
+ entry.setTitle(title);
+ entry.setSuffix(FileUtil.getExtension(file.getName().replace(".complete", "")));
+
+ File albumArt = FileUtil.getAlbumArtFile(context, entry);
+ if (albumArt.exists()) {
+ entry.setCoverArt(albumArt.getPath());
+ }
if(FileUtil.isVideoFile(file)) {
entry.setVideo(true);
}
- return entry;
- }
+ return entry;
+ }
@Override
public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener) throws Exception {
@@ -613,7 +627,7 @@ public class OfflineMusicService extends RESTMusicService {
@Override
public MusicDirectory getPodcastEpisodes(boolean refresh, String id, Context context, ProgressListener progressListener) throws Exception {
- return getMusicDirectory(FileUtil.getPodcastDirectory(context, id).getPath(), null, false, context, progressListener);
+ return getMusicDirectory(FileUtil.getPodcastDirectory(context, id).getPath(), null, false, context, progressListener, true);
}
@Override
diff --git a/src/github/daneren2005/dsub/service/parser/AbstractParser.java b/src/github/daneren2005/dsub/service/parser/AbstractParser.java
index 1a457754..9db40dad 100644
--- a/src/github/daneren2005/dsub/service/parser/AbstractParser.java
+++ b/src/github/daneren2005/dsub/service/parser/AbstractParser.java
@@ -50,6 +50,9 @@ public abstract class AbstractParser {
int code = getInteger("code");
String message;
switch (code) {
+ case 0:
+ message = context.getResources().getString(R.string.parser_server_error, get("message"));
+ break;
case 20:
message = context.getResources().getString(R.string.parser_upgrade_client);
break;
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index a6c416ca..57684d33 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -1214,32 +1214,13 @@ public final class Util {
File albumArtFile = FileUtil.getAlbumArtFile(context, song);
intent.putExtra("coverart", albumArtFile.getAbsolutePath());
-
- avrcpIntent.putExtra("playing", true);
- avrcpIntent.putExtra("track", song.getTitle());
- avrcpIntent.putExtra("artist", song.getArtist());
- avrcpIntent.putExtra("album", song.getAlbum());
- avrcpIntent.putExtra("ListSize",(long) downloadService.getSongs().size());
- avrcpIntent.putExtra("id", (long) downloadService.getCurrentPlayingIndex()+1);
- avrcpIntent.putExtra("duration", (long) downloadService.getPlayerDuration());
- avrcpIntent.putExtra("position", (long) downloadService.getPlayerPosition());
- avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath());
} else {
intent.putExtra("title", "");
intent.putExtra("artist", "");
intent.putExtra("album", "");
intent.putExtra("coverart", "");
-
- avrcpIntent.putExtra("playing", false);
- avrcpIntent.putExtra("track", "");
- avrcpIntent.putExtra("artist", "");
- avrcpIntent.putExtra("album", "");
- avrcpIntent.putExtra("ListSize",(long)0);
- avrcpIntent.putExtra("id", (long) 0);
- avrcpIntent.putExtra("duration", (long )0);
- avrcpIntent.putExtra("position", (long) 0);
- avrcpIntent.putExtra("coverart", "");
}
+ addTrackInfo(context, song, avrcpIntent);
context.sendBroadcast(intent);
context.sendBroadcast(avrcpIntent);
@@ -1248,7 +1229,7 @@ public final class Util {
/**
* <p>Broadcasts the given player state as the one being set.</p>
*/
- public static void broadcastPlaybackStatusChange(Context context, PlayerState state) {
+ public static void broadcastPlaybackStatusChange(Context context, MusicDirectory.Entry song, PlayerState state) {
Intent intent = new Intent(EVENT_PLAYSTATE_CHANGED);
Intent avrcpIntent = new Intent(AVRCP_PLAYSTATE_CHANGED);
@@ -1272,11 +1253,39 @@ public final class Util {
default:
return; // No need to broadcast.
}
+ addTrackInfo(context, song, avrcpIntent);
context.sendBroadcast(intent);
context.sendBroadcast(avrcpIntent);
}
+ private static void addTrackInfo(Context context, MusicDirectory.Entry song, Intent intent) {
+ if (song != null) {
+ DownloadService downloadService = (DownloadServiceImpl)context;
+ File albumArtFile = FileUtil.getAlbumArtFile(context, song);
+
+ intent.putExtra("playing", true);
+ intent.putExtra("track", song.getTitle());
+ intent.putExtra("artist", song.getArtist());
+ intent.putExtra("album", song.getAlbum());
+ intent.putExtra("ListSize", (long) downloadService.getSongs().size());
+ intent.putExtra("id", (long) downloadService.getCurrentPlayingIndex() + 1);
+ intent.putExtra("duration", (long) downloadService.getPlayerDuration());
+ intent.putExtra("position", (long) downloadService.getPlayerPosition());
+ intent.putExtra("coverart", albumArtFile.getAbsolutePath());
+ } else {
+ intent.putExtra("playing", false);
+ intent.putExtra("track", "");
+ intent.putExtra("artist", "");
+ intent.putExtra("album", "");
+ intent.putExtra("ListSize", (long) 0);
+ intent.putExtra("id", (long) 0);
+ intent.putExtra("duration", (long) 0);
+ intent.putExtra("position", (long) 0);
+ intent.putExtra("coverart", "");
+ }
+ }
+
/**
* Resolves the default text color for notifications.
*