Skip to content

Commit 327bdd2

Browse files
committed
[fix] Fix an issue that using the debounce operator on the download page causes some information not to be updated
1 parent c9a5a93 commit 327bdd2

File tree

11 files changed

+20
-24
lines changed

11 files changed

+20
-24
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ android {
2222
minSdk = 24
2323
targetSdk = 35
2424
versionCode = 24
25-
versionName = "2.1-beta04"
25+
versionName = "2.1-beta05"
2626

2727
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2828

app/src/main/java/com/skyd/anivu/base/mvi/MviIntent.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import androidx.compose.runtime.remember
66
import com.skyd.anivu.ext.startWith
77
import kotlinx.coroutines.Dispatchers
88
import kotlinx.coroutines.channels.Channel
9-
import kotlinx.coroutines.flow.collect
109
import kotlinx.coroutines.flow.consumeAsFlow
11-
import kotlinx.coroutines.flow.onEach
1210
import kotlinx.coroutines.withContext
1311

1412
/**

app/src/main/java/com/skyd/anivu/base/mvi/MviViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.skyd.anivu.base.mvi
22

33
import androidx.annotation.MainThread
4+
import kotlinx.coroutines.MainCoroutineDispatcher
45
import kotlinx.coroutines.flow.Flow
56
import kotlinx.coroutines.flow.StateFlow
67

@@ -18,7 +19,7 @@ interface MviViewModel<I : MviIntent, S : MviViewState, E : MviSingleEvent> {
1819
val singleEvent: Flow<E>
1920

2021
/**
21-
* Must be called in [kotlinx.coroutines.Dispatchers.Main.immediate],
22+
* Must be called in [MainCoroutineDispatcher.immediate],
2223
* otherwise it will throw an exception.
2324
*
2425
* If you want to process an intent from other [kotlinx.coroutines.CoroutineDispatcher],

app/src/main/java/com/skyd/anivu/ext/FlowExt.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.FlowCollector
1212
import kotlinx.coroutines.flow.buffer
1313
import kotlinx.coroutines.flow.catch
1414
import kotlinx.coroutines.flow.channelFlow
15-
import kotlinx.coroutines.flow.debounce
1615
import kotlinx.coroutines.flow.drop
1716
import kotlinx.coroutines.flow.emitAll
1817
import kotlinx.coroutines.flow.flow
@@ -21,6 +20,7 @@ import kotlinx.coroutines.flow.flowOn
2120
import kotlinx.coroutines.flow.map
2221
import kotlinx.coroutines.flow.merge
2322
import kotlinx.coroutines.flow.produceIn
23+
import kotlinx.coroutines.flow.sample
2424
import kotlinx.coroutines.flow.take
2525
import kotlinx.coroutines.launch
2626
import java.util.concurrent.atomic.AtomicBoolean
@@ -87,6 +87,6 @@ fun <T> Flow<T>.collectIn(
8787
flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState).collect(action)
8888
}
8989

90-
fun <T> Flow<T>.debounceWithoutFirst(timeoutMillis: Long) = merge(
91-
take(1), drop(1).debounce(timeoutMillis)
90+
fun <T> Flow<T>.sampleWithoutFirst(timeoutMillis: Long) = merge(
91+
take(1), drop(1).sample(timeoutMillis)
9292
)

app/src/main/java/com/skyd/anivu/model/repository/ArticleRepository.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.flow
2727
import kotlinx.coroutines.flow.flowOn
2828
import kotlinx.parcelize.Parcelize
2929
import javax.inject.Inject
30+
import kotlin.coroutines.cancellation.CancellationException
3031

3132
@Parcelize
3233
sealed class ArticleSort(open val asc: Boolean) : Parcelable {
@@ -105,8 +106,10 @@ class ArticleRepository @Inject constructor(
105106
feedDao.updateFeed(feedWithArticle.feed)
106107
}?.articles
107108
}.onFailure { e ->
108-
e.printStackTrace()
109-
(feedUrl + "\n" + e.message).showToast()
109+
if (e !is CancellationException) {
110+
e.printStackTrace()
111+
(feedUrl + "\n" + e.message).showToast()
112+
}
110113
}.getOrNull()
111114
}
112115
val articleBeanList = articleBeanListAsync.await() ?: return@async

app/src/main/java/com/skyd/anivu/model/repository/download/DownloadManager.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.skyd.anivu.model.repository.download
22

33
import androidx.work.WorkManager
44
import com.skyd.anivu.appContext
5-
import com.skyd.anivu.ext.debounceWithoutFirst
5+
import com.skyd.anivu.ext.sampleWithoutFirst
66
import com.skyd.anivu.model.bean.download.DownloadInfoBean
77
import com.skyd.anivu.model.bean.download.DownloadInfoBean.DownloadState
88
import com.skyd.anivu.model.bean.download.DownloadLinkUuidMapBean
@@ -21,8 +21,6 @@ import kotlinx.coroutines.flow.Flow
2121
import kotlinx.coroutines.flow.MutableSharedFlow
2222
import kotlinx.coroutines.flow.MutableStateFlow
2323
import kotlinx.coroutines.flow.catch
24-
import kotlinx.coroutines.flow.consumeAsFlow
25-
import kotlinx.coroutines.flow.distinctUntilChanged
2624
import kotlinx.coroutines.flow.filterIsInstance
2725
import kotlinx.coroutines.flow.first
2826
import kotlinx.coroutines.flow.launchIn
@@ -62,7 +60,7 @@ object DownloadManager {
6260
private fun Flow<DownloadManagerIntent>.onEachIntent(): Flow<DownloadManagerIntent> {
6361
return merge(
6462
filterIsInstance<DownloadManagerIntent.UpdateDownloadInfo>()
65-
.debounceWithoutFirst(100)
63+
.sampleWithoutFirst(100)
6664
.onEach { intent ->
6765
downloadInfoDao.updateDownloadInfo(intent.downloadInfoBean)
6866
putDownloadInfoToMap(
@@ -82,7 +80,7 @@ object DownloadManager {
8280
}.catch { it.printStackTrace() },
8381

8482
filterIsInstance<DownloadManagerIntent.UpdateDownloadProgress>()
85-
.debounceWithoutFirst(1000)
83+
.sampleWithoutFirst(1000)
8684
.onEach { intent ->
8785
val result = downloadInfoDao.updateDownloadProgress(
8886
link = intent.link,
@@ -105,7 +103,7 @@ object DownloadManager {
105103
}.catch { it.printStackTrace() },
106104

107105
filterIsInstance<DownloadManagerIntent.UpdateDownloadSize>()
108-
.debounceWithoutFirst(1000)
106+
.sampleWithoutFirst(1000)
109107
.onEach { intent ->
110108
val result = downloadInfoDao.updateDownloadSize(
111109
link = intent.link, size = intent.size,
@@ -116,7 +114,7 @@ object DownloadManager {
116114
}.catch { it.printStackTrace() },
117115

118116
filterIsInstance<DownloadManagerIntent.UpdateDownloadName>()
119-
.debounceWithoutFirst(200)
117+
.sampleWithoutFirst(200)
120118
.onEach { intent ->
121119
if (intent.name.isNullOrBlank()) return@onEach
122120
val result = downloadInfoDao.updateDownloadName(
@@ -146,7 +144,7 @@ object DownloadManager {
146144
.catch { it.printStackTrace() },
147145

148146
filterIsInstance<DownloadManagerIntent.UpdateDownloadDescription>()
149-
.debounceWithoutFirst(500)
147+
.sampleWithoutFirst(500)
150148
.onEach { intent ->
151149
val result = downloadInfoDao.updateDownloadDescription(
152150
link = intent.link,

app/src/main/java/com/skyd/anivu/model/repository/download/DownloadRepository.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.skyd.anivu.model.repository.download
22

33
import com.skyd.anivu.base.BaseRepository
44
import com.skyd.anivu.config.Const
5-
import com.skyd.anivu.ext.debounceWithoutFirst
5+
import com.skyd.anivu.ext.sampleWithoutFirst
66
import com.skyd.anivu.model.bean.download.DownloadInfoBean
77
import com.skyd.anivu.model.worker.download.DownloadTorrentWorker
88
import kotlinx.coroutines.Dispatchers
@@ -18,8 +18,8 @@ class DownloadRepository @Inject constructor() : BaseRepository() {
1818
suspend fun requestDownloadingVideos(): Flow<List<DownloadInfoBean>> {
1919
return combine(
2020
DownloadManager.getDownloadInfoList().distinctUntilChanged(),
21-
DownloadTorrentWorker.peerInfoMapFlow.debounceWithoutFirst(1000),
22-
DownloadTorrentWorker.torrentStatusMapFlow.debounceWithoutFirst(1000),
21+
DownloadTorrentWorker.peerInfoMapFlow.sampleWithoutFirst(1000),
22+
DownloadTorrentWorker.torrentStatusMapFlow.sampleWithoutFirst(1000),
2323
) { list, peerInfoMap, uploadPayloadRateMap ->
2424
list.map { downloadInfoBean ->
2525
downloadInfoBean.copy().apply {

app/src/main/java/com/skyd/anivu/ui/screen/feed/FeedScreen.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.skyd.anivu.ui.screen.feed
22

33
import androidx.activity.compose.BackHandler
4-
import androidx.compose.animation.animateContentSize
54
import androidx.compose.foundation.layout.Column
65
import androidx.compose.foundation.layout.PaddingValues
76
import androidx.compose.foundation.layout.WindowInsets

app/src/main/java/com/skyd/anivu/ui/screen/feed/item/Group1Item.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.skyd.anivu.ui.screen.feed.item
33
import androidx.compose.animation.core.animateDpAsState
44
import androidx.compose.animation.core.animateFloatAsState
55
import androidx.compose.foundation.background
6-
import androidx.compose.foundation.border
76
import androidx.compose.foundation.combinedClickable
87
import androidx.compose.foundation.layout.Row
98
import androidx.compose.foundation.layout.padding

app/src/main/java/com/skyd/anivu/ui/screen/feed/reorder/ReorderGroupPartialStateChange.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.skyd.anivu.ui.screen.feed.reorder
22

33
import com.skyd.anivu.model.bean.GroupVo
4-
import com.skyd.anivu.ui.screen.feed.reorder.ReorderGroupPartialStateChange.GroupList.Success
54

65

76
internal sealed interface ReorderGroupPartialStateChange {

app/src/main/java/com/skyd/anivu/ui/screen/feed/requestheaders/RequestHeadersPartialStateChange.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.skyd.anivu.ui.screen.feed.requestheaders
22

33
import com.skyd.anivu.model.bean.FeedBean
4-
import com.skyd.anivu.ui.screen.feed.reorder.ReorderGroupPartialStateChange.GroupList.Success
54

65

76
internal sealed interface RequestHeadersPartialStateChange {

0 commit comments

Comments
 (0)