Shows the same "Discard changes" as Simple Draw and doesn't show it if new event hasn't changed

This commit is contained in:
fnrngg
2020-06-08 15:18:49 +04:00
parent e6678cdf8d
commit 110250cf29
4 changed files with 33 additions and 87 deletions

View File

@@ -32,6 +32,7 @@ import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.models.* import com.simplemobiletools.calendar.pro.models.*
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
@@ -123,6 +124,9 @@ class EventActivity : SimpleActivity() {
} }
} }
private fun gotEvent(savedInstanceState: Bundle?, localEventType: EventType?, event: Event?) { private fun gotEvent(savedInstanceState: Bundle?, localEventType: EventType?, event: Event?) {
if (localEventType == null || localEventType.caldavCalendarId != 0) { if (localEventType == null || localEventType.caldavCalendarId != 0) {
config.lastUsedLocalEventTypeId = REGULAR_EVENT_TYPE_ID config.lastUsedLocalEventTypeId = REGULAR_EVENT_TYPE_ID
@@ -270,8 +274,8 @@ class EventActivity : SimpleActivity() {
} }
private fun isEventChanged(): Boolean { private fun isEventChanged(): Boolean {
var newStartTS = 0L var newStartTS: Long
var newEndTS = 0L var newEndTS: Long
getStartEndTimes().apply { getStartEndTimes().apply {
newStartTS = first newStartTS = first
newEndTS = second newEndTS = second
@@ -295,12 +299,11 @@ class EventActivity : SimpleActivity() {
override fun onBackPressed() { override fun onBackPressed() {
if (isEventChanged()) { if (isEventChanged()) {
CloseEditingDialog(this) { ConfirmationAdvancedDialog(this, "", R.string.save_before_closing, R.string.save, R.string.discard) {
when (it) { if (it) {
CLOSE_WITHOUT_SAVING -> { saveCurrentEvent()
finish() } else {
} super.onBackPressed()
SAVE_AND_CLOSE -> saveCurrentEvent()
} }
} }
} else { } else {
@@ -439,6 +442,27 @@ class EventActivity : SimpleActivity() {
checkAttendees() checkAttendees()
} }
private fun addDefValuesToNewEvent() {
var newStartTS: Long
var newEndTS: Long
getStartEndTimes().apply {
newStartTS = first
newEndTS = second
}
mEvent.apply {
startTS = newStartTS
endTS = newEndTS
reminder1Minutes = mReminder1Minutes
reminder1Type = mReminder1Type
reminder2Minutes = mReminder2Minutes
reminder2Type = mReminder2Type
reminder3Minutes = mReminder3Minutes
reminder3Type = mReminder3Type
eventType = mEventTypeId
}
}
private fun setupNewEvent() { private fun setupNewEvent() {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
event_title.requestFocus() event_title.requestFocus()
@@ -487,7 +511,7 @@ class EventActivity : SimpleActivity() {
} }
mEventEndDateTime = mEventStartDateTime.plusMinutes(addMinutes) mEventEndDateTime = mEventStartDateTime.plusMinutes(addMinutes)
} }
addDefValuesToNewEvent()
checkAttendees() checkAttendees()
} }

View File

@@ -1,33 +0,0 @@
package com.simplemobiletools.calendar.pro.dialogs
import android.app.Activity
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_return_without_saving.view.*
class CloseEditingDialog(val activity: Activity, val callback: (closeRule: Int) -> Unit) {
val dialog: AlertDialog?
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_return_without_saving, null)
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.yes) { _, _ -> dialogConfirmed(view as ViewGroup) }
.setNegativeButton(R.string.no, null)
.create().apply {
activity.setupDialogStuff(view, this)
}
}
private fun dialogConfirmed(view: ViewGroup) {
val closeRule = when (view.close_event_radio_view.checkedRadioButtonId) {
R.id.close_event_without_saving -> CLOSE_WITHOUT_SAVING
else -> SAVE_AND_CLOSE
}
dialog?.dismiss()
callback(closeRule)
}
}

View File

@@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/close_event_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="@dimen/big_margin"
android:paddingEnd="@dimen/big_margin"
android:paddingTop="@dimen/big_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/close_event_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/close_editing_event"
android:textSize="@dimen/bigger_text_size"/>
<RadioGroup
android:id="@+id/close_event_radio_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/close_event_without_saving"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:text="@string/close_without_saving"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/save_and_close_event"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:text="@string/save_and_close"/>
</RadioGroup>
</LinearLayout>

View File

@@ -293,9 +293,6 @@
<b>Reddit:</b> <b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools https://www.reddit.com/r/SimpleMobileTools
</string> </string>
<string name="close_editing_event" translatable="false">Are you sure you want to close?</string>
<string name="close_without_saving" translatable="false">Close without saving</string>
<string name="save_and_close" translatable="false">Save and close</string>
<!-- <!--
Haven't found some strings? There's more at Haven't found some strings? There's more at