diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/View.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/View.kt new file mode 100644 index 000000000..b3eb6ee5d --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/View.kt @@ -0,0 +1,7 @@ +package com.simplemobiletools.calendar.extensions + +import android.view.View + +fun View.beVisibleIf(beVisible: Boolean) = if (beVisible) visibility = View.VISIBLE else visibility = View.GONE + +fun View.beGoneIf(beGone: Boolean) = if (beGone) visibility = View.GONE else visibility = View.VISIBLE 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 fb1bbd638..9ea09b5e5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt @@ -12,6 +12,8 @@ import com.simplemobiletools.calendar.Formatter import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.activities.MainActivity import com.simplemobiletools.calendar.adapters.EventsListAdapter +import com.simplemobiletools.calendar.extensions.beGoneIf +import com.simplemobiletools.calendar.extensions.beVisibleIf import com.simplemobiletools.calendar.extensions.updateWidget import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.models.ListEvent @@ -27,6 +29,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, AdapterView.On var mSelectedItemsCnt = 0 var mListItems: ArrayList = ArrayList() + var mAllEvents: MutableList? = null lateinit var mToBeDeleted: MutableList lateinit var mView: View @@ -62,6 +65,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, AdapterView.On mListItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description)) } + mAllEvents = events val eventsAdapter = EventsListAdapter(context, mListItems) activity?.runOnUiThread { mView.calendar_events_list.apply { @@ -69,10 +73,20 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, AdapterView.On onItemClickListener = this@EventListFragment setMultiChoiceModeListener(this@EventListFragment) } + checkPlaceholderVisibility() } } - private fun getEventsToShow(events: MutableList): List { + private fun checkPlaceholderVisibility() { + val events = getEventsToShow(mAllEvents) + mView.calendar_empty_list_placeholder.beVisibleIf(events.isEmpty()) + mView.calendar_events_list.beGoneIf(events.isEmpty()) + } + + private fun getEventsToShow(events: MutableList?): List { + if (events == null) + return ArrayList() + return events.filter { !mToBeDeleted.contains(it.id) } } @@ -116,6 +130,9 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, AdapterView.On } fun deleteEvents() { + if (activity == null) + return + val eventIDs = Array(mToBeDeleted.size, { i -> (mToBeDeleted[i].toString()) }) DBHelper(activity.applicationContext, this).deleteEvents(eventIDs) mToBeDeleted.clear() @@ -173,6 +190,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, AdapterView.On } override fun eventsDeleted(cnt: Int) { + checkPlaceholderVisibility() context.updateWidget() } diff --git a/app/src/main/res/layout/fragment_event_list.xml b/app/src/main/res/layout/fragment_event_list.xml index 06e4852ee..e6ce89875 100644 --- a/app/src/main/res/layout/fragment_event_list.xml +++ b/app/src/main/res/layout/fragment_event_list.xml @@ -1,11 +1,29 @@ - + android:layout_height="match_parent"> + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0e9571540..104a1d278 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -8,6 +8,7 @@ Monatsansicht Jahresansicht Simple event list + Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom. Termin diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 495fadc21..6fe82bce0 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -8,6 +8,7 @@ Monthly view Yearly view Simple event list + Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom. Evento diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 84a55173c..f448e7e1e 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -8,6 +8,7 @@ Monthly view Yearly view Simple event list + Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom. イベント diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 779fcc230..3688f8b4a 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -8,6 +8,7 @@ Monthly view Yearly view Simple event list + Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom. Evento diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 353d5c581..a039e245d 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -8,6 +8,7 @@ Monthly view Yearly view Simple event list + Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom. Händelse diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index ed0d576d0..aa8b4a8fb 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,5 +1,6 @@ 16dp + 24dp 4dp 8dp 8dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a6d67830c..2dc497e13 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,6 +8,7 @@ Monthly view Yearly view Simple event list + Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom. Event