diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt index 222fac6882..7fbd7089a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt @@ -20,7 +20,7 @@ class DbOpenCallback : SupportSQLiteOpenHelper.Callback(DATABASE_VERSION) { /** * Version of the database. */ - const val DATABASE_VERSION = 11 + const val DATABASE_VERSION = 12 } override fun onCreate(db: SupportSQLiteDatabase) = with(db) { @@ -78,6 +78,9 @@ class DbOpenCallback : SupportSQLiteOpenHelper.Callback(DATABASE_VERSION) { if (oldVersion < 11) { db.execSQL(ChapterTable.pagesLeftQuery) } + if (oldVersion < 12) { + db.execSQL(MangaTable.addDateAddedCol) + } } override fun onConfigure(db: SupportSQLiteDatabase) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt index ac89bbc209..42b82ddd50 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt @@ -11,6 +11,7 @@ import com.pushtorefresh.storio.sqlite.queries.InsertQuery import com.pushtorefresh.storio.sqlite.queries.UpdateQuery import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaImpl +import eu.kanade.tachiyomi.data.database.tables.MangaTable import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_ARTIST import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_AUTHOR import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_CHAPTER_FLAGS @@ -64,6 +65,7 @@ class MangaPutResolver : DefaultPutResolver() { put(COL_VIEWER, obj.viewer) put(COL_HIDE_TITLE, obj.hide_title) put(COL_CHAPTER_FLAGS, obj.chapter_flags) + put(MangaTable.COL_DATE_ADDED, obj.date_added) } } @@ -85,6 +87,7 @@ interface BaseMangaGetResolver { viewer = cursor.getInt(cursor.getColumnIndex(COL_VIEWER)) chapter_flags = cursor.getInt(cursor.getColumnIndex(COL_CHAPTER_FLAGS)) hide_title = cursor.getInt(cursor.getColumnIndex(COL_HIDE_TITLE)) == 1 + date_added = cursor.getLong(cursor.getColumnIndex(MangaTable.COL_DATE_ADDED)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt index 8896493176..4ae78d49c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt @@ -36,6 +36,7 @@ interface Category : Serializable { LAST_READ_ASC, LAST_READ_DSC -> LibrarySort.LAST_READ TOTAL_ASC, TOTAL_DSC -> LibrarySort.TOTAL DRAG_AND_DROP -> LibrarySort.DRAG_AND_DROP + DATE_ADDED_ASC, DATE_ADDED_DSC -> LibrarySort.DATE_ADDED else -> null } @@ -45,6 +46,7 @@ interface Category : Serializable { UNREAD_ASC, UNREAD_DSC -> R.string.action_filter_unread LAST_READ_ASC, LAST_READ_DSC -> R.string.action_sort_last_read TOTAL_ASC, TOTAL_DSC -> R.string.action_sort_total + DATE_ADDED_ASC, DATE_ADDED_DSC -> R.string.action_date_added else -> R.string.action_sort_drag_and_drop } @@ -54,6 +56,7 @@ interface Category : Serializable { UNREAD_ASC, UNREAD_DSC -> 2 LAST_READ_ASC, LAST_READ_DSC -> 3 TOTAL_ASC, TOTAL_DSC -> 4 + DATE_ADDED_ASC, DATE_ADDED_DSC -> 5 else -> null } @@ -64,6 +67,7 @@ interface Category : Serializable { LibrarySort.UNREAD -> UNREAD_ASC LibrarySort.LAST_READ -> LAST_READ_ASC LibrarySort.TOTAL -> ALPHA_ASC + LibrarySort.DATE_ADDED -> DATE_ADDED_ASC else -> ALPHA_ASC } } @@ -80,6 +84,8 @@ interface Category : Serializable { private const val LAST_READ_DSC = 'h' private const val TOTAL_ASC = 'i' private const val TOTAL_DSC = 'j' + private const val DATE_ADDED_ASC = 'k' + private const val DATE_ADDED_DSC = 'l' fun create(name: String): Category = CategoryImpl().apply { this.name = name @@ -100,6 +106,7 @@ interface Category : Serializable { LibrarySort.UNREAD -> UNREAD_ASC LibrarySort.LAST_READ -> LAST_READ_ASC LibrarySort.TOTAL -> TOTAL_ASC + LibrarySort.DATE_ADDED -> DATE_ADDED_ASC LibrarySort.DRAG_AND_DROP -> DRAG_AND_DROP else -> DRAG_AND_DROP } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index 7f0baec7a2..e50d2ac22b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -17,6 +17,8 @@ interface Manga : SManga { var last_update: Long + var date_added: Long + var viewer: Int var chapter_flags: Int diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt index a1736d485a..82dfcefd36 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt @@ -40,6 +40,8 @@ open class MangaImpl : Manga { override var hide_title: Boolean = false + override var date_added: Long = 0 + override fun copyFrom(other: SManga) { if (other is MangaImpl && (other as MangaImpl)::title.isInitialized && !other.title.isBlank() && other.title != title) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt index c642536b01..27a087b3c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt @@ -40,6 +40,8 @@ object MangaTable { const val COL_HIDE_TITLE = "hideTitle" + const val COL_DATE_ADDED = "date_added" + val createTableQuery: String get() = """CREATE TABLE $TABLE( $COL_ID INTEGER NOT NULL PRIMARY KEY, @@ -57,7 +59,9 @@ object MangaTable { $COL_INITIALIZED BOOLEAN NOT NULL, $COL_VIEWER INTEGER NOT NULL, $COL_HIDE_TITLE INTEGER NOT NULL, - $COL_CHAPTER_FLAGS INTEGER NOT NULL + $COL_CHAPTER_FLAGS INTEGER NOT NULL, + $COL_DATE_ADDED LONG + )""" val createUrlIndexQuery: String @@ -69,4 +73,7 @@ object MangaTable { val addHideTitle: String get() = "ALTER TABLE $TABLE ADD COLUMN $COL_HIDE_TITLE INTEGER DEFAULT 0" + + val addDateAddedCol: String + get() = "ALTER TABLE ${MangaTable.TABLE} ADD COLUMN ${MangaTable.COL_DATE_ADDED} LONG DEFAULT 0" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt index 47b2eec0a9..040e693e49 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt @@ -37,6 +37,7 @@ import rx.subjects.PublishSubject import timber.log.Timber import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import java.util.Date /** * Presenter of [BrowseCatalogueController]. @@ -272,6 +273,12 @@ open class BrowseCataloguePresenter( */ fun changeMangaFavorite(manga: Manga) { manga.favorite = !manga.favorite + + when (manga.favorite) { + true -> manga.date_added = Date().time + false -> manga.date_added = 0 + } + db.insertManga(manga).executeAsBlocking() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt index 4eaef458b8..48eb89fa7b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt @@ -103,6 +103,7 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int LibrarySort.UNREAD -> R.string.action_filter_unread LibrarySort.LAST_READ -> R.string.action_sort_last_read LibrarySort.ALPHA -> R.string.title + LibrarySort.DATE_ADDED -> R.string.action_date_added else -> R.string.action_sort_drag_and_drop } )) @@ -165,6 +166,7 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int LibrarySort.LAST_READ -> R.id.action_last_read LibrarySort.UNREAD -> R.id.action_unread LibrarySort.LATEST_CHAPTER -> R.id.action_update + LibrarySort.DATE_ADDED -> R.id.action_date_added else -> R.id.action_alpha } ) @@ -208,6 +210,7 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int adapter.libraryListener.sortCategory(category.id!!, 'D' - 'a' + 1) return } + R.id.action_date_added -> 5 R.id.action_total_chaps -> 4 R.id.action_last_read -> 3 R.id.action_unread -> 2 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index ac48867179..bb459d39b9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -345,6 +345,9 @@ class LibraryPresenter( i2.chapterCount = totalChapters!![i2.manga.id!!] ?: 0 manga1TotalChapter.compareTo(mange2TotalChapter) } + sortingMode == LibrarySort.DATE_ADDED -> { + i1.manga.date_added.compareTo(i2.manga.date_added) + } else -> 0 } if (compare == 0) { @@ -418,6 +421,7 @@ class LibraryPresenter( i2.chapterCount = totalChapters!![i2.manga.id!!] ?: 0 manga1TotalChapter.compareTo(mange2TotalChapter) } + LibrarySort.DATE_ADDED -> i1.manga.date_added.compareTo(i2.manga.date_added) else -> sortAlphabetical(i1, i2) } if (!category.isAscending()) sort *= -1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt index 8e31025ecf..956e2f5816 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt @@ -8,4 +8,5 @@ object LibrarySort { const val UNREAD = 3 const val TOTAL = 4 const val DRAG_AND_DROP = 6 + const val DATE_ADDED = 7 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index f8e790c4b0..b0f40bd9ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -488,6 +488,12 @@ class MangaDetailsPresenter( fun toggleFavorite(): Boolean { manga.favorite = !manga.favorite + + when (manga.favorite) { + true -> manga.date_added = Date().time + false -> manga.date_added = 0 + } + db.insertManga(manga).executeAsBlocking() controller.updateHeader() return manga.favorite diff --git a/app/src/main/res/menu/cat_sort.xml b/app/src/main/res/menu/cat_sort.xml index 78cd8a7302..a227ea2513 100644 --- a/app/src/main/res/menu/cat_sort.xml +++ b/app/src/main/res/menu/cat_sort.xml @@ -26,4 +26,9 @@ android:id="@+id/action_total_chaps" android:title="@string/action_sort_total" android:icon="@drawable/ic_blank_24dp"/> + + \ No newline at end of file diff --git a/app/src/main/res/menu/main_sort.xml b/app/src/main/res/menu/main_sort.xml index b64dd7c8fa..5c6bb3b2ac 100644 --- a/app/src/main/res/menu/main_sort.xml +++ b/app/src/main/res/menu/main_sort.xml @@ -31,4 +31,9 @@ android:title="@string/action_sort_drag_and_drop" android:icon="@drawable/ic_blank_24dp"/> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c4861b404e..4806a59258 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -70,6 +70,7 @@ Alphabetically Enabled Total chapters + Date added Last read Drag & Drop Search