Add import IDs to existing tasks on start
This commit is contained in:
parent
908241cb63
commit
f2ef7d79e2
|
@ -1115,7 +1115,7 @@ class EventActivity : SimpleActivity() {
|
|||
val newImportId = if (mEvent.id != null) {
|
||||
mEvent.importId
|
||||
} else {
|
||||
UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
|
||||
generateImportId()
|
||||
}
|
||||
|
||||
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
||||
|
|
|
@ -159,6 +159,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
ConfirmationDialog(this, "", R.string.upgraded_to_pro_calendar, R.string.ok, 0, false) {}
|
||||
config.wasUpgradedFromFreeShown = true
|
||||
}
|
||||
|
||||
addImportIdsToTasks {
|
||||
refreshViewPager()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
|
@ -354,7 +354,7 @@ class TaskActivity : SimpleActivity() {
|
|||
val newImportId = if (mTask.id != null) {
|
||||
mTask.importId
|
||||
} else {
|
||||
UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
|
||||
generateImportId()
|
||||
}
|
||||
|
||||
val reminders = getReminders()
|
||||
|
|
|
@ -708,3 +708,24 @@ inline fun Context.queryCursorInlined(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.addImportIdsToTasks(callback: () -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
var count = 0
|
||||
|
||||
eventsDB.getAllTasks()
|
||||
.forEach { task ->
|
||||
if (task.importId.isEmpty()) {
|
||||
eventsDB.updateTaskImportId(
|
||||
importId = generateImportId(),
|
||||
id = task.id!!
|
||||
)
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.calendar.pro.helpers
|
|||
import com.simplemobiletools.calendar.pro.activities.EventActivity
|
||||
import com.simplemobiletools.calendar.pro.activities.TaskActivity
|
||||
import com.simplemobiletools.commons.helpers.MONTH_SECONDS
|
||||
import java.util.*
|
||||
|
||||
const val STORED_LOCALLY_ONLY = 0
|
||||
const val ROW_COUNT = 6
|
||||
|
@ -258,3 +259,7 @@ fun getActivityToOpen(isTask: Boolean) = if (isTask) {
|
|||
} else {
|
||||
EventActivity::class.java
|
||||
}
|
||||
|
||||
fun generateImportId(): String {
|
||||
return UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ interface EventsDao {
|
|||
@Query("SELECT * FROM events")
|
||||
fun getAllEvents(): List<Event>
|
||||
|
||||
@Query("SELECT * FROM events WHERE type = $TYPE_TASK")
|
||||
fun getAllTasks(): List<Event>
|
||||
|
||||
@Query("SELECT * FROM events WHERE event_type IN (:eventTypeIds) AND type = $TYPE_EVENT")
|
||||
fun getAllEventsWithTypes(eventTypeIds: List<Long>): List<Event>
|
||||
|
||||
|
@ -122,6 +125,9 @@ interface EventsDao {
|
|||
@Query("UPDATE events SET flags = :newFlags WHERE id = :id")
|
||||
fun updateTaskCompletion(id: Long, newFlags: Int)
|
||||
|
||||
@Query("UPDATE events SET import_id = :importId WHERE id = :id AND type = $TYPE_TASK")
|
||||
fun updateTaskImportId(importId: String, id: Long)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertOrUpdate(event: Event): Long
|
||||
|
||||
|
|
Loading…
Reference in New Issue