[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("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")
|
||||
|
||||
|
||||
@@ -511,7 +511,9 @@ fun ReaderItem(
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
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 {
|
||||
imageSize == null -> Modifier.weight(1f).height(heightDp)
|
||||
@@ -527,7 +529,7 @@ fun ReaderItem(
|
||||
val progress = model.progressList.getOrNull(index) ?: 0f
|
||||
|
||||
if (progress == Float.NEGATIVE_INFINITY)
|
||||
Icon(Icons.Filled.BrokenImage, null, tint = Orange500)
|
||||
Icon(Icons.Filled.BrokenImage, null)
|
||||
else if (progress.isFinite())
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
|
||||
@@ -123,39 +123,44 @@ class NetworkCache(context: Context) : DIAware {
|
||||
|
||||
requests[url] = networkScope.launch {
|
||||
runCatching {
|
||||
cacheDir.mkdirs()
|
||||
file.createNewFile()
|
||||
if (file.exists()) {
|
||||
progressFlow.emit(Float.POSITIVE_INFINITY)
|
||||
} else {
|
||||
cacheDir.mkdirs()
|
||||
file.createNewFile()
|
||||
|
||||
client.request<HttpStatement>(request).execute { httpResponse ->
|
||||
if (!httpResponse.status.isSuccess()) throw IOException("${request.url} failed with code ${httpResponse.status.value}")
|
||||
val responseChannel: ByteReadChannel = httpResponse.receive()
|
||||
val contentLength = httpResponse.contentLength() ?: -1
|
||||
var readBytes = 0f
|
||||
client.request<HttpStatement>(request).execute { httpResponse ->
|
||||
if (!httpResponse.status.isSuccess()) throw IOException("${request.url} failed with code ${httpResponse.status.value}")
|
||||
val responseChannel: ByteReadChannel = httpResponse.receive()
|
||||
val contentLength = httpResponse.contentLength() ?: -1
|
||||
var readBytes = 0f
|
||||
|
||||
file.outputStream().use { outputStream ->
|
||||
outputStream.channel.truncate(0)
|
||||
while (!responseChannel.isClosedForRead) {
|
||||
if (!isActive) {
|
||||
file.delete()
|
||||
break
|
||||
}
|
||||
|
||||
val packet = responseChannel.readRemaining(DEFAULT_BUFFER_SIZE.toLong())
|
||||
while (!packet.isEmpty) {
|
||||
file.outputStream().use { outputStream ->
|
||||
outputStream.channel.truncate(0)
|
||||
while (!responseChannel.isClosedForRead) {
|
||||
if (!isActive) {
|
||||
file.delete()
|
||||
break
|
||||
}
|
||||
|
||||
val bytes = packet.readBytes()
|
||||
outputStream.write(bytes)
|
||||
val packet =
|
||||
responseChannel.readRemaining(DEFAULT_BUFFER_SIZE.toLong())
|
||||
while (!packet.isEmpty) {
|
||||
if (!isActive) {
|
||||
file.delete()
|
||||
break
|
||||
}
|
||||
|
||||
readBytes += bytes.size
|
||||
progressFlow.emit(readBytes / contentLength)
|
||||
val bytes = packet.readBytes()
|
||||
outputStream.write(bytes)
|
||||
|
||||
readBytes += bytes.size
|
||||
progressFlow.emit(readBytes / contentLength)
|
||||
}
|
||||
}
|
||||
}
|
||||
progressFlow.emit(Float.POSITIVE_INFINITY)
|
||||
}
|
||||
progressFlow.emit(Float.POSITIVE_INFINITY)
|
||||
}
|
||||
}.onFailure {
|
||||
logger.warning(it)
|
||||
|
||||
Reference in New Issue
Block a user