From a5a65fc1eea5a573079ead629624b66bad07e307 Mon Sep 17 00:00:00 2001 From: Ritika Pahwa <83745993+RitikaPahwa4444@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:57:52 +0530 Subject: [PATCH] 5191: Fix UI elements not conforming to dark mode (#5193) * feedback dialog: fix black font in dark mode * LocationPickerActivity: fix light map in dark mode * Fix #5182 Switch From Mapbox to MapLibre (#5184) * Fix #5182 Switch From Mapbox to MapLibre * Fix #5182 Switch From Mapbox to MapLibre - Resolved requestFeature() issue * Fix #5182 Switch From Mapbox to MapLibre - Resolved dark mode issue on two screens * Fix #5182 Switch From Mapbox to MapLibre - Resolved dark mode issue on additional screens * Fix #5182 Switch From Mapbox to MapLibre - Resolved dark mode issue on notification screen * Fix #5182 Switch From Mapbox to MapLibre - Test errors * fix issue #5015 - custom image selector not identifying photo location (#5190) Co-authored-by: Siva * feedback dialog: fix black font in dark mode * LocationPickerActivity: fix light map in dark mode * LocationPicker: use predefined style based on device theme * LocationPickerActivityTest: add additional target exception in catch block * LocationPickerConstants: remove extra newline introduced --------- Co-authored-by: Kartikay Kaushik <93285364+kartikaykaushik14@users.noreply.github.com> Co-authored-by: Siva Subramaniam <112970189+siva-subramaniam-v@users.noreply.github.com> Co-authored-by: Siva --- .../LocationPicker/LocationPickerActivity.java | 13 ++++++++++++- .../LocationPicker/LocationPickerConstants.java | 8 ++++++++ app/src/main/res/layout/dialog_feedback.xml | 4 ++-- .../LocationPickerActivityUnitTests.kt | 15 +++++++++------ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java index 8e3a928db..f4505d94d 100644 --- a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java @@ -57,6 +57,7 @@ import fr.free.nrw.commons.R; import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.kvstore.JsonKvStore; import fr.free.nrw.commons.theme.BaseActivity; +import fr.free.nrw.commons.utils.SystemThemeUtils; import javax.inject.Inject; import javax.inject.Named; import org.jetbrains.annotations.NotNull; @@ -139,12 +140,21 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa @Named("default_preferences") public JsonKvStore applicationKvStore; + /** + * isDarkTheme: for keeping a track of the device theme and modifying the map theme accordingly + */ + @Inject + SystemThemeUtils systemThemeUtils; + private boolean isDarkTheme; @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { getWindow().requestFeature(Window.FEATURE_ACTION_BAR); super.onCreate(savedInstanceState); + isDarkTheme = systemThemeUtils.isDeviceInNightMode(); + + getWindow().requestFeature(Window.FEATURE_ACTION_BAR); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.hide(); @@ -238,7 +248,8 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa @Override public void onMapReady(final MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - mapboxMap.setStyle(Style.getPredefinedStyle("Streets"), this::onStyleLoaded); + mapboxMap.setStyle(isDarkTheme ? LocationPickerConstants.DARK_MAP_STYLE : + LocationPickerConstants.STREETS_MAP_STYLE, this::onStyleLoaded); } /** diff --git a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerConstants.java b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerConstants.java index eb27e496c..a7ee98f94 100644 --- a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerConstants.java +++ b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerConstants.java @@ -1,5 +1,7 @@ package fr.free.nrw.commons.LocationPicker; +import com.mapbox.mapboxsdk.maps.Style; + /** * Constants need for location picking */ @@ -11,6 +13,12 @@ public final class LocationPickerConstants { public static final String MAP_CAMERA_POSITION = "location.picker.cameraPosition"; + public static final String DARK_MAP_STYLE + = Style.getPredefinedStyle("Dark"); + + public static final String STREETS_MAP_STYLE + = Style.getPredefinedStyle("Streets"); + private LocationPickerConstants() { } diff --git a/app/src/main/res/layout/dialog_feedback.xml b/app/src/main/res/layout/dialog_feedback.xml index 9acef11bd..9817da9eb 100644 --- a/app/src/main/res/layout/dialog_feedback.xml +++ b/app/src/main/res/layout/dialog_feedback.xml @@ -15,7 +15,7 @@ android:layout_margin="@dimen/dimen_6" android:padding="@dimen/tiny_gap" android:textSize="24sp" - android:textColor="@color/black" + android:textColor="?android:attr/textColorPrimary" android:text="@string/navigation_item_feedback" android:layout_width="wrap_content" android:layout_height="wrap_content" /> @@ -44,7 +44,7 @@ android:layout_margin="@dimen/dimen_6" android:padding="4dp" android:textSize="21sp" - android:textColor="@color/black" + android:textColor="?android:attr/textColorPrimary" android:text="@string/select_feedback_data_choice" android:layout_width="wrap_content" android:layout_height="wrap_content" /> diff --git a/app/src/test/kotlin/fr/free/nrw/commons/locationpicker/LocationPickerActivityUnitTests.kt b/app/src/test/kotlin/fr/free/nrw/commons/locationpicker/LocationPickerActivityUnitTests.kt index b700ef8b1..1b45102db 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/locationpicker/LocationPickerActivityUnitTests.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/locationpicker/LocationPickerActivityUnitTests.kt @@ -143,12 +143,15 @@ class LocationPickerActivityUnitTests { method.invoke(activity, mapboxMap) fail("Expected an exception to be thrown") } catch (e: InvocationTargetException) { - assertTrue(e.targetException is MapboxConfigurationException) - assertEquals( - "\nUsing MapView requires calling Mapbox.getInstance(Context context, String apiKey," - + " WellKnownTileServer wellKnownTileServer) before inflating or creating the view.", - e.targetException.message - ) + assertTrue((e.targetException is MapboxConfigurationException) || + (e.targetException is ExceptionInInitializerError)) + if (e.targetException is MapboxConfigurationException) { + assertEquals( + "\nUsing MapView requires calling Mapbox.getInstance(Context context, String apiKey," + + " WellKnownTileServer wellKnownTileServer) before inflating or creating the view.", + e.targetException.message + ) + } } }