Skip to content

Commit a5a65fc

Browse files
RitikaPahwa4444kartikaykaushik14sivasubramaniamvSiva
authored
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 <doodsiva@gmail.com> * 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 <doodsiva@gmail.com>
1 parent 0f1e526 commit a5a65fc

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import fr.free.nrw.commons.Utils;
5858
import fr.free.nrw.commons.kvstore.JsonKvStore;
5959
import fr.free.nrw.commons.theme.BaseActivity;
60+
import fr.free.nrw.commons.utils.SystemThemeUtils;
6061
import javax.inject.Inject;
6162
import javax.inject.Named;
6263
import org.jetbrains.annotations.NotNull;
@@ -139,12 +140,21 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
139140
@Named("default_preferences")
140141
public
141142
JsonKvStore applicationKvStore;
143+
/**
144+
* isDarkTheme: for keeping a track of the device theme and modifying the map theme accordingly
145+
*/
146+
@Inject
147+
SystemThemeUtils systemThemeUtils;
148+
private boolean isDarkTheme;
142149

143150
@Override
144151
protected void onCreate(@Nullable final Bundle savedInstanceState) {
145152
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
146153
super.onCreate(savedInstanceState);
147154

155+
isDarkTheme = systemThemeUtils.isDeviceInNightMode();
156+
157+
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
148158
final ActionBar actionBar = getSupportActionBar();
149159
if (actionBar != null) {
150160
actionBar.hide();
@@ -238,7 +248,8 @@ private void getToolbarUI() {
238248
@Override
239249
public void onMapReady(final MapboxMap mapboxMap) {
240250
this.mapboxMap = mapboxMap;
241-
mapboxMap.setStyle(Style.getPredefinedStyle("Streets"), this::onStyleLoaded);
251+
mapboxMap.setStyle(isDarkTheme ? LocationPickerConstants.DARK_MAP_STYLE :
252+
LocationPickerConstants.STREETS_MAP_STYLE, this::onStyleLoaded);
242253
}
243254

244255
/**

app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerConstants.java

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.free.nrw.commons.LocationPicker;
22

3+
import com.mapbox.mapboxsdk.maps.Style;
4+
35
/**
46
* Constants need for location picking
57
*/
@@ -11,6 +13,12 @@ public final class LocationPickerConstants {
1113
public static final String MAP_CAMERA_POSITION
1214
= "location.picker.cameraPosition";
1315

16+
public static final String DARK_MAP_STYLE
17+
= Style.getPredefinedStyle("Dark");
18+
19+
public static final String STREETS_MAP_STYLE
20+
= Style.getPredefinedStyle("Streets");
21+
1422

1523
private LocationPickerConstants() {
1624
}

app/src/main/res/layout/dialog_feedback.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
android:layout_margin="@dimen/dimen_6"
1616
android:padding="@dimen/tiny_gap"
1717
android:textSize="24sp"
18-
android:textColor="@color/black"
18+
android:textColor="?android:attr/textColorPrimary"
1919
android:text="@string/navigation_item_feedback"
2020
android:layout_width="wrap_content"
2121
android:layout_height="wrap_content" />
@@ -44,7 +44,7 @@
4444
android:layout_margin="@dimen/dimen_6"
4545
android:padding="4dp"
4646
android:textSize="21sp"
47-
android:textColor="@color/black"
47+
android:textColor="?android:attr/textColorPrimary"
4848
android:text="@string/select_feedback_data_choice"
4949
android:layout_width="wrap_content"
5050
android:layout_height="wrap_content" />

app/src/test/kotlin/fr/free/nrw/commons/locationpicker/LocationPickerActivityUnitTests.kt

+9-6
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,15 @@ class LocationPickerActivityUnitTests {
143143
method.invoke(activity, mapboxMap)
144144
fail("Expected an exception to be thrown")
145145
} catch (e: InvocationTargetException) {
146-
assertTrue(e.targetException is MapboxConfigurationException)
147-
assertEquals(
148-
"\nUsing MapView requires calling Mapbox.getInstance(Context context, String apiKey,"
149-
+ " WellKnownTileServer wellKnownTileServer) before inflating or creating the view.",
150-
e.targetException.message
151-
)
146+
assertTrue((e.targetException is MapboxConfigurationException) ||
147+
(e.targetException is ExceptionInInitializerError))
148+
if (e.targetException is MapboxConfigurationException) {
149+
assertEquals(
150+
"\nUsing MapView requires calling Mapbox.getInstance(Context context, String apiKey,"
151+
+ " WellKnownTileServer wellKnownTileServer) before inflating or creating the view.",
152+
e.targetException.message
153+
)
154+
}
152155
}
153156
}
154157

0 commit comments

Comments
 (0)