Cleanup res
This commit is contained in:
1 parent
c91bbc94fd
commit
3c777905f5
10 files changed
+24
-629
No files matched your search
@@ -1,18 +1,19 @@
|
||||
package com.hippo.ehviewer.ui.login
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Cookie
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
@@ -33,10 +34,10 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
@@ -45,7 +46,6 @@ import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
@@ -195,10 +195,13 @@ fun CookieSignInScene() {
|
||||
.verticalScroll(rememberScrollState()),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.v_cookie_brown_x48),
|
||||
Icon(
|
||||
imageVector = Icons.Default.Cookie,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(dimensionResource(id = R.dimen.keyline_margin))
|
||||
modifier = Modifier
|
||||
.padding(dimensionResource(id = R.dimen.keyline_margin))
|
||||
.size(48.dp),
|
||||
tint = Color(0xff795548)
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = R.string.cookie_explain),
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.hippo.ehviewer.ui.scene
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.core.view.GravityCompat
|
||||
import com.google.accompanist.themeadapter.material3.Mdc3Theme
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.ui.scene.history.HistoryScreen
|
||||
|
||||
class HistoryComposeScreenFragmentBridge : BaseScene() {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
return ComposeView(requireContext()).apply {
|
||||
setContent {
|
||||
Mdc3Theme {
|
||||
HistoryScreen(this@HistoryComposeScreenFragmentBridge)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun toggleNavigationDrawer() {
|
||||
toggleDrawer(GravityCompat.START)
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun navToDetail(gi: GalleryInfo) {
|
||||
val args = Bundle()
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO)
|
||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi)
|
||||
navigate(R.id.galleryDetailScene, args)
|
||||
}
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
package com.hippo.ehviewer.ui.scene.history
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material3.AlertDialog
|
||||
// import androidx.compose.material3.DismissDirection
|
||||
// import androidx.compose.material3.DismissValue
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
// import androidx.compose.material3.SwipeToDismiss
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
// import androidx.compose.material3.rememberDismissState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.paging.compose.items
|
||||
import com.hippo.ehviewer.EhDB
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene
|
||||
import com.hippo.ehviewer.ui.scene.HistoryComposeScreenFragmentBridge
|
||||
import com.hippo.ehviewer.ui.widget.GalleryListLongClickDialog
|
||||
import com.hippo.ehviewer.ui.widget.ListInfoCard
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun HistoryScreen(hostFragment: HistoryComposeScreenFragmentBridge) {
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val historyData = remember {
|
||||
Pager(
|
||||
PagingConfig(20)
|
||||
) {
|
||||
EhDB.historyLazyList
|
||||
}.flow
|
||||
}.collectAsLazyPagingItems()
|
||||
|
||||
var dialogStatus by remember { mutableStateOf(HistoryScreenDialogStatus.NONE) }
|
||||
var selectedGalleryInfo by remember { mutableStateOf<GalleryInfo?>(null) }
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.history))
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { hostFragment.toggleNavigationDrawer() }) {
|
||||
Icon(imageVector = Icons.Default.Menu, contentDescription = "")
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = { dialogStatus = HistoryScreenDialogStatus.CLEAR_ALL }) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.v_clear_all_dark_x24),
|
||||
contentDescription = ""
|
||||
)
|
||||
}
|
||||
},
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
LazyColumn(
|
||||
contentPadding = paddingValues
|
||||
) {
|
||||
items(
|
||||
items = historyData,
|
||||
key = { item -> item.gid }
|
||||
) { info ->
|
||||
info?.let {
|
||||
/*
|
||||
val dismissState = rememberDismissState(
|
||||
confirmValueChange = {
|
||||
if (it == DismissValue.DismissedToStart)
|
||||
coroutineScope.launchIO {
|
||||
EhDB.deleteHistoryInfo(info)
|
||||
}
|
||||
true
|
||||
}
|
||||
)
|
||||
|
||||
SwipeToDismiss(
|
||||
state = dismissState,
|
||||
background = {
|
||||
val color by animateColorAsState(
|
||||
when (dismissState.targetValue) {
|
||||
DismissValue.Default -> Color.Transparent
|
||||
DismissValue.DismissedToEnd -> Color.Green
|
||||
DismissValue.DismissedToStart -> Color.Red
|
||||
}
|
||||
)
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.background(color)
|
||||
)
|
||||
},
|
||||
dismissContent = {
|
||||
// TODO: item delete & add animation
|
||||
// Bug tracker: https://issuetracker.google.com/issues/150812265
|
||||
ListInfoCard(
|
||||
{ hostFragment.navToDetail(it) },
|
||||
{
|
||||
selectedGalleryInfo = it
|
||||
dialogStatus = HistoryScreenDialogStatus.SELECT_ITEM
|
||||
},
|
||||
info = it,
|
||||
modifier = Modifier.animateItemPlacement()
|
||||
)
|
||||
},
|
||||
directions = setOf(DismissDirection.EndToStart)
|
||||
)
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (historyData.itemCount == 0) {
|
||||
NoHistory()
|
||||
}
|
||||
}
|
||||
|
||||
if (dialogStatus == HistoryScreenDialogStatus.CLEAR_ALL) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { dialogStatus = HistoryScreenDialogStatus.NONE },
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.clear_all))
|
||||
},
|
||||
text = {
|
||||
Text(text = stringResource(id = R.string.clear_all_history))
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
coroutineScope.launchIO {
|
||||
EhDB.clearHistoryInfo()
|
||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(id = R.string.clear_all))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
||||
}
|
||||
) {
|
||||
Text(stringResource(id = android.R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (dialogStatus == HistoryScreenDialogStatus.SELECT_ITEM) {
|
||||
selectedGalleryInfo?.let { info ->
|
||||
GalleryListLongClickDialog(
|
||||
info = info,
|
||||
{ dialogStatus = HistoryScreenDialogStatus.NONE },
|
||||
{ hostFragment.showTip(it, BaseScene.LENGTH_LONG) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NoHistory() {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.big_history),
|
||||
contentDescription = null,
|
||||
Modifier.padding(16.dp),
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = R.string.no_history),
|
||||
style = MaterialTheme.typography.headlineMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
enum class HistoryScreenDialogStatus {
|
||||
NONE,
|
||||
CLEAR_ALL,
|
||||
SELECT_ITEM
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Label
|
||||
import androidx.compose.material.icons.filled.PersonAdd
|
||||
import androidx.compose.material3.AssistChip
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
@@ -17,7 +20,6 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.intl.Locale
|
||||
@@ -156,7 +158,7 @@ fun GalleryDetailHeaderCard(
|
||||
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.keyline_margin)),
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_baseline_label_24),
|
||||
imageVector = Icons.Default.Label,
|
||||
contentDescription = null
|
||||
)
|
||||
})
|
||||
@@ -168,7 +170,7 @@ fun GalleryDetailHeaderCard(
|
||||
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.keyline_margin)),
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.file_upload_black_24dp),
|
||||
imageVector = Icons.Default.PersonAdd,
|
||||
contentDescription = null
|
||||
)
|
||||
})
|
||||
|
||||
@@ -9,6 +9,10 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.Favorite
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -19,11 +23,9 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.download.DownloadManager
|
||||
@@ -89,14 +91,16 @@ fun ListInfoCard(
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
if (DownloadManager.containDownloadInfo(info.gid)) {
|
||||
Icon(
|
||||
painterResource(id = R.drawable.v_download_x16),
|
||||
contentDescription = null
|
||||
Icons.Default.Download,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
if (info.favoriteSlot != -2) {
|
||||
Icon(
|
||||
painterResource(id = R.drawable.v_heart_x16),
|
||||
contentDescription = null
|
||||
Icons.Default.Favorite,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
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.Checkbox
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
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.EhDB
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
|
||||
private val downloadManager = DownloadManager
|
||||
|
||||
@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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@Composable
|
||||
fun <T : GalleryInfo> GalleryListLongClickDialog(
|
||||
info: T,
|
||||
onDismissRequest: () -> Unit,
|
||||
showTip: (String) -> Unit
|
||||
) {
|
||||
var dialogStatus by remember { mutableStateOf(DialogStatus.PRIMARY) }
|
||||
val context = LocalContext.current
|
||||
|
||||
val removeFromFavouriteSuccess = stringResource(id = R.string.remove_from_favorite_success)
|
||||
val removeFromFavouriteFailure = stringResource(id = R.string.remove_from_favorite_failure)
|
||||
val localFavName = stringResource(id = R.string.local_favorites)
|
||||
val addToFavSuccess = stringResource(id = R.string.add_to_favorite_success)
|
||||
val addToFavFailed = stringResource(id = R.string.add_to_favorite_failure)
|
||||
|
||||
suspend fun addToFav(slot: Int) {
|
||||
val favNameList = Settings.favCat.toMutableList().apply { add(0, localFavName) }
|
||||
runCatching {
|
||||
if (slot == -1) {
|
||||
EhDB.putLocalFavorites(info)
|
||||
} else {
|
||||
EhEngine.addFavorites(
|
||||
info.gid,
|
||||
info.token,
|
||||
slot,
|
||||
""
|
||||
)
|
||||
info.favoriteSlot = slot
|
||||
info.favoriteName = favNameList[slot + 1]
|
||||
EhDB.putHistoryInfoNonRefresh(info)
|
||||
}
|
||||
}.onSuccess {
|
||||
showTip(addToFavSuccess)
|
||||
}.onFailure {
|
||||
showTip(addToFavFailed)
|
||||
}
|
||||
onDismissRequest()
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
}
|
||||
|
||||
when (dialogStatus) {
|
||||
DialogStatus.PRIMARY -> {
|
||||
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)
|
||||
onDismissRequest()
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
},
|
||||
icon = painterResource(id = R.drawable.v_book_open_x24),
|
||||
text = stringResource(id = R.string.read)
|
||||
)
|
||||
if (remember { downloadManager.containDownloadInfo(info.gid) }) {
|
||||
DialogSelectorItem(
|
||||
onClick = {
|
||||
dialogStatus = DialogStatus.CONFIRM_REMOVE_DOWNLOAD
|
||||
},
|
||||
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 = {
|
||||
val defaultFav = Settings.defaultFavSlot
|
||||
if (defaultFav in -1..9) {
|
||||
launchIO {
|
||||
addToFav(defaultFav)
|
||||
}
|
||||
} else {
|
||||
dialogStatus = DialogStatus.SELECT_FAVOURITE
|
||||
}
|
||||
},
|
||||
icon = painterResource(id = R.drawable.v_heart_x24),
|
||||
text = stringResource(id = R.string.add_to_favourites)
|
||||
)
|
||||
} else {
|
||||
DialogSelectorItem(
|
||||
onClick = {
|
||||
onDismissRequest()
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
launchIO {
|
||||
runCatching {
|
||||
EhDB.removeLocalFavorites(info.gid)
|
||||
EhEngine.addFavorites(info.gid, info.token, -1, "")
|
||||
info.favoriteSlot = -2
|
||||
info.favoriteName = null
|
||||
EhDB.putHistoryInfoNonRefresh(info)
|
||||
showTip(removeFromFavouriteSuccess)
|
||||
}.onFailure {
|
||||
showTip(removeFromFavouriteFailure)
|
||||
}
|
||||
}
|
||||
},
|
||||
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 = DialogStatus.PRIMARY
|
||||
},
|
||||
icon = painterResource(id = R.drawable.v_folder_move_x24),
|
||||
text = stringResource(id = R.string.download_move_dialog_title)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {}
|
||||
)
|
||||
}
|
||||
|
||||
DialogStatus.CONFIRM_REMOVE_DOWNLOAD -> {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
onDismissRequest()
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
},
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.download_remove_dialog_title))
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(
|
||||
id = R.string.download_remove_dialog_message,
|
||||
info.title.orEmpty()
|
||||
)
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
onDismissRequest()
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
downloadManager.deleteDownload(info.gid)
|
||||
}) {
|
||||
Text(text = stringResource(id = android.R.string.ok))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
DialogStatus.SELECT_FAVOURITE -> {
|
||||
SelectFavouriteDialog(
|
||||
onFolderSelected = {
|
||||
launchIO {
|
||||
addToFav(it)
|
||||
}
|
||||
},
|
||||
onDismissRequest = {
|
||||
onDismissRequest()
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SelectFavouriteDialog(
|
||||
onFolderSelected: (Int) -> Unit,
|
||||
onDismissRequest: () -> Unit
|
||||
) {
|
||||
var rememberFavSlot by remember { mutableStateOf(false) }
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
confirmButton = {
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Checkbox(checked = rememberFavSlot, onCheckedChange = { rememberFavSlot = it })
|
||||
Text(text = stringResource(id = R.string.remember_favorite_collection))
|
||||
}
|
||||
},
|
||||
title = { Text(text = stringResource(id = R.string.add_favorites_dialog_title)) },
|
||||
text = {
|
||||
val localFavName = stringResource(id = R.string.local_favorites)
|
||||
Column {
|
||||
remember {
|
||||
Settings.favCat.toMutableList().apply { add(0, localFavName) }
|
||||
}.forEachIndexed { index, s ->
|
||||
TextButton(
|
||||
onClick = {
|
||||
onDismissRequest()
|
||||
Settings.putDefaultFavSlot(if (rememberFavSlot) index - 1 else Settings.INVALID_DEFAULT_FAV_SLOT)
|
||||
onFolderSelected(index - 1)
|
||||
},
|
||||
Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private enum class DialogStatus {
|
||||
PRIMARY,
|
||||
CONFIRM_REMOVE_DOWNLOAD,
|
||||
SELECT_FAVOURITE
|
||||
}
|
||||
Reference in new issue
Block a user