mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
moving some event type fetching functions into Room
This commit is contained in:
@ -111,7 +111,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
updateViewPager()
|
updateViewPager()
|
||||||
}
|
}
|
||||||
|
|
||||||
dbHelper.getEventTypes {
|
EventTypesHelper().getEventTypes(this) {
|
||||||
mShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty()
|
mShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import com.simplemobiletools.calendar.pro.R
|
|||||||
import com.simplemobiletools.calendar.pro.adapters.ManageEventTypesAdapter
|
import com.simplemobiletools.calendar.pro.adapters.ManageEventTypesAdapter
|
||||||
import com.simplemobiletools.calendar.pro.dialogs.EditEventTypeDialog
|
import com.simplemobiletools.calendar.pro.dialogs.EditEventTypeDialog
|
||||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||||
|
import com.simplemobiletools.calendar.pro.helpers.EventTypesHelper
|
||||||
import com.simplemobiletools.calendar.pro.interfaces.DeleteEventTypesListener
|
import com.simplemobiletools.calendar.pro.interfaces.DeleteEventTypesListener
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.models.EventType
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
@ -30,15 +31,13 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getEventTypes() {
|
private fun getEventTypes() {
|
||||||
dbHelper.getEventTypes {
|
EventTypesHelper().getEventTypes(this) {
|
||||||
runOnUiThread {
|
|
||||||
val adapter = ManageEventTypesAdapter(this, it, this, manage_event_types_list) {
|
val adapter = ManageEventTypesAdapter(this, it, this, manage_event_types_list) {
|
||||||
showEventTypeDialog(it as EventType)
|
showEventTypeDialog(it as EventType)
|
||||||
}
|
}
|
||||||
manage_event_types_list.adapter = adapter
|
manage_event_types_list.adapter = adapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu_event_types, menu)
|
menuInflater.inflate(R.menu.menu_event_types, menu)
|
||||||
|
@ -92,13 +92,14 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun checkPrimaryColor() {
|
private fun checkPrimaryColor() {
|
||||||
if (config.primaryColor != mStoredPrimaryColor) {
|
if (config.primaryColor != mStoredPrimaryColor) {
|
||||||
dbHelper.getEventTypes {
|
Thread {
|
||||||
if (it.filter { it.caldavCalendarId == 0 }.size == 1) {
|
val eventTypes = EventTypesHelper().getEventTypesSync(this)
|
||||||
val eventType = it.first { it.caldavCalendarId == 0 }
|
if (eventTypes.filter { it.caldavCalendarId == 0 }.size == 1) {
|
||||||
|
val eventType = eventTypes.first { it.caldavCalendarId == 0 }
|
||||||
eventType.color = config.primaryColor
|
eventType.color = config.primaryColor
|
||||||
dbHelper.updateEventType(eventType)
|
dbHelper.updateEventType(eventType)
|
||||||
}
|
}
|
||||||
}
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +212,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
if (newCalendarIds.isNotEmpty()) {
|
if (newCalendarIds.isNotEmpty()) {
|
||||||
val existingEventTypeNames = dbHelper.getEventTypesSync().map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
val existingEventTypeNames = EventTypesHelper().getEventTypesSync(applicationContext).map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
||||||
getSyncedCalDAVCalendars().forEach {
|
getSyncedCalDAVCalendars().forEach {
|
||||||
val calendarTitle = it.getFullTitle()
|
val calendarTitle = it.getFullTitle()
|
||||||
if (!existingEventTypeNames.contains(calendarTitle.toLowerCase())) {
|
if (!existingEventTypeNames.contains(calendarTitle.toLowerCase())) {
|
||||||
|
@ -6,7 +6,7 @@ import androidx.appcompat.app.AlertDialog
|
|||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
|
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
|
||||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
import com.simplemobiletools.calendar.pro.helpers.EventTypesHelper
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import kotlinx.android.synthetic.main.dialog_export_events.view.*
|
import kotlinx.android.synthetic.main.dialog_export_events.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -19,11 +19,10 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
|||||||
export_events_folder.text = activity.humanizePath(path)
|
export_events_folder.text = activity.humanizePath(path)
|
||||||
export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}")
|
export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}")
|
||||||
|
|
||||||
activity.dbHelper.getEventTypes {
|
EventTypesHelper().getEventTypes(activity) {
|
||||||
val eventTypes = HashSet<String>()
|
val eventTypes = HashSet<String>()
|
||||||
it.mapTo(eventTypes) { it.id.toString() }
|
it.mapTo(eventTypes) { it.id.toString() }
|
||||||
|
|
||||||
activity.runOnUiThread {
|
|
||||||
export_events_types_list.adapter = FilterEventTypeAdapter(activity, it, eventTypes)
|
export_events_types_list.adapter = FilterEventTypeAdapter(activity, it, eventTypes)
|
||||||
if (it.size > 1) {
|
if (it.size > 1) {
|
||||||
export_events_pick_types.beVisible()
|
export_events_pick_types.beVisible()
|
||||||
@ -33,7 +32,6 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
|
@ -5,7 +5,7 @@ import com.simplemobiletools.calendar.pro.R
|
|||||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
|
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
|
||||||
import com.simplemobiletools.calendar.pro.extensions.config
|
import com.simplemobiletools.calendar.pro.extensions.config
|
||||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
import com.simplemobiletools.calendar.pro.helpers.EventTypesHelper
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import kotlinx.android.synthetic.main.dialog_filter_event_types.view.*
|
import kotlinx.android.synthetic.main.dialog_filter_event_types.view.*
|
||||||
|
|
||||||
@ -14,9 +14,8 @@ class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> U
|
|||||||
private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null)
|
private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
activity.dbHelper.getEventTypes {
|
EventTypesHelper().getEventTypes(activity) {
|
||||||
val displayEventTypes = activity.config.displayEventTypes
|
val displayEventTypes = activity.config.displayEventTypes
|
||||||
activity.runOnUiThread {
|
|
||||||
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)
|
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
@ -27,7 +26,6 @@ class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun confirmEventTypes() {
|
private fun confirmEventTypes() {
|
||||||
val selectedItems = (view.filter_event_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsSet()
|
val selectedItems = (view.filter_event_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsSet()
|
||||||
|
@ -26,7 +26,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
|||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
|
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
|
||||||
radioGroup = view.dialog_radio_group
|
radioGroup = view.dialog_radio_group
|
||||||
|
|
||||||
activity.dbHelper.getEventTypes {
|
Thread {
|
||||||
calendars.forEach {
|
calendars.forEach {
|
||||||
val localEventType = activity.dbHelper.getEventTypeWithCalDAVCalendarId(it.id)
|
val localEventType = activity.dbHelper.getEventTypeWithCalDAVCalendarId(it.id)
|
||||||
if (localEventType != null) {
|
if (localEventType != null) {
|
||||||
@ -42,7 +42,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
|||||||
wasInit = true
|
wasInit = true
|
||||||
activity.updateTextColors(view.dialog_radio_holder)
|
activity.updateTextColors(view.dialog_radio_holder)
|
||||||
}
|
}
|
||||||
}
|
}.start()
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
.create().apply {
|
.create().apply {
|
||||||
|
@ -7,7 +7,7 @@ import android.widget.RadioGroup
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
import com.simplemobiletools.calendar.pro.extensions.config
|
import com.simplemobiletools.calendar.pro.extensions.config
|
||||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
import com.simplemobiletools.calendar.pro.helpers.EventTypesHelper
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.models.EventType
|
||||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
||||||
@ -31,7 +31,7 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val
|
|||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
|
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
|
||||||
radioGroup = view.dialog_radio_group
|
radioGroup = view.dialog_radio_group
|
||||||
|
|
||||||
activity.dbHelper.getEventTypes {
|
EventTypesHelper().getEventTypes(activity) {
|
||||||
eventTypes = it
|
eventTypes = it
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
eventTypes.filter { showCalDAVCalendars || it.caldavCalendarId == 0 }.forEach {
|
eventTypes.filter { showCalDAVCalendars || it.caldavCalendarId == 0 }.forEach {
|
||||||
|
@ -17,7 +17,6 @@ import androidx.fragment.app.Fragment
|
|||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
import com.simplemobiletools.calendar.pro.activities.EventActivity
|
import com.simplemobiletools.calendar.pro.activities.EventActivity
|
||||||
import com.simplemobiletools.calendar.pro.extensions.config
|
import com.simplemobiletools.calendar.pro.extensions.config
|
||||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
|
||||||
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
|
||||||
@ -58,16 +57,16 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
private var allDayRows = ArrayList<HashSet<Int>>()
|
private var allDayRows = ArrayList<HashSet<Int>>()
|
||||||
private var eventTypeColors = LongSparseArray<Int>()
|
private var eventTypeColors = LongSparseArray<Int>()
|
||||||
|
|
||||||
lateinit var inflater: LayoutInflater
|
private lateinit var inflater: LayoutInflater
|
||||||
lateinit var mView: View
|
private lateinit var mView: View
|
||||||
lateinit var mScrollView: MyScrollView
|
private lateinit var mScrollView: MyScrollView
|
||||||
lateinit var mCalendar: WeeklyCalendarImpl
|
private lateinit var mCalendar: WeeklyCalendarImpl
|
||||||
lateinit var mRes: Resources
|
private lateinit var mRes: Resources
|
||||||
lateinit var mConfig: Config
|
private lateinit var mConfig: Config
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
context!!.dbHelper.getEventTypes {
|
EventTypesHelper().getEventTypes(activity!!) {
|
||||||
it.map { eventTypeColors.put(it.id!!, it.color) }
|
it.map { eventTypeColors.put(it.id!!, it.color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -838,7 +838,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
private fun fillEvents(cursor: Cursor?): List<Event> {
|
private fun fillEvents(cursor: Cursor?): List<Event> {
|
||||||
val eventTypeColors = LongSparseArray<Int>()
|
val eventTypeColors = LongSparseArray<Int>()
|
||||||
getEventTypesSync().forEach {
|
context.eventTypesDB.getEventTypes().forEach {
|
||||||
eventTypeColors.put(it.id!!, it.color)
|
eventTypeColors.put(it.id!!, it.color)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,38 +880,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventTypes(callback: (types: ArrayList<EventType>) -> Unit) {
|
|
||||||
Thread {
|
|
||||||
callback(getEventTypesSync())
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getEventTypesSync(): ArrayList<EventType> {
|
|
||||||
val eventTypes = ArrayList<EventType>()
|
|
||||||
val cols = arrayOf(COL_ID, COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID, COL_TYPE_CALDAV_DISPLAY_NAME, COL_TYPE_CALDAV_EMAIL)
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
cursor = mDb.query(TYPES_TABLE_NAME, cols, null, null, null, null, "$COL_TYPE_TITLE ASC")
|
|
||||||
if (cursor?.moveToFirst() == true) {
|
|
||||||
do {
|
|
||||||
val id = cursor.getLongValue(COL_ID)
|
|
||||||
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
|
||||||
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
|
||||||
val calendarId = cursor.getIntValue(COL_TYPE_CALDAV_CALENDAR_ID)
|
|
||||||
val displayName = cursor.getStringValue(COL_TYPE_CALDAV_DISPLAY_NAME)
|
|
||||||
val email = cursor.getStringValue(COL_TYPE_CALDAV_EMAIL)
|
|
||||||
val eventType = EventType(id, title, color, calendarId, displayName, email)
|
|
||||||
eventTypes.add(eventType)
|
|
||||||
} while (cursor.moveToNext())
|
|
||||||
}
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
return eventTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
fun doEventTypesContainEvents(types: ArrayList<EventType>, callback: (contain: Boolean) -> Unit) {
|
fun doEventTypesContainEvents(types: ArrayList<EventType>, callback: (contain: Boolean) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val args = TextUtils.join(", ", types.map { it.id })
|
val args = TextUtils.join(", ", types.map { it.id })
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
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.models.EventType
|
||||||
|
|
||||||
|
class EventTypesHelper {
|
||||||
|
fun getEventTypes(activity: Activity, callback: (notes: ArrayList<EventType>) -> Unit) {
|
||||||
|
Thread {
|
||||||
|
val eventTypes = activity.eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
||||||
|
activity.runOnUiThread {
|
||||||
|
callback(eventTypes)
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEventTypesSync(context: Context) = context.eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
||||||
|
}
|
@ -42,7 +42,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||||||
|
|
||||||
fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
||||||
try {
|
try {
|
||||||
val eventTypes = activity.dbHelper.getEventTypesSync()
|
val eventTypes = EventTypesHelper().getEventTypesSync(activity)
|
||||||
val existingEvents = activity.dbHelper.getEventsWithImportIds()
|
val existingEvents = activity.dbHelper.getEventsWithImportIds()
|
||||||
val eventsToInsert = ArrayList<Event>()
|
val eventsToInsert = ArrayList<Event>()
|
||||||
var prevLine = ""
|
var prevLine = ""
|
||||||
|
@ -82,7 +82,6 @@ class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) {
|
|||||||
|
|
||||||
// it works more often than not, dont touch
|
// it works more often than not, dont touch
|
||||||
private fun markDaysWithEvents(days: ArrayList<DayMonthly>) {
|
private fun markDaysWithEvents(days: ArrayList<DayMonthly>) {
|
||||||
context.dbHelper.getEventTypes {
|
|
||||||
val dayEvents = HashMap<String, ArrayList<Event>>()
|
val dayEvents = HashMap<String, ArrayList<Event>>()
|
||||||
mEvents.forEach {
|
mEvents.forEach {
|
||||||
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
|
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
|
||||||
@ -109,7 +108,6 @@ class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) {
|
|||||||
}
|
}
|
||||||
callback.updateMonthlyCalendar(context, monthName, days, true, mTargetDate)
|
callback.updateMonthlyCalendar(context, monthName, days, true, mTargetDate)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun isToday(targetDate: DateTime, curDayInMonth: Int): Boolean {
|
private fun isToday(targetDate: DateTime, curDayInMonth: Int): Boolean {
|
||||||
val targetMonthDays = targetDate.dayOfMonth().maximumValue
|
val targetMonthDays = targetDate.dayOfMonth().maximumValue
|
||||||
|
Reference in New Issue
Block a user