network #28

Merged
AmineB merged 28 commits from davidoskky/ReaderForSelfoss-multiplatform:network into master 2022-08-22 19:01:16 +00:00
2 changed files with 6 additions and 3 deletions
Showing only changes of commit 1d5ab3205e - Show all commits

View File

@ -2,13 +2,14 @@ package bou.amine.apps.readerforselfossv2.android.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.repository.Repository
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
class AppViewModel(private val repository: Repository) : ViewModel() {
private val _toastMessageProvider = MutableSharedFlow<String>()
private val _toastMessageProvider = MutableSharedFlow<Int>()
val toastMessageProvider = _toastMessageProvider.asSharedFlow()
private var wasConnected = true
@ -16,10 +17,10 @@ class AppViewModel(private val repository: Repository) : ViewModel() {
viewModelScope.launch {
repository.isConnectionAvailable.collect { isConnected ->
if (isConnected && !wasConnected && repository.connectionMonitored) {
AmineB marked this conversation as resolved Outdated

It would be better to emit an enum. We'll handle the translation on the android/ios side.

It would be better to emit an enum. We'll handle the translation on the android/ios side.

What do you mean? This view model is already in the android side; these strings will have to be localized. I can do it now

What do you mean? This view model is already in the android side; these strings will have to be localized. I can do it now

I didn´t see that it was in the android side.

Yes, please use localized stringd.

I didn´t see that it was in the android side. Yes, please use localized stringd.
_toastMessageProvider.emit("Network connection is now available")
_toastMessageProvider.emit(R.string.network_connectivity_retrieved)
wasConnected = true
} else if (!isConnected && wasConnected && repository.connectionMonitored){
_toastMessageProvider.emit("Network connection lost")
_toastMessageProvider.emit(R.string.network_connectivity_lost)
wasConnected = false
}
}

View File

@ -143,6 +143,8 @@
<string name="pref_switch_update_sources">Check for new sources and tags</string>
<string name="pref_switch_update_sources_summary">Disable this if your server is receiving excessive amounts of database queries.</string>
<string name="no_network_connectivity">Not connected !</string>
<string name="network_connectivity_lost">"Network connection lost"</string>
<string name="network_connectivity_retrieved">"Network connection is now available"</string>
<string name="pref_switch_periodic_refresh">Sync articles</string>
<string name="pref_switch_periodic_refresh_off">Articles will not be synced in the background</string>
<string name="pref_switch_periodic_refresh_on">Articles will periodically be synced</string>