mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-01-19 09:09:47 +01:00
check if the title is free at creating a new note
This commit is contained in:
parent
5f4001e71a
commit
eebab76151
@ -101,6 +101,8 @@ public class MainActivity extends SimpleActivity {
|
||||
final String title = titleET.getText().toString().trim();
|
||||
if (title.isEmpty()) {
|
||||
Utils.showToast(getApplicationContext(), R.string.no_title);
|
||||
} else if (mDb.doesTitleExist(title)) {
|
||||
Utils.showToast(getApplicationContext(), R.string.title_taken);
|
||||
} else {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
|
@ -74,6 +74,20 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
return values;
|
||||
}
|
||||
|
||||
public boolean doesTitleExist(String title) {
|
||||
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);
|
||||
|
||||
if (cursor == null)
|
||||
return false;
|
||||
|
||||
final int cnt = cursor.getCount();
|
||||
cursor.close();
|
||||
return cnt == 1;
|
||||
}
|
||||
|
||||
public void updateNote(Note note) {
|
||||
final ContentValues values = fillContentValues(note);
|
||||
final String selection = COL_ID + " = ?";
|
||||
|
Loading…
Reference in New Issue
Block a user