@@ -114,8 +114,28 @@ fun MapStyle.uri(context: Context): String {
114114 }
115115}
116116
117+ fun SharedPreferences.mapStyleIsDark (): Boolean {
118+ return when (mapStyle) {
119+ MapStyle .Dark , MapStyle .CartoDarkMatter -> true
120+ MapStyle .Auto -> {
121+ false
122+ }
123+ else -> false
124+ }
125+ }
126+
117127fun SharedPreferences.markerBackgroundColor (context : Context ): Int {
118- return getInt(" markerBackgroundColor" , context.getPrimaryContainerColor())
128+ val customColor = getInt(" markerBackgroundColor" , - 1 )
129+ if (customColor != - 1 ) return customColor
130+
131+ if (useAdaptiveColors) {
132+ return context.getPrimaryContainerColor()
133+ }
134+
135+ val isDark = mapStyleIsDark() ||
136+ (context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK == Configuration .UI_MODE_NIGHT_YES )
137+
138+ return if (isDark) 0xFF0e95af .toInt() else 0xFF0e95af .toInt()
119139}
120140
121141fun SharedPreferences.setMarkerBackgroundColor (color : Int? ) {
@@ -151,7 +171,17 @@ fun SharedPreferences.setBoostedMarkerBackgroundColor(color: Int?) {
151171}
152172
153173fun SharedPreferences.markerIconColor (context : Context ): Int {
154- return getInt(" markerIconColor" , context.getOnPrimaryContainerColor())
174+ val customColor = getInt(" markerIconColor" , - 1 )
175+ if (customColor != - 1 ) return customColor
176+
177+ if (useAdaptiveColors) {
178+ return context.getOnPrimaryContainerColor()
179+ }
180+
181+ val isDark = mapStyleIsDark() ||
182+ (context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK == Configuration .UI_MODE_NIGHT_YES )
183+
184+ return if (isDark) 0xFFFFFFFF .toInt() else 0xFFFFFFFF .toInt() // White for both
155185}
156186
157187fun SharedPreferences.setMarkerIconColor (color : Int? ) {
@@ -168,7 +198,17 @@ fun SharedPreferences.setMarkerIconColor(color: Int?) {
168198}
169199
170200fun SharedPreferences.badgeBackgroundColor (context : Context ): Int {
171- return getInt(" badgeBackgroundColor" , context.getOnPrimaryContainerColor())
201+ val customColor = getInt(" badgeBackgroundColor" , - 1 )
202+ if (customColor != - 1 ) return customColor
203+
204+ if (useAdaptiveColors) {
205+ return context.getOnPrimaryContainerColor()
206+ }
207+
208+ val isDark = mapStyleIsDark() ||
209+ (context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK == Configuration .UI_MODE_NIGHT_YES )
210+
211+ return if (isDark) 0xFF00a63e .toInt() else 0xFF00a63e .toInt()
172212}
173213
174214fun SharedPreferences.setBadgeBackgroundColor (color : Int? ) {
@@ -185,7 +225,17 @@ fun SharedPreferences.setBadgeBackgroundColor(color: Int?) {
185225}
186226
187227fun SharedPreferences.badgeTextColor (context : Context ): Int {
188- return getInt(" badgeTextColor" , context.getPrimaryContainerColor())
228+ val customColor = getInt(" badgeTextColor" , - 1 )
229+ if (customColor != - 1 ) return customColor
230+
231+ if (useAdaptiveColors) {
232+ return context.getPrimaryContainerColor()
233+ }
234+
235+ val isDark = mapStyleIsDark() ||
236+ (context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK == Configuration .UI_MODE_NIGHT_YES )
237+
238+ return if (isDark) 0xFFFFFFFF .toInt() else 0xFFFFFFFF .toInt()
189239}
190240
191241fun SharedPreferences.setBadgeTextColor (color : Int? ) {
@@ -224,7 +274,17 @@ fun SharedPreferences.apiUrlV4(vararg pathSegments: String): HttpUrl {
224274private const val KEY_BUTTON_BACKGROUND_COLOR = " buttonBackgroundColor"
225275
226276fun SharedPreferences.buttonBackgroundColor (context : Context ): Int {
227- return getInt(KEY_BUTTON_BACKGROUND_COLOR , context.getTertiaryContainerColor())
277+ val customColor = getInt(KEY_BUTTON_BACKGROUND_COLOR , - 1 )
278+ if (customColor != - 1 ) return customColor
279+
280+ if (useAdaptiveColors) {
281+ return context.getTertiaryContainerColor()
282+ }
283+
284+ val isDark = mapStyleIsDark() ||
285+ (context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK == Configuration .UI_MODE_NIGHT_YES )
286+
287+ return if (isDark) 0xFF1f2937 .toInt() else 0xFF1f2937 .toInt()
228288}
229289
230290fun SharedPreferences.setButtonBackgroundColor (color : Int? ) {
@@ -243,7 +303,17 @@ fun SharedPreferences.setButtonBackgroundColor(color: Int?) {
243303private const val KEY_BUTTON_ICON_COLOR = " buttonIconColor"
244304
245305fun SharedPreferences.buttonIconColor (context : Context ): Int {
246- return getInt(KEY_BUTTON_ICON_COLOR , context.getOnTertiaryContainerColor())
306+ val customColor = getInt(KEY_BUTTON_ICON_COLOR , - 1 )
307+ if (customColor != - 1 ) return customColor
308+
309+ if (useAdaptiveColors) {
310+ return context.getOnTertiaryContainerColor()
311+ }
312+
313+ val isDark = mapStyleIsDark() ||
314+ (context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK == Configuration .UI_MODE_NIGHT_YES )
315+
316+ return if (isDark) 0xFFFFFFFF .toInt() else 0xFFFFFFFF .toInt()
247317}
248318
249319fun SharedPreferences.setButtonIconColor (color : Int? ) {
@@ -261,8 +331,24 @@ fun SharedPreferences.setButtonIconColor(color: Int?) {
261331
262332private const val KEY_BUTTON_BORDER_COLOR = " buttonBorderColor"
263333
334+ var SharedPreferences .useAdaptiveColors: Boolean
335+ get() = getBoolean(" useAdaptiveColors" , false )
336+ set(value) {
337+ edit { putBoolean(" useAdaptiveColors" , value) }
338+ }
339+
264340fun SharedPreferences.buttonBorderColor (context : Context ): Int {
265- return getInt(KEY_BUTTON_BORDER_COLOR , context.getOnTertiaryContainerColor())
341+ val customColor = getInt(KEY_BUTTON_BORDER_COLOR , - 1 )
342+ if (customColor != - 1 ) return customColor
343+
344+ if (useAdaptiveColors) {
345+ return context.getOnTertiaryContainerColor()
346+ }
347+
348+ val isDark = mapStyleIsDark() ||
349+ (context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK == Configuration .UI_MODE_NIGHT_YES )
350+
351+ return if (isDark) 0xFFFFFFFF .toInt() else 0xFFFFFFFF .toInt()
266352}
267353
268354fun SharedPreferences.setButtonBorderColor (color : Int? ) {
@@ -276,4 +362,4 @@ fun SharedPreferences.setButtonBorderColor(color: Int?) {
276362 )
277363 }
278364 }
279- }
365+ }
0 commit comments