Skip to content

Commit

Permalink
WeatherWidgetPreferenceFragment: fix crash if entry is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
thewizrd committed Jun 18, 2021
1 parent 0f2d7c1 commit 5b7b6ac
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,9 @@ class WeatherWidgetPreferenceFragment : ToolbarPreferenceFragmentCompat() {
private fun updateLocationView() {
val locationView = binding.widgetContainer.findViewById<TextView>(R.id.location_name)
if (locationView != null) {
locationView.text = if (mLastSelectedValue != null) locationPref.findEntryFromValue(mLastSelectedValue) else this.getString(R.string.pref_location)
locationView.text =
mLastSelectedValue?.let { locationPref.findEntryFromValue(it)?.toString() }
?: this.getString(R.string.pref_location)
locationView.visibility = if (hideLocNamePref.isChecked) View.GONE else View.VISIBLE
}
}
Expand Down Expand Up @@ -1098,18 +1100,21 @@ class WeatherWidgetPreferenceFragment : ToolbarPreferenceFragmentCompat() {
private fun buildMockData() {
if (mockLocData == null) {
mockLocData = LocationData().apply {
name = locationPref.findEntryFromValue(mLastSelectedValue)?.toString()
?: getString(R.string.pref_location)
name = mLastSelectedValue?.let { locationPref.findEntryFromValue(it)?.toString() }
?: getString(R.string.pref_location)
query = locationPref.value
latitude = 0.toDouble()
longitude = 0.toDouble()
tzLong = "UTC"
locationType = if (locationPref.value == Constants.KEY_GPS) LocationType.GPS else LocationType.SEARCH
locationType =
if (locationPref.value == Constants.KEY_GPS) LocationType.GPS else LocationType.SEARCH
weatherSource = wm.getWeatherAPI()
locationSource = wm.getLocationProvider().getLocationAPI()
}
} else {
mockLocData?.name = if (mLastSelectedValue != null) locationPref.findEntryFromValue(mLastSelectedValue).toString() else getString(R.string.pref_location)
mockLocData?.name =
mLastSelectedValue?.let { locationPref.findEntryFromValue(it)?.toString() }
?: getString(R.string.pref_location)
mockLocData?.query = locationPref.value
}

Expand Down

0 comments on commit 5b7b6ac

Please sign in to comment.