Compare commits
4 Commits
b31ab340ab
...
798c6ce27f
| Author | SHA1 | Date | |
|---|---|---|---|
| 798c6ce27f | |||
| f3111e84f9 | |||
| b298c6d86f | |||
| 809b2b4279 |
@ -92,6 +92,9 @@ dependencies {
|
|||||||
implementation("com.squareup.okhttp:okhttp:2.7.5")
|
implementation("com.squareup.okhttp:okhttp:2.7.5")
|
||||||
implementation("com.google.android.gms:play-services-location:21.0.1")
|
implementation("com.google.android.gms:play-services-location:21.0.1")
|
||||||
implementation("com.google.android.gms:play-services-tasks:18.2.0")
|
implementation("com.google.android.gms:play-services-tasks:18.2.0")
|
||||||
|
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
||||||
|
implementation("com.squareup.retrofit2:converter-gson:2.6.4")
|
||||||
|
implementation("com.squareup.retrofit2:converter-scalars:2.6.4")
|
||||||
// implementation ("androidx.window:window:1.0.0")
|
// implementation ("androidx.window:window:1.0.0")
|
||||||
// implementation("io.github.vaneproject:hanguleditor:1.0.0")
|
// implementation("io.github.vaneproject:hanguleditor:1.0.0")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,38 @@
|
|||||||
|
package rasel.lunar.launcher.model
|
||||||
|
|
||||||
|
import android.app.appsearch.StorageInfo
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class WeatherInfo (
|
||||||
|
@SerializedName("coord")
|
||||||
|
var coord: Location? = null,
|
||||||
|
|
||||||
|
@SerializedName("weather")
|
||||||
|
var weather: Array<Weather>? = null,
|
||||||
|
|
||||||
|
@SerializedName("main")
|
||||||
|
var main: Main? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
class Location {
|
||||||
|
var lon: String? = null
|
||||||
|
var lat: String? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
class Weather {
|
||||||
|
var id: String? = null
|
||||||
|
var main: String? = null
|
||||||
|
var description: String? = null
|
||||||
|
var icon: String? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
class Main {
|
||||||
|
var temp: String? = null
|
||||||
|
var feels_like: String? = null
|
||||||
|
var temp_min: String? = null
|
||||||
|
var temp_max: String? = null
|
||||||
|
var pressure: String? = null
|
||||||
|
var humidity: String? = null
|
||||||
|
var sea_level: String? = null
|
||||||
|
var grnd_level: String? = null
|
||||||
|
}
|
||||||
@ -7,7 +7,19 @@ import androidx.work.WorkerParameters
|
|||||||
import com.google.android.gms.location.LocationServices
|
import com.google.android.gms.location.LocationServices
|
||||||
import com.google.android.gms.location.Priority
|
import com.google.android.gms.location.Priority
|
||||||
import com.google.android.gms.tasks.CancellationTokenSource
|
import com.google.android.gms.tasks.CancellationTokenSource
|
||||||
|
import io.realm.kotlin.Realm
|
||||||
|
import io.realm.kotlin.RealmConfiguration
|
||||||
|
import io.realm.kotlin.types.TypedRealmObject
|
||||||
|
import rasel.lunar.launcher.model.WeatherInfo
|
||||||
import rasel.lunar.launcher.utils.BLog
|
import rasel.lunar.launcher.utils.BLog
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.Callback
|
||||||
|
import retrofit2.Response
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
import retrofit2.create
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
class OpenWeatherGetter : BaseGetter {
|
class OpenWeatherGetter : BaseGetter {
|
||||||
companion object {
|
companion object {
|
||||||
@ -24,9 +36,15 @@ class OpenWeatherGetter : BaseGetter {
|
|||||||
|
|
||||||
//87cd0810b7e4b4debd31a6ef98b98154
|
//87cd0810b7e4b4debd31a6ef98b98154
|
||||||
//{https://home.openweathermap.org/api 에서 정보를 조회 하자}
|
//{https://home.openweathermap.org/api 에서 정보를 조회 하자}
|
||||||
|
getWeather()
|
||||||
|
|
||||||
// 정형화된 정보를 취드하여 realm db에 저장 하자
|
// 정형화된 정보를 취드하여 realm db에 저장 하자
|
||||||
|
val config = RealmConfiguration.create(
|
||||||
|
schema = setOf(OpenWeatherGetter::class) as Set<KClass<out TypedRealmObject>>
|
||||||
|
)
|
||||||
|
val realm = Realm.open(config)
|
||||||
|
|
||||||
|
realm.close()
|
||||||
|
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
@ -34,24 +52,52 @@ class OpenWeatherGetter : BaseGetter {
|
|||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun getLocation() {
|
fun getLocation() {
|
||||||
val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this.applicationContext)
|
val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this.applicationContext)
|
||||||
// if (ActivityCompat.checkSelfPermission(
|
|
||||||
// this.applicationContext,
|
|
||||||
// Manifest.permission.ACCESS_FINE_LOCATION
|
|
||||||
// ) == PackageManager.PERMISSION_GRANTED &&
|
|
||||||
// ActivityCompat.checkSelfPermission(
|
|
||||||
// this.applicationContext,
|
|
||||||
// Manifest.permission.ACCESS_COARSE_LOCATION
|
|
||||||
// ) == PackageManager.PERMISSION_GRANTED
|
|
||||||
// ) {
|
|
||||||
fusedLocationProviderClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY,CancellationTokenSource().token)
|
fusedLocationProviderClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY,CancellationTokenSource().token)
|
||||||
.addOnSuccessListener{ success: Location? ->
|
.addOnSuccessListener{ success: Location? ->
|
||||||
success?.let {
|
success?.let {
|
||||||
BLog.LOGE("Location >>> $it")
|
BLog.LOGE("Location >>> $it")
|
||||||
|
BLog.LOGE("Location altitude >>> ${it.altitude}")
|
||||||
|
BLog.LOGE("Location latitude >>> ${it.latitude}")
|
||||||
}
|
}
|
||||||
}.addOnFailureListener{
|
}.addOnFailureListener{
|
||||||
BLog.LOGE("Location error >>> $it")
|
BLog.LOGE("Location error >>> $it")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
fun getWeather() {
|
||||||
|
val retro = Retrofit.Builder()
|
||||||
|
.baseUrl("https://api.openweathermap.org")
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val service = retro.create<RestrofitService>()
|
||||||
|
|
||||||
|
val call = service.getPosts()
|
||||||
|
|
||||||
|
call?.enqueue(object: Callback<WeatherInfo?> {
|
||||||
|
override fun onResponse(call: Call<WeatherInfo?>, response: Response<WeatherInfo?>) {
|
||||||
|
BLog.LOGE("Location error >>> $response")
|
||||||
|
|
||||||
|
// 받아온 결과를 메모리에 올려놓고 처리할 클래스가 필요해
|
||||||
|
response.body()?.let {w->
|
||||||
|
BLog.LOGE("Location error >>> ${w.coord}}")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<WeatherInfo?>, t: Throwable) {
|
||||||
|
BLog.LOGE("Location error >>> $t")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface RestrofitService {
|
||||||
|
@GET("/data/2.5/weather?lat=44.34&lon=10.99&appid=87cd0810b7e4b4debd31a6ef98b98154")
|
||||||
|
fun getPosts(): Call<WeatherInfo?>?
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user