Convert ReaderPageSheet to Compose (#481)
* Convert ReaderPageSheet to Compose * Cleanup unused --------- Co-authored-by: GG Bond <whatever@tagkong.com>
This commit is contained in:
1 parent
791ee0ddbf
commit
c517856e89
9 files changed
+77
-217
No files matched your search
@@ -46,10 +46,13 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ModalBottomSheetFix
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.core.content.FileProvider
|
||||
@@ -109,6 +112,7 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.sample
|
||||
import kotlinx.coroutines.launch
|
||||
import splitties.init.appCtx
|
||||
import splitties.systemservices.clipboardManager
|
||||
|
||||
@@ -735,7 +739,21 @@ class ReaderActivity : EhActivity() {
|
||||
* actions to perform is shown.
|
||||
*/
|
||||
fun onPageLongTap(page: ReaderPage) {
|
||||
ReaderPageSheet(this, page).show()
|
||||
lifecycleScope.launch {
|
||||
dialogState.dialog {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
fun dismiss() = it.cancel()
|
||||
val sheetState = rememberModalBottomSheetState()
|
||||
ModalBottomSheetFix(
|
||||
onDismissRequest = { dismiss() },
|
||||
sheetState = sheetState,
|
||||
) {
|
||||
ReaderPageSheet(page) {
|
||||
coroutineScope.launch { sheetState.hide() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,73 +1,63 @@
|
||||
package eu.kanade.tachiyomi.ui.reader
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import com.hippo.ehviewer.databinding.ReaderPageSheetBinding
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.FileCopy
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material.icons.filled.Save
|
||||
import androidx.compose.material.icons.filled.Share
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.util.findActivity
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog
|
||||
import moe.tarsin.kt.andThen
|
||||
|
||||
/**
|
||||
* Sheet to show when a page is long clicked.
|
||||
*/
|
||||
class ReaderPageSheet(
|
||||
private val activity: ReaderActivity,
|
||||
private val page: ReaderPage,
|
||||
) : BaseBottomSheetDialog(activity) {
|
||||
@Composable
|
||||
fun ReaderPageSheet(page: ReaderPage, dismiss: () -> Unit) {
|
||||
val activity = LocalContext.current.run { remember { findActivity<ReaderActivity>() } }
|
||||
val modifier = Modifier.fillMaxWidth().height(56.dp).padding(horizontal = 16.dp)
|
||||
|
||||
private lateinit var binding: ReaderPageSheetBinding
|
||||
|
||||
override fun createView(inflater: LayoutInflater): View {
|
||||
binding = ReaderPageSheetBinding.inflate(activity.layoutInflater, null, false)
|
||||
|
||||
binding.share.setOnClickListener { share() }
|
||||
binding.copy.setOnClickListener { copy() }
|
||||
binding.save.setOnClickListener { save() }
|
||||
binding.saveTo.setOnClickListener { saveTo() }
|
||||
binding.refresh.setOnClickListener { refresh() }
|
||||
binding.refreshOrgImg.setOnClickListener { refreshOrgImg() }
|
||||
|
||||
return binding.root
|
||||
@Composable
|
||||
fun Item(icon: ImageVector, @StringRes text: Int, onClick: () -> Unit) = Row(
|
||||
modifier = modifier.clickable(onClick = onClick andThen dismiss),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(imageVector = icon, contentDescription = null)
|
||||
Spacer(modifier = Modifier.size(32.dp))
|
||||
Text(text = stringResource(id = text))
|
||||
}
|
||||
|
||||
/**
|
||||
* Shares the image of this page with external apps.
|
||||
*/
|
||||
private fun share() {
|
||||
activity.shareImage(page.index)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the image of this page with external apps.
|
||||
*/
|
||||
private fun copy() {
|
||||
activity.copyImage(page.index)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the image of this page on external storage.
|
||||
*/
|
||||
private fun save() {
|
||||
activity.saveImage(page.index)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the image of this page to a custom location on external storage.
|
||||
*/
|
||||
private fun saveTo() {
|
||||
activity.saveImageTo(page.index)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
Item(icon = Icons.Default.Refresh, text = R.string.refresh) {
|
||||
activity.mGalleryProvider?.retryPage(page.index)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
private fun refreshOrgImg() {
|
||||
Item(icon = Icons.Default.Refresh, text = R.string.refresh_original) {
|
||||
activity.mGalleryProvider?.retryPage(page.index, true)
|
||||
dismiss()
|
||||
}
|
||||
Item(icon = Icons.Default.Share, text = R.string.action_share) {
|
||||
activity.shareImage(page.index)
|
||||
}
|
||||
Item(icon = Icons.Default.FileCopy, text = R.string.action_copy) {
|
||||
activity.copyImage(page.index)
|
||||
}
|
||||
Item(icon = Icons.Default.Save, text = R.string.action_save) {
|
||||
activity.saveImage(page.index)
|
||||
}
|
||||
Item(icon = Icons.Default.Save, text = R.string.action_save_to) {
|
||||
activity.saveImageTo(page.index)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package moe.tarsin.kt
|
||||
|
||||
inline infix fun (() -> Unit).andThen(crossinline block: () -> Unit): () -> Unit = {
|
||||
invoke()
|
||||
block()
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM15,5L8,5c-1.1,0 -1.99,0.9 -1.99,2L6,21c0,1.1 0.89,2 1.99,2L19,23c1.1,0 2,-0.9 2,-2L21,11l-6,-6zM8,21L8,7h6v5h5v9L8,21z" />
|
||||
</vector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/black"
|
||||
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,-4zM19,19L5,19L5,5h11.17L19,7.83L19,19zM12,12c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3zM6,6h9v4L6,10z"/>
|
||||
</vector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92s2.92,-1.31 2.92,-2.92c0,-1.61 -1.31,-2.92 -2.92,-2.92zM18,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM6,13c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,20.02c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1z"/>
|
||||
</vector>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="@string/pd_refresh" />
|
||||
|
||||
</vector>
|
||||
@@ -1,98 +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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/refresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:drawablePadding="32dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:text="@string/refresh"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:drawableStartCompat="@drawable/v_refresh_dark_x24"
|
||||
app:drawableTint="?attr/colorOnBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/refreshOrgImg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:drawablePadding="32dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:text="@string/refresh_original"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:drawableStartCompat="@drawable/v_refresh_dark_x24"
|
||||
app:drawableTint="?attr/colorOnBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/share"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:drawablePadding="32dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:text="@string/action_share"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:drawableStartCompat="@drawable/ic_share_24dp"
|
||||
app:drawableTint="?attr/colorOnBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/copy"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:drawablePadding="32dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:text="@string/action_copy"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:drawableStartCompat="@drawable/ic_file_copy_24"
|
||||
app:drawableTint="?attr/colorOnBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/save"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:drawablePadding="32dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:text="@string/action_save"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:drawableStartCompat="@drawable/ic_save_24dp"
|
||||
app:drawableTint="?attr/colorOnBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/save_to"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:drawablePadding="32dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:text="@string/action_save_to"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:drawableStartCompat="@drawable/ic_save_24dp"
|
||||
app:drawableTint="?attr/colorOnBackground" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -17,7 +17,6 @@
|
||||
<resources>
|
||||
|
||||
<string name="pd_pause" translatable="false">M14,19.14H18V5.14H14M6,19.14H10V5.14H6V19.14Z</string>
|
||||
<string name="pd_refresh" translatable="false">M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z</string>
|
||||
<string name="pd_file_image" translatable="false">M13,9H18.5L13,3.5V9M6,2H14L20,8V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V4C4,2.89 4.89,2 6,2M6,20H15L18,20V12L14,16L12,14L6,20M8,9A2,2 0 0,0 6,11A2,2 0 0,0 8,13A2,2 0 0,0 10,11A2,2 0 0,0 8,9Z</string>
|
||||
|
||||
</resources>
|
||||
Reference in new issue
Block a user