Compare commits

...
Author SHA1 Message Date
tarsin 746a045328 Bump to 1.8.8.0-alpha
Releases / Build (push) Has been cancelled
2023-05-17 22:49:34 +08:00
tarsin 2a4c7823c2 Bind downloadHolder with coroutine 2023-05-17 22:42:55 +08:00
tarsin b995510df1 Resolve #1082, #1081 again 2023-05-17 22:21:17 +08:00
tarsin a2852d6df9 Resolve #1082, #1081 again 2023-05-17 19:08:07 +08:00
tarsin 47863580a0 Resolve #1082, #1081 again 2023-05-17 19:01:39 +08:00
tarsin 9af6532331 Resolve #1082, #1081 2023-05-17 16:28:50 +08:00
2 changed files with 56 additions and 45 deletions

No files matched your search

+1 -1
View File
@@ -58,7 +58,7 @@ android {
minSdk = 28
targetSdk = 33
versionCode = 180038
versionName = "1.8.8.0-preview"
versionName = "1.8.8.0-alpha"
resourceConfigurations.addAll(
listOf(
"zh",
@@ -876,57 +876,68 @@ class DownloadsScene :
private val height = (Settings.listThumbSize * 3).pxToDp.dp
fun bind(info: DownloadInfo) {
val downloadDir = SpiderDen.getGalleryDownloadDir(info.gid)?.takeIf { it.isDirectory }
check(downloadDir != null)
val thumbLocation = downloadDir.subFile(".thumb")!!
val localReq = thumbLocation.takeIf { it.exists() }?.uri?.let {
context?.imageRequest {
data(it.toString())
memoryCacheKey(info.thumbKey)
lifecycleScope.launchIO {
val downloadDir = SpiderDen.getGalleryDownloadDir(info.gid) ?: run {
val title = EhUtils.getSuitableTitle(info)
val dirname = FileUtils.sanitizeFilename("${info.gid}-$title")
EhDB.putDownloadDirname(info.gid, dirname)
SpiderDen.getGalleryDownloadDir(info.gid)!!
}
}
binding.thumb.setMD3Content {
Card(onClick = ::onClick.partially1(binding.thumb)) {
var contentScale by remember { mutableStateOf(ContentScale.Fit) }
val coroutineScope = rememberCoroutineScope { Dispatchers.IO }
AsyncImage(
model = localReq ?: requestOf(info),
contentDescription = null,
modifier = Modifier.height(height).aspectRatio(0.6666667F),
onState = { state ->
if (state is AsyncImagePainter.State.Success) {
state.result.drawable.run {
if (CropDefaults.shouldCrop(intrinsicWidth, intrinsicHeight)) {
contentScale = ContentScale.Crop
}
}
coroutineScope.launch {
if (!thumbLocation.exists()) {
thumbLocation.ensureFile()
val key = info.thumbKey!!
imageCache[key]?.use {
UniFile.fromFile(it.data.toFile())!!.openFileDescriptor("r").use { src ->
thumbLocation.openFileDescriptor("w").use { dst ->
src sendTo dst
check(downloadDir.ensureDir())
val thumbLocation = downloadDir.subFile(".thumb")!!
val localReq = thumbLocation.takeIf { it.exists() }?.uri?.let {
context?.imageRequest {
data(it.toString())
memoryCacheKey(info.thumbKey)
}
}
withUIContext {
binding.thumb.setMD3Content {
Card(onClick = ::onClick.partially1(binding.thumb)) {
var contentScale by remember { mutableStateOf(ContentScale.Fit) }
val coroutineScope = rememberCoroutineScope { Dispatchers.IO }
AsyncImage(
model = localReq ?: requestOf(info),
contentDescription = null,
modifier = Modifier.height(height).aspectRatio(0.6666667F),
onState = { state ->
if (state is AsyncImagePainter.State.Success) {
state.result.drawable.run {
if (CropDefaults.shouldCrop(intrinsicWidth, intrinsicHeight)) {
contentScale = ContentScale.Crop
}
}
coroutineScope.launch {
runCatching {
if (!thumbLocation.exists()) {
thumbLocation.ensureFile()
val key = info.thumbKey!!
imageCache[key]?.use {
UniFile.fromFile(it.data.toFile())!!.openFileDescriptor("r").use { src ->
thumbLocation.openFileDescriptor("w").use { dst ->
src sendTo dst
}
}
}
}
}
}
}
}
}
if (state is AsyncImagePainter.State.Error) {
if (thumbLocation.exists()) {
coroutineScope.launch {
thumbLocation.delete()
withUIContext {
bind(info)
if (state is AsyncImagePainter.State.Error) {
if (thumbLocation.exists()) {
coroutineScope.launch {
thumbLocation.delete()
withUIContext {
bind(info)
}
}
}
}
}
}
},
contentScale = contentScale,
)
},
contentScale = contentScale,
)
}
}
}
}
binding.title.text = EhUtils.getSuitableTitle(info)