From 74381ef59e9c05129d77e82dac17ab0f0b9e3406 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 4 Jun 2021 23:26:37 -0400 Subject: [PATCH 1/6] Handle HEIF images (partly addresses #4756) --- .../kanade/tachiyomi/util/system/ImageUtil.kt | 77 +++++++------------ 1 file changed, 28 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt index 6d8210818..00771ea77 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt @@ -18,6 +18,7 @@ import androidx.core.graphics.green import androidx.core.graphics.red import tachiyomi.decoder.Format import tachiyomi.decoder.ImageDecoder +import tachiyomi.decoder.ImageType import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.InputStream @@ -41,30 +42,14 @@ object ImageUtil { fun findImageType(stream: InputStream): ImageType? { try { - val bytes = ByteArray(8) - - val length = if (stream.markSupported()) { - stream.mark(bytes.size) - stream.read(bytes, 0, bytes.size).also { stream.reset() } - } else { - stream.read(bytes, 0, bytes.size) - } - - if (length == -1) { - return null - } - - if (bytes.compareWith(charByteArrayOf(0xFF, 0xD8, 0xFF))) { - return ImageType.JPG - } - if (bytes.compareWith(charByteArrayOf(0x89, 0x50, 0x4E, 0x47))) { - return ImageType.PNG - } - if (bytes.compareWith("GIF8".toByteArray())) { - return ImageType.GIF - } - if (bytes.compareWith("RIFF".toByteArray())) { - return ImageType.WEBP + return when (getImageType(stream)?.format) { + // TODO: image-decoder library currently doesn't detect this + // Format.Avif -> ImageType.AVIF + Format.Gif -> ImageType.GIF + Format.Heif -> ImageType.HEIF + Format.Jpeg -> ImageType.JPEG + Format.Png -> ImageType.PNG + Format.Webp -> ImageType.WEBP } } catch (e: Exception) { } @@ -73,20 +58,7 @@ object ImageUtil { fun isAnimatedAndSupported(stream: InputStream): Boolean { try { - val bytes = ByteArray(32) - - val length = if (stream.markSupported()) { - stream.mark(bytes.size) - stream.read(bytes, 0, bytes.size).also { stream.reset() } - } else { - stream.read(bytes, 0, bytes.size) - } - - if (length == -1) { - return false - } - - val type = ImageDecoder.findType(bytes) ?: return false + val type = getImageType(stream) ?: return false return when (type.format) { Format.Gif -> true // Coil supports animated WebP on Android 9.0+ @@ -99,23 +71,30 @@ object ImageUtil { return false } - private fun ByteArray.compareWith(magic: ByteArray): Boolean { - return magic.indices.none { this[it] != magic[it] } - } + private fun getImageType(stream: InputStream): tachiyomi.decoder.ImageType? { + val bytes = ByteArray(32) - private fun charByteArrayOf(vararg bytes: Int): ByteArray { - return ByteArray(bytes.size).apply { - for (i in bytes.indices) { - set(i, bytes[i].toByte()) - } + val length = if (stream.markSupported()) { + stream.mark(bytes.size) + stream.read(bytes, 0, bytes.size).also { stream.reset() } + } else { + stream.read(bytes, 0, bytes.size) } + + if (length == -1) { + return null + } + + return ImageDecoder.findType(bytes) } enum class ImageType(val mime: String, val extension: String) { - JPG("image/jpeg", "jpg"), - PNG("image/png", "png"), + // AVIF("image/avif", "avif"), GIF("image/gif", "gif"), - WEBP("image/webp", "webp") + HEIF("image/heif", "heif"), + JPEG("image/jpeg", "jpg"), + PNG("image/png", "png"), + WEBP("image/webp", "webp"), } /** From fff72b61dfef494260bbfa544b21be820fbaeafc Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 4 Jun 2021 23:46:18 -0400 Subject: [PATCH 2/6] Fix image type build error --- .../main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt index 00771ea77..f65c1e68e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt @@ -43,13 +43,14 @@ object ImageUtil { fun findImageType(stream: InputStream): ImageType? { try { return when (getImageType(stream)?.format) { - // TODO: image-decoder library currently doesn't detect this - // Format.Avif -> ImageType.AVIF + // TODO: image-decoder library currently doesn't actually detect AVIF yet + Format.Avif -> ImageType.AVIF Format.Gif -> ImageType.GIF Format.Heif -> ImageType.HEIF Format.Jpeg -> ImageType.JPEG Format.Png -> ImageType.PNG Format.Webp -> ImageType.WEBP + else -> null } } catch (e: Exception) { } @@ -89,7 +90,7 @@ object ImageUtil { } enum class ImageType(val mime: String, val extension: String) { - // AVIF("image/avif", "avif"), + AVIF("image/avif", "avif"), GIF("image/gif", "gif"), HEIF("image/heif", "heif"), JPEG("image/jpeg", "jpg"), From a906e9b302f4aa4ce0d5c30b2a52d266b44eaaf5 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 5 Jun 2021 16:25:34 +0200 Subject: [PATCH 3/6] Added category-wise display setting (#5232) * Added category-wise display setting Co-authored-by: Rogavactive <30288842+Rogavactive@users.noreply.github.com> * Use flag instead of preference * Remove database call in LibraryItem * Remove unnecessary code Co-authored-by: Rogavactive <30288842+Rogavactive@users.noreply.github.com> --- .../data/database/models/Category.kt | 13 +++ .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../ui/library/LibraryCategoryView.kt | 20 +++-- .../tachiyomi/ui/library/LibraryController.kt | 4 +- .../tachiyomi/ui/library/LibraryItem.kt | 23 ++++- .../tachiyomi/ui/library/LibraryPresenter.kt | 19 +++- .../ui/library/LibrarySettingsSheet.kt | 86 ++++++++++++++++--- .../ui/setting/SettingsLibraryController.kt | 6 ++ .../main/res/layout/library_list_recycler.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 11 files changed, 153 insertions(+), 25 deletions(-) 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 43ef84c4e..14a842476 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 @@ -12,8 +12,21 @@ interface Category : Serializable { var flags: Int + private fun setFlags(flag: Int, mask: Int) { + flags = flags and mask.inv() or (flag and mask) + } + + var displayMode: Int + get() = flags and MASK + set(mode) = setFlags(mode, MASK) + companion object { + const val COMPACT_GRID = 0b00000000 + const val COMFORTABLE_GRID = 0b00000001 + const val LIST = 0b00000010 + const val MASK = 0b00000011 + fun create(name: String): Category = CategoryImpl().apply { this.name = name } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index dc6617740..fd756ad2f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -185,6 +185,8 @@ object PreferenceKeys { const val defaultCategory = "default_category" + const val categorizedDisplay = "categorized_display" + const val skipRead = "skip_read" const val skipFiltered = "skip_filtered" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index a195fadfe..9b061c2e5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -284,6 +284,8 @@ class PreferencesHelper(val context: Context) { fun defaultCategory() = prefs.getInt(Keys.defaultCategory, -1) + fun categorisedDisplaySettings() = flowPrefs.getBoolean(Keys.categorizedDisplay, false) + fun skipRead() = prefs.getBoolean(Keys.skipRead, false) fun skipFiltered() = prefs.getBoolean(Keys.skipFiltered, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 79eba7168..9851de2cd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -5,7 +5,6 @@ import android.util.AttributeSet import android.view.View import android.widget.FrameLayout import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter @@ -56,7 +55,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att /** * Recycler view of the list of manga. */ - private lateinit var recycler: RecyclerView + private lateinit var recycler: AutofitRecyclerView /** * Adapter to hold the manga in this category. @@ -73,9 +72,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att fun onCreate(controller: LibraryController, binding: LibraryCategoryBinding) { this.controller = controller - recycler = if (preferences.libraryDisplayMode().get() == DisplayMode.LIST) { - (binding.swipeRefresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply { - layoutManager = LinearLayoutManager(context) + recycler = if (preferences.libraryDisplayMode().get() == DisplayMode.LIST && + !preferences.categorisedDisplaySettings().get() + ) { + (binding.swipeRefresh.inflate(R.layout.library_list_recycler) as AutofitRecyclerView).apply { + spanCount = 1 } } else { (binding.swipeRefresh.inflate(R.layout.library_grid_recycler) as AutofitRecyclerView).apply { @@ -122,6 +123,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att fun onBind(category: Category) { this.category = category + // If displayMode should be set from category adjust manga count per row + if (preferences.categorisedDisplaySettings().get()) { + recycler.spanCount = if (category.displayMode == Category.LIST || (preferences.libraryDisplayMode().get() == DisplayMode.LIST && category.id == 0)) { + 1 + } else { + controller.mangaPerRow + } + } + adapter.mode = if (controller.selectedMangas.isNotEmpty()) { SelectableAdapter.Mode.MULTI } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index ab10a666a..409c738f3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -262,7 +262,9 @@ class LibraryController( } fun showSettingsSheet() { - settingsSheet?.show() + adapter?.categories?.get(binding.libraryPager.currentItem)?.let { category -> + settingsSheet?.show(category) + } } fun onNextLibraryUpdate(categories: List, mangaMap: Map>) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index daa683400..941a2c646 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -21,17 +21,34 @@ import eu.kanade.tachiyomi.widget.AutofitRecyclerView import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Preference) : +class LibraryItem( + val manga: LibraryManga, + private val shouldSetFromCategory: Preference, + private val defaultLibraryDisplayMode: Preference +) : AbstractFlexibleItem>(), IFilterable { private val sourceManager: SourceManager = Injekt.get() + var displayMode: Int = -1 var downloadCount = -1 var unreadCount = -1 var isLocal = false + private fun getDisplayMode(): DisplayMode { + return if (shouldSetFromCategory.get() && manga.category != 0) { + if (displayMode != -1) { + DisplayMode.values()[displayMode] + } else { + DisplayMode.COMPACT_GRID + } + } else { + defaultLibraryDisplayMode.get() + } + } + override fun getLayoutRes(): Int { - return when (libraryDisplayMode.get()) { + return when (getDisplayMode()) { DisplayMode.COMPACT_GRID -> R.layout.source_compact_grid_item DisplayMode.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item DisplayMode.LIST -> R.layout.source_list_item @@ -39,7 +56,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe } override fun createViewHolder(view: View, adapter: FlexibleAdapter>): LibraryHolder<*> { - return when (libraryDisplayMode.get()) { + return when (getDisplayMode()) { DisplayMode.COMPACT_GRID -> { val binding = SourceCompactGridItemBinding.bind(view) val parent = adapter.recyclerView as AutofitRecyclerView 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 a528ffba9..ed8dc3d6c 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 @@ -312,6 +312,13 @@ class LibraryPresenter( dbCategories } + libraryManga.forEach { (categoryId, libraryManga) -> + val category = categories.first { category -> category.id == categoryId } + libraryManga.forEach { libraryItem -> + libraryItem.displayMode = category.displayMode + } + } + this.categories = categories Library(categories, libraryManga) } @@ -333,10 +340,18 @@ class LibraryPresenter( * value. */ private fun getLibraryMangasObservable(): Observable { - val libraryDisplayMode = preferences.libraryDisplayMode() + val defaultLibraryDisplayMode = preferences.libraryDisplayMode() + val shouldSetFromCategory = preferences.categorisedDisplaySettings() return db.getLibraryMangas().asRxObservable() .map { list -> - list.map { LibraryItem(it, libraryDisplayMode) }.groupBy { it.manga.category } + list.map { libraryManga -> + // Display mode based on user preference: take it from global library setting or category + LibraryItem( + libraryManga, + shouldSetFromCategory, + defaultLibraryDisplayMode + ) + }.groupBy { it.manga.category } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 7f268532e..9cc1c4eb0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -5,6 +5,8 @@ import android.util.AttributeSet import android.view.View import com.bluelinelabs.conductor.Router import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.database.DatabaseHelper +import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager @@ -25,6 +27,7 @@ class LibrarySettingsSheet( val filters: Filter private val sort: Sort private val display: Display + private val db: DatabaseHelper by injectLazy() init { filters = Filter(router.activity!!) @@ -37,6 +40,16 @@ class LibrarySettingsSheet( display.onGroupClicked = onGroupClickListener } + /** + * adjusts selected button to match real state. + * @param currentCategory ID of currently shown category + */ + fun show(currentCategory: Category) { + display.currentCategory = currentCategory + display.adjustDisplaySelection() + super.show() + } + override fun getTabViews(): List = listOf( filters, sort, @@ -232,8 +245,31 @@ class LibrarySettingsSheet( inner class Display @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : Settings(context, attrs) { + private val displayGroup: DisplayGroup + private val badgeGroup: BadgeGroup + private val tabsGroup: TabsGroup + init { - setGroups(listOf(DisplayGroup(), BadgeGroup(), TabsGroup())) + displayGroup = DisplayGroup() + badgeGroup = BadgeGroup() + tabsGroup = TabsGroup() + setGroups(listOf(displayGroup, badgeGroup, tabsGroup)) + } + + // Refreshes Display Setting selections + fun adjustDisplaySelection() { + val mode = getDisplayModePreference() + displayGroup.setGroupSelections(mode) + displayGroup.items.forEach { adapter.notifyItemChanged(it) } + } + + // Gets user preference of currently selected display mode at current category + private fun getDisplayModePreference(): DisplayMode { + return if (preferences.categorisedDisplaySettings().get() && currentCategory != null && currentCategory?.id != 0) { + DisplayMode.values()[currentCategory?.displayMode ?: 0] + } else { + preferences.libraryDisplayMode().get() + } } inner class DisplayGroup : Group { @@ -247,10 +283,8 @@ class LibrarySettingsSheet( override val footer = null override fun initModels() { - val mode = preferences.libraryDisplayMode().get() - compactGrid.checked = mode == DisplayMode.COMPACT_GRID - comfortableGrid.checked = mode == DisplayMode.COMFORTABLE_GRID - list.checked = mode == DisplayMode.LIST + val mode = getDisplayModePreference() + setGroupSelections(mode) } override fun onItemClicked(item: Item) { @@ -260,17 +294,41 @@ class LibrarySettingsSheet( item.group.items.forEach { (it as Item.Radio).checked = false } item.checked = true - preferences.libraryDisplayMode().set( - when (item) { - compactGrid -> DisplayMode.COMPACT_GRID - comfortableGrid -> DisplayMode.COMFORTABLE_GRID - list -> DisplayMode.LIST - else -> throw NotImplementedError("Unknown display mode") - } - ) + setDisplayModePreference(item) item.group.items.forEach { adapter.notifyItemChanged(it) } } + + // Sets display group selections based on given mode + fun setGroupSelections(mode: DisplayMode) { + compactGrid.checked = mode == DisplayMode.COMPACT_GRID + comfortableGrid.checked = mode == DisplayMode.COMFORTABLE_GRID + list.checked = mode == DisplayMode.LIST + } + + private fun setDisplayModePreference(item: Item) { + if (preferences.categorisedDisplaySettings().get() && currentCategory != null && currentCategory?.id != 0) { + val flag = when (item) { + compactGrid -> Category.COMPACT_GRID + comfortableGrid -> Category.COMFORTABLE_GRID + list -> Category.LIST + else -> throw NotImplementedError("Unknown display mode") + } + + currentCategory?.displayMode = flag + + db.insertCategory(currentCategory!!).executeAsBlocking() + } else { + preferences.libraryDisplayMode().set( + when (item) { + compactGrid -> DisplayMode.COMPACT_GRID + comfortableGrid -> DisplayMode.COMFORTABLE_GRID + list -> DisplayMode.LIST + else -> throw NotImplementedError("Unknown display mode") + } + ) + } + } } inner class BadgeGroup : Group { @@ -336,6 +394,8 @@ class LibrarySettingsSheet( */ var onGroupClicked: (Group) -> Unit = {} + var currentCategory: Category? = null + fun setGroups(groups: List) { adapter = Adapter(groups.map { it.createItems() }.flatten()) recycler.adapter = adapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 17c433e33..3045e25e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -124,6 +124,12 @@ class SettingsLibraryController : SettingsController() { true } } + + switchPreference { + key = Keys.categorizedDisplay + titleRes = R.string.categorized_display_settings + defaultValue = false + } } preferenceCategory { diff --git a/app/src/main/res/layout/library_list_recycler.xml b/app/src/main/res/layout/library_list_recycler.xml index 38f5cfdf6..2604c02bd 100644 --- a/app/src/main/res/layout/library_list_recycler.xml +++ b/app/src/main/res/layout/library_list_recycler.xml @@ -1,5 +1,5 @@ -Default category Always ask + Per-category display settings %d category %d categories From edeee54fb2ebe09466bddd6be0abc64180955fc0 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 5 Jun 2021 09:52:06 -0400 Subject: [PATCH 4/6] Set orientation icon correctly when opening reader --- .../java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt | 3 +-- .../java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 95ca41bd6..9570cad65 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -422,8 +422,6 @@ class ReaderActivity : BaseRxActivity() presenter.setMangaOrientationType(newOrientation.flagValue) - updateOrientationShortcut(newOrientation.flagValue) - menuToggleToast?.cancel() menuToggleToast = toast(newOrientation.stringRes) } @@ -792,6 +790,7 @@ class ReaderActivity : BaseRxActivity() if (newOrientation.flag != requestedOrientation) { requestedOrientation = newOrientation.flag } + updateOrientationShortcut(presenter.getMangaOrientationType(resolveDefault = false)) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index e10d8924e..77d7fbecb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -527,10 +527,11 @@ class ReaderPresenter( /** * Returns the orientation type used by this manga or the default one. */ - fun getMangaOrientationType(): Int { + fun getMangaOrientationType(resolveDefault: Boolean = true): Int { val default = preferences.defaultOrientationType() - return when (manga?.orientationType) { - OrientationType.DEFAULT.flagValue -> default + val orientation = OrientationType.fromPreference(manga?.orientationType) + return when { + resolveDefault && orientation == OrientationType.DEFAULT -> default else -> manga?.orientationType ?: default } } From 04ebca8413403693870e58540eda02b1391f3b61 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 5 Jun 2021 10:18:13 -0400 Subject: [PATCH 5/6] Use smallest width instead of width for alt layouts --- .../java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt | 4 ++-- .../res/{layout-w720dp => layout-sw720dp}/main_activity.xml | 0 .../{layout-w720dp => layout-sw720dp}/manga_controller.xml | 0 .../{layout-w720dp => layout-sw720dp}/manga_info_header.xml | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename app/src/main/res/{layout-w720dp => layout-sw720dp}/main_activity.xml (100%) rename app/src/main/res/{layout-w720dp => layout-sw720dp}/manga_controller.xml (100%) rename app/src/main/res/{layout-w720dp => layout-sw720dp}/manga_info_header.xml (100%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 39878510f..5e87c2c61 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -271,8 +271,8 @@ fun Context.createFileInCacheDir(name: String): File { } /** - * We consider anything with a width of >= 720dp as a tablet, i.e. with layouts in layout-w720dp. + * We consider anything with a width of >= 720dp as a tablet, i.e. with layouts in layout-sw720dp. */ fun Context.isTablet(): Boolean { - return (resources.displayMetrics.widthPixels / resources.displayMetrics.density) >= 720 + return resources.configuration.smallestScreenWidthDp >= 720 } diff --git a/app/src/main/res/layout-w720dp/main_activity.xml b/app/src/main/res/layout-sw720dp/main_activity.xml similarity index 100% rename from app/src/main/res/layout-w720dp/main_activity.xml rename to app/src/main/res/layout-sw720dp/main_activity.xml diff --git a/app/src/main/res/layout-w720dp/manga_controller.xml b/app/src/main/res/layout-sw720dp/manga_controller.xml similarity index 100% rename from app/src/main/res/layout-w720dp/manga_controller.xml rename to app/src/main/res/layout-sw720dp/manga_controller.xml diff --git a/app/src/main/res/layout-w720dp/manga_info_header.xml b/app/src/main/res/layout-sw720dp/manga_info_header.xml similarity index 100% rename from app/src/main/res/layout-w720dp/manga_info_header.xml rename to app/src/main/res/layout-sw720dp/manga_info_header.xml From fdf178d4df5ca4819c972ca2730e86ef173beeca Mon Sep 17 00:00:00 2001 From: Hunter Nickel Date: Sat, 5 Jun 2021 08:37:21 -0600 Subject: [PATCH 6/6] Add behavior for modifying reader buttons depending on prev/next chapters (#5305) --- .../tachiyomi/ui/reader/ReaderActivity.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 9570cad65..dd5ccca66 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -88,6 +88,9 @@ class ReaderActivity : BaseRxActivity() addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } } + + private const val ENABLED_BUTTON_IMAGE_ALPHA = 255 + private const val DISABLED_BUTTON_IMAGE_ALPHA = 64 } private val preferences: PreferencesHelper by injectLazy() @@ -587,13 +590,28 @@ class ReaderActivity : BaseRxActivity() /** * Called from the presenter whenever a new [viewerChapters] have been set. It delegates the - * method to the current viewer, but also set the subtitle on the toolbar. + * method to the current viewer, but also set the subtitle on the toolbar, and + * hides or disables the reader prev/next buttons if there's a prev or next chapter */ fun setChapters(viewerChapters: ViewerChapters) { binding.pleaseWait.isVisible = false viewer?.setChapters(viewerChapters) binding.toolbar.subtitle = viewerChapters.currChapter.chapter.name + val leftChapterObject = if (viewer is R2LPagerViewer) viewerChapters.nextChapter else viewerChapters.prevChapter + val rightChapterObject = if (viewer is R2LPagerViewer) viewerChapters.prevChapter else viewerChapters.nextChapter + + if (leftChapterObject == null && rightChapterObject == null) { + binding.leftChapter.isVisible = false + binding.rightChapter.isVisible = false + } else { + binding.leftChapter.isEnabled = leftChapterObject != null + binding.leftChapter.imageAlpha = if (leftChapterObject != null) ENABLED_BUTTON_IMAGE_ALPHA else DISABLED_BUTTON_IMAGE_ALPHA + + binding.rightChapter.isEnabled = rightChapterObject != null + binding.rightChapter.imageAlpha = if (rightChapterObject != null) ENABLED_BUTTON_IMAGE_ALPHA else DISABLED_BUTTON_IMAGE_ALPHA + } + // Invalidate menu to show proper chapter bookmark state invalidateOptionsMenu() }