mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-04 08:07:32 +01:00
hide the Open note menu item if there is only 1 note
This commit is contained in:
parent
06e074ae6f
commit
b0fcd9daef
@ -27,6 +27,7 @@ public class MainActivity extends SimpleActivity {
|
||||
|
||||
private DBHelper mDb;
|
||||
private Note mCurrentNote;
|
||||
private int mNotesCnt;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -44,6 +45,9 @@ public class MainActivity extends SimpleActivity {
|
||||
super.onResume();
|
||||
invalidateOptionsMenu();
|
||||
mNotesView.setTextSize(TypedValue.COMPLEX_UNIT_PX, Utils.getTextSize(getApplicationContext()));
|
||||
|
||||
mNotesCnt = mDb.getNotes().size();
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,6 +65,12 @@ public class MainActivity extends SimpleActivity {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu, menu);
|
||||
|
||||
if (mNotesCnt <= 1) {
|
||||
final MenuItem item = menu.findItem(R.id.open_note);
|
||||
item.setVisible(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,9 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||
import com.simplemobiletools.notes.Constants;
|
||||
import com.simplemobiletools.notes.models.Note;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper {
|
||||
private static final String DB_NAME = "notes.db";
|
||||
private static final int DB_VERSION = 1;
|
||||
@ -78,7 +81,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
final String cols[] = {COL_ID};
|
||||
final String selection = COL_TITLE + " = ?";
|
||||
final String selectionArgs[] = {title};
|
||||
Cursor cursor = mDb.query(TABLE_NAME, cols, selection, selectionArgs, null, null, null);
|
||||
final Cursor cursor = mDb.query(TABLE_NAME, cols, selection, selectionArgs, null, null, null);
|
||||
|
||||
if (cursor == null)
|
||||
return false;
|
||||
@ -88,6 +91,26 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
return cnt == 1;
|
||||
}
|
||||
|
||||
public List<Note> getNotes() {
|
||||
final List<Note> notes = new ArrayList<>();
|
||||
final String cols[] = {COL_ID, COL_TITLE, COL_VALUE};
|
||||
final Cursor cursor = mDb.query(TABLE_NAME, cols, null, null, null, null, null);
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
final int id = cursor.getInt(cursor.getColumnIndex(COL_ID));
|
||||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String value = cursor.getString(cursor.getColumnIndex(COL_VALUE));
|
||||
final Note note = new Note(id, title, value);
|
||||
notes.add(note);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void updateNote(Note note) {
|
||||
final ContentValues values = fillContentValues(note);
|
||||
final String selection = COL_ID + " = ?";
|
||||
@ -105,10 +128,10 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
final int id = cursor.getInt(cursor.getColumnIndex(COL_ID));
|
||||
final String name = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String text = cursor.getString(cursor.getColumnIndex(COL_VALUE));
|
||||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String value = cursor.getString(cursor.getColumnIndex(COL_VALUE));
|
||||
cursor.close();
|
||||
return new Note(id, name, text);
|
||||
return new Note(id, title, value);
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user