Get rid of IntList, LongList
This commit is contained in:
1 parent
59e46aeeea
commit
8be6ad84fc
7 files changed
+40
-52
No files matched your search
@@ -32,9 +32,9 @@ import com.hippo.ehviewer.spider.readCompatFromUniFile
|
||||
import com.hippo.ehviewer.spider.write
|
||||
import com.hippo.ehviewer.util.AppConfig
|
||||
import com.hippo.ehviewer.util.ConcurrentPool
|
||||
import com.hippo.ehviewer.util.LongList
|
||||
import com.hippo.ehviewer.util.SimpleHandler
|
||||
import com.hippo.ehviewer.util.assertNotMainThread
|
||||
import com.hippo.ehviewer.util.mapNotNull
|
||||
import com.hippo.ehviewer.util.runAssertingNotMainThread
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
@@ -218,13 +218,12 @@ object DownloadManager : OnSpiderListener {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun startRangeDownload(gidList: LongList) {
|
||||
suspend fun startRangeDownload(gidList: LongArray) {
|
||||
var update = false
|
||||
for (i in 0 until gidList.size) {
|
||||
val gid = gidList[i]
|
||||
val info = mAllInfoMap[gid]
|
||||
for (element in gidList) {
|
||||
val info = mAllInfoMap[element]
|
||||
if (null == info) {
|
||||
Log.d(TAG, "Can't get download info with gid: $gid")
|
||||
Log.d(TAG, "Can't get download info with gid: $element")
|
||||
continue
|
||||
}
|
||||
if (info.state == DownloadInfo.STATE_NONE || info.state == DownloadInfo.STATE_FAILED || info.state == DownloadInfo.STATE_FINISH) {
|
||||
@@ -374,7 +373,7 @@ object DownloadManager : OnSpiderListener {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun stopRangeDownload(gidList: LongList) {
|
||||
suspend fun stopRangeDownload(gidList: LongArray) {
|
||||
stopRangeDownloadInternal(gidList)
|
||||
|
||||
// Update listener
|
||||
@@ -432,7 +431,7 @@ object DownloadManager : OnSpiderListener {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteRangeDownload(gidList: LongList) {
|
||||
suspend fun deleteRangeDownload(gidList: LongArray) {
|
||||
stopRangeDownloadInternal(gidList)
|
||||
val list = gidList.mapNotNull { gid ->
|
||||
mAllInfoMap.remove(gid)?.also { getInfoListForLabel(it.label)?.remove(it) }
|
||||
@@ -546,11 +545,11 @@ object DownloadManager : OnSpiderListener {
|
||||
|
||||
// Update in DB
|
||||
// Update mDownloadListener
|
||||
private suspend fun stopRangeDownloadInternal(gidList: LongList) {
|
||||
private suspend fun stopRangeDownloadInternal(gidList: LongArray) {
|
||||
// Two way
|
||||
if (gidList.size < mWaitList.size) {
|
||||
for (i in 0 until gidList.size) {
|
||||
stopDownloadInternal(gidList[i])
|
||||
for (element in gidList) {
|
||||
stopDownloadInternal(element)
|
||||
}
|
||||
} else {
|
||||
// Check current task
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.hippo.ehviewer.dao.DownloadInfo
|
||||
import com.hippo.ehviewer.ui.MainActivity
|
||||
import com.hippo.ehviewer.ui.scene.DownloadsScene
|
||||
import com.hippo.ehviewer.util.FileUtils
|
||||
import com.hippo.ehviewer.util.LongList
|
||||
import com.hippo.ehviewer.util.ReadableTime
|
||||
import com.hippo.ehviewer.util.SimpleHandler
|
||||
import com.hippo.ehviewer.util.getParcelableExtraCompat
|
||||
@@ -105,7 +104,7 @@ class DownloadService : Service(), DownloadManager.DownloadListener, CoroutineSc
|
||||
}
|
||||
|
||||
ACTION_START_RANGE -> {
|
||||
val gidList = intent.getParcelableExtraCompat<LongList>(KEY_GID_LIST)
|
||||
val gidList = intent.getLongArrayExtra(KEY_GID_LIST)
|
||||
if (gidList != null) {
|
||||
deferredMgr.await().startRangeDownload(gidList)
|
||||
}
|
||||
@@ -125,7 +124,7 @@ class DownloadService : Service(), DownloadManager.DownloadListener, CoroutineSc
|
||||
ACTION_STOP_CURRENT -> deferredMgr.await().stopCurrentDownload()
|
||||
|
||||
ACTION_STOP_RANGE -> {
|
||||
val gidList = intent.getParcelableExtraCompat<LongList>(KEY_GID_LIST)
|
||||
val gidList = intent.getLongArrayExtra(KEY_GID_LIST)
|
||||
if (gidList != null) {
|
||||
deferredMgr.await().stopRangeDownload(gidList)
|
||||
}
|
||||
@@ -141,7 +140,7 @@ class DownloadService : Service(), DownloadManager.DownloadListener, CoroutineSc
|
||||
}
|
||||
|
||||
ACTION_DELETE_RANGE -> {
|
||||
val gidList = intent.getParcelableExtraCompat<LongList>(KEY_GID_LIST)
|
||||
val gidList = intent.getLongArrayExtra(KEY_GID_LIST)
|
||||
if (gidList != null) {
|
||||
deferredMgr.await().deleteRangeDownload(gidList)
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ import com.hippo.ehviewer.download.downloadLocation
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene
|
||||
import com.hippo.ehviewer.ui.tools.DialogState
|
||||
import com.hippo.ehviewer.util.FavouriteStatusRouter
|
||||
import com.hippo.ehviewer.util.LongList
|
||||
import com.hippo.ehviewer.util.findActivity
|
||||
import com.hippo.ehviewer.util.isAtLeastT
|
||||
import com.hippo.ehviewer.util.mapToLongArray
|
||||
import com.hippo.ehviewer.util.requestPermission
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
@@ -99,19 +99,12 @@ suspend fun DialogState.startDownload(
|
||||
if (isAtLeastT) {
|
||||
requestPermission(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
val toStart = LongList()
|
||||
val toAdd = mutableListOf<BaseGalleryInfo>()
|
||||
for (gi in galleryInfos) {
|
||||
if (DownloadManager.containDownloadInfo(gi.gid)) {
|
||||
toStart.add(gi.gid)
|
||||
} else {
|
||||
toAdd.add(gi)
|
||||
}
|
||||
}
|
||||
val (toStart, toAdd) = galleryInfos.partition { DownloadManager.containDownloadInfo(it.gid) }
|
||||
if (toStart.isNotEmpty()) {
|
||||
val intent = Intent(context, DownloadService::class.java)
|
||||
intent.action = DownloadService.ACTION_START_RANGE
|
||||
intent.putExtra(DownloadService.KEY_GID_LIST, toStart)
|
||||
val list = toStart.mapToLongArray(GalleryInfo::gid)
|
||||
intent.putExtra(DownloadService.KEY_GID_LIST, list)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
if (toAdd.isEmpty()) {
|
||||
|
||||
@@ -60,7 +60,6 @@ import androidx.compose.ui.res.stringArrayResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.util.fastForEachReversed
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -111,8 +110,8 @@ import com.hippo.ehviewer.ui.setMD3Content
|
||||
import com.hippo.ehviewer.ui.tools.CropDefaults
|
||||
import com.hippo.ehviewer.ui.tools.DialogState
|
||||
import com.hippo.ehviewer.util.FileUtils
|
||||
import com.hippo.ehviewer.util.LongList
|
||||
import com.hippo.ehviewer.util.containsIgnoreCase
|
||||
import com.hippo.ehviewer.util.mapToLongArray
|
||||
import com.hippo.ehviewer.util.sendTo
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
@@ -447,12 +446,8 @@ class DownloadsScene :
|
||||
expanded = false
|
||||
val list = mList ?: return@DropdownMenuItem
|
||||
val activity = requireActivity()
|
||||
val gidList = LongList()
|
||||
list.fastForEachReversed { info ->
|
||||
if (info.state != DownloadInfo.STATE_FINISH) {
|
||||
gidList.add(info.gid)
|
||||
}
|
||||
}
|
||||
val gidList = list.filter { it.state != DownloadInfo.STATE_FINISH }
|
||||
.asReversed().mapToLongArray(DownloadInfo::gid)
|
||||
val intent = Intent(activity, DownloadService::class.java)
|
||||
intent.action = DownloadService.ACTION_START_RANGE
|
||||
intent.putExtra(DownloadService.KEY_GID_LIST, gidList)
|
||||
@@ -553,7 +548,7 @@ class DownloadsScene :
|
||||
} else {
|
||||
val downloadInfoList = tracker.getAndClearSelection()
|
||||
val gidList = if (position in 1..3) {
|
||||
LongList(downloadInfoList.map(DownloadInfo::gid).toMutableList())
|
||||
downloadInfoList.mapToLongArray(DownloadInfo::gid)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -690,7 +685,7 @@ class DownloadsScene :
|
||||
|
||||
private inner class DeleteRangeDialogHelper(
|
||||
private val mDownloadInfoList: List<DownloadInfo>,
|
||||
private val mGidList: LongList,
|
||||
private val mGidList: LongArray,
|
||||
private val mBuilder: CheckBoxDialogBuilder,
|
||||
) : DialogInterface.OnClickListener {
|
||||
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.hippo.ehviewer.util
|
||||
|
||||
inline fun <R : Any, C : MutableCollection<in R>> LongArray.mapNotNullTo(destination: C, transform: (Long) -> R?): C {
|
||||
forEach { element -> transform(element)?.let { destination.add(it) } }
|
||||
return destination
|
||||
}
|
||||
|
||||
inline fun <T> Collection<T>.mapToLongArray(transform: (T) -> Long): LongArray {
|
||||
val result = LongArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = transform(element)
|
||||
return result
|
||||
}
|
||||
|
||||
inline fun <R : Any> LongArray.mapNotNull(transform: (Long) -> R?): List<R> {
|
||||
return mapNotNullTo(ArrayList<R>(), transform)
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.hippo.ehviewer.util
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
class IntList(private val delegate: MutableList<Int> = mutableListOf()) :
|
||||
Parcelable, MutableList<Int> by delegate
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.hippo.ehviewer.util
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
class LongList(private val delegate: MutableList<Long> = mutableListOf()) :
|
||||
Parcelable, MutableList<Long> by delegate
|
||||
Reference in new issue
Block a user