remove the UNDO function from event list too

This commit is contained in:
tibbi 2017-02-07 23:19:58 +01:00
parent 0572e61594
commit fda34a0df4
20 changed files with 31 additions and 118 deletions

View File

@ -3,14 +3,11 @@ package com.simplemobiletools.calendar.activities
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v4.app.ActivityCompat
import android.support.v4.view.ViewPager
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import com.simplemobiletools.calendar.BuildConfig
import com.simplemobiletools.calendar.R
@ -27,6 +24,7 @@ import com.simplemobiletools.calendar.fragments.EventListFragment
import com.simplemobiletools.calendar.fragments.WeekFragment
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.views.MyScrollView
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
@ -39,15 +37,13 @@ import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import java.util.*
class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
class MainActivity : SimpleActivity(), NavigationListener {
private val PREFILLED_MONTHS = 73
private val PREFILLED_YEARS = 21
private val PREFILLED_WEEKS = 41
private val STORAGE_PERMISSION = 1
private var mIsMonthSelected = false
private var mSnackbar: Snackbar? = null
private var mEventListFragment: EventListFragment? = null
private var mStoredTextColor = 0
private var mStoredBackgroundColor = 0
private var mStoredPrimaryColor = 0
@ -83,7 +79,6 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
override fun onPause() {
super.onPause()
checkDeleteEvents()
mStoredTextColor = config.textColor
mStoredIsSundayFirst = config.isSundayFirst
mStoredBackgroundColor = config.backgroundColor
@ -326,37 +321,12 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
return years
}
fun checkDeleteEvents() {
if (mSnackbar != null && mSnackbar!!.isShown) {
deleteEvents()
} else {
undoDeletion()
}
}
private fun deleteEvents() {
mSnackbar!!.dismiss()
mEventListFragment?.deleteEvents()
}
private val undoDeletion = View.OnClickListener { undoDeletion() }
private fun undoDeletion() {
if (mSnackbar != null) {
mSnackbar!!.dismiss()
mEventListFragment?.undoDeletion()
}
}
private fun fillEventsList() {
main_view_pager.adapter = null
main_view_pager.beGone()
main_weekly_scrollview.beGone()
calendar_event_list_holder.beVisible()
if (mEventListFragment == null)
mEventListFragment = EventListFragment()
supportFragmentManager.beginTransaction().replace(R.id.calendar_event_list_holder, mEventListFragment, "").commit()
supportFragmentManager.beginTransaction().replace(R.id.calendar_event_list_holder, EventListFragment(), "").commit()
}
override fun goLeft() {
@ -382,22 +352,6 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
}
}
override fun notifyDeletion(cnt: Int) {
val msg = resources.getQuantityString(R.plurals.events_deleted, cnt, cnt)
mSnackbar = Snackbar.make(calendar_coordinator, msg, Snackbar.LENGTH_LONG)
mSnackbar!!.apply {
setCallback(object : Snackbar.Callback() {
override fun onDismissed(snackbar: Snackbar?, event: Int) {
super.onDismissed(snackbar, event)
mEventListFragment?.deleteEvents()
}
})
setAction(resources.getString(R.string.undo), undoDeletion)
setActionTextColor(Color.WHITE)
show()
}
}
private fun checkWhatsNewDialog() {
arrayListOf<Release>().apply {
add(Release(39, R.string.release_39))

View File

@ -10,6 +10,7 @@ import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.beInvisible
@ -17,7 +18,7 @@ import com.simplemobiletools.commons.extensions.beInvisibleIf
import kotlinx.android.synthetic.main.event_item_day_view.view.*
import java.util.*
class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val listener: ItemOperationsListener?, val itemClick: (Event) -> Unit) :
class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val listener: DeleteEventsListener?, val itemClick: (Event) -> Unit) :
RecyclerView.Adapter<DayEventsAdapter.ViewHolder>() {
val multiSelector = MultiSelector()
val views = ArrayList<View>()
@ -81,7 +82,7 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
val selections = multiSelector.selectedPositions
val ids = ArrayList<Int>(selections.size)
selections.forEach { ids.add(mItems[it].id) }
listener?.deleteIds(ids)
listener?.deleteEvents(ids)
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
@ -162,8 +163,4 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
}
}
}
interface ItemOperationsListener {
fun deleteIds(ids: ArrayList<Int>)
}
}

View File

@ -11,6 +11,7 @@ import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.models.ListEvent
import com.simplemobiletools.calendar.models.ListItem
import com.simplemobiletools.calendar.models.ListSection
@ -20,7 +21,7 @@ import com.simplemobiletools.commons.extensions.beInvisibleIf
import kotlinx.android.synthetic.main.event_list_item.view.*
import java.util.*
class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>, val listener: EventListAdapter.ItemOperationsListener?, val itemClick: (Int) -> Unit) :
class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>, val listener: DeleteEventsListener?, val itemClick: (Int) -> Unit) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
val multiSelector = MultiSelector()
val views = ArrayList<View>()
@ -97,7 +98,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
val selections = multiSelector.selectedPositions
val ids = ArrayList<Int>(selections.size)
selections.forEach { ids.add((mItems[it] as ListEvent).id) }
listener?.prepareForDeleting(ids)
listener?.deleteEvents(ids)
}
override fun getItemViewType(position: Int) = if (mItems[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
@ -202,8 +203,4 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
return itemView
}
}
interface ItemOperationsListener {
fun prepareForDeleting(ids: ArrayList<Int>)
}
}

View File

@ -20,6 +20,7 @@ import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.extensions.setupDialogStuff
@ -30,7 +31,7 @@ import org.joda.time.DateTime
import java.util.*
import kotlin.comparisons.compareBy
class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEventsListener, DayEventsAdapter.ItemOperationsListener {
class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEventsListener, DeleteEventsListener {
private var mTextColor = 0
private var mDayCode = ""
private var mListener: NavigationListener? = null
@ -136,7 +137,7 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
}
}
override fun deleteIds(ids: ArrayList<Int>) {
override fun deleteEvents(ids: ArrayList<Int>) {
val eventIDs = Array(ids.size, { i -> (ids[i].toString()) })
DBHelper(activity.applicationContext, this).deleteEvents(eventIDs)
}

View File

@ -8,14 +8,13 @@ import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.EventListAdapter
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.ListEvent
import com.simplemobiletools.calendar.models.ListItem
@ -27,17 +26,15 @@ import org.joda.time.DateTime
import java.util.*
import kotlin.comparisons.compareBy
class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, EventListAdapter.ItemOperationsListener {
var mAllEvents: MutableList<Event>? = null
class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, DeleteEventsListener {
var mAllEvents: MutableList<Event> = ArrayList()
var prevEventsHash = 0
lateinit var mToBeDeleted: MutableList<Int>
lateinit var mView: View
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater!!.inflate(R.layout.fragment_event_list, container, false)
val placeholderText = String.format(getString(R.string.two_string_placeholder), "${getString(R.string.no_upcoming_events)}\n", getString(R.string.add_some_events))
mView.calendar_empty_list_placeholder.text = placeholderText
mToBeDeleted = ArrayList<Int>()
return mView
}
@ -54,13 +51,12 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
override fun gotEvents(events: MutableList<Event>) {
val hash = events.hashCode()
if (prevEventsHash == hash)
if (prevEventsHash == hash || context == null)
return
prevEventsHash = hash
val filtered = getEventsToShow(events)
val listItems = ArrayList<ListItem>(filtered.size)
val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
val listItems = ArrayList<ListItem>(events.size)
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
var prevCode = ""
sublist.forEach {
@ -75,7 +71,6 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
mAllEvents = events
val eventsAdapter = EventListAdapter(activity as SimpleActivity, listItems, this) {
(activity as MainActivity).checkDeleteEvents()
editEvent(it)
}
activity?.runOnUiThread {
@ -87,16 +82,8 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.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>?) = events?.filter { !mToBeDeleted.contains(it.id) } ?: ArrayList()
override fun prepareForDeleting(ids: ArrayList<Int>) {
mToBeDeleted = ids
notifyDeletion()
mView.calendar_empty_list_placeholder.beVisibleIf(mAllEvents.isEmpty())
mView.calendar_events_list.beGoneIf(mAllEvents.isEmpty())
}
private fun editEvent(eventId: Int) {
@ -106,23 +93,9 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
}
}
private fun notifyDeletion() {
(activity as MainActivity).notifyDeletion(mToBeDeleted.size)
checkEvents()
}
fun deleteEvents() {
if (activity == null)
return
val eventIDs = Array(mToBeDeleted.size, { i -> (mToBeDeleted[i].toString()) })
override fun deleteEvents(ids: ArrayList<Int>) {
val eventIDs = Array(ids.size, { i -> (ids[i].toString()) })
DBHelper(activity.applicationContext, this).deleteEvents(eventIDs)
mToBeDeleted.clear()
}
fun undoDeletion() {
mToBeDeleted.clear()
checkEvents()
}
override fun eventInserted(event: Event) {
@ -134,10 +107,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
}
override fun eventsDeleted(cnt: Int) {
checkEvents()
checkPlaceholderVisibility()
}
interface DeleteListener : NavigationListener {
fun notifyDeletion(cnt: Int)
}
}

View File

@ -285,7 +285,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
mView.week_top_holder.viewTreeObserver.removeOnGlobalLayoutListener(this)
if (isFragmentVisible) {
if (isFragmentVisible && activity != null) {
(activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height)
}
}

View File

@ -220,7 +220,6 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
val selectionArgs = arrayOf(toTS.toString(), fromTS.toString())
val cursor = getEventsCursor(selection, selectionArgs)
events.addAll(fillEvents(cursor))
callback?.gotEvents(events)
}

View File

@ -0,0 +1,7 @@
package com.simplemobiletools.calendar.interfaces
import java.util.*
interface DeleteEventsListener {
fun deleteEvents(ids: ArrayList<Int>)
}

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Schlichter Kalender</string>
<string name="app_launcher_name">Kalender</string>
<string name="undo">Rückgängig</string>
<string name="change_view">Ansicht ändern</string>
<string name="weekly_view">Wochenansicht</string>
<string name="monthly_view">Monatsansicht</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Calendario simple</string>
<string name="app_launcher_name">Calendario</string>
<string name="undo">Deshacer</string>
<string name="change_view">Cambiar vista</string>
<string name="weekly_view">Weekly view</string>
<string name="monthly_view">Vista mensual</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Simple Calendar</string>
<string name="app_launcher_name">Calendrier</string>
<string name="undo">Annuler</string>
<string name="change_view">Changer de vue</string>
<string name="weekly_view">Weekly view</string>
<string name="monthly_view">Vue mensuelle</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">सरल कैलेंडर</string>
<string name="app_launcher_name">कैलेंडर</string>
<string name="undo">पूर्ववत करें</string>
<string name="change_view">दृश्य बदले</string>
<string name="weekly_view">Weekly view</string>
<string name="monthly_view">मासिक दृश्य</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Egyszerű naptár</string>
<string name="app_launcher_name">Naptár</string>
<string name="undo">Visszavonás</string>
<string name="change_view">Nézet megváltoztatása</string>
<string name="weekly_view">Weekly view</string>
<string name="monthly_view">Havi nézet</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Simple Calendar</string>
<string name="app_launcher_name">Calendar</string>
<string name="undo">Annulla</string>
<string name="change_view">Change view</string>
<string name="weekly_view">Weekly view</string>
<string name="monthly_view">Monthly view</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">לוח שנה פשוט</string>
<string name="app_launcher_name">לוח שנה</string>
<string name="undo">בטל פעולה אחרונה</string>
<string name="change_view">שינוי תצפית</string>
<string name="weekly_view">תצפית שבועית</string>
<string name="monthly_view">תצפית חודשית</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">シンプル カレンダー</string>
<string name="app_launcher_name">カレンダー</string>
<string name="undo">元に戻す</string>
<string name="change_view">ビューの変更</string>
<string name="weekly_view">Weekly view</string>
<string name="monthly_view">月ビュー</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Simple Calendar</string>
<string name="app_launcher_name">Calendário</string>
<string name="undo">Desfazer</string>
<string name="change_view">Mudar vista</string>
<string name="weekly_view">Vista semanal</string>
<string name="monthly_view">Vista mensal</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Simple Calendar</string>
<string name="app_launcher_name">Календарь</string>
<string name="undo">Отменить</string>
<string name="change_view">Отображение</string>
<string name="weekly_view">На неделю</string>
<string name="monthly_view">На месяц</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Simple Calendar</string>
<string name="app_launcher_name">Kalender</string>
<string name="undo">Ångra</string>
<string name="change_view">Ändra vy</string>
<string name="weekly_view">Veckovy</string>
<string name="monthly_view">Månadsvy</string>

View File

@ -1,7 +1,6 @@
<resources>
<string name="app_name">Simple Calendar</string>
<string name="app_launcher_name">Calendar</string>
<string name="undo">Undo</string>
<string name="change_view">Change view</string>
<string name="weekly_view">Weekly view</string>
<string name="monthly_view">Monthly view</string>