From fae763dbb046e8fa886667686b6f56327fbaa8da Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 3 Apr 2020 22:41:37 -0400 Subject: [PATCH] Manga info action buttons --- .../tachiyomi/ui/manga/MangaController.kt | 5 -- .../ui/manga/chapter/ChaptersController.kt | 3 +- .../ui/manga/chapter/ChaptersPresenter.kt | 4 -- .../ui/manga/info/MangaInfoController.kt | 51 +++++++-------- .../main/res/layout/manga_info_controller.xml | 65 +++++++++++++++---- app/src/main/res/menu/manga_info.xml | 14 ---- app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/styles.xml | 24 +++++++ 8 files changed, 105 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index e30816084..fa68cd31b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -28,7 +28,6 @@ import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersController import eu.kanade.tachiyomi.ui.manga.info.MangaInfoController import eu.kanade.tachiyomi.ui.manga.track.TrackController import eu.kanade.tachiyomi.util.system.toast -import java.util.Date import kotlinx.android.synthetic.main.main_activity.tabs import rx.Subscription import uy.kohesive.injekt.Injekt @@ -62,10 +61,6 @@ class MangaController : RxController, TabbedController { val fromCatalogue = args.getBoolean(FROM_CATALOGUE_EXTRA, false) - val lastUpdateRelay: BehaviorRelay = BehaviorRelay.create() - - val chapterCountRelay: BehaviorRelay = BehaviorRelay.create() - val mangaFavoriteRelay: PublishRelay = PublishRelay.create() private lateinit var binding: MangaControllerBinding diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 4c982432e..d62dbf4cf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -71,8 +71,7 @@ class ChaptersController : NucleusController(), override fun createPresenter(): ChaptersPresenter { val ctrl = parentController as MangaController - return ChaptersPresenter(ctrl.manga!!, ctrl.source!!, - ctrl.chapterCountRelay, ctrl.lastUpdateRelay, ctrl.mangaFavoriteRelay) + return ChaptersPresenter(ctrl.manga!!, ctrl.source!!, ctrl.mangaFavoriteRelay) } override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index e644e5810..5954dc09c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.os.Bundle -import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter @@ -14,7 +13,6 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed -import java.util.Date import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -29,8 +27,6 @@ import uy.kohesive.injekt.api.get class ChaptersPresenter( val manga: Manga, val source: Source, - private val chapterCountRelay: BehaviorRelay, - private val lastUpdateRelay: BehaviorRelay, private val mangaFavoriteRelay: PublishRelay, val preferences: PreferencesHelper = Injekt.get(), private val db: DatabaseHelper = Injekt.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index e637da8cb..1cfd5a163 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -17,6 +17,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.core.content.ContextCompat import androidx.core.content.pm.ShortcutInfoCompat import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.graphics.drawable.IconCompat @@ -35,7 +36,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.databinding.MangaInfoControllerBinding import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager @@ -54,7 +54,7 @@ import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.lang.truncateCenter import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.snack -import java.text.DateFormat +import eu.kanade.tachiyomi.util.view.visible import jp.wasabeef.glide.transformations.CropSquareTransformation import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -70,10 +70,6 @@ class MangaInfoController : NucleusController(), private val preferences: PreferencesHelper by injectLazy() - private val dateFormat: DateFormat by lazy { - preferences.dateFormat().getOrDefault() - } - private lateinit var binding: MangaInfoControllerBinding init { @@ -94,11 +90,19 @@ class MangaInfoController : NucleusController(), override fun onViewCreated(view: View) { super.onViewCreated(view) - // Set onclickListener to toggle favorite when FAB clicked. - binding.fabFavorite.clicks().subscribeUntilDestroy { onFabClick() } + // Set onclickListener to toggle favorite when favorite button clicked. + binding.btnFavorite.clicks().subscribeUntilDestroy { onFavoriteClick() } - // Set onLongClickListener to manage categories when FAB is clicked. - binding.fabFavorite.longClicks().subscribeUntilDestroy { onFabLongClick() } + // Set onLongClickListener to manage categories when favorite button is clicked. + binding.btnFavorite.longClicks().subscribeUntilDestroy { onFavoriteLongClick() } + + if (presenter.source is HttpSource) { + binding.btnWebview.visible() + binding.btnShare.visible() + + binding.btnWebview.clicks().subscribeUntilDestroy { openInWebView() } + binding.btnShare.clicks().subscribeUntilDestroy { shareManga() } + } // Set SwipeRefresh to refresh manga data. binding.swipeRefresh.refreshes().subscribeUntilDestroy { fetchMangaFromSource() } @@ -138,16 +142,10 @@ class MangaInfoController : NucleusController(), override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.manga_info, menu) - - if (presenter.source !is HttpSource) { - menu.findItem(R.id.action_share).isVisible = false - } } override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.action_open_in_web_view -> openInWebView() - R.id.action_share -> shareManga() R.id.action_add_to_home_screen -> addToHomeScreen() } return super.onOptionsItemSelected(item) @@ -245,7 +243,7 @@ class MangaInfoController : NucleusController(), }) // Set the favorite drawable to the correct one. - setFavoriteDrawable(manga.favorite) + setFavoriteButtonState(manga.favorite) // Set cover if it wasn't already. if (binding.mangaCover.drawable == null && !manga.thumbnail_url.isNullOrEmpty()) { @@ -315,17 +313,18 @@ class MangaInfoController : NucleusController(), } /** - * Update FAB with correct drawable. + * Update favorite button with correct drawable and text. * * @param isFavorite determines if manga is favorite or not. */ - private fun setFavoriteDrawable(isFavorite: Boolean) { + private fun setFavoriteButtonState(isFavorite: Boolean) { // Set the Favorite drawable to the correct one. // Border drawable if false, filled drawable if true. - binding.fabFavorite.setImageResource(if (isFavorite) - R.drawable.ic_bookmark_24dp - else - R.drawable.ic_add_to_library_24dp) + binding.btnFavorite.apply { + icon = ContextCompat.getDrawable(context, if (isFavorite) R.drawable.ic_bookmark_24dp else R.drawable.ic_add_to_library_24dp) + text = context.getString(if (isFavorite) R.string.in_library else R.string.add_to_library) + isChecked = isFavorite + } } /** @@ -361,7 +360,7 @@ class MangaInfoController : NucleusController(), binding.swipeRefresh.isRefreshing = value } - private fun onFabClick() { + private fun onFavoriteClick() { val manga = presenter.manga if (manga.favorite) { @@ -401,7 +400,7 @@ class MangaInfoController : NucleusController(), } } - private fun onFabLongClick() { + private fun onFavoriteLongClick() { val manga = presenter.manga if (manga.favorite && presenter.getCategories().isNotEmpty()) { @@ -415,7 +414,7 @@ class MangaInfoController : NucleusController(), ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected) .showDialog(router) } else { - onFabClick() + onFavoriteClick() } } diff --git a/app/src/main/res/layout/manga_info_controller.xml b/app/src/main/res/layout/manga_info_controller.xml index 948bae933..dfbbc289d 100644 --- a/app/src/main/res/layout/manga_info_controller.xml +++ b/app/src/main/res/layout/manga_info_controller.xml @@ -55,17 +55,6 @@ app:layout_constraintTop_toTopOf="parent" tools:background="@color/material_grey_700" /> - - + + + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/actions_bar" /> - - - - Ongoing Unknown Licensed + Add to library + In library Remove from library Title Added to library diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 84b6235a7..9a5f86209 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -273,6 +273,30 @@ ?attr/colorAccent + + + +