mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fixing some Lint warnings, minor code cleanup
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package com.simplemobiletools.calendar.activities
|
package com.simplemobiletools.calendar.activities
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.DatePickerDialog
|
import android.app.DatePickerDialog
|
||||||
import android.app.TimePickerDialog
|
import android.app.TimePickerDialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@@ -94,9 +93,11 @@ class EventActivity : SimpleActivity() {
|
|||||||
cancelNotification(mEvent.id)
|
cancelNotification(mEvent.id)
|
||||||
} else {
|
} else {
|
||||||
mEvent = Event()
|
mEvent = Event()
|
||||||
mReminder1Minutes = if (config.usePreviousEventReminders) config.lastEventReminderMinutes else config.defaultReminder1
|
config.apply {
|
||||||
mReminder2Minutes = if (config.usePreviousEventReminders) config.lastEventReminderMinutes2 else config.defaultReminder2
|
mReminder1Minutes = if (usePreviousEventReminders) lastEventReminderMinutes1 else defaultReminder1
|
||||||
mReminder3Minutes = if (config.usePreviousEventReminders) config.lastEventReminderMinutes3 else config.defaultReminder3
|
mReminder2Minutes = if (usePreviousEventReminders) lastEventReminderMinutes2 else defaultReminder2
|
||||||
|
mReminder3Minutes = if (usePreviousEventReminders) lastEventReminderMinutes3 else defaultReminder3
|
||||||
|
}
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
setupNewEvent()
|
setupNewEvent()
|
||||||
@@ -121,7 +122,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
event_repetition_limit_holder.setOnClickListener { showRepetitionTypePicker() }
|
event_repetition_limit_holder.setOnClickListener { showRepetitionTypePicker() }
|
||||||
|
|
||||||
event_reminder_1.setOnClickListener {
|
event_reminder_1.setOnClickListener {
|
||||||
handleNotificationAvailability() {
|
handleNotificationAvailability {
|
||||||
if (config.wasAlarmWarningShown) {
|
if (config.wasAlarmWarningShown) {
|
||||||
showReminder1Dialog()
|
showReminder1Dialog()
|
||||||
} else {
|
} else {
|
||||||
@@ -722,7 +723,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
|
|
||||||
config.apply {
|
config.apply {
|
||||||
if (usePreviousEventReminders) {
|
if (usePreviousEventReminders) {
|
||||||
lastEventReminderMinutes = reminder1
|
lastEventReminderMinutes1 = reminder1
|
||||||
lastEventReminderMinutes2 = reminder2
|
lastEventReminderMinutes2 = reminder2
|
||||||
lastEventReminderMinutes3 = reminder3
|
lastEventReminderMinutes3 = reminder3
|
||||||
}
|
}
|
||||||
@@ -862,7 +863,6 @@ class EventActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private fun setupStartDate() {
|
private fun setupStartDate() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
config.backgroundColor.getContrastColor()
|
config.backgroundColor.getContrastColor()
|
||||||
@@ -878,7 +878,6 @@ class EventActivity : SimpleActivity() {
|
|||||||
TimePickerDialog(this, mDialogTheme, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, config.use24HourFormat).show()
|
TimePickerDialog(this, mDialogTheme, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, config.use24HourFormat).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private fun setupEndDate() {
|
private fun setupEndDate() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
val datepicker = DatePickerDialog(this, mDialogTheme, endDateSetListener, mEventEndDateTime.year, mEventEndDateTime.monthOfYear - 1,
|
val datepicker = DatePickerDialog(this, mDialogTheme, endDateSetListener, mEventEndDateTime.year, mEventEndDateTime.monthOfYear - 1,
|
||||||
|
@@ -70,9 +70,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched(BuildConfig.APPLICATION_ID)
|
appLaunched(BuildConfig.APPLICATION_ID)
|
||||||
|
|
||||||
// just get a reference to the database to make sure it is created properly
|
|
||||||
dbHelper
|
|
||||||
|
|
||||||
checkWhatsNewDialog()
|
checkWhatsNewDialog()
|
||||||
calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW)
|
calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW)
|
||||||
calendar_fab.setOnClickListener {
|
calendar_fab.setOnClickListener {
|
||||||
|
@@ -142,10 +142,10 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
|
|||||||
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) { it ->
|
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) { it ->
|
||||||
events.removeAll(eventsToDelete)
|
events.removeAll(eventsToDelete)
|
||||||
|
|
||||||
val nonRepeatingEventIDs = eventsToDelete.filter { it.repeatInterval == 0 }.map { it.id.toString() }.toTypedArray()
|
val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.map { it.id.toString() }.toList().toTypedArray()
|
||||||
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true)
|
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||||
|
|
||||||
val repeatingEventIDs = eventsToDelete.filter { it.repeatInterval != 0 }.map { it.id }
|
val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.map { it.id }.toList()
|
||||||
activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
|
activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
|
||||||
removeSelectedItems(positions)
|
removeSelectedItems(positions)
|
||||||
}
|
}
|
||||||
|
@@ -200,7 +200,7 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
|
|||||||
private fun askConfirmDelete() {
|
private fun askConfirmDelete() {
|
||||||
val eventIds = selectedKeys.toMutableList()
|
val eventIds = selectedKeys.toMutableList()
|
||||||
val eventsToDelete = listItems.filter { selectedKeys.contains((it as? ListEvent)?.id) } as List<ListEvent>
|
val eventsToDelete = listItems.filter { selectedKeys.contains((it as? ListEvent)?.id) } as List<ListEvent>
|
||||||
val timestamps = eventsToDelete.map { (it as? ListEvent)?.startTS }.filterNotNull()
|
val timestamps = eventsToDelete.mapNotNull { (it as? ListEvent)?.startTS }
|
||||||
|
|
||||||
val hasRepeatableEvent = eventsToDelete.any { it.isRepeatable }
|
val hasRepeatableEvent = eventsToDelete.any { it.isRepeatable }
|
||||||
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) {
|
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) {
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package com.simplemobiletools.calendar.dialogs
|
package com.simplemobiletools.calendar.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.helpers.DAY
|
import com.simplemobiletools.calendar.helpers.DAY
|
||||||
import com.simplemobiletools.calendar.helpers.MONTH
|
import com.simplemobiletools.calendar.helpers.MONTH
|
||||||
@@ -22,7 +22,7 @@ class CustomEventRepeatIntervalDialog(val activity: Activity, val callback: (sec
|
|||||||
view.dialog_radio_view.check(R.id.dialog_radio_days)
|
view.dialog_radio_view.check(R.id.dialog_radio_days)
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmRepeatInterval() })
|
.setPositiveButton(R.string.ok) { dialogInterface, i -> confirmRepeatInterval() }
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.create().apply {
|
.create().apply {
|
||||||
activity.setupDialogStuff(view, this) {
|
activity.setupDialogStuff(view, this) {
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package com.simplemobiletools.calendar.dialogs
|
package com.simplemobiletools.calendar.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.helpers.DELETE_ALL_OCCURRENCES
|
import com.simplemobiletools.calendar.helpers.DELETE_ALL_OCCURRENCES
|
||||||
import com.simplemobiletools.calendar.helpers.DELETE_FUTURE_OCCURRENCES
|
import com.simplemobiletools.calendar.helpers.DELETE_FUTURE_OCCURRENCES
|
||||||
@@ -28,7 +28,7 @@ class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, hasRepeatab
|
|||||||
}
|
}
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed(view as ViewGroup) })
|
.setPositiveButton(R.string.yes) { dialog, which -> dialogConfirmed(view as ViewGroup) }
|
||||||
.setNegativeButton(R.string.no, null)
|
.setNegativeButton(R.string.no, null)
|
||||||
.create().apply {
|
.create().apply {
|
||||||
activity.setupDialogStuff(view, this)
|
activity.setupDialogStuff(view, this)
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package com.simplemobiletools.calendar.dialogs
|
package com.simplemobiletools.calendar.dialogs
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||||
|
@@ -17,7 +17,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
|||||||
init {
|
init {
|
||||||
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply {
|
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply {
|
||||||
export_events_folder.text = activity.humanizePath(path)
|
export_events_folder.text = activity.humanizePath(path)
|
||||||
export_events_filename.setText("events_${activity.getCurrentFormattedDateTime()}")
|
export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}")
|
||||||
|
|
||||||
activity.dbHelper.getEventTypes {
|
activity.dbHelper.getEventTypes {
|
||||||
val eventTypes = HashSet<String>()
|
val eventTypes = HashSet<String>()
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package com.simplemobiletools.calendar.dialogs
|
package com.simplemobiletools.calendar.dialogs
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package com.simplemobiletools.calendar.dialogs
|
package com.simplemobiletools.calendar.dialogs
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.DatePickerDialog
|
import android.app.DatePickerDialog
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -24,14 +23,18 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int,
|
|||||||
init {
|
init {
|
||||||
view = activity.layoutInflater.inflate(R.layout.dialog_repeat_limit_type_picker, null).apply {
|
view = activity.layoutInflater.inflate(R.layout.dialog_repeat_limit_type_picker, null).apply {
|
||||||
repeat_type_date.setOnClickListener { showRepetitionLimitDialog() }
|
repeat_type_date.setOnClickListener { showRepetitionLimitDialog() }
|
||||||
repeat_type_forever.setOnClickListener { callback(0); dialog.dismiss() }
|
|
||||||
repeat_type_count.setOnClickListener { dialog_radio_view.check(R.id.repeat_type_x_times) }
|
repeat_type_count.setOnClickListener { dialog_radio_view.check(R.id.repeat_type_x_times) }
|
||||||
|
repeat_type_forever.setOnClickListener {
|
||||||
|
callback(0)
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
view.dialog_radio_view.check(getCheckedItem())
|
view.dialog_radio_view.check(getCheckedItem())
|
||||||
|
|
||||||
if (repeatLimit in 1..startTS)
|
if (repeatLimit in 1..startTS) {
|
||||||
repeatLimit = startTS
|
repeatLimit = startTS
|
||||||
|
}
|
||||||
|
|
||||||
updateRepeatLimitText()
|
updateRepeatLimitText()
|
||||||
|
|
||||||
@@ -79,7 +82,6 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int,
|
|||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private fun showRepetitionLimitDialog() {
|
private fun showRepetitionLimitDialog() {
|
||||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (repeatLimit != 0) repeatLimit else getNowSeconds())
|
val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (repeatLimit != 0) repeatLimit else getNowSeconds())
|
||||||
val datepicker = DatePickerDialog(activity, activity.getDialogTheme(), repetitionLimitDateSetListener, repeatLimitDateTime.year,
|
val datepicker = DatePickerDialog(activity, activity.getDialogTheme(), repetitionLimitDateSetListener, repeatLimitDateTime.year,
|
||||||
|
@@ -2,9 +2,9 @@ package com.simplemobiletools.calendar.dialogs
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.RadioGroup
|
import android.widget.RadioGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
|
@@ -448,7 +448,7 @@ fun Context.handleEventDeleting(eventIds: List<Int>, timestamps: List<Int>, acti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DELETE_ALL_OCCURRENCES -> {
|
DELETE_ALL_OCCURRENCES -> {
|
||||||
val eventIDs = Array(eventIds.size, { i -> (eventIds[i].toString()) })
|
val eventIDs = Array(eventIds.size) { i -> (eventIds[i].toString()) }
|
||||||
dbHelper.deleteEvents(eventIDs, true)
|
dbHelper.deleteEvents(eventIDs, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,10 +2,10 @@ package com.simplemobiletools.calendar.fragments
|
|||||||
|
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.viewpager.widget.ViewPager
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.viewpager.widget.ViewPager
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.activities.MainActivity
|
import com.simplemobiletools.calendar.activities.MainActivity
|
||||||
import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
|
import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
|
||||||
|
@@ -117,53 +117,6 @@ class CalDAVHandler(val context: Context) {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
// it doesnt work properly, needs better SyncAdapter handling
|
|
||||||
private fun insertNewColor(eventType: EventType): Int {
|
|
||||||
val maxId = getMaxColorId(eventType) + 1
|
|
||||||
|
|
||||||
val values = ContentValues().apply {
|
|
||||||
put(CalendarContract.Colors.COLOR_KEY, maxId)
|
|
||||||
put(CalendarContract.Colors.COLOR, eventType.color)
|
|
||||||
put(CalendarContract.Colors.ACCOUNT_NAME, eventType.caldavEmail)
|
|
||||||
put(CalendarContract.Colors.ACCOUNT_TYPE, "com.google")
|
|
||||||
put(CalendarContract.Colors.COLOR_TYPE, CalendarContract.Colors.TYPE_CALENDAR)
|
|
||||||
}
|
|
||||||
|
|
||||||
val uri = CalendarContract.Colors.CONTENT_URI.buildUpon()
|
|
||||||
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
|
|
||||||
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, eventType.caldavEmail)
|
|
||||||
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, "com.google")
|
|
||||||
.build()
|
|
||||||
|
|
||||||
return if (context.contentResolver.insert(uri, values) != null) {
|
|
||||||
maxId
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getMaxColorId(eventType: EventType): Int {
|
|
||||||
val uri = CalendarContract.Colors.CONTENT_URI
|
|
||||||
val projection = arrayOf(CalendarContract.Colors.COLOR_KEY, CalendarContract.Colors.COLOR)
|
|
||||||
val selection = "${CalendarContract.Colors.COLOR_TYPE} = ? AND ${CalendarContract.Colors.ACCOUNT_NAME} = ?"
|
|
||||||
val selectionArgs = arrayOf(CalendarContract.Colors.TYPE_CALENDAR.toString(), eventType.caldavEmail)
|
|
||||||
var maxId = 1
|
|
||||||
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
maxId = Math.max(maxId, cursor.getIntValue(CalendarContract.Colors.COLOR_KEY))
|
|
||||||
} while (cursor.moveToNext())
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxId
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getAvailableCalDAVCalendarColors(eventType: EventType): ArrayList<Int> {
|
fun getAvailableCalDAVCalendarColors(eventType: EventType): ArrayList<Int> {
|
||||||
val colors = SparseIntArray()
|
val colors = SparseIntArray()
|
||||||
val uri = CalendarContract.Colors.CONTENT_URI
|
val uri = CalendarContract.Colors.CONTENT_URI
|
||||||
@@ -307,9 +260,7 @@ class CalDAVHandler(val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventIdsToDelete.forEach {
|
context.dbHelper.deleteEvents(eventIdsToDelete.toTypedArray(), false)
|
||||||
context.dbHelper.deleteEvents(eventIdsToDelete.toTypedArray(), false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertCalDAVEvent(event: Event) {
|
fun insertCalDAVEvent(event: Event) {
|
||||||
|
@@ -52,7 +52,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
get() = prefs.getInt(VIEW, MONTHLY_VIEW)
|
get() = prefs.getInt(VIEW, MONTHLY_VIEW)
|
||||||
set(view) = prefs.edit().putInt(VIEW, view).apply()
|
set(view) = prefs.edit().putInt(VIEW, view).apply()
|
||||||
|
|
||||||
var lastEventReminderMinutes: Int
|
var lastEventReminderMinutes1: Int
|
||||||
get() = prefs.getInt(LAST_EVENT_REMINDER_MINUTES, 10)
|
get() = prefs.getInt(LAST_EVENT_REMINDER_MINUTES, 10)
|
||||||
set(lastEventReminderMinutes) = prefs.edit().putInt(LAST_EVENT_REMINDER_MINUTES, lastEventReminderMinutes).apply()
|
set(lastEventReminderMinutes) = prefs.edit().putInt(LAST_EVENT_REMINDER_MINUTES, lastEventReminderMinutes).apply()
|
||||||
|
|
||||||
|
@@ -569,7 +569,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteEventTypes(eventTypes: ArrayList<EventType>, deleteEvents: Boolean, callback: (deletedCnt: Int) -> Unit) {
|
fun deleteEventTypes(eventTypes: ArrayList<EventType>, deleteEvents: Boolean, callback: (deletedCnt: Int) -> Unit) {
|
||||||
var deleteIds = eventTypes.filter { it.caldavCalendarId == 0 }.map { it.id }
|
var deleteIds = eventTypes.asSequence().filter { it.caldavCalendarId == 0 }.map { it.id }.toList()
|
||||||
deleteIds = deleteIds.filter { it != DBHelper.REGULAR_EVENT_TYPE_ID } as ArrayList<Int>
|
deleteIds = deleteIds.filter { it != DBHelper.REGULAR_EVENT_TYPE_ID } as ArrayList<Int>
|
||||||
|
|
||||||
val deletedSet = HashSet<String>()
|
val deletedSet = HashSet<String>()
|
||||||
@@ -693,8 +693,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
if (applyTypeFilter) {
|
if (applyTypeFilter) {
|
||||||
val displayEventTypes = context.config.displayEventTypes
|
val displayEventTypes = context.config.displayEventTypes
|
||||||
if (displayEventTypes.isNotEmpty()) {
|
if (displayEventTypes.isNotEmpty()) {
|
||||||
val types = displayEventTypes.joinToString(",", "(", ")")
|
val types = TextUtils.join(",", displayEventTypes)
|
||||||
selection += " AND $COL_EVENT_TYPE IN $types"
|
selection += " AND $COL_EVENT_TYPE IN ($types)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,7 +717,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Int = -1, applyTypeFilter: Boolean = false): List<Event> {
|
fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Int = -1, applyTypeFilter: Boolean = false): List<Event> {
|
||||||
val newEvents = ArrayList<Event>()
|
val newEvents = ArrayList<Event>()
|
||||||
|
|
||||||
// get repeatable events
|
|
||||||
var selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS <= $toTS AND $COL_START_TS != 0"
|
var selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS <= $toTS AND $COL_START_TS != 0"
|
||||||
if (eventId != -1)
|
if (eventId != -1)
|
||||||
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
|
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
|
||||||
@@ -725,8 +724,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
if (applyTypeFilter) {
|
if (applyTypeFilter) {
|
||||||
val displayEventTypes = context.config.displayEventTypes
|
val displayEventTypes = context.config.displayEventTypes
|
||||||
if (displayEventTypes.isNotEmpty()) {
|
if (displayEventTypes.isNotEmpty()) {
|
||||||
val types = displayEventTypes.joinToString(",", "(", ")")
|
val types = TextUtils.join(",", displayEventTypes)
|
||||||
selection += " AND $COL_EVENT_TYPE IN $types"
|
selection += " AND $COL_EVENT_TYPE IN ($types)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -819,8 +818,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
if (applyTypeFilter) {
|
if (applyTypeFilter) {
|
||||||
val displayEventTypes = context.config.displayEventTypes
|
val displayEventTypes = context.config.displayEventTypes
|
||||||
if (displayEventTypes.isNotEmpty()) {
|
if (displayEventTypes.isNotEmpty()) {
|
||||||
val types = displayEventTypes.joinToString(",", "(", ")")
|
val types = TextUtils.join(",", displayEventTypes)
|
||||||
selection += " AND $COL_EVENT_TYPE IN $types"
|
selection += " AND $COL_EVENT_TYPE IN ($types)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -830,7 +829,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if its the proper week, for events repeating by x weeks
|
// check if its the proper week, for events repeating every x weeks
|
||||||
private fun isOnProperWeek(event: Event, startTimes: SparseIntArray): Boolean {
|
private fun isOnProperWeek(event: Event, startTimes: SparseIntArray): Boolean {
|
||||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
||||||
val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
|
val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
|
||||||
|
@@ -140,8 +140,8 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||||||
|
|
||||||
val eventType = eventTypes.firstOrNull { it.id == curEventTypeId }
|
val eventType = eventTypes.firstOrNull { it.id == curEventTypeId }
|
||||||
val source = if (calDAVCalendarId == 0 || eventType?.isSyncedEventType() == false) SOURCE_IMPORTED_ICS else "$CALDAV-$calDAVCalendarId"
|
val source = if (calDAVCalendarId == 0 || eventType?.isSyncedEventType() == false) SOURCE_IMPORTED_ICS else "$CALDAV-$calDAVCalendarId"
|
||||||
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }),
|
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0) { -1 },
|
||||||
curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval,
|
curReminderMinutes.getOrElse(1) { -1 }, curReminderMinutes.getOrElse(2) { -1 }, curRepeatInterval,
|
||||||
curImportId, curFlags, curRepeatLimit, curRepeatRule, curEventTypeId, lastUpdated = curLastModified,
|
curImportId, curFlags, curRepeatLimit, curRepeatRule, curEventTypeId, lastUpdated = curLastModified,
|
||||||
source = source, location = curLocation)
|
source = source, location = curLocation)
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ import org.joda.time.DateTime
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context) {
|
class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) {
|
||||||
private val DAYS_CNT = 42
|
private val DAYS_CNT = 42
|
||||||
private val YEAR_PATTERN = "YYYY"
|
private val YEAR_PATTERN = "YYYY"
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
mTargetDate = targetDate
|
mTargetDate = targetDate
|
||||||
val startTS = mTargetDate.minusDays(7).seconds()
|
val startTS = mTargetDate.minusDays(7).seconds()
|
||||||
val endTS = mTargetDate.plusDays(43).seconds()
|
val endTS = mTargetDate.plusDays(43).seconds()
|
||||||
mContext.dbHelper.getEvents(startTS, endTS, applyTypeFilter = true) {
|
context.dbHelper.getEvents(startTS, endTS, applyTypeFilter = true) {
|
||||||
gotEvents(it)
|
gotEvents(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
val days = ArrayList<DayMonthly>(DAYS_CNT)
|
val days = ArrayList<DayMonthly>(DAYS_CNT)
|
||||||
val currMonthDays = mTargetDate.dayOfMonth().maximumValue
|
val currMonthDays = mTargetDate.dayOfMonth().maximumValue
|
||||||
var firstDayIndex = mTargetDate.withDayOfMonth(1).dayOfWeek
|
var firstDayIndex = mTargetDate.withDayOfMonth(1).dayOfWeek
|
||||||
if (!mContext.config.isSundayFirst)
|
if (!context.config.isSundayFirst)
|
||||||
firstDayIndex -= 1
|
firstDayIndex -= 1
|
||||||
val prevMonthDays = mTargetDate.minusMonths(1).dayOfMonth().maximumValue
|
val prevMonthDays = mTargetDate.minusMonths(1).dayOfMonth().maximumValue
|
||||||
|
|
||||||
@@ -76,13 +76,13 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
if (markDaysWithEvents) {
|
if (markDaysWithEvents) {
|
||||||
markDaysWithEvents(days)
|
markDaysWithEvents(days)
|
||||||
} else {
|
} else {
|
||||||
mCallback.updateMonthlyCalendar(mContext, monthName, days, false, mTargetDate)
|
callback.updateMonthlyCalendar(context, monthName, days, false, mTargetDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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>) {
|
||||||
mContext.dbHelper.getEventTypes {
|
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)
|
||||||
@@ -107,7 +107,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
days.filter { dayEvents.keys.contains(it.code) }.forEach {
|
days.filter { dayEvents.keys.contains(it.code) }.forEach {
|
||||||
it.dayEvents = dayEvents[it.code]!!
|
it.dayEvents = dayEvents[it.code]!!
|
||||||
}
|
}
|
||||||
mCallback.updateMonthlyCalendar(mContext, monthName, days, true, mTargetDate)
|
callback.updateMonthlyCalendar(context, monthName, days, true, mTargetDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
|
|
||||||
private val monthName: String
|
private val monthName: String
|
||||||
get() {
|
get() {
|
||||||
var month = Formatter.getMonthName(mContext, mTargetDate.monthOfYear)
|
var month = Formatter.getMonthName(context, mTargetDate.monthOfYear)
|
||||||
val targetYear = mTargetDate.toString(YEAR_PATTERN)
|
val targetYear = mTargetDate.toString(YEAR_PATTERN)
|
||||||
if (targetYear != DateTime().toString(YEAR_PATTERN)) {
|
if (targetYear != DateTime().toString(YEAR_PATTERN)) {
|
||||||
month += " $targetYear"
|
month += " $targetYear"
|
||||||
|
@@ -7,14 +7,14 @@ import com.simplemobiletools.calendar.models.Event
|
|||||||
import com.simplemobiletools.commons.helpers.WEEK_SECONDS
|
import com.simplemobiletools.commons.helpers.WEEK_SECONDS
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class WeeklyCalendarImpl(val mCallback: WeeklyCalendar, val mContext: Context) {
|
class WeeklyCalendarImpl(val callback: WeeklyCalendar, val context: Context) {
|
||||||
var mEvents = ArrayList<Event>()
|
var mEvents = ArrayList<Event>()
|
||||||
|
|
||||||
fun updateWeeklyCalendar(weekStartTS: Int) {
|
fun updateWeeklyCalendar(weekStartTS: Int) {
|
||||||
val endTS = weekStartTS + WEEK_SECONDS
|
val endTS = weekStartTS + WEEK_SECONDS
|
||||||
mContext.dbHelper.getEvents(weekStartTS, endTS, applyTypeFilter = true) {
|
context.dbHelper.getEvents(weekStartTS, endTS, applyTypeFilter = true) {
|
||||||
mEvents = it
|
mEvents = it
|
||||||
mCallback.updateWeeklyCalendar(it)
|
callback.updateWeeklyCalendar(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
private var paint: Paint
|
private var paint: Paint
|
||||||
private var eventTitlePaint: TextPaint
|
private var eventTitlePaint: TextPaint
|
||||||
private var gridPaint: Paint
|
private var gridPaint: Paint
|
||||||
|
private var config = context.config
|
||||||
private var dayWidth = 0f
|
private var dayWidth = 0f
|
||||||
private var dayHeight = 0f
|
private var dayHeight = 0f
|
||||||
private var primaryColor = 0
|
private var primaryColor = 0
|
||||||
@@ -54,9 +55,9 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
primaryColor = context.getAdjustedPrimaryColor()
|
primaryColor = context.getAdjustedPrimaryColor()
|
||||||
textColor = context.config.textColor
|
textColor = config.textColor
|
||||||
showWeekNumbers = context.config.showWeekNumbers
|
showWeekNumbers = config.showWeekNumbers
|
||||||
dimPastEvents = context.config.dimPastEvents
|
dimPastEvents = config.dimPastEvents
|
||||||
|
|
||||||
smallPadding = resources.displayMetrics.density.toInt()
|
smallPadding = resources.displayMetrics.density.toInt()
|
||||||
val normalTextSize = resources.getDimensionPixelSize(R.dimen.normal_text_size)
|
val normalTextSize = resources.getDimensionPixelSize(R.dimen.normal_text_size)
|
||||||
@@ -86,7 +87,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
|
|
||||||
fun updateDays(newDays: ArrayList<DayMonthly>) {
|
fun updateDays(newDays: ArrayList<DayMonthly>) {
|
||||||
days = newDays
|
days = newDays
|
||||||
showWeekNumbers = context.config.showWeekNumbers
|
showWeekNumbers = config.showWeekNumbers
|
||||||
horizontalOffset = if (showWeekNumbers) eventTitleHeight * 2 else 0
|
horizontalOffset = if (showWeekNumbers) eventTitleHeight * 2 else 0
|
||||||
initWeekDayLetters()
|
initWeekDayLetters()
|
||||||
setupCurrentDayOfWeekIndex()
|
setupCurrentDayOfWeekIndex()
|
||||||
@@ -111,7 +112,8 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allEvents = allEvents.sortedWith(compareBy({ -it.daysCnt }, { !it.isAllDay }, { it.startTS }, { it.startDayIndex }, { it.title })).toMutableList() as ArrayList<MonthViewEvent>
|
allEvents = allEvents.asSequence().sortedWith(compareBy({ -it.daysCnt }, { !it.isAllDay }, { it.startTS }, { it.startDayIndex }, { it.title }))
|
||||||
|
.toMutableList() as ArrayList<MonthViewEvent>
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
@@ -119,7 +121,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
dayVerticalOffsets.clear()
|
dayVerticalOffsets.clear()
|
||||||
measureDaySize(canvas)
|
measureDaySize(canvas)
|
||||||
|
|
||||||
if (context.config.showGrid) {
|
if (config.showGrid) {
|
||||||
drawGrid(canvas)
|
drawGrid(canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +151,9 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawEvents(canvas)
|
for (event in allEvents) {
|
||||||
|
drawEvent(event, canvas)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawGrid(canvas: Canvas) {
|
private fun drawGrid(canvas: Canvas) {
|
||||||
@@ -188,7 +192,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
val weekDays = days.subList(i * 7, i * 7 + 7)
|
val weekDays = days.subList(i * 7, i * 7 + 7)
|
||||||
weekNumberPaint.color = if (weekDays.any { it.isToday }) primaryColor else textColor
|
weekNumberPaint.color = if (weekDays.any { it.isToday }) primaryColor else textColor
|
||||||
|
|
||||||
// fourth day of the week matters
|
// fourth day of the week determines the week of the year number
|
||||||
val weekOfYear = days.getOrNull(i * 7 + 3)?.weekOfYear ?: 1
|
val weekOfYear = days.getOrNull(i * 7 + 3)?.weekOfYear ?: 1
|
||||||
val id = "$weekOfYear:"
|
val id = "$weekOfYear:"
|
||||||
val yPos = i * dayHeight + weekDaysLetterHeight
|
val yPos = i * dayHeight + weekDaysLetterHeight
|
||||||
@@ -203,12 +207,6 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
maxEventsPerDay = availableHeightForEvents / eventTitleHeight
|
maxEventsPerDay = availableHeightForEvents / eventTitleHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawEvents(canvas: Canvas) {
|
|
||||||
for (event in allEvents) {
|
|
||||||
drawEvent(event, canvas)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun drawEvent(event: MonthViewEvent, canvas: Canvas) {
|
private fun drawEvent(event: MonthViewEvent, canvas: Canvas) {
|
||||||
val verticalOffset = dayVerticalOffsets[event.startDayIndex]
|
val verticalOffset = dayVerticalOffsets[event.startDayIndex]
|
||||||
val xPos = event.startDayIndex % 7 * dayWidth + horizontalOffset
|
val xPos = event.startDayIndex % 7 * dayWidth + horizontalOffset
|
||||||
@@ -303,7 +301,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
|
|
||||||
private fun initWeekDayLetters() {
|
private fun initWeekDayLetters() {
|
||||||
dayLetters = context.resources.getStringArray(R.array.week_day_letters).toMutableList() as ArrayList<String>
|
dayLetters = context.resources.getStringArray(R.array.week_day_letters).toMutableList() as ArrayList<String>
|
||||||
if (context.config.isSundayFirst) {
|
if (config.isSundayFirst) {
|
||||||
dayLetters.moveLastItemToFront()
|
dayLetters.moveLastItemToFront()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,7 +313,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
}
|
}
|
||||||
|
|
||||||
currDayOfWeek = DateTime().dayOfWeek
|
currDayOfWeek = DateTime().dayOfWeek
|
||||||
if (context.config.isSundayFirst) {
|
if (config.isSundayFirst) {
|
||||||
currDayOfWeek %= 7
|
currDayOfWeek %= 7
|
||||||
} else {
|
} else {
|
||||||
currDayOfWeek--
|
currDayOfWeek--
|
||||||
|
@@ -15,11 +15,11 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
|
|||||||
private var dayWidth = 0f
|
private var dayWidth = 0f
|
||||||
private var dayHeight = 0f
|
private var dayHeight = 0f
|
||||||
private var weekDaysLetterHeight = 0
|
private var weekDaysLetterHeight = 0
|
||||||
|
private var horizontalOffset = 0
|
||||||
private var wereViewsAdded = false
|
private var wereViewsAdded = false
|
||||||
private var days = ArrayList<DayMonthly>()
|
private var days = ArrayList<DayMonthly>()
|
||||||
private var inflater: LayoutInflater
|
private var inflater: LayoutInflater
|
||||||
private var monthView: MonthView
|
private var monthView: MonthView
|
||||||
private var horizontalOffset = 0
|
|
||||||
private var dayClickCallback: ((day: DayMonthly) -> Unit)? = null
|
private var dayClickCallback: ((day: DayMonthly) -> Unit)? = null
|
||||||
|
|
||||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||||
|
@@ -69,9 +69,9 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
if (dayWidth == 0f) {
|
if (dayWidth == 0f) {
|
||||||
dayWidth = if (isLandscape) {
|
dayWidth = if (isLandscape) {
|
||||||
(canvas.width / 9).toFloat()
|
width / 9f
|
||||||
} else {
|
} else {
|
||||||
(canvas.width / 7).toFloat()
|
width / 7f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user