Added option to hide title on library grid view
This commit is contained in:
parent
eba07485e0
commit
18c8c6049c
@ -18,7 +18,7 @@ class DbOpenCallback : SupportSQLiteOpenHelper.Callback(DATABASE_VERSION) {
|
||||
/**
|
||||
* Version of the database.
|
||||
*/
|
||||
const val DATABASE_VERSION = 8
|
||||
const val DATABASE_VERSION = 9
|
||||
}
|
||||
|
||||
override fun onCreate(db: SupportSQLiteDatabase) = with(db) {
|
||||
@ -67,6 +67,9 @@ class DbOpenCallback : SupportSQLiteOpenHelper.Callback(DATABASE_VERSION) {
|
||||
db.execSQL(MangaTable.createLibraryIndexQuery)
|
||||
db.execSQL(ChapterTable.createUnreadChaptersIndexQuery)
|
||||
}
|
||||
if (oldVersion < 9) {
|
||||
db.execSQL(MangaTable.addHideTitle)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfigure(db: SupportSQLiteDatabase) {
|
||||
|
@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_CHAPTER_FLAGS
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_DESCRIPTION
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_FAVORITE
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_GENRE
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_HIDE_TITLE
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_ID
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_INITIALIZED
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_LAST_UPDATE
|
||||
@ -61,6 +62,7 @@ class MangaPutResolver : DefaultPutResolver<Manga>() {
|
||||
put(COL_LAST_UPDATE, obj.last_update)
|
||||
put(COL_INITIALIZED, obj.initialized)
|
||||
put(COL_VIEWER, obj.viewer)
|
||||
put(COL_HIDE_TITLE, obj.hide_title)
|
||||
put(COL_CHAPTER_FLAGS, obj.chapter_flags)
|
||||
}
|
||||
}
|
||||
@ -82,6 +84,7 @@ interface BaseMangaGetResolver {
|
||||
initialized = cursor.getInt(cursor.getColumnIndex(COL_INITIALIZED)) == 1
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,8 @@ interface Manga : SManga {
|
||||
|
||||
var chapter_flags: Int
|
||||
|
||||
var hide_title: Boolean
|
||||
|
||||
fun setChapterOrder(order: Int) {
|
||||
setFlags(order, SORT_MASK)
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ open class MangaImpl : Manga {
|
||||
|
||||
override var chapter_flags: Int = 0
|
||||
|
||||
override var hide_title: Boolean = false
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other == null || javaClass != other.javaClass) return false
|
||||
|
@ -82,6 +82,11 @@ interface MangaQueries : DbProvider {
|
||||
.withPutResolver(MangaViewerPutResolver())
|
||||
.prepare()
|
||||
|
||||
fun updateMangaHideTitle(manga: Manga) = db.put()
|
||||
.`object`(manga)
|
||||
.withPutResolver(MangaHideTitlePutResolver())
|
||||
.prepare()
|
||||
|
||||
fun updateMangaTitle(manga: Manga) = db.put()
|
||||
.`object`(manga)
|
||||
.withPutResolver(MangaTitlePutResolver())
|
||||
|
@ -0,0 +1,33 @@
|
||||
package eu.kanade.tachiyomi.data.database.resolvers
|
||||
|
||||
import android.content.ContentValues
|
||||
import com.pushtorefresh.storio.sqlite.StorIOSQLite
|
||||
import com.pushtorefresh.storio.sqlite.operations.put.PutResolver
|
||||
import com.pushtorefresh.storio.sqlite.operations.put.PutResult
|
||||
import com.pushtorefresh.storio.sqlite.queries.UpdateQuery
|
||||
import eu.kanade.tachiyomi.data.database.inTransactionReturn
|
||||
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||
|
||||
class MangaHideTitlePutResolver : PutResolver<Manga>() {
|
||||
|
||||
override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn {
|
||||
val updateQuery = mapToUpdateQuery(manga)
|
||||
val contentValues = mapToContentValues(manga)
|
||||
|
||||
val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues)
|
||||
PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table())
|
||||
}
|
||||
|
||||
fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder()
|
||||
.table(MangaTable.TABLE)
|
||||
.where("${MangaTable.COL_ID} = ?")
|
||||
.whereArgs(manga.id)
|
||||
.build()
|
||||
|
||||
fun mapToContentValues(manga: Manga) = ContentValues(1).apply {
|
||||
put(MangaTable.COL_HIDE_TITLE, manga.hide_title)
|
||||
}
|
||||
|
||||
}
|
@ -38,6 +38,8 @@ object MangaTable {
|
||||
|
||||
const val COL_CATEGORY = "category"
|
||||
|
||||
const val COL_HIDE_TITLE = "hideTitle"
|
||||
|
||||
val createTableQuery: String
|
||||
get() = """CREATE TABLE $TABLE(
|
||||
$COL_ID INTEGER NOT NULL PRIMARY KEY,
|
||||
@ -54,6 +56,7 @@ object MangaTable {
|
||||
$COL_LAST_UPDATE LONG,
|
||||
$COL_INITIALIZED BOOLEAN NOT NULL,
|
||||
$COL_VIEWER INTEGER NOT NULL,
|
||||
$COL_HIDE_TITLE INTEGER NOT NULL,
|
||||
$COL_CHAPTER_FLAGS INTEGER NOT NULL
|
||||
)"""
|
||||
|
||||
@ -63,4 +66,7 @@ object MangaTable {
|
||||
val createLibraryIndexQuery: String
|
||||
get() = "CREATE INDEX library_${COL_FAVORITE}_index ON $TABLE($COL_FAVORITE) " +
|
||||
"WHERE $COL_FAVORITE = 1"
|
||||
|
||||
val addHideTitle: String
|
||||
get() = "ALTER TABLE $TABLE ADD COLUMN $COL_HIDE_TITLE INTEGER DEFAULT 0"
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
this.controller = controller
|
||||
|
||||
recycler = if (preferences.libraryAsList().getOrDefault()) {
|
||||
(swipe_refresh.inflate(R.layout.library_list_recycler) as androidx.recyclerview.widget.RecyclerView).apply {
|
||||
layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
|
||||
(swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
} else {
|
||||
(swipe_refresh.inflate(R.layout.library_grid_recycler) as AutofitRecyclerView).apply {
|
||||
|
@ -30,6 +30,7 @@ import com.jakewharton.rxrelay.BehaviorRelay
|
||||
import com.jakewharton.rxrelay.PublishRelay
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
@ -435,6 +436,15 @@ class LibraryController(
|
||||
} else {
|
||||
mode.title = resources?.getString(R.string.label_selected, count)
|
||||
menu.findItem(R.id.action_edit_cover)?.isVisible = count == 1
|
||||
menu.findItem(R.id.action_hide_title)?.isVisible =
|
||||
!preferences.libraryAsList().getOrDefault()
|
||||
if (!preferences.libraryAsList().getOrDefault()) {
|
||||
val showAll =
|
||||
(selectedMangas.filter { (it as? LibraryManga)?.hide_title == true }).size == selectedMangas.size
|
||||
menu.findItem(R.id.action_hide_title)?.title = activity?.getString(
|
||||
if (showAll) R.string.label_show_title else R.string.label_hide_title
|
||||
)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -453,6 +463,12 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
R.id.action_migrate -> startMangaMigration()
|
||||
R.id.action_hide_title -> {
|
||||
val showAll = (selectedMangas.filter { (it as? LibraryManga)?.hide_title == true }
|
||||
).size == selectedMangas.size
|
||||
presenter.hideShowTitle(selectedMangas.toList(), !showAll)
|
||||
destroyActionModeIfNeeded()
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
return true
|
||||
|
@ -32,7 +32,11 @@ class LibraryGridHolder(
|
||||
*/
|
||||
override fun onSetValues(item: LibraryItem) {
|
||||
// Update the title of the manga.
|
||||
title.text = item.manga.title
|
||||
with(title) {
|
||||
visibility = if (item.manga.hide_title) View.GONE else View.VISIBLE
|
||||
text = item.manga.title
|
||||
}
|
||||
gradient.visibility = if (item.manga.hide_title) View.GONE else View.VISIBLE
|
||||
|
||||
// Update the unread count and its visibility.
|
||||
with(unread_text) {
|
||||
|
@ -5,6 +5,7 @@ import com.jakewharton.rxrelay.BehaviorRelay
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaCategory
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
@ -372,6 +373,15 @@ class LibraryPresenter(
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
fun hideShowTitle(mangas: List<Manga>, hide: Boolean) {
|
||||
mangas.forEach { it.hide_title = hide }
|
||||
db.inTransaction {
|
||||
mangas.forEach {
|
||||
db.updateMangaHideTitle(it).executeAsBlocking()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateMangaInternal(source: Source, sourceChapters: List<SChapter>,
|
||||
prevManga: Manga, manga: Manga, replace: Boolean) {
|
||||
|
||||
|
@ -76,16 +76,6 @@ class MangaController : RxController, TabbedController {
|
||||
)
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
backClosesApp = false
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
backClosesApp = false
|
||||
super.onActivityResumed(activity)
|
||||
}
|
||||
|
||||
override fun handleBack(): Boolean {
|
||||
return if (backClosesApp) {
|
||||
activity?.finishAffinity()
|
||||
@ -99,8 +89,7 @@ class MangaController : RxController, TabbedController {
|
||||
var source: Source? = null
|
||||
private set
|
||||
|
||||
var backClosesApp = false
|
||||
private set
|
||||
private var backClosesApp = false
|
||||
|
||||
var startingChapterYPos:Float? = null
|
||||
|
||||
|
@ -29,4 +29,10 @@
|
||||
android:title="@string/label_migration"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_hide_title"
|
||||
android:icon="@drawable/baseline_swap_calls_white_24"
|
||||
android:title="@string/label_hide_title"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
@ -22,6 +22,8 @@
|
||||
<string name="label_selected">Selected: %1$d</string>
|
||||
<string name="label_backup">Backup</string>
|
||||
<string name="label_migration">Source migration</string>
|
||||
<string name="label_hide_title">Hide title</string>
|
||||
<string name="label_show_title">Show title</string>
|
||||
<string name="label_extensions">Extensions</string>
|
||||
<string name="label_extension_info">Extension info</string>
|
||||
<string name="label_help">Help</string>
|
||||
|
Loading…
Reference in New Issue
Block a user