diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt index 70a00a57f..8f1dedece 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt @@ -10,9 +10,9 @@ import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter import com.simplemobiletools.calendar.dialogs.FilterEventTypesDialog import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode import com.simplemobiletools.calendar.helpers.DAY_CODE -import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.helpers.NEW_EVENT_START_TS import com.simplemobiletools.calendar.interfaces.NavigationListener @@ -42,7 +42,7 @@ class DayActivity : SimpleActivity(), NavigationListener, ViewPager.OnPageChange day_fab.setOnClickListener { addNewEvent() } updateTextColors(day_coordinator) - DBHelper.newInstance(applicationContext).getEventTypes { + dbHelper.getEventTypes { eventTypeColors.clear() it.map { eventTypeColors.put(it.id, it.color) } invalidateOptionsMenu() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index 8c005b9a4..2e349b5f5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -43,7 +43,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { mDialogTheme = getAppropriateTheme() val eventId = intent.getIntExtra(EVENT_ID, 0) - val event = DBHelper.newInstance(applicationContext).getEvent(eventId) + val event = dbHelper.getEvent(eventId) if (event != null) { mEvent = event mEventOccurrenceTS = intent.getIntExtra(EVENT_OCCURRENCE_TS, 0) @@ -231,7 +231,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } private fun updateEventType() { - val eventType = DBHelper.newInstance(applicationContext).getEventType(mEventTypeId) + val eventType = dbHelper.getEventType(mEventTypeId) if (eventType != null) { event_type.text = eventType.title event_type_color.setBackgroundWithStroke(eventType.color, config.backgroundColor) @@ -260,11 +260,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { private fun deleteEvent() { DeleteEventDialog(this, arrayListOf(mEvent.id)) { - val db = DBHelper.newInstance(applicationContext, null) if (it) { - db.deleteEvents(arrayOf(mEvent.id.toString())) + dbHelper.deleteEvents(arrayOf(mEvent.id.toString())) } else { - db.deleteEventOccurrence(mEvent.id, mEventOccurrenceTS) + dbHelper.deleteEventOccurrence(mEvent.id, mEventOccurrenceTS) } finish() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index dc1af8f53..d4fe86d4b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -19,10 +19,7 @@ import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter import com.simplemobiletools.calendar.dialogs.ChangeViewDialog import com.simplemobiletools.calendar.dialogs.FilterEventTypesDialog import com.simplemobiletools.calendar.dialogs.ImportEventsDialog -import com.simplemobiletools.calendar.extensions.config -import com.simplemobiletools.calendar.extensions.launchNewEventIntent -import com.simplemobiletools.calendar.extensions.seconds -import com.simplemobiletools.calendar.extensions.updateWidgets +import com.simplemobiletools.calendar.extensions.* import com.simplemobiletools.calendar.fragments.EventListFragment import com.simplemobiletools.calendar.fragments.WeekFragment import com.simplemobiletools.calendar.helpers.* @@ -79,7 +76,7 @@ class MainActivity : SimpleActivity(), NavigationListener { if (mStoredTextColor != config.textColor || mStoredBackgroundColor != config.backgroundColor || mStoredPrimaryColor != config.primaryColor) updateViewPager() - DBHelper.newInstance(applicationContext).getEventTypes { + dbHelper.getEventTypes { eventTypeColors.clear() it.map { eventTypeColors.put(it.id, it.color) } mShouldFilterBeVisible = eventTypeColors.size() > 1 || config.displayEventTypes.isEmpty() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt index 36e060e94..679f74199 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.adapters.EventTypeAdapter import com.simplemobiletools.calendar.dialogs.NewEventTypeDialog +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.interfaces.DeleteItemsListener import com.simplemobiletools.calendar.models.EventType @@ -32,7 +33,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteItemsListener { } private fun getEventTypes() { - DBHelper.newInstance(applicationContext).getEventTypes { + dbHelper.getEventTypes { runOnUiThread { manage_event_types_list.adapter = EventTypeAdapter(this, it, this) { showEventTypeDialog(it) @@ -46,7 +47,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteItemsListener { toast(R.string.cannot_delete_default_type) } - DBHelper.newInstance(applicationContext).deleteEventTypes(ids) { + dbHelper.deleteEventTypes(ids) { if (it > 0) { getEventTypes() } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt index 86890e500..35f1a689c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt @@ -8,6 +8,7 @@ import android.widget.RemoteViewsService import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R.id.event_item_holder import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.helpers.EVENT_ID @@ -18,7 +19,6 @@ import com.simplemobiletools.calendar.models.ListItem import com.simplemobiletools.calendar.models.ListSection import org.joda.time.DateTime import java.util.* -import kotlin.comparisons.compareBy class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory { val ITEM_EVENT = 0 @@ -98,7 +98,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV override fun onDataSetChanged() { val fromTS = DateTime().seconds() val toTS = DateTime().plusYears(1).seconds() - DBHelper.newInstance(context).getEventsInBackground(fromTS, toTS, object : DBHelper.GetEventsListener { + context.dbHelper.getEventsInBackground(fromTS, toTS, object : DBHelper.GetEventsListener { override fun gotEvents(events: MutableList) { val listItems = ArrayList(events.size) val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt index 47ef8e99c..f459b10fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt @@ -5,7 +5,7 @@ import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.ViewGroup import com.simplemobiletools.calendar.R -import com.simplemobiletools.calendar.helpers.DBHelper +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_delete_event.view.* @@ -14,7 +14,7 @@ class DeleteEventDialog(val activity: Activity, eventIds: List, val callbac val dialog: AlertDialog? init { - val events = DBHelper.newInstance(activity).getEventsWithIds(eventIds) + val events = activity.dbHelper.getEventsWithIds(eventIds) val hasRepeatableEvent = events.any { it.repeatInterval > 0 } val view = LayoutInflater.from(activity).inflate(R.layout.dialog_delete_event, null).apply { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt index dc179c072..1c9a1f1e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt @@ -6,7 +6,7 @@ import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.adapters.FilterEventTypeAdapter import com.simplemobiletools.calendar.extensions.config -import com.simplemobiletools.calendar.helpers.DBHelper +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_filter_event_types.view.* @@ -18,7 +18,7 @@ class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> U val view = LayoutInflater.from(activity).inflate(R.layout.dialog_filter_event_types, null) init { - DBHelper.newInstance(activity).getEventTypes { + activity.dbHelper.getEventTypes { val displayEventTypes = activity.config.displayEventTypes eventTypes = it view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt index 3d041e237..143054b38 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt @@ -6,6 +6,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.helpers.IcsParser import com.simplemobiletools.calendar.helpers.IcsParser.ImportResult.* @@ -47,7 +48,7 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback: } private fun updateEventType(view: ViewGroup) { - val eventType = DBHelper.newInstance(context).getEventType(currEventTypeId) + val eventType = context.dbHelper.getEventType(currEventTypeId) view.import_event_type_title.text = eventType!!.title view.import_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/NewEventTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/NewEventTypeDialog.kt index 884bd7885..aecf2f50d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/NewEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/NewEventTypeDialog.kt @@ -7,7 +7,7 @@ import android.view.WindowManager import android.widget.ImageView import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.extensions.config -import com.simplemobiletools.calendar.helpers.DBHelper +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.extensions.setBackgroundWithStroke @@ -34,7 +34,6 @@ class NewEventTypeDialog(val activity: Activity, var eventType: EventType? = nul } } - val db = DBHelper.newInstance(activity) AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) @@ -43,7 +42,7 @@ class NewEventTypeDialog(val activity: Activity, var eventType: EventType? = nul activity.setupDialogStuff(view, this, if (isNewEvent) R.string.add_new_type else R.string.edit_type) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ val title = view.type_title.value - val eventIdWithTitle = db.getEventTypeIdWithTitle(title) + val eventIdWithTitle = activity.dbHelper.getEventTypeIdWithTitle(title) var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1 if (!isEventTypeTitleTaken) isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1 @@ -60,9 +59,9 @@ class NewEventTypeDialog(val activity: Activity, var eventType: EventType? = nul val eventTypeId: Int if (isNewEvent) { - eventTypeId = db.insertEventType(eventType!!) + eventTypeId = activity.dbHelper.insertEventType(eventType!!) } else { - eventTypeId = db.updateEventType(eventType!!) + eventTypeId = activity.dbHelper.updateEventType(eventType!!) } if (eventTypeId != -1) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt index 68d5802b3..775f7e3f6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt @@ -8,6 +8,7 @@ import android.widget.RadioButton import android.widget.RadioGroup import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.extensions.hideKeyboard @@ -30,7 +31,7 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null) as ViewGroup radioGroup = view.dialog_radio_group - DBHelper.newInstance(activity).getEventTypes { + activity.dbHelper.getEventTypes { eventTypes = it activity.runOnUiThread { eventTypes.forEach { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt index 8c0db3f8e..06b9bdd9f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt @@ -17,6 +17,7 @@ import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.adapters.DayEventsAdapter import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.getAppropriateTheme import com.simplemobiletools.calendar.extensions.getFilteredEvents import com.simplemobiletools.calendar.helpers.* @@ -30,7 +31,6 @@ import kotlinx.android.synthetic.main.fragment_day.view.* import kotlinx.android.synthetic.main.top_navigation.view.* import org.joda.time.DateTime import java.util.* -import kotlin.comparisons.compareBy class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEventsListener, DeleteEventsListener { private var mTextColor = 0 @@ -142,9 +142,8 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents } override fun deleteEventOccurrences(parentIds: ArrayList, timestamps: ArrayList) { - val db = DBHelper.newInstance(context) parentIds.forEachIndexed { index, value -> - db.deleteEventOccurrence(parentIds[index], timestamps[index]) + context.dbHelper.deleteEventOccurrence(parentIds[index], timestamps[index]) } (activity as DayActivity).recheckEvents() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt index c15f557fb..e9fbc8c43 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.adapters.EventListAdapter import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.getFilteredEvents import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.helpers.DBHelper @@ -27,7 +28,6 @@ import com.simplemobiletools.commons.extensions.beVisibleIf import kotlinx.android.synthetic.main.fragment_event_list.view.* import org.joda.time.DateTime import java.util.* -import kotlin.comparisons.compareBy class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, DeleteEventsListener { private var mEvents: List = ArrayList() @@ -49,7 +49,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event private fun checkEvents() { val fromTS = DateTime().seconds() val toTS = DateTime().plusYears(1).seconds() - DBHelper.newInstance(context).getEvents(fromTS, toTS, this) + context.dbHelper.getEvents(fromTS, toTS, this) } override fun gotEvents(events: MutableList) { @@ -109,9 +109,8 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event } override fun deleteEventOccurrences(parentIds: ArrayList, timestamps: ArrayList) { - val db = DBHelper.newInstance(context) parentIds.forEachIndexed { index, value -> - db.deleteEventOccurrence(parentIds[index], timestamps[index]) + context.dbHelper.deleteEventOccurrence(parentIds[index], timestamps[index]) } checkEvents() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt index c07166be2..cdb39d329 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.helpers import android.content.Context import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.helpers.IcsParser.ImportResult.* import com.simplemobiletools.calendar.models.Event @@ -57,8 +58,7 @@ class IcsParser { fun parseIcs(context: Context, path: String, defaultEventType: Int): ImportResult { try { - val dbHelper = DBHelper.newInstance(context) - val importIDs = dbHelper.getImportIds() + val importIDs = context.dbHelper.getImportIds() var prevLine = "" File(path).inputStream().bufferedReader().use { @@ -109,7 +109,7 @@ class IcsParser { importIDs.add(curImportId) val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes, -1, -1, curRepeatInterval, curImportId, curFlags, curRepeatLimit, curEventType) - dbHelper.insert(event) { } + context.dbHelper.insert(event) { } eventsImported++ resetValues() } @@ -161,11 +161,10 @@ class IcsParser { categories } - val dbHelper = DBHelper.newInstance(context) - val eventId = dbHelper.getEventTypeIdWithTitle(eventTypeTitle) + val eventId = context.dbHelper.getEventTypeIdWithTitle(eventTypeTitle) if (eventId == -1) { val eventType = EventType(0, eventTypeTitle, context.resources.getColor(R.color.color_primary)) - curEventType = dbHelper.insertEventType(eventType) + curEventType = context.dbHelper.insertEventType(eventType) } else { curEventType = eventId } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt index ded2c98a0..37384bd18 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.helpers import android.content.Context import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.getFilteredEvents import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.interfaces.MonthlyCalendar @@ -29,7 +30,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context) mTargetDate = targetDate val startTS = mTargetDate.minusMonths(1).seconds() val endTS = mTargetDate.plusMonths(1).seconds() - DBHelper.newInstance(mContext).getEvents(startTS, endTS, this) + mContext.dbHelper.getEvents(startTS, endTS, this) } fun getPrevMonth() { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt index 91cd19f98..ec307c02d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.calendar.helpers import android.content.Context +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.interfaces.WeeklyCalendar import com.simplemobiletools.calendar.models.Event import java.util.* @@ -15,7 +16,7 @@ class WeeklyCalendarImpl(val mCallback: WeeklyCalendar, val mContext: Context) : fun updateWeeklyCalendar(weekStartTS: Int) { val startTS = weekStartTS val endTS = startTS + WEEK_SECONDS - DBHelper.newInstance(mContext).getEvents(startTS, endTS, this) + mContext.dbHelper.getEvents(startTS, endTS, this) } override fun gotEvents(events: MutableList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt index da02ed612..1bf1ba968 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.helpers import android.content.Context import android.util.SparseArray +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.getFilteredEvents import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.interfaces.YearlyCalendar @@ -15,7 +16,7 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val val startDateTime = DateTime().withTime(0, 0, 0, 0).withDate(year, 1, 1) val startTS = startDateTime.seconds() val endTS = startDateTime.plusYears(1).minusSeconds(1).seconds() - DBHelper.newInstance(context).getEvents(startTS, endTS, this) + context.dbHelper.getEvents(startTS, endTS, this) } override fun gotEvents(events: MutableList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/BootCompletedReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/BootCompletedReceiver.kt index 95defc3f9..f27744298 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/BootCompletedReceiver.kt @@ -3,13 +3,13 @@ package com.simplemobiletools.calendar.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder -import com.simplemobiletools.calendar.helpers.DBHelper class BootCompletedReceiver : BroadcastReceiver() { override fun onReceive(context: Context, arg1: Intent) { - val events = DBHelper.newInstance(context).getEventsAtReboot() + val events = context.dbHelper.getEventsAtReboot() for (event in events) { context.scheduleNextEventReminder(event) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt index 464b2dd22..316ba9a38 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt @@ -10,9 +10,9 @@ import android.net.Uri import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder import com.simplemobiletools.calendar.extensions.updateListWidget -import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.helpers.EVENT_ID import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.models.Event @@ -25,7 +25,7 @@ class NotificationReceiver : BroadcastReceiver() { if (id == -1) return - val event = DBHelper.newInstance(context).getEvent(id) + val event = context.dbHelper.getEvent(id) if (event == null || event.getReminders().isEmpty()) return