diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt
index b5f74d2c..c3184812 100644
--- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt
@@ -111,6 +111,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
findItem(R.id.open_note).isVisible = shouldBeVisible
findItem(R.id.delete_note).isVisible = shouldBeVisible
findItem(R.id.export_all_notes).isVisible = shouldBeVisible
+ findItem(R.id.save_note).isVisible = !config.autosaveNotes
}
pager_title_strip.beVisibleIf(shouldBeVisible)
@@ -118,9 +119,13 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
- saveCurrentNote()
+ if (config.autosaveNotes) {
+ saveCurrentNote()
+ }
+
when (item.itemId) {
R.id.open_note -> displayOpenNoteDialog()
+ R.id.save_note -> saveNote()
R.id.new_note -> displayNewNoteDialog()
R.id.rename_note -> displayRenameDialog()
R.id.share -> shareText()
@@ -461,6 +466,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
}
+ private fun saveNote() {
+ saveCurrentNote()
+ }
+
private fun getNoteIndexWithId(id: Int): Int {
for (i in 0 until mNotes.count()) {
if (mNotes[i].id == id) {
diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt
index 52284b32..25f225e9 100644
--- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt
@@ -33,6 +33,7 @@ class SettingsActivity : SimpleActivity() {
setupCustomizeColors()
setupUseEnglish()
+ setupAutosaveNotes()
setupDisplaySuccess()
setupClickableLinks()
setupMonospacedFont()
@@ -62,6 +63,14 @@ class SettingsActivity : SimpleActivity() {
}
}
+ private fun setupAutosaveNotes() {
+ settings_autosave_notes.isChecked = config.autosaveNotes
+ settings_autosave_notes_holder.setOnClickListener {
+ settings_autosave_notes.toggle()
+ config.autosaveNotes = settings_autosave_notes.isChecked
+ }
+ }
+
private fun setupDisplaySuccess() {
settings_display_success.isChecked = config.displaySuccess
settings_display_success_holder.setOnClickListener {
diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt
index 534aa514..cba3eb0c 100644
--- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt
@@ -52,7 +52,7 @@ class NoteFragment : Fragment() {
override fun setMenuVisibility(menuVisible: Boolean) {
super.setMenuVisibility(menuVisible)
- if (noteId != 0) {
+ if (noteId != 0 && context?.config?.autosaveNotes == true) {
saveText()
}
}
@@ -134,7 +134,9 @@ class NoteFragment : Fragment() {
override fun onPause() {
super.onPause()
- saveText()
+ if (context!!.config.autosaveNotes) {
+ saveText()
+ }
view.notes_view.removeTextChangedListener(textWatcher)
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt
index f9960c14..22e471f4 100644
--- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt
@@ -9,6 +9,10 @@ class Config(context: Context) : BaseConfig(context) {
fun newInstance(context: Context) = Config(context)
}
+ var autosaveNotes: Boolean
+ get() = prefs.getBoolean(AUTOSAVE_NOTES, true)
+ set(autosaveNotes) = prefs.edit().putBoolean(AUTOSAVE_NOTES, autosaveNotes).apply()
+
var displaySuccess: Boolean
get() = prefs.getBoolean(DISPLAY_SUCCESS, false)
set(displaySuccess) = prefs.edit().putBoolean(DISPLAY_SUCCESS, displaySuccess).apply()
diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt
index 1c98010a..c879c2ee 100644
--- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt
@@ -5,6 +5,7 @@ const val OPEN_NOTE_ID = "open_note_id"
// shared preferences
const val CURRENT_NOTE_ID = "current_note_id"
+const val AUTOSAVE_NOTES = "autosave_notes"
const val DISPLAY_SUCCESS = "display_success"
const val CLICKABLE_LINKS = "clickable_links"
const val WIDGET_NOTE_ID = "widget_note_id"
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index 941075b2..60483eba 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -50,6 +50,26 @@
+
+
+
+
+
+