From df4903cae57c76d7616690f7f04070d32b80cd76 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sun, 21 Aug 2022 21:30:07 +0200 Subject: [PATCH] Include the connectivity status library as a aar file --- androidApp/build.gradle.kts | 2 +- .../apps/readerforselfossv2/android/MyApp.kt | 2 +- connectionstatus/.gitignore | 1 - connectionstatus/build.gradle.kts | 65 -------------- .../src/androidMain/AndroidManifest.xml | 4 - .../github/ln12/library/ConnectivityStatus.kt | 85 ------------------ .../github/ln12/library/ConnectivityStatus.kt | 12 --- .../github/ln12/library/ConnectivityStatus.kt | 67 -------------- settings.gradle.kts | 3 +- shared/build.gradle.kts | 2 +- .../multiplatform-connectivity-status.aar | Bin 0 -> 5113 bytes .../repository/RepositoryImpl.kt | 2 +- 12 files changed, 5 insertions(+), 240 deletions(-) delete mode 100644 connectionstatus/.gitignore delete mode 100644 connectionstatus/build.gradle.kts delete mode 100644 connectionstatus/src/androidMain/AndroidManifest.xml delete mode 100644 connectionstatus/src/androidMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt delete mode 100644 connectionstatus/src/commonMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt delete mode 100644 connectionstatus/src/iosMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt create mode 100644 shared/libs/multiplatform-connectivity-status.aar diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 6d80981..527731a 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -210,5 +210,5 @@ dependencies { // 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(project(":connectionstatus")) + implementation(files("../shared/libs/multiplatform-connectivity-status.aar")) } \ No newline at end of file diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt index 50a857b..dbd036f 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt @@ -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.ln12.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 diff --git a/connectionstatus/.gitignore b/connectionstatus/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/connectionstatus/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/connectionstatus/build.gradle.kts b/connectionstatus/build.gradle.kts deleted file mode 100644 index 045698e..0000000 --- a/connectionstatus/build.gradle.kts +++ /dev/null @@ -1,65 +0,0 @@ -plugins { - id("com.android.library") - kotlin("multiplatform") -} - -group = "com.github.ln-12" -version = "1.1.0" - -repositories { - google() - mavenCentral() -} - -kotlin { - android { - compilations.all { - kotlinOptions.jvmTarget = "1.8" - } - - publishLibraryVariants("release", "debug") - } - ios() - - sourceSets { - val commonMain by getting { - dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0") - } - } - val commonTest by getting { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - - val androidMain by getting - val androidTest by getting { - dependencies { - implementation(kotlin("test-junit")) - implementation("junit:junit:4.13.2") - } - } - - val iosMain by getting - val iosTest by getting - } -} - -android { - compileSdk = 31 - sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") - defaultConfig { - minSdk = 21 - targetSdk = 31 - } -} - -// metadata is currently not supported for iOS -// https://youtrack.jetbrains.com/issue/KT-44459#focus=Comments-27-4645829.0-0 -kotlin.metadata { - compilations.matching { it.name == "iosMain" }.all { - compileKotlinTaskProvider.configure { enabled = false } - } -} \ No newline at end of file diff --git a/connectionstatus/src/androidMain/AndroidManifest.xml b/connectionstatus/src/androidMain/AndroidManifest.xml deleted file mode 100644 index f3a3bcb..0000000 --- a/connectionstatus/src/androidMain/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/connectionstatus/src/androidMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt b/connectionstatus/src/androidMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt deleted file mode 100644 index 027abed..0000000 --- a/connectionstatus/src/androidMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.github.ln12.library - -import android.content.Context -import android.net.ConnectivityManager -import android.net.Network -import android.net.NetworkCapabilities -import android.net.NetworkRequest -import android.os.Build -import android.util.Log -import kotlinx.coroutines.flow.MutableStateFlow - -// From library com.github.ln-12:multiplatform-connectivity-status:1.1.0 -// https://github.com/ln-12/multiplatform-connectivity-status -// Copyright 2021 Lorenzo Neumann -// Edited by davidoskky as here: https://github.com/ln-12/multiplatform-connectivity-status/pull/4 -actual class ConnectivityStatus(private val context: Context) { - actual val isNetworkConnected = MutableStateFlow(false) - - private var connectivityManager: ConnectivityManager? = null - private val networkCallback = object : ConnectivityManager.NetworkCallback() { - override fun onAvailable(network: Network) { - Log.d("Connectivity status", "Connected") - isNetworkConnected.value = true - } - - override fun onLost(network: Network) { - Log.d("Connectivity status", "Disconnected") - isNetworkConnected.value = false - } - } - - actual fun start() { - try { - if (connectivityManager == null) { - connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - // API 24 and above - connectivityManager!!.registerDefaultNetworkCallback(networkCallback) - - val currentNetwork = connectivityManager!!.activeNetwork - - if(currentNetwork == null) { - isNetworkConnected.value = false - - Log.d("Connectivity status", "Disconnected") - } - } else { - // API 23 and below - val networkRequest = NetworkRequest.Builder().apply { - addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) - } - }.build() - - connectivityManager!!.registerNetworkCallback(networkRequest, networkCallback) - - val currentNetwork = connectivityManager!!.activeNetworkInfo - - if(currentNetwork == null || ( - currentNetwork.type != ConnectivityManager.TYPE_ETHERNET && - currentNetwork.type != ConnectivityManager.TYPE_WIFI && - currentNetwork.type != ConnectivityManager.TYPE_MOBILE - )) { - isNetworkConnected.value = false - - Log.d("Connectivity status", "Disconnected") - } - } - - Log.d("Connectivity status", "Started") - } catch (e: Exception) { - Log.d("Connectivity status", "Failed to start: ${e.message.toString()}") - e.printStackTrace() - isNetworkConnected.value = false - } - } - - actual fun stop() { - connectivityManager?.unregisterNetworkCallback(networkCallback) - Log.d("Connectivity status", "Stopped") - } -} \ No newline at end of file diff --git a/connectionstatus/src/commonMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt b/connectionstatus/src/commonMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt deleted file mode 100644 index 3b25c82..0000000 --- a/connectionstatus/src/commonMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.ln12.library - -import kotlinx.coroutines.flow.MutableStateFlow - -// From library com.github.ln-12:multiplatform-connectivity-status:1.1.0 -// https://github.com/ln-12/multiplatform-connectivity-status -// Copyright 2021 Lorenzo Neumann -expect class ConnectivityStatus { - val isNetworkConnected: MutableStateFlow - fun start() - fun stop() -} \ No newline at end of file diff --git a/connectionstatus/src/iosMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt b/connectionstatus/src/iosMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt deleted file mode 100644 index e3c8970..0000000 --- a/connectionstatus/src/iosMain/kotlin/com/github/ln12/library/ConnectivityStatus.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.github.ln12.library - -import kotlinx.coroutines.flow.MutableStateFlow -import cocoapods.Reachability.* -import kotlinx.coroutines.MainScope -import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.launch -import platform.Foundation.NSLog -import platform.darwin.dispatch_async -import platform.darwin.dispatch_get_main_queue -import kotlin.native.concurrent.freeze - - -// From library com.github.ln-12:multiplatform-connectivity-status:1.1.0 -// https://github.com/ln-12/multiplatform-connectivity-status -// Copyright 2021 Lorenzo Neumann -actual class ConnectivityStatus { - actual val isNetworkConnected = MutableStateFlow(false) - - private var reachability: Reachability? = null - - // Swift can't directly use a MutableStateFlow, so the status - // is exposed via a lambda/closure - fun getStatus(success: (Boolean) -> Unit) { - MainScope().launch { - isNetworkConnected.collect { status -> - success(status) - } - } - } - - actual fun start() { - dispatch_async(dispatch_get_main_queue()) { - reachability = Reachability.reachabilityForInternetConnection() - - val reachableCallback = { reach: Reachability? -> - dispatch_async(dispatch_get_main_queue(), { - NSLog("Connected") - - isNetworkConnected.value = true - }.freeze()) - }.freeze() - reachability?.reachableBlock = reachableCallback - - val unreachableCallback = { reach: Reachability? -> - dispatch_async(dispatch_get_main_queue(), { - NSLog("Disconnected") - - isNetworkConnected.value = false - }.freeze()) - }.freeze() - reachability?.unreachableBlock = unreachableCallback - - reachability?.startNotifier() - - dispatch_async(dispatch_get_main_queue(), { - isNetworkConnected.value = reachability?.isReachable() ?: false - - NSLog("Initial reachability: ${reachability?.isReachable()}") - }.freeze()) - } - } - - actual fun stop() { - reachability?.stopNotifier() - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 9c56c94..0b32ec1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,5 +8,4 @@ pluginManagement { rootProject.name = "ReaderForSelfossV2" include(":androidApp") -include(":shared") -include(":connectionstatus") \ No newline at end of file +include(":shared") \ No newline at end of file diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index ca82dbd..ad4c8a8 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -40,7 +40,7 @@ kotlin { // 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(project(":connectionstatus")) + implementation(files("libs/multiplatform-connectivity-status.aar")) } } val commonTest by getting { diff --git a/shared/libs/multiplatform-connectivity-status.aar b/shared/libs/multiplatform-connectivity-status.aar new file mode 100644 index 0000000000000000000000000000000000000000..2af7712ab4a997267cdfe5f5a42e0a739ab320ce GIT binary patch literal 5113 zcmbW5WmFX0zQ#uy1PSRFKm=)|YiI=NZUMm=Dajc^Lb@A#X@*d`yQHLs9FQ824iNf2{xj{#`c| zg!#d60s8-S$W?%_ec^6X>mC5`@UAPlfxX?GR~+(htW~iR8WIGjGj8$=@RpSC@MV5a|=)7vi}F^GR3eePp#E<%5L$vzX!>P?%M(988#|t zqPZ_Bi}ba!ghcbK1%}!k;*JDf6UKl#L-z-xB&)lud~1fDcxGs>c2}pi316w;TntC7 z&jpbxUpD{~eKYE2(c;RIPpsVk+}pYF;2t|UH8-x)Lyj0(99C_O3z__MIMMs>7-$qZ zEzlGIz!?<)aQ`lbS8wc~PzY4e+0Lsb%U9pXs%uyU-Oa~sZP^zR#x@iZa=NBOMB%JV zZldU{=%1OyrlikCoyyDd5nFpYEvxx(b9+V9cgi>K{Ai*B+Y9d7#1yiCqAO)}ruzW%E=u&I8J|OYN=N-Kd8U`otW z7iotlOaWF(eDs5>a$HK!J{%Ieq9_RHCwO(7eBuf2J@9-McF+*Ri^?>l9WY_X@fyn> zO=s!IT1$GGozXSTe-Rk!Zaa&;Y-$?pmJiNI9Tu_POkkfd`$3Vk0SIQuVV|L_A3YEN z)XWYJEgH@wEarv0U6!~_Q zotA-#bM6JEAOg#J{+%(pa9qJ8bFy&|xcVoi3qlK%%egsMRAF6o-bp3 zZ)Yhl;qTRbO=QZGd}&cQMajh}8&}k3Vvw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%RR)gXa5j(E;(!FhRjxEkK+$2A83P$1 zxv;26vc7Yq8SvIxTqz{j>)uJ%AsYA6wsqh9)-mvQ^$(WkROl6L-fd>~DV8jlygt~q zT;;eorYRUDigWXO^H0?&&n;U0nGrtuExFLATnF^G5mv*Sh6}p?<{~L-NFK2}9s;^6 z>ATW-W~?Njp{pkJ%H37S?%%9P$llxO4Oqy*%MSboB4lUhCEyBy*@5j~c7h&W?j8^? zm=gr5rOod(E;OdYPpl=tJ2io95}y;@(A4HX(Gk$l*5KDrrJb6bfKDL=5EB|?x}&Y) zJ2-cw>K+a??*9$6?(Xxi@iFwD?O%B7?~=dct$zyufRCYff6@O9cKzMp?_lUZ2K;x# o?0;aQzYG7K+<%0scZ})(ouj@MKEXe&@a`t{-3^d;W&prH0RGivlmGw# literal 0 HcmV?d00001 diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index d3876bf..44fc676 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -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.ln12.library.ConnectivityStatus +import com.github.`ln-12`.library.ConnectivityStatus import com.russhwolf.settings.Settings import io.github.aakira.napier.Napier import kotlinx.coroutines.CoroutineScope