mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
new search filter layout
This commit is contained in:
parent
329ccaeb00
commit
5ef883ca67
@ -13,7 +13,6 @@ import com.github.libretube.adapters.SearchAdapter
|
||||
import com.github.libretube.databinding.FragmentSearchResultBinding
|
||||
import com.github.libretube.util.RetrofitInstance
|
||||
import com.github.libretube.util.hideKeyboard
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
@ -24,6 +23,7 @@ class SearchResultFragment : Fragment() {
|
||||
private lateinit var nextPage: String
|
||||
private var query: String = ""
|
||||
|
||||
private lateinit var searchAdapter: SearchAdapter
|
||||
private var apiSearchFilter: String = "all"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -43,36 +43,24 @@ class SearchResultFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.filterMenuImageView.setOnClickListener {
|
||||
val filterOptions = arrayOf(
|
||||
getString(R.string.all),
|
||||
getString(R.string.videos),
|
||||
getString(R.string.channels),
|
||||
getString(R.string.playlists),
|
||||
getString(R.string.music_songs),
|
||||
getString(R.string.music_videos),
|
||||
getString(R.string.music_albums),
|
||||
getString(R.string.music_playlists)
|
||||
)
|
||||
// filter options
|
||||
binding.filterChipGroup.setOnCheckedStateChangeListener { _, _ ->
|
||||
apiSearchFilter = when (
|
||||
binding.filterChipGroup.checkedChipId
|
||||
) {
|
||||
R.id.chip_all -> "all"
|
||||
R.id.chip_videos -> "videos"
|
||||
R.id.chip_channels -> "channels"
|
||||
R.id.chip_playlists -> "playlists"
|
||||
R.id.chip_music_songs -> "music_songs"
|
||||
R.id.chip_music_videos -> "music_videos"
|
||||
R.id.chip_music_albums -> "music_albums"
|
||||
R.id.chip_music_playlists -> "music_playlists"
|
||||
else -> throw IllegalArgumentException("Filter out of range")
|
||||
}
|
||||
fetchSearch()
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(getString(R.string.choose_filter))
|
||||
.setItems(filterOptions) { _, id ->
|
||||
apiSearchFilter = when (id) {
|
||||
0 -> "all"
|
||||
1 -> "videos"
|
||||
2 -> "channels"
|
||||
3 -> "playlists"
|
||||
4 -> "music_songs"
|
||||
5 -> "music_videos"
|
||||
6 -> "music_albums"
|
||||
7 -> "music_playlists"
|
||||
else -> "all"
|
||||
}
|
||||
}
|
||||
.setNegativeButton(getString(R.string.cancel), null)
|
||||
.show()
|
||||
}
|
||||
fetchSearch()
|
||||
|
||||
binding.searchRecycler.viewTreeObserver
|
||||
@ -99,7 +87,8 @@ class SearchResultFragment : Fragment() {
|
||||
runOnUiThread {
|
||||
if (response.items?.isNotEmpty() == true) {
|
||||
binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.searchRecycler.adapter = SearchAdapter(response.items, childFragmentManager)
|
||||
searchAdapter = SearchAdapter(response.items, childFragmentManager)
|
||||
binding.searchRecycler.adapter = searchAdapter
|
||||
}
|
||||
}
|
||||
nextPage = response.nextpage!!
|
||||
@ -123,8 +112,10 @@ class SearchResultFragment : Fragment() {
|
||||
return@launchWhenCreated
|
||||
}
|
||||
nextPage = response.nextpage!!
|
||||
with(binding.searchRecycler.adapter as SearchAdapter) {
|
||||
if (response.items?.isNotEmpty() == true) this.updateItems(response.items)
|
||||
kotlin.runCatching {
|
||||
if (response.items?.isNotEmpty() == true) {
|
||||
searchAdapter.updateItems(response.items.toMutableList())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".fragments.SearchFragment">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/filterMenu_imageView"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:src="@drawable/ic_filter" />
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/filter_bar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
app:layout_constraintBottom_toTopOf="@id/recycler_view"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/filter_chip_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
app:selectionRequired="true"
|
||||
app:singleLine="true"
|
||||
app:singleSelection="true">
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_all"
|
||||
style="@style/Chip"
|
||||
android:text="@string/all" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_videos"
|
||||
style="@style/Chip"
|
||||
android:text="@string/videos" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_channels"
|
||||
style="@style/Chip"
|
||||
android:text="@string/channels" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_playlists"
|
||||
style="@style/Chip"
|
||||
android:text="@string/playlists" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_music_songs"
|
||||
style="@style/Chip"
|
||||
android:text="@string/music_songs" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_music_videos"
|
||||
style="@style/Chip"
|
||||
android:text="@string/music_videos" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_music_albums"
|
||||
style="@style/Chip"
|
||||
android:text="@string/music_albums" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_music_playlists"
|
||||
style="@style/Chip"
|
||||
android:text="@string/music_playlists" />
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
</HorizontalScrollView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/search_recycler"
|
||||
|
@ -147,4 +147,11 @@
|
||||
<item name="android:textColor">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="Chip" parent="Widget.Material3.Chip.Suggestion">
|
||||
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
|
||||
</style>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user