mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
allow Editing events
This commit is contained in:
@@ -22,6 +22,7 @@ import com.simplemobiletools.calendar.DBHelper;
|
||||
import com.simplemobiletools.calendar.Formatter;
|
||||
import com.simplemobiletools.calendar.R;
|
||||
import com.simplemobiletools.calendar.Utils;
|
||||
import com.simplemobiletools.calendar.fragments.DayFragment;
|
||||
import com.simplemobiletools.calendar.models.Event;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
@@ -204,7 +205,7 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
||||
|
||||
private void deleteEvent() {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(DayActivity.Companion.getDELETED_ID(), mEvent.getId());
|
||||
intent.putExtra(DayFragment.Companion.getDELETED_ID(), mEvent.getId());
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
@@ -380,6 +381,7 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
||||
public void eventUpdated(Event event) {
|
||||
Utils.scheduleNotification(getApplicationContext(), event);
|
||||
Utils.showToast(getApplicationContext(), R.string.event_updated);
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,6 @@ import com.simplemobiletools.calendar.Formatter
|
||||
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.*
|
||||
@@ -19,15 +18,10 @@ import java.util.*
|
||||
class DayActivity : SimpleActivity(), DayFragment.DeleteListener, ViewPager.OnPageChangeListener {
|
||||
private val PREFILLED_DAYS = 61
|
||||
private var mDayCode: String? = null
|
||||
private var mEvents: MutableList<Event>? = null
|
||||
private var mSnackbar: Snackbar? = null
|
||||
private var mPagerDays: MutableList<String>? = null
|
||||
private var mPagerPos = 0
|
||||
|
||||
companion object {
|
||||
val DELETED_ID = "deleted_id"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_day)
|
||||
@@ -72,17 +66,6 @@ class DayActivity : SimpleActivity(), DayFragment.DeleteListener, ViewPager.OnPa
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
/*if (requestCode == EDIT_EVENT && resultCode == Activity.RESULT_OK && data != null) {
|
||||
val deletedId = data.getIntExtra(DELETED_ID, -1)
|
||||
if (deletedId != -1) {
|
||||
mToBeDeleted!!.clear()
|
||||
mToBeDeleted!!.add(deletedId)
|
||||
notifyEventDeletion(1)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun checkDeleteEvents() {
|
||||
if (mSnackbar != null && mSnackbar!!.isShown) {
|
||||
deleteEvents()
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.simplemobiletools.calendar.fragments
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
@@ -7,6 +8,7 @@ import android.graphics.PorterDuff
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.widget.AbsListView
|
||||
import android.widget.AdapterView
|
||||
@@ -35,6 +37,10 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
lateinit var mConfig: Config
|
||||
lateinit var mToBeDeleted: MutableList<Int>
|
||||
|
||||
companion object {
|
||||
val DELETED_ID = "deleted_id"
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater!!.inflate(R.layout.day_fragment, container, false)
|
||||
mRes = resources
|
||||
@@ -112,6 +118,9 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
}
|
||||
|
||||
private fun updateEvents(events: MutableList<Event>) {
|
||||
for (e in events) {
|
||||
Log.e("DEBUG", "GOT EVENT $e")
|
||||
}
|
||||
mEvents = ArrayList(events)
|
||||
val eventsToShow = getEventsToShow(events)
|
||||
val eventsAdapter = EventsAdapter(activity.baseContext, eventsToShow)
|
||||
@@ -128,6 +137,21 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
startActivityForResult(intent, EDIT_EVENT)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == EDIT_EVENT && resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
checkEvents()
|
||||
} else {
|
||||
val deletedId = data.getIntExtra(DELETED_ID, -1)
|
||||
if (deletedId != -1) {
|
||||
mToBeDeleted.clear()
|
||||
mToBeDeleted.add(deletedId)
|
||||
notifyDeletion()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getEventsToShow(events: MutableList<Event>): List<Event> {
|
||||
return events.filter { !mToBeDeleted.contains(it.id) }
|
||||
}
|
||||
@@ -141,6 +165,10 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
}
|
||||
}
|
||||
|
||||
notifyDeletion()
|
||||
}
|
||||
|
||||
private fun notifyDeletion() {
|
||||
mListener?.notifyDeletion(mToBeDeleted.size)
|
||||
updateEvents(mEvents!!)
|
||||
}
|
||||
|
Reference in New Issue
Block a user