@@ -12,7 +12,6 @@ import android.view.View
1212import android.view.ViewGroup
1313import androidx.core.content.ContextCompat
1414import androidx.core.view.isGone
15- import androidx.core.view.isInvisible
1615import androidx.core.view.isVisible
1716import androidx.lifecycle.lifecycleScope
1817import androidx.recyclerview.widget.GridLayoutManager
@@ -87,7 +86,6 @@ class DownloadsFragment : DynamicLayoutManagerFragment() {
8786
8887 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
8988 super .onViewCreated(view, savedInstanceState)
90- binding.deleteAll.isInvisible = true
9189 var selectedSortType =
9290 PreferenceHelper .getInt(PreferenceKeys .SELECTED_DOWNLOAD_SORT_TYPE , 0 )
9391 val filterOptions = resources.getStringArray(R .array.downloadSortOptions)
@@ -166,25 +164,31 @@ class DownloadsFragment : DynamicLayoutManagerFragment() {
166164 object : RecyclerView .AdapterDataObserver () {
167165 override fun onItemRangeRemoved (positionStart : Int , itemCount : Int ) {
168166 super .onItemRangeRemoved(positionStart, itemCount)
169- val binding = _binding ? : return
170- if (binding.downloads.adapter?.itemCount == 0 ) {
171- binding.downloads.isGone = true
172- binding.downloadsEmpty.isVisible = true
173- }
167+ toggleButtonsVisibility()
174168 }
175169 }
176170 )
177171
178- if (dbDownloads.isNotEmpty()) {
179- binding.deleteAll.isVisible = true
180- binding.deleteAll.setOnClickListener {
181- showDeleteAllDialog(binding.root.context, adapter)
182- }
183- }
172+ toggleButtonsVisibility()
184173
185174 binding.shuffleBackground.setOnClickListener {
186175 BackgroundHelper .playOnBackgroundOffline(requireContext(), null )
187176 }
177+
178+ binding.deleteAll.setOnClickListener {
179+ showDeleteAllDialog(binding.root.context, adapter)
180+ }
181+ }
182+
183+ private fun toggleButtonsVisibility () {
184+ val binding = _binding ? : return
185+
186+ val isEmpty = binding.downloads.adapter?.itemCount == 0
187+ binding.downloadsEmpty.isVisible = isEmpty
188+ binding.downloads.isGone = isEmpty
189+ binding.sortType.isGone = isEmpty
190+ binding.deleteAll.isGone = isEmpty
191+ binding.shuffleBackground.isGone = isEmpty
188192 }
189193
190194 private fun sortDownloadList (sortType : Int , previousSortType : Int? = null) {
0 commit comments