Skip to content

Commit cf7ee0b

Browse files
committed
fix unknown episode display issue
1 parent e6b74b7 commit cf7ee0b

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

app/src/main/java/com/wirelessalien/android/moviedb/helper/MovieDatabaseHelper.kt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,10 @@ class MovieDatabaseHelper (context: Context?) : SQLiteOpenHelper(context, databa
962962

963963
fun isShowInDatabase(movieId: Int): Boolean {
964964
val db = this.readableDatabase
965-
var cursor: android.database.Cursor? = null
965+
var cursor: Cursor? = null
966966
try {
967967
cursor = db.rawQuery(
968-
"SELECT * FROM ${MovieDatabaseHelper.TABLE_MOVIES} WHERE ${MovieDatabaseHelper.COLUMN_MOVIES_ID}=? LIMIT 1",
968+
"SELECT * FROM $TABLE_MOVIES WHERE $COLUMN_MOVIES_ID=? LIMIT 1",
969969
arrayOf(movieId.toString())
970970
)
971971
return (cursor?.count ?: 0) > 0
@@ -1115,4 +1115,25 @@ class MovieDatabaseHelper (context: Context?) : SQLiteOpenHelper(context, databa
11151115
}
11161116
return episodes
11171117
}
1118+
1119+
fun getMediaType(movieId: Int): String? {
1120+
val db = this.readableDatabase
1121+
var mediaType: String? = null
1122+
val cursor = db.query(
1123+
TABLE_MOVIES,
1124+
arrayOf(COLUMN_MOVIE),
1125+
"$COLUMN_MOVIES_ID = ?",
1126+
arrayOf(movieId.toString()),
1127+
null,
1128+
null,
1129+
null,
1130+
"1"
1131+
)
1132+
if (cursor.moveToFirst()) {
1133+
val typeInt = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_MOVIE))
1134+
mediaType = if (typeInt == 1) "movie" else "episode"
1135+
}
1136+
cursor.close()
1137+
return mediaType
1138+
}
11181139
}

app/src/main/java/com/wirelessalien/android/moviedb/work/ReleaseReminderWorker.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,14 @@ class ReleaseReminderWorker(context: Context, workerParams: WorkerParameters) :
127127
if (dateStr == null) continue
128128

129129
val calendarExists = showTraktId?.let { checkTraktCalendarExists(tktDb, it) } ?: false
130-
val movieExists = movieId?.let { checkMovieExists(movieDb, it) } ?: false
130+
val movieTypeMatches = if (movieId != null) {
131+
val dbMediaType = movieDb.getMediaType(movieId)
132+
dbMediaType == type
133+
} else {
134+
false
135+
}
131136

132-
if (calendarExists || movieExists) {
137+
if (calendarExists || movieTypeMatches) {
133138
val notificationKey = buildNotificationKey(type, movieId ?: 0, seasonNumber, episodeNumber, dateStr)
134139
if (!scheduledNotificationDbHelper.hasNotificationBeenScheduled(notificationKey)) {
135140
scheduleNotification(cursor, dateStr, notificationKey, "episode_reminder")
@@ -177,12 +182,12 @@ class ReleaseReminderWorker(context: Context, workerParams: WorkerParameters) :
177182
).use { it.count > 0 }
178183
}
179184

180-
private fun checkMovieExists(movieDb: MovieDatabaseHelper, movieId: Int): Boolean {
181-
return movieDb.readableDatabase.rawQuery(
182-
"SELECT 1 FROM ${MovieDatabaseHelper.TABLE_MOVIES} WHERE ${MovieDatabaseHelper.COLUMN_MOVIES_ID} = ?",
183-
arrayOf(movieId.toString())
184-
).use { it.count > 0 }
185-
}
185+
// private fun checkMovieExists(movieDb: MovieDatabaseHelper, movieId: Int): Boolean {
186+
// return movieDb.readableDatabase.rawQuery(
187+
// "SELECT 1 FROM ${MovieDatabaseHelper.TABLE_MOVIES} WHERE ${MovieDatabaseHelper.COLUMN_MOVIES_ID} = ?",
188+
// arrayOf(movieId.toString())
189+
// ).use { it.count > 0 }
190+
// }
186191

187192
private fun scheduleNotification(cursor: Cursor, dateStr: String, notificationKey: String, source: String) {
188193
try {

0 commit comments

Comments
 (0)