diff --git a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt index dbe718a90a..29cf3a967d 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt @@ -21,6 +21,7 @@ import com.github.libretube.helpers.ImageHelper import com.github.libretube.helpers.NavigationHelper import com.github.libretube.ui.activities.OfflinePlayerActivity import com.github.libretube.ui.base.BaseActivity +import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.fragments.DownloadTab import com.github.libretube.ui.sheets.DownloadOptionsBottomSheet import com.github.libretube.ui.sheets.DownloadOptionsBottomSheet.Companion.DELETE_DOWNLOAD_REQUEST_KEY @@ -56,6 +57,7 @@ class DownloadsAdapter( title.text = download.title uploaderName.text = download.uploader videoInfo.text = download.uploadDate?.let { TextUtils.localizeDate(it) } + watchProgress.setWatchProgressLength(download.videoId, download.duration ?: 0) val downloadSize = items.sumOf { it.downloadSize } val currentSize = items.filter { it.path.exists() }.sumOf { it.path.fileSize() } diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt index b396279fff..22912cb4a6 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt @@ -31,21 +31,21 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) { setBackgroundColor(backgroundColor) isGone = true - val progress = try { + if (duration == 0L) { + return + } + + val progress = runCatching { runBlocking { Database.watchPositionDao().findById(videoId)?.position + // divide by 1000 to convert ms to seconds + ?.toFloat()?.div(1000) } - } catch (e: Exception) { - return - } // divide by 1000 to convert ms to seconds - ?.toFloat()?.div(1000) - - if (progress == null || duration == 0L) { - return - } + }.getOrNull() ?: return updateLayoutParams { matchConstraintPercentWidth = progress / duration.toFloat() } + isVisible = true } diff --git a/app/src/main/res/layout/downloaded_media_row.xml b/app/src/main/res/layout/downloaded_media_row.xml index 68e3666ccb..29d3f1b992 100644 --- a/app/src/main/res/layout/downloaded_media_row.xml +++ b/app/src/main/res/layout/downloaded_media_row.xml @@ -16,66 +16,83 @@ android:layout_marginEnd="15dp" app:cardCornerRadius="8dp"> - - - - + - + + - - - - - - + + + + + + + app:layout_constraintStart_toStartOf="parent" + tools:visibility="visible" + tools:layout_width="20dp" /> + + + + + + + - @@ -120,7 +137,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="13sp" - tools:text="13.13MB"/> + tools:text="13.13MB" />