[Android] Add an indicator when data is pasted from the clipboard

Nicolas Pomepuy git at videolan.org
Tue Nov 2 12:31:14 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Oct 20 12:55:47 2021 +0200| [f43f9d789d059475b1b1fd9f95ce0539f1cb4445] | committer: Nicolas Pomepuy

Add an indicator when data is pasted from the clipboard

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

 .../resources/src/main/res/values/strings.xml       |  1 +
 .../vlc-android/res/layout-v21/mrl_panel.xml        | 12 ++++++++++++
 application/vlc-android/res/layout/mrl_panel.xml    | 15 ++++++++++++++-
 .../videolan/vlc/gui/network/MRLPanelFragment.kt    | 21 ++++++++++++---------
 4 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index e2da8afd4..a53f14e79 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -441,6 +441,7 @@
     <string name="log_service_text">Open the log console</string>
     <string name="copy_to_clipboard">Copy to clipboard</string>
     <string name="copied_to_clipboard">Copied log to clipboard.</string>
+    <string name="copied_from_clipboard">Address pasted from your clipboard</string>
     <string name="dump_logcat">Dump logcat log</string>
     <string name="dump_logcat_success">Logcat successfully dumped to %1$s!</string>
     <string name="dump_logcat_failure">Failed to dump logcat.</string>
diff --git a/application/vlc-android/res/layout-v21/mrl_panel.xml b/application/vlc-android/res/layout-v21/mrl_panel.xml
index 3442e61e9..180a05f2d 100644
--- a/application/vlc-android/res/layout-v21/mrl_panel.xml
+++ b/application/vlc-android/res/layout-v21/mrl_panel.xml
@@ -58,6 +58,18 @@
                             android:inputType="textUri"
                             android:text="@={viewmodel.observableSearchText}" />
                 </com.google.android.material.textfield.TextInputLayout>
+                <TextView
+                        android:id="@+id/clipboard_indicator"
+                        android:layout_width="0dp"
+                        android:layout_height="wrap_content"
+                        android:layout_marginStart="8dp"
+                        android:layout_marginEnd="8dp"
+                        android:text="@string/copied_from_clipboard"
+                        android:visibility="gone"
+                        app:layout_constraintEnd_toEndOf="parent"
+                        app:layout_constraintStart_toStartOf="parent"
+                        app:layout_constraintTop_toBottomOf="@+id/mrl_edit"
+                        tools:visibility="visible" />
 
                 <ImageView
                         android:id="@+id/play"
diff --git a/application/vlc-android/res/layout/mrl_panel.xml b/application/vlc-android/res/layout/mrl_panel.xml
index a094d0aef..52a780316 100644
--- a/application/vlc-android/res/layout/mrl_panel.xml
+++ b/application/vlc-android/res/layout/mrl_panel.xml
@@ -36,6 +36,7 @@
 
                 <com.google.android.material.textfield.TextInputLayout
                         android:id="@+id/mrl_edit"
+                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                         android:layout_width="0dp"
                         android:layout_height="wrap_content"
                         android:layout_marginStart="8dp"
@@ -46,7 +47,6 @@
                         app:layout_constraintEnd_toStartOf="@+id/play"
                         app:layout_constraintStart_toStartOf="parent"
                         app:layout_constraintTop_toTopOf="parent"
-                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                         tools:ignore="RtlSymmetry">
 
                     <EditText
@@ -59,6 +59,19 @@
                             android:text="@={viewmodel.observableSearchText}" />
                 </com.google.android.material.textfield.TextInputLayout>
 
+                <TextView
+                        android:id="@+id/clipboard_indicator"
+                        android:layout_width="0dp"
+                        android:layout_height="wrap_content"
+                        android:layout_marginStart="8dp"
+                        android:layout_marginEnd="8dp"
+                        android:text="@string/copied_from_clipboard"
+                        android:visibility="gone"
+                        app:layout_constraintEnd_toEndOf="parent"
+                        app:layout_constraintStart_toStartOf="parent"
+                        app:layout_constraintTop_toBottomOf="@+id/mrl_edit"
+                        tools:visibility="visible" />
+
                 <ImageView
                         android:id="@+id/play"
                         android:layout_width="wrap_content"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
index 08c6a727d..f03a868ee 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
@@ -44,6 +44,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
 import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.tools.Settings
 import org.videolan.tools.isValidUrl
+import org.videolan.tools.setVisible
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.MrlPanelBinding
 import org.videolan.vlc.gui.ContentActivity
@@ -60,8 +61,8 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
         View.OnClickListener, BrowserFragmentInterface,
         IStreamsFragmentDelegate by StreamsFragmentDelegate(), KeyboardListener {
 
+    private lateinit var binding: MrlPanelBinding
     private lateinit var adapter: MRLAdapter
-    private lateinit var editText: com.google.android.material.textfield.TextInputLayout
     private lateinit var viewModel: StreamsModel
 
     override fun onCreate(savedInstanceState: Bundle?) {
@@ -71,12 +72,11 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
     }
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
-        val binding = MrlPanelBinding.inflate(inflater, container, false)
+        binding = MrlPanelBinding.inflate(inflater, container, false)
         binding.viewmodel = viewModel
-        editText = binding.mrlEdit
-        editText.editText?.setOnKeyListener(this)
-        editText.editText?.setOnEditorActionListener(this)
-        editText.editText?.requestFocus()
+        binding.mrlEdit.editText?.setOnKeyListener(this)
+        binding.mrlEdit.editText?.setOnEditorActionListener(this)
+        binding.mrlEdit.editText?.requestFocus()
 
         adapter = MRLAdapter(getlistEventActor())
         val recyclerView = binding.mrlList
@@ -114,11 +114,14 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
     override fun onResume() {
         super.onResume()
         //Needed after privacy changes made in Android 10
-        editText.doOnLayout {
+        binding.mrlEdit.doOnLayout {
             try {
                 val clipBoardManager = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
                 val text = clipBoardManager?.primaryClip?.getItemAt(0)?.text?.toString()
-                if (text.isValidUrl()) viewModel.observableSearchText.set(text)
+                if (text.isValidUrl()) {
+                    viewModel.observableSearchText.set(text)
+                    binding.clipboardIndicator.setVisible()
+                }
             } catch (e: Exception) { }
         }
     }
@@ -157,6 +160,6 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
     }
 
     override fun hideKeyboard() {
-        UiTools.setKeyboardVisibility(editText, false)
+        UiTools.setKeyboardVisibility(binding.mrlEdit, false)
     }
 }



More information about the Android mailing list