mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Manga info action buttons
This commit is contained in:
		| @@ -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<Date> = BehaviorRelay.create() | ||||
|  | ||||
|     val chapterCountRelay: BehaviorRelay<Float> = BehaviorRelay.create() | ||||
|  | ||||
|     val mangaFavoriteRelay: PublishRelay<Boolean> = PublishRelay.create() | ||||
|  | ||||
|     private lateinit var binding: MangaControllerBinding | ||||
|   | ||||
| @@ -71,8 +71,7 @@ class ChaptersController : NucleusController<ChaptersPresenter>(), | ||||
|  | ||||
|     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 { | ||||
|   | ||||
| @@ -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<Float>, | ||||
|     private val lastUpdateRelay: BehaviorRelay<Date>, | ||||
|     private val mangaFavoriteRelay: PublishRelay<Boolean>, | ||||
|     val preferences: PreferencesHelper = Injekt.get(), | ||||
|     private val db: DatabaseHelper = Injekt.get(), | ||||
|   | ||||
| @@ -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<MangaInfoPresenter>(), | ||||
|  | ||||
|     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<MangaInfoPresenter>(), | ||||
|     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<MangaInfoPresenter>(), | ||||
|  | ||||
|     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<MangaInfoPresenter>(), | ||||
|         }) | ||||
|  | ||||
|         // 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<MangaInfoPresenter>(), | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 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<MangaInfoPresenter>(), | ||||
|         binding.swipeRefresh.isRefreshing = value | ||||
|     } | ||||
|  | ||||
|     private fun onFabClick() { | ||||
|     private fun onFavoriteClick() { | ||||
|         val manga = presenter.manga | ||||
|  | ||||
|         if (manga.favorite) { | ||||
| @@ -401,7 +400,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(), | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun onFabLongClick() { | ||||
|     private fun onFavoriteLongClick() { | ||||
|         val manga = presenter.manga | ||||
|  | ||||
|         if (manga.favorite && presenter.getCategories().isNotEmpty()) { | ||||
| @@ -415,7 +414,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(), | ||||
|             ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected) | ||||
|                     .showDialog(router) | ||||
|         } else { | ||||
|             onFabClick() | ||||
|             onFavoriteClick() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user