lets actually handle tasks as special events
This commit is contained in:
parent
f3b6eccfe3
commit
1f4bb65e6e
|
@ -11,7 +11,7 @@ import com.simplemobiletools.calendar.pro.extensions.config
|
||||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.pro.helpers.*
|
import com.simplemobiletools.calendar.pro.helpers.*
|
||||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||||
import com.simplemobiletools.calendar.pro.models.Task
|
import com.simplemobiletools.calendar.pro.models.Event
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import kotlinx.android.synthetic.main.activity_task.*
|
import kotlinx.android.synthetic.main.activity_task.*
|
||||||
|
@ -21,7 +21,7 @@ import java.util.*
|
||||||
class TaskActivity : SimpleActivity() {
|
class TaskActivity : SimpleActivity() {
|
||||||
private var mDialogTheme = 0
|
private var mDialogTheme = 0
|
||||||
private lateinit var mTaskDateTime: DateTime
|
private lateinit var mTaskDateTime: DateTime
|
||||||
private lateinit var mTask: Task
|
private lateinit var mTask: Event
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -59,11 +59,11 @@ class TaskActivity : SimpleActivity() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotTask(task: Task?) {
|
private fun gotTask(task: Event?) {
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
mTask = task
|
mTask = task
|
||||||
} else {
|
} else {
|
||||||
mTask = Task(null)
|
mTask = Event(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
task_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) }
|
task_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) }
|
||||||
|
@ -108,7 +108,7 @@ class TaskActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
TasksHelper(this).insertTask(mTask) {
|
EventsHelper(this).insertTask(mTask) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,13 @@ import com.simplemobiletools.calendar.pro.helpers.Converters
|
||||||
import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
|
import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
|
||||||
import com.simplemobiletools.calendar.pro.interfaces.EventTypesDao
|
import com.simplemobiletools.calendar.pro.interfaces.EventTypesDao
|
||||||
import com.simplemobiletools.calendar.pro.interfaces.EventsDao
|
import com.simplemobiletools.calendar.pro.interfaces.EventsDao
|
||||||
import com.simplemobiletools.calendar.pro.interfaces.TasksDao
|
|
||||||
import com.simplemobiletools.calendar.pro.interfaces.WidgetsDao
|
import com.simplemobiletools.calendar.pro.interfaces.WidgetsDao
|
||||||
import com.simplemobiletools.calendar.pro.models.Event
|
import com.simplemobiletools.calendar.pro.models.Event
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.models.EventType
|
||||||
import com.simplemobiletools.calendar.pro.models.Task
|
|
||||||
import com.simplemobiletools.calendar.pro.models.Widget
|
import com.simplemobiletools.calendar.pro.models.Widget
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
@Database(entities = [Event::class, EventType::class, Widget::class, Task::class], version = 6)
|
@Database(entities = [Event::class, EventType::class, Widget::class], version = 6)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class EventsDatabase : RoomDatabase() {
|
abstract class EventsDatabase : RoomDatabase() {
|
||||||
|
|
||||||
|
@ -31,8 +29,6 @@ abstract class EventsDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun WidgetsDao(): WidgetsDao
|
abstract fun WidgetsDao(): WidgetsDao
|
||||||
|
|
||||||
abstract fun TasksDao(): TasksDao
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var db: EventsDatabase? = null
|
private var db: EventsDatabase? = null
|
||||||
|
|
||||||
|
@ -112,8 +108,7 @@ abstract class EventsDatabase : RoomDatabase() {
|
||||||
private val MIGRATION_5_6 = object : Migration(5, 6) {
|
private val MIGRATION_5_6 = object : Migration(5, 6) {
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
database.apply {
|
database.apply {
|
||||||
execSQL("CREATE TABLE IF NOT EXISTS `tasks` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `start_ts` INTEGER NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, `reminder_1_minutes` INTEGER NOT NULL, `reminder_2_minutes` INTEGER NOT NULL, `reminder_3_minutes` INTEGER NOT NULL, `repeat_interval` INTEGER NOT NULL, `repeat_rule` INTEGER NOT NULL, `repeat_limit` INTEGER NOT NULL, `repetition_exceptions` TEXT NOT NULL, `import_id` TEXT NOT NULL, `time_zone` TEXT NOT NULL, `flags` INTEGER NOT NULL, `event_type` INTEGER NOT NULL, `last_updated` INTEGER NOT NULL, `source` TEXT NOT NULL, `color` INTEGER NOT NULL)")
|
execSQL("ALTER TABLE events ADD COLUMN type INTEGER NOT NULL DEFAULT 0")
|
||||||
execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_tasks_id` ON `tasks` (`id`)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ const val ITEM_SECTION_MONTH = 2
|
||||||
const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1
|
const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1
|
||||||
const val DEFAULT_START_TIME_CURRENT_TIME = -2
|
const val DEFAULT_START_TIME_CURRENT_TIME = -2
|
||||||
|
|
||||||
|
const val TYPE_EVENT = 0
|
||||||
|
const val TYPE_TASK = 1
|
||||||
|
|
||||||
const val DAY = 86400
|
const val DAY = 86400
|
||||||
const val WEEK = 604800
|
const val WEEK = 604800
|
||||||
const val MONTH = 2592001 // exact value not taken into account, Joda is used for adding months and years
|
const val MONTH = 2592001 // exact value not taken into account, Joda is used for adding months and years
|
||||||
|
|
|
@ -120,6 +120,12 @@ class EventsHelper(val context: Context) {
|
||||||
callback?.invoke(event.id!!)
|
callback?.invoke(event.id!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun insertTask(task: Event, callback: () -> Unit) {
|
||||||
|
eventsDB.insertOrUpdate(task)
|
||||||
|
context.updateWidgets()
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
|
||||||
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
|
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
|
||||||
try {
|
try {
|
||||||
for (event in events) {
|
for (event in events) {
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package com.simplemobiletools.calendar.pro.helpers
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
|
||||||
import com.simplemobiletools.calendar.pro.extensions.eventTypesDB
|
|
||||||
import com.simplemobiletools.calendar.pro.extensions.tasksDB
|
|
||||||
import com.simplemobiletools.calendar.pro.extensions.updateWidgets
|
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
|
||||||
import com.simplemobiletools.calendar.pro.models.Task
|
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|
||||||
|
|
||||||
class TasksHelper(val context: Context) {
|
|
||||||
private val tasksDB = context.tasksDB
|
|
||||||
private val eventTypesDB = context.eventTypesDB
|
|
||||||
|
|
||||||
fun getEventTypes(activity: Activity, callback: (notes: ArrayList<EventType>) -> Unit) {
|
|
||||||
ensureBackgroundThread {
|
|
||||||
var eventTypes = ArrayList<EventType>()
|
|
||||||
try {
|
|
||||||
eventTypes = eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
activity.runOnUiThread {
|
|
||||||
callback(eventTypes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun insertTask(task: Task, callback: () -> Unit) {
|
|
||||||
tasksDB.insertOrUpdate(task)
|
|
||||||
context.updateWidgets()
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.simplemobiletools.calendar.pro.interfaces
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.simplemobiletools.calendar.pro.models.Task
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface TasksDao {
|
|
||||||
@Query("SELECT * FROM tasks")
|
|
||||||
fun getAllTasks(): List<Task>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
fun insertOrUpdate(task: Task): Long
|
|
||||||
}
|
|
|
@ -39,7 +39,8 @@ data class Event(
|
||||||
@ColumnInfo(name = "last_updated") var lastUpdated: Long = 0L,
|
@ColumnInfo(name = "last_updated") var lastUpdated: Long = 0L,
|
||||||
@ColumnInfo(name = "source") var source: String = SOURCE_SIMPLE_CALENDAR,
|
@ColumnInfo(name = "source") var source: String = SOURCE_SIMPLE_CALENDAR,
|
||||||
@ColumnInfo(name = "availability") var availability: Int = 0,
|
@ColumnInfo(name = "availability") var availability: Int = 0,
|
||||||
@ColumnInfo(name = "color") var color: Int = 0
|
@ColumnInfo(name = "color") var color: Int = 0,
|
||||||
|
@ColumnInfo(name = "type") var type: Int = TYPE_EVENT
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -140,6 +141,7 @@ data class Event(
|
||||||
|
|
||||||
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
|
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
|
||||||
fun hasMissingYear() = flags and FLAG_MISSING_YEAR != 0
|
fun hasMissingYear() = flags and FLAG_MISSING_YEAR != 0
|
||||||
|
fun isTask() = type == TYPE_TASK
|
||||||
|
|
||||||
fun getReminders() = listOf(
|
fun getReminders() = listOf(
|
||||||
Reminder(reminder1Minutes, reminder1Type),
|
Reminder(reminder1Minutes, reminder1Type),
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
package com.simplemobiletools.calendar.pro.models
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.Index
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
|
||||||
import com.simplemobiletools.calendar.pro.helpers.*
|
|
||||||
import com.simplemobiletools.commons.extensions.addBitIf
|
|
||||||
import java.io.Serializable
|
|
||||||
|
|
||||||
@Entity(tableName = "tasks", indices = [(Index(value = ["id"], unique = true))])
|
|
||||||
data class Task(
|
|
||||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
|
||||||
@ColumnInfo(name = "start_ts") var startTS: Long = 0L,
|
|
||||||
@ColumnInfo(name = "title") var title: String = "",
|
|
||||||
@ColumnInfo(name = "description") var description: String = "",
|
|
||||||
@ColumnInfo(name = "reminder_1_minutes") var reminder1Minutes: Int = REMINDER_OFF,
|
|
||||||
@ColumnInfo(name = "reminder_2_minutes") var reminder2Minutes: Int = REMINDER_OFF,
|
|
||||||
@ColumnInfo(name = "reminder_3_minutes") var reminder3Minutes: Int = REMINDER_OFF,
|
|
||||||
@ColumnInfo(name = "repeat_interval") var repeatInterval: Int = 0,
|
|
||||||
@ColumnInfo(name = "repeat_rule") var repeatRule: Int = 0,
|
|
||||||
@ColumnInfo(name = "repeat_limit") var repeatLimit: Long = 0L,
|
|
||||||
@ColumnInfo(name = "repetition_exceptions") var repetitionExceptions: ArrayList<String> = ArrayList(),
|
|
||||||
@ColumnInfo(name = "import_id") var importId: String = "",
|
|
||||||
@ColumnInfo(name = "time_zone") var timeZone: String = "",
|
|
||||||
@ColumnInfo(name = "flags") var flags: Int = 0,
|
|
||||||
@ColumnInfo(name = "event_type") var eventType: Long = REGULAR_EVENT_TYPE_ID,
|
|
||||||
@ColumnInfo(name = "last_updated") var lastUpdated: Long = 0L,
|
|
||||||
@ColumnInfo(name = "source") var source: String = SOURCE_SIMPLE_CALENDAR,
|
|
||||||
@ColumnInfo(name = "color") var color: Int = 0
|
|
||||||
) : Serializable {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val serialVersionUID = -32456795132345616L
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
|
|
||||||
|
|
||||||
// properly return the start time of all-day tasks as midnight
|
|
||||||
fun getTaskStartTS(): Long {
|
|
||||||
return if (getIsAllDay()) {
|
|
||||||
Formatter.getDateTimeFromTS(startTS).withTime(0, 0, 0, 0).seconds()
|
|
||||||
} else {
|
|
||||||
startTS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isPastTask: Boolean
|
|
||||||
get() = flags and FLAG_IS_IN_PAST != 0
|
|
||||||
set(isPastTask) {
|
|
||||||
flags = flags.addBitIf(isPastTask, FLAG_IS_IN_PAST)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue