The app can now pull weather from an api for a specific url. No location functionality yet.

This commit is contained in:
ottoptj 2024-06-04 03:12:09 +03:00
commit 17cf58846d
3 changed files with 30 additions and 1 deletions

View file

@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>

View file

@ -60,6 +60,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
private val appMenuLinearLayoutManager = AppMenuLinearLayoutManager(this@MainActivity)
private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity)
private val animations = Animations()
private val weatherSystem = WeatherSystem()
private val swipeThreshold = 100
private val swipeVelocityThreshold = 100
@ -149,7 +150,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
val statusBarManager: Class<*> = Class.forName("android.app.StatusBarManager")
val expandMethod: Method = statusBarManager.getMethod("expandNotificationsPanel")
expandMethod.invoke(statusBarService)
weatherSystem.getWeather()
}
// Detect swipe left

View file

@ -1,4 +1,31 @@
package eu.ottop.yamlauncher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URL
class WeatherSystem {
fun getWeather() {
CoroutineScope(Dispatchers.IO).launch {
val url = URL("https://api.open-meteo.com/v1/forecast?latitude=60.16&longitude=24.93&current=temperature_2m")
with(url.openConnection() as HttpURLConnection) {
requestMethod = "GET"
inputStream.bufferedReader().use {
val response = it.readText()
// Parse the JSON response
val jsonObject = JSONObject(response)
// Access specific fields or nested objects
val currentData = jsonObject.getJSONObject("current")
val currentWeather = currentData.getInt("temperature_2m")
println("Field1: $currentWeather")
}
}}
}
}