|
|
|
@ -21,13 +21,16 @@ package org.isoron.uhabits.intents
|
|
|
|
|
|
|
|
|
|
import android.app.PendingIntent
|
|
|
|
|
import android.app.PendingIntent.FLAG_IMMUTABLE
|
|
|
|
|
import android.app.PendingIntent.FLAG_MUTABLE
|
|
|
|
|
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
|
|
|
|
|
import android.app.PendingIntent.getActivity
|
|
|
|
|
import android.app.PendingIntent.getBroadcast
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import org.isoron.uhabits.activities.habits.list.ListHabitsActivity
|
|
|
|
|
import org.isoron.uhabits.activities.habits.show.ShowHabitActivity
|
|
|
|
|
import org.isoron.uhabits.core.AppScope
|
|
|
|
|
import org.isoron.uhabits.core.models.Habit
|
|
|
|
|
import org.isoron.uhabits.core.models.Timestamp
|
|
|
|
@ -89,6 +92,20 @@ class PendingIntentFactory
|
|
|
|
|
)
|
|
|
|
|
.getPendingIntent(0, FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT)!!
|
|
|
|
|
|
|
|
|
|
fun showHabitTemplate(): PendingIntent {
|
|
|
|
|
return getActivity(
|
|
|
|
|
context,
|
|
|
|
|
0,
|
|
|
|
|
Intent(context, ShowHabitActivity::class.java),
|
|
|
|
|
getIntentTemplateFlags()
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun showHabitFillIn(habit: Habit) =
|
|
|
|
|
Intent().apply {
|
|
|
|
|
data = Uri.parse(habit.uriString)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun showReminder(
|
|
|
|
|
habit: Habit,
|
|
|
|
|
reminderTime: Long?,
|
|
|
|
@ -151,4 +168,43 @@ class PendingIntentFactory
|
|
|
|
|
FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun showNumberPickerTemplate(): PendingIntent {
|
|
|
|
|
return getActivity(
|
|
|
|
|
context,
|
|
|
|
|
1,
|
|
|
|
|
Intent(context, ListHabitsActivity::class.java).apply {
|
|
|
|
|
action = ListHabitsActivity.ACTION_EDIT
|
|
|
|
|
},
|
|
|
|
|
getIntentTemplateFlags()
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun showNumberPickerFillIn(habit: Habit, timestamp: Timestamp) = Intent().apply {
|
|
|
|
|
putExtra("habit", habit.id)
|
|
|
|
|
putExtra("timestamp", timestamp.unixTime)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun getIntentTemplateFlags(): Int {
|
|
|
|
|
var flags = 0
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
|
|
|
flags = flags or FLAG_MUTABLE
|
|
|
|
|
}
|
|
|
|
|
return flags
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun toggleCheckmarkTemplate(): PendingIntent =
|
|
|
|
|
getBroadcast(
|
|
|
|
|
context,
|
|
|
|
|
2,
|
|
|
|
|
Intent(context, WidgetReceiver::class.java).apply {
|
|
|
|
|
action = WidgetReceiver.ACTION_TOGGLE_REPETITION
|
|
|
|
|
},
|
|
|
|
|
getIntentTemplateFlags()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
fun toggleCheckmarkFillIn(habit: Habit, timestamp: Timestamp) = Intent().apply {
|
|
|
|
|
data = Uri.parse(habit.uriString)
|
|
|
|
|
putExtra("timestamp", timestamp.unixTime)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|