permanently enable autosave

This commit is contained in:
tibbi 2016-09-27 18:22:19 +02:00
parent c43e4c150f
commit 6a5e7f5cdb
16 changed files with 12 additions and 135 deletions

View File

@ -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);
}

View File

@ -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";

View File

@ -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());
}

View File

@ -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());

View File

@ -37,32 +37,6 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_autosave_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_padding"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/settings_autosave_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/settings_padding"
android:text="@string/autosave"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_autosave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_font_size_holder"
android:layout_width="match_parent"

View File

@ -1,11 +1,6 @@
<?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"
android:icon="@mipmap/save"
android:title="@string/save"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/share"
android:icon="@mipmap/share"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 B

View File

@ -6,17 +6,12 @@
<string name="share">Teilen</string>
<string name="share_via">Teilen via</string>
<string name="cannot_share_empty_text">Leerer Text kann nicht geteilt werden</string>
<string name="text_saved">Text gespeichert</string>
<string name="note_saved">Text gespeichert</string>
<string name="simple_note">Einfache Notiz</string>
<string name="enable_autosave">Aktiviere automatisches Speichern</string>
<string name="cancel">Abbrechen</string>
<string name="unsaved_changes">Ungesicherte Änderungen</string>
<string name="autosave_prompt_msg">Diese Notiz enthält ungesicherte Änderungen. Möchtest du automatisches Speichern aktivieren?</string>
<!-- Settings -->
<string name="settings">Einstellungen</string>
<string name="dark_theme">Dunkles Thema</string>
<string name="autosave">Automatisches Speichern</string>
<string name="note_font_size">Note font size</string>
<string name="small">Small</string>
<string name="normal">Normal</string>

View File

@ -6,17 +6,12 @@
<string name="share">Condividi</string>
<string name="share_via">Condividi via</string>
<string name="cannot_share_empty_text">Impossibile condividere un testo vuoto</string>
<string name="text_saved">Testo salvato</string>
<string name="note_saved">Testo salvato</string>
<string name="simple_note">Simple Note</string>
<string name="enable_autosave">Enable autosave</string>
<string name="cancel">Cancel</string>
<string name="unsaved_changes">Unsaved changes</string>
<string name="autosave_prompt_msg">Changes made to the note have not been saved. Do you want to enable autosave?</string>
<!-- Settings -->
<string name="settings">Impostazioni</string>
<string name="dark_theme">Tema scuro</string>
<string name="autosave">Autosalvataggio</string>
<string name="note_font_size">Note font size</string>
<string name="small">Small</string>
<string name="normal">Normal</string>

View File

@ -6,17 +6,12 @@
<string name="share">共有</string>
<string name="share_via">共有...</string>
<string name="cannot_share_empty_text">空のテキストは共有できません</string>
<string name="text_saved">テキストを保存しました</string>
<string name="note_saved">テキストを保存しました</string>
<string name="simple_note">シンプル メモ</string>
<string name="enable_autosave">Enable autosave</string>
<string name="cancel">Cancel</string>
<string name="unsaved_changes">Unsaved changes</string>
<string name="autosave_prompt_msg">Changes made to the note have not been saved. Do you want to enable autosave?</string>
<!-- Settings -->
<string name="settings">設定</string>
<string name="dark_theme">ダークテーマ</string>
<string name="autosave">自動保存</string>
<string name="note_font_size">Note font size</string>
<string name="small">Small</string>
<string name="normal">Normal</string>

View File

@ -6,17 +6,12 @@
<string name="share">Dela</string>
<string name="share_via">Dela via</string>
<string name="cannot_share_empty_text">Det går inte att dela utan text</string>
<string name="text_saved">Text sparad</string>
<string name="note_saved">Text sparad</string>
<string name="simple_note">Simple Note</string>
<string name="enable_autosave">Enable autosave</string>
<string name="cancel">Cancel</string>
<string name="unsaved_changes">Unsaved changes</string>
<string name="autosave_prompt_msg">Changes made to the note have not been saved. Do you want to enable autosave?</string>
<!-- Settings -->
<string name="settings">Inställningar</string>
<string name="dark_theme">Mörkt tema</string>
<string name="autosave">Spara automatiskt</string>
<string name="note_font_size">Note font size</string>
<string name="small">Small</string>
<string name="normal">Normal</string>

View File

@ -6,17 +6,12 @@
<string name="share">Share</string>
<string name="share_via">Share via</string>
<string name="cannot_share_empty_text">Cannot share empty text</string>
<string name="text_saved">Text Saved</string>
<string name="note_saved">Note Saved</string>
<string name="simple_note">Simple Note</string>
<string name="enable_autosave">Enable autosave</string>
<string name="cancel">Cancel</string>
<string name="unsaved_changes">Unsaved changes</string>
<string name="autosave_prompt_msg">Changes made to the note have not been saved. Do you want to enable autosave?</string>
<!-- Settings -->
<string name="settings">Settings</string>
<string name="dark_theme">Dark theme</string>
<string name="autosave">Autosave</string>
<string name="note_font_size">Note font size</string>
<string name="small">Small</string>
<string name="normal">Normal</string>