-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
637 additions
and
71 deletions.
There are no files selected for viewing
7 changes: 6 additions & 1 deletion
7
composeApp/src/commonMain/composeResources/drawable/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
|
||
logo.xml | ||
logo.xml | ||
test_experimental.xml | ||
test_performance.xml | ||
test_instant_messaging.xml | ||
test_websites.xml | ||
test_circumvention.xml |
10 changes: 10 additions & 0 deletions
10
composeApp/src/commonMain/composeResources/drawable/ic_chevron_right.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="#000" | ||
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/DefaultTestDescriptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.ooni.probe.data.models | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import org.jetbrains.compose.resources.DrawableResource | ||
import org.jetbrains.compose.resources.StringResource | ||
|
||
data class DefaultTestDescriptor( | ||
val label: String, | ||
val title: StringResource, | ||
val shortDescription: StringResource, | ||
val description: StringResource, | ||
val icon: DrawableResource, | ||
val color: Color, | ||
val animation: String, | ||
val dataUsage: StringResource, | ||
var netTests: List<NetTest>, | ||
var longRunningTests: List<NetTest> = emptyList(), | ||
) |
25 changes: 25 additions & 0 deletions
25
composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/Descriptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.ooni.probe.data.models | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
import org.jetbrains.compose.resources.DrawableResource | ||
|
||
data class Descriptor( | ||
val name: String, | ||
val title: @Composable () -> String, | ||
val shortDescription: @Composable () -> String?, | ||
val description: @Composable () -> String?, | ||
val icon: DrawableResource?, | ||
val color: Color?, | ||
val animation: String?, | ||
val dataUsage: @Composable () -> String?, | ||
val netTests: List<NetTest>, | ||
val longRunningTests: List<NetTest>? = null, | ||
val source: Source, | ||
) { | ||
sealed interface Source { | ||
data class Default(val value: DefaultTestDescriptor) : Source | ||
|
||
data class Installed(val value: InstalledTestDescriptorModel) : Source | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
composeApp/src/commonMain/kotlin/org/ooni/probe/data/models/LocalizationString.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
package org.ooni.probe.data.models | ||
|
||
import androidx.compose.ui.text.intl.Locale | ||
|
||
typealias LocalizationString = Map<String, String> | ||
|
||
fun LocalizationString.getCurrent() = get(Locale.current.language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetTestDescriptors.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.ooni.probe.domain | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.asFlow | ||
import kotlinx.coroutines.flow.flatMapLatest | ||
import kotlinx.coroutines.flow.map | ||
import org.jetbrains.compose.resources.stringResource | ||
import org.ooni.probe.data.models.DefaultTestDescriptor | ||
import org.ooni.probe.data.models.Descriptor | ||
import org.ooni.probe.data.models.InstalledTestDescriptorModel | ||
import org.ooni.probe.data.models.getCurrent | ||
|
||
class GetTestDescriptors( | ||
private val getDefaultTestDescriptors: () -> List<DefaultTestDescriptor>, | ||
private val listInstalledTestDescriptors: () -> Flow<List<InstalledTestDescriptorModel>>, | ||
) { | ||
operator fun invoke(): Flow<List<Descriptor>> { | ||
return suspend { | ||
getDefaultTestDescriptors() | ||
.map { it.toDescriptor() } | ||
}.asFlow() | ||
.flatMapLatest { defaultDescriptors -> | ||
listInstalledTestDescriptors() | ||
.map { list -> list.map { it.toDescriptor() } } | ||
.map { defaultDescriptors + it } | ||
} | ||
} | ||
|
||
private fun DefaultTestDescriptor.toDescriptor() = | ||
Descriptor( | ||
name = label, | ||
title = { stringResource(title) }, | ||
shortDescription = { stringResource(shortDescription) }, | ||
description = { stringResource(description) }, | ||
icon = icon, | ||
color = color, | ||
animation = animation, | ||
dataUsage = { stringResource(dataUsage) }, | ||
netTests = netTests, | ||
longRunningTests = longRunningTests, | ||
source = Descriptor.Source.Default(this), | ||
) | ||
|
||
private fun InstalledTestDescriptorModel.toDescriptor() = | ||
Descriptor( | ||
name = name, | ||
title = { nameIntl?.getCurrent() ?: name }, | ||
shortDescription = { shortDescriptionIntl?.getCurrent() ?: shortDescription }, | ||
description = { descriptionIntl?.getCurrent() ?: description }, | ||
// TODO: fetch drawable resource from path | ||
icon = null, | ||
color = color?.filter { it != '#' }?.toIntOrNull()?.let { Color(it) }, | ||
animation = animation, | ||
dataUsage = { null }, | ||
netTests = netTests.orEmpty(), | ||
source = Descriptor.Source.Installed(this), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.