mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Merge branch 'dev' into feature/custom-snooze
This commit is contained in:
@@ -54,6 +54,15 @@ class PendingIntentFactory
|
||||
},
|
||||
FLAG_UPDATE_CURRENT)
|
||||
|
||||
fun removeRepetition(habit: Habit): PendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
context, 3,
|
||||
Intent(context, WidgetReceiver::class.java).apply {
|
||||
action = WidgetReceiver.ACTION_REMOVE_REPETITION
|
||||
data = Uri.parse(habit.uriString)
|
||||
},
|
||||
FLAG_UPDATE_CURRENT)
|
||||
|
||||
fun showHabit(habit: Habit): PendingIntent =
|
||||
android.support.v4.app.TaskStackBuilder
|
||||
.create(context)
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.app.*
|
||||
import android.content.*
|
||||
import android.graphics.*
|
||||
import android.graphics.BitmapFactory.*
|
||||
import android.support.annotation.*
|
||||
import android.support.v4.app.*
|
||||
import android.support.v4.app.NotificationCompat.*
|
||||
import org.isoron.androidbase.*
|
||||
@@ -50,11 +51,24 @@ class AndroidNotificationTray
|
||||
override fun showNotification(habit: Habit,
|
||||
notificationId: Int,
|
||||
timestamp: Timestamp,
|
||||
reminderTime: Long) {
|
||||
reminderTime: Long)
|
||||
{
|
||||
val notificationManager = NotificationManagerCompat.from(context)
|
||||
val summary = buildSummary(reminderTime)
|
||||
notificationManager.notify(Int.MAX_VALUE, summary)
|
||||
val notification = buildNotification(habit, reminderTime, timestamp)
|
||||
notificationManager.notify(notificationId, notification)
|
||||
}
|
||||
|
||||
val checkAction = Action(
|
||||
@NonNull
|
||||
fun buildNotification(@NonNull habit: Habit,
|
||||
@NonNull reminderTime: Long,
|
||||
@NonNull timestamp: Timestamp) : Notification
|
||||
{
|
||||
|
||||
val addRepetitionAction = Action(
|
||||
R.drawable.ic_action_check,
|
||||
context.getString(R.string.check),
|
||||
context.getString(R.string.yes),
|
||||
pendingIntents.addCheckmark(habit, timestamp))
|
||||
|
||||
val snoozeAction = Action(
|
||||
@@ -62,6 +76,12 @@ class AndroidNotificationTray
|
||||
context.getString(R.string.snooze),
|
||||
pendingIntents.snoozeNotification(habit))
|
||||
|
||||
val removeRepetitionAction = Action(
|
||||
R.drawable.ic_action_cancel,
|
||||
context.getString(R.string.no),
|
||||
pendingIntents.removeRepetition(habit)
|
||||
)
|
||||
|
||||
val wearableBg = decodeResource(context.resources, R.drawable.stripe)
|
||||
|
||||
// Even though the set of actions is the same on the phone and
|
||||
@@ -69,7 +89,8 @@ class AndroidNotificationTray
|
||||
// WearableExtender.
|
||||
val wearableExtender = WearableExtender()
|
||||
.setBackground(wearableBg)
|
||||
.addAction(checkAction)
|
||||
.addAction(addRepetitionAction)
|
||||
.addAction(removeRepetitionAction)
|
||||
.addAction(snoozeAction)
|
||||
|
||||
val builder = NotificationCompat.Builder(context)
|
||||
@@ -78,20 +99,32 @@ class AndroidNotificationTray
|
||||
.setContentText(habit.description)
|
||||
.setContentIntent(pendingIntents.showHabit(habit))
|
||||
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
||||
.addAction(checkAction)
|
||||
.addAction(addRepetitionAction)
|
||||
.addAction(removeRepetitionAction)
|
||||
.addAction(snoozeAction)
|
||||
.setSound(ringtoneManager.getURI())
|
||||
.extend(wearableExtender)
|
||||
.setWhen(reminderTime)
|
||||
.setShowWhen(true)
|
||||
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
||||
.setGroup("default")
|
||||
|
||||
if (preferences.shouldMakeNotificationsLed())
|
||||
builder.setLights(Color.RED, 1000, 1000)
|
||||
|
||||
val notificationManager = context.getSystemService(
|
||||
Activity.NOTIFICATION_SERVICE) as NotificationManager
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
notificationManager.notify(notificationId, builder.build())
|
||||
@NonNull
|
||||
private fun buildSummary(@NonNull reminderTime: Long) : Notification
|
||||
{
|
||||
return NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getString(R.string.app_name))
|
||||
.setWhen(reminderTime)
|
||||
.setShowWhen(true)
|
||||
.setGroup("default")
|
||||
.setGroupSummary(true)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 266 B |
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 B |
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 323 B |
Binary file not shown.
|
After Width: | Height: | Size: 531 B |
@@ -220,4 +220,6 @@
|
||||
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
||||
<string name="question">Question</string>
|
||||
<string name="target">Target</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user