Long press page sheet now using menu sheet

This commit is contained in:
Jay 2020-05-21 15:34:43 -04:00
parent 45161220b8
commit 3455e36a33
6 changed files with 58 additions and 173 deletions

View File

@ -56,6 +56,9 @@ class MaterialMenuSheet(
val view = val view =
activity.layoutInflater.inflate(R.layout.menu_sheet_item, null) as ViewGroup activity.layoutInflater.inflate(R.layout.menu_sheet_item, null) as ViewGroup
val textView = view.getChildAt(0) as MaterialTextView val textView = view.getChildAt(0) as MaterialTextView
if (index == 0 && title == null) {
view.setBackgroundResource(R.drawable.rounded_item_background)
}
with(view) { with(view) {
id = item.id id = item.id
menu_layout.addView(this) menu_layout.addView(this)

View File

@ -23,6 +23,7 @@ import android.view.animation.AnimationUtils
import android.widget.SeekBar import android.widget.SeekBar
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import com.afollestad.materialdialogs.MaterialDialog
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog 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.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.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.AddToLibraryFirst
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
@ -568,7 +571,25 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
* actions to perform is shown. * actions to perform is shown.
*/ */
fun onPageLongTap(page: ReaderPage) { 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()) { if (chapters_bottom_sheet.sheetBehavior.isExpanded()) {
chapters_bottom_sheet.sheetBehavior?.collapse() chapters_bottom_sheet.sheetBehavior?.collapse()
} }
@ -607,6 +628,18 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
presenter.shareImage(page) 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 * Called from the presenter when a page is ready to be shared. It shows Android's default
* sharing tool. * sharing tool.

View File

@ -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()
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z" />
</vector>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:id="@android:id/mask">
<shape>
<solid android:color="@color/fullRippleColor" />
<corners
android:topLeftRadius="14dp"
android:topRightRadius="14dp" />
</shape>
</item>
</ripple>

View File

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/BottomSheetDialogTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_sheet_rounded_background"
android:orientation="vertical">
<LinearLayout
android:id="@+id/set_as_cover_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
android:gravity="center"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:tint="@color/md_white_1000_54"
app:srcCompat="@drawable/ic_photo_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="@string/set_as_cover" />
</LinearLayout>
<LinearLayout
android:id="@+id/share_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
android:gravity="center"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:tint="@color/md_white_1000_54"
app:srcCompat="@drawable/ic_share_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="@string/share" />
</LinearLayout>
<LinearLayout
android:id="@+id/save_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
android:gravity="center"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:tint="@color/md_white_1000_54"
app:srcCompat="@drawable/ic_file_download_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="@string/save" />
</LinearLayout>
</LinearLayout>