mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-25 17:12:38 +01:00
Remove usage of GlobalScope
This commit is contained in:
parent
08aefa270e
commit
aeda8bcc81
@ -22,10 +22,10 @@ import androidx.lifecycle.OnLifecycleEvent
|
|||||||
import arrow.core.Option
|
import arrow.core.Option
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.utils.BehaviorDataSource
|
import im.vector.app.core.utils.BehaviorDataSource
|
||||||
|
import im.vector.app.features.session.coroutineScope
|
||||||
import im.vector.app.features.ui.UiStateRepository
|
import im.vector.app.features.ui.UiStateRepository
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
@ -63,30 +63,30 @@ class AppStateHandler @Inject constructor(
|
|||||||
fun getCurrentRoomGroupingMethod(): RoomGroupingMethod? = selectedSpaceDataSource.currentValue?.orNull()
|
fun getCurrentRoomGroupingMethod(): RoomGroupingMethod? = selectedSpaceDataSource.currentValue?.orNull()
|
||||||
|
|
||||||
fun setCurrentSpace(spaceId: String?, session: Session? = null) {
|
fun setCurrentSpace(spaceId: String?, session: Session? = null) {
|
||||||
val uSession = session ?: activeSessionHolder.getSafeActiveSession()
|
val uSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.BySpace
|
if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.BySpace
|
||||||
&& spaceId == selectedSpaceDataSource.currentValue?.orNull()?.space()?.roomId) return
|
&& spaceId == selectedSpaceDataSource.currentValue?.orNull()?.space()?.roomId) return
|
||||||
val spaceSum = spaceId?.let { uSession?.getRoomSummary(spaceId) }
|
val spaceSum = spaceId?.let { uSession.getRoomSummary(spaceId) }
|
||||||
selectedSpaceDataSource.post(Option.just(RoomGroupingMethod.BySpace(spaceSum)))
|
selectedSpaceDataSource.post(Option.just(RoomGroupingMethod.BySpace(spaceSum)))
|
||||||
if (spaceId != null) {
|
if (spaceId != null) {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
uSession.coroutineScope.launch(Dispatchers.IO) {
|
||||||
tryOrNull {
|
tryOrNull {
|
||||||
uSession?.getRoom(spaceId)?.loadRoomMembersIfNeeded()
|
uSession.getRoom(spaceId)?.loadRoomMembersIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCurrentGroup(groupId: String?, session: Session? = null) {
|
fun setCurrentGroup(groupId: String?, session: Session? = null) {
|
||||||
val uSession = session ?: activeSessionHolder.getSafeActiveSession()
|
val uSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.ByLegacyGroup
|
if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.ByLegacyGroup
|
||||||
&& groupId == selectedSpaceDataSource.currentValue?.orNull()?.group()?.groupId) return
|
&& groupId == selectedSpaceDataSource.currentValue?.orNull()?.group()?.groupId) return
|
||||||
val activeGroup = groupId?.let { uSession?.getGroupSummary(groupId) }
|
val activeGroup = groupId?.let { uSession.getGroupSummary(groupId) }
|
||||||
selectedSpaceDataSource.post(Option.just(RoomGroupingMethod.ByLegacyGroup(activeGroup)))
|
selectedSpaceDataSource.post(Option.just(RoomGroupingMethod.ByLegacyGroup(activeGroup)))
|
||||||
if (groupId != null) {
|
if (groupId != null) {
|
||||||
GlobalScope.launch {
|
uSession.coroutineScope.launch {
|
||||||
tryOrNull {
|
tryOrNull {
|
||||||
uSession?.getGroup(groupId)?.fetchGroupData()
|
uSession.getGroup(groupId)?.fetchGroupData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user