1212import android .view .MenuItem ;
1313import android .view .inputmethod .InputMethodManager ;
1414import android .widget .EditText ;
15- import android .widget .Toast ;
1615
1716import com .simplemobiletools .notes .Config ;
1817import com .simplemobiletools .notes .Constants ;
@@ -39,6 +38,20 @@ protected void onCreate(Bundle savedInstanceState) {
3938 mNotesView .setText (text );
4039 }
4140
41+ @ Override
42+ protected void onResume () {
43+ super .onResume ();
44+ invalidateOptionsMenu ();
45+ }
46+
47+ @ Override
48+ protected void onPause () {
49+ super .onPause ();
50+ if (Config .newInstance (getApplicationContext ()).getIsAutosaveEnabled ()) {
51+ saveText (false );
52+ }
53+ }
54+
4255 @ Override
4356 protected void onDestroy () {
4457 super .onDestroy ();
@@ -48,14 +61,17 @@ protected void onDestroy() {
4861 @ Override
4962 public boolean onCreateOptionsMenu (Menu menu ) {
5063 getMenuInflater ().inflate (R .menu .menu , menu );
64+ if (Config .newInstance (getApplicationContext ()).getIsAutosaveEnabled ())
65+ menu .findItem (R .id .save ).setVisible (false );
66+
5167 return true ;
5268 }
5369
5470 @ Override
5571 public boolean onOptionsItemSelected (MenuItem item ) {
5672 switch (item .getItemId ()) {
5773 case R .id .save :
58- saveText ();
74+ saveText (true );
5975 return true ;
6076 case R .id .share :
6177 shareText ();
@@ -69,19 +85,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
6985 }
7086 }
7187
72- private void saveText () {
88+ private void saveText (boolean showToast ) {
7389 final String text = mNotesView .getText ().toString ().trim ();
7490 mPrefs .edit ().putString (Constants .TEXT , text ).apply ();
7591
76- Toast .makeText (this , getResources ().getString (R .string .text_saved ), Toast .LENGTH_SHORT ).show ();
92+ if (showToast ) {
93+ Utils .showToast (getApplicationContext (), R .string .text_saved );
94+ }
95+
7796 hideKeyboard ();
7897 updateWidget ();
7998 }
8099
81100 private void shareText () {
82101 final String text = mNotesView .getText ().toString ().trim ();
83102 if (text .isEmpty ()) {
84- Utils .showToast (this , R .string .cannot_share_empty_text );
103+ Utils .showToast (getApplicationContext () , R .string .cannot_share_empty_text );
85104 return ;
86105 }
87106
0 commit comments