Skip to content

Commit 15ef61f

Browse files
nik-conderBnyro
authored andcommitted
fix: visibility of UI elements in Downloads
1 parent b437cf2 commit 15ef61f

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import android.view.View
1212
import android.view.ViewGroup
1313
import androidx.core.content.ContextCompat
1414
import androidx.core.view.isGone
15-
import androidx.core.view.isInvisible
1615
import androidx.core.view.isVisible
1716
import androidx.lifecycle.lifecycleScope
1817
import 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) {

app/src/main/res/layout/fragment_downloads.xml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
android:layout_width="wrap_content"
1212
android:layout_height="wrap_content"
1313
android:layout_marginEnd="10dp"
14-
android:paddingVertical="5dp"
14+
android:clickable="true"
15+
android:drawablePadding="10dp"
1516
android:focusable="true"
1617
android:fontFamily="@font/roboto"
18+
android:paddingVertical="5dp"
1719
android:text="@string/sort_by"
18-
19-
android:clickable="true"
2020
android:textSize="15sp"
2121
android:textStyle="bold"
22-
android:drawablePadding="10dp"
22+
android:visibility="gone"
2323
app:drawableEndCompat="@drawable/ic_sort"
24-
app:layout_constraintTop_toTopOf="parent"
2524
app:layout_constraintEnd_toEndOf="parent"
26-
/>
25+
app:layout_constraintTop_toTopOf="parent"
26+
tools:visibility="visible" />
2727

2828
<LinearLayout
2929
android:id="@+id/downloads_empty"
@@ -70,9 +70,11 @@
7070
android:contentDescription="@string/shuffle"
7171
android:src="@drawable/ic_delete"
7272
android:tooltipText="@string/delete"
73+
android:visibility="gone"
7374
app:layout_constraintBottom_toBottomOf="parent"
7475
app:layout_constraintEnd_toEndOf="parent"
75-
tools:targetApi="o" />
76+
tools:targetApi="o"
77+
tools:visibility="visible" />
7678

7779
<com.google.android.material.floatingactionbutton.FloatingActionButton
7880
android:id="@+id/shuffle_background"
@@ -83,8 +85,10 @@
8385
android:contentDescription="@string/shuffle"
8486
android:src="@drawable/ic_shuffle"
8587
android:tooltipText="@string/shuffle"
88+
android:visibility="gone"
8689
app:layout_constraintBottom_toBottomOf="parent"
8790
app:layout_constraintEnd_toEndOf="parent"
88-
tools:targetApi="o" />
91+
tools:targetApi="o"
92+
tools:visibility="visible" />
8993

9094
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)