Skip to content

Commit

Permalink
feat(ui): video card v2
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Sep 20, 2024
1 parent d6e8b5d commit 20c40d8
Show file tree
Hide file tree
Showing 8 changed files with 840 additions and 534 deletions.
22 changes: 12 additions & 10 deletions app/src/main/java/com/junkfood/seal/download/DownloaderV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ import com.junkfood.seal.util.DownloadUtil
import com.junkfood.seal.util.FileUtil
import com.junkfood.seal.util.NotificationUtil
import com.yausername.youtubedl_android.YoutubeDL
import kotlin.collections.List
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.count
import kotlin.collections.firstOrNull
import kotlin.collections.forEach
import kotlin.collections.plusAssign
import kotlin.collections.set
import kotlin.collections.sortedBy
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set

private const val TAG = "DownloaderV2"

Expand Down Expand Up @@ -217,9 +211,17 @@ class DownloaderV2Impl(private val appContext: Context) : DownloaderV2, KoinComp
val res = YoutubeDL.destroyProcessById(preState.taskId)
if (res) {
preState.job.cancel()
state = State.Canceled(action = preState.action)
val progress = if (preState is Running) preState.progress else null
state = State.Canceled(action = preState.action, progress = progress)
}
}
Idle -> {
state = State.Canceled(action = FetchInfo)
}
ReadyWithInfo -> {
state = State.Canceled(action = Download)
}

else -> {
throw IllegalStateException()
}
Expand Down
27 changes: 15 additions & 12 deletions app/src/main/java/com/junkfood/seal/download/Task.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ data class Task(
val playlistIndex: Int? = null,
val preferences: DownloadUtil.DownloadPreferences,
val viewState: ViewState = ViewState.create(info, url),
val id: String = makeId(url, playlistIndex, preferences)
val id: String = makeId(url, playlistIndex, preferences),
) {
constructor(
url: String,
preferences: DownloadUtil.DownloadPreferences
preferences: DownloadUtil.DownloadPreferences,
) : this(info = null, url = url, preferences = preferences)

constructor(
info: VideoInfo,
preferences: DownloadUtil.DownloadPreferences
preferences: DownloadUtil.DownloadPreferences,
) : this(info = info, url = info.originalUrl.toString(), preferences = preferences)

sealed interface State : Comparable<State> {
Expand All @@ -38,10 +38,8 @@ data class Task(

data object Idle : State

data class FetchingInfo(
override val job: Job,
override val taskId: String,
) : State, Cancelable {
data class FetchingInfo(override val job: Job, override val taskId: String) :
State, Cancelable {
override val action: RestartableAction = RestartableAction.FetchInfo
}

Expand All @@ -51,15 +49,20 @@ data class Task(
override val job: Job,
override val taskId: String,
val progress: Float = PROGRESS_INDETERMINATE,
val progressText: String = ""
val progressText: String = "",
) : State, Cancelable {
override val action: RestartableAction = RestartableAction.Download
}

data class Canceled(override val action: RestartableAction) : State, Restartable
data class Canceled(
override val action: RestartableAction,
val progress: Float? = null,
) : State, Restartable

data class Error(val throwable: Throwable, override val action: RestartableAction) :
State, Restartable
data class Error(
val throwable: Throwable,
override val action: RestartableAction,
) : State, Restartable

data class Completed(val filePath: String?) : State

Expand Down Expand Up @@ -121,7 +124,7 @@ data class Task(
private fun makeId(
url: String,
playlistIndex: Int?,
preferences: DownloadUtil.DownloadPreferences
preferences: DownloadUtil.DownloadPreferences,
): String = "${url}_${playlistIndex}_${preferences.hashCode()}"
}
}
Loading

0 comments on commit 20c40d8

Please sign in to comment.