Download gallery to the data folder not cache folder
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package="xyz.quaver.pupil">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -14,16 +15,6 @@
|
||||
android:theme="@style/AppTheme"
|
||||
android:name=".Pupil">
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="xyz.quaver.pupil.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths"/>
|
||||
</provider>
|
||||
|
||||
<activity android:name=".ReaderActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"/>
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
import com.arlib.floatingsearchview.FloatingSearchView
|
||||
@@ -359,10 +360,9 @@ class MainActivity : AppCompatActivity() {
|
||||
isEnabled = !(adapter as GalleryBlockAdapter).completeFlag.get(galleryBlock.id, false)
|
||||
setOnClickListener {
|
||||
val downloader = GalleryDownloader.get(galleryBlock.id)
|
||||
if (downloader == null) {
|
||||
if (downloader == null)
|
||||
GalleryDownloader(context, galleryBlock, true).start()
|
||||
downloads.add(galleryBlock.id)
|
||||
} else {
|
||||
else {
|
||||
downloader.cancel()
|
||||
downloader.clearNotification()
|
||||
}
|
||||
@@ -377,12 +377,25 @@ class MainActivity : AppCompatActivity() {
|
||||
this?.cancelAndJoin()
|
||||
this?.clearNotification()
|
||||
}
|
||||
val cache = File(cacheDir, "imageCache/${galleryBlock.id}/images/")
|
||||
val cache = File(cacheDir, "imageCache/${galleryBlock.id}")
|
||||
val data = File(ContextCompat.getDataDir(this@MainActivity), "images/${galleryBlock.id}")
|
||||
cache.deleteRecursively()
|
||||
data.deleteRecursively()
|
||||
|
||||
downloads.remove(galleryBlock.id)
|
||||
|
||||
if (mode == Mode.DOWNLOAD) {
|
||||
runOnUiThread {
|
||||
cancelFetch()
|
||||
clearGalleries()
|
||||
fetchGalleries(query)
|
||||
loadBlocks()
|
||||
}
|
||||
}
|
||||
|
||||
dialog.dismiss()
|
||||
(adapter as GalleryBlockAdapter).completeFlag.put(galleryBlock.id, false)
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
|
||||
@@ -68,16 +68,30 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
|
||||
//Check cache
|
||||
val readerCache = File(context.cacheDir, "imageCache/${gallery.id}/reader.json")
|
||||
val imageCache = File(context.cacheDir, "imageCache/${gallery.id}/images")
|
||||
val readerCache = {
|
||||
File(ContextCompat.getDataDir(context), "images/${gallery.id}/reader.json").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(context.cacheDir, "imageCache/${gallery.id}/reader.json")
|
||||
}
|
||||
}
|
||||
}
|
||||
val imageCache = {
|
||||
File(ContextCompat.getDataDir(context), "images/${gallery.id}/images").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(context.cacheDir, "imageCache/${gallery.id}/images")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (readerCache.exists()) {
|
||||
if (readerCache.invoke().exists()) {
|
||||
val reader = Json(JsonConfiguration.Stable)
|
||||
.parse(ReaderItem.serializer().list, readerCache.readText())
|
||||
.parse(ReaderItem.serializer().list, readerCache.invoke().readText())
|
||||
|
||||
with(galleryblock_progressbar) {
|
||||
max = reader.size
|
||||
progress = imageCache.list()?.size ?: 0
|
||||
progress = imageCache.invoke().list()?.size ?: 0
|
||||
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
@@ -89,9 +103,9 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
val refresh = Timer(false).schedule(0, 1000) {
|
||||
post {
|
||||
with(view.galleryblock_progressbar) {
|
||||
progress = imageCache.list()?.size ?: 0
|
||||
progress = imageCache.invoke().list()?.size ?: 0
|
||||
|
||||
if (!readerCache.exists()) {
|
||||
if (!readerCache.invoke().exists()) {
|
||||
visibility = View.GONE
|
||||
max = 0
|
||||
progress = 0
|
||||
@@ -100,7 +114,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
} else {
|
||||
if (visibility == View.GONE) {
|
||||
val reader = Json(JsonConfiguration.Stable)
|
||||
.parse(ReaderItem.serializer().list, readerCache.readText())
|
||||
.parse(ReaderItem.serializer().list, readerCache.invoke().readText())
|
||||
max = reader.size
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.util.SparseArray
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.app.TaskStackBuilder
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.io.IOException
|
||||
@@ -15,6 +16,7 @@ import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import kotlinx.serialization.list
|
||||
import xyz.quaver.hitomi.*
|
||||
import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.ReaderActivity
|
||||
import java.io.File
|
||||
@@ -31,16 +33,30 @@ class GalleryDownloader(
|
||||
_notify: Boolean = false
|
||||
) : ContextWrapper(base) {
|
||||
|
||||
val downloads = (applicationContext as Pupil).downloads
|
||||
|
||||
var download: Boolean = false
|
||||
set(value) {
|
||||
if (value) {
|
||||
field = true
|
||||
notificationManager.notify(galleryBlock.id, notificationBuilder.build())
|
||||
|
||||
val data = File(ContextCompat.getDataDir(this), "images/${galleryBlock.id}")
|
||||
val cache = File(cacheDir, "imageCache/${galleryBlock.id}")
|
||||
|
||||
if (cache.exists() && !data.exists()) {
|
||||
cache.copyRecursively(data, true)
|
||||
cache.deleteRecursively()
|
||||
}
|
||||
|
||||
if (!reader.isActive && downloadJob?.isActive != true)
|
||||
field = false
|
||||
|
||||
downloads.add(galleryBlock.id)
|
||||
} else {
|
||||
field = false
|
||||
|
||||
downloads.remove(galleryBlock.id)
|
||||
}
|
||||
|
||||
onNotifyChangedHandler?.invoke(value)
|
||||
@@ -74,7 +90,12 @@ class GalleryDownloader(
|
||||
val useHiyobi = preference.getBoolean("use_hiyobi", false)
|
||||
|
||||
//Check cache
|
||||
val cache = File(cacheDir, "imageCache/${galleryBlock.id}/reader.json")
|
||||
val cache = File(ContextCompat.getDataDir(this@GalleryDownloader), "images/${galleryBlock.id}/reader.json").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(cacheDir, "imageCache/${galleryBlock.id}/reader.json")
|
||||
}
|
||||
}
|
||||
|
||||
if (cache.exists()) {
|
||||
val cached = json.parse(serializer, cache.readText())
|
||||
@@ -148,7 +169,12 @@ class GalleryDownloader(
|
||||
val name = "$index".padStart(4, '0')
|
||||
val ext = url.split('.').last()
|
||||
|
||||
val cache = File(cacheDir, "/imageCache/${galleryBlock.id}/images/$name.$ext")
|
||||
val cache = File(ContextCompat.getDataDir(this@GalleryDownloader), "images/${galleryBlock.id}/images/$name.$ext").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(cacheDir, "/imageCache/${galleryBlock.id}/images/$name.$ext")
|
||||
}
|
||||
}
|
||||
|
||||
if (!cache.exists())
|
||||
try {
|
||||
@@ -163,6 +189,8 @@ class GalleryDownloader(
|
||||
} catch (e: Exception) {
|
||||
cache.delete()
|
||||
|
||||
downloads.remove(galleryBlock.id)
|
||||
|
||||
onErrorHandler?.invoke(e)
|
||||
|
||||
notificationBuilder
|
||||
@@ -189,8 +217,19 @@ class GalleryDownloader(
|
||||
.setContentText(getString(R.string.reader_notification_complete))
|
||||
.setProgress(0, 0, false)
|
||||
|
||||
if (download)
|
||||
if (download) {
|
||||
File(cacheDir, "imageCache/${galleryBlock.id}").let {
|
||||
if (it.exists()) {
|
||||
it.copyRecursively(
|
||||
File(ContextCompat.getDataDir(this@GalleryDownloader), "images/${galleryBlock.id}"),
|
||||
true
|
||||
)
|
||||
it.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
notificationManager.notify(galleryBlock.id, notificationBuilder.build())
|
||||
}
|
||||
|
||||
download = false
|
||||
}
|
||||
@@ -207,6 +246,8 @@ class GalleryDownloader(
|
||||
|
||||
suspend fun cancelAndJoin() {
|
||||
downloadJob?.cancelAndJoin()
|
||||
|
||||
remove(galleryBlock.id)
|
||||
}
|
||||
|
||||
fun invokeOnReaderLoaded() {
|
||||
|
||||
@@ -20,4 +20,12 @@
|
||||
android:text="@string/main_dialog_delete"
|
||||
app:layout_constraintTop_toBottomOf="@id/main_dialog_download"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/main_export"
|
||||
style="?borderlessButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/main_dialog_export"
|
||||
app:layout_constraintTop_toBottomOf="@id/main_dialog_delete"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -59,4 +59,5 @@
|
||||
<string name="main_move">%1$dページへ移動</string>
|
||||
<string name="https_block_alert_title">(Korean only)</string>
|
||||
<string name="https_block_alert">(Korean only)</string>
|
||||
<string name="main_dialog_export">ギャラリーエクスポート</string>
|
||||
</resources>
|
||||
@@ -59,4 +59,5 @@
|
||||
<string name="main_move">%1$d 페이지로 이동</string>
|
||||
<string name="https_block_alert_title">접속 불가 현상 안내</string>
|
||||
<string name="https_block_alert">최근 https 차단으로 접속이 안 되는 경우가 발생하고 있습니다\n이 경우 플레이스토어에서 SNIper앱을 이용하시면 정상이용이 가능합니다.</string>
|
||||
<string name="main_dialog_export">갤러리 저장</string>
|
||||
</resources>
|
||||
@@ -46,6 +46,7 @@
|
||||
<string name="main_move">Move to page %1$d</string>
|
||||
|
||||
<string name="main_dialog_delete">Delete this gallery</string>
|
||||
<string name="main_dialog_export">Export this gallery</string>
|
||||
|
||||
<string name="help_dialog_title">WIP</string>
|
||||
<string name="help_dialog_message">While in progress!</string>
|
||||
|
||||
Reference in New Issue
Block a user