Add chapter bookmarking feature to Updates screen (#5984)

This commit is contained in:
Hunter Nickel 2021-10-01 06:11:31 -06:00 committed by GitHub
parent 2196dac63e
commit 7ed25704d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 4 deletions

View File

@ -13,6 +13,7 @@ class UpdatesAdapter(
var readColor = context.getResourceColor(R.attr.colorOnSurface, 0.38f) var readColor = context.getResourceColor(R.attr.colorOnSurface, 0.38f)
var unreadColor = context.getResourceColor(R.attr.colorOnSurface) var unreadColor = context.getResourceColor(R.attr.colorOnSurface)
var bookmarkedColor = context.getResourceColor(R.attr.colorAccent)
val coverClickListener: OnCoverClickListener = controller val coverClickListener: OnCoverClickListener = controller

View File

@ -324,6 +324,11 @@ class UpdatesController :
presenter.startDownloadingNow(chapter) presenter.startDownloadingNow(chapter)
} }
private fun bookmarkChapters(chapters: List<UpdatesItem>, bookmarked: Boolean) {
presenter.bookmarkChapters(chapters, bookmarked)
destroyActionModeIfNeeded()
}
/** /**
* Called when ActionMode created. * Called when ActionMode created.
* @param mode the ActionMode object * @param mode the ActionMode object
@ -346,6 +351,8 @@ class UpdatesController :
val chapters = getSelectedChapters() val chapters = getSelectedChapters()
binding.actionToolbar.findItem(R.id.action_download)?.isVisible = chapters.any { !it.isDownloaded } binding.actionToolbar.findItem(R.id.action_download)?.isVisible = chapters.any { !it.isDownloaded }
binding.actionToolbar.findItem(R.id.action_delete)?.isVisible = chapters.any { it.isDownloaded } binding.actionToolbar.findItem(R.id.action_delete)?.isVisible = chapters.any { it.isDownloaded }
binding.actionToolbar.findItem(R.id.action_bookmark)?.isVisible = chapters.any { !it.bookmark }
binding.actionToolbar.findItem(R.id.action_remove_bookmark)?.isVisible = chapters.all { it.bookmark }
binding.actionToolbar.findItem(R.id.action_mark_as_read)?.isVisible = chapters.any { !it.chapter.read } binding.actionToolbar.findItem(R.id.action_mark_as_read)?.isVisible = chapters.any { !it.chapter.read }
binding.actionToolbar.findItem(R.id.action_mark_as_unread)?.isVisible = chapters.all { it.chapter.read } binding.actionToolbar.findItem(R.id.action_mark_as_unread)?.isVisible = chapters.all { it.chapter.read }
} }
@ -370,6 +377,8 @@ class UpdatesController :
R.id.action_delete -> R.id.action_delete ->
ConfirmDeleteChaptersDialog(this, getSelectedChapters()) ConfirmDeleteChaptersDialog(this, getSelectedChapters())
.showDialog(router) .showDialog(router)
R.id.action_bookmark -> bookmarkChapters(getSelectedChapters(), true)
R.id.action_remove_bookmark -> bookmarkChapters(getSelectedChapters(), false)
R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())
else -> return false else -> return false

View File

@ -39,15 +39,18 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
// Set manga title // Set manga title
binding.mangaTitle.text = item.manga.title binding.mangaTitle.text = item.manga.title
// Check if chapter is read and set correct color // Check if chapter is read and/or bookmarked and set correct color
if (item.chapter.read) { if (item.chapter.read) {
binding.chapterTitle.setTextColor(adapter.readColor) binding.chapterTitle.setTextColor(adapter.readColor)
binding.mangaTitle.setTextColor(adapter.readColor) binding.mangaTitle.setTextColor(adapter.readColor)
} else { } else {
binding.chapterTitle.setTextColor(adapter.unreadColor)
binding.mangaTitle.setTextColor(adapter.unreadColor) binding.mangaTitle.setTextColor(adapter.unreadColor)
binding.chapterTitle.setTextColor(if (item.bookmark) adapter.bookmarkedColor else adapter.unreadColor)
} }
// Set bookmark status
binding.bookmarkIcon.isVisible = item.bookmark
// Set chapter status // Set chapter status
binding.download.isVisible = item.manga.source != LocalSource.ID binding.download.isVisible = item.manga.source != LocalSource.ID
binding.download.setState(item.status, item.progress) binding.download.setState(item.status, item.progress)

View File

@ -180,6 +180,22 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
) )
} }
/**
* Mark selected chapters as bookmarked
* @param items list of selected chapters
* @param bookmarked bookmark status
*/
fun bookmarkChapters(items: List<UpdatesItem>, bookmarked: Boolean) {
val chapters = items.map { it.chapter }
chapters.forEach {
it.bookmark = bookmarked
}
Observable.fromCallable { db.updateChaptersProgress(chapters).executeAsBlocking() }
.subscribeOn(Schedulers.io())
.subscribe()
}
/** /**
* Download selected chapters * Download selected chapters
* @param items list of recent chapters seleted. * @param items list of recent chapters seleted.

View File

@ -37,17 +37,31 @@
app:layout_constraintVertical_chainStyle="packed" app:layout_constraintVertical_chainStyle="packed"
tools:text="Manga title" /> tools:text="Manga title" />
<ImageView
android:id="@+id/bookmark_icon"
android:layout_width="16dp"
android:layout_height="0dp"
android:visibility="gone"
android:layout_marginEnd="4dp"
app:layout_constraintStart_toStartOf="@id/manga_title"
app:layout_constraintTop_toBottomOf="@id/manga_title"
app:layout_constraintBottom_toBottomOf="@id/chapter_title"
app:layout_constraintEnd_toStartOf="@id/chapter_title"
app:srcCompat="@drawable/ic_bookmark_24dp"
app:tint="?attr/colorAccent"
tools:visibility="visible"
/>
<TextView <TextView
android:id="@+id/chapter_title" android:id="@+id/chapter_title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.Caption" android:textAppearance="@style/TextAppearance.Regular.Caption"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/download" app:layout_constraintEnd_toStartOf="@+id/download"
app:layout_constraintStart_toEndOf="@+id/manga_cover" app:layout_constraintStart_toEndOf="@id/bookmark_icon"
app:layout_constraintTop_toBottomOf="@+id/manga_title" app:layout_constraintTop_toBottomOf="@+id/manga_title"
tools:text="Chapter title" /> tools:text="Chapter title" />

View File

@ -16,6 +16,20 @@
app:iconTint="?attr/colorOnToolbar" app:iconTint="?attr/colorOnToolbar"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/action_bookmark"
android:icon="@drawable/ic_bookmark_border_24dp"
android:title="@string/action_bookmark"
app:iconTint="?attr/colorOnToolbar"
app:showAsAction="always" />
<item
android:id="@+id/action_remove_bookmark"
android:icon="@drawable/ic_bookmark_24dp"
android:title="@string/action_remove_bookmark"
app:iconTint="?attr/colorOnToolbar"
app:showAsAction="always" />
<item <item
android:id="@+id/action_mark_as_read" android:id="@+id/action_mark_as_read"
android:icon="@drawable/ic_done_24dp" android:icon="@drawable/ic_done_24dp"