Made download simple
Bug fixed
This commit is contained in:
@@ -6,7 +6,6 @@ import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.preference.PreferenceManager
|
||||
import android.text.*
|
||||
import android.text.style.AlignmentSpan
|
||||
@@ -32,7 +31,6 @@ import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.activity_main_content.*
|
||||
import kotlinx.android.synthetic.main.dialog_galleryblock.view.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.io.IOException
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
@@ -48,12 +46,9 @@ import xyz.quaver.pupil.types.TagSuggestion
|
||||
import xyz.quaver.pupil.types.Tags
|
||||
import xyz.quaver.pupil.util.*
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.math.roundToInt
|
||||
@@ -417,7 +412,7 @@ class MainActivity : AppCompatActivity() {
|
||||
this?.clearNotification()
|
||||
}
|
||||
val cache = File(cacheDir, "imageCache/${galleryBlock.id}")
|
||||
val data = File(ContextCompat.getDataDir(this@MainActivity), "images/${galleryBlock.id}")
|
||||
val data = getCachedGallery(context, galleryBlock.id)
|
||||
cache.deleteRecursively()
|
||||
data.deleteRecursively()
|
||||
|
||||
@@ -437,73 +432,6 @@ class MainActivity : AppCompatActivity() {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
with(view.main_dialog_export) {
|
||||
val images = File(ContextCompat.getDataDir(this@MainActivity), "images/${galleryBlock.id}/images").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(cacheDir, "imageCache/${galleryBlock.id}/images")
|
||||
}
|
||||
}
|
||||
isEnabled = images.exists()
|
||||
|
||||
setOnClickListener {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val preference = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val zip = preference.getBoolean("export_zip", false)
|
||||
|
||||
if (zip) {
|
||||
var target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id} ${galleryBlock.title}.zip")
|
||||
|
||||
try {
|
||||
target.createNewFile()
|
||||
} catch (e: IOException) {
|
||||
target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id}.zip")
|
||||
|
||||
try {
|
||||
target.createNewFile()
|
||||
} catch (e: IOException) {
|
||||
Snackbar.make(main_layout, getString(R.string.main_export_error), Snackbar.LENGTH_LONG).show()
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
||||
FileOutputStream(target).use { targetStream ->
|
||||
ZipOutputStream(targetStream).use {zipStream ->
|
||||
images.listFiles().forEach {
|
||||
zipStream.putNextEntry(ZipEntry(it.name))
|
||||
|
||||
FileInputStream(it).use { fileStream ->
|
||||
fileStream.copyTo(zipStream)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id} ${galleryBlock.title}")
|
||||
|
||||
try {
|
||||
target.canonicalPath
|
||||
} catch (e: IOException) {
|
||||
target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id}")
|
||||
|
||||
try {
|
||||
target.canonicalPath
|
||||
} catch (e: IOException) {
|
||||
Snackbar.make(main_layout, getString(R.string.main_export_error), Snackbar.LENGTH_LONG).show()
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
||||
images.copyRecursively(target, true)
|
||||
}
|
||||
|
||||
Snackbar.make(main_layout, getString(R.string.main_export_complete), Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
|
||||
true
|
||||
@@ -1064,18 +992,18 @@ class MainActivity : AppCompatActivity() {
|
||||
galleryIDs.slice(currentPage*perPage until Math.min(currentPage*perPage+perPage, galleryIDs.size))
|
||||
}.chunked(5).let { chunks ->
|
||||
for (chunk in chunks)
|
||||
chunk.map {
|
||||
chunk.map { galleryID ->
|
||||
async {
|
||||
try {
|
||||
val json = Json(JsonConfiguration.Stable)
|
||||
val serializer = GalleryBlock.serializer()
|
||||
|
||||
val galleryBlock =
|
||||
File(cacheDir, "imageCache/$it/galleryBlock.json").let { cache ->
|
||||
File(getCachedGallery(this@MainActivity, galleryID), "galleryBlock.json").let { cache ->
|
||||
when {
|
||||
cache.exists() -> json.parse(serializer, cache.readText())
|
||||
else -> {
|
||||
getGalleryBlock(it).apply {
|
||||
getGalleryBlock(galleryID).apply {
|
||||
this ?: return@apply
|
||||
|
||||
if (!cache.parentFile.exists())
|
||||
@@ -1089,19 +1017,17 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
val thumbnail = async {
|
||||
val ext = galleryBlock.thumbnails[0].split('.').last()
|
||||
File(cacheDir, "imageCache/$it/thumbnail.$ext").apply {
|
||||
val cache = this
|
||||
|
||||
if (!cache.exists())
|
||||
File(getCachedGallery(this@MainActivity, galleryBlock.id), "thumbnail.$ext").apply {
|
||||
if (!exists())
|
||||
try {
|
||||
with(URL(galleryBlock.thumbnails[0]).openConnection() as HttpsURLConnection) {
|
||||
if (!cache.parentFile.exists())
|
||||
cache.parentFile.mkdirs()
|
||||
if (!this@apply.parentFile.exists())
|
||||
this@apply.parentFile.mkdirs()
|
||||
|
||||
inputStream.copyTo(FileOutputStream(cache))
|
||||
inputStream.copyTo(FileOutputStream(this@apply))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
cache.delete()
|
||||
delete()
|
||||
}
|
||||
}.absolutePath
|
||||
}
|
||||
|
||||
@@ -309,14 +309,6 @@ class ReaderActivity : AppCompatActivity() {
|
||||
if (!downloader.download)
|
||||
downloader.clearNotification()
|
||||
}
|
||||
|
||||
reader_fab_export.setOnClickListener {
|
||||
downloader.export( {
|
||||
Snackbar.make(reader_layout, getString(R.string.main_export_complete), Snackbar.LENGTH_LONG).show()
|
||||
}, {
|
||||
Snackbar.make(reader_layout, getString(R.string.main_export_error), Snackbar.LENGTH_LONG).show()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun fullscreen(isFullscreen: Boolean) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package xyz.quaver.pupil
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.preference.PreferenceManager
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
@@ -12,7 +13,6 @@ import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import kotlinx.android.synthetic.main.dialog_default_query.view.*
|
||||
@@ -67,39 +67,16 @@ class SettingsActivity : AppCompatActivity() {
|
||||
suffixIndex++
|
||||
}
|
||||
|
||||
return getString(R.string.settings_clear_cache_summary, size, suffix[suffixIndex])
|
||||
return getString(R.string.settings_clear_downloads_summary, size, suffix[suffixIndex])
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||
|
||||
with(findPreference<Preference>("delete_image_cache")) {
|
||||
this ?: return@with
|
||||
|
||||
val dir = File(context.cacheDir, "imageCache")
|
||||
|
||||
summary = getCacheSize(dir)
|
||||
|
||||
setOnPreferenceClickListener {
|
||||
AlertDialog.Builder(context).apply {
|
||||
setTitle(R.string.warning)
|
||||
setMessage(R.string.settings_clear_cache_alert_message)
|
||||
setPositiveButton(android.R.string.yes) { _, _ ->
|
||||
if (dir.exists())
|
||||
dir.deleteRecursively()
|
||||
|
||||
summary = getCacheSize(dir)
|
||||
}
|
||||
setNegativeButton(android.R.string.no) { _, _ -> }
|
||||
}.show()
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
with(findPreference<Preference>("delete_downloads")) {
|
||||
this ?: return@with
|
||||
|
||||
val dir = File(ContextCompat.getDataDir(context), "images")
|
||||
val dir = File(Environment.getExternalStorageDirectory(), "Pupil")
|
||||
|
||||
summary = getCacheSize(dir)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.AlertDialog
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import android.util.SparseBooleanArray
|
||||
import android.view.LayoutInflater
|
||||
@@ -31,6 +32,7 @@ import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.types.Tag
|
||||
import xyz.quaver.pupil.util.Histories
|
||||
import xyz.quaver.pupil.util.getCachedGallery
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
@@ -57,10 +59,10 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
}.toMap()
|
||||
|
||||
val (gallery: GalleryBlock, thumbnail: Deferred<String>) = item
|
||||
val (galleryBlock: GalleryBlock, thumbnail: Deferred<String>) = item
|
||||
|
||||
val artists = gallery.artists
|
||||
val series = gallery.series
|
||||
val artists = galleryBlock.artists
|
||||
val series = galleryBlock.series
|
||||
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val cache = thumbnail.await()
|
||||
@@ -68,10 +70,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
if (!File(cache).exists())
|
||||
return@launch
|
||||
|
||||
val bitmap = when {
|
||||
BuildConfig.DEBUG -> Bitmap.createScaledBitmap(BitmapFactory.decodeFile(thumbnail.await()), 5, 8, true)
|
||||
else -> BitmapFactory.decodeFile(thumbnail.await())
|
||||
}
|
||||
val bitmap = BitmapFactory.decodeFile(thumbnail.await())
|
||||
|
||||
post {
|
||||
galleryblock_thumbnail.setImageBitmap(bitmap)
|
||||
@@ -79,22 +78,8 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
|
||||
//Check cache
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
val readerCache = { File(getCachedGallery(context, galleryBlock.id), "reader.json") }
|
||||
val imageCache = { File(getCachedGallery(context, galleryBlock.id), "images") }
|
||||
|
||||
if (readerCache.invoke().exists()) {
|
||||
val reader = Json(JsonConfiguration.Stable)
|
||||
@@ -131,7 +116,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
|
||||
if (progress == max) {
|
||||
if (completeFlag.get(gallery.id, false)) {
|
||||
if (completeFlag.get(galleryBlock.id, false)) {
|
||||
with(view.galleryblock_progress_complete) {
|
||||
setImageResource(R.drawable.ic_progressbar)
|
||||
visibility = View.VISIBLE
|
||||
@@ -143,7 +128,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
drawable?.start()
|
||||
completeFlag.put(gallery.id, true)
|
||||
completeFlag.put(galleryBlock.id, true)
|
||||
}
|
||||
} else
|
||||
view.galleryblock_progress_complete.visibility = View.INVISIBLE
|
||||
@@ -157,7 +142,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
refreshTasks[this@GalleryViewHolder] = refresh
|
||||
}
|
||||
|
||||
galleryblock_title.text = gallery.title
|
||||
galleryblock_title.text = galleryBlock.title
|
||||
with(galleryblock_artist) {
|
||||
text = artists.joinToString(", ") { it.wordCapitalize() }
|
||||
visibility = when {
|
||||
@@ -204,31 +189,31 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
}
|
||||
with(galleryblock_type) {
|
||||
text = resources.getString(R.string.galleryblock_type, gallery.type).wordCapitalize()
|
||||
text = resources.getString(R.string.galleryblock_type, galleryBlock.type).wordCapitalize()
|
||||
setOnClickListener {
|
||||
setOnClickListener {
|
||||
for(callback in onChipClickedHandler)
|
||||
callback.invoke(Tag("type", gallery.type))
|
||||
callback.invoke(Tag("type", galleryBlock.type))
|
||||
}
|
||||
}
|
||||
}
|
||||
with(galleryblock_language) {
|
||||
text =
|
||||
resources.getString(R.string.galleryblock_language, languages[gallery.language])
|
||||
resources.getString(R.string.galleryblock_language, languages[galleryBlock.language])
|
||||
visibility = when {
|
||||
gallery.language.isNotEmpty() -> View.VISIBLE
|
||||
galleryBlock.language.isNotEmpty() -> View.VISIBLE
|
||||
else -> View.GONE
|
||||
}
|
||||
setOnClickListener {
|
||||
setOnClickListener {
|
||||
for(callback in onChipClickedHandler)
|
||||
callback.invoke(Tag("language", gallery.language))
|
||||
callback.invoke(Tag("language", galleryBlock.language))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
galleryblock_tag_group.removeAllViews()
|
||||
gallery.relatedTags.forEach {
|
||||
galleryBlock.relatedTags.forEach {
|
||||
val tag = Tag.parse(it).let { tag ->
|
||||
when {
|
||||
tag.area != null -> tag
|
||||
@@ -263,19 +248,19 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
galleryblock_tag_group.addView(chip)
|
||||
}
|
||||
|
||||
galleryblock_id.text = gallery.id.toString()
|
||||
galleryblock_id.text = galleryBlock.id.toString()
|
||||
|
||||
if (!::favorites.isInitialized)
|
||||
favorites = (context.applicationContext as Pupil).favorites
|
||||
|
||||
with(galleryblock_favorite) {
|
||||
post {
|
||||
isChecked = favorites.contains(gallery.id)
|
||||
isChecked = favorites.contains(galleryBlock.id)
|
||||
}
|
||||
setOnClickListener {
|
||||
when {
|
||||
isChecked -> favorites.add(gallery.id)
|
||||
else -> favorites.remove(gallery.id)
|
||||
isChecked -> favorites.add(galleryBlock.id)
|
||||
else -> favorites.remove(galleryBlock.id)
|
||||
}
|
||||
}
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
|
||||
@@ -38,10 +38,7 @@ class ReaderAdapter(private val images: List<String>) : RecyclerView.Adapter<Rea
|
||||
|
||||
options.inJustDecodeBounds = false
|
||||
|
||||
val image = when {
|
||||
BuildConfig.DEBUG -> Bitmap.createScaledBitmap(BitmapFactory.decodeFile(images[position], options), 5, 8, true)
|
||||
else -> BitmapFactory.decodeFile(images[position], options)
|
||||
}
|
||||
val image = BitmapFactory.decodeFile(images[position], options)
|
||||
|
||||
post { setImageBitmap(image) }
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ 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
|
||||
@@ -23,12 +22,9 @@ import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.ReaderActivity
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.concurrent.schedule
|
||||
@@ -48,7 +44,12 @@ class GalleryDownloader(
|
||||
field = true
|
||||
notificationManager.notify(galleryBlock.id, notificationBuilder.build())
|
||||
|
||||
val data = File(ContextCompat.getDataDir(this), "images/${galleryBlock.id}")
|
||||
val data = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id} ${galleryBlock.title}").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id}")
|
||||
}
|
||||
}
|
||||
val cache = File(cacheDir, "imageCache/${galleryBlock.id}")
|
||||
|
||||
if (cache.exists() && !data.exists()) {
|
||||
@@ -93,12 +94,7 @@ class GalleryDownloader(
|
||||
val serializer = ReaderItem.serializer().list
|
||||
|
||||
//Check cache
|
||||
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")
|
||||
}
|
||||
}
|
||||
val cache = File(getCachedGallery(this@GalleryDownloader, galleryBlock.id), "reader.json")
|
||||
|
||||
if (cache.exists()) {
|
||||
val cached = json.parse(serializer, cache.readText())
|
||||
@@ -181,12 +177,7 @@ class GalleryDownloader(
|
||||
val name = "$index".padStart(4, '0')
|
||||
val ext = url.split('.').last()
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
val cache = File(getCachedGallery(this@GalleryDownloader, galleryBlock.id), "images/$name.$ext")
|
||||
|
||||
if (!cache.exists())
|
||||
try {
|
||||
@@ -234,31 +225,17 @@ class GalleryDownloader(
|
||||
if (download) {
|
||||
File(cacheDir, "imageCache/${galleryBlock.id}").let {
|
||||
if (it.exists()) {
|
||||
it.copyRecursively(
|
||||
File(ContextCompat.getDataDir(this@GalleryDownloader), "images/${galleryBlock.id}"),
|
||||
true
|
||||
)
|
||||
val target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id}")
|
||||
|
||||
if (!target.exists())
|
||||
target.mkdirs()
|
||||
|
||||
it.copyRecursively(target, true)
|
||||
it.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
val preference = PreferenceManager.getDefaultSharedPreferences(this@GalleryDownloader)
|
||||
val autoExport = preference.getBoolean("auto_export", false)
|
||||
|
||||
if (autoExport) {
|
||||
export({
|
||||
notificationManager.notify(galleryBlock.id, notificationBuilder.build())
|
||||
}, {
|
||||
notificationBuilder
|
||||
.setContentTitle(galleryBlock.title)
|
||||
.setContentText(getString(R.string.main_export_error))
|
||||
.setProgress(0, 0, false)
|
||||
|
||||
notificationManager.notify(galleryBlock.id, notificationBuilder.build())
|
||||
})
|
||||
} else {
|
||||
notificationManager.notify(galleryBlock.id, notificationBuilder.build())
|
||||
}
|
||||
notificationManager.notify(galleryBlock.id, notificationBuilder.build())
|
||||
}
|
||||
|
||||
download = false
|
||||
@@ -314,69 +291,4 @@ class GalleryDownloader(
|
||||
notificationManager = NotificationManagerCompat.from(this)
|
||||
}
|
||||
|
||||
fun export(onSuccess: (() -> Unit)? = null, onError: (() -> Unit)? = null) {
|
||||
val images = File(ContextCompat.getDataDir(this), "images/${galleryBlock.id}/images").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(cacheDir, "imageCache/${galleryBlock.id}/images")
|
||||
}
|
||||
}
|
||||
|
||||
if (!images.exists())
|
||||
return
|
||||
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val preference = PreferenceManager.getDefaultSharedPreferences(this@GalleryDownloader)
|
||||
val zip = preference.getBoolean("export_zip", false)
|
||||
|
||||
if (zip) {
|
||||
var target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id} ${galleryBlock.title}.zip")
|
||||
|
||||
try {
|
||||
target.createNewFile()
|
||||
} catch (e: IOException) {
|
||||
target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id}.zip")
|
||||
|
||||
try {
|
||||
target.createNewFile()
|
||||
} catch (e: IOException) {
|
||||
onError?.invoke()
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
||||
FileOutputStream(target).use { targetStream ->
|
||||
ZipOutputStream(targetStream).use { zipStream ->
|
||||
images.listFiles().forEach {
|
||||
zipStream.putNextEntry(ZipEntry(it.name))
|
||||
|
||||
FileInputStream(it).use { fileStream ->
|
||||
fileStream.copyTo(zipStream)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id} ${galleryBlock.title}")
|
||||
|
||||
try {
|
||||
target.canonicalPath
|
||||
} catch (e: IOException) {
|
||||
target = File(Environment.getExternalStorageDirectory(), "Pupil/${galleryBlock.id}")
|
||||
|
||||
try {
|
||||
target.canonicalPath
|
||||
} catch (e: IOException) {
|
||||
onError?.invoke()
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
||||
images.copyRecursively(target, true)
|
||||
}
|
||||
|
||||
onSuccess?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
app/src/main/java/xyz/quaver/pupil/util/file.kt
Normal file
14
app/src/main/java/xyz/quaver/pupil/util/file.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package xyz.quaver.pupil.util
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import java.io.File
|
||||
|
||||
fun getCachedGallery(context: Context, galleryID: Int): File {
|
||||
return File(Environment.getExternalStorageDirectory(), "Pupil/$galleryID").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(context.cacheDir, "imageCache/$galleryID")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,14 +51,6 @@
|
||||
app:fab_label="@string/reader_fab_download"
|
||||
app:fab_size="mini"/>
|
||||
|
||||
<com.github.clans.fab.FloatingActionButton
|
||||
android:id="@+id/reader_fab_export"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_export"
|
||||
app:fab_label="@string/main_dialog_export"
|
||||
app:fab_size="mini"/>
|
||||
|
||||
<com.github.clans.fab.FloatingActionButton
|
||||
android:id="@+id/reader_fab_fullscreen"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -20,12 +20,4 @@
|
||||
android:text="@string/main_dialog_delete"
|
||||
app:layout_constraintTop_toBottomOf="@id/main_dialog_download"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/main_dialog_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>
|
||||
@@ -7,10 +7,8 @@
|
||||
<string name="main_search">検索</string>
|
||||
<string name="search_hint">ギャラリー検索</string>
|
||||
<string name="search_hint_with_page">ギャラリー検索</string>
|
||||
<string name="settings_cache_title">キャッシュ</string>
|
||||
<string name="settings_clear_image_cache">イメージキャッシュクリア</string>
|
||||
<string name="settings_clear_cache_alert_message">キャッシュをクリアするとイメージのロード速度に影響を与えます。\n実行しますか?</string>
|
||||
<string name="settings_clear_cache_summary">サイズ: %1$d%2$s</string>
|
||||
<string name="settings_clear_downloads_summary">サイズ: %1$d%2$s</string>
|
||||
<string name="settings_default_query">デフォルトキーワード</string>
|
||||
<string name="settings_galleries_per_page">一回にロードするギャラリー数</string>
|
||||
<string name="settings_search_title">検索設定</string>
|
||||
@@ -60,14 +58,11 @@
|
||||
<string name="main_export_complete">エクスポート完了</string>
|
||||
<string name="main_export_open_folder">フォルダを開く</string>
|
||||
<string name="main_export_error">エクスポートエラーが発生しました</string>
|
||||
<string name="settings_export_zip_title">zipエクスポート</string>
|
||||
<string name="settings_export_zip_summary">イメージフォルダの代わりzipファイルでエクスポート</string>
|
||||
<string name="settings_auto_export_title">自動エクスポート</string>
|
||||
<string name="settings_auto_export_summary">ダウンロード完了後自動的にエクスポート</string>
|
||||
<string name="settings_clear_downloads">ダウンロード削除</string>
|
||||
<string name="settings_clear_downloads_alert_message">ダウンロードしたギャラリーを全て削除します。\n実行しますか?</string>
|
||||
<string name="settings_use_hiyobi_summary">ロード速度を向上させるため可能であればhiyobi.meからイメージロード</string>
|
||||
<string name="main_drawer_favorite">お気に入り</string>
|
||||
<string name="main_open_gallery_by_id">ギャラリー番号で見る</string>
|
||||
<string name="main_open_gallery_by_id_error">エラーが発生しました</string>
|
||||
<string name="settings_storage">ストレージ</string>
|
||||
</resources>
|
||||
@@ -7,8 +7,7 @@
|
||||
<string name="search_hint_with_page">갤러리 검색</string>
|
||||
<string name="settings_default_query">기본 검색어</string>
|
||||
<string name="settings_clear_image_cache">이미지 캐시 정리하기</string>
|
||||
<string name="settings_clear_cache_alert_message">캐시를 정리하면 이미지 로딩속도가 느려질 수 있습니다.\n계속하시겠습니까?</string>
|
||||
<string name="settings_clear_cache_summary">사용량: %1$d%2$s</string>
|
||||
<string name="settings_clear_downloads_summary">사용량: %1$d%2$s</string>
|
||||
<string name="settings_galleries_per_page">한 번에 로드할 갤러리 수</string>
|
||||
<string name="settings_search_title">검색 설정</string>
|
||||
<string name="settings_title">설정</string>
|
||||
@@ -17,7 +16,6 @@
|
||||
<string name="warning">경고</string>
|
||||
<string name="main_no_result">결과 없음</string>
|
||||
<string name="main_search">검색</string>
|
||||
<string name="settings_cache_title">캐시</string>
|
||||
<string name="settings_miscellaneous_title">기타</string>
|
||||
<string name="settings_use_hiyobi_title">hiyobi.me 사용</string>
|
||||
<string name="settings_clear_history">기록 삭제</string>
|
||||
@@ -60,14 +58,11 @@
|
||||
<string name="main_export_complete">내보내기 완료</string>
|
||||
<string name="main_export_open_folder">폴더 열기</string>
|
||||
<string name="main_export_error">내보내기 오류가 발생했습니다</string>
|
||||
<string name="settings_export_zip_title">zip 파일로 내보내기</string>
|
||||
<string name="settings_export_zip_summary">이미지 폴더 대신 zip 파일로 내보내기</string>
|
||||
<string name="settings_auto_export_title">자동 내보내기</string>
|
||||
<string name="settings_auto_export_summary">다운로드가 끝난 후 자동 내보내기</string>
|
||||
<string name="settings_clear_downloads">다운로드 삭제</string>
|
||||
<string name="settings_clear_downloads_alert_message">다운로드 된 만화를 모두 삭제합니다.\n계속하시겠습니까?</string>
|
||||
<string name="settings_use_hiyobi_summary">속도 향상을 위해 가능하면 hiyobi.me에서 이미지 로드</string>
|
||||
<string name="main_drawer_favorite">즐겨찾기</string>
|
||||
<string name="main_open_gallery_by_id">갤러리 번호로 열기</string>
|
||||
<string name="main_open_gallery_by_id_error">갤러리를 찾지 못했습니다</string>
|
||||
<string name="settings_storage">저장 공간</string>
|
||||
</resources>
|
||||
@@ -81,10 +81,9 @@
|
||||
<string name="settings_search_title">Search Settings</string>
|
||||
<string name="settings_galleries_per_page">Galleries per page</string>
|
||||
<string name="settings_default_query">Default query</string>
|
||||
<string name="settings_cache_title">Cache</string>
|
||||
<string name="settings_storage">Storage</string>
|
||||
<string name="settings_clear_image_cache">Clear image cache</string>
|
||||
<string name="settings_clear_cache_summary">Currently using %1$d%2$s</string>
|
||||
<string name="settings_clear_cache_alert_message">Deleting cache can affect image loading speed.\nDo you want to continue?</string>
|
||||
<string name="settings_clear_downloads_summary">Currently using %1$d%2$s</string>
|
||||
<string name="settings_clear_downloads">Clear downloads</string>
|
||||
<string name="settings_clear_downloads_alert_message">Delete all downloaded galleries.\nDo you want to continue?</string>
|
||||
<string name="settings_clear_history">Clear history</string>
|
||||
@@ -93,10 +92,6 @@
|
||||
<string name="settings_miscellaneous_title">Miscellaneous</string>
|
||||
<string name="settings_use_hiyobi_title">Use hiyobi.me</string>
|
||||
<string name="settings_use_hiyobi_summary">Load images from hiyobi.me to improve loading speed (if available)</string>
|
||||
<string name="settings_export_zip_title">Export zip</string>
|
||||
<string name="settings_export_zip_summary">Export to zip instead of image folder</string>
|
||||
<string name="settings_auto_export_title">Auto Export</string>
|
||||
<string name="settings_auto_export_summary">Automatically exports galleries when download is finished</string>
|
||||
<string name="settings_security_mode_title">Enable security mode</string>
|
||||
<string name="settings_security_mode_summary">Enable security mode to make the screen invisible on recent app window</string>
|
||||
|
||||
|
||||
@@ -22,11 +22,7 @@
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
app:title="@string/settings_cache_title">
|
||||
|
||||
<Preference
|
||||
app:title="@string/settings_clear_image_cache"
|
||||
app:key="delete_image_cache"/>
|
||||
app:title="@string/settings_storage">
|
||||
|
||||
<Preference
|
||||
app:title="@string/settings_clear_downloads"
|
||||
@@ -46,16 +42,6 @@
|
||||
app:title="@string/settings_use_hiyobi_title"
|
||||
app:summary="@string/settings_use_hiyobi_summary"/>
|
||||
|
||||
<SwitchPreference
|
||||
app:key="export_zip"
|
||||
app:title="@string/settings_export_zip_title"
|
||||
app:summary="@string/settings_export_zip_summary"/>
|
||||
|
||||
<SwitchPreference
|
||||
app:key="auto_export"
|
||||
app:title="@string/settings_auto_export_title"
|
||||
app:summary="@string/settings_auto_export_summary"/>
|
||||
|
||||
<SwitchPreference
|
||||
app:key="security_mode"
|
||||
app:title="@string/settings_security_mode_title"
|
||||
|
||||
Reference in New Issue
Block a user