diff --git a/mono-build-logic/android-k-plugins/build.gradle.kts b/mono-build-logic/android-k-plugins/build.gradle.kts index 74149df..c21895d 100644 --- a/mono-build-logic/android-k-plugins/build.gradle.kts +++ b/mono-build-logic/android-k-plugins/build.gradle.kts @@ -4,6 +4,6 @@ plugins { dependencies { api(project(":android-plugins")) - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31") implementation("com.android.tools.build:gradle:7.0.4") } diff --git a/mono-build-logic/android-k-plugins/src/main/kotlin/app-android-module.gradle.kts b/mono-build-logic/android-k-plugins/src/main/kotlin/app-android-module.gradle.kts index eb5b8eb..1dbffd6 100644 --- a/mono-build-logic/android-k-plugins/src/main/kotlin/app-android-module.gradle.kts +++ b/mono-build-logic/android-k-plugins/src/main/kotlin/app-android-module.gradle.kts @@ -1,5 +1,3 @@ -import com.blundell.systemPropertyIsInAppPurchaseTest - plugins { id("android-module") id("com.android.application") @@ -15,11 +13,7 @@ android { } getByName("debug") { isDebuggable = true - if (systemPropertyIsInAppPurchaseTest()) { - println(" IAP TEST - DEBUG BUILD WITH PROD PACKAGE NAME -") - } else { - applicationIdSuffix = ".debug" - } + applicationIdSuffix = ".debug" } } } diff --git a/mono-build-logic/android-k-plugins/src/main/kotlin/com/blundell/GradleKtsExtensions.kt b/mono-build-logic/android-k-plugins/src/main/kotlin/com/blundell/GradleKtsExtensions.kt deleted file mode 100644 index 934c4e2..0000000 --- a/mono-build-logic/android-k-plugins/src/main/kotlin/com/blundell/GradleKtsExtensions.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.blundell - -import com.android.build.api.dsl.ApplicationDefaultConfig -import com.android.build.api.dsl.VariantDimension - -fun ApplicationDefaultConfig.appIdentifier(): String { - return "${applicationId}${applicationIdSuffix ?: ""}" -} - -fun VariantDimension.buildConfigStringField(key: String, value: String) { - buildConfigField("String", key, value) - println(" $key BuildConfig: $value") -} - -fun VariantDimension.resStringValue(key: String, value: String) { - resValue("string", key, value) - println(" $key ResourceString: $value") -} - -fun quotedString(value: String): String { - return "\"${value}\"" -} - -fun systemPropertyIsInAppPurchaseTest(): Boolean { - return System.getProperty("iap-test", "false").toBoolean() -} - -/** - * Cannot access class 'java.io.File'. Check your module classpath for missing or conflicting dependencies - * ^ avoiding this errors (seems like a gradle bug) by duplicating this method in each settings.gradle.kts - */ -//fun SettingsDelegate.monoInclude(name: String) { -// include(":$name") -// val project: ProjectDescriptor = project(":$name") -// project.projectDir = File("../mono-libraries/$name") -//} diff --git a/mono-build-logic/android-k-plugins/src/main/kotlin/com/blundell/SemVersion.kt b/mono-build-logic/android-k-plugins/src/main/kotlin/com/blundell/SemVersion.kt deleted file mode 100644 index 37c22f6..0000000 --- a/mono-build-logic/android-k-plugins/src/main/kotlin/com/blundell/SemVersion.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.blundell - -data class SemVersion(val major: Int, val minor: Int, val patch: Int, val build: Int) { - - /** - * 'nnn.nnn.nnn' (leading zero's dropped) - */ - fun asCode(): Int { - return (major * 10_000 + minor * 1000 + patch * 100) + build - } - - fun asName(): String { - return "$major.$minor.$patch" - } -} diff --git a/mono-build-logic/android-plugins/build.gradle.kts b/mono-build-logic/android-plugins/build.gradle.kts index e04159b..7b4734e 100644 --- a/mono-build-logic/android-plugins/build.gradle.kts +++ b/mono-build-logic/android-plugins/build.gradle.kts @@ -3,6 +3,6 @@ plugins { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31") implementation("com.android.tools.build:gradle:7.0.4") } diff --git a/mono-build-logic/android-plugins/src/main/groovy/android-module.gradle b/mono-build-logic/android-plugins/src/main/groovy/android-module.gradle index 8e03b91..489993a 100644 --- a/mono-build-logic/android-plugins/src/main/groovy/android-module.gradle +++ b/mono-build-logic/android-plugins/src/main/groovy/android-module.gradle @@ -18,7 +18,7 @@ afterEvaluate { project -> unitTests.returnDefaultValues = true } composeOptions { - kotlinCompilerExtensionVersion "1.1.0-rc02" + kotlinCompilerExtensionVersion compose_version } packagingOptions { resources { diff --git a/mono-build-logic/tut-app-1-plugins/build.gradle.kts b/mono-build-logic/tut-app-1-plugins/build.gradle.kts index b6af606..f593623 100644 --- a/mono-build-logic/tut-app-1-plugins/build.gradle.kts +++ b/mono-build-logic/tut-app-1-plugins/build.gradle.kts @@ -1,11 +1,9 @@ plugins { -// id("groovy-gradle-plugin") // This enables src/main/groovy `kotlin-dsl` // This enables src/main/kotlin -// id("java-gradle-plugin") } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30") // 1.4.10 - implementation("com.android.tools.build:gradle:7.0.4") //4.1.0 + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31") + implementation("com.android.tools.build:gradle:7.0.4") implementation(project(":android-k-plugins")) } diff --git a/mono-build-logic/tut-app-1-plugins/src/main/kotlin/tut-app-1.gradle.kts b/mono-build-logic/tut-app-1-plugins/src/main/kotlin/tut-app-1.gradle.kts index bb24a1b..bc2f757 100644 --- a/mono-build-logic/tut-app-1-plugins/src/main/kotlin/tut-app-1.gradle.kts +++ b/mono-build-logic/tut-app-1-plugins/src/main/kotlin/tut-app-1.gradle.kts @@ -1,5 +1,3 @@ -import com.blundell.SemVersion - plugins { id("app-android-module") } @@ -7,10 +5,7 @@ plugins { android { defaultConfig { applicationId = "com.blundell.tut1" - - SemVersion(0, 1, 0, 0).apply { - versionCode = asCode() - versionName = asName() - } + versionCode = 1 + versionName = "1.0.0" } } diff --git a/mono-build-logic/tut-app-2-plugins/build.gradle.kts b/mono-build-logic/tut-app-2-plugins/build.gradle.kts index b6af606..f593623 100644 --- a/mono-build-logic/tut-app-2-plugins/build.gradle.kts +++ b/mono-build-logic/tut-app-2-plugins/build.gradle.kts @@ -1,11 +1,9 @@ plugins { -// id("groovy-gradle-plugin") // This enables src/main/groovy `kotlin-dsl` // This enables src/main/kotlin -// id("java-gradle-plugin") } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30") // 1.4.10 - implementation("com.android.tools.build:gradle:7.0.4") //4.1.0 + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31") + implementation("com.android.tools.build:gradle:7.0.4") implementation(project(":android-k-plugins")) } diff --git a/mono-build-logic/tut-app-2-plugins/src/main/kotlin/tut-app-2.gradle.kts b/mono-build-logic/tut-app-2-plugins/src/main/kotlin/tut-app-2.gradle.kts index beb4666..ff452d6 100644 --- a/mono-build-logic/tut-app-2-plugins/src/main/kotlin/tut-app-2.gradle.kts +++ b/mono-build-logic/tut-app-2-plugins/src/main/kotlin/tut-app-2.gradle.kts @@ -1,5 +1,3 @@ -import com.blundell.SemVersion - plugins { id("app-android-module") } @@ -7,10 +5,7 @@ plugins { android { defaultConfig { applicationId = "com.blundell.tut2" - - SemVersion(0, 1, 3, 0).apply { - versionCode = asCode() - versionName = asName() - } + versionCode = 13 + versionName = "1.3.0" } } diff --git a/mono-libraries/http/README.md b/mono-libraries/http/README.md index cec4b8f..6f09133 100644 --- a/mono-libraries/http/README.md +++ b/mono-libraries/http/README.md @@ -1,5 +1 @@ This module handles talking through HTTP. -It also makes some assumptions about mobile connections: -- we'll want to retry failed connections a few times before reporting an error -- we expect timeouts to be longer than the default on mobile (TODO) -- we want errors to be reported as kotlin.Result and not exceptions diff --git a/mono-libraries/http/src/main/java/modularisation/blundell/library/http/OkHttpExecutor.kt b/mono-libraries/http/src/main/java/modularisation/blundell/library/http/OkHttpExecutor.kt index 10160d3..71954fd 100644 --- a/mono-libraries/http/src/main/java/modularisation/blundell/library/http/OkHttpExecutor.kt +++ b/mono-libraries/http/src/main/java/modularisation/blundell/library/http/OkHttpExecutor.kt @@ -34,6 +34,9 @@ class OkHttpExecutor( } catch (e: InterruptedIOException) { logg.e("Interrupted exception.") return Result.failure(NetworkException(Timeout(e))) + } catch (e: Exception) { + logg.e("Catch all exception.") + return Result.failure(NetworkException(Timeout(e))) } } diff --git a/tut-app-1/app/build.gradle.kts b/tut-app-1/app/build.gradle.kts index 3f27c9f..e648ed5 100644 --- a/tut-app-1/app/build.gradle.kts +++ b/tut-app-1/app/build.gradle.kts @@ -5,9 +5,7 @@ plugins { dependencies { val implementation by configurations val debugImplementation by configurations - val testImplementation by configurations - implementation(project(":http")) implementation(project(":logging")) val composeVersion = rootProject.extra["compose_version"] @@ -23,6 +21,4 @@ dependencies { implementation("androidx.activity:activity-compose:1.4.0") debugImplementation("androidx.compose.ui:ui-tooling:$composeVersion") - - testImplementation("junit:junit:latest.release") } diff --git a/tut-app-1/app/src/main/java/com/blundell/tut1/AppViewModelFactory.kt b/tut-app-1/app/src/main/java/com/blundell/tut1/AppViewModelFactory.kt index 3bf0ea4..4ea1846 100644 --- a/tut-app-1/app/src/main/java/com/blundell/tut1/AppViewModelFactory.kt +++ b/tut-app-1/app/src/main/java/com/blundell/tut1/AppViewModelFactory.kt @@ -3,7 +3,6 @@ package com.blundell.tut1 import android.app.Application import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import modularisation.blundell.library.http.api.HttpBootstrapper import modularisation.blundell.library.logging.api.LoggBootstrapper class AppViewModelFactory( @@ -12,11 +11,9 @@ class AppViewModelFactory( override fun create(modelClass: Class): T { val logg = LoggBootstrapper.getLogger(BuildConfig.DEBUG, "TUT1") - val httpNetworker = HttpBootstrapper.getHttpNetworker(logg) @Suppress("UNCHECKED_CAST") return MainViewModel( logg, - httpNetworker, ) as T } } diff --git a/tut-app-1/app/src/main/java/com/blundell/tut1/MainActivity.kt b/tut-app-1/app/src/main/java/com/blundell/tut1/MainActivity.kt index 9691637..692c6fe 100644 --- a/tut-app-1/app/src/main/java/com/blundell/tut1/MainActivity.kt +++ b/tut-app-1/app/src/main/java/com/blundell/tut1/MainActivity.kt @@ -23,27 +23,15 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + logg.d("onCreate") val model: MainViewModel by viewModels { AppViewModelFactory(this.application) } - model.viewState.observe(this) { state -> - when (state) { - is ViewState.Complete -> logg.d("State complete.") - is ViewState.Error -> logg.d("State error.") - is ViewState.Loading -> logg.d("State loading.") - ViewState.Idle -> logg.d("State idle.") - } - } model.onStart() setContent { Tut1Theme { val state by (viewModel() as MainViewModel).viewState.observeAsState(ViewState.Idle) when (state) { - is ViewState.Idle -> { - Surface(color = MaterialTheme.colors.background) { - Text(text = "Welcome!") - } - } is ViewState.Complete -> { val stateComplete = state as ViewState.Complete Surface(color = MaterialTheme.colors.background) { @@ -53,15 +41,6 @@ class MainActivity : ComponentActivity() { ) } } - is ViewState.Error -> { - val stateError = state as ViewState.Error - Surface(color = MaterialTheme.colors.background) { - Text( - style = MaterialTheme.typography.h3, - text = stateError.errorMessage, - ) - } - } is ViewState.Loading -> { val stateLoading = state as ViewState.Loading Surface(color = MaterialTheme.colors.background) { @@ -72,6 +51,9 @@ class MainActivity : ComponentActivity() { ) } } + else -> { + // TUT do nothing + } } } } diff --git a/tut-app-1/app/src/main/java/com/blundell/tut1/MainViewModel.kt b/tut-app-1/app/src/main/java/com/blundell/tut1/MainViewModel.kt index e305915..c560653 100644 --- a/tut-app-1/app/src/main/java/com/blundell/tut1/MainViewModel.kt +++ b/tut-app-1/app/src/main/java/com/blundell/tut1/MainViewModel.kt @@ -6,12 +6,10 @@ import androidx.lifecycle.viewModelScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import modularisation.blundell.library.http.api.HttpNetworker import modularisation.blundell.library.logging.api.Logg class MainViewModel( private val logg: Logg, - private val httpNetworker: HttpNetworker, ) : ViewModel() { val viewState = MutableLiveData(ViewState.Idle) @@ -19,33 +17,15 @@ class MainViewModel( fun onStart() { logg.d("VM onStart()") viewModelScope.launch(Dispatchers.Main) { - viewState.value = ViewState.Loading("Doing some http background stuff.") + viewState.value = ViewState.Loading("Doing some background world creating stuff.") } viewModelScope.launch(Dispatchers.IO) { - val content = httpNetworker - .getContent("https://your.westlancs.gov.uk/?uprn=100010662672") - if (content.isSuccess) { - val contentHtml = content.getOrThrow() - try { - logg.d("Doing stuff") - delay(1000) - viewModelScope.launch(Dispatchers.Main) { - viewState.value = ViewState.Complete( - "Completed stuff", - ) - } - } catch (ex: Exception) { - logg.e("Failed to do stuff", IllegalStateException("Error in [$contentHtml].")) - viewModelScope.launch(Dispatchers.Main) { - viewState.value = ViewState.Error("Oh no! A reading error occurred, sorry about that.") - } - } - } else { - logg.e("Failed to load.", content.exceptionOrNull()!!) - viewModelScope.launch(Dispatchers.Main) { - viewState.value = ViewState.Error("Oh no! A network error occurred, sorry about that.") - } + logg.d("Doing background stuff.") + delay(2000) + viewModelScope.launch(Dispatchers.Main) { + viewState.value = ViewState.Complete("Hello World!") } + logg.d("Background stuff finished.") } } } @@ -53,6 +33,5 @@ class MainViewModel( sealed class ViewState { data class Complete(val message: String) : ViewState() data class Loading(val loadingMessage: String) : ViewState() - data class Error(val errorMessage: String) : ViewState() object Idle : ViewState() } diff --git a/tut-app-1/app/src/test/java/com/blundell/tut1/ExampleUnitTest.kt b/tut-app-1/app/src/test/java/com/blundell/tut1/ExampleUnitTest.kt deleted file mode 100644 index 0ed9d87..0000000 --- a/tut-app-1/app/src/test/java/com/blundell/tut1/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.blundell.tut1 - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/tut-app-2/app/src/androidTest/java/com/blundell/tut1/ExampleInstrumentedTest.kt b/tut-app-2/app/src/androidTest/java/com/blundell/tut1/ExampleInstrumentedTest.kt deleted file mode 100644 index 08f62ec..0000000 --- a/tut-app-2/app/src/androidTest/java/com/blundell/tut1/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.blundell.tut1 - -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.ext.junit.runners.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.blundell.reallybincolor", appContext.packageName) - } -} diff --git a/tut-app-2/app/src/main/java/com/blundell/tut1/MainActivity.kt b/tut-app-2/app/src/main/java/com/blundell/tut1/MainActivity.kt index 9691637..c00aaab 100644 --- a/tut-app-2/app/src/main/java/com/blundell/tut1/MainActivity.kt +++ b/tut-app-2/app/src/main/java/com/blundell/tut1/MainActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.viewModels +import androidx.compose.foundation.layout.Column import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface @@ -13,7 +14,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel -import com.blundell.tut1.ui.theme.Tut1Theme +import com.blundell.tut1.ui.theme.Tut2Theme import modularisation.blundell.library.logging.api.Logg import modularisation.blundell.library.logging.api.LoggBootstrapper @@ -23,20 +24,13 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + logg.d("onCreate") val model: MainViewModel by viewModels { AppViewModelFactory(this.application) } - model.viewState.observe(this) { state -> - when (state) { - is ViewState.Complete -> logg.d("State complete.") - is ViewState.Error -> logg.d("State error.") - is ViewState.Loading -> logg.d("State loading.") - ViewState.Idle -> logg.d("State idle.") - } - } model.onStart() setContent { - Tut1Theme { + Tut2Theme { val state by (viewModel() as MainViewModel).viewState.observeAsState(ViewState.Idle) when (state) { is ViewState.Idle -> { @@ -55,7 +49,7 @@ class MainActivity : ComponentActivity() { } is ViewState.Error -> { val stateError = state as ViewState.Error - Surface(color = MaterialTheme.colors.background) { + Surface(color = MaterialTheme.colors.error) { Text( style = MaterialTheme.typography.h3, text = stateError.errorMessage, @@ -65,11 +59,13 @@ class MainActivity : ComponentActivity() { is ViewState.Loading -> { val stateLoading = state as ViewState.Loading Surface(color = MaterialTheme.colors.background) { - CircularProgressIndicator() - Text( - style = MaterialTheme.typography.h3, - text = "Loading... ${stateLoading.loadingMessage}", - ) + Column { + CircularProgressIndicator() + Text( + style = MaterialTheme.typography.h3, + text = "Loading... ${stateLoading.loadingMessage}", + ) + } } } } @@ -82,7 +78,7 @@ class MainActivity : ComponentActivity() { @Preview(showBackground = true) @Composable fun DefaultPreview() { - Tut1Theme { + Tut2Theme { Text(text = "Hello ${"Android"}!") } } diff --git a/tut-app-2/app/src/main/java/com/blundell/tut1/MainViewModel.kt b/tut-app-2/app/src/main/java/com/blundell/tut1/MainViewModel.kt index e305915..4c2f4fe 100644 --- a/tut-app-2/app/src/main/java/com/blundell/tut1/MainViewModel.kt +++ b/tut-app-2/app/src/main/java/com/blundell/tut1/MainViewModel.kt @@ -23,19 +23,20 @@ class MainViewModel( } viewModelScope.launch(Dispatchers.IO) { val content = httpNetworker - .getContent("https://your.westlancs.gov.uk/?uprn=100010662672") + .getContent("https://ip-fast.com/api/ip/") if (content.isSuccess) { - val contentHtml = content.getOrThrow() + val apiResultIp = content.getOrThrow() try { logg.d("Doing stuff") delay(1000) viewModelScope.launch(Dispatchers.Main) { viewState.value = ViewState.Complete( - "Completed stuff", + "From https://ip-fast.com/api/ip/ " + + "\nYour IP $apiResultIp", ) } } catch (ex: Exception) { - logg.e("Failed to do stuff", IllegalStateException("Error in [$contentHtml].")) + logg.e("Failed to do stuff", IllegalStateException("Error in [$apiResultIp].")) viewModelScope.launch(Dispatchers.Main) { viewState.value = ViewState.Error("Oh no! A reading error occurred, sorry about that.") } diff --git a/tut-app-2/app/src/main/java/com/blundell/tut1/ui/theme/Theme.kt b/tut-app-2/app/src/main/java/com/blundell/tut1/ui/theme/Theme.kt index 4f0fe95..a3c2a2a 100644 --- a/tut-app-2/app/src/main/java/com/blundell/tut1/ui/theme/Theme.kt +++ b/tut-app-2/app/src/main/java/com/blundell/tut1/ui/theme/Theme.kt @@ -28,7 +28,7 @@ private val LightColorPalette = lightColors( ) @Composable -fun Tut1Theme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) { +fun Tut2Theme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) { val colors = if (darkTheme) { DarkColorPalette } else { diff --git a/tut-app-2/app/src/test/java/com/blundell/tut1/ExampleUnitTest.kt b/tut-app-2/app/src/test/java/com/blundell/tut1/ExampleUnitTest.kt deleted file mode 100644 index b6a1304..0000000 --- a/tut-app-2/app/src/test/java/com/blundell/tut1/ExampleUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.blundell.tut1 - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/tut-app-2/build.gradle.kts b/tut-app-2/build.gradle.kts index 87e267d..52a230e 100644 --- a/tut-app-2/build.gradle.kts +++ b/tut-app-2/build.gradle.kts @@ -10,7 +10,7 @@ buildscript { } dependencies { classpath("com.android.tools.build:gradle:7.0.4") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files