Skip to content

Commit

Permalink
WIP as I'm going to Miami and would like to continue working on this …
Browse files Browse the repository at this point in the history
…there...
  • Loading branch information
MizzleDK committed Oct 12, 2014
1 parent 47114b6 commit 89f9a05
Show file tree
Hide file tree
Showing 17 changed files with 233 additions and 165 deletions.
4 changes: 4 additions & 0 deletions res/menu/tv_show_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
android:showAsAction="ifRoom"
android:title="@string/menuFavouriteTitleRemove">
</item>
<item
android:id="@+id/share"
android:icon="@drawable/share"
android:title="@string/menuShareTitle"/>

<group
android:id="@+id/group1"
Expand Down
6 changes: 3 additions & 3 deletions src/com/miz/db/DbAdapterCollections.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public long createCollection(String collectionId, String collection) {
}

public boolean collectionExists(String collectionId) {
Cursor mCursor = mDatabase.query(true, DATABASE_TABLE, ALL_COLUMNS, KEY_COLLECTION_ID + "='" + collectionId + "'", null, null, null, null, null);
Cursor mCursor = mDatabase.query(true, DATABASE_TABLE, ALL_COLUMNS, KEY_COLLECTION_ID + " = ?", new String[]{collectionId}, null, null, null, null);
if (mCursor == null)
return false;
try {
Expand All @@ -70,7 +70,7 @@ public boolean collectionExists(String collectionId) {
}

public String getCollection(String collectionId) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_COLLECTION_ID + "='" + collectionId + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_COLLECTION_ID + " = ?", new String[]{collectionId}, null, null, null);
String collection = "";

if (cursor != null) {
Expand Down Expand Up @@ -108,7 +108,7 @@ public HashMap<String, String> getCollectionsMap() {
}

public boolean deleteCollection(String collectionId) {
return mDatabase.delete(DATABASE_TABLE, KEY_COLLECTION_ID + "='" + collectionId + "'", null) > 0;
return mDatabase.delete(DATABASE_TABLE, KEY_COLLECTION_ID + " = ?", new String[]{collectionId}) > 0;
}

public boolean deleteAllCollections() {
Expand Down
18 changes: 11 additions & 7 deletions src/com/miz/db/DbAdapterMovieMappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public Cursor getAllFilepaths(boolean includeRemoved) {
public Cursor getAllUnidentifiedFilepaths() {
return mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, "NOT(" + KEY_IGNORED + " = '1') AND " + KEY_TMDB_ID + "='" + DbAdapterMovies.UNIDENTIFIED_ID + "'", null, null, null, null);
}

public boolean deleteAllUnidentifiedFilepaths() {
return mDatabase.delete(DATABASE_TABLE, KEY_TMDB_ID + " = ?", new String[]{DbAdapterMovies.UNIDENTIFIED_ID}) > 0;
}

public String getFirstFilepathForMovie(String tmdbId) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, new String[]{KEY_TMDB_ID, KEY_FILEPATH}, KEY_TMDB_ID + "='" + tmdbId + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, new String[]{KEY_TMDB_ID, KEY_FILEPATH}, KEY_TMDB_ID + " = ?", new String[]{tmdbId}, null, null, null);
String filepath = "";

if (cursor != null) {
Expand All @@ -80,11 +84,11 @@ public boolean updateTmdbId(String filepath, String newTmdbId) {
ContentValues values = new ContentValues();
values.put(KEY_TMDB_ID, newTmdbId);

return mDatabase.update(DATABASE_TABLE, values, KEY_FILEPATH + "='" + filepath + "'", null) > 0;
return mDatabase.update(DATABASE_TABLE, values, KEY_FILEPATH + " = ?", new String[]{filepath}) > 0;
}

public boolean exists(String tmdbId) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_TMDB_ID + "='" + tmdbId + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_TMDB_ID + " = ?", new String[]{tmdbId}, null, null, null);
boolean result = false;

if (cursor != null) {
Expand Down Expand Up @@ -119,7 +123,7 @@ public boolean filepathExists(String tmdbId, String filepath) {
}

public boolean deleteMovie(String tmdbId) {
return mDatabase.delete(DATABASE_TABLE, KEY_TMDB_ID + "='" + tmdbId + "'", null) > 0;
return mDatabase.delete(DATABASE_TABLE, KEY_TMDB_ID + " = ?", new String[]{tmdbId}) > 0;
}

public boolean deleteAllMovies() {
Expand All @@ -129,11 +133,11 @@ public boolean deleteAllMovies() {
public boolean ignoreMovie(String tmdbId) {
ContentValues ignore = new ContentValues();
ignore.put(KEY_IGNORED, 1);
return mDatabase.update(DATABASE_TABLE, ignore, KEY_TMDB_ID + "='" + tmdbId + "'", null) > 0;
return mDatabase.update(DATABASE_TABLE, ignore, KEY_TMDB_ID + " = ?", new String[]{tmdbId}) > 0;
}

public boolean hasMultipleFilepaths(String tmdbId) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_TMDB_ID + "='" + tmdbId + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_TMDB_ID + " = ?", new String[]{tmdbId}, null, null, null);
boolean result = false;

if (cursor != null) {
Expand All @@ -150,7 +154,7 @@ public boolean hasMultipleFilepaths(String tmdbId) {
}

public ArrayList<String> getMovieFilepaths(String tmdbId) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_TMDB_ID + "='" + tmdbId + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_TMDB_ID + " = ?", new String[]{tmdbId}, null, null, null);
ArrayList<String> paths = new ArrayList<String>();

if (cursor != null) {
Expand Down
14 changes: 7 additions & 7 deletions src/com/miz/db/DbAdapterMovies.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ public boolean updateMovie(String tmdbid, String title, String plot, String imdb
ContentValues updateValues = createUpdateContentValues(title, plot, imdbid, rating, tagline, release, certification,
runtime, trailer, genres, actors, collectionId, date);

return mDatabase.update(DATABASE_TABLE, updateValues, KEY_TMDB_ID + "='" + tmdbid + "'", null) > 0 &&
return mDatabase.update(DATABASE_TABLE, updateValues, KEY_TMDB_ID + " = ?", new String[]{tmdbid}) > 0 &&
MizuuApplication.getCollectionsAdapter().createCollection(collectionId, collectionId) > 0;
}

public boolean updateMovieSingleItem(String tmdbId, String column, String value) {
ContentValues values = new ContentValues();
values.put(column, value);

return mDatabase.update(DATABASE_TABLE, values, KEY_TMDB_ID + "='" + tmdbId + "'", null) > 0;
return mDatabase.update(DATABASE_TABLE, values, KEY_TMDB_ID + " = ?", new String[]{tmdbId}) > 0;
}

/**
Expand All @@ -119,7 +119,7 @@ public boolean updateMovieSingleItem(String tmdbId, String column, String value)
public boolean editUpdateMovie(String tmdbId, String title, String plot, String rating, String tagline, String release,
String certification, String runtime, String genres, String toWatch, String hasWatched, String date) {
ContentValues updateValues = createEditContentValues(title, plot, rating, tagline, release, certification, runtime, genres, toWatch, hasWatched, date);
return mDatabase.update(DATABASE_TABLE, updateValues, KEY_TMDB_ID + "='" + tmdbId + "'", null) > 0;
return mDatabase.update(DATABASE_TABLE, updateValues, KEY_TMDB_ID + " = ?", new String[]{tmdbId}) > 0;
}

public boolean editMovie(String movieId, String title, String tagline, String description,
Expand All @@ -133,7 +133,7 @@ public boolean editMovie(String movieId, String title, String tagline, String de
cv.put(KEY_CERTIFICATION, certification);
cv.put(KEY_RUNTIME, runtime);
cv.put(KEY_GENRES, genres);
return mDatabase.update(DATABASE_TABLE, cv, KEY_TMDB_ID + "='" + movieId + "'", null) > 0;
return mDatabase.update(DATABASE_TABLE, cv, KEY_TMDB_ID + " = ?", new String[]{movieId}) > 0;
}

/**
Expand All @@ -148,7 +148,7 @@ public boolean ignoreMovie(String tmdbId) {
* Deletes movie
*/
public boolean deleteMovie(String tmdbId) {
boolean result = mDatabase.delete(DATABASE_TABLE, KEY_TMDB_ID + "='" + tmdbId + "'", null) > 0;
boolean result = mDatabase.delete(DATABASE_TABLE, KEY_TMDB_ID + " = ?", new String[]{tmdbId}) > 0;

// When deleting a movie, check if there's other movies
// linked to the collection - if not, delete the collection entry
Expand All @@ -164,7 +164,7 @@ public boolean deleteAllMovies() {
}

public String getCollectionId(String tmdbId) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, SELECT_ALL, KEY_TMDB_ID + "='" + tmdbId + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, SELECT_ALL, KEY_TMDB_ID + " = ?", new String[]{tmdbId}, null, null, null);
String collectionId = "";

if (cursor != null) {
Expand All @@ -182,7 +182,7 @@ public String getCollectionId(String tmdbId) {
}

public boolean hasMultipleCollectionMappings(String collectionId) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, SELECT_ALL, KEY_COLLECTION_ID + "='" + collectionId + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, SELECT_ALL, KEY_COLLECTION_ID + " = ?", new String[]{collectionId}, null, null, null);
boolean result = false;

if (cursor != null) {
Expand Down
33 changes: 22 additions & 11 deletions src/com/miz/db/DbAdapterTvShowEpisodeMappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public boolean filepathExists(String showId, String season, String episode, Stri
}

public String getFirstFilepath(String showId, String season, String episode) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + "='" + showId + "' AND " + KEY_SEASON + "='" +
season + "' AND " + KEY_EPISODE + "='" + episode + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + " = ? AND " + KEY_SEASON + " = ? AND " + KEY_EPISODE + " = ?",
new String[]{showId, season, episode}, null, null, null);
String filepath = "";

if (cursor != null) {
Expand All @@ -98,8 +98,8 @@ public String getFirstFilepath(String showId, String season, String episode) {
public ArrayList<String> getFilepathsForEpisode(String showId, String season, String episode) {
ArrayList<String> paths = new ArrayList<String>();

Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + "='" + showId + "' AND " + KEY_SEASON + "='" +
season + "' AND " + KEY_EPISODE + "='" + episode + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + " = ? AND " + KEY_SEASON + " = ? AND " + KEY_EPISODE + " = ?",
new String[]{showId, season, episode}, null, null, null);

if (cursor != null) {
try {
Expand All @@ -115,6 +115,11 @@ public ArrayList<String> getFilepathsForEpisode(String showId, String season, St
return paths;
}

public Cursor getAllUnidentifiedFilepaths() {
String[] selectionArgs = new String[]{DbAdapterTvShows.UNIDENTIFIED_ID};
return mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + " = ?", selectionArgs, null, null, null);
}

public Cursor getAllFilepaths() {
return mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, null, null, null, null, null);
}
Expand All @@ -125,11 +130,11 @@ public Cursor getAllFilepathInfo(String filepath) {
}

public Cursor getAllFilepaths(String showId) {
return mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + "='" + showId + "'", null, null, null, null);
return mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + " = ?", new String[]{showId}, null, null, null);
}

public Cursor getAllIgnoredFilepaths() {
return mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_IGNORED + "='1'", null, null, null, null);
return mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_IGNORED + " = '1'", null, null, null, null);
}

public boolean deleteFilepath(String filepath) {
Expand Down Expand Up @@ -177,16 +182,20 @@ public boolean ignoreFilepath(String filepath) {

public boolean deleteAllFilepaths(String showId) {
boolean result = MizuuApplication.getTvEpisodeDbAdapter().deleteAllEpisodes(showId); // This also deletes the show
return result && mDatabase.delete(DATABASE_TABLE, KEY_SHOW_ID + "='" + showId + "'", null) > 0;
return result && mDatabase.delete(DATABASE_TABLE, KEY_SHOW_ID + " = ?", new String[]{showId}) > 0;
}

public boolean deleteAllFilepaths() {
return mDatabase.delete(DATABASE_TABLE, null, null) > 0;
}

public boolean deleteAllUnidentifiedFilepaths() {
return mDatabase.delete(DATABASE_TABLE, KEY_SHOW_ID + " = ?", new String[]{DbAdapterTvShows.UNIDENTIFIED_ID}) > 0;
}

public boolean hasMultipleFilepaths(String showId, String season, String episode) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + "='" + showId + "' AND " + KEY_SEASON + "='" +
season + "' AND " + KEY_EPISODE + "='" + episode + "'", null, null, null, null);
Cursor cursor = mDatabase.query(DATABASE_TABLE, ALL_COLUMNS, KEY_SHOW_ID + " = ? AND " + KEY_SEASON + " = ? AND " + KEY_EPISODE + " = ?",
new String[]{showId, season, episode}, null, null, null);
boolean result = false;

if (cursor != null) {
Expand All @@ -203,13 +212,15 @@ public boolean hasMultipleFilepaths(String showId, String season, String episode
}

public boolean removeSeason(String showId, int season) {
return mDatabase.delete(DATABASE_TABLE, KEY_SHOW_ID + "='" + showId + "' AND " + KEY_SEASON + "='" + MizLib.addIndexZero(season) + "'", null) > 0;
return mDatabase.delete(DATABASE_TABLE, KEY_SHOW_ID + " = ? AND " + KEY_SEASON + " = ?",
new String[]{showId, MizLib.addIndexZero(season)}) > 0;
}

public boolean ignoreSeason(String showId, int season) {
ContentValues values = new ContentValues();
values.put(KEY_IGNORED, 1); // Set the ignored value to 1 (true)

return mDatabase.update(DATABASE_TABLE, values, KEY_SHOW_ID + "='" + showId + "' AND " + KEY_SEASON + "='" + MizLib.addIndexZero(season) + "'", null) > 0;
return mDatabase.update(DATABASE_TABLE, values, KEY_SHOW_ID + " = ? AND " + KEY_SEASON + " = ?",
new String[]{showId, MizLib.addIndexZero(season)}) > 0;
}
}
Loading

0 comments on commit 89f9a05

Please sign in to comment.