mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-01-29 13:39:16 +01:00
fix #133, add an option to disable autosave
This commit is contained in:
parent
be4d06f04c
commit
b59649dfea
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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"
|
||||
|
@ -50,6 +50,26 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_autosave_notes_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_autosave_notes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/autosave_notes"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_display_success_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -1,6 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/save_note"
|
||||
android:icon="@drawable/ic_save"
|
||||
android:title="@string/save"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/open_note"
|
||||
android:icon="@drawable/ic_open"
|
||||
|
Loading…
x
Reference in New Issue
Block a user