|
|
@ -88,8 +88,26 @@ internal class StackRemoteViewsFactory(private val context: Context, intent: Int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun getViewAt(position: Int): RemoteViews? {
|
|
|
|
override fun getViewAt(position: Int): RemoteViews? {
|
|
|
|
Log.i("StackRemoteViewsFactory", "getViewAt $position")
|
|
|
|
Log.i("StackRemoteViewsFactory", "getViewAt $position started")
|
|
|
|
return if (0 <= position && position < remoteViews.size) remoteViews[position] else null
|
|
|
|
if (position < 0 || position >= remoteViews.size) return null
|
|
|
|
|
|
|
|
val app = context.applicationContext as HabitsApplication
|
|
|
|
|
|
|
|
val prefs = app.component.preferences
|
|
|
|
|
|
|
|
val habitList = app.component.habitList
|
|
|
|
|
|
|
|
val options = AppWidgetManager.getInstance(context).getAppWidgetOptions(widgetId)
|
|
|
|
|
|
|
|
if (Looper.myLooper() == null) Looper.prepare()
|
|
|
|
|
|
|
|
val habits = habitIds.map { habitList.getById(it) ?: throw HabitNotFoundException() }
|
|
|
|
|
|
|
|
val h = habits[position]
|
|
|
|
|
|
|
|
val widget = constructWidget(h, prefs)
|
|
|
|
|
|
|
|
widget.setDimensions(getDimensionsFromOptions(context, options))
|
|
|
|
|
|
|
|
val landscapeViews = widget.landscapeRemoteViews
|
|
|
|
|
|
|
|
val portraitViews = widget.portraitRemoteViews
|
|
|
|
|
|
|
|
val factory = PendingIntentFactory(context, IntentFactory())
|
|
|
|
|
|
|
|
val intent = StackWidgetType.getIntentFillIn(factory, widgetType, h, habits, getToday())
|
|
|
|
|
|
|
|
landscapeViews.setOnClickFillInIntent(R.id.button, intent)
|
|
|
|
|
|
|
|
portraitViews.setOnClickFillInIntent(R.id.button, intent)
|
|
|
|
|
|
|
|
val remoteViews = RemoteViews(landscapeViews, portraitViews)
|
|
|
|
|
|
|
|
Log.i("StackRemoteViewsFactory", "getViewAt $position ended")
|
|
|
|
|
|
|
|
return remoteViews
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun constructWidget(
|
|
|
|
private fun constructWidget(
|
|
|
@ -134,28 +152,6 @@ internal class StackRemoteViewsFactory(private val context: Context, intent: Int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDataSetChanged() {
|
|
|
|
override fun onDataSetChanged() {
|
|
|
|
Log.i("StackRemoteViewsFactory", "onDataSetChanged started")
|
|
|
|
|
|
|
|
val app = context.applicationContext as HabitsApplication
|
|
|
|
|
|
|
|
val prefs = app.component.preferences
|
|
|
|
|
|
|
|
val habitList = app.component.habitList
|
|
|
|
|
|
|
|
val options = AppWidgetManager.getInstance(context).getAppWidgetOptions(widgetId)
|
|
|
|
|
|
|
|
val newRemoteViews = ArrayList<RemoteViews>()
|
|
|
|
|
|
|
|
if (Looper.myLooper() == null) Looper.prepare()
|
|
|
|
|
|
|
|
val habits = habitIds.map { habitList.getById(it) ?: throw HabitNotFoundException() }
|
|
|
|
|
|
|
|
for (h in habits) {
|
|
|
|
|
|
|
|
val widget = constructWidget(h, prefs)
|
|
|
|
|
|
|
|
widget.setDimensions(getDimensionsFromOptions(context, options))
|
|
|
|
|
|
|
|
val landscapeViews = widget.landscapeRemoteViews
|
|
|
|
|
|
|
|
val portraitViews = widget.portraitRemoteViews
|
|
|
|
|
|
|
|
val factory = PendingIntentFactory(context, IntentFactory())
|
|
|
|
|
|
|
|
val intent = StackWidgetType.getIntentFillIn(factory, widgetType, h, habits, getToday())
|
|
|
|
|
|
|
|
landscapeViews.setOnClickFillInIntent(R.id.button, intent)
|
|
|
|
|
|
|
|
portraitViews.setOnClickFillInIntent(R.id.button, intent)
|
|
|
|
|
|
|
|
newRemoteViews.add(RemoteViews(landscapeViews, portraitViews))
|
|
|
|
|
|
|
|
Log.i("StackRemoteViewsFactory", "onDataSetChanged constructed widget ${h.id}")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
remoteViews = newRemoteViews
|
|
|
|
|
|
|
|
Log.i("StackRemoteViewsFactory", "onDataSetChanged ended")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
init {
|
|
|
|