This commit is contained in:
tom5079
2020-09-02 00:13:25 +09:00
parent 7704c96955
commit 9583897ada
16 changed files with 237 additions and 140 deletions

View File

@@ -23,7 +23,6 @@ import android.app.Activity
import android.content.Intent
import android.graphics.drawable.Animatable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.*
import android.text.style.AlignmentSpan
@@ -448,6 +447,7 @@ class MainActivity : AppCompatActivity() {
DownloadService.cancel(this@MainActivity, galleryID)
}
else {
downloadFolderManager.addDownloadFolder(galleryID)
DownloadService.download(this@MainActivity, galleryID)
}
}
@@ -771,7 +771,7 @@ class MainActivity : AppCompatActivity() {
}
}
R.id.main_menu_sort_newest -> {
sortMode = MainActivity.SortMode.NEWEST
sortMode = SortMode.NEWEST
it.isChecked = true
runOnUiThread {
@@ -1006,7 +1006,7 @@ class MainActivity : AppCompatActivity() {
totalItems = it.size
}
}
else -> doSearch("$defaultQuery $query", sortMode == MainActivity.SortMode.POPULAR).also {
else -> doSearch("$defaultQuery $query", sortMode == SortMode.POPULAR).also {
totalItems = it.size
}
}
@@ -1027,13 +1027,7 @@ class MainActivity : AppCompatActivity() {
}
}
Mode.DOWNLOAD -> {
val downloads = getDownloadDirectory(this@MainActivity).listFiles()?.filter { file ->
file.isDirectory && file.name.toIntOrNull() != null
}?.sortedByDescending {
it.lastModified()
}?.map {
it.name.toInt()
} ?: emptyList()
val downloads = downloadFolderManager.downloadFolderMap.keys.toList()
when {
query.isEmpty() -> downloads.also {

View File

@@ -18,6 +18,7 @@
package xyz.quaver.pupil.ui
import android.app.DownloadManager
import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
@@ -91,8 +92,6 @@ class ReaderActivity : AppCompatActivity() {
}
}
private var deleteOnExit = true
private val timer = Timer()
private var autoTimer: Timer? = null
@@ -244,12 +243,13 @@ class ReaderActivity : AppCompatActivity() {
timer.cancel()
(reader_recyclerview?.adapter as? ReaderAdapter)?.timer?.cancel()
if (deleteOnExit) {
if (!DownloadFolderManager.getInstance(this).isDownloading(galleryID)) {
downloader?.cancel(galleryID)
DownloadFolderManager.getInstance(this).deleteDownloadFolder(galleryID)
}
unbindService(conn)
if (downloader != null)
unbindService(conn)
}
override fun onBackPressed() {
@@ -285,7 +285,7 @@ class ReaderActivity : AppCompatActivity() {
}
private fun initDownloader() {
DownloadService.download(this, galleryID)
DownloadService.download(this, galleryID, true)
bindService(Intent(this, DownloadService::class.java), conn, BIND_AUTO_CREATE)
timer.schedule(1000, 1000) {
@@ -379,12 +379,14 @@ class ReaderActivity : AppCompatActivity() {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("cache_disable", false))
Toast.makeText(context, R.string.settings_download_when_cache_disable_warning, Toast.LENGTH_SHORT).show()
else {
if (deleteOnExit) {
deleteOnExit = false
cache.moveToDownload()
animateDownloadFAB(true)
} else {
val downloadManager = DownloadFolderManager.getInstance(this@ReaderActivity)
if (downloadManager.isDownloading(galleryID)) {
downloadManager.deleteDownloadFolder(galleryID)
animateDownloadFAB(false)
} else {
downloadManager.addDownloadFolder(galleryID)
animateDownloadFAB(true)
}
}
}

View File

@@ -35,6 +35,7 @@ import net.rdrei.android.dirchooser.DirectoryChooserActivity
import net.rdrei.android.dirchooser.DirectoryChooserConfig
import xyz.quaver.pupil.R
import xyz.quaver.pupil.util.*
import xyz.quaver.pupil.util.downloader.DownloadFolderManager
import java.io.File
@SuppressLint("InflateParams")
@@ -114,10 +115,10 @@ class DownloadLocationDialog(val activity: Activity) : AlertDialog(activity) {
})
externalFilesDirs.indexOfFirst {
it.canonicalPath == getDownloadDirectory(context).canonicalPath
it.canonicalPath == DownloadFolderManager.getInstance(context).downloadFolder.canonicalPath
}.let { index ->
if (index < 0)
buttons.first().first.isChecked = true
buttons.last().first.isChecked = true
else
buttons[index].first.isChecked = true
}

View File

@@ -209,6 +209,9 @@ class SettingsFragment :
"proxy" -> {
summary = context?.let { getProxyInfo().type.name }
}
"download_folder" -> {
summary = FileX(context, Preferences.get<String>("download_folder")).canonicalPath
}
}
}
}
@@ -221,6 +224,11 @@ class SettingsFragment :
initPreferences()
}
override fun onDestroy() {
Preferences.unregisterOnSharedPreferenceChangeListener(this)
super.onDestroy()
}
private fun initPreferences() {
for (i in 0 until preferenceScreen.preferenceCount) {
@@ -274,13 +282,7 @@ class SettingsFragment :
onPreferenceClickListener = this@SettingsFragment
}
"download_folder" -> {
setSummaryProvider {
val uri: String = Preferences[it.key]
kotlin.runCatching {
FileX(context, uri).canonicalPath
}.getOrElse { "" }
}
summary = FileX(context, Preferences.get<String>("download_folder")).canonicalPath
onPreferenceClickListener = this@SettingsFragment
}