diff --git a/app/build.gradle b/app/build.gradle index f6c3faf..6ce5d91 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,7 @@ android { buildTypes { debug { versionNameSuffix "-dev" + applicationIdSuffix ".debug" debuggable true shrinkResources false minifyEnabled false diff --git a/app/src/main/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSource.kt b/app/src/main/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSource.kt index ed4d856..1d23967 100644 --- a/app/src/main/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSource.kt +++ b/app/src/main/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSource.kt @@ -16,7 +16,7 @@ class VideoInPendingLocalSource( get() = sharedPreferencesManager.pendingVideosFlow .map { stringSet -> stringSet.asSequence().map { timeThenUrl -> timeThenUrl.getTimeAndOriginal() } - .sortedByDescending { it.first } + .sortedBy { it.first } .map { it.second } .map { it.asVideoInPending() } .toList() diff --git a/app/src/main/java/org/fnives/tiktokdownloader/data/usecase/VideoDownloadingProcessorUseCase.kt b/app/src/main/java/org/fnives/tiktokdownloader/data/usecase/VideoDownloadingProcessorUseCase.kt index b96bade..155df97 100644 --- a/app/src/main/java/org/fnives/tiktokdownloader/data/usecase/VideoDownloadingProcessorUseCase.kt +++ b/app/src/main/java/org/fnives/tiktokdownloader/data/usecase/VideoDownloadingProcessorUseCase.kt @@ -43,7 +43,7 @@ class VideoDownloadingProcessorUseCase( private val fetch = MutableStateFlow(ProcessingState.RUNNING) private val _processState by lazy { - combineIntoPair(fetch, videoInPendingLocalSource.observeLastPendingVideo()) + combineIntoPair(fetch, videoInPendingLocalSource.observeFirstPendingVideo()) .filter { it.first == ProcessingState.RUNNING } .map { it.second } .debounce(WORK_FLOW_DEBOUNCE) @@ -134,7 +134,7 @@ class VideoDownloadingProcessorUseCase( private fun combineIntoPair(flow1: Flow, flow2: Flow): Flow> = combine(flow1, flow2) { item1, item2 -> item1 to item2 } - private fun VideoInPendingLocalSource.observeLastPendingVideo(): Flow = - pendingVideos.map { it.lastOrNull() }.distinctUntilChanged() + private fun VideoInPendingLocalSource.observeFirstPendingVideo(): Flow = + pendingVideos.map { it.firstOrNull() }.distinctUntilChanged() } } \ No newline at end of file diff --git a/app/src/main/java/org/fnives/tiktokdownloader/ui/main/queue/QueueFragment.kt b/app/src/main/java/org/fnives/tiktokdownloader/ui/main/queue/QueueFragment.kt index 9baaf19..9943908 100644 --- a/app/src/main/java/org/fnives/tiktokdownloader/ui/main/queue/QueueFragment.kt +++ b/app/src/main/java/org/fnives/tiktokdownloader/ui/main/queue/QueueFragment.kt @@ -38,25 +38,25 @@ class QueueFragment : Fragment(R.layout.fragment_queue) { input.setText("") } - viewModel.navigationEvent.observe(viewLifecycleOwner, Observer { + viewModel.navigationEvent.observe(viewLifecycleOwner) { val intent = when (val data = it.item) { is QueueViewModel.NavigationEvent.OpenBrowser -> { createBrowserIntent(data.url) } is QueueViewModel.NavigationEvent.OpenGallery -> createGalleryIntent(data.uri) - null -> return@Observer + null -> return@observe } startActivity(intent) - }) + } - viewModel.downloads.observe(viewLifecycleOwner, { videoStates -> + viewModel.downloads.observe(viewLifecycleOwner) { videoStates -> adapter.submitList(videoStates, Runnable { val indexToScrollTo = videoStates.indexOfFirst { it is VideoState.InProcess } .takeIf { it != -1 } ?: return@Runnable recycler.smoothScrollToPosition(indexToScrollTo) }) - }) + } } companion object { diff --git a/app/src/main/java/org/fnives/tiktokdownloader/ui/shared/ViewModelExtensions.kt b/app/src/main/java/org/fnives/tiktokdownloader/ui/shared/ViewModelExtensions.kt index a93ef45..6ea3eea 100644 --- a/app/src/main/java/org/fnives/tiktokdownloader/ui/shared/ViewModelExtensions.kt +++ b/app/src/main/java/org/fnives/tiktokdownloader/ui/shared/ViewModelExtensions.kt @@ -1,12 +1,12 @@ package org.fnives.tiktokdownloader.ui.shared -import androidx.fragment.app.Fragment -import androidx.lifecycle.* +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -import kotlin.properties.ReadOnlyProperty fun CoroutineScope.asLiveData(flow: Flow): LiveData { val liveData = MutableLiveData() diff --git a/app/src/test/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSourceTest.kt b/app/src/test/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSourceTest.kt index 03a10b2..b65bf87 100644 --- a/app/src/test/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSourceTest.kt +++ b/app/src/test/java/org/fnives/tiktokdownloader/data/local/VideoInPendingLocalSourceTest.kt @@ -76,11 +76,11 @@ class VideoInPendingLocalSourceTest { } @Test - fun GIVEN_observing_PendingVideos_WHEN_2_video_marked_as_pending_THEN_both_of_them_are_sent_out_in_correct_reverse_order() = + fun GIVEN_observing_PendingVideos_WHEN_2_video_marked_as_pending_THEN_both_of_them_are_sent_out_in_correct_order() = runBlocking { val videoInPending1 = VideoInPending("id1", "alma1") val videoInPending2 = VideoInPending("id2", "alma2") - val expected = listOf(emptyList(), listOf(videoInPending1), listOf(videoInPending2, videoInPending1)) + val expected = listOf(emptyList(), listOf(videoInPending1), listOf(videoInPending1, videoInPending2)) val actual = async(coroutineContext) { sut.pendingVideos.take(3).toList()