feat: list searching
This commit is contained in:
parent
e1a865c973
commit
988e4def64
6 changed files with 117 additions and 12 deletions
|
@ -69,6 +69,7 @@ class CalendarActivity : AppCompatActivity() {
|
|||
binding.listTitle.setText(R.string.release_calendar)
|
||||
binding.listSort.visibility = View.GONE
|
||||
binding.random.visibility = View.GONE
|
||||
binding.search.visibility = View.GONE
|
||||
binding.listTabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||
this@CalendarActivity.selectedTabIdx = tab?.position ?: 1
|
||||
|
|
|
@ -302,7 +302,7 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
|||
} catch (e: Exception) {
|
||||
Injekt.get<CrashlyticsInterface>().logException(e)
|
||||
Logger.log(e)
|
||||
toast("Error starting video")
|
||||
toast("Error starting video: ${e.message}")
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,14 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import ani.dantotsu.R
|
||||
|
@ -26,6 +29,7 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
class ListActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityListBinding
|
||||
private val scope = lifecycleScope
|
||||
|
@ -177,5 +181,28 @@ class ListActivity : AppCompatActivity() {
|
|||
supportFragmentManager.findFragmentByTag("f" + currentTab?.position.toString()) as? ListFragment
|
||||
currentFragment?.randomOptionClick()
|
||||
}
|
||||
|
||||
binding.search.setOnClickListener {
|
||||
toggleSearchView(binding.searchView.isVisible)
|
||||
if (!binding.searchView.isVisible) {
|
||||
model.unfilterLists()
|
||||
}
|
||||
}
|
||||
|
||||
binding.searchViewText.addTextChangedListener {
|
||||
model.searchLists(binding.searchViewText.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleSearchView(isVisible: Boolean) {
|
||||
if (isVisible) {
|
||||
binding.searchView.visibility = View.GONE
|
||||
binding.searchViewText.text.clear()
|
||||
} else {
|
||||
binding.searchView.visibility = View.VISIBLE
|
||||
binding.searchViewText.requestFocus()
|
||||
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.showSoftInput(binding.searchViewText, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,4 +38,30 @@ class ListViewModel : ViewModel() {
|
|||
lists.postValue(filteredLists)
|
||||
}
|
||||
|
||||
fun searchLists(search: String) {
|
||||
if (search.isEmpty()) {
|
||||
lists.postValue(unfilteredLists.value)
|
||||
return
|
||||
}
|
||||
val currentLists = unfilteredLists.value ?: return
|
||||
val filteredLists = currentLists.mapValues { entry ->
|
||||
entry.value.filter { media ->
|
||||
media.name?.contains(
|
||||
search,
|
||||
ignoreCase = true
|
||||
) == true || media.synonyms.any { it.contains(search, ignoreCase = true) } ||
|
||||
media.nameRomaji.contains(
|
||||
search,
|
||||
ignoreCase = true
|
||||
)
|
||||
} as ArrayList<Media>
|
||||
}.toMutableMap()
|
||||
|
||||
lists.postValue(filteredLists)
|
||||
}
|
||||
|
||||
fun unfilterLists() {
|
||||
lists.postValue(unfilteredLists.value)
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue