Skip to content

Commit

Permalink
feat: add support for using OONI Icons in descriptors. (#244)
Browse files Browse the repository at this point in the history
* allow ooni icons to be used for descriptors.
  • Loading branch information
aanorbel authored Nov 18, 2024
1 parent 65620ab commit f717826
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import kotlinx.datetime.format.MonthNames
import kotlinx.datetime.format.char
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_LastUpdatd
import ooniprobe.composeapp.generated.resources.months
import ooniprobe.composeapp.generated.resources.test_circumvention
import ooniprobe.composeapp.generated.resources.test_experimental
import ooniprobe.composeapp.generated.resources.test_instant_messaging
import ooniprobe.composeapp.generated.resources.test_performance
import ooniprobe.composeapp.generated.resources.test_websites
import org.jetbrains.compose.resources.stringArrayResource
import org.ooni.probe.data.TestDescriptor
import org.ooni.probe.shared.InstalledDescriptorIcons
Expand Down Expand Up @@ -74,14 +79,24 @@ fun InstalledTestDescriptorModel.toDescriptor(updateStatus: UpdateStatus = Updat
},
icon = icon?.let(InstalledDescriptorIcons::getIconFromValue),
color = color?.hexToColor(),
animation = animation?.let(Animation::fromFileName),
animation = icon?.let { determineAnimation(it) } ?: animation?.let(Animation::fromFileName),
dataUsage = { null },
expirationDate = expirationDate,
netTests = netTests.orEmpty(),
source = Descriptor.Source.Installed(this),
updateStatus = updateStatus,
)

private val iconAnimationMap = mapOf(
Res.drawable.test_websites to Animation.Websites,
Res.drawable.test_instant_messaging to Animation.InstantMessaging,
Res.drawable.test_circumvention to Animation.Circumvention,
Res.drawable.test_performance to Animation.Performance,
Res.drawable.test_experimental to Animation.Experimental,
)

private fun determineAnimation(icon: String): Animation? = iconAnimationMap[InstalledDescriptorIcons.getIconFromValue(icon)]

private fun dateTimeFormat(monthNames: List<String>) =
Format {
monthName(MonthNames(monthNames))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ import ooniprobe.composeapp.generated.resources.fa_umbrella
import ooniprobe.composeapp.generated.resources.fa_utensils
import ooniprobe.composeapp.generated.resources.fa_wine_glass
import ooniprobe.composeapp.generated.resources.ooni_empty_state
import ooniprobe.composeapp.generated.resources.test_circumvention
import ooniprobe.composeapp.generated.resources.test_experimental
import ooniprobe.composeapp.generated.resources.test_instant_messaging
import ooniprobe.composeapp.generated.resources.test_performance
import ooniprobe.composeapp.generated.resources.test_websites
import org.jetbrains.compose.resources.DrawableResource

enum class InstalledDescriptorIcons(
Expand Down Expand Up @@ -170,6 +175,11 @@ enum class InstalledDescriptorIcons(
FaUmbrella("FaUmbrella", Res.drawable.fa_umbrella),
FaUtensils("FaUtensils", Res.drawable.fa_utensils),
FaWineGlass("FaWineGlass", Res.drawable.fa_wine_glass),
OoniWebsites("OoniWebsites", Res.drawable.test_websites),
OoniInstantMessaging("OoniInstantMessaging", Res.drawable.test_instant_messaging),
OoniCircumvention("OoniCircumvention", Res.drawable.test_circumvention),
OoniPerformance("OoniPerformance", Res.drawable.test_performance),
OoniExperimental("OoniExperimental", Res.drawable.test_experimental),
;

companion object {
Expand Down

0 comments on commit f717826

Please sign in to comment.