Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: watch progress support for downloads #6741

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConstraintLayout.LayoutParams> {
matchConstraintPercentWidth = progress / duration.toFloat()
}

isVisible = true
}
129 changes: 73 additions & 56 deletions app/src/main/res/layout/downloaded_media_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,83 @@
android:layout_marginEnd="15dp"
app:cardCornerRadius="8dp">

<ImageView
android:id="@+id/thumbnailImage"
android:layout_width="150dp"
android:layout_height="83dp"
android:scaleType="fitXY"
tools:src="@tools:sample/backgrounds/scenic" />


<androidx.cardview.widget.CardView
android:id="@+id/durationContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:visibility="gone"
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="@id/thumbnailImage"
tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/thumbnail_duration"
<ImageView
android:id="@+id/thumbnailImage"
android:layout_width="150dp"
android:layout_height="83dp"
android:scaleType="fitXY"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/backgrounds/scenic" />

<androidx.cardview.widget.CardView
android:id="@+id/durationContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="2dp"
android:textColor="@color/duration_text_color"
android:textSize="11sp"
tools:text="05:36" />

</androidx.cardview.widget.CardView>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/downloadOverlay"
android:layout_width="150dp"
android:layout_height="83dp"
android:background="#BF000000">

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="52dp"
android:layout_height="52dp"
android:indeterminateOnly="false"
android:progressDrawable="@drawable/circular_progress"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:visibility="gone"
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="@id/thumbnailImage"
tools:visibility="visible">

<TextView
android:id="@+id/thumbnail_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="2dp"
android:textColor="@color/duration_text_color"
android:textSize="11sp"
tools:text="05:36" />

</androidx.cardview.widget.CardView>

<View
android:id="@+id/watch_progress"
style="@style/WatchProgress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible"
tools:layout_width="20dp" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/downloadOverlay"
android:layout_width="150dp"
android:layout_height="83dp"
android:background="#BF000000"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="52dp"
android:layout_height="52dp"
android:indeterminateOnly="false"
android:progressDrawable="@drawable/circular_progress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/resumePauseBtn"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_download"
app:layout_constraintBottom_toBottomOf="@id/progressBar"
app:layout_constraintLeft_toLeftOf="@id/progressBar"
app:layout_constraintRight_toRightOf="@id/progressBar"
app:layout_constraintTop_toTopOf="@id/progressBar" />
</androidx.constraintlayout.widget.ConstraintLayout>

<ImageView
android:id="@+id/resumePauseBtn"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_download"
app:layout_constraintBottom_toBottomOf="@id/progressBar"
app:layout_constraintLeft_toLeftOf="@id/progressBar"
app:layout_constraintRight_toRightOf="@id/progressBar"
app:layout_constraintTop_toTopOf="@id/progressBar" />
</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>
Expand Down Expand Up @@ -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" />

</LinearLayout>

Expand Down
Loading