mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07: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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user