[Reader] Enable Gesture, Adjusted BrokenImage tint
[NetworkCache] Don't download existing file again
This commit is contained in:
@@ -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")
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -123,39 +123,44 @@ class NetworkCache(context: Context) : DIAware {
|
|||||||
|
|
||||||
requests[url] = networkScope.launch {
|
requests[url] = networkScope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
cacheDir.mkdirs()
|
if (file.exists()) {
|
||||||
file.createNewFile()
|
progressFlow.emit(Float.POSITIVE_INFINITY)
|
||||||
|
} else {
|
||||||
|
cacheDir.mkdirs()
|
||||||
|
file.createNewFile()
|
||||||
|
|
||||||
client.request<HttpStatement>(request).execute { httpResponse ->
|
client.request<HttpStatement>(request).execute { httpResponse ->
|
||||||
if (!httpResponse.status.isSuccess()) throw IOException("${request.url} failed with code ${httpResponse.status.value}")
|
if (!httpResponse.status.isSuccess()) throw IOException("${request.url} failed with code ${httpResponse.status.value}")
|
||||||
val responseChannel: ByteReadChannel = httpResponse.receive()
|
val responseChannel: ByteReadChannel = httpResponse.receive()
|
||||||
val contentLength = httpResponse.contentLength() ?: -1
|
val contentLength = httpResponse.contentLength() ?: -1
|
||||||
var readBytes = 0f
|
var readBytes = 0f
|
||||||
|
|
||||||
file.outputStream().use { outputStream ->
|
file.outputStream().use { outputStream ->
|
||||||
outputStream.channel.truncate(0)
|
outputStream.channel.truncate(0)
|
||||||
while (!responseChannel.isClosedForRead) {
|
while (!responseChannel.isClosedForRead) {
|
||||||
if (!isActive) {
|
|
||||||
file.delete()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
val packet = responseChannel.readRemaining(DEFAULT_BUFFER_SIZE.toLong())
|
|
||||||
while (!packet.isEmpty) {
|
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
file.delete()
|
file.delete()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
val bytes = packet.readBytes()
|
val packet =
|
||||||
outputStream.write(bytes)
|
responseChannel.readRemaining(DEFAULT_BUFFER_SIZE.toLong())
|
||||||
|
while (!packet.isEmpty) {
|
||||||
|
if (!isActive) {
|
||||||
|
file.delete()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
readBytes += bytes.size
|
val bytes = packet.readBytes()
|
||||||
progressFlow.emit(readBytes / contentLength)
|
outputStream.write(bytes)
|
||||||
|
|
||||||
|
readBytes += bytes.size
|
||||||
|
progressFlow.emit(readBytes / contentLength)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
progressFlow.emit(Float.POSITIVE_INFINITY)
|
||||||
}
|
}
|
||||||
progressFlow.emit(Float.POSITIVE_INFINITY)
|
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
logger.warning(it)
|
logger.warning(it)
|
||||||
|
|||||||
Reference in New Issue
Block a user