clear history

This commit is contained in:
reduplicated 2022-11-05 01:27:35 +01:00
parent 9e67e856a0
commit 60a2f7c1c5
4 changed files with 69 additions and 1 deletions

View file

@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.ui.search package com.lagradost.cloudstream3.ui.search
import android.content.DialogInterface
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -10,6 +11,7 @@ import android.widget.AbsListView
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.ImageView import android.widget.ImageView
import android.widget.ListView import android.widget.ListView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -28,6 +30,7 @@ import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
import com.lagradost.cloudstream3.APIHolder.getApiSettings import com.lagradost.cloudstream3.APIHolder.getApiSettings
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.Resource
@ -343,7 +346,7 @@ class SearchFragment : Fragment() {
searchViewModel.updateHistory() searchViewModel.updateHistory()
} }
search_history_recycler?.isVisible = showHistory search_history_holder?.isVisible = showHistory
search_master_recycler?.isVisible = !showHistory && isAdvancedSearch search_master_recycler?.isVisible = !showHistory && isAdvancedSearch
search_autofit_results?.isVisible = !showHistory && !isAdvancedSearch search_autofit_results?.isVisible = !showHistory && !isAdvancedSearch
@ -352,7 +355,41 @@ class SearchFragment : Fragment() {
} }
}) })
search_clear_call_history?.setOnClickListener {
activity?.let { ctx ->
val builder: AlertDialog.Builder = AlertDialog.Builder(ctx)
val dialogClickListener =
DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_POSITIVE -> {
removeKeys(SEARCH_HISTORY_KEY)
searchViewModel.updateHistory()
}
DialogInterface.BUTTON_NEGATIVE -> {
}
}
}
try {
builder.setTitle(R.string.clear_history).setMessage(
ctx.getString(R.string.delete_message).format(
ctx.getString(R.string.history)
)
)
.setPositiveButton(R.string.sort_clear, dialogClickListener)
.setNegativeButton(R.string.cancel, dialogClickListener)
.show()
} catch (e: Exception) {
logError(e)
// ye you somehow fucked up formatting did you?
}
}
}
observe(searchViewModel.currentHistory) { list -> observe(searchViewModel.currentHistory) { list ->
search_clear_call_history?.isVisible = list.isNotEmpty()
(search_history_recycler.adapter as? SearchHistoryAdaptor?)?.updateList(list) (search_history_recycler.adapter as? SearchHistoryAdaptor?)?.updateList(list)
} }

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<vector android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/white"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M30,36.5V33.5H37.25V36.5ZM30,18.1V15.1H44V18.1ZM30,27.3V24.3H41.75V27.3ZM6.25,14.25H4V11.25H12.5V9H19.25V11.25H27.75V14.25H25.5V35Q25.5,36.2 24.6,37.1Q23.7,38 22.5,38H9.25Q8.05,38 7.15,37.1Q6.25,36.2 6.25,35ZM9.25,14.25V35Q9.25,35 9.25,35Q9.25,35 9.25,35H22.5Q22.5,35 22.5,35Q22.5,35 22.5,35V14.25ZM9.25,14.25V35Q9.25,35 9.25,35Q9.25,35 9.25,35Q9.25,35 9.25,35Q9.25,35 9.25,35Z"/>
</vector>

View file

@ -112,6 +112,11 @@
android:nextFocusLeft="@id/nav_rail_view" android:nextFocusLeft="@id/nav_rail_view"
android:visibility="gone" android:visibility="gone"
tools:listitem="@layout/homepage_parent" /> tools:listitem="@layout/homepage_parent" />
<FrameLayout
android:id="@+id/search_history_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_history_recycler" android:id="@+id/search_history_recycler"
@ -122,5 +127,19 @@
android:descendantFocusability="afterDescendants" android:descendantFocusability="afterDescendants"
android:nextFocusLeft="@id/nav_rail_view" android:nextFocusLeft="@id/nav_rail_view"
android:visibility="visible" android:visibility="visible"
android:paddingBottom="50dp"
tools:listitem="@layout/search_history_item" /> tools:listitem="@layout/search_history_item" />
<com.google.android.material.button.MaterialButton
android:id="@+id/search_clear_call_history"
style="@style/BlackButton"
android:layout_gravity="bottom"
android:padding="0dp"
app:cornerRadius="0dp"
android:layout_margin="0dp"
android:text="@string/clear_history"
app:icon="@drawable/delete_all"
android:layout_width="match_parent"
android:layout_height="50dp" />
</FrameLayout>
</LinearLayout> </LinearLayout>

View file

@ -647,4 +647,7 @@
<string name="skip_type_mixed_op">Mixed opening</string> <string name="skip_type_mixed_op">Mixed opening</string>
<string name="skip_type_creddits">Credits</string> <string name="skip_type_creddits">Credits</string>
<string name="skip_type_intro">Intro</string> <string name="skip_type_intro">Intro</string>
<string name="clear_history">Clear history</string>
<string name="history">History</string>
</resources> </resources>