Add continue reading button, some resources gotten from J2k

This commit is contained in:
Jobobby04
2020-08-06 17:45:18 -04:00
parent f60b29c763
commit 2f98dd2046
15 changed files with 212 additions and 4 deletions
@@ -278,4 +278,6 @@ object PreferenceKeys {
const val enhancedEHentaiView = "enhanced_e_hentai_view"
const val webtoonEnableZoomOut = "webtoon_enable_zoom_out"
const val startReadingButton = "start_reading_button"
}
@@ -382,4 +382,6 @@ class PreferencesHelper(val context: Context) {
fun enhancedEHentaiView() = flowPrefs.getBoolean(Keys.enhancedEHentaiView, true)
fun webtoonEnableZoomOut() = flowPrefs.getBoolean(Keys.webtoonEnableZoomOut, false)
fun startReadingButton() = flowPrefs.getBoolean(Keys.startReadingButton, true)
}
@@ -36,7 +36,7 @@ import uy.kohesive.injekt.injectLazy
*
* @param view the fragment containing this adapter.
*/
class LibraryCategoryAdapter(view: LibraryCategoryView) :
class LibraryCategoryAdapter(view: LibraryCategoryView, val controller: LibraryController) :
FlexibleAdapter<LibraryItem>(null, view, true) {
// EXH -->
private val db: DatabaseHelper by injectLazy()
@@ -61,6 +61,8 @@ class LibraryCategoryAdapter(view: LibraryCategoryView) :
*/
private var mangas: List<LibraryItem> = emptyList()
val libraryListener: LibraryListener = controller
// SY -->
val onItemReleaseListener: CategoryAdapter.OnItemReleaseListener = view
// SY <--
@@ -226,5 +228,9 @@ class LibraryCategoryAdapter(view: LibraryCategoryView) :
return@any false
}
}
interface LibraryListener {
fun startReading(manga: Manga, adapter: LibraryCategoryAdapter)
}
// EXH <--
}
@@ -106,7 +106,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
}
}
adapter = LibraryCategoryAdapter(this)
adapter = LibraryCategoryAdapter(this, controller)
recycler.setHasFixedSize(true)
recycler.adapter = adapter
@@ -13,9 +13,13 @@ import kotlinx.android.synthetic.main.source_comfortable_grid_item.badges
import kotlinx.android.synthetic.main.source_comfortable_grid_item.card
import kotlinx.android.synthetic.main.source_comfortable_grid_item.download_text
import kotlinx.android.synthetic.main.source_comfortable_grid_item.local_text
import kotlinx.android.synthetic.main.source_comfortable_grid_item.play_layout
import kotlinx.android.synthetic.main.source_comfortable_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_comfortable_grid_item.title
import kotlinx.android.synthetic.main.source_comfortable_grid_item.unread_text
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.android.view.clicks
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@@ -31,6 +35,16 @@ class LibraryComfortableGridHolder(
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
) : LibraryCompactGridHolder(view, adapter) {
// SY -->
init {
play_layout.clicks()
.onEach {
playButtonClicked()
}
.launchIn((adapter as LibraryCategoryAdapter).controller.scope)
}
// SY <--
/**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga.
@@ -38,6 +52,9 @@ class LibraryComfortableGridHolder(
* @param item the manga item to bind.
*/
override fun onSetValues(item: LibraryItem) {
// SY -->
manga = item.manga
// SY <--
// Update the title of the manga.
title.text = item.manga.title
@@ -57,6 +74,10 @@ class LibraryComfortableGridHolder(
// set local visibility if its local manga
local_text.isVisible = item.manga.isLocal()
// SY -->
play_layout.isVisible = (item.manga.unread > 0 && item.startReadingButton)
// SY <--
// For rounded corners
card.clipToOutline = true
@@ -6,6 +6,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.util.isLocal
@@ -13,9 +14,13 @@ import kotlinx.android.synthetic.main.source_compact_grid_item.badges
import kotlinx.android.synthetic.main.source_compact_grid_item.card
import kotlinx.android.synthetic.main.source_compact_grid_item.download_text
import kotlinx.android.synthetic.main.source_compact_grid_item.local_text
import kotlinx.android.synthetic.main.source_compact_grid_item.play_layout
import kotlinx.android.synthetic.main.source_compact_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_compact_grid_item.title
import kotlinx.android.synthetic.main.source_compact_grid_item.unread_text
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.android.view.clicks
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@@ -33,6 +38,18 @@ open class LibraryCompactGridHolder(
// SY <--
) : LibraryHolder(view, adapter) {
var manga: Manga? = null
// SY -->
init {
play_layout.clicks()
.onEach {
playButtonClicked()
}
.launchIn((adapter as LibraryCategoryAdapter).controller.scope)
}
// SY <--
/**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga.
@@ -40,6 +57,9 @@ open class LibraryCompactGridHolder(
* @param item the manga item to bind.
*/
override fun onSetValues(item: LibraryItem) {
// SY -->
manga = item.manga
// SY <--
// Update the title of the manga.
title.text = item.manga.title
@@ -59,6 +79,10 @@ open class LibraryCompactGridHolder(
// set local visibility if its local manga
local_text.isVisible = item.manga.isLocal()
// SY -->
play_layout.isVisible = (item.manga.unread > 0 && item.startReadingButton)
// SY <--
// For rounded corners
card.clipToOutline = true
@@ -71,4 +95,10 @@ open class LibraryCompactGridHolder(
.dontAnimate()
.into(thumbnail)
}
// SY -->
fun playButtonClicked() {
manga?.let { (adapter as LibraryCategoryAdapter).controller.startReading(it, (adapter as LibraryCategoryAdapter)) }
}
// SY <--
}
@@ -21,6 +21,7 @@ import com.google.android.material.tabs.TabLayout
import com.jakewharton.rxrelay.BehaviorRelay
import com.jakewharton.rxrelay.PublishRelay
import com.tfcporciuncula.flow.Preference
import eu.davidea.flexibleadapter.SelectableAdapter
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.database.models.Manga
@@ -39,6 +40,7 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.toast
import exh.EH_SOURCE_ID
@@ -69,7 +71,8 @@ class LibraryController(
TabbedController,
ActionMode.Callback,
ChangeMangaCategoriesDialog.Listener,
DeleteLibraryMangasDialog.Listener {
DeleteLibraryMangasDialog.Listener,
LibraryCategoryAdapter.LibraryListener {
/**
* Position of the active category.
@@ -792,5 +795,17 @@ class LibraryController(
}
oldSyncStatus = status
}
override fun startReading(manga: Manga, adapter: LibraryCategoryAdapter) {
if (adapter.mode == SelectableAdapter.Mode.MULTI) {
toggleSelection(manga)
return
}
val activity = activity ?: return
val chapter = presenter.getFirstUnread(manga) ?: return
val intent = ReaderActivity.newIntent(activity, manga, chapter)
destroyActionModeIfNeeded()
startActivity(intent)
}
// <-- EXH
}
@@ -44,6 +44,10 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
var downloadCount = -1
var unreadCount = -1
// SY -->
var startReadingButton = false
// SY <--
override fun getLayoutRes(): Int {
return when (libraryDisplayMode.get()) {
DisplayMode.COMPACT_GRID -> R.layout.source_compact_grid_item
@@ -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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaCategory
import eu.kanade.tachiyomi.data.download.DownloadManager
@@ -181,6 +182,7 @@ class LibraryPresenter(
private fun setBadges(map: LibraryMap) {
val showDownloadBadges = preferences.downloadBadge().get()
val showUnreadBadges = preferences.unreadBadge().get()
val startReadingButton = preferences.startReadingButton().get()
for ((_, itemList) in map) {
for (item in itemList) {
@@ -197,6 +199,10 @@ class LibraryPresenter(
// Unset unread count if not enabled
-1
}
// SY -->
item.startReadingButton = startReadingButton
// SY <--
}
}
}
@@ -443,4 +449,17 @@ class LibraryPresenter(
db.setMangaCategories(mc, mangas)
}
// SY -->
/** Returns first unread chapter of a manga */
fun getFirstUnread(manga: Manga): Chapter? {
val chapters = db.getChapters(manga).executeAsBlocking()
return if (manga.source == EH_SOURCE_ID || manga.source == EXH_SOURCE_ID) {
val chapter = chapters.sortedBy { it.source_order }.getOrNull(0)
if (chapter?.read == false) chapter else null
} else {
chapters.sortedByDescending { it.source_order }.find { !it.read }
}
}
// SY <--
}
@@ -236,7 +236,7 @@ class LibrarySettingsSheet(
Settings(context, attrs) {
init {
setGroups(listOf(DisplayGroup(), BadgeGroup(), TabsGroup()))
setGroups(listOf(DisplayGroup(), BadgeGroup(), /* SY --> */ ButtonsGroup(), /* SY <-- */ TabsGroup()))
}
inner class DisplayGroup : Group {
@@ -300,6 +300,29 @@ class LibrarySettingsSheet(
}
}
// SY -->
inner class ButtonsGroup : Group {
private val startReadingButton = Item.CheckboxGroup(R.string.action_start_reading_button, this)
override val header = Item.Header(R.string.buttons_header)
override val items = listOf(startReadingButton)
override val footer = null
override fun initModels() {
startReadingButton.checked = preferences.startReadingButton().get()
}
override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup
item.checked = !item.checked
when (item) {
startReadingButton -> preferences.startReadingButton().set((item.checked))
}
adapter.notifyItemChanged(item)
}
}
// SY <--
inner class TabsGroup : Group {
private val showTabs = Item.CheckboxGroup(R.string.action_display_show_tabs, this)