Cleanup DownloadManager

This commit is contained in:
tarsin committed 2023-07-12 10:20:41 +08:00
1 parent 2fd9982c37
commit b1fbefc09e
4 files changed
+20 -68

No files matched your search

+2 -16
View File
@@ -112,10 +112,9 @@ object EhDB {
return raw
}
@Synchronized
fun updateDownloadLabel(raw: DownloadLabel?) {
suspend fun updateDownloadLabel(raw: DownloadLabel) {
val dao = db.downloadLabelDao()
dao.update(raw!!)
dao.update(raw)
}
@Synchronized
@@ -332,32 +331,23 @@ object EhDB {
it.close()
context.deleteDatabase(tempDBName)
} use { oldDB ->
// Download label
runCatching {
val downloadLabelList = oldDB.downloadLabelDao().list()
DownloadManager.addDownloadLabel(downloadLabelList)
}
// Downloads
runCatching {
val downloadInfoList = oldDB.downloadsDao().list()
DownloadManager.addDownload(downloadInfoList, false)
}
// Download dirname
runCatching {
oldDB.downloadDirnameDao().list().forEach {
putDownloadDirname(it.gid, it.dirname)
}
}
// History
runCatching {
val historyInfoList = oldDB.historyDao().list()
putHistoryInfo(historyInfoList)
}
// QuickSearch
runCatching {
val quickSearchList = oldDB.quickSearchDao().list()
val currentQuickSearchList = db.quickSearchDao().list()
@@ -366,15 +356,11 @@ object EhDB {
}
importQuickSearch(importList)
}
// LocalFavorites
runCatching {
oldDB.localFavoritesDao().list().forEach {
putLocalFavorites(it)
}
}
// Filter
runCatching {
val filterList = oldDB.filterDao().list()
val currentFilterList = db.filterDao().list()
@@ -18,7 +18,7 @@ interface DownloadLabelDao {
fun update(downloadLabels: List<DownloadLabel>)
@Update
fun update(downloadLabel: DownloadLabel)
suspend fun update(downloadLabel: DownloadLabel)
@Insert
fun insert(t: DownloadLabel): Long
@@ -284,14 +284,6 @@ object DownloadManager : OnSpiderListener {
// No-op
}
override fun onChange() {
// No-op
}
override fun onRenameLabel(from: String, to: String) {
// No-op
}
override fun onRemove(info: DownloadInfo, list: List<DownloadInfo>, position: Int) {
trySend(info)
}
@@ -737,7 +729,7 @@ object DownloadManager : OnSpiderListener {
}
}
fun renameLabel(from: String, to: String) {
suspend fun renameLabel(from: String, to: String) {
// Find in label list
var found = false
for (raw in labelList) {
@@ -762,11 +754,6 @@ object DownloadManager : OnSpiderListener {
}
// Put list back with new label
map[to] = list
// Notify listener
for (l in mDownloadInfoListeners) {
l.onRenameLabel(from, to)
}
}
suspend fun deleteLabel(label: String) {
@@ -797,11 +784,6 @@ object DownloadManager : OnSpiderListener {
// Sort
defaultInfoList.sortByDateDescending()
// Notify listener
for (l in mDownloadInfoListeners) {
l.onChange()
}
}
val isIdle: Boolean
@@ -901,16 +883,6 @@ object DownloadManager : OnSpiderListener {
*/
fun onReload()
/**
* The list is gone, use default list please
*/
fun onChange()
/**
* Rename label
*/
fun onRenameLabel(from: String, to: String)
/**
* Remove the special info from the special position
*/
@@ -99,7 +99,6 @@ import com.hippo.ehviewer.util.sendTo
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchNonCancellable
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.lang.withUIContext
import eu.kanade.tachiyomi.util.system.pxToDp
import kotlinx.coroutines.Dispatchers
@@ -642,23 +641,6 @@ class DownloadsScene :
updateView()
}
override fun onChange() {
lifecycleScope.launchUI {
mLabel = null
updateForLabel()
updateView()
}
}
override fun onRenameLabel(from: String, to: String) {
if (mLabel != from) {
return
}
mLabel = to
updateForLabel()
updateView()
}
override fun onRemove(info: DownloadInfo, list: List<DownloadInfo>, position: Int) {
if (mList !== list) {
return
@@ -1075,10 +1057,19 @@ class DownloadsScene :
} else {
mBuilder.setError(null)
mDialog.dismiss()
downloadManager.renameLabel(mOriginalLabel!!, text)
if (mLabelAdapter != null) {
initLabels()
mLabelAdapter!!.notifyDataSetChanged()
lifecycleScope.launchIO {
downloadManager.renameLabel(mOriginalLabel!!, text)
if (mLabelAdapter != null) {
withUIContext {
initLabels()
mLabelAdapter!!.notifyDataSetChanged()
if (mLabel == mOriginalLabel) {
mLabel = text
updateForLabel()
updateView()
}
}
}
}
}
}
@@ -1160,6 +1151,9 @@ class DownloadsScene :
DownloadManager.deleteLabel(label)
mLabels.removeAt(position)
withUIContext {
mLabel = null
updateForLabel()
updateView()
mLabelAdapter!!.notifyItemRemoved(position)
}
}