Skip to content

Commit a221ad9

Browse files
committed
widget activities grid, change ListView to static layout
1 parent cb93c1d commit a221ad9

47 files changed

Lines changed: 543 additions & 232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

data_local/src/main/java/com/example/util/simpletimetracker/data_local/prefs/PrefsRepoImpl.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class PrefsRepoImpl @Inject constructor(
578578

579579
override fun setQuickSettingsWidget(widgetId: Int, data: QuickSettingsWidgetType) {
580580
val key = KEY_QUICK_SETTINGS_WIDGET_TYPE + widgetId
581-
logPrefsDataAccess("set $widgetId")
581+
logPrefsDataAccess("setQuickSettingsWidget $widgetId")
582582
val type = when (data) {
583583
is QuickSettingsWidgetType.AllowMultitasking -> 0L
584584
is QuickSettingsWidgetType.ShowRecordTagSelection -> 1L
@@ -588,7 +588,7 @@ class PrefsRepoImpl @Inject constructor(
588588

589589
override fun getQuickSettingsWidget(widgetId: Int): QuickSettingsWidgetType {
590590
val key = KEY_QUICK_SETTINGS_WIDGET_TYPE + widgetId
591-
logPrefsDataAccess("get $key")
591+
logPrefsDataAccess("getQuickSettingsWidget $key")
592592
return when (prefs.getLong(key, 0)) {
593593
0L -> QuickSettingsWidgetType.AllowMultitasking
594594
1L -> QuickSettingsWidgetType.ShowRecordTagSelection
@@ -598,7 +598,25 @@ class PrefsRepoImpl @Inject constructor(
598598

599599
override fun removeQuickSettingsWidget(widgetId: Int) {
600600
val key = KEY_QUICK_SETTINGS_WIDGET_TYPE + widgetId
601-
logPrefsDataAccess("remove $key")
601+
logPrefsDataAccess("removeQuickSettingsWidget $key")
602+
prefs.edit { remove(key) }
603+
}
604+
605+
override fun setGridWidget(widgetId: Int, page: Int) {
606+
val key = KEY_GRID_WIDGET_PAGE + widgetId
607+
logPrefsDataAccess("setGridWidget $key")
608+
prefs.edit { putInt(key, page) }
609+
}
610+
611+
override fun getGridWidget(widgetId: Int): Int {
612+
val key = KEY_GRID_WIDGET_PAGE + widgetId
613+
logPrefsDataAccess("getGridWidget $key")
614+
return prefs.getInt(key, 0)
615+
}
616+
617+
override fun removeGridWidget(widgetId: Int) {
618+
val key = KEY_GRID_WIDGET_PAGE + widgetId
619+
logPrefsDataAccess("removeGridWidget $key")
602620
prefs.edit { remove(key) }
603621
}
604622

@@ -760,6 +778,7 @@ class PrefsRepoImpl @Inject constructor(
760778
private const val KEY_STATISTICS_WIDGET_RANGE_LAST_DAYS = "statistics_widget_range_last_days_"
761779
private const val KEY_STATISTICS_WIDGET_FILTERING_TYPE = "statistics_widget_filtering_type_"
762780
private const val KEY_QUICK_SETTINGS_WIDGET_TYPE = "quick_settings_widget_type_"
781+
private const val KEY_GRID_WIDGET_PAGE = "grid_widget_page_"
763782

764783
// Removed
765784
private const val KEY_SORT_RECORD_TYPES_BY_COLOR = "sortRecordTypesByColor" // Boolean

domain/src/main/java/com/example/util/simpletimetracker/domain/notifications/interactor/UpdateExternalViewsInteractor.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
3838
Update.WidgetSingleTypes.takeIf { getRetroactiveTrackingMode() }
3939
?: Update.WidgetSingleType(listOf(typeId)),
4040
Update.WidgetUniversal.takeIf { getRetroactiveTrackingMode() },
41+
Update.WidgetGrid.takeIf { !fromArchive },
4142
Update.Wear.takeIf { !fromArchive || getRetroactiveTrackingMode() },
4243
Update.NotificationTypes.takeIf { !fromArchive },
4344
Update.NotificationWithControls.takeIf { !fromArchive },
@@ -49,6 +50,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
4950
Update.NotificationTypes,
5051
Update.NotificationWithControls,
5152
Update.Wear,
53+
Update.WidgetGrid,
5254
)
5355
}
5456

@@ -61,6 +63,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
6163
Update.GoalReschedule(listOf(typeId)), // Goals changed, or categories assigned changed.
6264
Update.WidgetSingleTypes,
6365
Update.WidgetUniversal,
66+
Update.WidgetGrid,
6467
Update.WidgetStatistics,
6568
Update.Wear,
6669
)
@@ -70,6 +73,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
7073
runUpdates(
7174
Update.NotificationTypes,
7275
Update.NotificationWithControls,
76+
Update.WidgetGrid,
7377
Update.Wear,
7478
)
7579
}
@@ -116,6 +120,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
116120
Update.GoalTagReschedule(fullTagIds).takeIf { fullTagIds.isNotEmpty() },
117121
Update.WidgetSingleTypes.takeIf { updateWidgets },
118122
Update.WidgetUniversal.takeIf { updateWidgets },
123+
Update.WidgetGrid.takeIf { updateWidgets },
119124
Update.WidgetStatistics.takeIf { updateWidgets },
120125
Update.Wear.takeIf { updateWidgets },
121126
)
@@ -138,6 +143,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
138143
Update.GoalTagReschedule(tagIds).takeIf { tagIds.isNotEmpty() },
139144
Update.WidgetSingleTypes,
140145
Update.WidgetUniversal,
146+
Update.WidgetGrid,
141147
Update.WidgetStatistics,
142148
Update.Wear,
143149
)
@@ -156,6 +162,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
156162
Update.WidgetSingleTypes.takeIf { getRetroactiveTrackingMode() }
157163
?: Update.WidgetSingleType(typeIds),
158164
Update.WidgetUniversal.takeIf { getRetroactiveTrackingMode() },
165+
Update.WidgetGrid,
159166
Update.Wear.takeIf { getRetroactiveTrackingMode() },
160167
)
161168
}
@@ -174,6 +181,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
174181
Update.WidgetSingleTypes.takeIf { getRetroactiveTrackingMode() }
175182
?: Update.WidgetSingleType(typeIds),
176183
Update.WidgetUniversal.takeIf { getRetroactiveTrackingMode() },
184+
Update.WidgetGrid,
177185
Update.Wear.takeIf { getRetroactiveTrackingMode() },
178186
)
179187
}
@@ -268,6 +276,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
268276
Update.WidgetSingleType(listOf(typeId)),
269277
Update.NotificationType(listOf(typeId)),
270278
Update.NotificationWithControls,
279+
Update.WidgetGrid,
271280
)
272281
}
273282

@@ -276,13 +285,15 @@ class UpdateExternalViewsInteractor @Inject constructor(
276285
Update.WidgetSingleTypes,
277286
Update.NotificationTypes,
278287
Update.NotificationWithControls,
288+
Update.WidgetGrid,
279289
)
280290
}
281291

282292
suspend fun onRepeatEnabled() {
283293
runUpdates(
284294
Update.NotificationTypes,
285295
Update.NotificationWithControls,
296+
Update.WidgetGrid,
286297
Update.Wear,
287298
)
288299
}
@@ -293,6 +304,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
293304
Update.WidgetSingleTypes,
294305
Update.NotificationTypes,
295306
Update.NotificationWithControls,
307+
Update.WidgetGrid,
296308
Update.GoalReschedule(),
297309
Update.GoalTagReschedule(),
298310
)
@@ -304,6 +316,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
304316
Update.WidgetSingleTypes,
305317
Update.NotificationTypes,
306318
Update.NotificationWithControls,
319+
Update.WidgetGrid,
307320
Update.GoalReschedule(),
308321
Update.GoalTagReschedule(),
309322
)
@@ -381,6 +394,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
381394
runUpdates(
382395
Update.WidgetSingleTypes,
383396
Update.WidgetUniversal,
397+
Update.WidgetGrid,
384398
Update.NotificationWithControls,
385399
Update.Wear,
386400
)
@@ -391,6 +405,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
391405
runUpdates(
392406
Update.WidgetSingleTypes,
393407
Update.WidgetUniversal,
408+
Update.WidgetGrid,
394409
Update.WidgetStatistics,
395410
Update.WidgetQuickSettings,
396411
)
@@ -417,6 +432,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
417432
Update.GoalTagReschedule(),
418433
Update.WidgetSingleTypes,
419434
Update.WidgetUniversal,
435+
Update.WidgetGrid,
420436
Update.WidgetStatistics,
421437
Update.WidgetQuickSettings,
422438
Update.Wear,
@@ -431,13 +447,15 @@ class UpdateExternalViewsInteractor @Inject constructor(
431447
Update.GoalTagReschedule(),
432448
Update.WidgetStatistics,
433449
Update.WidgetSingleTypes,
450+
Update.WidgetGrid,
434451
)
435452
}
436453

437454
suspend fun onRestoreFromArchive() {
438455
runUpdates(
439456
Update.NotificationTypes,
440457
Update.NotificationWithControls,
458+
Update.WidgetGrid,
441459
Update.Wear,
442460
)
443461
}
@@ -449,6 +467,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
449467
Update.NotificationWithControls,
450468
Update.WidgetSingleTypes,
451469
Update.WidgetUniversal,
470+
Update.WidgetGrid,
452471
Update.WidgetStatistics,
453472
Update.WidgetQuickSettings,
454473
Update.Wear,
@@ -485,7 +504,8 @@ class UpdateExternalViewsInteractor @Inject constructor(
485504
}
486505
is Update.WidgetUniversal -> {
487506
widgetInteractor.updateWidgets(WidgetType.UNIVERSAL)
488-
// TODO WIDGET add goals and add more update sources
507+
}
508+
is Update.WidgetGrid -> {
489509
widgetInteractor.updateWidgets(WidgetType.GRID)
490510
}
491511
is Update.WidgetSingleTypes -> {
@@ -529,6 +549,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
529549
data object WidgetStatistics : Update
530550
data object WidgetQuickSettings : Update
531551
data object WidgetUniversal : Update
552+
data object WidgetGrid : Update
532553
data object WidgetSingleTypes : Update
533554
data class WidgetSingleType(val typeIds: List<Long>) : Update
534555
data object Wear : Update

domain/src/main/java/com/example/util/simpletimetracker/domain/prefs/interactor/PrefsInteractor.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,18 @@ class PrefsInteractor @Inject constructor(
826826
prefsRepo.removeQuickSettingsWidget(widgetId)
827827
}
828828

829+
suspend fun setGridWidget(widgetId: Int, page: Int) = withContext(Dispatchers.IO) {
830+
prefsRepo.setGridWidget(widgetId, page)
831+
}
832+
833+
suspend fun getGridWidget(widgetId: Int): Int = withContext(Dispatchers.IO) {
834+
prefsRepo.getGridWidget(widgetId)
835+
}
836+
837+
suspend fun removeGridWidget(widgetId: Int) = withContext(Dispatchers.IO) {
838+
prefsRepo.removeGridWidget(widgetId)
839+
}
840+
829841
suspend fun setCardOrderManual(cardsOrder: Map<Long, Long>) = withContext(Dispatchers.IO) {
830842
prefsRepo.cardOrderManual = mapOrderManual(cardsOrder)
831843
}

domain/src/main/java/com/example/util/simpletimetracker/domain/prefs/repo/PrefsRepo.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ interface PrefsRepo {
222222

223223
fun removeQuickSettingsWidget(widgetId: Int)
224224

225+
fun setGridWidget(widgetId: Int, page: Int)
226+
227+
fun getGridWidget(widgetId: Int): Int
228+
229+
fun removeGridWidget(widgetId: Int)
230+
225231
fun clear()
226232
fun clearDefaultTypesHidden()
227233
fun clearRetroactiveMultitaskingHidden()

domain/src/main/java/com/example/util/simpletimetracker/domain/widget/interactor/WidgetInteractor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ interface WidgetInteractor {
1414

1515
fun updateQuickSettingsWidget(widgetId: Int)
1616

17+
fun updateGridWidget(widgetId: Int)
18+
1719
fun updateWidgets(type: WidgetType)
1820
}

features/feature_views/src/main/res/values/dimens.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@
3838

3939
<dimen name="widget_statistics_refresh_button_size">20dp</dimen>
4040

41+
<dimen name="widget_grid_controls_button_size">32dp</dimen>
42+
<dimen name="widget_grid_controls_image_size">24dp</dimen>
43+
4144
<dimen name="rounded_span_radius">99dp</dimen>
4245
</resources>

features/feature_widget/src/main/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@
9898
android:resource="@xml/widget_quick_settings_info" />
9999
</receiver>
100100

101-
<service android:name=".grid.WidgetGridRemoteViewsService"
102-
android:permission="android.permission.BIND_REMOTEVIEWS" />
103-
104101
</application>
105102

106103
</manifest>

features/feature_widget/src/main/java/com/example/util/simpletimetracker/feature_widget/common/WidgetInteractorImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ class WidgetInteractorImpl @Inject constructor(
1919

2020
override fun updateQuickSettingsWidget(widgetId: Int) = widgetManager.updateQuickSettingsWidget(widgetId)
2121

22+
override fun updateGridWidget(widgetId: Int) = widgetManager.updateGridWidget(widgetId)
23+
2224
override fun updateWidgets(type: WidgetType) = widgetManager.updateWidgets(listOf(type))
2325
}

features/feature_widget/src/main/java/com/example/util/simpletimetracker/feature_widget/common/WidgetManager.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class WidgetManager @Inject constructor(
1919
@ApplicationContext private val context: Context,
2020
) {
2121

22-
// TODO WIDGET add update
2322
fun updateSingleWidget(widgetId: Int) {
2423
val intent = Intent(context, WidgetSingleProvider::class.java)
2524
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
@@ -52,10 +51,17 @@ class WidgetManager @Inject constructor(
5251
context.sendBroadcast(intent)
5352
}
5453

54+
fun updateGridWidget(widgetId: Int) {
55+
val intent = Intent(context, WidgetGridProvider::class.java)
56+
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
57+
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(widgetId))
58+
context.sendBroadcast(intent)
59+
}
60+
5561
fun updateWidgets(types: List<WidgetType>) {
5662
val widgetsToUpdate = types
5763
.takeUnless { it.isEmpty() }
58-
?: WidgetType.values().toList()
64+
?: WidgetType.entries
5965

6066
val providers = widgetsToUpdate.map { type ->
6167
when (type) {

features/feature_widget/src/main/java/com/example/util/simpletimetracker/feature_widget/common/WidgetViewsHolder.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ class WidgetViewsHolder @Inject constructor(
2222
private var recordTypeView: RecordTypeView? = null
2323
private var statisticsView: WidgetStatisticsChartView? = null
2424
private var statisticsRefreshView: IconView? = null
25+
private var gridRecordTypeView: RecordTypeView? = null
2526

2627
fun initialize() {
2728
getRecordTypeView(context)
29+
getGridRecordTypeView(context)
2830
getStatisticsView(context)
2931
getStatisticsRefreshView(context)
3032
}
@@ -38,6 +40,15 @@ class WidgetViewsHolder @Inject constructor(
3840
return view
3941
}
4042

43+
fun getGridRecordTypeView(context: Context): RecordTypeView {
44+
gridRecordTypeView?.let { return it }
45+
val view = allowVmViolations {
46+
RecordTypeView(ContextThemeWrapper(context, R.style.AppTheme))
47+
}
48+
gridRecordTypeView = view
49+
return view
50+
}
51+
4152
fun getStatisticsView(context: Context): WidgetStatisticsChartView {
4253
statisticsView?.let { return it }
4354
val view = allowVmViolations {

0 commit comments

Comments
 (0)