Fix page saving
This commit is contained in:
17
.idea/deploymentTargetDropDown.xml
generated
Normal file
17
.idea/deploymentTargetDropDown.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Pixel_API_S.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2021-02-19T19:02:37.198775Z" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -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'
|
||||
|
||||
@@ -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<OkHttpClient>().newCall(request).await().use { response ->
|
||||
val fileName =
|
||||
URLUtil.guessFileName(
|
||||
pageUrl,
|
||||
response.contentDisposition,
|
||||
response.mimeType
|
||||
)
|
||||
val file = get<PagesCache>()[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)
|
||||
|
||||
Reference in New Issue
Block a user