show a placeholder at event list in case its empty

This commit is contained in:
tibbi 2016-10-24 20:17:26 +02:00
parent de22b320fb
commit bcea981499
10 changed files with 59 additions and 9 deletions

View file

@ -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

View file

@ -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<ListItem> = ArrayList()
var mAllEvents: MutableList<Event>? = null
lateinit var mToBeDeleted: MutableList<Int>
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<Event>): List<Event> {
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<Event>?): List<Event> {
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()
}

View file

@ -1,11 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calendar_events_list"
android:id="@+id/calendar_events_list_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoiceModal"
android:clipToPadding="false"
android:divider="@null"
android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/medium_padding"/>
android:layout_height="match_parent">
<ListView
android:id="@+id/calendar_events_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoiceModal"
android:clipToPadding="false"
android:divider="@null"
android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/medium_padding"
android:visibility="gone"/>
<TextView
android:id="@+id/calendar_empty_list_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.5"
android:gravity="center_horizontal"
android:lineSpacingExtra="1dp"
android:padding="@dimen/big_margin"
android:text="@string/no_events_added"/>
</RelativeLayout>

View file

@ -8,6 +8,7 @@
<string name="monthly_view">Monatsansicht</string>
<string name="yearly_view">Jahresansicht</string>
<string name="simple_event_list">Simple event list</string>
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
<!-- Event -->
<string name="event">Termin</string>

View file

@ -8,6 +8,7 @@
<string name="monthly_view">Monthly view</string>
<string name="yearly_view">Yearly view</string>
<string name="simple_event_list">Simple event list</string>
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
<!-- Event -->
<string name="event">Evento</string>

View file

@ -8,6 +8,7 @@
<string name="monthly_view">Monthly view</string>
<string name="yearly_view">Yearly view</string>
<string name="simple_event_list">Simple event list</string>
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
<!-- Event -->
<string name="event">イベント</string>

View file

@ -8,6 +8,7 @@
<string name="monthly_view">Monthly view</string>
<string name="yearly_view">Yearly view</string>
<string name="simple_event_list">Simple event list</string>
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
<!-- Event -->
<string name="event">Evento</string>

View file

@ -8,6 +8,7 @@
<string name="monthly_view">Monthly view</string>
<string name="yearly_view">Yearly view</string>
<string name="simple_event_list">Simple event list</string>
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
<!-- Event -->
<string name="event">Händelse</string>

View file

@ -1,5 +1,6 @@
<resources>
<dimen name="activity_margin">16dp</dimen>
<dimen name="big_margin">24dp</dimen>
<dimen name="small_padding">4dp</dimen>
<dimen name="medium_padding">8dp</dimen>
<dimen name="social_padding">8dp</dimen>

View file

@ -8,6 +8,7 @@
<string name="monthly_view">Monthly view</string>
<string name="yearly_view">Yearly view</string>
<string name="simple_event_list">Simple event list</string>
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
<!-- Event -->
<string name="event">Event</string>