aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-11-23 12:06:40 -0800
committerAllan Wang <me@allanwang.ca>2021-11-23 12:06:40 -0800
commit98b46d9e5341ac827ec776c6e5dd48ac301d4522 (patch)
tree248197175124d221bd79576b4537f49961e61e15
parent602290c33ac25f9308f8adfc459033cd50e13497 (diff)
downloadfrost-98b46d9e5341ac827ec776c6e5dd48ac301d4522.tar.gz
frost-98b46d9e5341ac827ec776c6e5dd48ac301d4522.tar.bz2
frost-98b46d9e5341ac827ec776c6e5dd48ac301d4522.zip
Begin removing experimental coroutines annotation
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt7
-rw-r--r--app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt35
3 files changed, 4 insertions, 40 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
index 8585f68b..9d16c63a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -130,7 +130,6 @@ import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.scopes.ActivityScoped
-import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlin.math.abs
@@ -140,7 +139,6 @@ import kotlin.math.abs
*
* Most of the logic that is unrelated to handling fragments
*/
-@UseExperimental(ExperimentalCoroutinesApi::class)
@AndroidEntryPoint
abstract class BaseMainActivity :
BaseActivity(),
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index 2e44e5f9..16606691 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -26,7 +26,6 @@ import com.pitchedapps.frost.views.BadgedIcon
import com.pitchedapps.frost.web.FrostEmitter
import com.pitchedapps.frost.web.asFrostEmitter
import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -39,10 +38,12 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
-@UseExperimental(ExperimentalCoroutinesApi::class)
class MainActivity : BaseMainActivity() {
- private val fragmentMutableFlow = MutableSharedFlow<Int>(extraBufferCapacity = 10, onBufferOverflow = BufferOverflow.DROP_OLDEST)
+ private val fragmentMutableFlow = MutableSharedFlow<Int>(
+ extraBufferCapacity = 10,
+ onBufferOverflow = BufferOverflow.DROP_OLDEST
+ )
override val fragmentFlow: SharedFlow<Int> = fragmentMutableFlow.asSharedFlow()
override val fragmentEmit: FrostEmitter<Int> = fragmentMutableFlow.asFrostEmitter()
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
index 551d0b7b..7acb4761 100644
--- a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
+++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
@@ -17,22 +17,18 @@
package com.pitchedapps.frost.utils
import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.async
-import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.count
import kotlinx.coroutines.flow.filterNotNull
-import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
-import kotlinx.coroutines.withContext
import java.util.concurrent.Executors
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.Test
@@ -43,39 +39,8 @@ import kotlin.test.assertTrue
/**
* Collection of tests around coroutines
*/
-@UseExperimental(ExperimentalCoroutinesApi::class)
class CoroutineTest {
- /**
- * Hooks onto the refresh channel for one true -> false cycle.
- * Returns the list of event ids that were emitted
- */
- private suspend fun transition(channel: ReceiveChannel<Pair<Boolean, Int>>): List<Pair<Boolean, Int>> {
- var refreshed = false
- return listen(channel) { (refreshing, _) ->
- if (refreshed && !refreshing)
- return@listen true
- if (refreshing)
- refreshed = true
- return@listen false
- }
- }
-
- private suspend fun <T> listen(
- channel: ReceiveChannel<T>,
- shouldEnd: suspend (T) -> Boolean = { false }
- ): List<T> =
- withContext(Dispatchers.IO) {
- val data = mutableListOf<T>()
- channel.receiveAsFlow()
- for (c in channel) {
- data.add(c)
- if (shouldEnd(c)) break
- }
- channel.cancel()
- return@withContext data
- }
-
private fun <T : Any> SharedFlow<T?>.takeUntilNull(): Flow<T> =
takeWhile { it != null }.filterNotNull()