mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
permanently enable autosave
This commit is contained in:
@ -30,22 +30,6 @@ public class Config {
|
||||
mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply();
|
||||
}
|
||||
|
||||
public boolean getIsAutosaveEnabled() {
|
||||
return mPrefs.getBoolean(Constants.AUTOSAVE, false);
|
||||
}
|
||||
|
||||
public void setIsAutosaveEnabled(boolean enabled) {
|
||||
mPrefs.edit().putBoolean(Constants.AUTOSAVE, enabled).apply();
|
||||
}
|
||||
|
||||
public boolean getShouldPromptAutosave() {
|
||||
return mPrefs.getBoolean(Constants.PROMPT_AUTOSAVE, true);
|
||||
}
|
||||
|
||||
public void setShouldPromptAutosave(boolean prompt) {
|
||||
mPrefs.edit().putBoolean(Constants.PROMPT_AUTOSAVE, prompt).apply();
|
||||
}
|
||||
|
||||
public int getFontSize() {
|
||||
return mPrefs.getInt(Constants.FONT_SIZE, Constants.FONT_SIZE_MEDIUM);
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ public class Constants {
|
||||
public static final String PREFS_KEY = "Notes";
|
||||
public static final String IS_FIRST_RUN = "is_first_run";
|
||||
public static final String IS_DARK_THEME = "is_dark_theme";
|
||||
public static final String AUTOSAVE = "autosave";
|
||||
public static final String PROMPT_AUTOSAVE = "prompt_autosave";
|
||||
public static final String FONT_SIZE = "font_size";
|
||||
public static final String WIDGET_BG_COLOR = "widget_bg_color";
|
||||
public static final String WIDGET_TEXT_COLOR = "widget_text_color";
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.simplemobiletools.notes.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -48,19 +46,7 @@ public class MainActivity extends SimpleActivity {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (mConfig.getIsAutosaveEnabled()) {
|
||||
saveText(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mConfig.getShouldPromptAutosave() && !getCurrentNote().equals(getSavedNote())) {
|
||||
mConfig.setShouldPromptAutosave(false);
|
||||
displayAutosavePrompt();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
saveText();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,18 +58,12 @@ public class MainActivity extends SimpleActivity {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu, menu);
|
||||
if (mConfig.getIsAutosaveEnabled())
|
||||
menu.findItem(R.id.save).setVisible(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.save:
|
||||
saveText(true);
|
||||
return true;
|
||||
case R.id.share:
|
||||
shareText();
|
||||
return true;
|
||||
@ -103,30 +83,14 @@ public class MainActivity extends SimpleActivity {
|
||||
|
||||
}
|
||||
|
||||
private void displayAutosavePrompt() {
|
||||
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
||||
alertDialog.setTitle(getString(R.string.unsaved_changes));
|
||||
alertDialog.setMessage(getString(R.string.autosave_prompt_msg));
|
||||
|
||||
alertDialog.setNegativeButton(R.string.cancel, null);
|
||||
alertDialog.setPositiveButton(R.string.enable_autosave, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mConfig.setIsAutosaveEnabled(true);
|
||||
supportInvalidateOptionsMenu();
|
||||
}
|
||||
});
|
||||
alertDialog.create().show();
|
||||
}
|
||||
|
||||
private void saveText(boolean showToast) {
|
||||
final String text = getCurrentNote();
|
||||
mPrefs.edit().putString(Constants.TEXT, text).apply();
|
||||
|
||||
if (showToast) {
|
||||
Utils.showToast(getApplicationContext(), R.string.text_saved);
|
||||
private void saveText() {
|
||||
final String newText = getCurrentNote();
|
||||
final String oldText = mPrefs.getString(Constants.TEXT, "");
|
||||
if (!newText.equals(oldText)) {
|
||||
Utils.showToast(getApplicationContext(), R.string.note_saved);
|
||||
}
|
||||
|
||||
mPrefs.edit().putString(Constants.TEXT, newText).apply();
|
||||
hideKeyboard();
|
||||
Utils.updateWidget(getApplicationContext());
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import butterknife.OnItemSelected;
|
||||
|
||||
public class SettingsActivity extends SimpleActivity {
|
||||
@BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch;
|
||||
@BindView(R.id.settings_autosave) SwitchCompat mAutosaveSwitch;
|
||||
@BindView(R.id.settings_font_size) AppCompatSpinner mFontSizeSpinner;
|
||||
|
||||
private static Config mConfig;
|
||||
@ -29,19 +28,13 @@ public class SettingsActivity extends SimpleActivity {
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setupDarkTheme();
|
||||
setupAutosave();
|
||||
setupFontSize();
|
||||
mConfig.setShouldPromptAutosave(false);
|
||||
}
|
||||
|
||||
private void setupDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
|
||||
}
|
||||
|
||||
private void setupAutosave() {
|
||||
mAutosaveSwitch.setChecked(mConfig.getIsAutosaveEnabled());
|
||||
}
|
||||
|
||||
private void setupFontSize() {
|
||||
mFontSizeSpinner.setSelection(mConfig.getFontSize());
|
||||
}
|
||||
@ -53,12 +46,6 @@ public class SettingsActivity extends SimpleActivity {
|
||||
restartActivity();
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_autosave_holder)
|
||||
public void handleAutosave() {
|
||||
mAutosaveSwitch.setChecked(!mAutosaveSwitch.isChecked());
|
||||
mConfig.setIsAutosaveEnabled(mAutosaveSwitch.isChecked());
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.settings_font_size)
|
||||
public void handleFontSize() {
|
||||
mConfig.setFontSize(mFontSizeSpinner.getSelectedItemPosition());
|
||||
|
Reference in New Issue
Block a user