From b2a1ba777d805e2a8a90db7c3fb9ebf15c9edee7 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 3 Oct 2015 00:27:47 +0200 Subject: [PATCH] Use constraints, delete chapters when deleting a Manga --- .../java/eu/kanade/mangafeed/data/helpers/DbOpenHelper.java | 6 ++++++ .../java/eu/kanade/mangafeed/data/tables/ChaptersTable.java | 3 ++- .../eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/DbOpenHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/DbOpenHelper.java index 9eeb40b27e..3a4de35a55 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/DbOpenHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/helpers/DbOpenHelper.java @@ -27,4 +27,10 @@ public class DbOpenHelper extends SQLiteOpenHelper { public void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) { // no impl } + + @Override + public void onConfigure(SQLiteDatabase db){ + db.setForeignKeyConstraintsEnabled(true); + } + } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java b/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java index 88eb8c601c..e11c405530 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java @@ -37,7 +37,8 @@ public class ChaptersTable { + COLUMN_NAME + " TEXT NOT NULL, " + COLUMN_READ + " BOOLEAN NOT NULL, " + COLUMN_DATE_FETCH + " LONG NOT NULL, " - + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangasTable.TABLE + "(" + MangasTable.COLUMN_ID + ")" + + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangasTable.TABLE + "(" + MangasTable.COLUMN_ID + ") " + + "ON DELETE CASCADE" + ");"; } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java index 87112f7656..f23e75debf 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java @@ -36,6 +36,9 @@ public class MangaLibraryHolder extends ItemViewHolder { mUnreadText.setVisibility(View.VISIBLE); mUnreadText.setText(Integer.toString(manga.unread)); } + else { + mUnreadText.setVisibility(View.GONE); + } Glide.with(getContext()) .load("http://img1.wikia.nocookie.net/__cb20090524204255/starwars/images/thumb/1/1a/R2d2.jpg/400px-R2d2.jpg") .centerCrop()