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)
|
||||
}
|
||||
|
||||
}
|
|
@ -86,7 +86,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_weight="1"
|
||||
android:visibility="gone"></FrameLayout>
|
||||
android:visibility="gone"/>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/searchView"
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
<TextView
|
||||
android:id="@+id/listTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
|
@ -43,13 +43,22 @@
|
|||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
android:textSize="16sp"
|
||||
android:textSize="14sp"
|
||||
tools:text="@string/app_name" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/search"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:contentDescription="@string/search"
|
||||
app:srcCompat="@drawable/ic_round_search_24"
|
||||
app:tint="?attr/colorOnBackground" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/random"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:contentDescription="@string/random_selection"
|
||||
app:srcCompat="@drawable/ic_shuffle_24"
|
||||
|
@ -57,8 +66,8 @@
|
|||
|
||||
<ImageButton
|
||||
android:id="@+id/filter"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:contentDescription="@string/filter"
|
||||
app:srcCompat="@drawable/ic_round_filter_alt_24"
|
||||
|
@ -66,15 +75,57 @@
|
|||
|
||||
<ImageButton
|
||||
android:id="@+id/listSort"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:contentDescription="@string/sort_by"
|
||||
app:srcCompat="@drawable/ic_round_sort_24"
|
||||
app:tint="?attr/colorOnBackground" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/searchView"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:transitionName="@string/search"
|
||||
app:boxBackgroundColor="?android:attr/colorBackground"
|
||||
app:hintTextColor="?attr/colorOnBackground"
|
||||
app:boxStrokeColor="?attr/colorOnBackground"
|
||||
app:cursorColor="?attr/colorOnBackground"
|
||||
app:boxBackgroundMode="outline"
|
||||
app:boxCornerRadiusBottomEnd="28dp"
|
||||
app:boxCornerRadiusBottomStart="28dp"
|
||||
app:boxCornerRadiusTopEnd="28dp"
|
||||
app:boxCornerRadiusTopStart="28dp"
|
||||
app:endIconDrawable="@drawable/ic_round_search_24"
|
||||
app:endIconTint="?attr/colorOnBackground"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:hintAnimationEnabled="true">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/searchViewText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_weight="1"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:hint="@string/search"
|
||||
android:imeOptions="actionSearch"
|
||||
android:inputType="textPersonName"
|
||||
android:padding="8dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:selectAllOnFocus="true"
|
||||
android:textSize="14sp"
|
||||
tools:ignore="LabelFor,TextContrastCheck" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue