diff --git a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt index 1267f899..7fc115c3 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt @@ -308,7 +308,7 @@ internal class LauncherActivity : AppCompatActivity() { mWorkManager?.cancelAllWorkByTag(LocationGetter.TAG) mWorkManager?.enqueueUniquePeriodicWork( LocationGetter.TAG, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, - PeriodicWorkRequestBuilder(PrefHelper.shortTimePeriod, TimeUnit.MINUTES) + PeriodicWorkRequestBuilder(PrefHelper.longTimePeriod, TimeUnit.MINUTES) .addTag(LocationGetter.TAG) .build()) }, weatherDelay, TimeUnit.SECONDS) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt index 1ebe49c4..22f4025b 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt @@ -92,6 +92,8 @@ import bums.lunatic.launcher.workers.LocationGetter import bums.lunatic.launcher.workers.RecentCall import bums.lunatic.launcher.workers.RecentSms import bums.lunatic.launcher.workers.WorkersDb +import bums.lunatic.launcher.workers.latitudeRange +import bums.lunatic.launcher.workers.longitudeRange import io.realm.kotlin.ext.query import io.realm.kotlin.notifications.InitialResults import io.realm.kotlin.notifications.ResultsChange @@ -105,6 +107,7 @@ import kotlinx.coroutines.launch import org.json.JSONArray import org.json.JSONObject import java.math.BigDecimal +import java.math.RoundingMode import java.net.URLEncoder import java.util.Calendar import java.util.Date @@ -351,12 +354,15 @@ internal class LauncherHome : Fragment() { } @SuppressLint("NotifyDataSetChanged") - suspend fun queryWeatherWithLoc(){ + fun queryWeatherWithLoc(){ WorkersDb.getRealm().apply { + var latR = latitudeRange(BigDecimal.valueOf(LocationGetter.latitude).setScale(6,RoundingMode.HALF_UP).toDouble(), 200) + var lonR = longitudeRange(BigDecimal.valueOf(LocationGetter.latitude).setScale(6,RoundingMode.HALF_UP).toDouble(),BigDecimal.valueOf(LocationGetter.longitude).setScale(6,RoundingMode.HALF_UP).toDouble(), 200) query() - .query("lat == $0 AND lon == $1", - LocationGetter.latitude?.let { BigDecimal.valueOf(it).toDouble() }, - LocationGetter.longitude?.let { BigDecimal.valueOf(it).toDouble() } + .query("lat >= $0 AND lat <= $1 AND lon >= $2 AND lon <= $3 AND time_epoch >= $4", + latR.first(),latR.last(), + lonR.first(),lonR.last(), + (System.currentTimeMillis() / 1000L).toLong() ).also { BLog.LOGE("re >>> ${it.description()}") }.find().let {hours -> diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt index 6e583566..d98e0616 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt @@ -39,7 +39,7 @@ object RssFeedsParser { it.data?.nsfw = nsfw if(((it.data?.created_utc ?: 0).toLong() * 1000L > dateTime)) { (it.data as? RssDataInterface)?.let { rss -> - if (rss.title().contains("request") == false) { + if (rss.title().contains("request", true) == false) { returnList.add(rss) } } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationGetter.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationGetter.kt index 9650eba3..3cfbc68e 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationGetter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationGetter.kt @@ -17,8 +17,8 @@ import kotlin.math.cos class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGetter(context, workerParams) { companion object { val TAG = "LocationGetter" - var longitude: Double? = null - var latitude: Double? = null + var longitude: Double = 0.0 + var latitude: Double = 0.0 } @SuppressLint("MissingPermission") diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt index 12555dd4..96137334 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt @@ -13,11 +13,14 @@ import android.os.Build import android.os.IBinder import android.widget.Toast import androidx.core.app.ActivityCompat +import bums.lunatic.launcher.LauncherActivity.Companion.runWeatherGetter import bums.lunatic.launcher.helpers.PrefHelper import bums.lunatic.launcher.helpers.PrefString import bums.lunatic.launcher.helpers.letTrue import bums.lunatic.launcher.model.LocationLog import bums.lunatic.launcher.utils.BLog +import bums.lunatic.launcher.workers.LocationGetter.Companion.latitude +import bums.lunatic.launcher.workers.LocationGetter.Companion.longitude import com.google.android.gms.location.LocationServices import com.google.gson.Gson import io.realm.kotlin.ext.query @@ -121,6 +124,9 @@ class LocationUpdateService : Service(), LocationListener { override fun onLocationChanged(p0: Location) { BLog.LOGE("p0") PrefHelper.isLocationOn().letTrue { + longitude = p0.longitude + latitude = p0.latitude + runWeatherGetter() pushLocation(this.applicationContext, p0.latitude,p0.longitude) } } @@ -160,6 +166,9 @@ class LocationUpdateService : Service(), LocationListener { java.lang.Double.toString(location.latitude) + location.longitude + "from method", Toast.LENGTH_LONG ).show() + longitude = location.longitude + latitude = location.latitude + runWeatherGetter() pushLocation(this.applicationContext, location.latitude, location.longitude) } }