Skip to content

Commit

Permalink
fixes #178 -- add last checked timestamp to medium size widget
Browse files Browse the repository at this point in the history
  • Loading branch information
sphrak committed Sep 21, 2019
1 parent e1545b0 commit d15d5a8
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.subjects.PublishSubject
import javax.inject.Inject
import org.threeten.bp.LocalDateTime
import org.threeten.bp.format.DateTimeFormatter
import timber.log.Timber

@WeatherForecastMediumFeatureScope
Expand Down Expand Up @@ -84,6 +86,10 @@ class WeatherForecastMediumAppWidgetProvider : BaseAppWidgetProvider() {
Intent(context, WeatherForecastMediumService::class.java)
}

private val dateTimeFormat: DateTimeFormatter by lazy {
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
}

private val pendingIntent: PendingIntent by lazy {
PendingIntent
.getBroadcast(
Expand Down Expand Up @@ -210,12 +216,6 @@ class WeatherForecastMediumAppWidgetProvider : BaseAppWidgetProvider() {

remoteViews.setRemoteAdapter(R.id.weatherForecastMediumGridView, serviceIntent)

appWidgetManager
.notifyAppWidgetViewDataChanged(
appWidgetId,
R.id.weatherForecastMediumGridView
)

weather.windSpeed?.let {
remoteViews.setTextViewText(
R.id.weatherMediumWindSpeed,
Expand Down Expand Up @@ -270,13 +270,23 @@ class WeatherForecastMediumAppWidgetProvider : BaseAppWidgetProvider() {
)
}

val datetimeStamp: LocalDateTime = LocalDateTime.now()

remoteViews.setTextViewText(
R.id.weatherMediumUpdatedAt,
datetimeStamp
.format(dateTimeFormat)
.toString()
)

weather.feelsLikeTemperature?.let {
remoteViews.setTextViewText(R.id.weatherMediumFeelsLikeTemperature, feelsLikeTemperature)
} ?: remoteViews.setViewVisibility(R.id.weatherMediumFeelsLikeTemperature, View.GONE)

remoteViews.setTextViewText(R.id.weatherMediumTemperature, temperature)
remoteViews.setTextViewText(R.id.weatherMediumLocalityName, localityName)
}

appWidgetManager.updateAppWidget(appWidgetId, remoteViews)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class WeatherForecastMediumService : RemoteViewsService() {
private val intent: Intent?
) : RemoteViewsFactory {

@Inject
lateinit var appWidgetManager: AppWidgetManager

@Inject
lateinit var viewModel: WeatherForecastMediumServiceViewModel

Expand Down Expand Up @@ -89,12 +92,7 @@ class WeatherForecastMediumService : RemoteViewsService() {

override fun onDataSetChanged() {
Timber.d("ON DATASET CHANGED")
onInitialisedSubject
.onNext(
WeatherForecastMediumServiceView
.Event
.OnInitialised(appWidgetId)
)
// no-op
}

override fun getLoadingView(): RemoteViews? = null
Expand Down Expand Up @@ -154,7 +152,7 @@ class WeatherForecastMediumService : RemoteViewsService() {
Observable.mergeArray(
onInitialisedSubject
.toObservable()
).subscribeOn(
).observeOn(
scheduler.io()
).compose(
viewModel()
Expand Down Expand Up @@ -185,6 +183,7 @@ class WeatherForecastMediumService : RemoteViewsService() {
Timber.d("RECEIVED WEATHER: $weatherForecastMediumServiceModelList")
list.clear()
list.addAll(weatherForecastMediumServiceModelList)
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.weatherForecastMediumGridView)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fi.kroon.vadret.presentation.weatherforecastwidget.medium.service.di

import android.appwidget.AppWidgetManager
import android.content.Context
import dagger.Module
import dagger.Provides
import fi.kroon.vadret.presentation.weatherforecastwidget.medium.service.WeatherForecastMediumServiceView
Expand All @@ -24,4 +26,11 @@ object WeatherForecastMediumServiceModule {
@JvmStatic
@WeatherForecastMediumServiceScope
fun provideCompositeDisposable(): CompositeDisposable = CompositeDisposable()

@Provides
@JvmStatic
@WeatherForecastMediumServiceScope
fun provideAppWidgetManager(context: Context): AppWidgetManager =
AppWidgetManager
.getInstance(context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
android:textColor="@android:color/white"
android:textSize="@dimen/weather_forecast_small_small_text" />

<TextView
android:id="@+id/weatherMediumUpdatedAt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/weather_forecast_medium_last_updated_spacing"
android:textColor="@color/widget_last_updated_text_dark"
android:textSize="@dimen/weather_forecast_small_tiny_text" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
android:textColor="@android:color/white"
android:textSize="@dimen/weather_forecast_small_small_text" />

<TextView
android:id="@+id/weatherMediumUpdatedAt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/weather_forecast_medium_last_updated_spacing"
android:textColor="@color/widget_last_updated_text_light"
android:textSize="@dimen/weather_forecast_small_tiny_text" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
android:textColor="@android:color/white"
android:textSize="@dimen/weather_forecast_small_small_text" />

<TextView
android:id="@+id/weatherMediumUpdatedAt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/weather_forecast_medium_last_updated_spacing"
android:textColor="@color/widget_last_updated_text_light"
android:textSize="@dimen/weather_forecast_small_tiny_text" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/raw/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.2.3] -- 2019-09-21

### Added
- Added last time checked timestamp on medium widget

### Fixed
- FC on Weather widget medium again (wops)

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@
<color name="widget_background_light">#1AFFFFFF</color>
<color name="widget_background_dark">#1A000000</color>

<!-- Dark/Light Widget Last Updated Text Color -->
<color name="widget_last_updated_text_light">#F4F4F4</color>
<color name="widget_last_updated_text_dark">#F4F4F4</color>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<dimen name="weather_forecast_small_splash_icons_height">14dp</dimen>
<dimen name="weather_forecast_small_icon_margin_end">4dp</dimen>
<dimen name="weather_forecast_small_small_text">14sp</dimen>
<dimen name="weather_forecast_small_tiny_text">10sp</dimen>
<dimen name="weather_forecast_small_temperature_text_size">14sp</dimen>
<dimen name="weather_forecast_small_item_spacing">8dp</dimen>
<dimen name="weather_forecast_small_item_divider_width">1dp</dimen>
Expand All @@ -88,6 +89,7 @@
<dimen name="weather_forecast_medium_splash_icons_height">14dp</dimen>
<dimen name="weather_forecast_medium_icon_margin_end">4dp</dimen>
<dimen name="weather_forecast_medium_padding">4dp</dimen>
<dimen name="weather_forecast_medium_last_updated_spacing">2dp</dimen>

<!-- Weather Forecast Empty Layout -->
<dimen name="weather_forecast_empty_margin_top">4dp</dimen>
Expand Down

0 comments on commit d15d5a8

Please sign in to comment.