diff --git a/app/src/main/java/com/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt b/app/src/main/java/com/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt index 9e75dbe5..dd19e44a 100644 --- a/app/src/main/java/com/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt +++ b/app/src/main/java/com/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt @@ -1,15 +1,19 @@ package com.alexandr7035.gitstat.view.repositories +import android.annotation.SuppressLint import android.os.Bundle import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import androidx.navigation.navGraphViewModels import com.alexandr7035.gitstat.R import com.alexandr7035.gitstat.databinding.FragmentHostRepositoriesListBinding +import com.google.android.material.badge.BadgeDrawable +import com.google.android.material.badge.BadgeUtils import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import dagger.hilt.android.AndroidEntryPoint @@ -31,6 +35,7 @@ class RepositoriesListHostFragment : Fragment() { return binding!!.root } + @SuppressLint("UnsafeOptInUsageError") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -73,6 +78,11 @@ class RepositoriesListHostFragment : Fragment() { true } + // Icon mark for applied filters + val badge: BadgeDrawable = BadgeDrawable.create(requireContext()) + badge.backgroundColor = ContextCompat.getColor(requireContext(), R.color.yellow_400) + BadgeUtils.attachBadgeDrawable(badge, binding!!.toolbar, R.id.item_filters) + // Update counters in the tabs viewModel.getActiveRepositoriesLiveData().observe(viewLifecycleOwner, { val repos = viewModel.getFilteredRepositoriesList(it) @@ -84,6 +94,15 @@ class RepositoriesListHostFragment : Fragment() { (binding!!.tabLayout.getTabAt(1) as TabLayout.Tab).text = "Archived (${repos.size})" }) + viewModel.getAllRepositoriesListLiveData().observe(viewLifecycleOwner, { + + val repos = viewModel.getFilteredRepositoriesList(it) + + // When unfiltered and filtered lists differ in length + // Means some filters are applied + // Show or hide badge + badge.isVisible = it.size != repos.size + }) } diff --git a/app/src/main/java/com/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt b/app/src/main/java/com/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt index a3ee6ded..fbfa1937 100644 --- a/app/src/main/java/com/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt +++ b/app/src/main/java/com/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt @@ -117,6 +117,7 @@ class RepositoriesFiltersDialog(): BottomSheetDialogFragment() { // Reload the lists from cache // FIXME separate for tabs + viewModel.updateAllRepositoriesLiveData() viewModel.updateArchivedRepositoriesLiveData() viewModel.updateActiveRepositoriesLiveData() diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1c55081e..77e302fa 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -17,4 +17,5 @@ #898989 #B1B1B1 + #FFC107 \ No newline at end of file