mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-03 12:07:44 +01:00
avoid creating unnecessary background threads
This commit is contained in:
parent
1276b0e622
commit
231fa7f3e7
@ -98,18 +98,18 @@ class EventActivity : SimpleActivity() {
|
||||
(mAttendeePlaceholder as LayerDrawable).findDrawableByLayerId(R.id.attendee_circular_background).applyColorFilter(config.primaryColor)
|
||||
|
||||
val eventId = intent.getLongExtra(EVENT_ID, 0L)
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val event = eventsDB.getEventWithId(eventId)
|
||||
if (eventId != 0L && event == null) {
|
||||
finish()
|
||||
return@Thread
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
val localEventType = eventTypesDB.getEventTypeWithId(config.lastUsedLocalEventTypeId)
|
||||
runOnUiThread {
|
||||
gotEvent(savedInstanceState, localEventType, event)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotEvent(savedInstanceState: Bundle?, localEventType: EventType?, event: Event?) {
|
||||
@ -377,12 +377,12 @@ class EventActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun checkAttendees() {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
fillAvailableContacts()
|
||||
runOnUiThread {
|
||||
updateAttendees()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleNotificationAvailability(callback: () -> Unit) {
|
||||
@ -716,7 +716,7 @@ class EventActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun updateEventType() {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventType = eventTypesDB.getEventTypeWithId(mEventTypeId)
|
||||
if (eventType != null) {
|
||||
runOnUiThread {
|
||||
@ -724,7 +724,7 @@ class EventActivity : SimpleActivity() {
|
||||
event_type_color.setFillWithStroke(eventType.color, config.backgroundColor)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCalDAVCalendar() {
|
||||
@ -783,7 +783,7 @@ class EventActivity : SimpleActivity() {
|
||||
} else {
|
||||
event_caldav_calendar_email.text = currentCalendar.accountName
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val calendarColor = eventsHelper.getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color
|
||||
?: currentCalendar.color
|
||||
|
||||
@ -798,7 +798,7 @@ class EventActivity : SimpleActivity() {
|
||||
setPadding(paddingLeft, 0, paddingRight, 0)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -826,7 +826,7 @@ class EventActivity : SimpleActivity() {
|
||||
|
||||
private fun deleteEvent() {
|
||||
DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
when (it) {
|
||||
DELETE_SELECTED_OCCURRENCE -> eventsHelper.addEventRepetitionException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
DELETE_FUTURE_OCCURRENCES -> eventsHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
|
||||
@ -835,7 +835,7 @@ class EventActivity : SimpleActivity() {
|
||||
runOnUiThread {
|
||||
finish()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -851,9 +851,9 @@ class EventActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun saveCurrentEvent() {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
saveEvent()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveEvent() {
|
||||
@ -982,13 +982,13 @@ class EventActivity : SimpleActivity() {
|
||||
private fun showEditRepeatingEventDialog() {
|
||||
EditRepeatingEventDialog(this) {
|
||||
if (it) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
eventsHelper.updateEvent(mEvent, true, true) {
|
||||
finish()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
} else {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
eventsHelper.addEventRepetitionException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
mEvent.apply {
|
||||
parentId = id!!.toLong()
|
||||
@ -1001,7 +1001,7 @@ class EventActivity : SimpleActivity() {
|
||||
eventsHelper.insertEvent(mEvent, true, true) {
|
||||
finish()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
val uri = intent.data
|
||||
if (uri.authority == "com.android.calendar") {
|
||||
if (uri.path.startsWith("/events")) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
// intents like content://com.android.calendar/events/1756
|
||||
val eventId = uri.lastPathSegment
|
||||
val id = eventsDB.getEventIdWithLastImportId("%-$eventId")
|
||||
@ -362,7 +362,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
} else if (intent?.extras?.getBoolean("DETAIL_VIEW", false) == true) {
|
||||
// clicking date on a third party widget: content://com.android.calendar/time/1507309245683
|
||||
val timestamp = uri.pathSegments.last()
|
||||
@ -449,7 +449,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
val items = getHolidayRadioItems()
|
||||
RadioGroupDialog(this, items) {
|
||||
toast(R.string.importing)
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val holidays = getString(R.string.holidays)
|
||||
var eventTypeId = eventsHelper.getEventTypeIdWithTitle(holidays)
|
||||
if (eventTypeId == -1L) {
|
||||
@ -464,7 +464,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
updateViewPager()
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -473,7 +473,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
if (it) {
|
||||
SetRemindersDialog(this) {
|
||||
val reminders = it
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
addContactEvents(true, reminders) {
|
||||
if (it > 0) {
|
||||
toast(R.string.birthdays_added)
|
||||
@ -482,7 +482,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
toast(R.string.no_birthdays)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(R.string.no_contacts_permission)
|
||||
@ -495,7 +495,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
if (it) {
|
||||
SetRemindersDialog(this) {
|
||||
val reminders = it
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
addContactEvents(false, reminders) {
|
||||
if (it > 0) {
|
||||
toast(R.string.anniversaries_added)
|
||||
@ -504,7 +504,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
toast(R.string.no_anniversaries)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(R.string.no_contacts_permission)
|
||||
@ -755,7 +755,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
private fun exportEvents() {
|
||||
FilePickerDialog(this, pickFile = false, showFAB = true) {
|
||||
ExportEventsDialog(this, it) { exportPastEvents, file, eventTypes ->
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val events = eventsHelper.getEventsToExport(exportPastEvents, eventTypes)
|
||||
if (events.isEmpty()) {
|
||||
toast(R.string.no_entries_for_exporting)
|
||||
@ -768,7 +768,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
})
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.simplemobiletools.calendar.pro.interfaces.DeleteEventTypesListener
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import kotlinx.android.synthetic.main.activity_manage_event_types.*
|
||||
import java.util.*
|
||||
|
||||
@ -59,9 +60,9 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
||||
}
|
||||
}
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
eventsHelper.deleteEventTypes(eventTypes, deleteEvents)
|
||||
}.start()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -102,14 +102,14 @@ class SettingsActivity : SimpleActivity() {
|
||||
|
||||
private fun checkPrimaryColor() {
|
||||
if (config.primaryColor != mStoredPrimaryColor) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventTypes = eventsHelper.getEventTypesSync()
|
||||
if (eventTypes.filter { it.caldavCalendarId == 0 }.size == 1) {
|
||||
val eventType = eventTypes.first { it.caldavCalendarId == 0 }
|
||||
eventType.color = config.primaryColor
|
||||
eventsHelper.insertOrUpdateEventTypeSync(eventType)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,13 +195,13 @@ class SettingsActivity : SimpleActivity() {
|
||||
settings_manage_synced_calendars_holder.beGone()
|
||||
settings_caldav_pull_to_refresh_holder.beGone()
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
config.getSyncedCalendarIdsAsList().forEach {
|
||||
calDAVHelper.deleteCalDAVCalendarEvents(it.toLong())
|
||||
}
|
||||
eventTypesDB.deleteEventTypesWithCalendarId(config.getSyncedCalendarIdsAsList())
|
||||
updateDefaultEventTypeText()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
toast(R.string.syncing)
|
||||
}
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
if (newCalendarIds.isNotEmpty()) {
|
||||
val existingEventTypeNames = eventsHelper.getEventTypesSync().map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
||||
getSyncedCalDAVCalendars().forEach {
|
||||
@ -253,7 +253,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
|
||||
eventTypesDB.deleteEventTypesWithCalendarId(removedCalendarIds)
|
||||
updateDefaultEventTypeText()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -630,7 +630,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
settings_default_event_type.text = getString(R.string.last_used_one)
|
||||
}
|
||||
} else {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventType = eventTypesDB.getEventTypeWithId(config.defaultEventTypeId)
|
||||
if (eventType != null) {
|
||||
config.lastUsedCaldavCalendarId = eventType.caldavCalendarId
|
||||
@ -641,7 +641,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
config.defaultEventTypeId = -1
|
||||
updateDefaultEventTypeText()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -694,13 +694,13 @@ class SettingsActivity : SimpleActivity() {
|
||||
handlePermission(PERMISSION_READ_STORAGE) {
|
||||
if (it) {
|
||||
FilePickerDialog(this) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
try {
|
||||
parseFile(it)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.refreshCalDAVCalendars
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
open class SimpleActivity : BaseSimpleActivity() {
|
||||
val CALDAV_REFRESH_DELAY = 3000L
|
||||
@ -40,12 +41,12 @@ open class SimpleActivity : BaseSimpleActivity() {
|
||||
|
||||
fun Context.syncCalDAVCalendars(callback: () -> Unit) {
|
||||
calDAVRefreshCallback = callback
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val uri = CalendarContract.Calendars.CONTENT_URI
|
||||
contentResolver.unregisterContentObserver(calDAVSyncObserver)
|
||||
contentResolver.registerContentObserver(uri, false, calDAVSyncObserver)
|
||||
refreshCalDAVCalendars(config.caldavSyncedCalendarIds, true)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
// caldav refresh content observer triggers multiple times in a row at updating, so call the callback only a few seconds after the (hopefully) last one
|
||||
@ -55,11 +56,11 @@ open class SimpleActivity : BaseSimpleActivity() {
|
||||
if (!selfChange) {
|
||||
calDAVRefreshHandler.removeCallbacksAndMessages(null)
|
||||
calDAVRefreshHandler.postDelayed({
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
unregisterObserver()
|
||||
calDAVRefreshCallback?.invoke()
|
||||
calDAVRefreshCallback = null
|
||||
}.start()
|
||||
}
|
||||
}, CALDAV_REFRESH_DELAY)
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,14 @@ import com.simplemobiletools.calendar.pro.extensions.eventsDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.rescheduleReminder
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||
import com.simplemobiletools.commons.extensions.showPickSecondsDialogHelper
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
class SnoozeReminderActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
showPickSecondsDialogHelper(config.snoozeTime, true, cancelCallback = { dialogCancelled() }) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventId = intent.getLongExtra(EVENT_ID, 0L)
|
||||
val event = eventsDB.getEventWithId(eventId)
|
||||
config.snoozeTime = it / 60
|
||||
@ -21,7 +22,7 @@ class SnoozeReminderActivity : AppCompatActivity() {
|
||||
runOnUiThread {
|
||||
finishActivity()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beInvisible
|
||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import kotlinx.android.synthetic.main.event_item_day_view.view.*
|
||||
|
||||
@ -142,7 +143,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
|
||||
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) { it ->
|
||||
events.removeAll(eventsToDelete)
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.mapNotNull { it.id }.toMutableList()
|
||||
activity.eventsHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||
|
||||
@ -151,7 +152,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
|
||||
activity.runOnUiThread {
|
||||
removeSelectedItems(positions)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beInvisible
|
||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import kotlinx.android.synthetic.main.event_list_item.view.*
|
||||
@ -208,7 +209,7 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
|
||||
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) {
|
||||
listItems.removeAll(eventsToDelete)
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val nonRepeatingEventIDs = eventsToDelete.filter { !it.isRepeatable }.mapNotNull { it.id }.toMutableList()
|
||||
activity.eventsHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||
|
||||
@ -218,7 +219,7 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
|
||||
listener?.refreshItems()
|
||||
finishActMode()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import kotlinx.android.synthetic.main.dialog_event_type.view.*
|
||||
|
||||
class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = null, val callback: (eventType: EventType) -> Unit) {
|
||||
@ -45,9 +46,9 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
||||
activity.setupDialogStuff(view, this, if (isNewEvent) R.string.add_new_type else R.string.edit_type) {
|
||||
showKeyboard(view.type_title)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
eventTypeConfirmed(view.type_title.value, this)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
|
||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import kotlinx.android.synthetic.main.dialog_import_events.view.*
|
||||
|
||||
class ImportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (refreshView: Boolean) -> Unit) {
|
||||
@ -21,7 +22,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
val config = activity.config
|
||||
|
||||
init {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
if (activity.eventTypesDB.getEventTypeWithId(config.lastUsedLocalEventTypeId) == null) {
|
||||
config.lastUsedLocalEventTypeId = REGULAR_EVENT_TYPE_ID
|
||||
}
|
||||
@ -42,7 +43,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
activity.runOnUiThread {
|
||||
initDialog()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initDialog() {
|
||||
@ -69,25 +70,25 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(null)
|
||||
activity.toast(R.string.importing)
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val overrideFileEventTypes = view.import_events_checkbox.isChecked
|
||||
val result = IcsImporter(activity).importEvents(path, currEventTypeId, currEventTypeCalDAVCalendarId, overrideFileEventTypes)
|
||||
handleParseResult(result)
|
||||
dismiss()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateEventType(view: ViewGroup) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventType = activity.eventTypesDB.getEventTypeWithId(currEventTypeId)
|
||||
activity.runOnUiThread {
|
||||
view.import_event_type_title.text = eventType!!.getDisplayTitle()
|
||||
view.import_event_type_color.setFillWithStroke(eventType.color, activity.config.backgroundColor)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleParseResult(result: IcsImporter.ImportResult) {
|
||||
|
@ -14,6 +14,7 @@ import com.simplemobiletools.calendar.pro.models.CalDAVCalendar
|
||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import kotlinx.android.synthetic.main.dialog_select_radio_group.view.*
|
||||
import kotlinx.android.synthetic.main.radio_button_with_color.view.*
|
||||
|
||||
@ -26,7 +27,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
|
||||
radioGroup = view.dialog_radio_group
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
calendars.forEach {
|
||||
val localEventType = activity.eventsHelper.getEventTypeWithCalDAVCalendarId(it.id)
|
||||
if (localEventType != null) {
|
||||
@ -42,7 +43,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
||||
wasInit = true
|
||||
activity.updateTextColors(view.dialog_radio_holder)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.create().apply {
|
||||
|
@ -11,17 +11,18 @@ import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.sharePathIntent
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import java.io.File
|
||||
import java.util.TreeSet
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
fun BaseSimpleActivity.shareEvents(ids: List<Long>) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val file = getTempFile()
|
||||
if (file == null) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return@Thread
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
val events = eventsDB.getEventsWithIds(ids) as ArrayList<Event>
|
||||
@ -30,7 +31,7 @@ fun BaseSimpleActivity.shareEvents(ids: List<Long>) {
|
||||
sharePathIntent(file.absolutePath, BuildConfig.APPLICATION_ID)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.getTempFile(): File? {
|
||||
|
@ -33,10 +33,7 @@ import com.simplemobiletools.calendar.pro.receivers.CalDAVSyncReceiver
|
||||
import com.simplemobiletools.calendar.pro.receivers.NotificationReceiver
|
||||
import com.simplemobiletools.calendar.pro.services.SnoozeService
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.SILENT
|
||||
import com.simplemobiletools.commons.helpers.WEEK_SECONDS
|
||||
import com.simplemobiletools.commons.helpers.YEAR_SECONDS
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeZone
|
||||
import org.joda.time.LocalDate
|
||||
@ -334,10 +331,10 @@ fun Context.getSyncedCalDAVCalendars() = calDAVHelper.getCalDAVCalendars(config.
|
||||
|
||||
fun Context.recheckCalDAVCalendars(callback: () -> Unit) {
|
||||
if (config.caldavSync) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
calDAVHelper.refreshCalendars(false, callback)
|
||||
updateWidgets()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
class EventsHelper(val context: Context) {
|
||||
private val config = context.config
|
||||
@ -14,7 +15,7 @@ class EventsHelper(val context: Context) {
|
||||
private val eventTypesDB = context.eventTypesDB
|
||||
|
||||
fun getEventTypes(activity: Activity, showWritableOnly: Boolean, callback: (notes: ArrayList<EventType>) -> Unit) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
var eventTypes = ArrayList<EventType>()
|
||||
try {
|
||||
eventTypes = eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
||||
@ -32,18 +33,18 @@ class EventsHelper(val context: Context) {
|
||||
activity.runOnUiThread {
|
||||
callback(eventTypes)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun getEventTypesSync() = eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
||||
|
||||
fun insertOrUpdateEventType(activity: Activity, eventType: EventType, callback: ((newEventTypeId: Long) -> Unit)? = null) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventTypeId = insertOrUpdateEventTypeSync(eventType)
|
||||
activity.runOnUiThread {
|
||||
callback?.invoke(eventTypeId)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun insertOrUpdateEventTypeSync(eventType: EventType): Long {
|
||||
@ -132,10 +133,10 @@ class EventsHelper(val context: Context) {
|
||||
}
|
||||
|
||||
fun deleteAllEvents() {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventIds = eventsDB.getEventIds().toMutableList()
|
||||
deleteEvents(eventIds, true)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteEvent(id: Long, deleteFromCalDAV: Boolean) = deleteEvents(arrayListOf(id), deleteFromCalDAV)
|
||||
@ -189,14 +190,14 @@ class EventsHelper(val context: Context) {
|
||||
}
|
||||
|
||||
fun doEventTypesContainEvents(eventTypeIds: ArrayList<Long>, callback: (contain: Boolean) -> Unit) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val eventIds = eventsDB.getEventIdsByEventType(eventTypeIds)
|
||||
callback(eventIds.isNotEmpty())
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun getEventsWithSearchQuery(text: String, activity: Activity, callback: (searchedText: String, events: List<Event>) -> Unit) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
val searchQuery = "%$text%"
|
||||
val events = eventsDB.getEventsForSearch(searchQuery)
|
||||
val displayEventTypes = config.displayEventTypes
|
||||
@ -204,12 +205,12 @@ class EventsHelper(val context: Context) {
|
||||
activity.runOnUiThread {
|
||||
callback(text, filteredEvents)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun addEventRepetitionException(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean) {
|
||||
Thread {
|
||||
val parentEvent = eventsDB.getEventWithId(parentEventId) ?: return@Thread
|
||||
ensureBackgroundThread {
|
||||
val parentEvent = eventsDB.getEventWithId(parentEventId) ?: return@ensureBackgroundThread
|
||||
var repetitionExceptions = parentEvent.repetitionExceptions
|
||||
repetitionExceptions.add(Formatter.getDayCodeFromTS(occurrenceTS))
|
||||
repetitionExceptions = repetitionExceptions.distinct().toMutableList() as ArrayList<String>
|
||||
@ -219,13 +220,13 @@ class EventsHelper(val context: Context) {
|
||||
if (addToCalDAV && config.caldavSync) {
|
||||
context.calDAVHelper.insertEventRepeatException(parentEvent, occurrenceTS)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun getEvents(fromTS: Long, toTS: Long, eventId: Long = -1L, applyTypeFilter: Boolean = true, callback: (events: ArrayList<Event>) -> Unit) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
getEventsSync(fromTS, toTS, eventId, applyTypeFilter, callback)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun getEventsSync(fromTS: Long, toTS: Long, eventId: Long = -1L, applyTypeFilter: Boolean, callback: (events: ArrayList<Event>) -> Unit) {
|
||||
|
@ -10,6 +10,7 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.writeLn
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
@ -31,7 +32,7 @@ class IcsExporter {
|
||||
return@getFileOutputStream
|
||||
}
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
calendars = activity.calDAVHelper.getCalDAVCalendars("", false)
|
||||
if (showExportingToast) {
|
||||
activity.toast(R.string.exporting)
|
||||
@ -76,7 +77,7 @@ class IcsExporter {
|
||||
eventsFailed > 0 -> EXPORT_PARTIAL
|
||||
else -> EXPORT_OK
|
||||
})
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +90,7 @@ class IcsExporter {
|
||||
writeLn("$ACTION$DISPLAY")
|
||||
} else {
|
||||
writeLn("$ACTION$EMAIL")
|
||||
val attendee = calendars.firstOrNull { it.id == event.getCalDAVCalendarId()}?.accountName
|
||||
val attendee = calendars.firstOrNull { it.id == event.getCalDAVCalendarId() }?.accountName
|
||||
if (attendee != null) {
|
||||
writeLn("$ATTENDEE$MAILTO$attendee")
|
||||
}
|
||||
|
@ -6,16 +6,17 @@ import android.content.Intent
|
||||
import com.simplemobiletools.calendar.pro.extensions.notifyRunningEvents
|
||||
import com.simplemobiletools.calendar.pro.extensions.recheckCalDAVCalendars
|
||||
import com.simplemobiletools.calendar.pro.extensions.scheduleAllEvents
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
class BootCompletedReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
context.apply {
|
||||
scheduleAllEvents()
|
||||
notifyRunningEvents()
|
||||
recheckCalDAVCalendars {}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.simplemobiletools.calendar.pro.extensions.updateListWidget
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.helpers.REMINDER_NOTIFICATION
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
class NotificationReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
@ -18,9 +19,9 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
val wakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "simplecalendar:notificationreceiver")
|
||||
wakelock.acquire(3000)
|
||||
|
||||
Thread {
|
||||
ensureBackgroundThread {
|
||||
handleIntent(context, intent)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleIntent(context: Context, intent: Intent) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user