From fcd10bb0f0a2c5d28b6d984cf2fa2c0a4b29b249 Mon Sep 17 00:00:00 2001 From: archroid Date: Tue, 10 May 2022 20:53:59 +0430 Subject: [PATCH] Added search history icon; Fixed a nullpointer crash --- .../java/com/github/libretube/SearchFragment.kt | 11 ++++++++--- app/src/main/res/drawable/ic_history.xml | 11 +++++++++++ app/src/main/res/layout/searchhistory_row.xml | 14 ++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/ic_history.xml diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 87d88ecde..ec77960fe 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -213,9 +213,14 @@ class SearchFragment : Fragment() { } private fun getHistory(): List { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) - val set: Set = sharedPreferences.getStringSet("search_history", null)!! - return set.toList() + try { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + val set: Set = sharedPreferences.getStringSet("search_history", HashSet())!! + return set.toList() + } catch (e: Exception) { + return emptyList() + } + } } diff --git a/app/src/main/res/drawable/ic_history.xml b/app/src/main/res/drawable/ic_history.xml new file mode 100644 index 000000000..61ded0dec --- /dev/null +++ b/app/src/main/res/drawable/ic_history.xml @@ -0,0 +1,11 @@ + + + + diff --git a/app/src/main/res/layout/searchhistory_row.xml b/app/src/main/res/layout/searchhistory_row.xml index 8c6b31e6a..e3282ec58 100644 --- a/app/src/main/res/layout/searchhistory_row.xml +++ b/app/src/main/res/layout/searchhistory_row.xml @@ -7,6 +7,16 @@ android:layout_marginBottom="16dp" android:background="?android:attr/selectableItemBackground"> + @@ -24,7 +34,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" - android:padding="8dp" + android:padding="5dp" android:src="@drawable/ic_close2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"