Skip to content

Commit

Permalink
Consider current context to check for night mode
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Chagas <[email protected]>
  • Loading branch information
rtchagas committed Mar 6, 2020
1 parent 84916e7 commit 3b0e1b3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PingPlacePicker private constructor() {
* Set whether the library should return the place coordinate retrieved from GooglePlace or the actual selected location from google map
*/
fun setShouldReturnActualLatLng(shouldReturnActualLatLng: Boolean): IntentBuilder {
intent.putExtra(PlacePickerActivity.EXTRA_SHOULD_RETURN_ACTUAL_LATLNG, shouldReturnActualLatLng)
intent.putExtra(PlacePickerActivity.EXTRA_RETURN_ACTUAL_LATLNG, shouldReturnActualLatLng)
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class PlaceConfirmDialogFragment : AppCompatDialogFragment(), PingKoinComponent
PingPlacePicker.mapsApiKey
)

if (UiUtils.isNightModeEnabled()) {
if (UiUtils.isNightModeEnabled(requireContext())) {
mapUrl += Config.STATIC_MAP_URL_STYLE_DARK
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,

// For passing extra parameters to this activity.
const val EXTRA_LOCATION = "extra_location"
const val EXTRA_SHOULD_RETURN_ACTUAL_LATLNG = "extra_should_return_actual_latlng"
const val EXTRA_RETURN_ACTUAL_LATLNG = "extra_return_actual_latlng"

// Keys for storing activity state.
private const val STATE_CAMERA_POSITION = "state_camera_position"
Expand Down Expand Up @@ -204,7 +204,7 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
override fun onPlaceConfirmed(place: Place) {
val data = Intent()

if (intent.getBooleanExtra(EXTRA_SHOULD_RETURN_ACTUAL_LATLNG, false)){
if (intent.getBooleanExtra(EXTRA_RETURN_ACTUAL_LATLNG, false)){
data.putExtra(PingPlacePicker.EXTRA_ACTUAL_LATLNG, selectedLatLng)
}
else {
Expand Down Expand Up @@ -580,7 +580,7 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
*/
private fun setMapStyle() {

if (!UiUtils.isNightModeEnabled()) {
if (!UiUtils.isNightModeEnabled(this)) {
return
}

Expand Down
12 changes: 6 additions & 6 deletions library/src/main/java/com/rtchagas/pingplacepicker/ui/UiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.rtchagas.pingplacepicker.ui

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.util.TypedValue
import androidx.annotation.ColorInt
import com.google.android.libraries.places.api.model.Place
import com.rtchagas.pingplacepicker.R
import org.jetbrains.anko.configuration
import java.util.*


object UiUtils {
Expand All @@ -21,7 +22,7 @@ object UiUtils {

place.types?.let {
for (type: Place.Type in it) {
val name = type.name.toLowerCase()
val name = type.name.toLowerCase(Locale.ENGLISH)
val id: Int = context.resources
.getIdentifier("ic_places_$name", defType, defPackage)
if (id > 0) return id
Expand All @@ -35,12 +36,11 @@ object UiUtils {
/**
* Returns whether the current selected theme is night mode or not
*/
fun isNightModeEnabled(): Boolean {
fun isNightModeEnabled(context: Context): Boolean {

val currentNightMode =
(Resources.getSystem().configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK)
val nightMode = (context.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK)

return currentNightMode == Configuration.UI_MODE_NIGHT_YES
return nightMode == Configuration.UI_MODE_NIGHT_YES
}

@ColorInt
Expand Down

0 comments on commit 3b0e1b3

Please sign in to comment.