Wake screen widget (#8)

* - Update widget validation
* - Cleaned widget folder and code
This commit is contained in:
2022-02-15 00:57:52 +00:00
committed by GitHub
parent ed78d40cc0
commit a1a32e4ceb
11 changed files with 213 additions and 244 deletions

View File

@@ -29,7 +29,7 @@ class ServicesHelper(
private val repository: Repository,
private val settingsRepository: SettingsRepository,
private val locationProvider: LocationProvider
){
) {
@RequiresPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
suspend fun fetchData(): Boolean {
@@ -60,13 +60,14 @@ class ServicesHelper(
suspend fun getWidgetWeather(): WidgetData? {
return try {
val result = repository.loadSingleCurrentWeatherFromRoom(CURRENT_LOCATION)
val epoc = System.currentTimeMillis()
result.weather.let {
val bitmap = it.current?.icon
val location = locationProvider.getLocationNameFromLatLong(it.lat, it.lon)
val temp = it.current?.temp?.toInt().toString()
WidgetData(location, bitmap, temp)
WidgetData(location, bitmap, temp, epoc)
}
} catch (e: Exception) {
null
@@ -80,7 +81,7 @@ class ServicesHelper(
result.weather.daily?.drop(1)?.dropLast(2)?.forEach { dailyWeather ->
val day = dailyWeather.dt?.toSmallDayName()
val bitmap = withContext(Dispatchers.Main) {
val bitmap = withContext(Dispatchers.Main) {
getBitmapFromUrl(dailyWeather.icon)
}
val temp = dailyWeather.max?.toInt().toString()
@@ -102,15 +103,16 @@ class ServicesHelper(
val bitmap = it.current?.icon
val location = locationProvider.getLocationNameFromLatLong(it.lat, it.lon)
val temp = it.current?.temp?.toInt().toString()
val epoc = System.currentTimeMillis()
WidgetData(location, bitmap, temp)
WidgetData(location, bitmap, temp, epoc)
}
val list = mutableListOf<InnerWidgetCellData>()
result.weather.daily?.drop(1)?.dropLast(2)?.forEach { dailyWeather ->
val day = dailyWeather.dt?.toSmallDayName()
val icon = dailyWeather.icon
val icon = dailyWeather.icon
val temp = dailyWeather.max?.toInt().toString()
val item = InnerWidgetCellData(day, icon, temp)
@@ -126,25 +128,24 @@ class ServicesHelper(
private suspend fun getBitmapFromUrl(imageAddress: String?): Bitmap? {
return suspendCoroutine { cont ->
Picasso.get().load(imageAddress).into(object : Target {
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
cont.resume(bitmap)
}
Picasso.get().load(imageAddress).into(object : Target {
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
cont.resume(bitmap)
}
override fun onBitmapFailed(e: Exception?, d: Drawable?) {
cont.resume(null)
}
override fun onBitmapFailed(e: Exception?, d: Drawable?) {
cont.resume(null)
}
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {}
})
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {}
})
}
}
fun getWidgetBackground(): Int {
return if (settingsRepository.isBlackBackground()) {
return if (settingsRepository.isBlackBackground())
Color.BLACK
} else {
else
Color.TRANSPARENT
}
}
}

View File

@@ -5,7 +5,8 @@ import android.graphics.Bitmap
data class WidgetData(
val location: String?,
val icon: String?,
val currentTemp: String?
val currentTemp: String?,
val timeStamp: Long
)
data class InnerWidgetData(

View File

@@ -133,6 +133,7 @@
android:rowCount="1">
<LinearLayout
android:id="@+id/widget_item_0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
@@ -165,6 +166,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/widget_item_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
@@ -197,6 +199,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/widget_item_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
@@ -229,6 +232,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/widget_item_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
@@ -260,6 +264,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/widget_item_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"