avoid showing unwritable calendars in some places

This commit is contained in:
tibbi 2019-02-13 22:22:26 +01:00
parent e11f940293
commit ee73674468
10 changed files with 21 additions and 13 deletions

View file

@ -548,7 +548,7 @@ class EventActivity : SimpleActivity() {
private fun showEventTypeDialog() {
hideKeyboard()
SelectEventTypeDialog(this, mEventTypeId, false, true, false) {
SelectEventTypeDialog(this, mEventTypeId, false, true, false, true) {
mEventTypeId = it.id!!
updateEventType()
}
@ -613,7 +613,7 @@ class EventActivity : SimpleActivity() {
event_caldav_calendar_divider.beVisible()
val calendars = calDAVHelper.getCalDAVCalendars("", true).filter {
config.getSyncedCalendarIdsAsList().contains(it.id)
it.canWrite() && config.getSyncedCalendarIdsAsList().contains(it.id)
}
updateCurrentCalendarInfo(if (mEventCalendarId == STORED_LOCALLY_ONLY) null else getCalendarWithId(calendars, getCalendarId()))

View file

@ -105,7 +105,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
updateViewPager()
}
eventsHelper.getEventTypes(this) {
eventsHelper.getEventTypes(this, false) {
val newShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty()
if (newShouldFilterBeVisible != mShouldFilterBeVisible) {
mShouldFilterBeVisible = newShouldFilterBeVisible

View file

@ -30,7 +30,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
}
private fun getEventTypes() {
eventsHelper.getEventTypes(this) {
eventsHelper.getEventTypes(this, false) {
val adapter = ManageEventTypesAdapter(this, it, this, manage_event_types_list) {
showEventTypeDialog(it as EventType)
}

View file

@ -617,7 +617,7 @@ class SettingsActivity : SimpleActivity() {
updateDefaultEventTypeText()
settings_default_event_type.text = getString(R.string.last_used_one)
settings_default_event_type_holder.setOnClickListener {
SelectEventTypeDialog(this, config.defaultEventTypeId, true, false, true) {
SelectEventTypeDialog(this, config.defaultEventTypeId, true, false, true, true) {
config.defaultEventTypeId = it.id!!
updateDefaultEventTypeText()
}

View file

@ -19,7 +19,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal
export_events_folder.text = activity.humanizePath(path)
export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}")
activity.eventsHelper.getEventTypes(activity) {
activity.eventsHelper.getEventTypes(activity, false) {
val eventTypes = HashSet<String>()
it.mapTo(eventTypes) { it.id.toString() }

View file

@ -14,7 +14,7 @@ class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> U
private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null)
init {
activity.eventsHelper.getEventTypes(activity) {
activity.eventsHelper.getEventTypes(activity, false) {
val displayEventTypes = activity.config.displayEventTypes
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)

View file

@ -49,7 +49,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_events, null) as ViewGroup).apply {
updateEventType(this)
import_event_type_holder.setOnClickListener {
SelectEventTypeDialog(activity, currEventTypeId, true, true, false) {
SelectEventTypeDialog(activity, currEventTypeId, true, true, false, true) {
currEventTypeId = it.id!!
currEventTypeCalDAVCalendarId = it.caldavCalendarId

View file

@ -19,7 +19,7 @@ import kotlinx.android.synthetic.main.radio_button_with_color.view.*
import java.util.*
class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val showCalDAVCalendars: Boolean, val showNewEventTypeOption: Boolean,
val addLastUsedOneAsFirstOption: Boolean, val callback: (eventType: EventType) -> Unit) {
val addLastUsedOneAsFirstOption: Boolean, val showOnlyWritable: Boolean, val callback: (eventType: EventType) -> Unit) {
private val NEW_EVENT_TYPE_ID = -2L
private val LAST_USED_EVENT_TYPE_ID = -1L
@ -32,7 +32,7 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
radioGroup = view.dialog_radio_group
activity.eventsHelper.getEventTypes(activity) {
activity.eventsHelper.getEventTypes(activity, showOnlyWritable) {
eventTypes = it
activity.runOnUiThread {
if (addLastUsedOneAsFirstOption) {

View file

@ -67,7 +67,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
context!!.eventsHelper.getEventTypes(activity!!) {
context!!.eventsHelper.getEventTypes(activity!!, false) {
it.map { eventTypeColors.put(it.id!!, it.color) }
}

View file

@ -13,9 +13,17 @@ class EventsHelper(val context: Context) {
private val eventsDB = context.eventsDB
private val eventTypesDB = context.eventTypesDB
fun getEventTypes(activity: Activity, callback: (notes: ArrayList<EventType>) -> Unit) {
fun getEventTypes(activity: Activity, showWritableOnly: Boolean, callback: (notes: ArrayList<EventType>) -> Unit) {
Thread {
val eventTypes = eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
var eventTypes = eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
if (showWritableOnly) {
val caldavCalendars = activity.calDAVHelper.getCalDAVCalendars("", true)
eventTypes = eventTypes.filter {
val eventType = it
it.caldavCalendarId == 0 || caldavCalendars.firstOrNull { it.id == eventType.caldavCalendarId }?.canWrite() == true
}.toMutableList() as ArrayList<EventType>
}
activity.runOnUiThread {
callback(eventTypes)
}