From 0b336610df9fda7e202ef2bc3f1ea5b10a477c18 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sat, 21 Nov 2020 11:09:44 -0700 Subject: [PATCH] WIP: Move to KMP --- .../java/com/wbrawner/pihelper/AddPiHelperViewModel.kt | 2 +- .../java/com/wbrawner/pihelper/PiHelperApplication.kt | 2 -- .../main/java/com/wbrawner/pihelper/PiHelperModule.kt | 9 ++++++++- .../main/java/com/wbrawner/pihelper/PiHelperViewModel.kt | 2 +- shared/build.gradle.kts | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) rename {app => android}/src/main/java/com/wbrawner/pihelper/PiHelperModule.kt (75%) diff --git a/android/src/main/java/com/wbrawner/pihelper/AddPiHelperViewModel.kt b/android/src/main/java/com/wbrawner/pihelper/AddPiHelperViewModel.kt index 9b5d1f3..8353931 100644 --- a/android/src/main/java/com/wbrawner/pihelper/AddPiHelperViewModel.kt +++ b/android/src/main/java/com/wbrawner/pihelper/AddPiHelperViewModel.kt @@ -20,7 +20,7 @@ const val IP_MAX = 255 class AddPiHelperViewModel( private val sharedPreferences: SharedPreferences, - private val apiService: PiHoleApiService = KtorPiHoleApiService() + private val apiService: PiHoleApiService ) : ViewModel() { @Volatile diff --git a/android/src/main/java/com/wbrawner/pihelper/PiHelperApplication.kt b/android/src/main/java/com/wbrawner/pihelper/PiHelperApplication.kt index a346e9a..985ce3c 100644 --- a/android/src/main/java/com/wbrawner/pihelper/PiHelperApplication.kt +++ b/android/src/main/java/com/wbrawner/pihelper/PiHelperApplication.kt @@ -2,7 +2,6 @@ package com.wbrawner.pihelper import android.app.Application import android.content.Context -import com.wbrawner.piholeclient.piHoleClientModule import org.koin.android.ext.koin.androidContext import org.koin.android.ext.koin.androidLogger import org.koin.core.context.startKoin @@ -15,7 +14,6 @@ class PiHelperApplication: Application() { androidLogger() androidContext(this@PiHelperApplication) modules(listOf( - piHoleClientModule, piHelperModule )) } diff --git a/app/src/main/java/com/wbrawner/pihelper/PiHelperModule.kt b/android/src/main/java/com/wbrawner/pihelper/PiHelperModule.kt similarity index 75% rename from app/src/main/java/com/wbrawner/pihelper/PiHelperModule.kt rename to android/src/main/java/com/wbrawner/pihelper/PiHelperModule.kt index adf00c6..7a470f7 100644 --- a/app/src/main/java/com/wbrawner/pihelper/PiHelperModule.kt +++ b/android/src/main/java/com/wbrawner/pihelper/PiHelperModule.kt @@ -1,12 +1,15 @@ package com.wbrawner.pihelper import androidx.security.crypto.EncryptedSharedPreferences -import com.wbrawner.piholeclient.NAME_BASE_URL +import com.wbrawner.pihelper.shared.KtorPiHoleApiService +import com.wbrawner.pihelper.shared.PiHoleApiService +import com.wbrawner.pihelper.shared.httpClient import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.core.qualifier.named import org.koin.dsl.module const val ENCRYPTED_SHARED_PREFS_FILE_NAME = "pihelper.prefs" +const val NAME_BASE_URL = "baseUrl" val piHelperModule = module { single { @@ -30,4 +33,8 @@ val piHelperModule = module { single(named(NAME_BASE_URL)) { get().getString(KEY_BASE_URL, "") } + + single { + KtorPiHoleApiService(httpClient()) + } } \ No newline at end of file diff --git a/android/src/main/java/com/wbrawner/pihelper/PiHelperViewModel.kt b/android/src/main/java/com/wbrawner/pihelper/PiHelperViewModel.kt index 3831fbc..cf0061a 100644 --- a/android/src/main/java/com/wbrawner/pihelper/PiHelperViewModel.kt +++ b/android/src/main/java/com/wbrawner/pihelper/PiHelperViewModel.kt @@ -2,7 +2,7 @@ package com.wbrawner.pihelper import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import com.wbrawner.piholeclient.PiHoleApiService +import com.wbrawner.pihelper.shared.PiHoleApiService import com.wbrawner.pihelper.shared.Status import com.wbrawner.pihelper.shared.StatusProvider import kotlinx.coroutines.delay diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 6457525..295af86 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -41,7 +41,7 @@ kotlin { val androidMain by getting { dependencies { implementation("com.google.android.material:material:1.2.0") - implementation("io.ktor:ktor-client-android:$ktor_version") + api("io.ktor:ktor-client-android:$ktor_version") } } val androidTest by getting {