[Android] TV: Message for no result in search

Geoffrey Métais git at videolan.org
Thu Dec 6 15:21:08 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec  6 13:33:56 2018 +0100| [bb02548990ec53afaca3de9ac2c6f827c36c2047] | committer: Geoffrey Métais

TV: Message for no result in search

See #468

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

 vlc-android/res/layout/tv_search.xml                | 21 ++++++++++++++++-----
 .../src/org/videolan/vlc/gui/tv/SearchActivity.java | 11 ++++++++++-
 .../src/org/videolan/vlc/gui/tv/SearchFragment.kt   | 12 +++++++++---
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/vlc-android/res/layout/tv_search.xml b/vlc-android/res/layout/tv_search.xml
index 2b5b3e9c1..532c707f0 100644
--- a/vlc-android/res/layout/tv_search.xml
+++ b/vlc-android/res/layout/tv_search.xml
@@ -1,6 +1,17 @@
 <?xml version="1.0" encoding="utf-8"?>
-<fragment xmlns:android="http://schemas.android.com/apk/res/android"
-          android:name="org.videolan.vlc.gui.tv.SearchFragment"
-          android:id="@+id/search_fragment"
-          android:layout_width="match_parent"
-          android:layout_height="match_parent" />
\ No newline at end of file
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+    <fragment
+        android:id="@+id/search_fragment"
+        android:name="org.videolan.vlc.gui.tv.SearchFragment"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
+    <TextView
+        android:id="@+id/empty"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:gravity="center"
+        android:text="@string/no_result"
+        android:visibility="gone"/>
+</FrameLayout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
index 1ddace811..2a4db130f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
@@ -23,15 +23,19 @@ package org.videolan.vlc.gui.tv;
 import android.annotation.TargetApi;
 import android.os.Build;
 import android.os.Bundle;
-import androidx.fragment.app.FragmentActivity;
+import android.view.View;
+import android.widget.TextView;
 
 import org.videolan.vlc.R;
 
+import androidx.fragment.app.FragmentActivity;
+
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 public class SearchActivity extends FragmentActivity {
     private static final String TAG = "VLC/SearchActivity";
 
     private SearchFragment mFragment;
+    private TextView mEmptyView;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -39,6 +43,11 @@ public class SearchActivity extends FragmentActivity {
         setContentView(R.layout.tv_search);
         mFragment = (SearchFragment) getSupportFragmentManager()
                 .findFragmentById(R.id.search_fragment);
+        mEmptyView = findViewById(R.id.empty);
+    }
+
+    public void updateEmptyView(boolean empty) {
+        mEmptyView.setVisibility(empty ? View.VISIBLE : View.GONE);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
index 1af36e551..61ff8fcde 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
@@ -26,9 +26,9 @@ import android.app.SearchManager
 import android.content.Intent
 import android.os.Build
 import android.os.Bundle
+import android.text.TextUtils
 import androidx.leanback.app.SearchSupportFragment
 import androidx.leanback.widget.*
-import android.text.TextUtils
 import kotlinx.coroutines.launch
 import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.media.*
@@ -76,8 +76,10 @@ class SearchFragment : SearchSupportFragment(), SearchSupportFragment.SearchResu
     }
 
     private fun loadRows(query: String?) = coroutineScope.launch {
-        val searchAggregate = context?.getFromMl { search(query) } ?: return at launch
-        val empty = searchAggregate.isEmpty
+        val searchAggregate = context?.getFromMl { search(query) }
+        val empty = searchAggregate == null || searchAggregate.isEmpty
+        updateEmtyView(empty)
+        if (searchAggregate == null || empty) return at launch
         val mediaEmpty = empty || (Tools.isArrayEmpty(searchAggregate.tracks) && Tools.isArrayEmpty(searchAggregate.videos))
         val cp = CardPresenter(requireActivity())
         val videoAdapter = ArrayObjectAdapter(cp)
@@ -110,6 +112,10 @@ class SearchFragment : SearchSupportFragment(), SearchSupportFragment.SearchResu
             rowsAdapter.add(ListRow(HeaderItem(0, resources.getString(R.string.genres)), genresAdapter))
     }
 
+    private fun updateEmtyView(empty: Boolean) {
+        (activity as? SearchActivity)?.updateEmptyView(empty)
+    }
+
     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
         if (requestCode == REQUEST_SPEECH && resultCode == Activity.RESULT_OK) setSearchQuery(data, true)
     }



More information about the Android mailing list