Skip to content

Commit

Permalink
Make notification immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
abaker committed May 18, 2024
1 parent 74fca07 commit a49c233
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 77 deletions.
14 changes: 7 additions & 7 deletions app/src/main/java/org/tasks/Notifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.voice.VoiceOutputAssistant
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.delay
import org.tasks.data.dao.TaskDao
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_GEO_ENTER
import org.tasks.data.entity.Alarm.Companion.TYPE_GEO_EXIT
import org.tasks.data.entity.Geofence
import org.tasks.data.entity.Notification
import org.tasks.data.dao.TaskDao
import org.tasks.data.fetchFiltered
import org.tasks.intents.TaskIntents
import org.tasks.notifications.AudioManager
Expand Down Expand Up @@ -77,12 +77,12 @@ class Notifier @Inject constructor(
geofences
.filter { if (arrival) it.isArrival else it.isDeparture }
.map {
Notification().apply {
taskId = it.task
type = if (arrival) TYPE_GEO_ENTER else TYPE_GEO_EXIT
timestamp = currentTimeMillis()
location = place
}
Notification(
taskId = it.task,
type = if (arrival) TYPE_GEO_ENTER else TYPE_GEO_EXIT,
timestamp = currentTimeMillis(),
location = place,
)
}
.let { triggerNotifications(it) }

Expand Down
65 changes: 0 additions & 65 deletions app/src/main/java/org/tasks/jobs/AlarmEntry.java

This file was deleted.

22 changes: 22 additions & 0 deletions app/src/main/java/org/tasks/jobs/AlarmEntry.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.tasks.jobs

import org.tasks.data.entity.Notification
import org.tasks.time.DateTimeUtils2.currentTimeMillis
import org.tasks.time.printTimestamp

data class AlarmEntry(
val id: Long,
val taskId: Long,
val time: Long,
val type: Int
) {
fun toNotification(): Notification = Notification(
taskId = taskId,
type = type,
timestamp = currentTimeMillis(),
)

override fun toString(): String {
return "AlarmEntry(id=$id, taskId=$taskId, time=${printTimestamp(time)}, type=$type)"
}
}
10 changes: 5 additions & 5 deletions data/src/main/kotlin/org/tasks/data/entity/Notification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import org.tasks.data.db.Table
data class Notification(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "uid")
var uid: Long = 0,
val uid: Long = 0,
@ColumnInfo(name = "task")
var taskId: Long = 0,
val taskId: Long = 0,
@ColumnInfo(name = "timestamp")
var timestamp: Long = 0,
val timestamp: Long = 0,
@ColumnInfo(name = "type")
var type: Int = 0,
val type: Int = 0,
@ColumnInfo(name = "location")
var location: Long? = null,
val location: Long? = null,
) {
companion object {
const val TABLE_NAME = "notification"
Expand Down

0 comments on commit a49c233

Please sign in to comment.