Skip to content

Commit

Permalink
feat: added clearhistory button (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
sneazy-ibo authored Jun 14, 2024
1 parent 124c8f5 commit 899af3e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/src/main/java/ani/dantotsu/media/SearchAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -375,4 +387,3 @@ class SearchAdapter(private val activity: SearchActivity, private val type: Stri
override fun getItemCount(): Int = chips.size
}
}

6 changes: 6 additions & 0 deletions app/src/main/java/ani/dantotsu/media/SearchHistoryAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_round_history_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="@android:color/white"
android:pathData="M13.26,3C8.17,2.86 4,6.95 4,12L2.21,12c-0.45,0 -0.67,0.54 -0.35,0.85l2.79,2.8c0.2,0.2 0.51,0.2 0.71,0l2.79,-2.8c0.31,-0.31 0.09,-0.85 -0.36,-0.85L6,12c0,-3.9 3.18,-7.05 7.1,-7 3.72,0.05 6.85,3.18 6.9,6.9 0.05,3.91 -3.1,7.1 -7,7.1 -1.61,0 -3.1,-0.55 -4.28,-1.48 -0.4,-0.31 -0.96,-0.28 -1.32,0.08 -0.42,0.42 -0.39,1.13 0.08,1.49C9,20.29 10.91,21 13,21c5.05,0 9.14,-4.17 9,-9.26 -0.13,-4.69 -4.05,-8.61 -8.74,-8.74zM12.75,8c-0.41,0 -0.75,0.34 -0.75,0.75v3.68c0,0.35 0.19,0.68 0.49,0.86l3.12,1.85c0.36,0.21 0.82,0.09 1.03,-0.26 0.21,-0.36 0.09,-0.82 -0.26,-1.03l-2.88,-1.71v-3.4c0,-0.4 -0.34,-0.74 -0.75,-0.74z"/>
</vector>
26 changes: 26 additions & 0 deletions app/src/main/res/layout/item_search_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@
app:drawableTint="?attr/colorPrimary" />
</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/clearHistory"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center"
android:padding="8dp"
app:boxStrokeColor="@color/text_input_layout_stroke_color"
app:cardBackgroundColor="@color/nav_bg"
app:cardCornerRadius="16dp"
app:contentPadding="4dp"
app:contentPaddingLeft="8dp"
app:contentPaddingRight="8dp"
tools:ignore="ContentDescription,TextContrastCheck">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="4dp"
android:fontFamily="@font/poppins_bold"
android:text="@string/clear_history"
android:textColor="?attr/colorPrimary"
app:drawableStartCompat="@drawable/ic_round_history_24"
app:drawableTint="?attr/colorPrimary" />
</androidx.cardview.widget.CardView>

<ani.dantotsu.FadingEdgeRecyclerView
android:id="@+id/searchChipRecycler"
android:layout_width="0dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
<string name="install_addon">Install Add-on</string>
<string name="download_addon_not_found">Add-on not found</string>
<string name="image">Image</string>
<string name="clear_history">Clear History</string>
<string name="failed_ext_install_conflict">Failed to install extension due to conflict</string>
<string name="reading">READING</string>
<string name="watching">WATCHING</string>
Expand Down

0 comments on commit 899af3e

Please sign in to comment.