diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt index 5a3c57d6..4cd5c19b 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt @@ -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 -> diff --git a/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt b/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt index 1e13d689..b7f46eb8 100644 --- a/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt @@ -19,9 +19,12 @@ class MainNavFragmentViewModelX( secondarySource: Source ) : ViewModel() { - private val order = MutableLiveData(Order.LAST_UPDATE) - private val sections = MutableLiveData
(Section.All) - private val searchQuery = MutableLiveData("") + var order = MutableLiveData(Order.LAST_UPDATE) + private set + var sections = MutableLiveData
(Section.All) + private set + var searchQuery = MutableLiveData("") + private set fun request(source: Source): Request { var mSearchQuery = ""