mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-04-02 20:41:15 +02:00
avoid showing unwritable calendars in some places
This commit is contained in:
parent
e11f940293
commit
ee73674468
@ -548,7 +548,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun showEventTypeDialog() {
|
private fun showEventTypeDialog() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
SelectEventTypeDialog(this, mEventTypeId, false, true, false) {
|
SelectEventTypeDialog(this, mEventTypeId, false, true, false, true) {
|
||||||
mEventTypeId = it.id!!
|
mEventTypeId = it.id!!
|
||||||
updateEventType()
|
updateEventType()
|
||||||
}
|
}
|
||||||
@ -613,7 +613,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
event_caldav_calendar_divider.beVisible()
|
event_caldav_calendar_divider.beVisible()
|
||||||
|
|
||||||
val calendars = calDAVHelper.getCalDAVCalendars("", true).filter {
|
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()))
|
updateCurrentCalendarInfo(if (mEventCalendarId == STORED_LOCALLY_ONLY) null else getCalendarWithId(calendars, getCalendarId()))
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
updateViewPager()
|
updateViewPager()
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsHelper.getEventTypes(this) {
|
eventsHelper.getEventTypes(this, false) {
|
||||||
val newShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty()
|
val newShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty()
|
||||||
if (newShouldFilterBeVisible != mShouldFilterBeVisible) {
|
if (newShouldFilterBeVisible != mShouldFilterBeVisible) {
|
||||||
mShouldFilterBeVisible = newShouldFilterBeVisible
|
mShouldFilterBeVisible = newShouldFilterBeVisible
|
||||||
|
@ -30,7 +30,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getEventTypes() {
|
private fun getEventTypes() {
|
||||||
eventsHelper.getEventTypes(this) {
|
eventsHelper.getEventTypes(this, false) {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -617,7 +617,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
updateDefaultEventTypeText()
|
updateDefaultEventTypeText()
|
||||||
settings_default_event_type.text = getString(R.string.last_used_one)
|
settings_default_event_type.text = getString(R.string.last_used_one)
|
||||||
settings_default_event_type_holder.setOnClickListener {
|
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!!
|
config.defaultEventTypeId = it.id!!
|
||||||
updateDefaultEventTypeText()
|
updateDefaultEventTypeText()
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ 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.eventsHelper.getEventTypes(activity) {
|
activity.eventsHelper.getEventTypes(activity, false) {
|
||||||
val eventTypes = HashSet<String>()
|
val eventTypes = HashSet<String>()
|
||||||
it.mapTo(eventTypes) { it.id.toString() }
|
it.mapTo(eventTypes) { it.id.toString() }
|
||||||
|
|
||||||
|
@ -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)
|
private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
activity.eventsHelper.getEventTypes(activity) {
|
activity.eventsHelper.getEventTypes(activity, false) {
|
||||||
val displayEventTypes = activity.config.displayEventTypes
|
val displayEventTypes = activity.config.displayEventTypes
|
||||||
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)
|
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)
|
||||||
|
|
||||||
|
@ -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 {
|
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_events, null) as ViewGroup).apply {
|
||||||
updateEventType(this)
|
updateEventType(this)
|
||||||
import_event_type_holder.setOnClickListener {
|
import_event_type_holder.setOnClickListener {
|
||||||
SelectEventTypeDialog(activity, currEventTypeId, true, true, false) {
|
SelectEventTypeDialog(activity, currEventTypeId, true, true, false, true) {
|
||||||
currEventTypeId = it.id!!
|
currEventTypeId = it.id!!
|
||||||
currEventTypeCalDAVCalendarId = it.caldavCalendarId
|
currEventTypeCalDAVCalendarId = it.caldavCalendarId
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import kotlinx.android.synthetic.main.radio_button_with_color.view.*
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val showCalDAVCalendars: Boolean, val showNewEventTypeOption: Boolean,
|
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 NEW_EVENT_TYPE_ID = -2L
|
||||||
private val LAST_USED_EVENT_TYPE_ID = -1L
|
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
|
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.eventsHelper.getEventTypes(activity) {
|
activity.eventsHelper.getEventTypes(activity, showOnlyWritable) {
|
||||||
eventTypes = it
|
eventTypes = it
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
if (addLastUsedOneAsFirstOption) {
|
if (addLastUsedOneAsFirstOption) {
|
||||||
|
@ -67,7 +67,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
context!!.eventsHelper.getEventTypes(activity!!) {
|
context!!.eventsHelper.getEventTypes(activity!!, false) {
|
||||||
it.map { eventTypeColors.put(it.id!!, it.color) }
|
it.map { eventTypeColors.put(it.id!!, it.color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,17 @@ class EventsHelper(val context: Context) {
|
|||||||
private val eventsDB = context.eventsDB
|
private val eventsDB = context.eventsDB
|
||||||
private val eventTypesDB = context.eventTypesDB
|
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 {
|
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 {
|
activity.runOnUiThread {
|
||||||
callback(eventTypes)
|
callback(eventTypes)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user