[fix] Offline mode display exception

This commit is contained in:
acite
2025-09-28 01:54:02 +08:00
parent 9bad0dcbc2
commit 2166229923
4 changed files with 16 additions and 8 deletions

View File

@@ -120,6 +120,10 @@ class FetchManager @Inject constructor(
} }
suspend fun startVideoDownload(video: Video) { suspend fun startVideoDownload(video: Video) {
if(getAllDownloadsAsync().any{
it.extras.getString("class", "") == video.klass && it.extras.getString("id", "") == video.id })
return
makeFolder(video) makeFolder(video)
File( File(
context.getExternalFilesDir(null), context.getExternalFilesDir(null),

View File

@@ -51,6 +51,7 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import java.io.File import java.io.File
import kotlin.collections.sortedWith import kotlin.collections.sortedWith
import kotlin.math.abs
@Composable @Composable
fun TransmissionScreen( fun TransmissionScreen(
@@ -254,7 +255,7 @@ private fun VideoDownloadCard(
// progress bar // progress bar
LinearProgressIndicator( LinearProgressIndicator(
progress = { model.progress.coerceIn(0, 100) / 100f }, progress = { abs(model.progress).coerceIn(0, 100) / 100f },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp, bottom = 8.dp), .padding(top = 8.dp, bottom = 8.dp),

View File

@@ -349,12 +349,13 @@ fun VideoCard(
{ {
videoScreenViewModel.download(i) videoScreenViewModel.download(i)
} }
Toast.makeText(
videoScreenViewModel.context,
"Start downloading ${video.video.group}",
Toast.LENGTH_SHORT
).show()
} }
Toast.makeText(
videoScreenViewModel.context,
"Start downloading ${video.video.group}",
Toast.LENGTH_SHORT
).show()
} }
), ),
shape = RoundedCornerShape(6.dp), shape = RoundedCornerShape(6.dp),

View File

@@ -36,7 +36,7 @@ import javax.inject.Singleton
@HiltViewModel @HiltViewModel
class VideoScreenViewModel @Inject constructor( class VideoScreenViewModel @Inject constructor(
private val fetchManager: FetchManager, val fetchManager: FetchManager,
@ApplicationContext val context: Context, @ApplicationContext val context: Context,
val mediaManager: MediaManager, val mediaManager: MediaManager,
val recentManager: RecentManager, val recentManager: RecentManager,
@@ -82,7 +82,9 @@ class VideoScreenViewModel @Inject constructor(
videoLibrary.classesMap["Offline"] = mutableStateListOf<Video>() videoLibrary.classesMap["Offline"] = mutableStateListOf<Video>()
val downloaded = fetchManager.getAllDownloadsAsync().filter { val downloaded = fetchManager.getAllDownloadsAsync().filter {
it.status == Status.COMPLETED && it.extras.getString("class", "") != "comic" it.status == Status.COMPLETED &&
it.extras.getString("class", "") != "comic" &&
it.extras.getString("type", "") == "main"
} }
val jsonQuery = downloaded.map{ File( val jsonQuery = downloaded.map{ File(