mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Add sort by date added
This commit is contained in:
parent
362a088367
commit
a7765146fd
@ -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) {
|
||||
|
@ -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<Manga>() {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ interface Manga : SManga {
|
||||
|
||||
var last_update: Long
|
||||
|
||||
var date_added: Long
|
||||
|
||||
var viewer: Int
|
||||
|
||||
var chapter_flags: Int
|
||||
|
@ -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) {
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -26,4 +26,9 @@
|
||||
android:id="@+id/action_total_chaps"
|
||||
android:title="@string/action_sort_total"
|
||||
android:icon="@drawable/ic_blank_24dp"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_date_added"
|
||||
android:title="@string/action_date_added"
|
||||
android:icon="@drawable/ic_blank_24dp"/>
|
||||
</menu>
|
@ -31,4 +31,9 @@
|
||||
android:title="@string/action_sort_drag_and_drop"
|
||||
android:icon="@drawable/ic_blank_24dp"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_date_added"
|
||||
android:title="@string/action_date_added"
|
||||
android:icon="@drawable/ic_blank_24dp"/>
|
||||
|
||||
</menu>
|
@ -70,6 +70,7 @@
|
||||
<string name="action_sort_alpha">Alphabetically</string>
|
||||
<string name="action_sort_enabled">Enabled</string>
|
||||
<string name="action_sort_total">Total chapters</string>
|
||||
<string name="action_date_added">Date Added</string>
|
||||
<string name="action_sort_last_read">Last read</string>
|
||||
<string name="action_sort_drag_and_drop">Drag & Drop</string>
|
||||
<string name="action_search">Search</string>
|
||||
|
Loading…
Reference in New Issue
Block a user