[Reader] Enable Gesture, Adjusted BrokenImage tint

[NetworkCache] Don't download existing file again
This commit is contained in:
tom5079
2021-12-25 14:19:28 +09:00
parent bf3e7d7117
commit fcbe107fe7
3 changed files with 32 additions and 25 deletions

View File

@@ -137,7 +137,7 @@ dependencies {
implementation("ru.noties.markwon:core:3.1.0") implementation("ru.noties.markwon:core:3.1.0")
implementation("xyz.quaver:documentfilex:0.7.1") implementation("xyz.quaver:documentfilex:0.7.1")
implementation("xyz.quaver:subsampledimage:0.0.1-alpha15-SNAPSHOT") implementation("xyz.quaver:subsampledimage:0.0.1-alpha16-SNAPSHOT")
implementation("com.google.guava:guava:31.0.1-jre") implementation("com.google.guava:guava:31.0.1-jre")

View File

@@ -511,7 +511,9 @@ fun ReaderItem(
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
) { ) {
images.let { if (readerOptions.orientation.isReverse) it.reversed() else it }.forEach { (index, imageSize, imageSource) -> images.let { if (readerOptions.orientation.isReverse) it.reversed() else it }.forEach { (index, imageSize, imageSource) ->
val state = rememberSubSampledImageState() val state = rememberSubSampledImageState().apply {
isGestureEnabled = true
}
val modifier = when { val modifier = when {
imageSize == null -> Modifier.weight(1f).height(heightDp) imageSize == null -> Modifier.weight(1f).height(heightDp)
@@ -527,7 +529,7 @@ fun ReaderItem(
val progress = model.progressList.getOrNull(index) ?: 0f val progress = model.progressList.getOrNull(index) ?: 0f
if (progress == Float.NEGATIVE_INFINITY) if (progress == Float.NEGATIVE_INFINITY)
Icon(Icons.Filled.BrokenImage, null, tint = Orange500) Icon(Icons.Filled.BrokenImage, null)
else if (progress.isFinite()) else if (progress.isFinite())
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally

View File

@@ -123,6 +123,9 @@ class NetworkCache(context: Context) : DIAware {
requests[url] = networkScope.launch { requests[url] = networkScope.launch {
runCatching { runCatching {
if (file.exists()) {
progressFlow.emit(Float.POSITIVE_INFINITY)
} else {
cacheDir.mkdirs() cacheDir.mkdirs()
file.createNewFile() file.createNewFile()
@@ -140,7 +143,8 @@ class NetworkCache(context: Context) : DIAware {
break break
} }
val packet = responseChannel.readRemaining(DEFAULT_BUFFER_SIZE.toLong()) val packet =
responseChannel.readRemaining(DEFAULT_BUFFER_SIZE.toLong())
while (!packet.isEmpty) { while (!packet.isEmpty) {
if (!isActive) { if (!isActive) {
file.delete() file.delete()
@@ -157,6 +161,7 @@ class NetworkCache(context: Context) : DIAware {
} }
progressFlow.emit(Float.POSITIVE_INFINITY) progressFlow.emit(Float.POSITIVE_INFINITY)
} }
}
}.onFailure { }.onFailure {
logger.warning(it) logger.warning(it)
file.delete() file.delete()