Skip to content

Commit

Permalink
connect functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Peketr committed Mar 18, 2024
1 parent ca428a7 commit bcf9120
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ open class CheckmarkWidget(

override fun getOnClickPendingIntent(context: Context): PendingIntent? {
return if (habit.isNumerical) {
pendingIntentFactory.showNumberPicker(habit, DateUtils.getTodayWithOffset())
if (habit.increment == 0.0)
pendingIntentFactory.showNumberPicker(habit, DateUtils.getTodayWithOffset())
else
pendingIntentFactory.incrementNumerical(habit, null)
} else {
pendingIntentFactory.toggleCheckmark(habit, null)
}
Expand Down

0 comments on commit bcf9120

Please sign in to comment.