Fixed crash when download folder is changed
This commit is contained in:
@@ -20,7 +20,7 @@ android {
|
|||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 57
|
versionCode 57
|
||||||
versionName "4.21-hotfix1"
|
versionName "5.0-alpha1"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ import xyz.quaver.pupil.favorites
|
|||||||
import xyz.quaver.pupil.types.Tag
|
import xyz.quaver.pupil.types.Tag
|
||||||
import xyz.quaver.pupil.util.Preferences
|
import xyz.quaver.pupil.util.Preferences
|
||||||
import xyz.quaver.pupil.util.downloader.Cache
|
import xyz.quaver.pupil.util.downloader.Cache
|
||||||
import xyz.quaver.pupil.util.downloader.DownloadFolderManager
|
import xyz.quaver.pupil.util.downloader.DownloadManager
|
||||||
import xyz.quaver.pupil.util.wordCapitalize
|
import xyz.quaver.pupil.util.wordCapitalize
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
@@ -94,7 +94,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (progress == max) {
|
if (progress == max) {
|
||||||
val downloadManager = DownloadFolderManager.getInstance(context)
|
val downloadManager = DownloadManager.getInstance(context)
|
||||||
|
|
||||||
if (completeFlag.get(galleryID, false)) {
|
if (completeFlag.get(galleryID, false)) {
|
||||||
with(view.galleryblock_progress_complete) {
|
with(view.galleryblock_progress_complete) {
|
||||||
@@ -357,7 +357,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
|||||||
mItemManger.closeAllExcept(layout)
|
mItemManger.closeAllExcept(layout)
|
||||||
|
|
||||||
holder.view.galleryblock_download.text =
|
holder.view.galleryblock_download.text =
|
||||||
if (DownloadFolderManager.getInstance(holder.view.context).isDownloading(galleryID))
|
if (DownloadManager.getInstance(holder.view.context).isDownloading(galleryID))
|
||||||
holder.view.context.getString(android.R.string.cancel)
|
holder.view.context.getString(android.R.string.cancel)
|
||||||
else
|
else
|
||||||
holder.view.context.getString(R.string.main_download)
|
holder.view.context.getString(R.string.main_download)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import android.app.PendingIntent
|
|||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.util.Log
|
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
@@ -43,7 +42,7 @@ import xyz.quaver.pupil.client
|
|||||||
import xyz.quaver.pupil.interceptors
|
import xyz.quaver.pupil.interceptors
|
||||||
import xyz.quaver.pupil.ui.ReaderActivity
|
import xyz.quaver.pupil.ui.ReaderActivity
|
||||||
import xyz.quaver.pupil.util.downloader.Cache
|
import xyz.quaver.pupil.util.downloader.Cache
|
||||||
import xyz.quaver.pupil.util.downloader.DownloadFolderManager
|
import xyz.quaver.pupil.util.downloader.DownloadManager
|
||||||
import xyz.quaver.pupil.util.ellipsize
|
import xyz.quaver.pupil.util.ellipsize
|
||||||
import xyz.quaver.pupil.util.normalizeID
|
import xyz.quaver.pupil.util.normalizeID
|
||||||
import xyz.quaver.pupil.util.requestBuilders
|
import xyz.quaver.pupil.util.requestBuilders
|
||||||
@@ -121,7 +120,7 @@ class DownloadService : Service() {
|
|||||||
.setProgress(max, progress, false)
|
.setProgress(max, progress, false)
|
||||||
.setContentText("$progress/$max")
|
.setContentText("$progress/$max")
|
||||||
|
|
||||||
if (DownloadFolderManager.getInstance(this).getDownloadFolder(galleryID) != null)
|
if (DownloadManager.getInstance(this).getDownloadFolder(galleryID) != null)
|
||||||
notification.let { notificationManager.notify(galleryID, it.build()) }
|
notification.let { notificationManager.notify(galleryID, it.build()) }
|
||||||
else
|
else
|
||||||
notificationManager.cancel(galleryID)
|
notificationManager.cancel(galleryID)
|
||||||
@@ -226,7 +225,7 @@ class DownloadService : Service() {
|
|||||||
notify(galleryID)
|
notify(galleryID)
|
||||||
|
|
||||||
if (isCompleted(galleryID)) {
|
if (isCompleted(galleryID)) {
|
||||||
if (DownloadFolderManager.getInstance(this@DownloadService)
|
if (DownloadManager.getInstance(this@DownloadService)
|
||||||
.getDownloadFolder(galleryID) != null)
|
.getDownloadFolder(galleryID) != null)
|
||||||
Cache.getInstance(this@DownloadService, galleryID).moveToDownload()
|
Cache.getInstance(this@DownloadService, galleryID).moveToDownload()
|
||||||
|
|
||||||
@@ -279,7 +278,7 @@ class DownloadService : Service() {
|
|||||||
|
|
||||||
fun delete(galleryID: Int, startId: Int? = null) = CoroutineScope(Dispatchers.IO).launch {
|
fun delete(galleryID: Int, startId: Int? = null) = CoroutineScope(Dispatchers.IO).launch {
|
||||||
cancel(galleryID)
|
cancel(galleryID)
|
||||||
DownloadFolderManager.getInstance(this@DownloadService).deleteDownloadFolder(galleryID)
|
DownloadManager.getInstance(this@DownloadService).deleteDownloadFolder(galleryID)
|
||||||
Cache.delete(galleryID)
|
Cache.delete(galleryID)
|
||||||
|
|
||||||
startId?.let { stopSelf(it) }
|
startId?.let { stopSelf(it) }
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.app.Activity
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.drawable.Animatable
|
import android.graphics.drawable.Animatable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.*
|
import android.text.*
|
||||||
import android.text.style.AlignmentSpan
|
import android.text.style.AlignmentSpan
|
||||||
@@ -50,13 +51,16 @@ import com.google.android.material.snackbar.Snackbar
|
|||||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import kotlinx.android.synthetic.main.activity_main_content.*
|
import kotlinx.android.synthetic.main.activity_main_content.*
|
||||||
|
import kotlinx.android.synthetic.main.settings_activity.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import net.rdrei.android.dirchooser.DirectoryChooserActivity
|
||||||
import xyz.quaver.hitomi.doSearch
|
import xyz.quaver.hitomi.doSearch
|
||||||
import xyz.quaver.hitomi.getGalleryIDsFromNozomi
|
import xyz.quaver.hitomi.getGalleryIDsFromNozomi
|
||||||
import xyz.quaver.hitomi.getSuggestionsForQuery
|
import xyz.quaver.hitomi.getSuggestionsForQuery
|
||||||
|
import xyz.quaver.io.FileX
|
||||||
import xyz.quaver.pupil.R
|
import xyz.quaver.pupil.R
|
||||||
import xyz.quaver.pupil.adapters.GalleryBlockAdapter
|
import xyz.quaver.pupil.adapters.GalleryBlockAdapter
|
||||||
import xyz.quaver.pupil.favorites
|
import xyz.quaver.pupil.favorites
|
||||||
@@ -64,10 +68,11 @@ import xyz.quaver.pupil.histories
|
|||||||
import xyz.quaver.pupil.services.DownloadService
|
import xyz.quaver.pupil.services.DownloadService
|
||||||
import xyz.quaver.pupil.types.TagSuggestion
|
import xyz.quaver.pupil.types.TagSuggestion
|
||||||
import xyz.quaver.pupil.types.Tags
|
import xyz.quaver.pupil.types.Tags
|
||||||
|
import xyz.quaver.pupil.ui.dialog.DownloadLocationDialog
|
||||||
import xyz.quaver.pupil.ui.dialog.GalleryDialog
|
import xyz.quaver.pupil.ui.dialog.GalleryDialog
|
||||||
import xyz.quaver.pupil.util.*
|
import xyz.quaver.pupil.util.*
|
||||||
import xyz.quaver.pupil.util.downloader.Cache
|
import xyz.quaver.pupil.util.downloader.Cache
|
||||||
import xyz.quaver.pupil.util.downloader.DownloadFolderManager
|
import xyz.quaver.pupil.util.downloader.DownloadManager
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
@@ -110,7 +115,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private var loadingJob: Job? = null
|
private var loadingJob: Job? = null
|
||||||
private var currentPage = 0
|
private var currentPage = 0
|
||||||
|
|
||||||
private lateinit var downloadFolderManager: DownloadFolderManager
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -146,7 +150,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
downloadFolderManager = DownloadFolderManager.getInstance(this)
|
if (Preferences["download_folder", ""].isEmpty())
|
||||||
|
DownloadLocationDialog(this).show()
|
||||||
|
|
||||||
checkUpdate(this)
|
checkUpdate(this)
|
||||||
|
|
||||||
initView()
|
initView()
|
||||||
@@ -225,7 +231,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
when(requestCode) {
|
when(requestCode) {
|
||||||
R.id.request_settings -> {
|
R.id.request_settings.normalizeID() -> {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
cancelFetch()
|
cancelFetch()
|
||||||
clearGalleries()
|
clearGalleries()
|
||||||
@@ -233,10 +239,44 @@ class MainActivity : AppCompatActivity() {
|
|||||||
loadBlocks()
|
loadBlocks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
R.id.request_lock -> {
|
R.id.request_lock.normalizeID() -> {
|
||||||
if (resultCode != Activity.RESULT_OK)
|
if (resultCode != Activity.RESULT_OK)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
R.id.request_download_folder.normalizeID() -> {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
data?.data?.also { uri ->
|
||||||
|
val takeFlags: Int =
|
||||||
|
intent.flags and (Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||||
|
contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||||
|
|
||||||
|
if (FileX(this, uri).canWrite())
|
||||||
|
Preferences["download_folder"] = uri.toString()
|
||||||
|
else
|
||||||
|
Snackbar.make(
|
||||||
|
settings,
|
||||||
|
R.string.settings_download_folder_not_writable,
|
||||||
|
Snackbar.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
R.id.request_download_folder_old.normalizeID() -> {
|
||||||
|
if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
|
||||||
|
val directory = data?.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR)!!
|
||||||
|
|
||||||
|
if (!File(directory).canWrite())
|
||||||
|
Snackbar.make(
|
||||||
|
settings,
|
||||||
|
R.string.settings_download_folder_not_writable,
|
||||||
|
Snackbar.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
else
|
||||||
|
Preferences["download_folder"] = File(directory).canonicalPath
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,11 +483,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (Preferences["cache_disable"])
|
if (Preferences["cache_disable"])
|
||||||
Toast.makeText(context, R.string.settings_download_when_cache_disable_warning, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.settings_download_when_cache_disable_warning, Toast.LENGTH_SHORT).show()
|
||||||
else {
|
else {
|
||||||
if (downloadFolderManager.isDownloading(galleryID)) { //download in progress
|
if (DownloadManager.getInstance(context).isDownloading(galleryID)) { //download in progress
|
||||||
DownloadService.cancel(this@MainActivity, galleryID)
|
DownloadService.cancel(this@MainActivity, galleryID)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
downloadFolderManager.addDownloadFolder(galleryID)
|
DownloadManager.getInstance(context).addDownloadFolder(galleryID)
|
||||||
DownloadService.download(this@MainActivity, galleryID)
|
DownloadService.download(this@MainActivity, galleryID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1027,7 +1067,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode.DOWNLOAD -> {
|
Mode.DOWNLOAD -> {
|
||||||
val downloads = downloadFolderManager.downloadFolderMap.keys.toList()
|
val downloads = DownloadManager.getInstance(this@MainActivity).downloadFolderMap.keys.toList()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
query.isEmpty() -> downloads.also {
|
query.isEmpty() -> downloads.also {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package xyz.quaver.pupil.ui
|
package xyz.quaver.pupil.ui
|
||||||
|
|
||||||
import android.app.DownloadManager
|
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
@@ -26,7 +25,6 @@ import android.graphics.drawable.Animatable
|
|||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
@@ -38,7 +36,6 @@ import androidx.recyclerview.widget.PagerSnapHelper
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
|
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
|
||||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||||
import com.bumptech.glide.Glide
|
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import kotlinx.android.synthetic.main.activity_reader.*
|
import kotlinx.android.synthetic.main.activity_reader.*
|
||||||
@@ -55,7 +52,7 @@ import xyz.quaver.pupil.histories
|
|||||||
import xyz.quaver.pupil.services.DownloadService
|
import xyz.quaver.pupil.services.DownloadService
|
||||||
import xyz.quaver.pupil.util.Preferences
|
import xyz.quaver.pupil.util.Preferences
|
||||||
import xyz.quaver.pupil.util.downloader.Cache
|
import xyz.quaver.pupil.util.downloader.Cache
|
||||||
import xyz.quaver.pupil.util.downloader.DownloadFolderManager
|
import xyz.quaver.pupil.util.downloader.DownloadManager
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.schedule
|
import kotlin.concurrent.schedule
|
||||||
import kotlin.concurrent.timer
|
import kotlin.concurrent.timer
|
||||||
@@ -83,12 +80,10 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
private val conn = object: ServiceConnection {
|
private val conn = object: ServiceConnection {
|
||||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||||
downloader = (service as DownloadService.Binder).service
|
downloader = (service as DownloadService.Binder).service
|
||||||
Log.i("PUPILD", "CON")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName?) {
|
override fun onServiceDisconnected(name: ComponentName?) {
|
||||||
downloader = null
|
downloader = null
|
||||||
Log.i("PUPILD", "DIS")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,9 +238,9 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
timer.cancel()
|
timer.cancel()
|
||||||
(reader_recyclerview?.adapter as? ReaderAdapter)?.timer?.cancel()
|
(reader_recyclerview?.adapter as? ReaderAdapter)?.timer?.cancel()
|
||||||
|
|
||||||
if (!DownloadFolderManager.getInstance(this).isDownloading(galleryID)) {
|
if (!DownloadManager.getInstance(this).isDownloading(galleryID)) {
|
||||||
downloader?.cancel(galleryID)
|
downloader?.cancel(galleryID)
|
||||||
DownloadFolderManager.getInstance(this).deleteDownloadFolder(galleryID)
|
DownloadManager.getInstance(this).deleteDownloadFolder(galleryID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloader != null)
|
if (downloader != null)
|
||||||
@@ -373,13 +368,13 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
with(reader_fab_download) {
|
with(reader_fab_download) {
|
||||||
animateDownloadFAB(DownloadFolderManager.getInstance(this@ReaderActivity).getDownloadFolder(galleryID) != null) //If download in progress, animate button
|
animateDownloadFAB(DownloadManager.getInstance(this@ReaderActivity).getDownloadFolder(galleryID) != null) //If download in progress, animate button
|
||||||
|
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("cache_disable", false))
|
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("cache_disable", false))
|
||||||
Toast.makeText(context, R.string.settings_download_when_cache_disable_warning, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.settings_download_when_cache_disable_warning, Toast.LENGTH_SHORT).show()
|
||||||
else {
|
else {
|
||||||
val downloadManager = DownloadFolderManager.getInstance(this@ReaderActivity)
|
val downloadManager = DownloadManager.getInstance(this@ReaderActivity)
|
||||||
|
|
||||||
if (downloadManager.isDownloading(galleryID)) {
|
if (downloadManager.isDownloading(galleryID)) {
|
||||||
downloadManager.deleteDownloadFolder(galleryID)
|
downloadManager.deleteDownloadFolder(galleryID)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import net.rdrei.android.dirchooser.DirectoryChooserActivity
|
|||||||
import net.rdrei.android.dirchooser.DirectoryChooserConfig
|
import net.rdrei.android.dirchooser.DirectoryChooserConfig
|
||||||
import xyz.quaver.pupil.R
|
import xyz.quaver.pupil.R
|
||||||
import xyz.quaver.pupil.util.*
|
import xyz.quaver.pupil.util.*
|
||||||
import xyz.quaver.pupil.util.downloader.DownloadFolderManager
|
import xyz.quaver.pupil.util.downloader.DownloadManager
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
@@ -115,7 +115,7 @@ class DownloadLocationDialog(val activity: Activity) : AlertDialog(activity) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
externalFilesDirs.indexOfFirst {
|
externalFilesDirs.indexOfFirst {
|
||||||
it.canonicalPath == DownloadFolderManager.getInstance(context).downloadFolder.canonicalPath
|
it.canonicalPath == DownloadManager.getInstance(context).downloadFolder.canonicalPath
|
||||||
}.let { index ->
|
}.let { index ->
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
buttons.last().first.isChecked = true
|
buttons.last().first.isChecked = true
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import xyz.quaver.pupil.ui.dialog.DownloadLocationDialog
|
|||||||
import xyz.quaver.pupil.ui.dialog.MirrorDialog
|
import xyz.quaver.pupil.ui.dialog.MirrorDialog
|
||||||
import xyz.quaver.pupil.ui.dialog.ProxyDialog
|
import xyz.quaver.pupil.ui.dialog.ProxyDialog
|
||||||
import xyz.quaver.pupil.util.*
|
import xyz.quaver.pupil.util.*
|
||||||
|
import xyz.quaver.pupil.util.downloader.DownloadManager
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|||||||
@@ -275,13 +275,6 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
|||||||
if (e.message?.contains("cancel", true) != false)
|
if (e.message?.contains("cancel", true) != false)
|
||||||
return
|
return
|
||||||
|
|
||||||
Log.i("PUPILD", "FAIL ${call.request().tag()} (${e.message})")
|
|
||||||
FirebaseCrashlytics.getInstance().apply {
|
|
||||||
log("FAIL ${call.request().tag()} (${e.message})")
|
|
||||||
setCustomKey("POS", "FAIL")
|
|
||||||
recordException(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
cancel(galleryID)
|
cancel(galleryID)
|
||||||
queue.add(galleryID)
|
queue.add(galleryID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package xyz.quaver.pupil.util.downloader
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
import android.content.ContextWrapper
|
||||||
import android.util.Log
|
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -78,7 +77,7 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
|
|||||||
}.getOrNull() ?: Metadata()
|
}.getOrNull() ?: Metadata()
|
||||||
|
|
||||||
val downloadFolder: FileX?
|
val downloadFolder: FileX?
|
||||||
get() = DownloadFolderManager.getInstance(this).getDownloadFolder(galleryID)
|
get() = DownloadManager.getInstance(this).getDownloadFolder(galleryID)
|
||||||
|
|
||||||
val cacheFolder: FileX
|
val cacheFolder: FileX
|
||||||
get() = FileX(this, cacheDir, "imageCache/$galleryID").also {
|
get() = FileX(this, cacheDir, "imageCache/$galleryID").also {
|
||||||
@@ -101,7 +100,6 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
|
|||||||
|
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Log.i("PUPILD", "$file")
|
|
||||||
file.createNewFile()
|
file.createNewFile()
|
||||||
}
|
}
|
||||||
file.writeText(Json.encodeToString(metadata))
|
file.writeText(Json.encodeToString(metadata))
|
||||||
@@ -202,7 +200,6 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
|
|||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
fun moveToDownload() = CoroutineScope(Dispatchers.IO).launch {
|
fun moveToDownload() = CoroutineScope(Dispatchers.IO).launch {
|
||||||
val downloadFolder = downloadFolder ?: return@launch
|
val downloadFolder = downloadFolder ?: return@launch
|
||||||
Log.i("PUPILD", "MOVING $galleryID")
|
|
||||||
|
|
||||||
metadata.imageList?.forEach { imageName ->
|
metadata.imageList?.forEach { imageName ->
|
||||||
imageName ?: return@forEach
|
imageName ?: return@forEach
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ import xyz.quaver.pupil.services.DownloadService
|
|||||||
import xyz.quaver.pupil.util.Preferences
|
import xyz.quaver.pupil.util.Preferences
|
||||||
import xyz.quaver.pupil.util.formatDownloadFolder
|
import xyz.quaver.pupil.util.formatDownloadFolder
|
||||||
|
|
||||||
class DownloadFolderManager private constructor(context: Context) : ContextWrapper(context) {
|
class DownloadManager private constructor(context: Context) : ContextWrapper(context) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Volatile private var instance: DownloadFolderManager? = null
|
@Volatile private var instance: DownloadManager? = null
|
||||||
|
|
||||||
fun getInstance(context: Context) =
|
fun getInstance(context: Context) =
|
||||||
instance ?: synchronized(this) {
|
instance ?: synchronized(this) {
|
||||||
instance ?: DownloadFolderManager(context).also { instance = it }
|
instance ?: DownloadManager(context).also { instance = it }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,22 +55,34 @@ class DownloadFolderManager private constructor(context: Context) : ContextWrapp
|
|||||||
}
|
}
|
||||||
}.invoke()
|
}.invoke()
|
||||||
|
|
||||||
val downloadFolderMap: MutableMap<Int, String> = {
|
private var prevDownloadFolder: FileX? = null
|
||||||
val file = downloadFolder.getChild(".download")
|
private var downloadFolderMapInstance: MutableMap<Int, String>? = null
|
||||||
|
val downloadFolderMap: MutableMap<Int, String>
|
||||||
|
@Synchronized
|
||||||
|
get() {
|
||||||
|
if (prevDownloadFolder != downloadFolder) {
|
||||||
|
prevDownloadFolder = downloadFolder
|
||||||
|
downloadFolderMapInstance = {
|
||||||
|
val file = downloadFolder.getChild(".download")
|
||||||
|
|
||||||
val data = if (file.exists())
|
val data = if (file.exists())
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
file.readText()?.let { Json.decodeFromString<MutableMap<Int, String>>(it) }
|
file.readText()?.let { Json.decodeFromString<MutableMap<Int, String>>(it) }
|
||||||
}.onFailure { file.delete() }.getOrNull()
|
}.onFailure { file.delete() }.getOrNull()
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|
||||||
|
data ?: {
|
||||||
|
file.createNewFile()
|
||||||
|
file.writeText("{}")
|
||||||
|
mutableMapOf<Int, String>()
|
||||||
|
}.invoke()
|
||||||
|
}.invoke()
|
||||||
|
}
|
||||||
|
|
||||||
|
return downloadFolderMapInstance!!
|
||||||
|
}
|
||||||
|
|
||||||
data ?: {
|
|
||||||
file.createNewFile()
|
|
||||||
file.writeText("{}")
|
|
||||||
mutableMapOf<Int, String>()
|
|
||||||
}.invoke()
|
|
||||||
}.invoke()
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun isDownloading(galleryID: Int): Boolean {
|
fun isDownloading(galleryID: Int): Boolean {
|
||||||
@@ -90,7 +102,7 @@ class DownloadFolderManager private constructor(context: Context) : ContextWrapp
|
|||||||
return
|
return
|
||||||
|
|
||||||
val name = runBlocking {
|
val name = runBlocking {
|
||||||
Cache.getInstance(this@DownloadFolderManager, galleryID).getGalleryBlock()
|
Cache.getInstance(this@DownloadManager, galleryID).getGalleryBlock()
|
||||||
}?.formatDownloadFolder() ?: return
|
}?.formatDownloadFolder() ?: return
|
||||||
|
|
||||||
val folder = downloadFolder.getChild(name)
|
val folder = downloadFolder.getChild(name)
|
||||||
@@ -98,7 +110,7 @@ class DownloadFolderManager private constructor(context: Context) : ContextWrapp
|
|||||||
if (!folder.exists())
|
if (!folder.exists())
|
||||||
folder.mkdirs()
|
folder.mkdirs()
|
||||||
|
|
||||||
downloadFolderMap[galleryID] = name
|
downloadFolderMap[galleryID] = folder.name
|
||||||
|
|
||||||
downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap))
|
downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap))
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user