From 5feeaab2117eb8df393c05450f41a3019f0c7a9b Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Tue, 13 Feb 2024 15:12:43 +0100 Subject: [PATCH 1/3] Feat: Add Icon support for OONI Run v2 descriptors (#649) ## Proposed Changes - Add supported icons in project and track. --- .../adddescriptor/AddDescriptorActivity.kt | 9 +++++- .../ooniprobe/common/OONIDescriptor.kt | 6 +++- .../ooniprobe/common/StringUtils.java | 28 +++++++++++++++++++ .../ooniprobe/model/database/Result.java | 2 +- app/src/main/res/drawable/fa_anchor.xml | 9 ++++++ app/src/main/res/drawable/fa_award.xml | 9 ++++++ app/src/main/res/drawable/fa_bed.xml | 9 ++++++ app/src/main/res/drawable/fa_bone.xml | 9 ++++++ app/src/main/res/drawable/fa_book_reader.xml | 9 ++++++ app/src/main/res/drawable/fa_brush.xml | 9 ++++++ app/src/main/res/drawable/fa_building.xml | 9 ++++++ app/src/main/res/drawable/fa_cake_candles.xml | 9 ++++++ app/src/main/res/drawable/fa_car.xml | 9 ++++++ app/src/main/res/drawable/fa_carrot.xml | 9 ++++++ .../res/drawable/fa_cloud_showers_heavy.xml | 9 ++++++ app/src/main/res/drawable/fa_cloud_sun.xml | 9 ++++++ app/src/main/res/drawable/fa_compass.xml | 9 ++++++ app/src/main/res/drawable/fa_computer.xml | 9 ++++++ app/src/main/res/drawable/fa_crown.xml | 9 ++++++ app/src/main/res/drawable/fa_cube.xml | 9 ++++++ app/src/main/res/drawable/fa_dove.xml | 9 ++++++ app/src/main/res/drawable/fa_dragon.xml | 9 ++++++ app/src/main/res/drawable/fa_droplet.xml | 9 ++++++ app/src/main/res/drawable/fa_faucet.xml | 9 ++++++ app/src/main/res/drawable/fa_feather.xml | 9 ++++++ app/src/main/res/drawable/fa_film.xml | 9 ++++++ app/src/main/res/drawable/fa_fire.xml | 9 ++++++ app/src/main/res/drawable/fa_fish.xml | 9 ++++++ .../main/res/drawable/fa_flag_checkered.xml | 9 ++++++ app/src/main/res/drawable/fa_gauge.xml | 9 ++++++ app/src/main/res/drawable/fa_ghost.xml | 9 ++++++ app/src/main/res/drawable/fa_gift.xml | 9 ++++++ app/src/main/res/drawable/fa_glasses.xml | 9 ++++++ .../main/res/drawable/fa_graduation_cap.xml | 9 ++++++ app/src/main/res/drawable/fa_guitar.xml | 9 ++++++ app/src/main/res/drawable/fa_hammer.xml | 9 ++++++ app/src/main/res/drawable/fa_hand.xml | 9 ++++++ app/src/main/res/drawable/fa_handshake.xml | 9 ++++++ app/src/main/res/drawable/fa_hippo.xml | 9 ++++++ app/src/main/res/drawable/fa_ice_cream.xml | 9 ++++++ app/src/main/res/drawable/fa_industry.xml | 9 ++++++ app/src/main/res/drawable/fa_kiwi_bird.xml | 9 ++++++ app/src/main/res/drawable/fa_magnet.xml | 9 ++++++ app/src/main/res/drawable/fa_map.xml | 9 ++++++ app/src/main/res/drawable/fa_map_signs.xml | 9 ++++++ app/src/main/res/drawable/fa_meteor.xml | 9 ++++++ app/src/main/res/drawable/fa_microscope.xml | 9 ++++++ app/src/main/res/drawable/fa_moon.xml | 9 ++++++ app/src/main/res/drawable/fa_mountain_sun.xml | 9 ++++++ app/src/main/res/drawable/fa_mug_hot.xml | 9 ++++++ app/src/main/res/drawable/fa_music.xml | 9 ++++++ app/src/main/res/drawable/fa_paw.xml | 9 ++++++ app/src/main/res/drawable/fa_pen_nib.xml | 9 ++++++ app/src/main/res/drawable/fa_pepper_hot.xml | 9 ++++++ .../main/res/drawable/fa_person_biking.xml | 9 ++++++ app/src/main/res/drawable/fa_pills.xml | 9 ++++++ app/src/main/res/drawable/fa_plane.xml | 9 ++++++ app/src/main/res/drawable/fa_plug.xml | 9 ++++++ app/src/main/res/drawable/fa_radio.xml | 9 ++++++ app/src/main/res/drawable/fa_rainbow.xml | 9 ++++++ app/src/main/res/drawable/fa_ribbon.xml | 9 ++++++ app/src/main/res/drawable/fa_road.xml | 9 ++++++ app/src/main/res/drawable/fa_rocket.xml | 9 ++++++ app/src/main/res/drawable/fa_sack_dollar.xml | 9 ++++++ app/src/main/res/drawable/fa_school.xml | 9 ++++++ app/src/main/res/drawable/fa_scissors.xml | 9 ++++++ app/src/main/res/drawable/fa_seedling.xml | 9 ++++++ app/src/main/res/drawable/fa_shield.xml | 9 ++++++ app/src/main/res/drawable/fa_skull.xml | 9 ++++++ app/src/main/res/drawable/fa_smile.xml | 9 ++++++ app/src/main/res/drawable/fa_snowflake.xml | 9 ++++++ app/src/main/res/drawable/fa_socks.xml | 9 ++++++ app/src/main/res/drawable/fa_spider.xml | 9 ++++++ .../main/res/drawable/fa_suitcase_medical.xml | 9 ++++++ app/src/main/res/drawable/fa_sun.xml | 9 ++++++ .../fa_temperature_three_quarters.xml | 9 ++++++ app/src/main/res/drawable/fa_tractor.xml | 9 ++++++ app/src/main/res/drawable/fa_tree.xml | 9 ++++++ app/src/main/res/drawable/fa_trophy.xml | 9 ++++++ app/src/main/res/drawable/fa_umbrella.xml | 9 ++++++ .../main/res/drawable/fa_user_astronaut.xml | 9 ++++++ app/src/main/res/drawable/fa_utensils.xml | 9 ++++++ app/src/main/res/drawable/fa_volcano.xml | 9 ++++++ app/src/main/res/drawable/fa_wine_glass.xml | 9 ++++++ 84 files changed, 762 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/openobservatory/ooniprobe/common/StringUtils.java create mode 100644 app/src/main/res/drawable/fa_anchor.xml create mode 100644 app/src/main/res/drawable/fa_award.xml create mode 100644 app/src/main/res/drawable/fa_bed.xml create mode 100644 app/src/main/res/drawable/fa_bone.xml create mode 100644 app/src/main/res/drawable/fa_book_reader.xml create mode 100644 app/src/main/res/drawable/fa_brush.xml create mode 100644 app/src/main/res/drawable/fa_building.xml create mode 100644 app/src/main/res/drawable/fa_cake_candles.xml create mode 100644 app/src/main/res/drawable/fa_car.xml create mode 100644 app/src/main/res/drawable/fa_carrot.xml create mode 100644 app/src/main/res/drawable/fa_cloud_showers_heavy.xml create mode 100644 app/src/main/res/drawable/fa_cloud_sun.xml create mode 100644 app/src/main/res/drawable/fa_compass.xml create mode 100644 app/src/main/res/drawable/fa_computer.xml create mode 100644 app/src/main/res/drawable/fa_crown.xml create mode 100644 app/src/main/res/drawable/fa_cube.xml create mode 100644 app/src/main/res/drawable/fa_dove.xml create mode 100644 app/src/main/res/drawable/fa_dragon.xml create mode 100644 app/src/main/res/drawable/fa_droplet.xml create mode 100644 app/src/main/res/drawable/fa_faucet.xml create mode 100644 app/src/main/res/drawable/fa_feather.xml create mode 100644 app/src/main/res/drawable/fa_film.xml create mode 100644 app/src/main/res/drawable/fa_fire.xml create mode 100644 app/src/main/res/drawable/fa_fish.xml create mode 100644 app/src/main/res/drawable/fa_flag_checkered.xml create mode 100644 app/src/main/res/drawable/fa_gauge.xml create mode 100644 app/src/main/res/drawable/fa_ghost.xml create mode 100644 app/src/main/res/drawable/fa_gift.xml create mode 100644 app/src/main/res/drawable/fa_glasses.xml create mode 100644 app/src/main/res/drawable/fa_graduation_cap.xml create mode 100644 app/src/main/res/drawable/fa_guitar.xml create mode 100644 app/src/main/res/drawable/fa_hammer.xml create mode 100644 app/src/main/res/drawable/fa_hand.xml create mode 100644 app/src/main/res/drawable/fa_handshake.xml create mode 100644 app/src/main/res/drawable/fa_hippo.xml create mode 100644 app/src/main/res/drawable/fa_ice_cream.xml create mode 100644 app/src/main/res/drawable/fa_industry.xml create mode 100644 app/src/main/res/drawable/fa_kiwi_bird.xml create mode 100644 app/src/main/res/drawable/fa_magnet.xml create mode 100644 app/src/main/res/drawable/fa_map.xml create mode 100644 app/src/main/res/drawable/fa_map_signs.xml create mode 100644 app/src/main/res/drawable/fa_meteor.xml create mode 100644 app/src/main/res/drawable/fa_microscope.xml create mode 100644 app/src/main/res/drawable/fa_moon.xml create mode 100644 app/src/main/res/drawable/fa_mountain_sun.xml create mode 100644 app/src/main/res/drawable/fa_mug_hot.xml create mode 100644 app/src/main/res/drawable/fa_music.xml create mode 100644 app/src/main/res/drawable/fa_paw.xml create mode 100644 app/src/main/res/drawable/fa_pen_nib.xml create mode 100644 app/src/main/res/drawable/fa_pepper_hot.xml create mode 100644 app/src/main/res/drawable/fa_person_biking.xml create mode 100644 app/src/main/res/drawable/fa_pills.xml create mode 100644 app/src/main/res/drawable/fa_plane.xml create mode 100644 app/src/main/res/drawable/fa_plug.xml create mode 100644 app/src/main/res/drawable/fa_radio.xml create mode 100644 app/src/main/res/drawable/fa_rainbow.xml create mode 100644 app/src/main/res/drawable/fa_ribbon.xml create mode 100644 app/src/main/res/drawable/fa_road.xml create mode 100644 app/src/main/res/drawable/fa_rocket.xml create mode 100644 app/src/main/res/drawable/fa_sack_dollar.xml create mode 100644 app/src/main/res/drawable/fa_school.xml create mode 100644 app/src/main/res/drawable/fa_scissors.xml create mode 100644 app/src/main/res/drawable/fa_seedling.xml create mode 100644 app/src/main/res/drawable/fa_shield.xml create mode 100644 app/src/main/res/drawable/fa_skull.xml create mode 100644 app/src/main/res/drawable/fa_smile.xml create mode 100644 app/src/main/res/drawable/fa_snowflake.xml create mode 100644 app/src/main/res/drawable/fa_socks.xml create mode 100644 app/src/main/res/drawable/fa_spider.xml create mode 100644 app/src/main/res/drawable/fa_suitcase_medical.xml create mode 100644 app/src/main/res/drawable/fa_sun.xml create mode 100644 app/src/main/res/drawable/fa_temperature_three_quarters.xml create mode 100644 app/src/main/res/drawable/fa_tractor.xml create mode 100644 app/src/main/res/drawable/fa_tree.xml create mode 100644 app/src/main/res/drawable/fa_trophy.xml create mode 100644 app/src/main/res/drawable/fa_umbrella.xml create mode 100644 app/src/main/res/drawable/fa_user_astronaut.xml create mode 100644 app/src/main/res/drawable/fa_utensils.xml create mode 100644 app/src/main/res/drawable/fa_volcano.xml create mode 100644 app/src/main/res/drawable/fa_wine_glass.xml diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt index 2368d9445..8d8a7d4f8 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt @@ -25,6 +25,7 @@ import org.openobservatory.ooniprobe.activity.adddescriptor.adapter.AddDescripto import org.openobservatory.ooniprobe.activity.adddescriptor.adapter.GroupedItem import org.openobservatory.ooniprobe.common.PreferenceManager import org.openobservatory.ooniprobe.common.ReadMorePlugin +import org.openobservatory.ooniprobe.common.StringUtils import org.openobservatory.ooniprobe.common.TestDescriptorManager import org.openobservatory.ooniprobe.databinding.ActivityAddDescriptorBinding import org.openobservatory.ooniprobe.model.database.TestDescriptor @@ -87,7 +88,13 @@ class AddDescriptorActivity : AbstractActivity() { fun setImageViewResource(imageView: ImageView, iconName: String?) { /* TODO(aanorbel): Update to parse the icon name and set the correct icon. * Remember to ignore icons generated when generated doing this.*/ - imageView.setImageResource(R.drawable.ooni_empty_state) + imageView.setImageResource( + imageView.context.resources.getIdentifier( + StringUtils.camelToSnake( + iconName + ), "drawable", imageView.context.packageName + ) + ) } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt index c51823f2b..6f66dc0bc 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt @@ -63,7 +63,11 @@ abstract class AbstractDescriptor( * @return Int representing the display icon for the current descriptor. */ open fun getDisplayIcon(context: Context): Int { - return context.resources.getIdentifier(icon, "drawable", context.packageName).let { + return context.resources.getIdentifier( + StringUtils.camelToSnake( + icon + ), "drawable", context.packageName + ).let { if (it == 0) R.drawable.ooni_empty_state else it } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/StringUtils.java b/app/src/main/java/org/openobservatory/ooniprobe/common/StringUtils.java new file mode 100644 index 000000000..0de33c475 --- /dev/null +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/StringUtils.java @@ -0,0 +1,28 @@ +package org.openobservatory.ooniprobe.common; + +public class StringUtils { + public static String camelToSnake(String camelCase) { + + try { + final char[] name = camelCase.toCharArray(); + final StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < name.length; i++) { + if (Character.isUpperCase(name[i]) || name[i] == '.' || name[i] == '$') { + if (i != 0 && name[i - 1] != '.' && name[i - 1] != '$') { + builder.append('_'); + } + if (name[i] != '.' && name[i] != '$') { + builder.append(Character.toLowerCase(name[i])); + } + } else { + builder.append(name[i]); + } + } + + return builder.toString(); + } catch (Exception e){ + return "ooni_empty_state"; + } + } +} diff --git a/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java b/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java index 36d5a7ba4..898cf761a 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java @@ -251,7 +251,7 @@ public Optional> getDescriptor(Context context) * If there is an {@link IllegalArgumentException} * This should only happen when the test_group_name is not a valid {@link OONITests} value, * Which means the `test_group_name` is not an OONI provided test or an installed `Descriptor`. - * Orphan results for an uninstalled OONI Run v2 descriptor would fall into this category and thus should not exist. + * Orphan resulta for an uninstalled OONI Run v2 descriptor would fall into this category and thus should not exist. * We return an {@link Optional#absent()} object. */ return Optional.absent(); diff --git a/app/src/main/res/drawable/fa_anchor.xml b/app/src/main/res/drawable/fa_anchor.xml new file mode 100644 index 000000000..d4c71aa43 --- /dev/null +++ b/app/src/main/res/drawable/fa_anchor.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_award.xml b/app/src/main/res/drawable/fa_award.xml new file mode 100644 index 000000000..81260d336 --- /dev/null +++ b/app/src/main/res/drawable/fa_award.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_bed.xml b/app/src/main/res/drawable/fa_bed.xml new file mode 100644 index 000000000..45b7c6ebb --- /dev/null +++ b/app/src/main/res/drawable/fa_bed.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_bone.xml b/app/src/main/res/drawable/fa_bone.xml new file mode 100644 index 000000000..dae5e661d --- /dev/null +++ b/app/src/main/res/drawable/fa_bone.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_book_reader.xml b/app/src/main/res/drawable/fa_book_reader.xml new file mode 100644 index 000000000..1f17693a4 --- /dev/null +++ b/app/src/main/res/drawable/fa_book_reader.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_brush.xml b/app/src/main/res/drawable/fa_brush.xml new file mode 100644 index 000000000..47a019528 --- /dev/null +++ b/app/src/main/res/drawable/fa_brush.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_building.xml b/app/src/main/res/drawable/fa_building.xml new file mode 100644 index 000000000..4254f9646 --- /dev/null +++ b/app/src/main/res/drawable/fa_building.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_cake_candles.xml b/app/src/main/res/drawable/fa_cake_candles.xml new file mode 100644 index 000000000..b31b7f87f --- /dev/null +++ b/app/src/main/res/drawable/fa_cake_candles.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_car.xml b/app/src/main/res/drawable/fa_car.xml new file mode 100644 index 000000000..bfcc15eb6 --- /dev/null +++ b/app/src/main/res/drawable/fa_car.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_carrot.xml b/app/src/main/res/drawable/fa_carrot.xml new file mode 100644 index 000000000..4b4321cf8 --- /dev/null +++ b/app/src/main/res/drawable/fa_carrot.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_cloud_showers_heavy.xml b/app/src/main/res/drawable/fa_cloud_showers_heavy.xml new file mode 100644 index 000000000..c6b759dd3 --- /dev/null +++ b/app/src/main/res/drawable/fa_cloud_showers_heavy.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_cloud_sun.xml b/app/src/main/res/drawable/fa_cloud_sun.xml new file mode 100644 index 000000000..51055dad4 --- /dev/null +++ b/app/src/main/res/drawable/fa_cloud_sun.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_compass.xml b/app/src/main/res/drawable/fa_compass.xml new file mode 100644 index 000000000..e56c503e9 --- /dev/null +++ b/app/src/main/res/drawable/fa_compass.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_computer.xml b/app/src/main/res/drawable/fa_computer.xml new file mode 100644 index 000000000..20d95ed3e --- /dev/null +++ b/app/src/main/res/drawable/fa_computer.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_crown.xml b/app/src/main/res/drawable/fa_crown.xml new file mode 100644 index 000000000..db056c763 --- /dev/null +++ b/app/src/main/res/drawable/fa_crown.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_cube.xml b/app/src/main/res/drawable/fa_cube.xml new file mode 100644 index 000000000..e0dc78136 --- /dev/null +++ b/app/src/main/res/drawable/fa_cube.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_dove.xml b/app/src/main/res/drawable/fa_dove.xml new file mode 100644 index 000000000..02fd67b06 --- /dev/null +++ b/app/src/main/res/drawable/fa_dove.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_dragon.xml b/app/src/main/res/drawable/fa_dragon.xml new file mode 100644 index 000000000..523b2add4 --- /dev/null +++ b/app/src/main/res/drawable/fa_dragon.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_droplet.xml b/app/src/main/res/drawable/fa_droplet.xml new file mode 100644 index 000000000..8fabc656f --- /dev/null +++ b/app/src/main/res/drawable/fa_droplet.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_faucet.xml b/app/src/main/res/drawable/fa_faucet.xml new file mode 100644 index 000000000..31ec4b0da --- /dev/null +++ b/app/src/main/res/drawable/fa_faucet.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_feather.xml b/app/src/main/res/drawable/fa_feather.xml new file mode 100644 index 000000000..43fa96de7 --- /dev/null +++ b/app/src/main/res/drawable/fa_feather.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_film.xml b/app/src/main/res/drawable/fa_film.xml new file mode 100644 index 000000000..8611526cb --- /dev/null +++ b/app/src/main/res/drawable/fa_film.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_fire.xml b/app/src/main/res/drawable/fa_fire.xml new file mode 100644 index 000000000..12374376d --- /dev/null +++ b/app/src/main/res/drawable/fa_fire.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_fish.xml b/app/src/main/res/drawable/fa_fish.xml new file mode 100644 index 000000000..e6abd769a --- /dev/null +++ b/app/src/main/res/drawable/fa_fish.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_flag_checkered.xml b/app/src/main/res/drawable/fa_flag_checkered.xml new file mode 100644 index 000000000..29b560fd7 --- /dev/null +++ b/app/src/main/res/drawable/fa_flag_checkered.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_gauge.xml b/app/src/main/res/drawable/fa_gauge.xml new file mode 100644 index 000000000..398f619e1 --- /dev/null +++ b/app/src/main/res/drawable/fa_gauge.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_ghost.xml b/app/src/main/res/drawable/fa_ghost.xml new file mode 100644 index 000000000..e4db79a04 --- /dev/null +++ b/app/src/main/res/drawable/fa_ghost.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_gift.xml b/app/src/main/res/drawable/fa_gift.xml new file mode 100644 index 000000000..a403ac6b8 --- /dev/null +++ b/app/src/main/res/drawable/fa_gift.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_glasses.xml b/app/src/main/res/drawable/fa_glasses.xml new file mode 100644 index 000000000..67e221708 --- /dev/null +++ b/app/src/main/res/drawable/fa_glasses.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_graduation_cap.xml b/app/src/main/res/drawable/fa_graduation_cap.xml new file mode 100644 index 000000000..4730971eb --- /dev/null +++ b/app/src/main/res/drawable/fa_graduation_cap.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_guitar.xml b/app/src/main/res/drawable/fa_guitar.xml new file mode 100644 index 000000000..fe7247ad1 --- /dev/null +++ b/app/src/main/res/drawable/fa_guitar.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_hammer.xml b/app/src/main/res/drawable/fa_hammer.xml new file mode 100644 index 000000000..430262cc0 --- /dev/null +++ b/app/src/main/res/drawable/fa_hammer.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_hand.xml b/app/src/main/res/drawable/fa_hand.xml new file mode 100644 index 000000000..df2d00345 --- /dev/null +++ b/app/src/main/res/drawable/fa_hand.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_handshake.xml b/app/src/main/res/drawable/fa_handshake.xml new file mode 100644 index 000000000..fc7c60c98 --- /dev/null +++ b/app/src/main/res/drawable/fa_handshake.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_hippo.xml b/app/src/main/res/drawable/fa_hippo.xml new file mode 100644 index 000000000..fa35d6ffe --- /dev/null +++ b/app/src/main/res/drawable/fa_hippo.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_ice_cream.xml b/app/src/main/res/drawable/fa_ice_cream.xml new file mode 100644 index 000000000..d50d59cc6 --- /dev/null +++ b/app/src/main/res/drawable/fa_ice_cream.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_industry.xml b/app/src/main/res/drawable/fa_industry.xml new file mode 100644 index 000000000..9b57b66f9 --- /dev/null +++ b/app/src/main/res/drawable/fa_industry.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_kiwi_bird.xml b/app/src/main/res/drawable/fa_kiwi_bird.xml new file mode 100644 index 000000000..025b1d1da --- /dev/null +++ b/app/src/main/res/drawable/fa_kiwi_bird.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_magnet.xml b/app/src/main/res/drawable/fa_magnet.xml new file mode 100644 index 000000000..9a3a6bd91 --- /dev/null +++ b/app/src/main/res/drawable/fa_magnet.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_map.xml b/app/src/main/res/drawable/fa_map.xml new file mode 100644 index 000000000..f40243a69 --- /dev/null +++ b/app/src/main/res/drawable/fa_map.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_map_signs.xml b/app/src/main/res/drawable/fa_map_signs.xml new file mode 100644 index 000000000..9dca18713 --- /dev/null +++ b/app/src/main/res/drawable/fa_map_signs.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_meteor.xml b/app/src/main/res/drawable/fa_meteor.xml new file mode 100644 index 000000000..0e1ea7044 --- /dev/null +++ b/app/src/main/res/drawable/fa_meteor.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_microscope.xml b/app/src/main/res/drawable/fa_microscope.xml new file mode 100644 index 000000000..efed4ff46 --- /dev/null +++ b/app/src/main/res/drawable/fa_microscope.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_moon.xml b/app/src/main/res/drawable/fa_moon.xml new file mode 100644 index 000000000..1d0cb335d --- /dev/null +++ b/app/src/main/res/drawable/fa_moon.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_mountain_sun.xml b/app/src/main/res/drawable/fa_mountain_sun.xml new file mode 100644 index 000000000..99caa011a --- /dev/null +++ b/app/src/main/res/drawable/fa_mountain_sun.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_mug_hot.xml b/app/src/main/res/drawable/fa_mug_hot.xml new file mode 100644 index 000000000..4a3c8a442 --- /dev/null +++ b/app/src/main/res/drawable/fa_mug_hot.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_music.xml b/app/src/main/res/drawable/fa_music.xml new file mode 100644 index 000000000..41e0a80e2 --- /dev/null +++ b/app/src/main/res/drawable/fa_music.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_paw.xml b/app/src/main/res/drawable/fa_paw.xml new file mode 100644 index 000000000..dad4cbb75 --- /dev/null +++ b/app/src/main/res/drawable/fa_paw.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_pen_nib.xml b/app/src/main/res/drawable/fa_pen_nib.xml new file mode 100644 index 000000000..0927a15ce --- /dev/null +++ b/app/src/main/res/drawable/fa_pen_nib.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_pepper_hot.xml b/app/src/main/res/drawable/fa_pepper_hot.xml new file mode 100644 index 000000000..7890e7f97 --- /dev/null +++ b/app/src/main/res/drawable/fa_pepper_hot.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_person_biking.xml b/app/src/main/res/drawable/fa_person_biking.xml new file mode 100644 index 000000000..d971ab9e1 --- /dev/null +++ b/app/src/main/res/drawable/fa_person_biking.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_pills.xml b/app/src/main/res/drawable/fa_pills.xml new file mode 100644 index 000000000..81a8a3278 --- /dev/null +++ b/app/src/main/res/drawable/fa_pills.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_plane.xml b/app/src/main/res/drawable/fa_plane.xml new file mode 100644 index 000000000..fc5a16a07 --- /dev/null +++ b/app/src/main/res/drawable/fa_plane.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_plug.xml b/app/src/main/res/drawable/fa_plug.xml new file mode 100644 index 000000000..115302dd1 --- /dev/null +++ b/app/src/main/res/drawable/fa_plug.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_radio.xml b/app/src/main/res/drawable/fa_radio.xml new file mode 100644 index 000000000..e3508650b --- /dev/null +++ b/app/src/main/res/drawable/fa_radio.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_rainbow.xml b/app/src/main/res/drawable/fa_rainbow.xml new file mode 100644 index 000000000..2e3bd8a31 --- /dev/null +++ b/app/src/main/res/drawable/fa_rainbow.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_ribbon.xml b/app/src/main/res/drawable/fa_ribbon.xml new file mode 100644 index 000000000..efe92f454 --- /dev/null +++ b/app/src/main/res/drawable/fa_ribbon.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_road.xml b/app/src/main/res/drawable/fa_road.xml new file mode 100644 index 000000000..60f571f83 --- /dev/null +++ b/app/src/main/res/drawable/fa_road.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_rocket.xml b/app/src/main/res/drawable/fa_rocket.xml new file mode 100644 index 000000000..5fbcec2a4 --- /dev/null +++ b/app/src/main/res/drawable/fa_rocket.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_sack_dollar.xml b/app/src/main/res/drawable/fa_sack_dollar.xml new file mode 100644 index 000000000..39e4fba30 --- /dev/null +++ b/app/src/main/res/drawable/fa_sack_dollar.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_school.xml b/app/src/main/res/drawable/fa_school.xml new file mode 100644 index 000000000..9e0d3d294 --- /dev/null +++ b/app/src/main/res/drawable/fa_school.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_scissors.xml b/app/src/main/res/drawable/fa_scissors.xml new file mode 100644 index 000000000..4ad5a1163 --- /dev/null +++ b/app/src/main/res/drawable/fa_scissors.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_seedling.xml b/app/src/main/res/drawable/fa_seedling.xml new file mode 100644 index 000000000..dc04ab510 --- /dev/null +++ b/app/src/main/res/drawable/fa_seedling.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_shield.xml b/app/src/main/res/drawable/fa_shield.xml new file mode 100644 index 000000000..667bd6b62 --- /dev/null +++ b/app/src/main/res/drawable/fa_shield.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_skull.xml b/app/src/main/res/drawable/fa_skull.xml new file mode 100644 index 000000000..db0d0b3cd --- /dev/null +++ b/app/src/main/res/drawable/fa_skull.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_smile.xml b/app/src/main/res/drawable/fa_smile.xml new file mode 100644 index 000000000..03ee29dba --- /dev/null +++ b/app/src/main/res/drawable/fa_smile.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_snowflake.xml b/app/src/main/res/drawable/fa_snowflake.xml new file mode 100644 index 000000000..b6c51a6e9 --- /dev/null +++ b/app/src/main/res/drawable/fa_snowflake.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_socks.xml b/app/src/main/res/drawable/fa_socks.xml new file mode 100644 index 000000000..1768e9cac --- /dev/null +++ b/app/src/main/res/drawable/fa_socks.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_spider.xml b/app/src/main/res/drawable/fa_spider.xml new file mode 100644 index 000000000..ae82070ae --- /dev/null +++ b/app/src/main/res/drawable/fa_spider.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_suitcase_medical.xml b/app/src/main/res/drawable/fa_suitcase_medical.xml new file mode 100644 index 000000000..697ebf040 --- /dev/null +++ b/app/src/main/res/drawable/fa_suitcase_medical.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_sun.xml b/app/src/main/res/drawable/fa_sun.xml new file mode 100644 index 000000000..5e051a84e --- /dev/null +++ b/app/src/main/res/drawable/fa_sun.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_temperature_three_quarters.xml b/app/src/main/res/drawable/fa_temperature_three_quarters.xml new file mode 100644 index 000000000..e5abcbc54 --- /dev/null +++ b/app/src/main/res/drawable/fa_temperature_three_quarters.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_tractor.xml b/app/src/main/res/drawable/fa_tractor.xml new file mode 100644 index 000000000..46737d840 --- /dev/null +++ b/app/src/main/res/drawable/fa_tractor.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_tree.xml b/app/src/main/res/drawable/fa_tree.xml new file mode 100644 index 000000000..e466e8fc8 --- /dev/null +++ b/app/src/main/res/drawable/fa_tree.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_trophy.xml b/app/src/main/res/drawable/fa_trophy.xml new file mode 100644 index 000000000..29ca3332a --- /dev/null +++ b/app/src/main/res/drawable/fa_trophy.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_umbrella.xml b/app/src/main/res/drawable/fa_umbrella.xml new file mode 100644 index 000000000..48e9420fa --- /dev/null +++ b/app/src/main/res/drawable/fa_umbrella.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_user_astronaut.xml b/app/src/main/res/drawable/fa_user_astronaut.xml new file mode 100644 index 000000000..e39692128 --- /dev/null +++ b/app/src/main/res/drawable/fa_user_astronaut.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_utensils.xml b/app/src/main/res/drawable/fa_utensils.xml new file mode 100644 index 000000000..1bf4c8bec --- /dev/null +++ b/app/src/main/res/drawable/fa_utensils.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_volcano.xml b/app/src/main/res/drawable/fa_volcano.xml new file mode 100644 index 000000000..5ebebe8b7 --- /dev/null +++ b/app/src/main/res/drawable/fa_volcano.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/fa_wine_glass.xml b/app/src/main/res/drawable/fa_wine_glass.xml new file mode 100644 index 000000000..9d19cd03d --- /dev/null +++ b/app/src/main/res/drawable/fa_wine_glass.xml @@ -0,0 +1,9 @@ + + + From bd68a9186665e11107bd39da965cea003636df68 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Tue, 13 Feb 2024 15:13:10 +0100 Subject: [PATCH 2/3] Feat: Update `OverviewActivity.java` interface with missing functions (#653) Fixes # ## Proposed Changes - Adds uninstall button - Adds setting for auto-update - Updates preferences to properly save autorun settings --- .../ooniprobe/activity/OverviewActivity.java | 32 ++++++++++++- .../adddescriptor/AddDescriptorActivity.kt | 2 +- .../adddescriptor/AddDescriptorViewModel.kt | 11 ++--- .../activity/overview/OverviewViewModel.kt | 20 ++++++++- .../ooniprobe/common/OONIDescriptor.kt | 5 ++- .../ooniprobe/common/TestDescriptorManager.kt | 36 ++++++++++++++- .../model/database/TestDescriptor.kt | 6 ++- app/src/main/res/layout/activity_overview.xml | 45 +++++++++++++++++-- 8 files changed, 139 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java b/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java index 19092a60f..33dbe6c93 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java @@ -28,8 +28,11 @@ import org.openobservatory.ooniprobe.common.PreferenceManager; import org.openobservatory.ooniprobe.common.ReadMorePlugin; import org.openobservatory.ooniprobe.databinding.ActivityOverviewBinding; +import org.openobservatory.ooniprobe.model.database.InstalledDescriptor; import org.openobservatory.ooniprobe.model.database.Result; +import org.openobservatory.ooniprobe.model.database.TestDescriptor; +import java.text.SimpleDateFormat; import java.util.Locale; import javax.inject.Inject; @@ -76,7 +79,20 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { binding.desc.setTextDirection(View.TEXT_DIRECTION_RTL); } } else { - markwon.setMarkdown(binding.desc, descriptor.getDescription()); + if (descriptor instanceof InstalledDescriptor) { + TestDescriptor testDescriptor = ((InstalledDescriptor) descriptor).getTestDescriptor(); + markwon.setMarkdown( + binding.desc, + String.format( + "Created by %s on %s\n\n%s", + testDescriptor.getAuthor(), + new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH).format(testDescriptor.getDescriptorCreationTime()), + descriptor.getDescription() + ) + ); + } else { + markwon.setMarkdown(binding.desc, descriptor.getDescription()); + } } Result lastResult = Result.getLastResult(descriptor.getName()); if (lastResult == null) { @@ -119,6 +135,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { binding.expandableListView.expandGroup(i); } + if (descriptor instanceof InstalledDescriptor) { + binding.uninstallLink.setVisibility(View.VISIBLE); + binding.automaticUpdatesContainer.setVisibility(View.VISIBLE); + binding.automaticUpdatesSwitch.setChecked(((InstalledDescriptor) descriptor).getTestDescriptor().isAutoUpdate()); + } else { + binding.uninstallLink.setVisibility(View.GONE); + /** + * We need to set the height to 0 because the layout is broken when the view is gone + */ + binding.automaticUpdatesContainer.getLayoutParams().height = 0; + } + setUpOnCLickListeners(); } @@ -149,6 +177,8 @@ public void setThemeColor(int color) { private void setUpOnCLickListeners() { binding.customUrl.setOnClickListener(view -> customUrlClick()); + binding.uninstallLink.setOnClickListener(view -> viewModel.uninstallLinkClicked(this, (InstalledDescriptor) descriptor)); + binding.automaticUpdatesSwitch.setOnCheckedChangeListener((compoundButton, isChecked) -> viewModel.automaticUpdatesSwitchClicked(isChecked)); } @Override diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt index 8d8a7d4f8..fd313b7c0 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt @@ -149,7 +149,7 @@ class AddDescriptorActivity : AbstractActivity() { when (item.itemId) { R.id.add_descriptor -> { viewModel.onAddButtonClicked( - selectedNettest = adapter.nettests.filter { it.selected }, + disabledAutorunNettests = adapter.nettests.filter { it.selected }, automatedUpdates = binding.automaticUpdatesSwitch.isChecked ) true diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorViewModel.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorViewModel.kt index a5a3e03cc..90d25ec08 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorViewModel.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorViewModel.kt @@ -85,21 +85,16 @@ class AddDescriptorViewModel constructor( /** * This method is called when the "Add Link" button is clicked. * It adds the descriptor to the descriptor manager and signals that the activity should finish. - * @param selectedNettest is the list of selected nettests. + * @param disabledAutorunNettests is the list of disabled nettests for autorun. * @param automatedUpdates is a boolean indicating whether automated updates should be enabled. */ - fun onAddButtonClicked(selectedNettest: List, automatedUpdates: Boolean) { + fun onAddButtonClicked(disabledAutorunNettests: List, automatedUpdates: Boolean) { descriptor.value?.let { descriptor -> descriptorManager.addDescriptor( descriptor = descriptor.apply { isAutoUpdate = automatedUpdates - nettests = selectedNettest.filter { it.selected }.map { nettest -> - OONIRunNettest( - name = nettest.name, - inputs = nettest.inputs - ) - } }, + disabledAutorunNettests = disabledAutorunNettests ).also { finishActivity() } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewViewModel.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewViewModel.kt index cfa010fed..63ad8333c 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewViewModel.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewViewModel.kt @@ -3,11 +3,15 @@ package org.openobservatory.ooniprobe.activity.overview import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import org.openobservatory.engine.BaseNettest +import org.openobservatory.ooniprobe.activity.AbstractActivity +import org.openobservatory.ooniprobe.activity.OverviewActivity import org.openobservatory.ooniprobe.activity.runtests.RunTestsViewModel import org.openobservatory.ooniprobe.common.AbstractDescriptor import org.openobservatory.ooniprobe.common.PreferenceManager +import org.openobservatory.ooniprobe.common.TestDescriptorManager import org.openobservatory.ooniprobe.common.disableTest import org.openobservatory.ooniprobe.common.enableTest +import org.openobservatory.ooniprobe.model.database.InstalledDescriptor import javax.inject.Inject class TestGroupItem( @@ -18,10 +22,12 @@ class TestGroupItem( class OverviewViewModel() : ViewModel() { var descriptor: MutableLiveData> = MutableLiveData() lateinit var preferenceManager: PreferenceManager + lateinit var descriptorManager: TestDescriptorManager @Inject - constructor(preferenceManager: PreferenceManager) : this() { + constructor(preferenceManager: PreferenceManager, descriptorManager: TestDescriptorManager) : this() { this.preferenceManager = preferenceManager + this.descriptorManager = descriptorManager } @@ -73,6 +79,18 @@ class OverviewViewModel() : ViewModel() { this.descriptor.postValue(descriptor) } + fun uninstallLinkClicked(activity: AbstractActivity, descriptor: InstalledDescriptor) { + descriptorManager.delete(descriptor) + activity.finish() + } + + fun automaticUpdatesSwitchClicked(isChecked: Boolean) { + descriptor.value?.let { + it.descriptor?.isAutoUpdate = isChecked + it.descriptor?.save() + } + } + companion object { const val SELECT_ALL = "SELECT_ALL" const val SELECT_SOME = "SELECT_SOME" diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt index 6f66dc0bc..95e0f53ae 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt @@ -165,7 +165,10 @@ abstract class AbstractDescriptor( * @return String representing the preference prefix. */ fun preferencePrefix(): String { - return OONITests.values().find { it.label == name }?.let { "" } ?: "descriptor_id_" + return when (descriptor?.runId != null) { + true -> descriptor?.preferencePrefix() ?: "" + else -> "" + } } /** diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/TestDescriptorManager.kt b/app/src/main/java/org/openobservatory/ooniprobe/common/TestDescriptorManager.kt index 68ab895c7..d0e301ec8 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/TestDescriptorManager.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/TestDescriptorManager.kt @@ -6,6 +6,10 @@ import org.openobservatory.engine.BaseNettest import org.openobservatory.engine.LoggerArray import org.openobservatory.engine.OONIRunFetchResponse import org.openobservatory.ooniprobe.BuildConfig +import org.openobservatory.ooniprobe.activity.adddescriptor.adapter.GroupedItem +import org.openobservatory.ooniprobe.model.database.InstalledDescriptor +import org.openobservatory.ooniprobe.model.database.Result +import org.openobservatory.ooniprobe.model.database.Result_Table import org.openobservatory.ooniprobe.model.database.TestDescriptor import org.openobservatory.ooniprobe.model.database.TestDescriptor_Table import org.openobservatory.ooniprobe.model.database.Url @@ -20,7 +24,10 @@ import javax.inject.Singleton * This class is responsible for managing the test descriptors */ @Singleton -class TestDescriptorManager @Inject constructor(private val context: Context) { +class TestDescriptorManager @Inject constructor( + private val context: Context, + private val preferenceManager: PreferenceManager +) { private val descriptors: List> = ooniDescriptors(context) fun getDescriptors(): List> { @@ -72,12 +79,24 @@ class TestDescriptorManager @Inject constructor(private val context: Context) { ) } - fun addDescriptor(descriptor: TestDescriptor): Boolean { + fun addDescriptor( + descriptor: TestDescriptor, + disabledAutorunNettests: List + ): Boolean { descriptor.getNettests() .filter { it.name == WebConnectivity.NAME } .forEach { it.inputs?.forEach { url -> Url.checkExistingUrl(url) } } + descriptor.getNettests().map { it.name } + .filter { item -> disabledAutorunNettests.map { it.name }.contains(item) } + .forEach { item -> + preferenceManager.enableTest( + name = item, + prefix = descriptor.preferencePrefix(), + autoRun = true + ) + } return descriptor.save() } @@ -85,4 +104,17 @@ class TestDescriptorManager @Inject constructor(private val context: Context) { return SQLite.select().from(TestDescriptor::class.java) .where(TestDescriptor_Table.isArchived.eq(false)).queryList() } + + fun delete(descriptor: InstalledDescriptor): Boolean { + preferenceManager.sp.all.entries.forEach {entry -> + if (entry.key.contains(descriptor.testDescriptor.runId.toString())) { + preferenceManager.sp.edit().remove(entry.key).apply() + } + } + return SQLite.select().from(Result::class.java) + .where(Result_Table.descriptor_runId.eq(descriptor.testDescriptor.runId)) + .queryList().forEach { it.delete(context) }.run { + descriptor.testDescriptor.delete() + } + } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.kt b/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.kt index 5dd766480..8e66dbefa 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.kt @@ -59,7 +59,11 @@ class TestDescriptor( var translationCreationTime: Date? = null, @Column(typeConverter = NettestConverter::class) var nettests: Any = emptyList() -) : BaseModel(), Serializable +) : BaseModel(), Serializable { + fun preferencePrefix(): String { + return "${runId}_" + } +} private const val DESCRIPTOR_TEST_NAME = "ooni_run" class InstalledDescriptor( diff --git a/app/src/main/res/layout/activity_overview.xml b/app/src/main/res/layout/activity_overview.xml index 226f9a5bc..4efea4b0a 100644 --- a/app/src/main/res/layout/activity_overview.xml +++ b/app/src/main/res/layout/activity_overview.xml @@ -132,12 +132,34 @@ android:layout_height="wrap_content" android:paddingVertical="32dp" /> + + + + + + + + - +