[Android] Fix Favorites management
Geoffrey Métais
git at videolan.org
Fri Mar 27 16:43:47 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 27 16:41:40 2015 +0100| [af1f9e8eec1dd07184b8119463dc1ca78081af0d] | committer: Geoffrey Métais
Fix Favorites management
- Fix favs and folders not recognized as TYPE_DIR
- Update add/delete fav option on click
- Use strings resources instead of hardcoded values
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=af1f9e8eec1dd07184b8119463dc1ca78081af0d
---
.../org/videolan/vlc/gui/tv/MainTvActivity.java | 1 +
.../vlc/gui/tv/MediaItemDetailsFragment.java | 31 +++++++++++++-------
.../vlc/gui/tv/browser/BrowserGridFragment.java | 7 +++--
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index eafc909..b0b286a 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -207,6 +207,7 @@ public class MainTvActivity extends Activity implements IVideoBrowser, OnItemVie
Intent intent = new Intent(this,
DetailsActivity.class);
// pass the item information
+ intent.putExtra("media", (MediaWrapper) mSelectedItem);
intent.putExtra("item", new MediaItemDetails(media.getTitle(), media.getArtist(), media.getAlbum(), media.getLocation()));
startActivity(intent);
return true;
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
index c8cf459..3ed13f9 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
@@ -79,13 +79,21 @@ public class MediaItemDetailsFragment extends DetailsFragment implements AudioSe
private void buildDetails() {
Bundle extras = getActivity().getIntent().getExtras();
mMedia = extras.getParcelable("item");
+ boolean hasMedia = extras.containsKey("media");
ClassPresenterSelector selector = new ClassPresenterSelector();
- final MediaWrapper media = new MediaWrapper(mMedia.getLocation());
- media.setTitle(mMedia.getTitle());
+ final MediaWrapper media = hasMedia ? (MediaWrapper) extras.getParcelable("media") : new MediaWrapper(mMedia.getLocation());
+ if (!hasMedia){
+ media.setTitle(mMedia.getTitle());
+ }
// Attach your media item details presenter to the row presenter:
DetailsOverviewRowPresenter rowPresenter =
new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
+ Resources res = getActivity().getResources();
+ final DetailsOverviewRow detailsOverview = new DetailsOverviewRow(mMedia);
+ final Action actionAdd = new Action(ID_FAVORITE_ADD, getString(R.string.favorites_add));
+ final Action actionDelete = new Action(ID_FAVORITE_DELETE, getString(R.string.favorites_remove));
+
rowPresenter.setBackgroundColor(getResources().getColor(R.color.orange500));
rowPresenter.setOnActionClickedListener(new OnActionClickedListener() {
@@ -104,11 +112,17 @@ public class MediaItemDetailsFragment extends DetailsFragment implements AudioSe
break;
case ID_FAVORITE_ADD:
mDb.addNetworkFavItem(mMedia.getLocation(), mMedia.getTitle());
- Toast.makeText(getActivity(), "Saved to favorites", Toast.LENGTH_SHORT).show();
+ detailsOverview.removeAction(actionAdd);
+ detailsOverview.addAction(actionDelete);
+ mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
+ Toast.makeText(getActivity(), R.string.favorite_added, Toast.LENGTH_SHORT).show();
break;
case ID_FAVORITE_DELETE:
- mDb.deleteNetworkFav(mMedia.getLocation());
- Toast.makeText(getActivity(), "Removed from favorites", Toast.LENGTH_SHORT).show();
+ mDb.deleteNetworkFav(mMedia.getLocation());
+ detailsOverview.removeAction(actionDelete);
+ detailsOverview.addAction(actionAdd);
+ mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
+ Toast.makeText(getActivity(), R.string.favorite_removed, Toast.LENGTH_SHORT).show();
break;
case ID_BROWSE:
TvUtil.openMedia(getActivity(), media, null);
@@ -120,18 +134,15 @@ public class MediaItemDetailsFragment extends DetailsFragment implements AudioSe
new ListRowPresenter());
mRowsAdapter = new ArrayObjectAdapter(selector);
- Resources res = getActivity().getResources();
- DetailsOverviewRow detailsOverview = new DetailsOverviewRow(mMedia);
-
if (media.getType() == MediaWrapper.TYPE_DIR) {
mDb = MediaDatabase.getInstance();
detailsOverview.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_network_big));
detailsOverview.setImageScaleUpAllowed(true);
detailsOverview.addAction(new Action(ID_BROWSE, "Browse folder"));
if (mDb.networkFavExists(mMedia.getLocation()))
- detailsOverview.addAction(new Action(ID_FAVORITE_DELETE, "Remove from favorites"));
+ detailsOverview.addAction(actionDelete);
else
- detailsOverview.addAction(new Action(ID_FAVORITE_ADD, "Add to favorites"));
+ detailsOverview.addAction(actionAdd);
} else {
// Add images and action buttons to the details view
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java
index 11871ff..802bb13 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java
@@ -30,7 +30,6 @@ import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
-import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.util.MediaBrowser;
import org.videolan.vlc.MediaWrapper;
@@ -82,7 +81,10 @@ public class BrowserGridFragment extends GridFragment implements MediaBrowser.Ev
}
@Override
public void onMediaAdded(int index, Media media) {
- mMediaList.add(new MediaWrapper(media));
+ MediaWrapper mw = new MediaWrapper(media);
+ int type = mw.getType();
+ if (type == MediaWrapper.TYPE_AUDIO || type == MediaWrapper.TYPE_VIDEO || type == MediaWrapper.TYPE_DIR)
+ mMediaList.add(mw);
if (mMrl == null) { // we are at root level
mAdapter.clear();
@@ -125,6 +127,7 @@ public class BrowserGridFragment extends GridFragment implements MediaBrowser.Ev
Intent intent = new Intent(getActivity(),
DetailsActivity.class);
// pass the item information
+ intent.putExtra("media", mItemSelected);
intent.putExtra("item", (Parcelable) new MediaItemDetails(mItemSelected.getTitle(), mItemSelected.getArtist(), mItemSelected.getAlbum(), mItemSelected.getLocation()));
startActivity(intent);
}
More information about the Android
mailing list