Use the connectivity-status library from the repository rather than the local copy
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
parent
1d5ab3205e
commit
4c78b22614
@ -207,8 +207,5 @@ dependencies {
|
|||||||
implementation("android.arch.work:work-runtime-ktx:1.0.1")
|
implementation("android.arch.work:work-runtime-ktx:1.0.1")
|
||||||
|
|
||||||
// Network information
|
// Network information
|
||||||
// TODO: When updating this library, check if the todo in RepositoryImpl.startNetwork can be resolved
|
implementation("com.github.ln-12:multiplatform-connectivity-status:1.3.0")
|
||||||
// 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"))
|
|
||||||
}
|
}
|
@ -22,7 +22,7 @@ import bou.amine.apps.readerforselfossv2.repository.Repository
|
|||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import com.ftinc.scoop.Scoop
|
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.AbstractDrawerImageLoader
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||||
import com.russhwolf.settings.Settings
|
import com.russhwolf.settings.Settings
|
||||||
@ -37,12 +37,14 @@ class MyApp : MultiDexApplication(), DIAware {
|
|||||||
|
|
||||||
override val di by DI.lazy {
|
override val di by DI.lazy {
|
||||||
import(networkModule)
|
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()) }
|
bind<AppViewModel>() with singleton { AppViewModel(repository = instance()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val repository: Repository by instance()
|
private val repository: Repository by instance()
|
||||||
private val viewModel: AppViewModel by instance()
|
private val viewModel: AppViewModel by instance()
|
||||||
|
private val connectivityStatus: ConnectivityStatus by instance()
|
||||||
private lateinit var config: Config
|
private lateinit var config: Config
|
||||||
private lateinit var settings : Settings
|
private lateinit var settings : Settings
|
||||||
|
|
||||||
@ -60,7 +62,7 @@ class MyApp : MultiDexApplication(), DIAware {
|
|||||||
|
|
||||||
handleNotificationChannels()
|
handleNotificationChannels()
|
||||||
|
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(repository))
|
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(connectivityStatus, repository))
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
viewModel.toastMessageProvider.collect { toastMessage ->
|
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) {
|
override fun onResume(owner: LifecycleOwner) {
|
||||||
super.onResume(owner)
|
super.onResume(owner)
|
||||||
repository.startNetwork()
|
repository.connectionMonitored = true
|
||||||
|
connectivityStatus.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause(owner: LifecycleOwner) {
|
override fun onPause(owner: LifecycleOwner) {
|
||||||
repository.stopNetwork()
|
repository.connectionMonitored = false
|
||||||
|
connectivityStatus.stop()
|
||||||
super.onPause(owner)
|
super.onPause(owner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,7 @@ kotlin {
|
|||||||
implementation("io.github.aakira:napier:2.6.1")
|
implementation("io.github.aakira:napier:2.6.1")
|
||||||
|
|
||||||
// Network information
|
// 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.3.0")
|
||||||
//implementation("com.github.ln-12:multiplatform-connectivity-status:1.1.0")
|
|
||||||
implementation(files("libs/multiplatform-connectivity-status.aar"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val commonTest by getting {
|
val commonTest by getting {
|
||||||
|
Binary file not shown.
@ -5,7 +5,7 @@ import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
|||||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
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 com.russhwolf.settings.Settings
|
||||||
import io.github.aakira.napier.Napier
|
import io.github.aakira.napier.Napier
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -342,20 +342,5 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
|
|
||||||
fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride
|
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
|
// TODO: Handle offline actions
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user