Removing DataSource stops in ViewModels to make sure this is handled by the Screen class
This commit is contained in:
@@ -141,9 +141,6 @@ class CardFeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
|
|||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
LocalCache.live.removeObserver(cacheListener)
|
LocalCache.live.removeObserver(cacheListener)
|
||||||
|
|
||||||
dataSource.stop()
|
|
||||||
viewModelScope.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.screen
|
package com.vitorpamplona.amethyst.ui.screen
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
@@ -16,20 +14,16 @@ import com.vitorpamplona.amethyst.service.NostrGlobalDataSource
|
|||||||
import com.vitorpamplona.amethyst.service.NostrHomeDataSource
|
import com.vitorpamplona.amethyst.service.NostrHomeDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrThreadDataSource
|
import com.vitorpamplona.amethyst.service.NostrThreadDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
|
import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrUserProfileZapsDataSource
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import nostr.postr.events.TextNoteEvent
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
|
||||||
|
|
||||||
class NostrChannelFeedViewModel: FeedViewModel(NostrChannelDataSource)
|
class NostrChannelFeedViewModel: FeedViewModel(NostrChannelDataSource)
|
||||||
class NostrChatRoomFeedViewModel: FeedViewModel(NostrChatRoomDataSource)
|
class NostrChatRoomFeedViewModel: FeedViewModel(NostrChatRoomDataSource)
|
||||||
@@ -139,9 +133,6 @@ abstract class FeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel()
|
|||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
LocalCache.live.removeObserver(cacheListener)
|
LocalCache.live.removeObserver(cacheListener)
|
||||||
|
|
||||||
dataSource.stop()
|
|
||||||
viewModelScope.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,9 +87,6 @@ open class LnZapFeedViewModel(val dataSource: NostrDataSource<Pair<Note, Note>>)
|
|||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
LocalCache.live.removeObserver(cacheListener)
|
LocalCache.live.removeObserver(cacheListener)
|
||||||
|
|
||||||
dataSource.stop()
|
|
||||||
viewModelScope.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,9 +102,6 @@ open class UserFeedViewModel(val dataSource: NostrDataSource<User>): ViewModel()
|
|||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
LocalCache.live.removeObserver(cacheListener)
|
LocalCache.live.removeObserver(cacheListener)
|
||||||
|
|
||||||
dataSource.stop()
|
|
||||||
viewModelScope.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user