network #28
@ -17,6 +17,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.doOnNextLayout
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.*
|
||||
import androidx.room.Room
|
||||
import androidx.work.Constraints
|
||||
@ -178,6 +179,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
|
||||
dataBase = AndroidDeviceDatabase(applicationContext)
|
||||
|
||||
lifecycleScope.launch {
|
||||
AmineB marked this conversation as resolved
Outdated
|
||||
repository.toastMessageState.collect {
|
||||
Toast.makeText(baseContext, it, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
handleBottomBar()
|
||||
handleDrawer()
|
||||
|
||||
|
@ -10,6 +10,9 @@ import com.russhwolf.settings.Settings
|
||||
import io.github.aakira.napier.Napier
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class Repository(private val api: SelfossApi, private val apiDetails: ApiDetailsService, connectivityStatus: ConnectivityStatus) {
|
||||
@ -18,6 +21,9 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
var items = ArrayList<SelfossModel.Item>()
|
||||
private val isConnectionAvailable = connectivityStatus.isNetworkConnected
|
||||
|
||||
private val _toastMessageState = MutableSharedFlow<String>(0)
|
||||
val toastMessageState = _toastMessageState.asSharedFlow()
|
||||
|
||||
var baseUrl = apiDetails.getBaseUrl()
|
||||
lateinit var dateUtils: DateUtils
|
||||
|
||||
@ -45,6 +51,13 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
updateApiVersion()
|
||||
dateUtils = DateUtils(apiMajorVersion)
|
||||
reloadBadges()
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
`isConnectionAvailable.value && !offlineOverride` should be refactored inside a method named `isNetworkAvailable()`
|
||||
|
||||
isConnectionAvailable.asStateFlow().collect { connectionAvailable ->
|
||||
if (!connectionAvailable) {
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
There should be a message emited on network available too. There should be a message emited on network available too.
|
||||
// TODO: Localize this string
|
||||
_toastMessageState.emit("Network connection lost")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
This block should be after the else, since the db will work as a fallback and we'll get the items from there. Same for the other block later. This block should be after the else, since the db will work as a fallback and we'll get the items from there.
Same for the other block later.
davidoskky
commented
I'm not sure how the database will handle this. I'm not sure how the database will handle this.
This is correct as of now, moving this block after the else will generate errors if the else block is encountered since the fetchedItems variables is only defined within the if block.
AmineB
commented
The The `else` block would have the BD fetching that'll assign the DB items to `fetchedItems`.
|
||||
|
Loading…
Reference in New Issue
Block a user
This shouldn't be only on the home activity.
Yes, however it might actually be better to remove this logic from the repository and implement a viewModel to send these messages.
Localization in the common source set appears to be complicated.