diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-11-11 21:32:03 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-11-11 21:32:03 -0800 |
commit | b5a1a88fe737430e99b82d0e9ac4df310486600a (patch) | |
tree | 7b269b51bda04c3cf8e391d4ef281b4a6bd77b4a /src | |
parent | 9f1f29344b1ce6b21285bc781446debf8c16cb23 (diff) | |
download | dsub-b5a1a88fe737430e99b82d0e9ac4df310486600a.tar.gz dsub-b5a1a88fe737430e99b82d0e9ac4df310486600a.tar.bz2 dsub-b5a1a88fe737430e99b82d0e9ac4df310486600a.zip |
Styled action buttons, added bookmark logic
Diffstat (limited to 'src')
5 files changed, 98 insertions, 9 deletions
diff --git a/src/github/daneren2005/dsub/domain/Bookmark.java b/src/github/daneren2005/dsub/domain/Bookmark.java index 83002a62..d1f470ce 100644 --- a/src/github/daneren2005/dsub/domain/Bookmark.java +++ b/src/github/daneren2005/dsub/domain/Bookmark.java @@ -28,7 +28,7 @@ import java.util.Locale; /**
* Created by Scott on 11/4/13.
*/
-public class Bookmark {
+public class Bookmark implements Serializable {
private int position;
private String username;
private String comment;
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 057b302f..232eda85 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -47,6 +47,8 @@ import github.daneren2005.dsub.domain.RemoteControlState; import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.view.FadeOutAnimation;
@@ -91,6 +93,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe private Button jukeboxButton;
private View toggleListButton;
private ImageButton starButton;
+ private ImageButton bookmarkButton;
private View mainLayout;
private ScheduledExecutorService executorService;
private DownloadFile currentPlaying;
@@ -168,6 +171,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe equalizerButton = (Button)rootView.findViewById(R.id.download_equalizer);
visualizerButton = (Button)rootView.findViewById(R.id.download_visualizer);
jukeboxButton = (Button)rootView.findViewById(R.id.download_jukebox);
+ bookmarkButton = (ImageButton) rootView.findViewById(R.id.download_bookmark);
LinearLayout visualizerViewLayout = (LinearLayout)rootView.findViewById(R.id.download_visualizer_view_layout);
toggleListButton =rootView.findViewById(R.id.download_toggle_list);
@@ -196,6 +200,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe equalizerButton.setOnTouchListener(touchListener);
visualizerButton.setOnTouchListener(touchListener);
jukeboxButton.setOnTouchListener(touchListener);
+ bookmarkButton.setOnTouchListener(touchListener);
emptyTextView.setOnTouchListener(touchListener);
albumArtImageView.setOnTouchListener(touchListener);
@@ -377,6 +382,31 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe }
});
+ bookmarkButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
+ if (currentDownload != null) {
+ MusicDirectory.Entry currentSong = currentDownload.getSong();
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.createBookmark(currentSong.getId(), getDownloadService().getPlayerPosition(), "", context, null);
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ Util.toast(context, R.string.download_save_bookmark);
+ setControlsVisible(true);
+ }
+ }.execute();
+ }
+ });
+
toggleListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -479,6 +509,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
+ DownloadService downloadService = getDownloadService();
if(Util.isOffline(context)) {
menuInflater.inflate(R.menu.nowplaying_offline, menu);
} else {
@@ -489,11 +520,11 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe menuInflater.inflate(R.menu.nowplaying_downloading, menu);
}
- if(getDownloadService() != null && getDownloadService().getSleepTimer()) {
+ if(downloadService != null && downloadService.getSleepTimer()) {
menu.findItem(R.id.menu_toggle_timer).setTitle(R.string.download_stop_timer);
}
}
- if(getDownloadService() != null && getDownloadService().getKeepScreenOn()) {
+ if(downloadService != null && downloadService.getKeepScreenOn()) {
menu.findItem(R.id.menu_screen_on_off).setTitle(R.string.download_menu_screen_off);
}
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java index b0969b29..f89e7f9c 100644 --- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java @@ -20,6 +20,7 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; import android.util.Log; +import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -29,12 +30,16 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.domain.Bookmark; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.TabBackgroundTask; +import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.BookmarkAdapter; import java.io.Serializable; import java.util.ArrayList; @@ -67,6 +72,7 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV bookmarkListView = (ListView)rootView.findViewById(R.id.fragment_list); bookmarkListView.setOnItemClickListener(this); + registerForContextMenu(bookmarkListView); emptyView = rootView.findViewById(R.id.fragment_list_empty); if(bookmarks == null) { @@ -91,6 +97,32 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV return false; } + + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + + MusicDirectory.Entry entry = bookmarks.get(info.position).getEntry(); + onCreateContextMenu(menu, view, menuInfo, entry); + if(!Util.isOffline(context)) { + menu.removeItem(R.id.song_menu_remove_playlist); + } + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + if(onContextItemSelected(menuItem, bookmarks.get(info.position).getEntry())) { + return true; + } + + return true; + } @Override protected void refresh(final boolean refresh) { @@ -128,6 +160,13 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + DownloadService downloadService = getDownloadService(); + if(downloadService == null) { + return; + } + Bookmark bookmark = (Bookmark) parent.getItemAtPosition(position); + downloadService.download(bookmark); + Util.startActivityWithoutTransition(context, DownloadActivity.class); } } diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 7e8c8c81..1a254c73 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -22,6 +22,7 @@ import java.util.List; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.audiofx.VisualizerController; +import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.domain.RemoteControlState; @@ -33,6 +34,7 @@ import github.daneren2005.dsub.domain.RepeatMode; */ public interface DownloadService { + void download(Bookmark bookmark); void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle); void downloadBackground(List<MusicDirectory.Entry> songs, boolean save); diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index d88b5262..e379291f 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -28,6 +28,7 @@ import static github.daneren2005.dsub.domain.PlayerState.STARTED; import static github.daneren2005.dsub.domain.PlayerState.STOPPED; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.audiofx.VisualizerController; +import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.domain.RemoteControlState; @@ -270,6 +271,17 @@ public class DownloadServiceImpl extends Service implements DownloadService { return binder; } + @Override + public synchronized void download(Bookmark bookmark) { + clear(); + DownloadFile downloadFile = new DownloadFile(this, bookmark.getEntry(), false); + downloadList.add(downloadFile); + revision++; + updateJukeboxPlaylist(); + play(0, true, bookmark.getPosition()); + lifecycleSupport.serializeDownloadQueue(); + } + @Override public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle) { setShufflePlayEnabled(false); @@ -666,8 +678,10 @@ public class DownloadServiceImpl extends Service implements DownloadService { public synchronized void play(int index) { play(index, true); } - - private synchronized void play(int index, boolean start) { + private synchronized void play(int index, boolean start) { + play(index, start, 0); + } + private synchronized void play(int index, boolean start, int position) { if (index < 0 || index >= size()) { reset(); setCurrentPlaying(null, false); @@ -683,7 +697,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { remoteController.changeTrack(index, downloadList.get(index)); setPlayerState(STARTED); } else { - bufferAndPlay(); + bufferAndPlay(position); } } if (remoteState == RemoteControlState.LOCAL) { @@ -1071,14 +1085,17 @@ public class DownloadServiceImpl extends Service implements DownloadService { remoteController.setVolume(up); } - private synchronized void bufferAndPlay() { + private synchronized void bufferAndPlay() { + bufferAndPlay(0); + } + private synchronized void bufferAndPlay(int position) { if(playerState != PREPARED) { reset(); - bufferTask = new BufferTask(currentPlaying, 0); + bufferTask = new BufferTask(currentPlaying, position); bufferTask.start(); } else { - doPlay(currentPlaying, 0, true); + doPlay(currentPlaying, position, true); } } |