Add manga-wised rotation mode settings

Co-Authored-By: Andreas <6576096+ghostbear@users.noreply.github.com>
This commit is contained in:
Jays2Kings 2021-07-10 17:33:09 -04:00
parent 2ac761729d
commit 5911ad2fd4
30 changed files with 393 additions and 261 deletions

View File

@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.updater.UpdaterJob
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import eu.kanade.tachiyomi.ui.library.LibraryPresenter
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
import eu.kanade.tachiyomi.util.system.toast
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -113,7 +114,12 @@ object Migrations {
}
if (oldVersion < 73) {
// Reset rotation to Free after replacing Lock
preferences.rotation().set(1)
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
if (prefs.contains("pref_rotation_type_key")) {
prefs.edit {
putInt("pref_rotation_type_key", 1)
}
}
}
if (oldVersion < 74) {
// Turn on auto updates for all users
@ -141,6 +147,28 @@ object Migrations {
LibraryUpdateJob.setupTask(context, 3)
}
}
if (oldVersion < 77) {
// Migrate Rotation and Viewer values to default values for viewer_flags
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {
1 -> OrientationType.FREE.flagValue
2 -> OrientationType.PORTRAIT.flagValue
3 -> OrientationType.LANDSCAPE.flagValue
4 -> OrientationType.LOCKED_PORTRAIT.flagValue
5 -> OrientationType.LOCKED_LANDSCAPE.flagValue
else -> OrientationType.FREE.flagValue
}
// Reading mode flag and prefValue is the same value
val newReadingMode = prefs.getInt("pref_default_viewer_key", 1)
prefs.edit {
putInt("pref_default_orientation_type_key", newOrientation)
remove("pref_rotation_type_key")
putInt("pref_default_reading_mode_key", newReadingMode)
remove("pref_default_viewer_key")
}
}
return true
}
return false

View File

@ -26,7 +26,7 @@ data class BackupManga(
// @ProtoNumber(11) val lastUpdate: Long = 0, 1.x value, not used in 0.x
// @ProtoNumber(12) val lastInit: Long = 0, 1.x value, not used in 0.x
@ProtoNumber(13) var dateAdded: Long = 0,
@ProtoNumber(14) var viewer: Int = 0,
@ProtoNumber(14) var viewer: Int = 0, // Replaced by viewer_flags
// @ProtoNumber(15) val flags: Int = 0, 1.x value, not used in 0.x
@ProtoNumber(16) var chapters: List<BackupChapter> = emptyList(),
@ProtoNumber(17) var categories: List<Int> = emptyList(),
@ -35,6 +35,7 @@ data class BackupManga(
@ProtoNumber(100) var favorite: Boolean = true,
@ProtoNumber(101) var chapterFlags: Int = 0,
@ProtoNumber(102) var history: List<BackupHistory> = emptyList(),
@ProtoNumber(103) var viewer_flags: Int? = null,
// SY specific values
@ProtoNumber(602) var customStatus: Int = 0,
@ -60,7 +61,11 @@ data class BackupManga(
favorite = this@BackupManga.favorite
source = this@BackupManga.source
date_added = this@BackupManga.dateAdded
viewer = this@BackupManga.viewer
viewer_flags = (
this@BackupManga.viewer_flags
?: this@BackupManga.viewer
).takeIf { it != 0 }
?: -1
chapter_flags = this@BackupManga.chapterFlags
}
}
@ -112,7 +117,8 @@ data class BackupManga(
favorite = manga.favorite,
source = manga.source,
dateAdded = manga.date_added,
viewer = manga.viewer,
viewer = manga.readingModeType,
viewer_flags = manga.viewer_flags.takeIf { it != -1 } ?: 0,
chapterFlags = manga.chapter_flags
).also { backupManga ->
customMangaManager?.getManga(manga)?.let {

View File

@ -16,7 +16,7 @@ object MangaTypeAdapter {
value(it.url)
value(it.title)
value(it.source)
value(it.viewer)
value(it.viewer_flags)
value(it.chapter_flags)
endArray()
}
@ -27,7 +27,7 @@ object MangaTypeAdapter {
manga.url = nextString()
manga.title = nextString()
manga.source = nextLong()
manga.viewer = nextInt()
manga.viewer_flags = nextInt()
manga.chapter_flags = nextInt()
endArray()
manga

View File

@ -62,7 +62,7 @@ class MangaPutResolver : DefaultPutResolver<Manga>() {
put(COL_FAVORITE, obj.favorite)
put(COL_LAST_UPDATE, obj.last_update)
put(COL_INITIALIZED, obj.initialized)
put(COL_VIEWER, obj.viewer)
put(COL_VIEWER, obj.viewer_flags)
put(COL_HIDE_TITLE, obj.hide_title)
put(COL_CHAPTER_FLAGS, obj.chapter_flags)
put(COL_DATE_ADDED, obj.date_added)
@ -84,7 +84,7 @@ interface BaseMangaGetResolver {
favorite = cursor.getInt(cursor.getColumnIndex(COL_FAVORITE)) == 1
last_update = cursor.getLong(cursor.getColumnIndex(COL_LAST_UPDATE))
initialized = cursor.getInt(cursor.getColumnIndex(COL_INITIALIZED)) == 1
viewer = cursor.getInt(cursor.getColumnIndex(COL_VIEWER))
viewer_flags = 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(COL_DATE_ADDED))

View File

@ -4,7 +4,8 @@ import android.content.Context
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType
import tachiyomi.source.model.MangaInfo
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -22,7 +23,7 @@ interface Manga : SManga {
var date_added: Long
var viewer: Int
var viewer_flags: Int
var chapter_flags: Int
@ -32,26 +33,30 @@ interface Manga : SManga {
fun isHidden() = status == -1
fun setChapterOrder(order: Int) {
setFlags(order, SORT_MASK)
setFlags(SORT_LOCAL, SORT_SELF_MASK)
setChapterFlags(order, CHAPTER_SORT_MASK)
setChapterFlags(CHAPTER_SORT_LOCAL, CHAPTER_SORT_SELF_MASK)
}
fun setSortToGlobal() = setFlags(SORT_GLOBAL, SORT_SELF_MASK)
fun setSortToGlobal() = setChapterFlags(CHAPTER_SORT_GLOBAL, CHAPTER_SORT_SELF_MASK)
private fun setFlags(flag: Int, mask: Int) {
private fun setChapterFlags(flag: Int, mask: Int) {
chapter_flags = chapter_flags and mask.inv() or (flag and mask)
}
fun sortDescending(): Boolean = chapter_flags and SORT_MASK == SORT_DESC
private fun setViewerFlags(flag: Int, mask: Int) {
viewer_flags = viewer_flags and mask.inv() or (flag and mask)
}
fun usesLocalSort(): Boolean = chapter_flags and SORT_SELF_MASK == SORT_LOCAL
fun sortDescending(): Boolean = chapter_flags and CHAPTER_SORT_MASK == CHAPTER_SORT_DESC
fun usesLocalSort(): Boolean = chapter_flags and CHAPTER_SORT_SELF_MASK == CHAPTER_SORT_LOCAL
fun sortDescending(defaultDesc: Boolean): Boolean {
return if (chapter_flags and SORT_SELF_MASK == SORT_GLOBAL) defaultDesc
return if (chapter_flags and CHAPTER_SORT_SELF_MASK == CHAPTER_SORT_GLOBAL) defaultDesc
else sortDescending()
}
fun showChapterTitle(defaultShow: Boolean): Boolean = chapter_flags and DISPLAY_MASK == DISPLAY_NUMBER
fun showChapterTitle(defaultShow: Boolean): Boolean = chapter_flags and CHAPTER_DISPLAY_MASK == CHAPTER_DISPLAY_NUMBER
fun seriesType(context: Context, sourceManager: SourceManager? = null): String {
return context.getString(
@ -125,7 +130,7 @@ interface Manga : SManga {
currentTags.none { tag -> isComicTag(tag) }
)
) {
ReaderActivity.WEBTOON
ReadingModeType.WEBTOON.flagValue
} else if (currentTags.any
{ tag ->
tag == "chinese" || tag == "manhua" ||
@ -136,7 +141,7 @@ interface Manga : SManga {
) ||
(sourceName.contains("manhua", true) && currentTags.none { tag -> isMangaTag(tag) })
) {
ReaderActivity.LEFT_TO_RIGHT
ReadingModeType.LEFT_TO_RIGHT.flagValue
} else 0
}
@ -194,57 +199,65 @@ interface Manga : SManga {
// Used to display the chapter's title one way or another
var displayMode: Int
get() = chapter_flags and DISPLAY_MASK
set(mode) = setFlags(mode, DISPLAY_MASK)
get() = chapter_flags and CHAPTER_DISPLAY_MASK
set(mode) = setChapterFlags(mode, CHAPTER_DISPLAY_MASK)
var readFilter: Int
get() = chapter_flags and READ_MASK
set(filter) = setFlags(filter, READ_MASK)
get() = chapter_flags and CHAPTER_READ_MASK
set(filter) = setChapterFlags(filter, CHAPTER_READ_MASK)
var downloadedFilter: Int
get() = chapter_flags and DOWNLOADED_MASK
set(filter) = setFlags(filter, DOWNLOADED_MASK)
get() = chapter_flags and CHAPTER_DOWNLOADED_MASK
set(filter) = setChapterFlags(filter, CHAPTER_DOWNLOADED_MASK)
var bookmarkedFilter: Int
get() = chapter_flags and BOOKMARKED_MASK
set(filter) = setFlags(filter, BOOKMARKED_MASK)
get() = chapter_flags and CHAPTER_BOOKMARKED_MASK
set(filter) = setChapterFlags(filter, CHAPTER_BOOKMARKED_MASK)
var sorting: Int
get() = chapter_flags and SORTING_MASK
set(sort) = setFlags(sort, SORTING_MASK)
get() = chapter_flags and CHAPTER_SORTING_MASK
set(sort) = setChapterFlags(sort, CHAPTER_SORTING_MASK)
var readingModeType: Int
get() = viewer_flags and ReadingModeType.MASK
set(readingMode) = setViewerFlags(readingMode, ReadingModeType.MASK)
var orientationType: Int
get() = viewer_flags and OrientationType.MASK
set(rotationType) = setViewerFlags(rotationType, OrientationType.MASK)
companion object {
const val SORT_DESC = 0x00000000
const val SORT_ASC = 0x00000001
const val SORT_MASK = 0x00000001
const val CHAPTER_SORT_DESC = 0x00000000
const val CHAPTER_SORT_ASC = 0x00000001
const val CHAPTER_SORT_MASK = 0x00000001
const val SORT_GLOBAL = 0x00000000
const val SORT_LOCAL = 0x00001000
const val SORT_SELF_MASK = 0x00001000
const val CHAPTER_SORT_GLOBAL = 0x00000000
const val CHAPTER_SORT_LOCAL = 0x00001000
const val CHAPTER_SORT_SELF_MASK = 0x00001000
// Generic filter that does not filter anything
const val SHOW_ALL = 0x00000000
const val SHOW_UNREAD = 0x00000002
const val SHOW_READ = 0x00000004
const val READ_MASK = 0x00000006
const val CHAPTER_SHOW_UNREAD = 0x00000002
const val CHAPTER_SHOW_READ = 0x00000004
const val CHAPTER_READ_MASK = 0x00000006
const val SHOW_DOWNLOADED = 0x00000008
const val SHOW_NOT_DOWNLOADED = 0x00000010
const val DOWNLOADED_MASK = 0x00000018
const val CHAPTER_SHOW_DOWNLOADED = 0x00000008
const val CHAPTER_SHOW_NOT_DOWNLOADED = 0x00000010
const val CHAPTER_DOWNLOADED_MASK = 0x00000018
const val SHOW_BOOKMARKED = 0x00000020
const val SHOW_NOT_BOOKMARKED = 0x00000040
const val BOOKMARKED_MASK = 0x00000060
const val CHAPTER_SHOW_BOOKMARKED = 0x00000020
const val CHAPTER_SHOW_NOT_BOOKMARKED = 0x00000040
const val CHAPTER_BOOKMARKED_MASK = 0x00000060
const val SORTING_SOURCE = 0x00000000
const val SORTING_NUMBER = 0x00000100
const val SORTING_MASK = 0x00000100
const val CHAPTER_SORTING_SOURCE = 0x00000000
const val CHAPTER_SORTING_NUMBER = 0x00000100
const val CHAPTER_SORTING_MASK = 0x00000100
const val DISPLAY_NAME = 0x00000000
const val DISPLAY_NUMBER = 0x00100000
const val DISPLAY_MASK = 0x00100000
const val CHAPTER_DISPLAY_NAME = 0x00000000
const val CHAPTER_DISPLAY_NUMBER = 0x00100000
const val CHAPTER_DISPLAY_MASK = 0x00100000
const val TYPE_MANGA = 1
const val TYPE_MANHWA = 2

View File

@ -56,7 +56,7 @@ open class MangaImpl : Manga {
override var initialized: Boolean = false
override var viewer: Int = -1
override var viewer_flags: Int = -1
override var chapter_flags: Int = 0

View File

@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.data.database.resolvers.MangaFlagsPutResolver
import eu.kanade.tachiyomi.data.database.resolvers.MangaInfoPutResolver
import eu.kanade.tachiyomi.data.database.resolvers.MangaLastUpdatedPutResolver
import eu.kanade.tachiyomi.data.database.resolvers.MangaTitlePutResolver
import eu.kanade.tachiyomi.data.database.resolvers.MangaViewerPutResolver
import eu.kanade.tachiyomi.data.database.tables.CategoryTable
import eu.kanade.tachiyomi.data.database.tables.ChapterTable
import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable
@ -79,9 +78,24 @@ interface MangaQueries : DbProvider {
fun insertMangas(mangas: List<Manga>) = db.put().objects(mangas).prepare()
fun updateFlags(manga: Manga) = db.put()
fun updateChapterFlags(manga: Manga) = db.put()
.`object`(manga)
.withPutResolver(MangaFlagsPutResolver())
.withPutResolver(MangaFlagsPutResolver(MangaTable.COL_CHAPTER_FLAGS, Manga::chapter_flags))
.prepare()
fun updateChapterFlags(manga: List<Manga>) = db.put()
.objects(manga)
.withPutResolver(MangaFlagsPutResolver(MangaTable.COL_CHAPTER_FLAGS, Manga::chapter_flags, true))
.prepare()
fun updateViewerFlags(manga: Manga) = db.put()
.`object`(manga)
.withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags))
.prepare()
fun updateViewerFlags(manga: List<Manga>) = db.put()
.objects(manga)
.withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags, true))
.prepare()
fun updateLastUpdated(manga: Manga) = db.put()
@ -99,11 +113,6 @@ interface MangaQueries : DbProvider {
.withPutResolver(MangaDateAddedPutResolver())
.prepare()
fun updateMangaViewer(manga: Manga) = db.put()
.`object`(manga)
.withPutResolver(MangaViewerPutResolver())
.prepare()
fun updateMangaTitle(manga: Manga) = db.put()
.`object`(manga)
.withPutResolver(MangaTitlePutResolver())

View File

@ -1,6 +1,6 @@
package eu.kanade.tachiyomi.data.database.resolvers
import android.content.ContentValues
import androidx.core.content.contentValuesOf
import com.pushtorefresh.storio.sqlite.StorIOSQLite
import com.pushtorefresh.storio.sqlite.operations.put.PutResolver
import com.pushtorefresh.storio.sqlite.operations.put.PutResult
@ -8,8 +8,9 @@ import com.pushtorefresh.storio.sqlite.queries.UpdateQuery
import eu.kanade.tachiyomi.data.database.inTransactionReturn
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.tables.MangaTable
import kotlin.reflect.KProperty1
class MangaFlagsPutResolver : PutResolver<Manga>() {
class MangaFlagsPutResolver(private val colName: String, private val fieldGetter: KProperty1<Manga, Int>, private val updateAll: Boolean = false) : PutResolver<Manga>() {
override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn {
val updateQuery = mapToUpdateQuery(manga)
@ -19,13 +20,24 @@ class MangaFlagsPutResolver : PutResolver<Manga>() {
PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table())
}
fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder()
.table(MangaTable.TABLE)
.where("${MangaTable.COL_ID} = ?")
.whereArgs(manga.id)
.build()
fun mapToUpdateQuery(manga: Manga): UpdateQuery {
val builder = UpdateQuery.builder()
fun mapToContentValues(manga: Manga) = ContentValues(1).apply {
put(MangaTable.COL_CHAPTER_FLAGS, manga.chapter_flags)
return if (updateAll) {
builder
.table(MangaTable.TABLE)
.build()
} else {
builder
.table(MangaTable.TABLE)
.where("${MangaTable.COL_ID} = ?")
.whereArgs(manga.id)
.build()
}
}
fun mapToContentValues(manga: Manga) =
contentValuesOf(
colName to fieldGetter.get(manga)
)
}

View File

@ -1,31 +0,0 @@
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.Manga
import eu.kanade.tachiyomi.data.database.tables.MangaTable
class MangaViewerPutResolver : 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_VIEWER, manga.viewer)
}
}

View File

@ -18,8 +18,6 @@ object PreferenceKeys {
const val deniedA11FilePermission = "denied_a11_file_permission"
const val rotation = "pref_rotation_type_key"
const val enableTransitions = "pref_enable_transitions_key"
const val pagerCutoutBehavior = "pager_cutout_behavior"
@ -44,7 +42,9 @@ object PreferenceKeys {
const val colorFilterMode = "color_filter_mode"
const val defaultViewer = "pref_default_viewer_key"
const val defaultReadingMode = "pref_default_reading_mode_key"
const val defaultOrientationType = "pref_default_orientation_type_key"
const val imageScaleType = "pref_image_scale_type_key"
@ -229,6 +229,18 @@ object PreferenceKeys {
const val incognitoMode = "incognito_mode"
const val defaultChapterFilterByRead = "default_chapter_filter_by_read"
const val defaultChapterFilterByDownloaded = "default_chapter_filter_by_downloaded"
const val defaultChapterFilterByBookmarked = "default_chapter_filter_by_bookmarked"
const val defaultChapterSortBySourceOrNumber = "default_chapter_sort_by_source_or_number" // and upload date
const val defaultChapterSortByAscendingOrDescending = "default_chapter_sort_by_ascending_or_descending"
const val defaultChapterDisplayByNameOrNumber = "default_chapter_display_by_name_or_number"
fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId"
fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId"

View File

@ -5,15 +5,19 @@ import android.content.SharedPreferences
import android.net.Uri
import android.os.Environment
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.f2prateek.rx.preferences.Preference
import com.f2prateek.rx.preferences.RxSharedPreferences
import com.tfcporciuncula.flow.FlowSharedPreferences
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
import eu.kanade.tachiyomi.ui.reader.settings.PageLayout
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import eu.kanade.tachiyomi.ui.recents.RecentMangaAdapter
import eu.kanade.tachiyomi.util.system.Themes
@ -119,8 +123,6 @@ class PreferencesHelper(val context: Context) {
fun lightTheme() = flowPrefs.getEnum(Keys.lightTheme, Themes.PURE_WHITE)
fun darkTheme() = flowPrefs.getEnum(Keys.darkTheme, Themes.DARK)
fun rotation() = flowPrefs.getInt(Keys.rotation, 1)
fun pageTransitions() = flowPrefs.getBoolean(Keys.enableTransitions, true)
fun pagerCutoutBehavior() = flowPrefs.getInt(Keys.pagerCutoutBehavior, 0)
@ -145,7 +147,9 @@ class PreferencesHelper(val context: Context) {
fun colorFilterMode() = flowPrefs.getInt(Keys.colorFilterMode, 0)
fun defaultViewer() = prefs.getInt(Keys.defaultViewer, 2)
fun defaultReadingMode() = prefs.getInt(Keys.defaultReadingMode, ReadingModeType.RIGHT_TO_LEFT.flagValue)
fun defaultOrientationType() = flowPrefs.getInt(Keys.defaultOrientationType, OrientationType.FREE.flagValue)
fun imageScaleType() = flowPrefs.getInt(Keys.imageScaleType, 1)
@ -421,4 +425,27 @@ class PreferencesHelper(val context: Context) {
fun openChapterInShortcuts() = prefs.getBoolean(Keys.openChapterInShortcuts, true)
fun incognitoMode() = flowPrefs.getBoolean(Keys.incognitoMode, false)
fun filterChapterByRead() = prefs.getInt(Keys.defaultChapterFilterByRead, Manga.SHOW_ALL)
fun filterChapterByDownloaded() = prefs.getInt(Keys.defaultChapterFilterByDownloaded, Manga.SHOW_ALL)
fun filterChapterByBookmarked() = prefs.getInt(Keys.defaultChapterFilterByBookmarked, Manga.SHOW_ALL)
fun sortChapterBySourceOrNumber() = prefs.getInt(Keys.defaultChapterSortBySourceOrNumber, Manga.CHAPTER_SORTING_SOURCE)
fun displayChapterByNameOrNumber() = prefs.getInt(Keys.defaultChapterDisplayByNameOrNumber, Manga.CHAPTER_DISPLAY_NAME)
fun sortChapterByAscendingOrDescending() = prefs.getInt(Keys.defaultChapterSortByAscendingOrDescending, Manga.CHAPTER_SORT_DESC)
fun setChapterSettingsDefault(manga: Manga) {
prefs.edit {
putInt(Keys.defaultChapterFilterByRead, manga.readFilter)
putInt(Keys.defaultChapterFilterByDownloaded, manga.downloadedFilter)
putInt(Keys.defaultChapterFilterByBookmarked, manga.bookmarkedFilter)
putInt(Keys.defaultChapterSortBySourceOrNumber, manga.sorting)
putInt(Keys.defaultChapterDisplayByNameOrNumber, manga.displayMode)
putInt(Keys.defaultChapterSortByAscendingOrDescending, if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC)
}
}
}

View File

@ -50,7 +50,6 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.manga.MangaShortcutManager
import eu.kanade.tachiyomi.util.system.executeOnIO
import eu.kanade.tachiyomi.util.system.isTablet
import eu.kanade.tachiyomi.util.system.launchIO
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -213,8 +212,8 @@ class MangaDetailsPresenter(
* @param hide set title to hidden
*/
fun hideTitle(hide: Boolean) {
manga.displayMode = if (hide) Manga.DISPLAY_NUMBER else Manga.DISPLAY_NAME
db.updateFlags(manga).executeAsBlocking()
manga.displayMode = if (hide) Manga.CHAPTER_DISPLAY_NUMBER else Manga.CHAPTER_DISPLAY_NAME
db.updateChapterFlags(manga).executeAsBlocking()
controller.refreshAdapter()
}
@ -236,11 +235,11 @@ class MangaDetailsPresenter(
val chapters = chapterFilter.filterChapters(chapterList, manga)
val sortFunction: (Chapter, Chapter) -> Int = when (manga.sorting) {
Manga.SORTING_SOURCE -> when (sortDescending()) {
Manga.CHAPTER_SORTING_SOURCE -> when (sortDescending()) {
true -> { c1, c2 -> c1.source_order.compareTo(c2.source_order) }
false -> { c1, c2 -> c2.source_order.compareTo(c1.source_order) }
}
Manga.SORTING_NUMBER -> when (sortDescending()) {
Manga.CHAPTER_SORTING_NUMBER -> when (sortDescending()) {
true -> { c1, c2 -> c2.chapter_number.compareTo(c1.chapter_number) }
false -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) }
}
@ -509,7 +508,7 @@ class MangaDetailsPresenter(
* Sets the sorting order and requests an UI update.
*/
fun setSortOrder(descend: Boolean) {
manga.setChapterOrder(if (descend) Manga.SORT_DESC else Manga.SORT_ASC)
manga.setChapterOrder(if (descend) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC)
asyncUpdateMangaAndChapters()
}
@ -525,7 +524,7 @@ class MangaDetailsPresenter(
* Sets the sorting method and requests an UI update.
*/
fun setSortMethod(bySource: Boolean) {
manga.sorting = if (bySource) Manga.SORTING_SOURCE else Manga.SORTING_NUMBER
manga.sorting = if (bySource) Manga.CHAPTER_SORTING_SOURCE else Manga.CHAPTER_SORTING_NUMBER
asyncUpdateMangaAndChapters()
}
@ -534,18 +533,18 @@ class MangaDetailsPresenter(
*/
fun setFilters(read: Boolean, unread: Boolean, downloaded: Boolean, bookmarked: Boolean) {
manga.readFilter = when {
read -> Manga.SHOW_READ
unread -> Manga.SHOW_UNREAD
read -> Manga.CHAPTER_SHOW_READ
unread -> Manga.CHAPTER_SHOW_UNREAD
else -> Manga.SHOW_ALL
}
manga.downloadedFilter = if (downloaded) Manga.SHOW_DOWNLOADED else Manga.SHOW_ALL
manga.bookmarkedFilter = if (bookmarked) Manga.SHOW_BOOKMARKED else Manga.SHOW_ALL
manga.downloadedFilter = if (downloaded) Manga.CHAPTER_SHOW_DOWNLOADED else Manga.SHOW_ALL
manga.bookmarkedFilter = if (bookmarked) Manga.CHAPTER_SHOW_BOOKMARKED else Manga.SHOW_ALL
asyncUpdateMangaAndChapters()
}
private fun asyncUpdateMangaAndChapters(justChapters: Boolean = false) {
scope.launch {
if (!justChapters) db.updateFlags(manga).executeOnIO()
if (!justChapters) db.updateChapterFlags(manga).executeOnIO()
getChapters()
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
}
@ -553,10 +552,10 @@ class MangaDetailsPresenter(
fun currentFilters(): String {
val filtersId = mutableListOf<Int?>()
filtersId.add(if (manga.readFilter == Manga.SHOW_READ) R.string.read else null)
filtersId.add(if (manga.readFilter == Manga.SHOW_UNREAD) R.string.unread else null)
filtersId.add(if (manga.downloadedFilter == Manga.SHOW_DOWNLOADED) R.string.downloaded else null)
filtersId.add(if (manga.bookmarkedFilter == Manga.SHOW_BOOKMARKED) R.string.bookmarked else null)
filtersId.add(if (manga.readFilter == Manga.CHAPTER_SHOW_READ) R.string.read else null)
filtersId.add(if (manga.readFilter == Manga.CHAPTER_SHOW_UNREAD) R.string.unread else null)
filtersId.add(if (manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED) R.string.downloaded else null)
filtersId.add(if (manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED) R.string.bookmarked else null)
return filtersId.filterNotNull().joinToString(", ") { preferences.context.getString(it) }
}
@ -656,8 +655,8 @@ class MangaDetailsPresenter(
manga.genre = if (tags.isNullOrEmpty()) null else tagsString?.trim()
if (seriesType != null) {
manga.genre = setSeriesType(seriesType, manga.genre).joinToString(", ") { it.capitalize() }
manga.viewer = -1
db.updateMangaViewer(manga).executeAsBlocking()
manga.viewer_flags = -1
db.updateViewerFlags(manga).executeAsBlocking()
}
manga.status = status ?: SManga.UNKNOWN
LocalSource(downloadManager.context).updateMangaInfo(manga)
@ -670,8 +669,8 @@ class MangaDetailsPresenter(
}
if (seriesType != null) {
genre = setSeriesType(seriesType, genre?.joinToString(", "))
manga.viewer = -1
db.updateMangaViewer(manga).executeAsBlocking()
manga.viewer_flags = -1
db.updateViewerFlags(manga).executeAsBlocking()
}
val manga = CustomMangaManager.MangaJson(
manga.id!!,

View File

@ -40,10 +40,10 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att
}
fun setCheckboxes(manga: Manga) {
binding.showRead.isChecked = manga.readFilter == Manga.SHOW_READ
binding.showUnread.isChecked = manga.readFilter == Manga.SHOW_UNREAD
binding.showDownload.isChecked = manga.downloadedFilter == Manga.SHOW_DOWNLOADED
binding.showBookmark.isChecked = manga.bookmarkedFilter == Manga.SHOW_BOOKMARKED
binding.showRead.isChecked = manga.readFilter == Manga.CHAPTER_SHOW_READ
binding.showUnread.isChecked = manga.readFilter == Manga.CHAPTER_SHOW_UNREAD
binding.showDownload.isChecked = manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED
binding.showBookmark.isChecked = manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED
binding.showAll.isChecked = !(
binding.showRead.isChecked || binding.showUnread.isChecked ||

View File

@ -34,7 +34,7 @@ class ChapterHolder(
val chapter = item.chapter
val isLocked = item.isLocked
binding.chapterTitle.text = when (manga.displayMode) {
Manga.DISPLAY_NUMBER -> {
Manga.CHAPTER_DISPLAY_NUMBER -> {
val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble())
itemView.context.getString(R.string.chapter_, number)
}

View File

@ -88,9 +88,9 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) :
}
)
binding.hideTitles.isChecked = presenter.manga.displayMode != Manga.DISPLAY_NAME
binding.hideTitles.isChecked = presenter.manga.displayMode != Manga.CHAPTER_DISPLAY_NAME
binding.sortMethodGroup.check(
if (presenter.manga.sorting == Manga.SORTING_SOURCE) R.id.sort_by_source else {
if (presenter.manga.sorting == Manga.CHAPTER_SORTING_SOURCE) R.id.sort_by_source else {
R.id.sort_by_number
}
)

View File

@ -19,6 +19,7 @@ import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.util.Date
class MigrationPresenter(
private val sourceManager: SourceManager = Injekt.get(),
@ -143,6 +144,19 @@ class MigrationPresenter(
manga.favorite = true
db.updateMangaFavorite(manga).executeAsBlocking()
manga.chapter_flags = prevManga.chapter_flags
db.updateChapterFlags(manga).executeAsBlocking()
manga.viewer_flags = prevManga.viewer_flags
db.updateViewerFlags(manga).executeAsBlocking()
// Update date added
if (replace) {
manga.date_added = prevManga.date_added
prevManga.date_added = 0
} else {
manga.date_added = Date().time
}
// SearchPresenter#networkToLocalManga may have updated the manga title, so ensure db gets updated title
db.updateMangaTitle(manga).executeAsBlocking()
}

View File

@ -186,12 +186,6 @@ class ReaderActivity :
private var lastCropRes = 0
companion object {
@Suppress("unused")
const val LEFT_TO_RIGHT = 1
const val RIGHT_TO_LEFT = 2
const val VERTICAL = 3
const val WEBTOON = 4
const val VERTICAL_PLUS = 5
const val SHIFT_DOUBLE_PAGES = "shiftingDoublePages"
const val SHIFTED_PAGE_INDEX = "shiftedPageIndex"
@ -366,7 +360,7 @@ class ReaderActivity :
)
}
private fun updateRotationShortcut(preference: Int) {
private fun updateOrientationShortcut(preference: Int) {
val orientation = OrientationType.fromPreference(preference)
binding.chaptersSheet.rotationSheetButton.setImageResource(orientation.iconRes)
}
@ -582,13 +576,15 @@ class ReaderActivity :
setOnClickListener {
popupMenu(
items = OrientationType.values().map { it.prefValue to it.stringRes },
selectedItemId = preferences.rotation().get(),
items = OrientationType.values().map { it.flagValue to it.stringRes },
selectedItemId = presenter.manga?.orientationType
?: preferences.defaultOrientationType().get(),
) {
val newOrientation = OrientationType.fromPreference(itemId)
preferences.rotation().set(newOrientation.prefValue)
setOrientation(newOrientation.flag)
presenter.setMangaOrientationType(newOrientation.flagValue)
updateOrientationShortcut(newOrientation.flagValue)
}
}
}
@ -608,10 +604,10 @@ class ReaderActivity :
readingMode.setOnClickListener { readingMode ->
readingMode.popupMenu(
items = ReadingModeType.values().map { it.prefValue to it.stringRes },
selectedItemId = presenter.manga?.viewer,
items = ReadingModeType.values().map { it.flagValue to it.stringRes },
selectedItemId = presenter.manga?.readingModeType,
) {
presenter.setMangaViewer(itemId)
presenter.setMangaReadingMode(itemId)
}
}
}
@ -622,7 +618,6 @@ class ReaderActivity :
.onEach { updateCropBordersShortcut() }
.launchIn(scope)
}
preferences.rotation().asImmediateFlowIn(scope) { updateRotationShortcut(it) }
binding.chaptersSheet.shiftPageButton.setOnClickListener {
shiftDoublePages()
@ -829,25 +824,25 @@ class ReaderActivity :
*/
fun setManga(manga: Manga) {
val prevViewer = viewer
val noDefault = manga.viewer == -1
val mangaViewer = presenter.getMangaViewer()
val noDefault = manga.viewer_flags == -1
val mangaViewer = presenter.getMangaReadingMode()
val newViewer = when (mangaViewer) {
LEFT_TO_RIGHT -> L2RPagerViewer(this)
VERTICAL -> VerticalPagerViewer(this)
WEBTOON -> WebtoonViewer(this)
VERTICAL_PLUS -> WebtoonViewer(this, hasMargins = true)
ReadingModeType.LEFT_TO_RIGHT.flagValue -> L2RPagerViewer(this)
ReadingModeType.VERTICAL.flagValue -> VerticalPagerViewer(this)
ReadingModeType.WEBTOON.flagValue -> WebtoonViewer(this)
ReadingModeType.CONTINUOUS_VERTICAL.flagValue -> WebtoonViewer(this, hasMargins = true)
else -> R2LPagerViewer(this)
}
if (noDefault && presenter.manga?.viewer!! > 0) {
if (noDefault && presenter.manga?.readingModeType!! > 0) {
snackbar = binding.readerLayout.snack(
getString(
R.string.reading_,
getString(
when (mangaViewer) {
RIGHT_TO_LEFT -> R.string.right_to_left_viewer
VERTICAL -> R.string.vertical_viewer
WEBTOON -> R.string.webtoon_style
ReadingModeType.RIGHT_TO_LEFT.flagValue -> R.string.right_to_left_viewer
ReadingModeType.VERTICAL.flagValue -> R.string.vertical_viewer
ReadingModeType.WEBTOON.flagValue -> R.string.webtoon_style
else -> R.string.left_to_right_viewer
}
).toLowerCase(Locale.getDefault())
@ -855,11 +850,13 @@ class ReaderActivity :
4000
) {
if (presenter.manga?.isLongStrip() != true) setAction(R.string.use_default) {
presenter.setMangaViewer(0)
presenter.setMangaReadingMode(0)
}
}
}
setOrientation(presenter.getMangaOrientationType())
// Destroy previous viewer if there was one
if (prevViewer != null) {
prevViewer.destroy()
@ -903,7 +900,7 @@ class ReaderActivity :
invalidateOptionsMenu()
updateCropBordersShortcut()
updateBottomShortcuts()
val viewerMode = ReadingModeType.fromPreference(presenter?.manga?.viewer ?: 0)
val viewerMode = ReadingModeType.fromPreference(presenter?.manga?.readingModeType ?: 0)
binding.chaptersSheet.readingMode.setImageResource(viewerMode.iconRes)
}
@ -1371,7 +1368,7 @@ class ReaderActivity :
/**
* Forces the user preferred [orientation] on the activity.
*/
private fun setOrientation(orientation: Int) {
fun setOrientation(orientation: Int) {
val newOrientation = OrientationType.fromPreference(orientation)
if (newOrientation.flag != requestedOrientation) {
requestedOrientation = newOrientation.flag
@ -1389,12 +1386,11 @@ class ReaderActivity :
* Initializes the reader subscriptions.
*/
init {
setOrientation(preferences.rotation().get())
preferences.rotation().asFlow()
preferences.defaultOrientationType().asFlow()
.drop(1)
.onEach {
delay(250)
setOrientation(it)
setOrientation(presenter.getMangaOrientationType())
}
.launchIn(scope)

View File

@ -30,6 +30,8 @@ import eu.kanade.tachiyomi.ui.reader.loader.ChapterLoader
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.storage.DiskUtil
@ -117,8 +119,8 @@ class ReaderPresenter(
chapterFilter.filterChaptersForReader(dbChapters, manga, selectedChapter)
when (manga.sorting) {
Manga.SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader)
Manga.SORTING_NUMBER -> ChapterLoadByNumber().get(chaptersForReader, selectedChapter)
Manga.CHAPTER_SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader)
Manga.CHAPTER_SORTING_NUMBER -> ChapterLoadByNumber().get(chaptersForReader, selectedChapter)
else -> error("Unknown sorting method")
}.map(::ReaderChapter)
}
@ -215,7 +217,7 @@ class ReaderPresenter(
chapterFilter.filterChaptersForReader(dbChapters, manga, getCurrentChapter()?.chapter)
.sortedBy {
when (manga.sorting) {
Manga.SORTING_NUMBER -> it.chapter_number
Manga.CHAPTER_SORTING_NUMBER -> it.chapter_number
else -> it.source_order.toFloat()
}
}.map {
@ -235,21 +237,6 @@ class ReaderPresenter(
return chapterItems
}
/**
* Removes all filters and requests an UI update.
*/
fun setFilters(read: Boolean, unread: Boolean, downloaded: Boolean, bookmarked: Boolean) {
val manga = manga ?: return
manga.readFilter = when {
read -> Manga.SHOW_READ
unread -> Manga.SHOW_UNREAD
else -> Manga.SHOW_ALL
}
manga.downloadedFilter = if (downloaded) Manga.SHOW_DOWNLOADED else Manga.SHOW_ALL
manga.bookmarkedFilter = if (bookmarked) Manga.SHOW_BOOKMARKED else Manga.SHOW_ALL
db.updateFlags(manga).executeAsBlocking()
}
/**
* Initializes this presenter with the given [manga] and [initialChapterId]. This method will
* set the chapter loader, view subscriptions and trigger an initial load.
@ -594,29 +581,32 @@ class ReaderPresenter(
/**
* Returns the viewer position used by this manga or the default one.
*/
fun getMangaViewer(): Int {
val default = preferences.defaultViewer()
fun getMangaReadingMode(): Int {
val default = preferences.defaultReadingMode()
val manga = manga ?: return default
val readerType = manga.defaultReaderType()
if (manga.viewer == -1 ||
if (manga.viewer_flags == -1 ||
// Force webtoon mode
(manga.isLongStrip() && readerType != manga.viewer)
(manga.isLongStrip() && readerType != manga.readingModeType)
) {
val cantSwitchToLTR =
(readerType == ReaderActivity.LEFT_TO_RIGHT && default != ReaderActivity.RIGHT_TO_LEFT)
manga.viewer = if (cantSwitchToLTR) 0 else readerType
db.updateMangaViewer(manga).asRxObservable().subscribe()
(
readerType == ReadingModeType.LEFT_TO_RIGHT.flagValue &&
default != ReadingModeType.RIGHT_TO_LEFT.flagValue
)
manga.readingModeType = if (cantSwitchToLTR) 0 else readerType
db.updateViewerFlags(manga).asRxObservable().subscribe()
}
return if (manga.viewer == 0) default else manga.viewer
return if (manga.readingModeType == 0) default else manga.readingModeType
}
/**
* Updates the viewer position for the open manga.
*/
fun setMangaViewer(viewer: Int) {
fun setMangaReadingMode(readingModeType: Int) {
val manga = manga ?: return
manga.viewer = viewer
db.updateMangaViewer(manga).executeAsBlocking()
manga.readingModeType = readingModeType
db.updateViewerFlags(manga).executeAsBlocking()
Observable.timer(250, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
.subscribeFirst({ view, _ ->
@ -633,6 +623,36 @@ class ReaderPresenter(
})
}
/**
* Returns the orientation type used by this manga or the default one.
*/
fun getMangaOrientationType(): Int {
val default = preferences.defaultOrientationType().get()
return when (manga?.orientationType) {
OrientationType.DEFAULT.flagValue -> default
else -> manga?.orientationType ?: default
}
}
/**
* Updates the orientation type for the open manga.
*/
fun setMangaOrientationType(rotationType: Int) {
val manga = manga ?: return
manga.orientationType = rotationType
db.updateViewerFlags(manga).executeAsBlocking()
Timber.i("Manga orientation is ${manga.orientationType}")
Observable.timer(250, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
.subscribeFirst({ view, _ ->
val currChapters = viewerChaptersRelay.value
if (currChapters != null) {
view.setOrientation(getMangaOrientationType())
}
})
}
/**
* Saves the image of this [page] in the given [directory] and returns the file location.
*/

View File

@ -41,7 +41,7 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B
val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter)
binding.chapterTitle.text = when (manga.displayMode) {
Manga.DISPLAY_NUMBER -> {
Manga.CHAPTER_DISPLAY_NUMBER -> {
val number = item.decimalFormat.format(item.chapter_number.toDouble())
itemView.context.getString(R.string.chapter_, number)
}

View File

@ -5,16 +5,21 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
enum class OrientationType(val prefValue: Int, val flag: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) {
FREE(1, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.free, R.drawable.ic_screen_rotation_24dp),
PORTRAIT(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, R.string.portrait, R.drawable.ic_stay_current_portrait_24dp),
LANDSCAPE(3, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, R.string.landscape, R.drawable.ic_stay_current_landscape_24dp),
LOCKED_PORTRAIT(4, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, R.string.locked_portrait, R.drawable.ic_screen_lock_portrait_24dp),
LOCKED_LANDSCAPE(5, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, R.string.locked_landscape, R.drawable.ic_screen_lock_landscape_24dp),
enum class OrientationType(val prefValue: Int, val flag: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) {
DEFAULT(0, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.default_value, R.drawable.ic_screen_rotation_24dp, 0x00000000),
FREE(1, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.free, R.drawable.ic_screen_rotation_24dp, 0x00000008),
PORTRAIT(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, R.string.portrait, R.drawable.ic_stay_current_portrait_24dp, 0x00000010),
LANDSCAPE(3, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, R.string.landscape, R.drawable.ic_stay_current_landscape_24dp, 0x00000018),
LOCKED_PORTRAIT(4, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, R.string.locked_portrait, R.drawable.ic_screen_lock_portrait_24dp, 0x00000020),
LOCKED_LANDSCAPE(5, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, R.string.locked_landscape, R.drawable.ic_screen_lock_landscape_24dp, 0x00000028),
;
companion object {
const val MASK = 0x00000038
fun fromPreference(preference: Int): OrientationType =
values().find { it.prefValue == preference } ?: FREE
values().find { it.flagValue == preference } ?: FREE
fun fromSpinner(position: Int?) = values().find { value -> value.prefValue == position } ?: DEFAULT
}
}

View File

@ -15,17 +15,31 @@ class ReaderGeneralView @JvmOverloads constructor(context: Context, attrs: Attri
override fun inflateBinding() = ReaderGeneralLayoutBinding.bind(this)
override fun initGeneralPreferences() {
binding.viewerSeries.onItemSelectedListener = { position ->
activity.presenter.setMangaViewer(position)
val readingModeType = ReadingModeType.fromSpinner(position)
(context as ReaderActivity).presenter.setMangaReadingMode(readingModeType.flagValue)
val mangaViewer = activity.presenter.getMangaViewer()
if (mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS) {
val mangaViewer = activity.presenter.getMangaReadingMode()
if (mangaViewer == ReadingModeType.WEBTOON.flagValue || mangaViewer == ReadingModeType.CONTINUOUS_VERTICAL.flagValue) {
initWebtoonPreferences()
} else {
initPagerPreferences()
}
}
binding.viewerSeries.setSelection((context as? ReaderActivity)?.presenter?.manga?.viewer ?: 0)
binding.rotationMode.bindToPreference(preferences.rotation(), 1)
binding.viewerSeries.setSelection(
(context as? ReaderActivity)?.presenter?.manga?.readingModeType?.let {
ReadingModeType.fromPreference(it).prefValue
} ?: 0
)
binding.rotationMode.onItemSelectedListener = { position ->
val rotationType = OrientationType.fromSpinner(position)
(context as ReaderActivity).presenter.setMangaOrientationType(rotationType.flagValue)
}
binding.rotationMode.setSelection(
(context as ReaderActivity).presenter.manga?.orientationType?.let {
OrientationType.fromPreference(it).prefValue
} ?: 0
)
binding.backgroundColor.bindToPreference(preferences.readerTheme(), 0)
binding.showPageNumber.bindToPreference(preferences.showPageNumber())
binding.fullscreen.bindToPreference(preferences.fullscreen())

View File

@ -19,9 +19,8 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
override fun initGeneralPreferences() {
with(binding) {
scaleType.bindToPreference(preferences.imageScaleType(), 1) {
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
val isWebtoonView =
mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaReadingMode() ?: 0
val isWebtoonView = ReadingModeType.isWebtoonType(mangaViewer)
updatePagedGroup(!isWebtoonView)
}
zoomStart.bindToPreference(preferences.zoomStart(), 1)
@ -31,19 +30,17 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
pagerInvert.bindToPreference(preferences.pagerNavInverted())
extendPastCutout.bindToPreference(preferences.pagerCutoutBehavior())
pageLayout.bindToPreference(preferences.pageLayout()) {
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
val isWebtoonView =
mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaReadingMode() ?: 0
val isWebtoonView = ReadingModeType.isWebtoonType(mangaViewer)
updatePagedGroup(!isWebtoonView)
}
invertDoublePages.bindToPreference(preferences.invertDoublePages())
pageLayout.title = pageLayout.title.toString().addBetaTag(context)
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
val isWebtoonView =
mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
val hasMargins = mangaViewer == ReaderActivity.VERTICAL_PLUS
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaReadingMode() ?: 0
val isWebtoonView = ReadingModeType.isWebtoonType(mangaViewer)
val hasMargins = mangaViewer == ReadingModeType.CONTINUOUS_VERTICAL.flagValue
cropBordersWebtoon.bindToPreference(if (hasMargins) preferences.cropBorders() else preferences.cropBordersWebtoon())
webtoonSidePadding.bindToIntPreference(
preferences.webtoonSidePadding(),
@ -58,9 +55,9 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
}
fun updatePrefs() {
val mangaViewer = activity.presenter.getMangaViewer()
val isWebtoonView = mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
val hasMargins = mangaViewer == ReaderActivity.VERTICAL_PLUS
val mangaViewer = activity.presenter.getMangaReadingMode()
val isWebtoonView = ReadingModeType.isWebtoonType(mangaViewer)
val hasMargins = mangaViewer == ReadingModeType.CONTINUOUS_VERTICAL.flagValue
binding.cropBordersWebtoon.bindToPreference(if (hasMargins) preferences.cropBorders() else preferences.cropBordersWebtoon())
updatePagedGroup(!isWebtoonView)
}

View File

@ -5,17 +5,18 @@ import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.lang.next
enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) {
DEFAULT(0, R.string.default_value, R.drawable.ic_reader_default_24dp),
LEFT_TO_RIGHT(1, R.string.left_to_right_viewer, R.drawable.ic_reader_ltr_24dp),
RIGHT_TO_LEFT(2, R.string.right_to_left_viewer, R.drawable.ic_reader_rtl_24dp),
VERTICAL(3, R.string.vertical_viewer, R.drawable.ic_reader_vertical_24dp),
WEBTOON(4, R.string.webtoon, R.drawable.ic_reader_webtoon_24dp),
CONTINUOUS_VERTICAL(5, R.string.continuous_vertical, R.drawable.ic_reader_continuous_vertical_24dp),
enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) {
DEFAULT(0, R.string.default_value, R.drawable.ic_reader_default_24dp, 0x00000000),
LEFT_TO_RIGHT(1, R.string.left_to_right_viewer, R.drawable.ic_reader_ltr_24dp, 0x00000001),
RIGHT_TO_LEFT(2, R.string.right_to_left_viewer, R.drawable.ic_reader_rtl_24dp, 0x00000002),
VERTICAL(3, R.string.vertical_viewer, R.drawable.ic_reader_vertical_24dp, 0x00000003),
WEBTOON(4, R.string.webtoon, R.drawable.ic_reader_webtoon_24dp, 0x00000004),
CONTINUOUS_VERTICAL(5, R.string.continuous_vertical, R.drawable.ic_reader_continuous_vertical_24dp, 0x00000005),
;
companion object {
fun fromPreference(preference: Int): ReadingModeType = values().find { it.prefValue == preference } ?: DEFAULT
fun fromPreference(preference: Int): ReadingModeType = values().find { it.flagValue == preference } ?: DEFAULT
const val MASK = 0x00000007
fun getNextReadingMode(preference: Int): ReadingModeType {
val current = fromPreference(preference)
@ -26,5 +27,12 @@ enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @D
val mode = fromPreference(preference)
return mode == LEFT_TO_RIGHT || mode == RIGHT_TO_LEFT || mode == VERTICAL
}
fun isWebtoonType(preference: Int): Boolean {
val mode = fromPreference(preference)
return mode == WEBTOON || mode == CONTINUOUS_VERTICAL
}
fun fromSpinner(position: Int?) = values().find { value -> value.prefValue == position } ?: DEFAULT
}
}

View File

@ -36,10 +36,10 @@ class TabbedReaderSettingsSheet(
null
) as ReaderFilterView
var showWebview: Boolean = {
val mangaViewer = readerActivity.presenter.getMangaViewer()
mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
}()
var showWebtoonView: Boolean = run {
val mangaViewer = readerActivity.presenter.getMangaReadingMode()
ReadingModeType.isWebtoonType(mangaViewer)
}
override var offset = 0
@ -51,7 +51,7 @@ class TabbedReaderSettingsSheet(
override fun getTabTitles(): List<Int> = listOf(
R.string.general,
if (showWebview) R.string.webtoon else R.string.paged,
if (showWebtoonView) R.string.webtoon else R.string.paged,
R.string.filter
)
@ -130,7 +130,7 @@ class TabbedReaderSettingsSheet(
}
fun updateTabs(isWebtoon: Boolean) {
showWebview = isWebtoon
showWebtoonView = isWebtoon
binding.pager.adapter?.notifyDataSetChanged()
pagedView.updatePrefs()
}

View File

@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
import eu.kanade.tachiyomi.ui.reader.settings.PageLayout
import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import eu.kanade.tachiyomi.util.lang.addBetaTag
import eu.kanade.tachiyomi.util.system.isTablet
@ -23,16 +24,12 @@ class SettingsReaderController : SettingsController() {
preferenceCategory {
titleRes = R.string.general
intListPreference(activity) {
key = Keys.defaultViewer
key = Keys.defaultReadingMode
titleRes = R.string.default_reading_mode
entriesRes = arrayOf(
R.string.left_to_right_viewer,
R.string.right_to_left_viewer,
R.string.vertical_viewer,
R.string.webtoon,
R.string.continuous_vertical
)
entryRange = 1..5
entriesRes = ReadingModeType.values().drop(1)
.map { value -> value.stringRes }.toTypedArray()
entryValues = ReadingModeType.values().drop(1)
.map { value -> value.flagValue }
defaultValue = 2
}
intListPreference(activity) {
@ -92,12 +89,13 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.display
intListPreference(activity) {
key = Keys.rotation
titleRes = R.string.rotation
val enumConstants = OrientationType.values()
key = Keys.defaultOrientationType
titleRes = R.string.default_orientation
val enumConstants = OrientationType.values().drop(1)
entriesRes = enumConstants.map { it.stringRes }.toTypedArray()
entryRange = 1..enumConstants.size
defaultValue = 1
entryValues = OrientationType.values().drop(1)
.map { value -> value.flagValue }
defaultValue = OrientationType.FREE.flagValue
}
intListPreference(activity) {
key = Keys.readerTheme

View File

@ -11,10 +11,10 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl
// filters chapters based on the manga values
fun <T : Chapter> filterChapters(chapters: List<T>, manga: Manga): List<T> {
val readEnabled = manga.readFilter == Manga.SHOW_READ
val unreadEnabled = manga.readFilter == Manga.SHOW_UNREAD
val downloadEnabled = manga.downloadedFilter == Manga.SHOW_DOWNLOADED
val bookmarkEnabled = manga.bookmarkedFilter == Manga.SHOW_BOOKMARKED
val readEnabled = manga.readFilter == Manga.CHAPTER_SHOW_READ
val unreadEnabled = manga.readFilter == Manga.CHAPTER_SHOW_UNREAD
val downloadEnabled = manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED
val bookmarkEnabled = manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED
// if none of the filters are enabled skip the filtering of them
return if (readEnabled || unreadEnabled || downloadEnabled || bookmarkEnabled) {

View File

@ -38,6 +38,14 @@
app:title="@string/reading_mode"
android:entries="@array/viewers_selector" />
<eu.kanade.tachiyomi.widget.MaterialSpinnerView
android:id="@+id/rotation_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:title="@string/orientation"
android:entries="@array/rotation_type" />
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline6"
android:textSize="15sp"
@ -47,14 +55,6 @@
android:layout_marginTop="12dp"
android:text="@string/general" />
<eu.kanade.tachiyomi.widget.MaterialSpinnerView
android:id="@+id/rotation_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:title="@string/rotation"
android:entries="@array/rotation_type" />
<eu.kanade.tachiyomi.widget.MaterialSpinnerView
android:id="@+id/background_color"
android:layout_width="match_parent"

View File

@ -79,6 +79,7 @@
</string-array>
<string-array name="rotation_type">
<item>@string/default_value</item>
<item>@string/free</item>
<item>@string/portrait</item>
<item>@string/landscape</item>

View File

@ -953,6 +953,8 @@
<string name="retry">Retry</string>
<string name="right">Right</string>
<string name="rotation">Rotation</string>
<string name="default_orientation">Default orientation</string>
<string name="orientation">Orientation</string>
<string name="save">Save</string>
<string name="search">Search</string>
<string name="search_">Search %1$s</string>

View File

@ -89,7 +89,7 @@ class BackupTest {
root.add(Backup.MANGAS, mangaEntries)
root.add(Backup.CATEGORIES, categoryEntries)
}
/*
/**
* Test that checks if no crashes when no categories in library.
*/
@ -105,6 +105,7 @@ class BackupTest {
val dbCats = db.getCategories().executeAsBlocking()
assertThat(dbCats).isEmpty()
}
*/
/**
* Test to check if single category gets restored
@ -150,7 +151,7 @@ class BackupTest {
assertThat(dbCats[3].name).isEqualTo(category4.name)
assertThat(dbCats[4].name).isEqualTo(category5.name)
}
/*
/**
* Test if restore of manga is successful
*/
@ -217,6 +218,7 @@ class BackupTest {
assertThat(dbCats[0].viewer).isEqualTo(3)
assertThat(dbCats[0].description).isEqualTo("This is a description")
}
*/
/**
* Test if chapter restore is successful