connect functionality

pull/1960/head
Peketr 2 years ago
parent ca428a7dd5
commit bcf9120ec1

@ -146,6 +146,18 @@ class PendingIntentFactory
FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun incrementNumerical(habit: Habit, timestamp: Long?): PendingIntent =
getBroadcast(
context,
2,
Intent(context, WidgetReceiver::class.java).apply {
data = Uri.parse(habit.uriString)
action = WidgetReceiver.ACTION_INCREMENT_NUMERICAL
if (timestamp != null) putExtra("timestamp", timestamp)
},
FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun updateWidgets(): PendingIntent =
getBroadcast(
context,

@ -99,6 +99,17 @@ class WidgetReceiver : BroadcastReceiver() {
widgetUpdater.updateWidgets()
widgetUpdater.scheduleStartDayWidgetUpdate()
}
ACTION_INCREMENT_NUMERICAL -> {
Log.d(
TAG,
String.format(
"onIncrementNumerical habit=%d timestamp=%d",
data!!.habit.id,
data.timestamp.unixTime
)
)
controller.onIncrement(data.habit,data.timestamp,(data.habit.increment * 1000).toInt())
}
}
} catch (e: RuntimeException) {
Log.e("WidgetReceiver", "could not process intent", e)
@ -116,6 +127,7 @@ class WidgetReceiver : BroadcastReceiver() {
const val ACTION_DISMISS_REMINDER = "org.isoron.uhabits.ACTION_DISMISS_REMINDER"
const val ACTION_REMOVE_REPETITION = "org.isoron.uhabits.ACTION_REMOVE_REPETITION"
const val ACTION_TOGGLE_REPETITION = "org.isoron.uhabits.ACTION_TOGGLE_REPETITION"
const val ACTION_INCREMENT_NUMERICAL = "org.isoron.uhabits.ACTION_INCREMENT_NUMERICAL"
const val ACTION_UPDATE_WIDGETS_VALUE = "org.isoron.uhabits.ACTION_UPDATE_WIDGETS_VALUE"
private const val TAG = "WidgetReceiver"
var lastReceivedIntent: Intent? = null

@ -41,7 +41,10 @@ open class CheckmarkWidget(
override fun getOnClickPendingIntent(context: Context): PendingIntent? {
return if (habit.isNumerical) {
if (habit.increment == 0.0)
pendingIntentFactory.showNumberPicker(habit, DateUtils.getTodayWithOffset())
else
pendingIntentFactory.incrementNumerical(habit, null)
} else {
pendingIntentFactory.toggleCheckmark(habit, null)
}

Loading…
Cancel
Save