[Android] Toggle favorite with play/pause or Y button
Geoffrey Métais
git at videolan.org
Mon Feb 9 11:30:50 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 5 15:46:11 2015 +0100| [2c26403bc2e6407244b26868a020da9ffad22a73] | committer: Geoffrey Métais
Toggle favorite with play/pause or Y button
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2c26403bc2e6407244b26868a020da9ffad22a73
---
.../vlc/gui/tv/browser/BrowserGridFragment.java | 24 +++++++++--------
.../vlc/gui/tv/browser/VerticalGridActivity.java | 27 ++++++++++++--------
2 files changed, 30 insertions(+), 21 deletions(-)
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 eef8632..932f12e 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
@@ -24,6 +24,7 @@ package org.videolan.vlc.gui.tv.browser;
import android.os.Bundle;
import android.view.View;
+import android.widget.Toast;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
@@ -43,13 +44,6 @@ public class BrowserGridFragment extends GridFragment implements MediaBrowser.Ev
public String mMrl;
ArrayList<MediaWrapper> mMediaList = null;
- private View.OnClickListener mSearchClickedListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- toggleFavorite(mMrl);
- }
- };
-
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null){
@@ -75,8 +69,6 @@ public class BrowserGridFragment extends GridFragment implements MediaBrowser.Ev
}
}
setOnItemViewClickedListener(mClickListener);
- if (mMrl != null)
- setOnSearchClickedListener(mSearchClickedListener);
}
}
@@ -123,11 +115,21 @@ public class BrowserGridFragment extends GridFragment implements MediaBrowser.Ev
mAdapter.notifyArrayItemRangeChanged(0, mMediaList.size());
}
+ public void toggleFavorite() {
+ if (mMrl != null)
+ toggleFavorite(mMrl);
+ }
+
public void toggleFavorite(String mrl) {
MediaDatabase db = MediaDatabase.getInstance();
- if (db.networkFavExists(mrl))
+ String text;
+ if (db.networkFavExists(mrl)) {
db.deleteNetworkFav(mrl);
- else
+ text = "Removed from favorites";
+ } else {
db.addNetworkFavItem(mrl);
+ text = "Saved to favorites";
+ }
+ Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
}
}
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
index 7407b4f..798581b 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
@@ -19,16 +19,16 @@
*****************************************************************************/
package org.videolan.vlc.gui.tv.browser;
-import org.videolan.vlc.R;
-import org.videolan.vlc.gui.network.NetworkFragment;
-import org.videolan.vlc.gui.tv.MainTvActivity;
-
import android.app.Activity;
-import android.app.FragmentTransaction;
import android.os.Bundle;
+import android.view.KeyEvent;
+
+import org.videolan.vlc.R;
+import org.videolan.vlc.gui.tv.MainTvActivity;
public class VerticalGridActivity extends Activity {
+ GridFragment mFragment;
@Override
public void onCreate(Bundle savedInstanceState)
{
@@ -36,19 +36,26 @@ public class VerticalGridActivity extends Activity {
setContentView(R.layout.tv_vertical_grid);
getWindow().setBackgroundDrawableResource(R.drawable.background);
long type = getIntent().getLongExtra(MainTvActivity.BROWSER_TYPE, -1);
- GridFragment fragment;
if (type == MainTvActivity.HEADER_VIDEO)
- fragment = new VideoGridFragment();
+ mFragment = new VideoGridFragment();
else if (type == MainTvActivity.HEADER_CATEGORIES)
- fragment = new MusicFragment();
+ mFragment = new MusicFragment();
else if (type == MainTvActivity.HEADER_NETWORK)
- fragment = new BrowserGridFragment();
+ mFragment = new BrowserGridFragment();
else {
finish();
return;
}
getFragmentManager().beginTransaction()
- .add(R.id.tv_fragment_placeholder, fragment)
+ .add(R.id.tv_fragment_placeholder, mFragment)
.commit();
}
+
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (mFragment instanceof BrowserGridFragment && (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_BUTTON_Y)) {
+ ((BrowserGridFragment)mFragment).toggleFavorite();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
}
More information about the Android
mailing list