add some event deletion related code
This commit is contained in:
parent
92048e5342
commit
78bd16252e
|
@ -1,26 +1,25 @@
|
|||
package com.simplemobiletools.calendar.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.view.View
|
||||
import com.simplemobiletools.calendar.Constants
|
||||
import com.simplemobiletools.calendar.Formatter
|
||||
import com.simplemobiletools.calendar.NavigationListener
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter
|
||||
import com.simplemobiletools.calendar.fragments.DayFragment
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import kotlinx.android.synthetic.main.activity_day.*
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class DayActivity : SimpleActivity(), NavigationListener {
|
||||
|
||||
class DayActivity : SimpleActivity(), DayFragment.DeleteListener {
|
||||
private val PREFILLED_DAYS = 61
|
||||
private var mDayCode: String? = null
|
||||
private var mEvents: MutableList<Event>? = null
|
||||
private var mSnackbar: Snackbar? = null
|
||||
private var mToBeDeleted: MutableList<Int>? = null
|
||||
private var mPagerDays: MutableList<String>? = null
|
||||
|
||||
companion object {
|
||||
|
@ -39,8 +38,6 @@ class DayActivity : SimpleActivity(), NavigationListener {
|
|||
fillViewPager(mDayCode!!)
|
||||
|
||||
day_fab.setOnClickListener { addNewEvent() }
|
||||
|
||||
//mToBeDeleted = ArrayList<Int>()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -123,7 +120,7 @@ class DayActivity : SimpleActivity(), NavigationListener {
|
|||
|
||||
private fun undoDeletion() {
|
||||
if (mSnackbar != null) {
|
||||
mToBeDeleted!!.clear()
|
||||
//mToBeDeleted!!.clear()
|
||||
mSnackbar!!.dismiss()
|
||||
//updateEvents(mEvents)
|
||||
}
|
||||
|
@ -162,4 +159,12 @@ class DayActivity : SimpleActivity(), NavigationListener {
|
|||
override fun goToDateTime(dateTime: DateTime) {
|
||||
fillViewPager(Formatter.getDayCodeFromDateTime(dateTime))
|
||||
}
|
||||
|
||||
override fun notifyDeletion(cnt: Int) {
|
||||
val msg = resources.getQuantityString(R.plurals.events_deleted, cnt, cnt)
|
||||
mSnackbar = Snackbar.make(day_coordinator, msg, Snackbar.LENGTH_INDEFINITE)
|
||||
mSnackbar!!.setAction(resources.getString(R.string.undo), undoDeletion)
|
||||
mSnackbar!!.setActionTextColor(Color.WHITE)
|
||||
mSnackbar!!.show()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@ import android.support.v4.app.Fragment
|
|||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.app.FragmentStatePagerAdapter
|
||||
import com.simplemobiletools.calendar.Constants
|
||||
import com.simplemobiletools.calendar.NavigationListener
|
||||
import com.simplemobiletools.calendar.fragments.DayFragment
|
||||
|
||||
class MyDayPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: NavigationListener) :
|
||||
class MyDayPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: DayFragment.DeleteListener) :
|
||||
FragmentStatePagerAdapter(fm) {
|
||||
|
||||
override fun getCount(): Int {
|
||||
|
|
|
@ -21,19 +21,19 @@ import kotlinx.android.synthetic.main.day_fragment.view.*
|
|||
import kotlinx.android.synthetic.main.top_navigation.view.*
|
||||
import java.util.*
|
||||
|
||||
class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnItemClickListener,
|
||||
AbsListView.MultiChoiceModeListener {
|
||||
class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnItemClickListener, AbsListView.MultiChoiceModeListener {
|
||||
private val EDIT_EVENT = 1
|
||||
|
||||
private var mTextColor: Int = 0
|
||||
private var mSelectedItemsCnt: Int = 0
|
||||
private var mDayCode: String = ""
|
||||
private var mEvents: MutableList<Event>? = null
|
||||
private var mListener: NavigationListener? = null
|
||||
private var mListener: DeleteListener? = null
|
||||
|
||||
lateinit var mRes: Resources
|
||||
lateinit var mHolder: RelativeLayout
|
||||
lateinit var mConfig: Config
|
||||
lateinit var mToBeDeleted: MutableList<Int>
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater!!.inflate(R.layout.day_fragment, container, false)
|
||||
|
@ -53,6 +53,7 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
|||
|
||||
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mToBeDeleted = ArrayList<Int>()
|
||||
checkEvents()
|
||||
}
|
||||
|
||||
|
@ -76,7 +77,7 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
|||
}
|
||||
}
|
||||
|
||||
fun setListener(listener: NavigationListener) {
|
||||
fun setListener(listener: DeleteListener) {
|
||||
mListener = listener
|
||||
}
|
||||
|
||||
|
@ -128,13 +129,20 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
|||
}
|
||||
|
||||
private fun getEventsToShow(events: MutableList<Event>): List<Event> {
|
||||
/*val cnt = events.size
|
||||
for (i in cnt - 1 downTo 0) {
|
||||
if (mToBeDeleted!!.contains(events[i].id)) {
|
||||
events.removeAt(i)
|
||||
return events.filter { !mToBeDeleted.contains(it.id) }
|
||||
}
|
||||
|
||||
private fun prepareDeleteEvents() {
|
||||
val checked = mHolder.day_events.checkedItemPositions
|
||||
for (i in mEvents!!.indices) {
|
||||
if (checked.get(i)) {
|
||||
val event = mEvents!![i]
|
||||
mToBeDeleted.add(event.id)
|
||||
}
|
||||
}*/
|
||||
return events
|
||||
}
|
||||
|
||||
mListener?.notifyDeletion(mToBeDeleted.size)
|
||||
updateEvents(mEvents!!)
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
|
@ -144,7 +152,7 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
|||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.delete -> {
|
||||
//prepareDeleteEvents()
|
||||
prepareDeleteEvents()
|
||||
mode.finish()
|
||||
return true
|
||||
}
|
||||
|
@ -193,4 +201,8 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
|||
override fun gotEvents(events: MutableList<Event>) {
|
||||
updateEvents(events)
|
||||
}
|
||||
|
||||
interface DeleteListener : NavigationListener {
|
||||
fun notifyDeletion(cnt: Int)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue