코루틴 부분 수정
This commit is contained in:
parent
0eaeb0cb30
commit
51d6a9b5b5
@ -69,6 +69,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.ConnectionPool
|
import okhttp3.ConnectionPool
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -298,83 +299,64 @@ internal class LauncherHome : Fragment() {
|
|||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
|
||||||
suspend fun qByl(){
|
|
||||||
val re = WorkersDb.getRealm().query<Hour>().query("lat == $0 AND lon == $1",
|
|
||||||
LocationGetter.latitude?.let { BigDecimal.valueOf(it).toDouble() },
|
|
||||||
LocationGetter.longitude?.let { BigDecimal.valueOf(it).toDouble() })
|
|
||||||
BLog.LOGE("re >>> ${re.description()}")
|
|
||||||
re.find().asFlow().collect { it ->
|
|
||||||
val li = it.list
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
mWeatherAdapter?.let{
|
|
||||||
it.update(
|
|
||||||
mutableListOf<Hour>().apply {
|
|
||||||
this.addAll(it.filter(li))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
it.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
|
||||||
private fun queryWeather() {
|
|
||||||
val re = WorkersDb.getRealm().query<Hour>()
|
|
||||||
BLog.LOGE("re >>> ${re.description()}")
|
|
||||||
re.find()
|
|
||||||
val weatherJob2 = CoroutineScope(Dispatchers.Default).launch {
|
|
||||||
re.asFlow().collect { changes ->
|
|
||||||
// BLog.LOGE("testtestetset ${LocationGetter.latitude}")
|
|
||||||
// Handler(Looper.getMainLooper()).post {
|
|
||||||
// BLog.LOGE("testtestetset2 ${changes.list.size}")
|
|
||||||
// }
|
|
||||||
qByl()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
weatherJob2.start()
|
|
||||||
|
|
||||||
// mWeatherResult = WorkersDb.getRealm().query<WeatherForcast>().find()
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
// val weatherJob = CoroutineScope(Dispatchers.Default).launch {
|
suspend fun queryWeatherWithLoc(){
|
||||||
// mWeatherResult?.asFlow()?.collect { changes ->
|
WorkersDb.getRealm()
|
||||||
// BLog.LOGE("saved weatherForcast >>> asFlow ${changes.list}")
|
.query<Hour>()
|
||||||
|
.query("lat == $0 AND lon == $1",
|
||||||
|
LocationGetter.latitude?.let { BigDecimal.valueOf(it).toDouble() },
|
||||||
|
LocationGetter.longitude?.let { BigDecimal.valueOf(it).toDouble() }
|
||||||
|
).also {
|
||||||
|
BLog.LOGE("re >>> ${it.description()}")
|
||||||
|
}.find().let {hours ->
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
mWeatherAdapter?.let {
|
||||||
|
it.update(
|
||||||
|
mutableListOf<Hour>().apply {
|
||||||
|
this.addAll(hours)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
it.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// .asFlow()
|
||||||
|
// .collect { changes ->
|
||||||
// if (changes.list.size > 0) {
|
// if (changes.list.size > 0) {
|
||||||
// changes.list.first().forecast?.forecastdayRealm?.let { li ->
|
// Handler(Looper.getMainLooper()).post {
|
||||||
// BLog.LOGE("LauncherHome Saved Forecastdays >>> ${li.size}")
|
// mWeatherAdapter?.let {
|
||||||
// Handler(Looper.getMainLooper()).post {
|
// it.update(
|
||||||
// mWeatherAdapter?.let{
|
// mutableListOf<Hour>().apply {
|
||||||
// it.update(
|
// this.addAll(it.filter(changes.list))
|
||||||
// mutableListOf<Hour>().apply {
|
// }
|
||||||
// li.forEach { i ->
|
// )
|
||||||
// if (i == li.first()) {
|
// it.notifyDataSetChanged()
|
||||||
// this.addAll(it
|
|
||||||
// .filter(
|
|
||||||
// i.hourRealm.also { hli ->
|
|
||||||
// BLog.LOGE("testtestetset ${LocationGetter.latitude}")
|
|
||||||
// BLog.LOGE("LauncherHome Saved hli size >>> ${hli.size}")
|
|
||||||
// BLog.LOGE("LauncherHome Saved hli size >>> ${hli.first().lat}")
|
|
||||||
// BLog.LOGE("LauncherHome Saved hli size >>> ${hli.first().lon}")
|
|
||||||
// }
|
|
||||||
// ).also { fli ->
|
|
||||||
// BLog.LOGE("LauncherHome Saved fli size >>> ${fli.size}")
|
|
||||||
//// BLog.LOGE("LauncherHome Saved hli size >>> ${fli.first().lat}")
|
|
||||||
//// BLog.LOGE("LauncherHome Saved hli size >>> ${fli.first().lon}")
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// } else {
|
|
||||||
// this.addAll(i.hourRealm)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// it.notifyDataSetChanged()
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
}
|
||||||
// weatherJob.start()
|
|
||||||
|
var weatherJob : Job? = null
|
||||||
|
var result : RealmResults<WeatherForcast>? = null
|
||||||
|
// lateinit var weatherJob : Job
|
||||||
|
// @SuppressLint("NotifyDataSetChanged")
|
||||||
|
private fun queryWeather() {
|
||||||
|
result = WorkersDb.getRealm().query<WeatherForcast>().also {
|
||||||
|
BLog.LOGE("re >>> ${it.description()}") // 쿼리 로그
|
||||||
|
}.find()
|
||||||
|
weatherJob?.cancel()
|
||||||
|
weatherJob = CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
result?.asFlow()?.collect { li ->
|
||||||
|
BLog.LOGE("queryWeather done. >>> ${li}")
|
||||||
|
if (li.list.size > 0) {
|
||||||
|
BLog.LOGE("queryWeather done. >>> ${li.list.size}")
|
||||||
|
queryWeatherWithLoc()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
weatherJob?.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
val hideListViewTime = 1000L * 60L * 15L
|
val hideListViewTime = 1000L * 60L * 15L
|
||||||
|
|||||||
@ -14,8 +14,10 @@ class WeatherForcast: RealmObject {
|
|||||||
var location: Location? = null
|
var location: Location? = null
|
||||||
var current: Current? = null
|
var current: Current? = null
|
||||||
var forecast: Forecast? = null
|
var forecast: Forecast? = null
|
||||||
|
var lastUpdateTime : Long = 0L
|
||||||
|
|
||||||
fun readyForSaving() {
|
fun readyForSaving() {
|
||||||
|
lastUpdateTime = System.currentTimeMillis()
|
||||||
forecast?.fill()
|
forecast?.fill()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import com.google.android.gms.tasks.CancellationTokenSource
|
|||||||
import io.realm.kotlin.UpdatePolicy
|
import io.realm.kotlin.UpdatePolicy
|
||||||
import io.realm.kotlin.ext.asFlow
|
import io.realm.kotlin.ext.asFlow
|
||||||
import io.realm.kotlin.ext.query
|
import io.realm.kotlin.ext.query
|
||||||
|
import rasel.lunar.launcher.model.Hour
|
||||||
import rasel.lunar.launcher.model.WeatherForcast
|
import rasel.lunar.launcher.model.WeatherForcast
|
||||||
import rasel.lunar.launcher.utils.BLog
|
import rasel.lunar.launcher.utils.BLog
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
@ -51,6 +52,7 @@ class OpenWeatherGetter(context: Context, workerParams: WorkerParameters) : Base
|
|||||||
|
|
||||||
fun getWeather(latitude: Double, longitude: Double) {
|
fun getWeather(latitude: Double, longitude: Double) {
|
||||||
BLog.LOGE("into getWeather")
|
BLog.LOGE("into getWeather")
|
||||||
|
///saved weatherForcast
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(URI_WEATHERAPI)
|
.baseUrl(URI_WEATHERAPI)
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
@ -60,7 +62,7 @@ class OpenWeatherGetter(context: Context, workerParams: WorkerParameters) : Base
|
|||||||
ver = VER_WEATHERAPI,
|
ver = VER_WEATHERAPI,
|
||||||
key = KEY_WEATHERAPI,
|
key = KEY_WEATHERAPI,
|
||||||
q = "$latitude,$longitude",
|
q = "$latitude,$longitude",
|
||||||
days = DAYS.toString()
|
days = (System.currentTimeMillis() % 5L).toInt().toString()
|
||||||
)?.execute()?.let { response ->
|
)?.execute()?.let { response ->
|
||||||
BLog.LOGE("into getWeather afterc excute")
|
BLog.LOGE("into getWeather afterc excute")
|
||||||
BLog.LOGE("weatherApi forecast response >>> $response")
|
BLog.LOGE("weatherApi forecast response >>> $response")
|
||||||
@ -75,8 +77,10 @@ class OpenWeatherGetter(context: Context, workerParams: WorkerParameters) : Base
|
|||||||
}
|
}
|
||||||
// Realm에 저장
|
// Realm에 저장
|
||||||
WorkersDb.getRealm().writeBlocking {
|
WorkersDb.getRealm().writeBlocking {
|
||||||
copyToRealm(weatherInfo, UpdatePolicy.ALL)
|
var result = copyToRealm(weatherInfo, UpdatePolicy.ALL)
|
||||||
|
BLog.LOGE("saved weatherForcast >>> ${result}")
|
||||||
}
|
}
|
||||||
|
BLog.LOGE("saved weatherForcast >>> ${WorkersDb.getRealm().query<Hour>().count().find()}")
|
||||||
BLog.LOGE("saved weatherForcast >>> ${WorkersDb.getRealm().query<WeatherForcast>().first().find()?.forecast?.forecastdayRealm?.size}")
|
BLog.LOGE("saved weatherForcast >>> ${WorkersDb.getRealm().query<WeatherForcast>().first().find()?.forecast?.forecastdayRealm?.size}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user