Move GalleryList card longclick dialog to separate file
This commit is contained in:
1 parent
1e3556cc8e
commit
e058885c7c
3 files changed
+153
-105
No files matched your search
@@ -1,6 +1,5 @@
|
|||||||
package com.hippo.ehviewer.ui.scene
|
package com.hippo.ehviewer.ui.scene
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -12,7 +11,6 @@ import com.google.accompanist.themeadapter.material3.Mdc3Theme
|
|||||||
import com.hippo.ehviewer.R
|
import com.hippo.ehviewer.R
|
||||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||||
import com.hippo.ehviewer.ui.scene.history.HistoryScreen
|
import com.hippo.ehviewer.ui.scene.history.HistoryScreen
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
|
||||||
|
|
||||||
class HistoryComposeScreenFragmentBridge : BaseScene() {
|
class HistoryComposeScreenFragmentBridge : BaseScene() {
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@@ -41,12 +39,4 @@ class HistoryComposeScreenFragmentBridge : BaseScene() {
|
|||||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi)
|
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi)
|
||||||
navigate(R.id.galleryDetailScene, args)
|
navigate(R.id.galleryDetailScene, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainThread
|
|
||||||
fun navToReader(gi: GalleryInfo) {
|
|
||||||
val intent = Intent(activity, ReaderActivity::class.java)
|
|
||||||
intent.action = ReaderActivity.ACTION_EH
|
|
||||||
intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, gi)
|
|
||||||
startActivity(intent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,10 @@ import androidx.compose.animation.animateColorAsState
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
@@ -38,7 +35,6 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -51,9 +47,9 @@ import androidx.paging.compose.items
|
|||||||
import com.hippo.ehviewer.EhApplication
|
import com.hippo.ehviewer.EhApplication
|
||||||
import com.hippo.ehviewer.EhDB
|
import com.hippo.ehviewer.EhDB
|
||||||
import com.hippo.ehviewer.R
|
import com.hippo.ehviewer.R
|
||||||
import com.hippo.ehviewer.client.EhUtils
|
|
||||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||||
import com.hippo.ehviewer.ui.scene.HistoryComposeScreenFragmentBridge
|
import com.hippo.ehviewer.ui.scene.HistoryComposeScreenFragmentBridge
|
||||||
|
import com.hippo.ehviewer.ui.widget.GalleryListLongClickDialog
|
||||||
import com.hippo.ehviewer.ui.widget.ListInfoCard
|
import com.hippo.ehviewer.ui.widget.ListInfoCard
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
|
|
||||||
@@ -190,100 +186,13 @@ fun HistoryScreen(hostFragment: HistoryComposeScreenFragmentBridge) {
|
|||||||
|
|
||||||
if (dialogStatus == HistoryScreenDialogStatus.SELECT_ITEM) {
|
if (dialogStatus == HistoryScreenDialogStatus.SELECT_ITEM) {
|
||||||
selectedGalleryInfo?.let { info ->
|
selectedGalleryInfo?.let { info ->
|
||||||
AlertDialog(
|
GalleryListLongClickDialog(info = info) {
|
||||||
onDismissRequest = { dialogStatus = HistoryScreenDialogStatus.NONE },
|
dialogStatus = HistoryScreenDialogStatus.NONE
|
||||||
title = {
|
}
|
||||||
Text(
|
|
||||||
text = EhUtils.getSuitableTitle(info),
|
|
||||||
maxLines = 2,
|
|
||||||
style = MaterialTheme.typography.titleMedium
|
|
||||||
)
|
|
||||||
},
|
|
||||||
text = {
|
|
||||||
Column {
|
|
||||||
DialogSelectorItem(
|
|
||||||
onClick = {
|
|
||||||
hostFragment.navToReader(info)
|
|
||||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
|
||||||
},
|
|
||||||
icon = painterResource(id = R.drawable.v_book_open_x24),
|
|
||||||
text = stringResource(id = R.string.read)
|
|
||||||
)
|
|
||||||
if (remember { downloadManager.containDownloadInfo(info.gid) }) {
|
|
||||||
DialogSelectorItem(
|
|
||||||
onClick = {
|
|
||||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
|
||||||
},
|
|
||||||
icon = painterResource(id = R.drawable.v_delete_x24),
|
|
||||||
text = stringResource(id = R.string.delete_downloads)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
DialogSelectorItem(
|
|
||||||
onClick = {
|
|
||||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
|
||||||
},
|
|
||||||
icon = painterResource(id = R.drawable.v_download_x24),
|
|
||||||
text = stringResource(id = R.string.download)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (info.favoriteSlot == -2) {
|
|
||||||
DialogSelectorItem(
|
|
||||||
onClick = {
|
|
||||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
|
||||||
},
|
|
||||||
icon = painterResource(id = R.drawable.v_heart_x24),
|
|
||||||
text = stringResource(id = R.string.add_to_favourites)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
DialogSelectorItem(
|
|
||||||
onClick = {
|
|
||||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
|
||||||
},
|
|
||||||
icon = painterResource(id = R.drawable.v_heart_broken_x24),
|
|
||||||
text = stringResource(id = R.string.remove_from_favourites)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (remember { downloadManager.containDownloadInfo(info.gid) }) {
|
|
||||||
DialogSelectorItem(
|
|
||||||
onClick = {
|
|
||||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
|
||||||
},
|
|
||||||
icon = painterResource(id = R.drawable.v_folder_move_x24),
|
|
||||||
text = stringResource(id = R.string.download_move_dialog_title)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmButton = {}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun DialogSelectorItem(
|
|
||||||
onClick: () -> Unit,
|
|
||||||
icon: Painter,
|
|
||||||
text: String
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable(onClick = onClick),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = icon,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = text,
|
|
||||||
style = MaterialTheme.typography.titleMedium
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun NoHistory() {
|
private fun NoHistory() {
|
||||||
Column(
|
Column(
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package com.hippo.ehviewer.ui.widget
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.core.content.ContextCompat.startActivity
|
||||||
|
import com.hippo.ehviewer.R
|
||||||
|
import com.hippo.ehviewer.client.EhUtils
|
||||||
|
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DialogSelectorItem(
|
||||||
|
onClick: () -> Unit,
|
||||||
|
icon: Painter,
|
||||||
|
text: String
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(onClick = onClick),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painter = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.padding(16.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun GalleryListLongClickDialog(
|
||||||
|
info: GalleryInfo,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
|
) {
|
||||||
|
var dialogStatus by remember { mutableStateOf(DialogStatus.PRIMARY) }
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = {
|
||||||
|
dialogStatus = DialogStatus.PRIMARY
|
||||||
|
onDismissRequest()
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = EhUtils.getSuitableTitle(info),
|
||||||
|
maxLines = 2,
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
DialogSelectorItem(
|
||||||
|
onClick = {
|
||||||
|
val intent = Intent(context, ReaderActivity::class.java)
|
||||||
|
intent.action = ReaderActivity.ACTION_EH
|
||||||
|
intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, info)
|
||||||
|
startActivity(context, intent, null)
|
||||||
|
dialogStatus = DialogStatus.PRIMARY
|
||||||
|
onDismissRequest()
|
||||||
|
},
|
||||||
|
icon = painterResource(id = R.drawable.v_book_open_x24),
|
||||||
|
text = stringResource(id = R.string.read)
|
||||||
|
)
|
||||||
|
if (remember {
|
||||||
|
com.hippo.ehviewer.ui.scene.history.downloadManager.containDownloadInfo(
|
||||||
|
info.gid
|
||||||
|
)
|
||||||
|
}) {
|
||||||
|
DialogSelectorItem(
|
||||||
|
onClick = {
|
||||||
|
dialogStatus = DialogStatus.PRIMARY
|
||||||
|
},
|
||||||
|
icon = painterResource(id = R.drawable.v_delete_x24),
|
||||||
|
text = stringResource(id = R.string.delete_downloads)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
DialogSelectorItem(
|
||||||
|
onClick = {
|
||||||
|
dialogStatus = DialogStatus.PRIMARY
|
||||||
|
},
|
||||||
|
icon = painterResource(id = R.drawable.v_download_x24),
|
||||||
|
text = stringResource(id = R.string.download)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (info.favoriteSlot == -2) {
|
||||||
|
DialogSelectorItem(
|
||||||
|
onClick = {
|
||||||
|
dialogStatus = DialogStatus.PRIMARY
|
||||||
|
},
|
||||||
|
icon = painterResource(id = R.drawable.v_heart_x24),
|
||||||
|
text = stringResource(id = R.string.add_to_favourites)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
DialogSelectorItem(
|
||||||
|
onClick = {
|
||||||
|
dialogStatus = DialogStatus.PRIMARY
|
||||||
|
},
|
||||||
|
icon = painterResource(id = R.drawable.v_heart_broken_x24),
|
||||||
|
text = stringResource(id = R.string.remove_from_favourites)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (remember {
|
||||||
|
com.hippo.ehviewer.ui.scene.history.downloadManager.containDownloadInfo(
|
||||||
|
info.gid
|
||||||
|
)
|
||||||
|
}) {
|
||||||
|
DialogSelectorItem(
|
||||||
|
onClick = {
|
||||||
|
dialogStatus = DialogStatus.PRIMARY
|
||||||
|
},
|
||||||
|
icon = painterResource(id = R.drawable.v_folder_move_x24),
|
||||||
|
text = stringResource(id = R.string.download_move_dialog_title)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum class DialogStatus {
|
||||||
|
PRIMARY,
|
||||||
|
SELECT_FAVOURITE
|
||||||
|
}
|
||||||
Reference in new issue
Block a user