From 40f27ae634c58871d308b902dc93c136d0127fc9 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Thu, 25 Feb 2021 20:10:38 +0200 Subject: [PATCH] Fix page saving --- .idea/deploymentTargetDropDown.xml | 17 +++++++++++++++ app/build.gradle | 6 +++--- .../kotatsu/reader/ui/ReaderViewModel.kt | 21 +++++-------------- 3 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 000000000..27370aa28 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 0eb291004..d806ee47b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,7 +16,7 @@ android { minSdkVersion 21 targetSdkVersion 30 versionCode gitCommits - versionName '1.0-rc1' + versionName '1.0-rc2' kapt { arguments { @@ -66,7 +66,7 @@ dependencies { implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2' - implementation 'androidx.core:core-ktx:1.5.0-beta01' + implementation 'androidx.core:core-ktx:1.5.0-beta02' implementation 'androidx.activity:activity-ktx:1.2.0' implementation 'androidx.fragment:fragment-ktx:1.3.0' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0' @@ -76,7 +76,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-process:2.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - implementation 'androidx.recyclerview:recyclerview:1.2.0-beta01' + implementation 'androidx.recyclerview:recyclerview:1.2.0-beta02' implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01' implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.work:work-runtime-ktx:2.5.0' diff --git a/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt b/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt index a49931ffb..573f9c878 100644 --- a/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt +++ b/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt @@ -8,8 +8,6 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import kotlinx.coroutines.* import kotlinx.coroutines.flow.* -import okhttp3.OkHttpClient -import okhttp3.Request import org.koin.core.component.KoinComponent import org.koin.core.component.get import org.koitharu.kotatsu.base.domain.MangaDataRepository @@ -20,11 +18,11 @@ import org.koitharu.kotatsu.core.exceptions.MangaNotFoundException import org.koitharu.kotatsu.core.model.Manga import org.koitharu.kotatsu.core.model.MangaChapter import org.koitharu.kotatsu.core.model.MangaPage -import org.koitharu.kotatsu.core.network.CommonHeaders import org.koitharu.kotatsu.core.os.ShortcutsRepository import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.ReaderMode import org.koitharu.kotatsu.history.domain.HistoryRepository +import org.koitharu.kotatsu.local.data.PagesCache import org.koitharu.kotatsu.reader.ui.pager.ReaderPage import org.koitharu.kotatsu.reader.ui.pager.ReaderUiState import org.koitharu.kotatsu.utils.MediaStoreCompat @@ -156,20 +154,11 @@ class ReaderViewModel( }?.toMangaPage() ?: error("Page not found") val repo = page.source.repository val pageUrl = repo.getPageUrl(page) - val request = Request.Builder() - .url(pageUrl) - .header(CommonHeaders.REFERER, page.referer) - .get() - .build() - val uri = get().newCall(request).await().use { response -> - val fileName = - URLUtil.guessFileName( - pageUrl, - response.contentDisposition, - response.mimeType - ) + val file = get()[pageUrl] ?: error("Page not found in cache") + val uri = file.inputStream().use { input -> + val fileName = URLUtil.guessFileName(pageUrl, null, null) MediaStoreCompat(resolver).insertImage(fileName) { - checkNotNull(response.body).byteStream().copyTo(it) + input.copyTo(it) } } onPageSaved.postCall(uri)