mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Flow migration: remove Shortcuts process from main thread
This commit is contained in:
parent
b93e67ed11
commit
da47bfde2b
4 changed files with 10 additions and 3 deletions
|
@ -137,6 +137,6 @@ object VectorStaticModule {
|
||||||
@Provides
|
@Provides
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun providesCoroutineDispatchers(): CoroutineDispatchers {
|
fun providesCoroutineDispatchers(): CoroutineDispatchers {
|
||||||
return CoroutineDispatchers(io = Dispatchers.IO)
|
return CoroutineDispatchers(io = Dispatchers.IO, computation = Dispatchers.Default)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,6 @@ package im.vector.app.core.dispatchers
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
data class CoroutineDispatchers @Inject constructor(val io: CoroutineDispatcher)
|
data class CoroutineDispatchers @Inject constructor(
|
||||||
|
val io: CoroutineDispatcher,
|
||||||
|
val computation: CoroutineDispatcher)
|
||||||
|
|
|
@ -23,8 +23,11 @@ import androidx.core.content.getSystemService
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
import androidx.lifecycle.asFlow
|
import androidx.lifecycle.asFlow
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import im.vector.app.core.dispatchers.CoroutineDispatchers
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import org.matrix.android.sdk.api.session.room.RoomSortOrder
|
import org.matrix.android.sdk.api.session.room.RoomSortOrder
|
||||||
|
@ -34,6 +37,7 @@ import javax.inject.Inject
|
||||||
|
|
||||||
class ShortcutsHandler @Inject constructor(
|
class ShortcutsHandler @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
private val appDispatchers: CoroutineDispatchers,
|
||||||
private val shortcutCreator: ShortcutCreator,
|
private val shortcutCreator: ShortcutCreator,
|
||||||
private val activeSessionHolder: ActiveSessionHolder
|
private val activeSessionHolder: ActiveSessionHolder
|
||||||
) {
|
) {
|
||||||
|
@ -67,6 +71,7 @@ class ShortcutsHandler @Inject constructor(
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
?.flowOn(appDispatchers.computation)
|
||||||
?.launchIn(coroutineScope)
|
?.launchIn(coroutineScope)
|
||||||
?: Job()
|
?: Job()
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ class KeysExporterTest {
|
||||||
private val keysExporter = KeysExporter(
|
private val keysExporter = KeysExporter(
|
||||||
session = FakeSession(fakeCryptoService = cryptoService),
|
session = FakeSession(fakeCryptoService = cryptoService),
|
||||||
context = context.instance,
|
context = context.instance,
|
||||||
dispatchers = CoroutineDispatchers(Dispatchers.Unconfined)
|
dispatchers = CoroutineDispatchers(Dispatchers.Unconfined, Dispatchers.Unconfined)
|
||||||
)
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|
Loading…
Reference in a new issue