diff options
author | Tom Willemsen | 2012-08-10 22:03:34 +0200 |
---|---|---|
committer | Tom Willemsen | 2012-08-10 22:03:34 +0200 |
commit | f30b4fcd3a525d2fa3c2d85fb11e8e7aa3a6a031 (patch) | |
tree | 00cdeeb15ca9de3574e9c1e80ece9c849e926eb6 /src/ryuslash/org/dvdroid/DVDDataSource.java | |
parent | 2689fd0c5010d6e97616dfbc8557d0828b3d4064 (diff) | |
download | dvdroid-f30b4fcd3a525d2fa3c2d85fb11e8e7aa3a6a031.tar.gz dvdroid-f30b4fcd3a525d2fa3c2d85fb11e8e7aa3a6a031.zip |
Add edit and delete functionality
* res/values/strings.xml: Add strings for `main_context_menu_edit' and
`main_context_menu_delete'.
* src/ryuslash/org/dvdroid/AddDVDActivity.java (saveDVD): Renamed from
`createDVD'. When ID is greater than 0 update, otherwise create.
(onCreate): Get ID from the `Intent' that was used to start this
activity. If ID is greater than 0, show known information in the
inputs.
* src/ryuslash/org/dvdroid/DVDDataSource.java:
(createValues):
(updateDVD):
(getById): New functions.
(createDVD): Use `createValues' to get the values for the database.
(deleteDVD): Add overloaded function that takes a `long', make the
original function use this to delete a `DVD'.
* src/ryuslash/org/dvdroid/DVDroidActivity.java: Implement
`ActionMode.Callback'.
(onActivityResult): If REQUESTCODE is `2' reset the intent
information so as not to confuse it during its next invocation.
Finish action mode.
(onActionItemClicked):
(onCreateActionMode):
(onDestroyActionMode):
(onListItemClick):
(onPrepareActionMode):
(reloadList):
(showEditDVD): New functions.
(onCreate): Instantiate the ADD_DVD `Intent'.
Diffstat (limited to 'src/ryuslash/org/dvdroid/DVDDataSource.java')
-rw-r--r-- | src/ryuslash/org/dvdroid/DVDDataSource.java | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/ryuslash/org/dvdroid/DVDDataSource.java b/src/ryuslash/org/dvdroid/DVDDataSource.java index b9fe166..e10fb24 100644 --- a/src/ryuslash/org/dvdroid/DVDDataSource.java +++ b/src/ryuslash/org/dvdroid/DVDDataSource.java @@ -33,7 +33,8 @@ public class DVDDataSource dbHelper.close(); } - public DVD createDVD(String title, int watched, int wishlist) + private ContentValues createValues(String title, int watched, + int wishlist) { ContentValues values = new ContentValues(); @@ -41,6 +42,12 @@ public class DVDDataSource values.put(SQLiteHelper.COLUMN_WATCHED, watched); values.put(SQLiteHelper.COLUMN_WISHLIST, wishlist); + return values; + } + + public DVD createDVD(String title, int watched, int wishlist) + { + ContentValues values = createValues(title, watched, wishlist); long insertId = database.insert(SQLiteHelper.TABLE_DVD, null, values); Cursor cursor = database.query(SQLiteHelper.TABLE_DVD, @@ -57,14 +64,42 @@ public class DVDDataSource return newDVD; } + public void updateDVD(long id, String title, int watched, int wishlist) + { + ContentValues values = createValues(title, watched, wishlist); + String whereArgs[] = { "" + id }; + + database.update(SQLiteHelper.TABLE_DVD, values, "id = ?", + whereArgs); + } + public void deleteDVD(DVD dvd) { - long id = dvd.getId(); - System.out.println("DVD deleted with id: " + id); + deleteDVD(dvd.getId()); + } + + public void deleteDVD(long id) + { database.delete(SQLiteHelper.TABLE_DVD, SQLiteHelper.COLUMN_ID + " = " + id, null); } + public DVD getById(long id) + { + Cursor cursor = database.query(SQLiteHelper.TABLE_DVD, + allColumns, + SQLiteHelper.COLUMN_ID + " = " + id, + null, null, null, null); + + cursor.moveToFirst(); + + DVD dvd = cursorToDVD(cursor); + + cursor.close(); + + return dvd; + } + public List<DVD> getListFromCursor(Cursor cursor) { List<DVD> dvds = new ArrayList<DVD>(); |