added shimmer on format loading
This commit is contained in:
parent
bf5af91195
commit
f9913eadf5
4 changed files with 160 additions and 6 deletions
|
|
@ -17,6 +17,7 @@ import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel.Type
|
|||
import com.deniscerri.ytdlnis.util.FileUtil
|
||||
import com.deniscerri.ytdlnis.util.InfoUtil
|
||||
import com.deniscerri.ytdlnis.util.UiUtil
|
||||
import com.facebook.shimmer.ShimmerFrameLayout
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -53,6 +54,8 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
}
|
||||
|
||||
val linearLayout = view.findViewById<LinearLayout>(R.id.format_list_linear_layout)
|
||||
val shimmers = view.findViewById<ShimmerFrameLayout>(R.id.format_list_shimmer)
|
||||
shimmers.visibility = View.GONE
|
||||
addFormatsToView(linearLayout)
|
||||
|
||||
val refreshBtn = view.findViewById<Button>(R.id.format_refresh)
|
||||
|
|
@ -61,6 +64,10 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
lifecycleScope.launch {
|
||||
try {
|
||||
refreshBtn.isEnabled = false
|
||||
linearLayout.visibility = View.GONE
|
||||
shimmers.visibility = View.VISIBLE
|
||||
shimmers.startShimmer()
|
||||
|
||||
val res = withContext(Dispatchers.IO){
|
||||
infoUtil.getFormats(item.url)
|
||||
}
|
||||
|
|
@ -72,8 +79,16 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
if (formats.isEmpty()) throw Exception()
|
||||
addFormatsToView(linearLayout)
|
||||
refreshBtn.visibility = View.GONE
|
||||
|
||||
linearLayout.visibility = View.VISIBLE
|
||||
shimmers.visibility = View.GONE
|
||||
shimmers.stopShimmer()
|
||||
}catch (e: Exception){
|
||||
refreshBtn.isEnabled = true
|
||||
linearLayout.visibility = View.VISIBLE
|
||||
shimmers.visibility = View.GONE
|
||||
shimmers.stopShimmer()
|
||||
|
||||
e.printStackTrace()
|
||||
Toast.makeText(context, getString(R.string.error_updating_formats), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
|
|
|||
109
app/src/main/res/layout/format_item_shimmer.xml
Normal file
109
app/src/main/res/layout/format_item_shimmer.xml
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/format_card_constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingVertical="5dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/container"
|
||||
android:layout_width="60dp"
|
||||
android:background="@color/light_grey"
|
||||
android:textColor="@color/white"
|
||||
android:clickable="false"
|
||||
android:layout_height="55dp"
|
||||
android:gravity="center"
|
||||
android:minWidth="30dp"
|
||||
app:cornerRadius="10dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/container"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/format_note"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginStart="10dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@+id/format_note"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/codec"
|
||||
android:ellipsize="end"
|
||||
android:maxLength="17"
|
||||
style="@style/Widget.Material3.FloatingActionButton.Large.Secondary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="@color/light_grey"
|
||||
android:clickable="false"
|
||||
android:gravity="center"
|
||||
android:minWidth="30dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
app:cornerRadius="10dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/file_size"
|
||||
style="@style/Widget.Material3.FloatingActionButton.Large.Tertiary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="@color/light_grey"
|
||||
android:clickable="false"
|
||||
android:gravity="center"
|
||||
android:minWidth="30dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
app:cornerRadius="10dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/format_id"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="10dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:background="@color/light_grey"
|
||||
android:clickable="false"
|
||||
android:gravity="bottom|end"
|
||||
android:maxLength="10"
|
||||
android:minWidth="30dp"
|
||||
app:cornerRadius="10dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="1.0" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -68,11 +68,38 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
|
||||
<com.facebook.shimmer.ShimmerFrameLayout
|
||||
android:id="@+id/format_list_shimmer"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/format_item_shimmer" />
|
||||
|
||||
<include layout="@layout/format_item_shimmer" />
|
||||
|
||||
<include layout="@layout/format_item_shimmer" />
|
||||
|
||||
<include layout="@layout/format_item_shimmer" />
|
||||
|
||||
<include layout="@layout/format_item_shimmer" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout android:id="@+id/downloads_element_bottom_sheet"
|
||||
<FrameLayout xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/downloads_element_bottom_sheet"
|
||||
style="@style/Widget.Material3.BottomSheet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -50,9 +51,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/linearLayout4"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/linearLayout4"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
|
|
@ -60,9 +59,13 @@
|
|||
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Secondary"
|
||||
android:layout_width="55dp"
|
||||
android:layout_height="55dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:clickable="false"
|
||||
app:cornerRadius="10dp" />
|
||||
android:elevation="0dp"
|
||||
app:borderWidth="0dp"
|
||||
app:cornerRadius="10dp"
|
||||
app:elevation="0dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue