From 899af3ee1aa73ac4ec523e6dc95f3af54e6eacdf Mon Sep 17 00:00:00 2001 From: ibo <41344259+sneazy-ibo@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:07:38 +0200 Subject: [PATCH] feat: added clearhistory button (#416) --- .../java/ani/dantotsu/media/SearchAdapter.kt | 13 +++++++++- .../dantotsu/media/SearchHistoryAdapter.kt | 6 +++++ .../main/res/drawable/ic_round_history_24.xml | 10 +++++++ .../main/res/layout/item_search_header.xml | 26 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_round_history_24.xml diff --git a/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt b/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt index ecf3692c63..21f0b68380 100644 --- a/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt @@ -183,6 +183,12 @@ class SearchAdapter(private val activity: SearchActivity, private val type: Stri binding.searchByImage.setOnClickListener { activity.startActivity(Intent(activity, ImageSearchActivity::class.java)) } + binding.clearHistory.setOnClickListener { + it.startAnimation(fadeOutAnimation()) + it.visibility = View.GONE + searchHistoryAdapter.clearHistory() + } + updateClearHistoryVisibility() fun searchTitle() { activity.result.apply { search = @@ -300,11 +306,17 @@ class SearchAdapter(private val activity: SearchActivity, private val type: Stri } binding.searchResultLayout.visibility = View.VISIBLE + binding.clearHistory.visibility = View.GONE binding.searchHistoryList.visibility = View.GONE binding.searchByImage.visibility = View.GONE } } + private fun updateClearHistoryVisibility() { + binding.clearHistory.visibility = + if (searchHistoryAdapter.itemCount > 0) View.VISIBLE else View.GONE + } + private fun fadeInAnimation(): Animation { return AlphaAnimation(0f, 1f).apply { duration = 150 @@ -375,4 +387,3 @@ class SearchAdapter(private val activity: SearchActivity, private val type: Stri override fun getItemCount(): Int = chips.size } } - diff --git a/app/src/main/java/ani/dantotsu/media/SearchHistoryAdapter.kt b/app/src/main/java/ani/dantotsu/media/SearchHistoryAdapter.kt index f1519e2b62..4e2988e361 100644 --- a/app/src/main/java/ani/dantotsu/media/SearchHistoryAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/SearchHistoryAdapter.kt @@ -49,6 +49,12 @@ class SearchHistoryAdapter(private val type: String, private val searchClicked: PrefManager.setVal(historyType, searchHistory) } + fun clearHistory() { + searchHistory?.clear() + PrefManager.setVal(historyType, searchHistory) + submitList(searchHistory?.toList()) + } + override fun onCreateViewHolder( parent: ViewGroup, viewType: Int diff --git a/app/src/main/res/drawable/ic_round_history_24.xml b/app/src/main/res/drawable/ic_round_history_24.xml new file mode 100644 index 0000000000..1d5164d340 --- /dev/null +++ b/app/src/main/res/drawable/ic_round_history_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/item_search_header.xml b/app/src/main/res/layout/item_search_header.xml index dfd6083ca4..bd30343c5b 100644 --- a/app/src/main/res/layout/item_search_header.xml +++ b/app/src/main/res/layout/item_search_header.xml @@ -117,6 +117,32 @@ app:drawableTint="?attr/colorPrimary" /> + + + + + Install Add-on Add-on not found Image + Clear History Failed to install extension due to conflict READING WATCHING