diff options
author | daneren2005 <daneren2005@gmail.com> | 2013-11-13 16:15:11 -0800 |
---|---|---|
committer | daneren2005 <daneren2005@gmail.com> | 2013-11-13 16:15:11 -0800 |
commit | 15ddacc196542228de9fc2566e2b591b883b2486 (patch) | |
tree | 34347a90a147d3d80665e7d084906131d1dbe145 /src/github/daneren2005 | |
parent | 70d1c53869765f07c54feabea62a13fc7e316132 (diff) | |
download | dsub-15ddacc196542228de9fc2566e2b591b883b2486.tar.gz dsub-15ddacc196542228de9fc2566e2b591b883b2486.tar.bz2 dsub-15ddacc196542228de9fc2566e2b591b883b2486.zip |
Added bookmark details/delete support
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r-- | src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java | 72 |
1 files changed, 63 insertions, 9 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java index f89e7f9c..97e3c2c8 100644 --- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java @@ -42,6 +42,8 @@ import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.BookmarkAdapter; import java.io.Serializable; +import java.text.Format; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; @@ -50,6 +52,7 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV private ListView bookmarkListView; private View emptyView; private List<Bookmark> bookmarks; + private BookmarkAdapter bookmarkAdapter; @Override public void onCreate(Bundle bundle) { @@ -101,13 +104,8 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV @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); - } + MenuInflater inflater = context.getMenuInflater(); + inflater.inflate(R.menu.select_bookmark_context, menu); } @Override @@ -117,7 +115,18 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV } AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - if(onContextItemSelected(menuItem, bookmarks.get(info.position).getEntry())) { + Bookmark bookmark = bookmarks.get(info.position); + + switch(menuItem.getItemId()) { + case R.bookmark_menu_info: + displayBookmarkInfo(bookmark); + break; + case R.bookmark_menu_delete: + deleteBookmark(bookmark); + break; + } + + if(onContextItemSelected(menuItem, bookmark.getEntry())) { return true; } @@ -150,7 +159,7 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV emptyView.setVisibility(result == null || result.isEmpty() ? View.VISIBLE : View.GONE); if (result != null) { - bookmarkListView.setAdapter(new BookmarkAdapter(context, result)); + bookmarkListView.setAdapter(bookmarkAdapter = new BookmarkAdapter(context, result)); bookmarkListView.setVisibility(View.VISIBLE); } } @@ -169,4 +178,49 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV downloadService.download(bookmark); Util.startActivityWithoutTransition(context, DownloadActivity.class); } + + private void displayBookmarkInfo(final Bookmark bookmark) { + Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + String msg = context.getResources().getString(R.string.bookmark_details, + song.getTitle(), Util.formatDuration(bookmark.getPosition), + formatter.format(bookmark.getCreated()), formatter.format(bookmark.getChanged()), bookmark.getComment()); + + Util.info(context, R.string.bookmark_details_title, msg); + } + private void deleteBookmark(final Bookmark bookmark) { + final MusicDirectory.Entry entry = bookmark.getEntry(); + Util.confirmDialog(context, R.string.bookmark_delete_title, entry.getTitle(), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new LoadingTask<Void>(context, false) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.deleteBookmark(entry.getId(), context, null); + return null; + } + + @Override + protected void done(Void result) { + bookmarkAdapter.remove(bookmark); + bookmarkAdapter.notifyDataSetChanged(); + Util.toast(context, context.getResources().getString(R.string.bookmark_deleted, entry.getTitle())); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.bookmark_deleted_error, entry.getTitle()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + }); + } } |