network #28

Merged
AmineB merged 28 commits from davidoskky/ReaderForSelfoss-multiplatform:network into master 2022-08-22 19:01:16 +00:00
5 changed files with 13 additions and 29 deletions
Showing only changes of commit 4c78b22614 - Show all commits

View File

@ -207,8 +207,5 @@ dependencies {
implementation("android.arch.work:work-runtime-ktx:1.0.1")
// Network information
// TODO: When updating this library, check if the todo in RepositoryImpl.startNetwork can be resolved
// TODO: Include this library once this is merged https://github.com/ln-12/multiplatform-connectivity-status/pull/4
// implementation("com.github.ln-12:multiplatform-connectivity-status:1.1.0")
implementation(files("../shared/libs/multiplatform-connectivity-status.aar"))
implementation("com.github.ln-12:multiplatform-connectivity-status:1.3.0")
}

View File

@ -22,7 +22,7 @@ import bou.amine.apps.readerforselfossv2.repository.Repository
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.ftinc.scoop.Scoop
import com.github.`ln-12`.library.ConnectivityStatus
import com.github.ln_12.library.ConnectivityStatus
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader
import com.russhwolf.settings.Settings
@ -37,12 +37,14 @@ class MyApp : MultiDexApplication(), DIAware {
override val di by DI.lazy {
import(networkModule)
bind<Repository>() with singleton { Repository(instance(), instance(), ConnectivityStatus(applicationContext)) }
bind<Repository>() with singleton { Repository(instance(), instance(), connectivityStatus) }
bind<ConnectivityStatus>() with singleton { ConnectivityStatus(applicationContext) }
bind<AppViewModel>() with singleton { AppViewModel(repository = instance()) }
}
private val repository: Repository by instance()
private val viewModel: AppViewModel by instance()
private val connectivityStatus: ConnectivityStatus by instance()
private lateinit var config: Config
private lateinit var settings : Settings
@ -60,7 +62,7 @@ class MyApp : MultiDexApplication(), DIAware {
handleNotificationChannels()
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(repository))
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(connectivityStatus, repository))
CoroutineScope(Dispatchers.Main).launch {
viewModel.toastMessageProvider.collect { toastMessage ->
@ -131,15 +133,17 @@ class MyApp : MultiDexApplication(), DIAware {
}
}
class AppLifeCycleObserver(val repository: Repository) : DefaultLifecycleObserver {
class AppLifeCycleObserver(val connectivityStatus: ConnectivityStatus, val repository: Repository) : DefaultLifecycleObserver {
override fun onResume(owner: LifecycleOwner) {
super.onResume(owner)
repository.startNetwork()
repository.connectionMonitored = true
connectivityStatus.start()
}
override fun onPause(owner: LifecycleOwner) {
repository.stopNetwork()
repository.connectionMonitored = false
connectivityStatus.stop()
super.onPause(owner)
}
}

View File

@ -38,9 +38,7 @@ kotlin {
implementation("io.github.aakira:napier:2.6.1")
// Network information
// TODO: Include this library once this is merged https://github.com/ln-12/multiplatform-connectivity-status/pull/4
//implementation("com.github.ln-12:multiplatform-connectivity-status:1.1.0")
implementation(files("libs/multiplatform-connectivity-status.aar"))
implementation("com.github.ln-12:multiplatform-connectivity-status:1.3.0")
}
}
val commonTest by getting {

View File

@ -5,7 +5,7 @@ import bou.amine.apps.readerforselfossv2.rest.SelfossModel
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
import bou.amine.apps.readerforselfossv2.utils.DateUtils
import bou.amine.apps.readerforselfossv2.utils.ItemType
import com.github.`ln-12`.library.ConnectivityStatus
import com.github.ln_12.library.ConnectivityStatus
import com.russhwolf.settings.Settings
import io.github.aakira.napier.Napier
import kotlinx.coroutines.CoroutineScope
@ -342,20 +342,5 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride
// TODO: Start and stop the monitoring within Android and iOS code
// This should be performed in the architecture specific code
// However it is not possible on android due to the dash contained in the name of the library
// com.github.ln-12:multiplatform-connectivity-status:1.1.0
// https://github.com/ln-12/multiplatform-connectivity-status/issues/2
fun startNetwork() {
connectionMonitored = true
connectivityStatus.start()
}
fun stopNetwork() {
connectionMonitored = false
connectivityStatus.stop()
}
// TODO: Handle offline actions
}