[Android] Dismiss MRL dialog on media launch

Geoffrey Métais git at videolan.org
Mon Jul 17 17:20:32 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jul 17 17:19:58 2017 +0200| [8f94743c1d98619ced0b6dfff7c23a673e9fa26d] | committer: Geoffrey Métais

Dismiss MRL dialog on media launch

> https://code.videolan.org/videolan/vlc-android/commit/8f94743c1d98619ced0b6dfff7c23a673e9fa26d
---

 .../src/org/videolan/vlc/gui/network/MRLAdapter.java  | 15 +++++++++++----
 .../videolan/vlc/gui/network/MRLPanelFragment.java    | 19 ++++++++++++-------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java b/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java
index e270db15e..99264a200 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java
@@ -27,12 +27,16 @@ import android.view.ViewGroup;
 import android.widget.TextView;
 
 import org.videolan.medialibrary.media.HistoryItem;
+import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.R;
-import org.videolan.vlc.gui.helpers.UiTools;
-import org.videolan.vlc.media.MediaUtils;
 
 class MRLAdapter extends RecyclerView.Adapter<MRLAdapter.ViewHolder> {
     private HistoryItem[] mDataset;
+    private MediaPlayerController playerController;
+
+    interface MediaPlayerController {
+        void playMedia(MediaWrapper mw);
+    }
 
     public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
         TextView uriTv, titleTv;
@@ -46,11 +50,14 @@ class MRLAdapter extends RecyclerView.Adapter<MRLAdapter.ViewHolder> {
 
         @Override
         public void onClick(View v) {
-                UiTools.setKeyboardVisibility(itemView, false);
-                MediaUtils.openMedia(v.getContext(), mDataset[getLayoutPosition()].getMedia());
+            playerController.playMedia(mDataset[getLayoutPosition()].getMedia());
         }
     }
 
+    MRLAdapter(MediaPlayerController playerController) {
+        this.playerController = playerController;
+    }
+
     @Override
     public MRLAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                     int viewType) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
index 6ce4858cc..d9e0a4af7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
@@ -44,7 +44,7 @@ import org.videolan.vlc.gui.DialogActivity;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.media.MediaUtils;
 
-public class MRLPanelFragment extends DialogFragment implements View.OnKeyListener, TextView.OnEditorActionListener, View.OnClickListener {
+public class MRLPanelFragment extends DialogFragment implements View.OnKeyListener, TextView.OnEditorActionListener, View.OnClickListener, MRLAdapter.MediaPlayerController {
     private static final String TAG = "VLC/MrlPanelFragment";
     public static final String KEY_MRL = "mrl";
     private MRLAdapter mAdapter;
@@ -63,7 +63,7 @@ public class MRLPanelFragment extends DialogFragment implements View.OnKeyListen
         RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.mrl_list);
         recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
         recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
-        mAdapter = new MRLAdapter();
+        mAdapter = new MRLAdapter(this);
         recyclerView.setAdapter(mAdapter);
         v.findViewById(R.id.send).setOnClickListener(this);
         return v;
@@ -106,18 +106,23 @@ public class MRLPanelFragment extends DialogFragment implements View.OnKeyListen
 
     private boolean processUri() {
         if (mEditText.getEditText() != null && !TextUtils.isEmpty(mEditText.getEditText().getText())) {
-            UiTools.setKeyboardVisibility(mEditText, false);
             MediaWrapper mw = new MediaWrapper(Uri.parse(mEditText.getEditText().getText().toString().trim()));
-            mw.setType(MediaWrapper.TYPE_STREAM);
-            MediaUtils.openMedia(getActivity(), mw);
-            updateHistory();
-            getActivity().supportInvalidateOptionsMenu();
+            playMedia(mw);
             mEditText.getEditText().getText().clear();
             return true;
         }
         return false;
     }
 
+    public void playMedia(MediaWrapper mw) {
+        mw.setType(MediaWrapper.TYPE_STREAM);
+        MediaUtils.openMedia(getActivity(), mw);
+        updateHistory();
+        getActivity().supportInvalidateOptionsMenu();
+        UiTools.setKeyboardVisibility(mEditText, false);
+        dismiss();
+    }
+
     @Override
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
         return false;



More information about the Android mailing list