diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 69f1afb..0d4476f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -92,6 +92,9 @@ dependencies { 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-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("io.github.vaneproject:hanguleditor:1.0.0") } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/model/WeatherInfo.kt b/app/src/main/kotlin/rasel/lunar/launcher/model/WeatherInfo.kt new file mode 100644 index 0000000..fe3de05 --- /dev/null +++ b/app/src/main/kotlin/rasel/lunar/launcher/model/WeatherInfo.kt @@ -0,0 +1,38 @@ +package rasel.lunar.launcher.model + +import android.app.appsearch.StorageInfo +import com.google.gson.annotations.SerializedName + +class WeatherInfo { + @SerializedName("coord") + private var coord: Location? = null + + @SerializedName("weather") + private var weather: Weather? = null + + @SerializedName("main") + private 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 +} \ No newline at end of file diff --git a/app/src/main/kotlin/rasel/lunar/launcher/workers/OpenWeatherGetter.kt b/app/src/main/kotlin/rasel/lunar/launcher/workers/OpenWeatherGetter.kt index 2b57091..2363bf4 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/OpenWeatherGetter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/OpenWeatherGetter.kt @@ -7,7 +7,16 @@ import androidx.work.WorkerParameters import com.google.android.gms.location.LocationServices import com.google.android.gms.location.Priority import com.google.android.gms.tasks.CancellationTokenSource +import rasel.lunar.launcher.model.WeatherInfo 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 retrofit2.http.Path class OpenWeatherGetter : BaseGetter { companion object { @@ -24,6 +33,7 @@ class OpenWeatherGetter : BaseGetter { //87cd0810b7e4b4debd31a6ef98b98154 //{https://home.openweathermap.org/api 에서 정보를 조회 하자} + getWeather() // 정형화된 정보를 취드하여 realm db에 저장 하자 @@ -34,24 +44,47 @@ class OpenWeatherGetter : BaseGetter { @SuppressLint("MissingPermission") fun getLocation() { 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) - .addOnSuccessListener{ success: Location? -> - success?.let { - BLog.LOGE("Location >>> $it") - } - }.addOnFailureListener{ - BLog.LOGE("Location error >>> $it") + fusedLocationProviderClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY,CancellationTokenSource().token) + .addOnSuccessListener{ success: Location? -> + success?.let { + BLog.LOGE("Location >>> $it") + BLog.LOGE("Location altitude >>> ${it.altitude}") + BLog.LOGE("Location latitude >>> ${it.latitude}") } - return -// } + }.addOnFailureListener{ + BLog.LOGE("Location error >>> $it") + } + return } -} \ No newline at end of file + + fun getWeather() { + val retro = Retrofit.Builder() + .baseUrl("https://api.openweathermap.org") + .addConverterFactory(GsonConverterFactory.create()) + .build() + + val service = retro.create() + + val call = service.getPosts("lat=44.34&lon=10.99&appid=87cd0810b7e4b4debd31a6ef98b98154") + + call!!.enqueue(object: Callback() { + override fun onResponse( + call: Call, + response: Response + ) { + BLog.LOGE("Location >>> ") + } + + override fun onFailure(call: Call, t: Throwable) { + BLog.LOGE("Location >>> ") + } + + }) + } +} + +interface RestrofitService { + @GET("/data/2.5/weather?{post}}") + fun getPosts(@Path("post") post: String?): Call? +} +