Skip to content

Commit

Permalink
Add mark to filters icon when filters applied
Browse files Browse the repository at this point in the history
Related #25 #65
  • Loading branch information
alexandr7035 committed Sep 22, 2021
1 parent 9d62920 commit 90534d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,6 +35,7 @@ class RepositoriesListHostFragment : Fragment() {
return binding!!.root
}

@SuppressLint("UnsafeOptInUsageError")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand Down Expand Up @@ -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)
Expand All @@ -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
})
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class RepositoriesFiltersDialog(): BottomSheetDialogFragment() {

// Reload the lists from cache
// FIXME separate for tabs
viewModel.updateAllRepositoriesLiveData()
viewModel.updateArchivedRepositoriesLiveData()
viewModel.updateActiveRepositoriesLiveData()

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
<color name="gray_200">#898989</color>
<color name="gray_100">#B1B1B1</color>

<color name="yellow_400">#FFC107</color>
</resources>

0 comments on commit 90534d7

Please sign in to comment.