mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
The app can now pull weather from an api for a specific url. No location functionality yet.
This commit is contained in:
parent
eb91eb8a9d
commit
17cf58846d
3 changed files with 30 additions and 1 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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¤t=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")
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue