Fix: Fixed the last updated time.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.github.droidworksstudio.launcher.helper.weather
|
|||||||
|
|
||||||
data class WeatherResponse(
|
data class WeatherResponse(
|
||||||
val name: String,
|
val name: String,
|
||||||
|
val dt: Long,
|
||||||
val main: Main,
|
val main: Main,
|
||||||
val wind: Wind,
|
val wind: Wind,
|
||||||
val sys: Sys,
|
val sys: Sys,
|
||||||
@@ -22,13 +23,13 @@ data class Main(
|
|||||||
val humidity: Int
|
val humidity: Int
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Weather(
|
|
||||||
val description: String,
|
|
||||||
val id: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class Sys(
|
data class Sys(
|
||||||
val country: String,
|
val country: String,
|
||||||
val sunrise: Int,
|
val sunrise: Int,
|
||||||
val sunset: Int
|
val sunset: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Weather(
|
||||||
|
val description: String,
|
||||||
|
val id: Int
|
||||||
)
|
)
|
||||||
@@ -20,7 +20,6 @@ import android.os.Environment
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
||||||
@@ -338,8 +337,6 @@ class MainActivity : AppCompatActivity(), LocationListener {
|
|||||||
val assets = jsonObject.getJSONArray("assets")
|
val assets = jsonObject.getJSONArray("assets")
|
||||||
val apkUrl = (assets.get(1) as JSONObject).getString("browser_download_url")
|
val apkUrl = (assets.get(1) as JSONObject).getString("browser_download_url")
|
||||||
|
|
||||||
Log.d("testingIssues", "$latestVersion > $currentVersion")
|
|
||||||
|
|
||||||
if (latestVersion > currentVersion) {
|
if (latestVersion > currentVersion) {
|
||||||
val sharedPreferences = getSharedPreferences("update_prefs", Context.MODE_PRIVATE)
|
val sharedPreferences = getSharedPreferences("update_prefs", Context.MODE_PRIVATE)
|
||||||
val declinedVersion = sharedPreferences.getString("declined_version", "")
|
val declinedVersion = sharedPreferences.getString("declined_version", "")
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ import java.util.Calendar
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.absoluteValue
|
|
||||||
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -127,7 +126,6 @@ class WidgetFragment : Fragment(),
|
|||||||
context.getSharedPreferences(Constants.WEATHER_PREFS, Context.MODE_PRIVATE)
|
context.getSharedPreferences(Constants.WEATHER_PREFS, Context.MODE_PRIVATE)
|
||||||
val latitude = sharedPreferences.getFloat(Constants.LATITUDE, 0f)
|
val latitude = sharedPreferences.getFloat(Constants.LATITUDE, 0f)
|
||||||
val longitude = sharedPreferences.getFloat(Constants.LONGITUDE, 0f)
|
val longitude = sharedPreferences.getFloat(Constants.LONGITUDE, 0f)
|
||||||
val timestamp = convertTimestampToReadableDate(sharedPreferences.getLong("cachedDataTimestamp", 0))
|
|
||||||
|
|
||||||
// Pre-fetch preferences
|
// Pre-fetch preferences
|
||||||
val showWeatherWidget = preferenceHelper.showWeatherWidget
|
val showWeatherWidget = preferenceHelper.showWeatherWidget
|
||||||
@@ -162,6 +160,7 @@ class WidgetFragment : Fragment(),
|
|||||||
Log.d("weatherResponse", "$weatherResponse")
|
Log.d("weatherResponse", "$weatherResponse")
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
val timestamp = convertTimestampToReadableDate(weatherResponse.dt)
|
||||||
binding.apply {
|
binding.apply {
|
||||||
weatherCity.text = getString(R.string.widget_weather_location, weatherResponse.name, weatherResponse.sys.country)
|
weatherCity.text = getString(R.string.widget_weather_location, weatherResponse.name, weatherResponse.sys.country)
|
||||||
weatherTemperature.text = getString(R.string.widget_weather_temp, weatherResponse.main.temp, temperatureScale)
|
weatherTemperature.text = getString(R.string.widget_weather_temp, weatherResponse.main.temp, temperatureScale)
|
||||||
@@ -230,11 +229,13 @@ class WidgetFragment : Fragment(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun convertTimestampToReadableDate(timestamp: Long): String {
|
private fun convertTimestampToReadableDate(timestamp: Long): String {
|
||||||
val date = Date(timestamp)
|
// Multiply by 1000 to convert seconds to milliseconds if the timestamp is in seconds
|
||||||
|
val date = Date(timestamp * 1000)
|
||||||
val format = SimpleDateFormat("hh:mm aa", Locale.getDefault())
|
val format = SimpleDateFormat("hh:mm aa", Locale.getDefault())
|
||||||
return format.format(date)
|
return format.format(date)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun setupBatteryWidget() {
|
private fun setupBatteryWidget() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
if (!preferenceHelper.showBatteryWidget) return@launch
|
if (!preferenceHelper.showBatteryWidget) return@launch
|
||||||
|
|||||||
Reference in New Issue
Block a user