Compare commits

..

No commits in common. "798c6ce27f5d364cb20c6918510f0a8a18ac7fcc" and "b31ab340ab83169ef0bdf5036f2b3b57fa130d38" have entirely different histories.

3 changed files with 19 additions and 106 deletions

View File

@ -92,9 +92,6 @@ 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")
} }

View File

@ -1,38 +0,0 @@
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
}

View File

@ -7,19 +7,7 @@ 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 {
@ -36,15 +24,9 @@ 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()
} }
@ -52,52 +34,24 @@ class OpenWeatherGetter : BaseGetter {
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
fun getLocation() { fun getLocation() {
val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this.applicationContext) val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this.applicationContext)
fusedLocationProviderClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY,CancellationTokenSource().token) // if (ActivityCompat.checkSelfPermission(
.addOnSuccessListener{ success: Location? -> // this.applicationContext,
success?.let { // Manifest.permission.ACCESS_FINE_LOCATION
BLog.LOGE("Location >>> $it") // ) == PackageManager.PERMISSION_GRANTED &&
BLog.LOGE("Location altitude >>> ${it.altitude}") // ActivityCompat.checkSelfPermission(
BLog.LOGE("Location latitude >>> ${it.latitude}") // this.applicationContext,
// Manifest.permission.ACCESS_COARSE_LOCATION
// ) == PackageManager.PERMISSION_GRANTED
// ) {
fusedLocationProviderClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY,CancellationTokenSource().token)
.addOnSuccessListener{ success: Location? ->
success?.let {
BLog.LOGE("Location >>> $it")
}
}.addOnFailureListener{
BLog.LOGE("Location error >>> $it")
} }
}.addOnFailureListener{ return
BLog.LOGE("Location error >>> $it") // }
}
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?>?
}