mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Manga info action buttons
This commit is contained in:
parent
c0792522a4
commit
fae763dbb0
8 changed files with 105 additions and 63 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,17 +55,6 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:background="@color/material_grey_700" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_favorite"
|
||||
style="@style/Theme.Widget.FAB"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/guideline"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/guideline"
|
||||
app:srcCompat="@drawable/ic_add_to_library_24dp" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
|
@ -187,6 +176,58 @@
|
|||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/actions_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/guideline">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_favorite"
|
||||
style="@style/Theme.Widget.Button.Icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_to_library"
|
||||
app:icon="@drawable/ic_add_to_library_24dp" />
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButton-->
|
||||
<!-- android:id="@+id/btn_tracking"-->
|
||||
<!-- style="@style/Theme.Widget.Button.Icon"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="8dp"-->
|
||||
<!-- android:text="@string/manga_tracking_tab"-->
|
||||
<!-- app:icon="@drawable/ic_sync_24dp" />-->
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_share"
|
||||
style="@style/Theme.Widget.Button.Icon.Textless"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:contentDescription="@string/action_share"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_share_24dp"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_webview"
|
||||
style="@style/Theme.Widget.Button.Icon.Textless"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:contentDescription="@string/action_open_in_web_view"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_public_24dp"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/manga_summary_label"
|
||||
style="@style/TextAppearance.Medium.Body2"
|
||||
|
@ -199,7 +240,7 @@
|
|||
android:textIsSelectable="false"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/guideline" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/actions_bar" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/manga_summary"
|
||||
|
|
|
@ -2,20 +2,6 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:icon="@drawable/ic_share_24dp"
|
||||
android:title="@string/action_share"
|
||||
app:iconTint="?attr/colorOnPrimary"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_open_in_web_view"
|
||||
android:icon="@drawable/ic_public_24dp"
|
||||
android:title="@string/action_open_in_web_view"
|
||||
app:iconTint="?attr/colorOnPrimary"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_add_to_home_screen"
|
||||
android:title="@string/action_add_to_home_screen"
|
||||
|
|
|
@ -406,6 +406,8 @@
|
|||
<string name="ongoing">Ongoing</string>
|
||||
<string name="unknown">Unknown</string>
|
||||
<string name="licensed">Licensed</string>
|
||||
<string name="add_to_library">Add to library</string>
|
||||
<string name="in_library">In library</string>
|
||||
<string name="remove_from_library">Remove from library</string>
|
||||
<string name="manga_info_full_title_label">Title</string>
|
||||
<string name="manga_added_library">Added to library</string>
|
||||
|
|
|
@ -273,6 +273,30 @@
|
|||
<item name="rippleColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Widget.Button.Icon" parent="Widget.MaterialComponents.Button.OutlinedButton.Icon">
|
||||
<item name="android:minHeight">0dp</item>
|
||||
<item name="android:paddingBottom">4dp</item>
|
||||
|
||||
<item name="elevation">0dp</item>
|
||||
|
||||
<item name="android:textSize">12sp</item>
|
||||
<item name="textAllCaps">false</item>
|
||||
<item name="cornerRadius">16dp</item>
|
||||
|
||||
<item name="iconTint">?colorAccent</item>
|
||||
<item name="rippleColor">?colorAccent</item>
|
||||
<item name="android:textColor">?attr/colorOnBackground</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Widget.Button.Icon.Textless">
|
||||
<item name="android:minWidth">0dp</item>
|
||||
<item name="android:paddingLeft">8dp</item>
|
||||
<item name="android:paddingRight">8dp</item>
|
||||
<item name="android:paddingStart">8dp</item>
|
||||
<item name="android:paddingEnd">8dp</item>
|
||||
<item name="iconPadding">0dp</item>
|
||||
</style>
|
||||
|
||||
|
||||
<!--===-->
|
||||
<!--OLD-->
|
||||
|
|
Loading…
Reference in a new issue