Add: Check the selected category on launch/resume

This commit is contained in:
machiav3lli 2022-02-20 02:56:41 +01:00
parent 555bf1f14f
commit e7295d90d6
2 changed files with 24 additions and 10 deletions

View File

@ -6,9 +6,11 @@ import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.Scaffold
import androidx.core.view.children
import com.google.android.material.chip.Chip
import com.looker.droidify.R
import com.looker.droidify.content.Preferences
import com.looker.droidify.database.entity.Category
import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentExploreXBinding
import com.looker.droidify.entity.Section
@ -64,14 +66,23 @@ class ExploreFragment : MainNavFragmentX() {
}
}
viewModel.categories.observe(viewLifecycleOwner) {
binding.categories.removeAllViews()
binding.categories.addView(Chip(requireContext(), null, R.attr.chipStyle).apply {
setText(R.string.all_applications)
})
it.forEach {
binding.categories.addView(Chip(requireContext(), null, R.attr.chipStyle).apply {
text = it
binding.categories.apply {
removeAllViews()
addView(Chip(requireContext(), null, R.attr.chipStyle).apply {
setText(R.string.all_applications)
id = R.id.SHOW_ALL
})
it.forEach {
addView(Chip(requireContext(), null, R.attr.chipStyle).apply {
text = it
})
}
val selectedSection = viewModel.sections.value
check(
children.filterNotNull()
.find { it is Chip && selectedSection is Category && it.text == selectedSection.name }?.id
?: R.id.SHOW_ALL
)
}
}
binding.categories.setOnCheckedChangeListener { group, checkedId ->

View File

@ -19,9 +19,12 @@ class MainNavFragmentViewModelX(
secondarySource: Source
) : ViewModel() {
private val order = MutableLiveData(Order.LAST_UPDATE)
private val sections = MutableLiveData<Section>(Section.All)
private val searchQuery = MutableLiveData("")
var order = MutableLiveData(Order.LAST_UPDATE)
private set
var sections = MutableLiveData<Section>(Section.All)
private set
var searchQuery = MutableLiveData("")
private set
fun request(source: Source): Request {
var mSearchQuery = ""