From 3455e36a33f2718b55005792ddeeb0199ff3687d Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 21 May 2020 15:34:43 -0400 Subject: [PATCH] Long press page sheet now using menu sheet --- .../tachiyomi/ui/library/MaterialMenuSheet.kt | 3 + .../tachiyomi/ui/reader/ReaderActivity.kt | 35 +++++++- .../tachiyomi/ui/reader/ReaderPageSheet.kt | 87 ------------------- app/src/main/res/drawable/ic_save_24dp.xml | 9 ++ .../res/drawable/rounded_item_background.xml | 12 +++ app/src/main/res/layout/reader_page_sheet.xml | 85 ------------------ 6 files changed, 58 insertions(+), 173 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt create mode 100644 app/src/main/res/drawable/ic_save_24dp.xml create mode 100644 app/src/main/res/drawable/rounded_item_background.xml delete mode 100644 app/src/main/res/layout/reader_page_sheet.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt index da5d6b68ad..d945a1c18c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt @@ -56,6 +56,9 @@ class MaterialMenuSheet( val view = activity.layoutInflater.inflate(R.layout.menu_sheet_item, null) as ViewGroup val textView = view.getChildAt(0) as MaterialTextView + if (index == 0 && title == null) { + view.setBackgroundResource(R.drawable.rounded_item_background) + } with(view) { id = item.id menu_layout.addView(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 40047ed32a..74cf0e1728 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -23,6 +23,7 @@ import android.view.animation.AnimationUtils import android.widget.SeekBar import androidx.appcompat.app.AppCompatDelegate import androidx.core.graphics.ColorUtils +import com.afollestad.materialdialogs.MaterialDialog import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog @@ -33,7 +34,9 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity +import eu.kanade.tachiyomi.ui.library.MaterialMenuSheet import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success @@ -568,7 +571,25 @@ class ReaderActivity : BaseRxActivity(), * actions to perform is shown. */ fun onPageLongTap(page: ReaderPage) { - ReaderPageSheet(this, page).show() + val items = listOf( + MaterialMenuSheet.MenuSheetItem( + 0, R.drawable.ic_photo_24dp, R.string.set_as_cover + ), + MaterialMenuSheet.MenuSheetItem( + 1, R.drawable.ic_share_24dp, R.string.share + ), + MaterialMenuSheet.MenuSheetItem( + 2, R.drawable.ic_save_24dp, R.string.save + ) + ) + MaterialMenuSheet(this, items) { _, item -> + when (item) { + 0 -> setAsCover(page) + 1 -> shareImage(page) + 2 -> saveImage(page) + } + true + }.show() if (chapters_bottom_sheet.sheetBehavior.isExpanded()) { chapters_bottom_sheet.sheetBehavior?.collapse() } @@ -607,6 +628,18 @@ class ReaderActivity : BaseRxActivity(), presenter.shareImage(page) } + fun setCover(page: ReaderPage) { + if (page.status != Page.READY) return + + MaterialDialog(this) + .title(R.string.use_image_as_cover) + .positiveButton(android.R.string.yes) { + setAsCover(page) + } + .negativeButton(android.R.string.no) + .show() + } + /** * Called from the presenter when a page is ready to be shared. It shows Android's default * sharing tool. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt deleted file mode 100644 index 5c8ebd4423..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt +++ /dev/null @@ -1,87 +0,0 @@ -package eu.kanade.tachiyomi.ui.reader - -import android.graphics.Color -import android.os.Build -import android.os.Bundle -import android.view.View -import android.view.ViewGroup -import com.afollestad.materialdialogs.MaterialDialog -import com.google.android.material.bottomsheet.BottomSheetDialog -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.source.model.Page -import eu.kanade.tachiyomi.ui.reader.model.ReaderPage -import eu.kanade.tachiyomi.util.system.hasSideNavBar -import eu.kanade.tachiyomi.util.system.isInNightMode -import eu.kanade.tachiyomi.util.view.setBottomEdge -import eu.kanade.tachiyomi.util.view.setEdgeToEdge -import kotlinx.android.synthetic.main.reader_page_sheet.* - -/** - * Sheet to show when a page is long clicked. - */ -class ReaderPageSheet( - private val activity: ReaderActivity, - private val page: ReaderPage -) : BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) { - - /** - * View used on this sheet. - */ - private val view = activity.layoutInflater.inflate(R.layout.reader_page_sheet, null) - - init { - setContentView(view) - setEdgeToEdge(activity, view) - window?.navigationBarColor = Color.TRANSPARENT - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && - !context.isInNightMode() && - !activity.window.decorView.rootWindowInsets.hasSideNavBar()) - window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - - setBottomEdge(save_layout, activity) - - set_as_cover_layout.setOnClickListener { setAsCover() } - share_layout.setOnClickListener { share() } - save_layout.setOnClickListener { save() } - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - val width = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_width) - if (width > 0) { - window?.setLayout(width, ViewGroup.LayoutParams.MATCH_PARENT) - } - } - - /** - * Sets the image of this page as the cover of the manga. - */ - private fun setAsCover() { - if (page.status != Page.READY) return - - MaterialDialog(activity) - .title(R.string.use_image_as_cover) - .positiveButton(android.R.string.yes) { - activity.setAsCover(page) - dismiss() - } - .negativeButton(android.R.string.no) - .show() - } - - /** - * Shares the image of this page with external apps. - */ - private fun share() { - activity.shareImage(page) - dismiss() - } - - /** - * Saves the image of this page on external storage. - */ - private fun save() { - activity.saveImage(page) - dismiss() - } -} diff --git a/app/src/main/res/drawable/ic_save_24dp.xml b/app/src/main/res/drawable/ic_save_24dp.xml new file mode 100644 index 0000000000..0651fcc6c3 --- /dev/null +++ b/app/src/main/res/drawable/ic_save_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/rounded_item_background.xml b/app/src/main/res/drawable/rounded_item_background.xml new file mode 100644 index 0000000000..993bd4c219 --- /dev/null +++ b/app/src/main/res/drawable/rounded_item_background.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/reader_page_sheet.xml b/app/src/main/res/layout/reader_page_sheet.xml deleted file mode 100644 index 9edf138966..0000000000 --- a/app/src/main/res/layout/reader_page_sheet.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -