Added warning when closing edit scene

This commit is contained in:
fnrngg 2020-06-05 22:00:20 +04:00
parent f9a99736ca
commit 2f348944a7
5 changed files with 98 additions and 1 deletions

View File

@ -240,11 +240,27 @@ class EventActivity : SimpleActivity() {
R.id.delete -> deleteEvent()
R.id.duplicate -> duplicateEvent()
R.id.share -> shareEvent()
android.R.id.home -> onBackPressed()
else -> return super.onOptionsItemSelected(item)
}
return true
}
override fun onBackPressed() {
CloseEditingDialog(this) {
ensureBackgroundThread {
when (it) {
CLOSE_WITHOUT_SAVING -> {
runOnUiThread {
finish()
}
}
SAVE_AND_CLOSE -> saveEvent()
}
}
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (!mWasActivityInitialized) {
@ -334,6 +350,7 @@ class EventActivity : SimpleActivity() {
updateAttendeesVisibility()
}
private fun setupEditEvent() {
val realStart = if (mEventOccurrenceTS == 0L) mEvent.startTS else mEventOccurrenceTS
val duration = mEvent.endTS - mEvent.startTS
@ -1011,7 +1028,6 @@ class EventActivity : SimpleActivity() {
eventsHelper.deleteEvent(mEvent.id!!, true)
mEvent.id = null
}
storeEvent(wasRepeatable)
}

View File

@ -0,0 +1,33 @@
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

@ -155,4 +155,7 @@ const val DELETE_ALL_OCCURRENCES = 2
const val REMINDER_NOTIFICATION = 0
const val REMINDER_EMAIL = 1
const val CLOSE_WITHOUT_SAVING = 0
const val SAVE_AND_CLOSE = 1
fun getNowSeconds() = System.currentTimeMillis() / 1000L

View File

@ -0,0 +1,42 @@
<?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,6 +293,9 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</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