Skip to content

Commit b3f1d06

Browse files
committed
update weather
1 parent af7ed5e commit b3f1d06

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

app/src/main/java/com/amazon/tv/leanbacklauncher/MainActivity.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import android.widget.TextView
3333
import androidx.appcompat.app.AppCompatActivity
3434
import androidx.appcompat.widget.AppCompatImageView
3535
import androidx.core.content.res.ResourcesCompat
36+
import androidx.core.text.isDigitsOnly
3637
import androidx.leanback.widget.BaseGridView
3738
import androidx.leanback.widget.OnChildViewHolderSelectedListener
3839
import androidx.leanback.widget.VerticalGridView
@@ -587,20 +588,38 @@ class MainActivity : AppCompatActivity(), OnEditModeChangedListener,
587588
lw.useCurrentLocation = true
588589
lw.updateCurrentLocation = true
589590
} else {
591+
lw.useCurrentLocation = false
590592
RowPreferences.getUserLocation(this)?.let { loc ->
591593
if (loc.isNotEmpty())
592-
lw.fetchCurrentWeatherByCityName(loc)
594+
if (loc.isDigitsOnly()) { // assume city id, ex. 524901
595+
if (BuildConfig.DEBUG) Log.d(TAG, "fetchCurrentWeatherByCityId($loc)")
596+
lw.fetchCurrentWeatherByCityId(loc)
597+
} else if (loc.split(", ").size == 2 &&
598+
loc.split(", ").first().toDoubleOrNull() != null &&
599+
loc.split(", ").last().toDoubleOrNull() != null
600+
) { // assume coordinates, ex. 45.75 47.61
601+
val lat = loc.split(", ").first().toDouble()
602+
val lon = loc.split(", ").last().toDouble()
603+
if (BuildConfig.DEBUG) Log.d(TAG, "fetchCurrentWeatherByLocation($lat,$lon)")
604+
lw.fetchCurrentWeatherByLocation(lat, lon)
605+
} else {
606+
if (BuildConfig.DEBUG) Log.d(TAG, "fetchCurrentWeatherByCityName($loc)")
607+
lw.fetchCurrentWeatherByCityName(loc)
608+
}
609+
else
610+
LauncherApplication.Toast(R.string.user_location_warning, true)
593611
}
594612
}
595613

596614
lw.weatherCallback = object : LocalWeather.WeatherCallback {
597615
override fun onSuccess(weather: Weather) {
598-
if (BuildConfig.DEBUG) Log.d(TAG, "LocalWeather onSuccess()")
616+
if (BuildConfig.DEBUG) Log.d(TAG, "LocalWeather onSuccess() -> updateWeatherDetails")
599617
updateWeatherDetails(weather)
600618
}
601619

602620
override fun onFailure(exception: Throwable?) {
603621
Log.e(TAG, "Weather fetching exception ${exception!!.message!!}")
622+
LauncherApplication.Toast("Weather error: ${exception!!.message!!}", true)
604623
}
605624
}
606625

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
android:fontFamily="@string/light_font"
7878
android:gravity="center"
7979
android:textColor="@color/clock_text_color"
80-
android:textSize="18sp"
80+
android:textSize="16sp"
8181
android:visibility="gone" />
8282

8383
</LinearLayout>

app/src/main/res/values-ru/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ com.amazon.device.sale.service
214214
<string name="use_current_location_title">Текущее местоположение</string>
215215
<string name="use_current_location_description">Использовать местоположение из ОС (требуется разрешение на местоположение и сервисы Google)</string>
216216
<string name="user_location_title">Местоположение пользователя</string>
217+
<string name="user_location_warning">Местоположение для погоды не задано в настройках</string>
217218
<string name="v7_preference_off">ВЫКЛ</string>
218219
<string name="v7_preference_on">ВКЛ</string>
219220
<string name="videos_row_title">Раздел «Видео»</string>
220221
<string name="wallpaper_title">Фон по умолчанию</string>
221222
<string name="wallpaper_choose">Поместите изображение фона в корневой каталог хранилища и выберите здесь</string>
222223
<string name="weather_home_title">Настройки погоды</string>
223224
<string name="weather_home_description">Местная погода и прогноз на главной странице</string>
224-
</resources>
225+
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ or recommendations will not work properly."</string>
263263
<string name="use_current_location_title">Use current location</string>
264264
<string name="use_current_location_description">Autodetect location by OS (Google services and location permission required)</string>
265265
<string name="user_location_title">User location</string>
266+
<string name="user_location_warning">User location for weather not set in preferences</string>
266267
<string name="error_app_not_found">No suitable applications found</string>
267268
<string name="v7_preference_off">OFF</string>
268269
<string name="v7_preference_on">ON</string>

0 commit comments

Comments
 (0)