mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Fixed startup crash when internet is off and weather enabled. Updated accessibility service settings location.
This commit is contained in:
parent
84c37734c9
commit
6282b83897
3 changed files with 53 additions and 39 deletions
|
|
@ -41,10 +41,10 @@ class WeatherSystem(private val context: Context) {
|
||||||
{ location: Location? ->
|
{ location: Location? ->
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val latitude = location.latitude
|
val latitude = location.latitude
|
||||||
val longitude = location.longitude
|
val longitude = location.longitude
|
||||||
sharedPreferenceManager.setWeatherLocation("latitude=${latitude}&longitude=${longitude}", "Latest GPS location")
|
sharedPreferenceManager.setWeatherLocation("latitude=${latitude}&longitude=${longitude}", "Latest GPS location")
|
||||||
activity.updateWeatherText()
|
activity.updateWeatherText()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -55,10 +55,10 @@ class WeatherSystem(private val context: Context) {
|
||||||
fun getSearchedLocations(searchTerm: String?) : MutableList<Map<String, String>> {
|
fun getSearchedLocations(searchTerm: String?) : MutableList<Map<String, String>> {
|
||||||
val foundLocations = mutableListOf<Map<String, String>>()
|
val foundLocations = mutableListOf<Map<String, String>>()
|
||||||
|
|
||||||
val url = URL("https://geocoding-api.open-meteo.com/v1/search?name=$searchTerm&count=50&language=en&format=json")
|
val url = URL("https://geocoding-api.open-meteo.com/v1/search?name=$searchTerm&count=50&language=en&format=json")
|
||||||
with(url.openConnection() as HttpURLConnection) {
|
with(url.openConnection() as HttpURLConnection) {
|
||||||
requestMethod = "GET"
|
requestMethod = "GET"
|
||||||
try {
|
try {
|
||||||
inputStream.bufferedReader().use {
|
inputStream.bufferedReader().use {
|
||||||
val response = it.readText()
|
val response = it.readText()
|
||||||
val jsonObject = JSONObject(response)
|
val jsonObject = JSONObject(response)
|
||||||
|
|
@ -85,50 +85,57 @@ class WeatherSystem(private val context: Context) {
|
||||||
// Run with Dispatchers.IO from the outside
|
// Run with Dispatchers.IO from the outside
|
||||||
fun getTemp() : String {
|
fun getTemp() : String {
|
||||||
|
|
||||||
val tempUnits = sharedPreferenceManager.getTempUnits()
|
val tempUnits = sharedPreferenceManager.getTempUnits()
|
||||||
var currentWeather = ""
|
var currentWeather = ""
|
||||||
|
|
||||||
val location = sharedPreferenceManager.getWeatherLocation()
|
val location = sharedPreferenceManager.getWeatherLocation()
|
||||||
|
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
if (location.isNotEmpty()) {
|
if (location.isNotEmpty()) {
|
||||||
val url = URL("https://api.open-meteo.com/v1/forecast?$location&temperature_unit=${tempUnits}¤t=temperature_2m,weather_code")
|
val url =
|
||||||
|
URL("https://api.open-meteo.com/v1/forecast?$location&temperature_unit=${tempUnits}¤t=temperature_2m,weather_code")
|
||||||
with(url.openConnection() as HttpURLConnection) {
|
with(url.openConnection() as HttpURLConnection) {
|
||||||
requestMethod = "GET"
|
requestMethod = "GET"
|
||||||
|
|
||||||
inputStream.bufferedReader().use {
|
try {
|
||||||
val response = it.readText()
|
inputStream.bufferedReader().use {
|
||||||
|
val response = it.readText()
|
||||||
|
|
||||||
val jsonObject = JSONObject(response)
|
val jsonObject = JSONObject(response)
|
||||||
|
|
||||||
val currentData = jsonObject.getJSONObject("current")
|
val currentData = jsonObject.getJSONObject("current")
|
||||||
|
|
||||||
var weatherType = ""
|
var weatherType = ""
|
||||||
|
|
||||||
|
when (currentData.getInt("weather_code")) {
|
||||||
|
0, 1 -> {
|
||||||
|
weatherType = "☀\uFE0E" // Sunny
|
||||||
|
}
|
||||||
|
|
||||||
|
2, 3, 45, 48 -> {
|
||||||
|
weatherType = "☁\uFE0E" // Sunny
|
||||||
|
}
|
||||||
|
|
||||||
|
51, 53, 55, 56, 57, 61, 63, 65, 67, 80, 81, 82 -> {
|
||||||
|
weatherType = "☂\uFE0E" // Rain
|
||||||
|
}
|
||||||
|
|
||||||
|
71, 73, 75, 77, 85, 86 -> {
|
||||||
|
weatherType = "❄\uFE0E" // Snow
|
||||||
|
}
|
||||||
|
|
||||||
|
95, 96, 99 -> {
|
||||||
|
weatherType = "⛈\uFE0E" // Thunder
|
||||||
|
}
|
||||||
|
|
||||||
when (currentData.getInt("weather_code")) {
|
|
||||||
0, 1 -> {
|
|
||||||
weatherType = "☀\uFE0E" // Sunny
|
|
||||||
}
|
|
||||||
2, 3, 45, 48 -> {
|
|
||||||
weatherType = "☁\uFE0E" // Sunny
|
|
||||||
}
|
|
||||||
51, 53, 55, 56, 57, 61, 63, 65, 67, 80, 81, 82 -> {
|
|
||||||
weatherType = "☂\uFE0E" // Rain
|
|
||||||
}
|
|
||||||
71, 73, 75, 77, 85, 86 -> {
|
|
||||||
weatherType = "❄\uFE0E" // Snow
|
|
||||||
}
|
|
||||||
95, 96, 99 -> {
|
|
||||||
weatherType = "⛈\uFE0E" // Thunder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentWeather = "$weatherType ${currentData.getInt("temperature_2m")}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
currentWeather = "$weatherType ${currentData.getInt("temperature_2m")}"
|
} catch(_: Exception) {}
|
||||||
|
}}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (tempUnits) {
|
return when (tempUnits) {
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,16 @@
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="SettingsTheme" parent="Base.Theme.YamLauncher">
|
<style name="SettingsTheme" parent="Theme.AppCompat.NoActionBar">
|
||||||
<item name="android:windowBackground">@color/settings_bg</item>
|
<item name="android:windowBackground">@color/settings_bg</item>
|
||||||
<item name="android:windowShowWallpaper">false</item>
|
<item name="android:windowShowWallpaper">false</item>
|
||||||
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
|
||||||
|
<item name="android:windowFullscreen">true</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
<item name="android:enforceNavigationBarContrast">false</item>
|
||||||
|
<item name="android:enforceStatusBarContrast">false</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
|
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@
|
||||||
android:accessibilityEventTypes="typeViewClicked"
|
android:accessibilityEventTypes="typeViewClicked"
|
||||||
android:accessibilityFeedbackType="feedbackGeneric"
|
android:accessibilityFeedbackType="feedbackGeneric"
|
||||||
android:notificationTimeout="100"
|
android:notificationTimeout="100"
|
||||||
android:settingsActivity="eu.ottop.yamlauncher.SettingsActivity"/>
|
android:settingsActivity="eu.ottop.yamlauncher.settings.SettingsActivity"/>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue