mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-12 09:50:48 +01:00
Added warning when closing edit scene
This commit is contained in:
parent
f9a99736ca
commit
2f348944a7
@ -240,11 +240,27 @@ class EventActivity : SimpleActivity() {
|
|||||||
R.id.delete -> deleteEvent()
|
R.id.delete -> deleteEvent()
|
||||||
R.id.duplicate -> duplicateEvent()
|
R.id.duplicate -> duplicateEvent()
|
||||||
R.id.share -> shareEvent()
|
R.id.share -> shareEvent()
|
||||||
|
android.R.id.home -> onBackPressed()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
CloseEditingDialog(this) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
when (it) {
|
||||||
|
CLOSE_WITHOUT_SAVING -> {
|
||||||
|
runOnUiThread {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SAVE_AND_CLOSE -> saveEvent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
if (!mWasActivityInitialized) {
|
if (!mWasActivityInitialized) {
|
||||||
@ -334,6 +350,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
updateAttendeesVisibility()
|
updateAttendeesVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun setupEditEvent() {
|
private fun setupEditEvent() {
|
||||||
val realStart = if (mEventOccurrenceTS == 0L) mEvent.startTS else mEventOccurrenceTS
|
val realStart = if (mEventOccurrenceTS == 0L) mEvent.startTS else mEventOccurrenceTS
|
||||||
val duration = mEvent.endTS - mEvent.startTS
|
val duration = mEvent.endTS - mEvent.startTS
|
||||||
@ -1011,7 +1028,6 @@ class EventActivity : SimpleActivity() {
|
|||||||
eventsHelper.deleteEvent(mEvent.id!!, true)
|
eventsHelper.deleteEvent(mEvent.id!!, true)
|
||||||
mEvent.id = null
|
mEvent.id = null
|
||||||
}
|
}
|
||||||
|
|
||||||
storeEvent(wasRepeatable)
|
storeEvent(wasRepeatable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -155,4 +155,7 @@ const val DELETE_ALL_OCCURRENCES = 2
|
|||||||
const val REMINDER_NOTIFICATION = 0
|
const val REMINDER_NOTIFICATION = 0
|
||||||
const val REMINDER_EMAIL = 1
|
const val REMINDER_EMAIL = 1
|
||||||
|
|
||||||
|
const val CLOSE_WITHOUT_SAVING = 0
|
||||||
|
const val SAVE_AND_CLOSE = 1
|
||||||
|
|
||||||
fun getNowSeconds() = System.currentTimeMillis() / 1000L
|
fun getNowSeconds() = System.currentTimeMillis() / 1000L
|
||||||
|
42
app/src/main/res/layout/dialog_return_without_saving.xml
Normal file
42
app/src/main/res/layout/dialog_return_without_saving.xml
Normal 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>
|
@ -293,6 +293,9 @@
|
|||||||
<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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user