diff --git a/app/src/main/java/ani/dantotsu/media/CalendarActivity.kt b/app/src/main/java/ani/dantotsu/media/CalendarActivity.kt index e91936aafb..66cec7e40f 100644 --- a/app/src/main/java/ani/dantotsu/media/CalendarActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/CalendarActivity.kt @@ -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 diff --git a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt index a7bd82490d..24134f91d9 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt @@ -302,7 +302,7 @@ class SelectorDialogFragment : BottomSheetDialogFragment() { } catch (e: Exception) { Injekt.get().logException(e) Logger.log(e) - toast("Error starting video") + toast("Error starting video: ${e.message}") dismiss() } } diff --git a/app/src/main/java/ani/dantotsu/media/user/ListActivity.kt b/app/src/main/java/ani/dantotsu/media/user/ListActivity.kt index e511e487bb..994a0c789f 100644 --- a/app/src/main/java/ani/dantotsu/media/user/ListActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/user/ListActivity.kt @@ -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) + } } } diff --git a/app/src/main/java/ani/dantotsu/media/user/ListViewModel.kt b/app/src/main/java/ani/dantotsu/media/user/ListViewModel.kt index d415b432c3..d81bef7d52 100644 --- a/app/src/main/java/ani/dantotsu/media/user/ListViewModel.kt +++ b/app/src/main/java/ani/dantotsu/media/user/ListViewModel.kt @@ -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 + }.toMutableMap() + + lists.postValue(filteredLists) + } + + fun unfilterLists() { + lists.postValue(unfilteredLists.value) + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_extensions.xml b/app/src/main/res/layout/activity_extensions.xml index cc6b4da77e..246c1785e8 100644 --- a/app/src/main/res/layout/activity_extensions.xml +++ b/app/src/main/res/layout/activity_extensions.xml @@ -86,7 +86,7 @@ android:layout_height="match_parent" android:layout_gravity="bottom" android:layout_weight="1" - android:visibility="gone"> + android:visibility="gone"/> + + + + + + +