mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Add chapter bookmarking feature to Updates screen (#5984)
This commit is contained in:
		| @@ -13,6 +13,7 @@ class UpdatesAdapter( | ||||
|  | ||||
|     var readColor = context.getResourceColor(R.attr.colorOnSurface, 0.38f) | ||||
|     var unreadColor = context.getResourceColor(R.attr.colorOnSurface) | ||||
|     var bookmarkedColor = context.getResourceColor(R.attr.colorAccent) | ||||
|  | ||||
|     val coverClickListener: OnCoverClickListener = controller | ||||
|  | ||||
|   | ||||
| @@ -324,6 +324,11 @@ class UpdatesController : | ||||
|         presenter.startDownloadingNow(chapter) | ||||
|     } | ||||
|  | ||||
|     private fun bookmarkChapters(chapters: List<UpdatesItem>, bookmarked: Boolean) { | ||||
|         presenter.bookmarkChapters(chapters, bookmarked) | ||||
|         destroyActionModeIfNeeded() | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called when ActionMode created. | ||||
|      * @param mode the ActionMode object | ||||
| @@ -346,6 +351,8 @@ class UpdatesController : | ||||
|             val chapters = getSelectedChapters() | ||||
|             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_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_unread)?.isVisible = chapters.all { it.chapter.read } | ||||
|         } | ||||
| @@ -370,6 +377,8 @@ class UpdatesController : | ||||
|             R.id.action_delete -> | ||||
|                 ConfirmDeleteChaptersDialog(this, getSelectedChapters()) | ||||
|                     .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_unread -> markAsUnread(getSelectedChapters()) | ||||
|             else -> return false | ||||
|   | ||||
| @@ -39,15 +39,18 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) | ||||
|         // Set 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) { | ||||
|             binding.chapterTitle.setTextColor(adapter.readColor) | ||||
|             binding.mangaTitle.setTextColor(adapter.readColor) | ||||
|         } else { | ||||
|             binding.chapterTitle.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 | ||||
|         binding.download.isVisible = item.manga.source != LocalSource.ID | ||||
|         binding.download.setState(item.status, item.progress) | ||||
|   | ||||
| @@ -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 | ||||
|      * @param items list of recent chapters seleted. | ||||
|   | ||||
| @@ -37,17 +37,31 @@ | ||||
|         app:layout_constraintVertical_chainStyle="packed" | ||||
|         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 | ||||
|         android:id="@+id/chapter_title" | ||||
|         android:layout_width="0dp" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_marginStart="16dp" | ||||
|         android:ellipsize="end" | ||||
|         android:maxLines="1" | ||||
|         android:textAppearance="@style/TextAppearance.Regular.Caption" | ||||
|         app:layout_constraintBottom_toBottomOf="parent" | ||||
|         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" | ||||
|         tools:text="Chapter title" /> | ||||
|  | ||||
|   | ||||
| @@ -16,6 +16,20 @@ | ||||
|         app:iconTint="?attr/colorOnToolbar" | ||||
|         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 | ||||
|         android:id="@+id/action_mark_as_read" | ||||
|         android:icon="@drawable/ic_done_24dp" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user