Make notification immutable

pull/2906/head
Alex Baker 2 years ago
parent 74fca07c1b
commit a49c233584

@ -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
@ -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) }

@ -1,65 +0,0 @@
package org.tasks.jobs;
import static org.tasks.time.DateTimeUtils2.currentTimeMillis;
import static org.tasks.time.DateTimeUtilsKt.printTimestamp;
import org.tasks.data.entity.Notification;
import java.util.Objects;
public class AlarmEntry {
private final long alarmId;
private final long taskId;
private final long time;
private final int type;
public AlarmEntry(long alarmId, long taskId, Long time, int type) {
this.alarmId = alarmId;
this.taskId = taskId;
this.time = time;
this.type = type;
}
public long getId() {
return alarmId;
}
public long getTime() {
return time;
}
public long getTaskId() {
return taskId;
}
public int getType() {
return type;
}
public Notification toNotification() {
Notification notification = new Notification();
notification.setTaskId(taskId);
notification.setType(type);
notification.setTimestamp(currentTimeMillis());
return notification;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AlarmEntry that = (AlarmEntry) o;
return alarmId == that.alarmId && taskId == that.taskId && time == that.time && type == that.type;
}
@Override
public int hashCode() {
return Objects.hash(alarmId, taskId, time, type);
}
@Override
public String toString() {
return "AlarmEntry{alarmId=" + alarmId + ", taskId=" + taskId + ", time=" + printTimestamp(time) + ", type=" + type + '}';
}
}

@ -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)"
}
}

@ -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"

Loading…
Cancel
Save