Skip to content

Commit

Permalink
Initial Commit :octocat:
Browse files Browse the repository at this point in the history
  • Loading branch information
blundell committed Jan 5, 2022
0 parents commit 3f4be0c
Show file tree
Hide file tree
Showing 118 changed files with 2,680 additions and 0 deletions.
Empty file added .gitignore
Empty file.
8 changes: 8 additions & 0 deletions mono-build-logic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/.idea
.DS_Store
/build
build/
.externalNativeBuild
.cxx
9 changes: 9 additions & 0 deletions mono-build-logic/android-k-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
`kotlin-dsl` // This enables src/main/kotlin
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30")
implementation("com.android.tools.build:gradle:7.0.4")
api(project(":android-plugins"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import com.blundell.systemPropertyIsInAppPurchaseTest

plugins {
id("android-module")
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
}

android {
buildTypes {
getByName("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
getByName("debug") {
isDebuggable = true
if (systemPropertyIsInAppPurchaseTest()) {
println(" IAP TEST - DEBUG BUILD WITH PROD PACKAGE NAME -")
} else {
applicationIdSuffix = ".debug"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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")
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins {
id("android-module")
id("com.android.library")
id("kotlin-android")
}
8 changes: 8 additions & 0 deletions mono-build-logic/android-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id("groovy-gradle-plugin") // This enables src/main/groovy
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30")
implementation("com.android.tools.build:gradle:7.0.4")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
afterEvaluate { project ->
if (project.hasProperty("android")) {
android {
compileSdk 31

defaultConfig {
minSdk 28
targetSdk 30

vectorDrawables {
useSupportLibrary true
}

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

testOptions {
unitTests.returnDefaultValues = true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
useIR = true
}
buildFeatures {
compose true
}
}
}
}

12 changes: 12 additions & 0 deletions mono-build-logic/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dependencyResolutionManagement {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
}

include("android-plugins")
include("android-k-plugins")
include("tut-app-1-plugins")
include("tut-app-2-plugins")
8 changes: 8 additions & 0 deletions mono-build-logic/tut-app-1-plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/.idea
.DS_Store
/build
build/
.externalNativeBuild
.cxx
11 changes: 11 additions & 0 deletions mono-build-logic/tut-app-1-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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(project(":android-k-plugins"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import com.blundell.SemVersion

plugins {
id("app-android-module")
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
}

android {
defaultConfig {
applicationId = "com.blundell.tut1"

SemVersion(0, 1, 0, 0).apply {
versionCode = asCode()
versionName = asName()
}
}
}
8 changes: 8 additions & 0 deletions mono-build-logic/tut-app-2-plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/.idea
.DS_Store
/build
build/
.externalNativeBuild
.cxx
11 changes: 11 additions & 0 deletions mono-build-logic/tut-app-2-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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(project(":android-k-plugins"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import com.blundell.*

plugins {
id("app-android-module")
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
}

android {
defaultConfig {
applicationId = "com.blundell.tut2"

SemVersion(0, 1, 3, 0).apply {
versionCode = asCode()
versionName = asName()
}
}
}
2 changes: 2 additions & 0 deletions mono-libraries/http/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
.gradle
5 changes: 5 additions & 0 deletions mono-libraries/http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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
14 changes: 14 additions & 0 deletions mono-libraries/http/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id("library-android-module")
}

dependencies {
implementation(project(":logging"))

implementation("androidx.core:core-ktx:1.6.0")
val composeVersion = rootProject.extra["compose_version"]
implementation("androidx.compose.runtime:runtime-livedata:$composeVersion")
implementation("com.squareup.okhttp3:okhttp:4.9.1")

testImplementation("junit:junit:latest.release")
}
4 changes: 4 additions & 0 deletions mono-libraries/http/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="modularisation.blundell.library.http">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package modularisation.blundell.library.http

import modularisation.blundell.library.http.api.NetworkException
import modularisation.blundell.library.http.api.NetworkException.Failure
import modularisation.blundell.library.http.api.NetworkException.Timeout
import modularisation.blundell.library.logging.api.Logg
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import java.io.InterruptedIOException
import java.net.SocketTimeoutException

class OkHttpExecutor(
private val logg: Logg,
private val client: OkHttpClient,
) {

/**
* TODO retries
*/
internal fun execute(request: Request): Result<Response> {
logg.d("Executing request [${request.method}/${request.url}]")
try {
val response = this.client.newCall(request).execute()
if (response.isSuccessful) {
return Result.success(response)
} else {
logg.e("Network exception [${response.code}].")
return Result.failure(NetworkException(Failure("${response.code}/${response.message}")))
}
} catch (e: SocketTimeoutException) {
logg.e("Socket exception.")
return Result.failure(NetworkException(Timeout(e)))
} catch (e: InterruptedIOException) {
logg.e("Interrupted exception.")
return Result.failure(NetworkException(Timeout(e)))
}
}

}
Loading

0 comments on commit 3f4be0c

Please sign in to comment.