Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ooni/probe-multiplatform into feat/…
Browse files Browse the repository at this point in the history
…flavor-support
  • Loading branch information
aanorbel committed Jul 29, 2024
2 parents 0120815 + d020530 commit e40a241
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 214 deletions.
13 changes: 8 additions & 5 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ val appConfig =
AppConfig(
appId = "org.dw.probe",
appName = "News Media Scan",
srcRoot = "src/ooniMain/kotlin",
resRoot = "src/ooniMain/resources",
srcRoot = "src/dwMain/kotlin",
resRoot = "src/dwMain/resources",
),
"ooni" to
AppConfig(
appId = "org.ooni.probe",
appName = "OONI Probe",
srcRoot = "src/dwMain/kotlin",
resRoot = "src/dwMain/resources",
srcRoot = "src/ooniMain/kotlin",
resRoot = "src/ooniMain/resources",
),
)

Expand Down Expand Up @@ -78,8 +78,8 @@ kotlin {
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.kotlin.serialization)
implementation(libs.bundles.tooling)

// add source directories and resources based on flavor
getByName("commonMain") {
kotlin.srcDir(config.srcRoot)
}
Expand Down Expand Up @@ -131,6 +131,9 @@ android {
isMinifyEnabled = false
}
}
buildFeatures {
buildConfig = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
26 changes: 22 additions & 4 deletions composeApp/src/androidMain/kotlin/org/ooni/probe/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package org.ooni.probe

import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import org.ooni.engine.AndroidOonimkallBridge
import org.ooni.probe.di.Dependencies
import org.ooni.probe.shared.Platform
import org.ooni.probe.shared.PlatformInfo

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val bridge = AndroidOonimkallBridge()
val dependencies = Dependencies(bridge, filesDir.absolutePath)

setContent {
App(dependencies)
App(setupDependencies())
}
}

private fun setupDependencies(): Dependencies {
val platformInfo =
object : PlatformInfo {
override val version = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
override val platform = Platform.Android
override val osVersion = Build.VERSION.SDK_INT.toString()
override val model = "${Build.MANUFACTURER} ${Build.MODEL}"
}
val bridge = AndroidOonimkallBridge()
val dependencies =
Dependencies(
platformInfo = platformInfo,
oonimkallBridge = bridge,
baseFileDir = filesDir.absolutePath,
)
return dependencies
}
}
21 changes: 21 additions & 0 deletions composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.ooni.probe

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import co.touchlab.kermit.Logger
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.ooni.probe.di.Dependencies
import org.ooni.probe.ui.AppTheme
Expand All @@ -12,13 +15,31 @@ import org.ooni.probe.ui.main.MainScreen
@Composable
@Preview
fun App(dependencies: Dependencies) {
LaunchedEffect(Unit) {
logAppStart(dependencies)
}

AppTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
MainScreen(
dependencies.mainViewModel,
)
}
}
}

private fun logAppStart(dependencies: Dependencies) {
with(dependencies.platformInfo) {
Logger.i(
"""
---APP START---
Platform: $platform ($osVersion)"
Version: $version
Model: $model
""".trimIndent(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package org.ooni.probe.di
import kotlinx.serialization.json.Json
import org.ooni.engine.Engine
import org.ooni.engine.OonimkallBridge
import org.ooni.probe.shared.PlatformInfo
import org.ooni.probe.ui.main.MainViewModel

class Dependencies(
val platformInfo: PlatformInfo,
private val oonimkallBridge: OonimkallBridge,
private val baseFileDir: String,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ooni.probe.shared

interface PlatformInfo {
val version: String
val platform: Platform
val osVersion: String
val model: String
}

enum class Platform {
Android,
Ios,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,34 @@ package org.ooni.probe
import androidx.compose.ui.window.ComposeUIViewController
import org.ooni.engine.OonimkallBridge
import org.ooni.probe.di.Dependencies
import org.ooni.probe.shared.Platform
import org.ooni.probe.shared.PlatformInfo
import platform.Foundation.NSBundle
import platform.Foundation.NSTemporaryDirectory
import platform.UIKit.UIDevice

fun mainViewController(bridge: OonimkallBridge) =
ComposeUIViewController {
App(Dependencies(bridge, NSTemporaryDirectory()))
App(setupDependencies(bridge))
}

fun setupDependencies(bridge: OonimkallBridge): Dependencies {
return Dependencies(
platformInfo =
object : PlatformInfo {
override val version =
(NSBundle.mainBundle.infoDictionary?.get("CFBundleVersion") as? String).orEmpty()

override val platform = Platform.Ios

override val osVersion =
with(UIDevice.currentDevice) {
"$systemName $systemVersion"
}

override val model = UIDevice.currentDevice.model
},
oonimkallBridge = bridge,
baseFileDir = NSTemporaryDirectory(),
)
}
52 changes: 0 additions & 52 deletions config/dw/build.gradle.kts

This file was deleted.

4 changes: 0 additions & 4 deletions config/dw/src/androidMain/res/values/strings.xml

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions config/dw/src/commonMain/composeResources/values/strings.xml

This file was deleted.

3 changes: 0 additions & 3 deletions config/dw/src/commonMain/kotlin/Config.kt

This file was deleted.

52 changes: 0 additions & 52 deletions config/ooni/build.gradle.kts

This file was deleted.

4 changes: 0 additions & 4 deletions config/ooni/src/androidMain/res/values/strings.xml

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions config/ooni/src/commonMain/kotlin/Config.kt

This file was deleted.

Loading

0 comments on commit e40a241

Please sign in to comment.