Merge pull request #1312 from Yairks/master

Add option to update this and future occurrences
This commit is contained in:
Tibor Kaputa 2021-03-21 19:02:14 +01:00 committed by GitHub
commit cead17087f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 19 deletions

View File

@ -1135,13 +1135,8 @@ class EventActivity : SimpleActivity() {
private fun showEditRepeatingEventDialog() { private fun showEditRepeatingEventDialog() {
EditRepeatingEventDialog(this) { EditRepeatingEventDialog(this) {
if (it) { when (it) {
ensureBackgroundThread { 0 -> {
eventsHelper.updateEvent(mEvent, true, true) {
finish()
}
}
} else {
ensureBackgroundThread { ensureBackgroundThread {
eventsHelper.addEventRepetitionException(mEvent.id!!, mEventOccurrenceTS, true) eventsHelper.addEventRepetitionException(mEvent.id!!, mEventOccurrenceTS, true)
mEvent.apply { mEvent.apply {
@ -1157,6 +1152,27 @@ class EventActivity : SimpleActivity() {
} }
} }
} }
1 -> {
ensureBackgroundThread {
eventsHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
mEvent.apply {
id = null
}
eventsHelper.insertEvent(mEvent, true, true) {
finish()
}
}
}
2 -> {
ensureBackgroundThread {
eventsHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
eventsHelper.updateEvent(mEvent, true, true) {
finish()
}
}
}
}
} }
} }

View File

@ -8,13 +8,14 @@ import com.simplemobiletools.commons.extensions.hideKeyboard
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_edit_repeating_event.view.* import kotlinx.android.synthetic.main.dialog_edit_repeating_event.view.*
class EditRepeatingEventDialog(val activity: SimpleActivity, val callback: (allOccurrences: Boolean) -> Unit) { class EditRepeatingEventDialog(val activity: SimpleActivity, val callback: (allOccurrences: Int) -> Unit) {
var dialog: AlertDialog var dialog: AlertDialog
init { init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_edit_repeating_event, null) as ViewGroup).apply { val view = (activity.layoutInflater.inflate(R.layout.dialog_edit_repeating_event, null) as ViewGroup).apply {
edit_repeating_event_one_only.setOnClickListener { sendResult(false) } edit_repeating_event_one_only.setOnClickListener { sendResult(0) }
edit_repeating_event_all_occurrences.setOnClickListener { sendResult(true) } edit_repeating_event_this_and_future_occurences.setOnClickListener { sendResult(1)}
edit_repeating_event_all_occurrences.setOnClickListener { sendResult(2) }
} }
dialog = AlertDialog.Builder(activity) dialog = AlertDialog.Builder(activity)
@ -25,7 +26,7 @@ class EditRepeatingEventDialog(val activity: SimpleActivity, val callback: (allO
} }
} }
private fun sendResult(allOccurrences: Boolean) { private fun sendResult(allOccurrences: Int) {
callback(allOccurrences) callback(allOccurrences)
dialog.dismiss() dialog.dismiss()
} }

View File

@ -30,6 +30,14 @@
android:paddingTop="@dimen/activity_margin" android:paddingTop="@dimen/activity_margin"
android:text="@string/update_one_only"/> android:text="@string/update_one_only"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/edit_repeating_event_this_and_future_occurences"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin"
android:text="@string/update_this_and_future_occurrences" />
<com.simplemobiletools.commons.views.MyCompatRadioButton <com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/edit_repeating_event_all_occurrences" android:id="@+id/edit_repeating_event_all_occurrences"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -51,6 +51,7 @@
<string name="delete_future_occurrences">Delete this and all future occurrences</string> <string name="delete_future_occurrences">Delete this and all future occurrences</string>
<string name="delete_all_occurrences">Delete all occurrences</string> <string name="delete_all_occurrences">Delete all occurrences</string>
<string name="update_one_only">Update the selected occurrence only</string> <string name="update_one_only">Update the selected occurrence only</string>
<string name="update_this_and_future_occurrences">Update this and all future occurrences</string>
<string name="update_all_occurrences">Update all occurrences</string> <string name="update_all_occurrences">Update all occurrences</string>
<string name="repeat_till_date">Repeat till a date</string> <string name="repeat_till_date">Repeat till a date</string>
<string name="stop_repeating_after_x">Stop repeating after x occurrences</string> <string name="stop_repeating_after_x">Stop repeating after x occurrences</string>