Skip to content

Commit 41673ab

Browse files
author
FunkyMuse
committed
make author name Long clickable
Closes #47
1 parent e5d1071 commit 41673ab

File tree

11 files changed

+157
-120
lines changed

11 files changed

+157
-120
lines changed

book/bookui/src/main/java/com/funkymuse/aurora/bookui/BookUi.kt

+37-20
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package com.funkymuse.aurora.bookui
33
import androidx.compose.foundation.ExperimentalFoundationApi
44
import androidx.compose.foundation.Image
55
import androidx.compose.foundation.combinedClickable
6+
import androidx.compose.foundation.gestures.detectTapGestures
67
import androidx.compose.foundation.layout.*
78
import androidx.compose.material.Card
89
import androidx.compose.material.Text
910
import androidx.compose.runtime.Composable
1011
import androidx.compose.ui.Alignment
1112
import androidx.compose.ui.Modifier
1213
import androidx.compose.ui.geometry.Size
13-
import androidx.compose.ui.graphics.Color
14+
import androidx.compose.ui.input.pointer.pointerInput
15+
import androidx.compose.ui.platform.LocalClipboardManager
1416
import androidx.compose.ui.res.stringResource
17+
import androidx.compose.ui.text.AnnotatedString
1518
import androidx.compose.ui.text.TextStyle
1619
import androidx.compose.ui.text.font.FontStyle
1720
import androidx.compose.ui.text.font.FontWeight
@@ -23,7 +26,6 @@ import coil.compose.rememberImagePainter
2326
import com.funkymuse.aurora.generalbook.GeneralBook
2427
import com.funkymuse.aurora.loadingcomponent.BoxShimmer
2528
import com.funkymuse.aurora.serverconstants.LIBGEN_BASE_URL
26-
2729
import com.funkymuse.style.shape.Shapes
2830

2931
/**
@@ -34,16 +36,17 @@ import com.funkymuse.style.shape.Shapes
3436
@OptIn(ExperimentalFoundationApi::class)
3537
@Composable
3638
fun Book(
37-
book: GeneralBook,
38-
onLongClick: (() -> Unit)? = null,
39-
onClick: () -> Unit = {}
39+
book: GeneralBook,
40+
onCopiedToClipBoard: (String) -> Unit = {},
41+
onLongClick: (() -> Unit)? = null,
42+
onClick: () -> Unit = {}
4043
) {
4144
Card(
42-
shape = Shapes.large,
43-
modifier = Modifier
44-
.padding(16.dp, 8.dp)
45-
.fillMaxWidth()
46-
.wrapContentHeight(),
45+
shape = Shapes.large,
46+
modifier = Modifier
47+
.padding(16.dp, 8.dp)
48+
.fillMaxWidth()
49+
.wrapContentHeight(),
4750
) {
4851
Box(
4952
modifier = Modifier
@@ -52,19 +55,19 @@ fun Book(
5255
Row(modifier = Modifier.width(IntrinsicSize.Max)) {
5356
Box(
5457
modifier = Modifier
55-
.weight(0.3f, false)
56-
.padding(16.dp)
58+
.weight(0.3f, false)
59+
.padding(16.dp)
5760
) {
5861
AddStaticImage(remoteImage = book.image)
5962
}
6063
Box(
6164
modifier = Modifier
62-
.weight(0.7f)
63-
.padding(8.dp)
65+
.weight(0.7f)
66+
.padding(8.dp)
6467
) {
6568
Column {
6669
AddTitle(titleText = book.title)
67-
AddAuthor(authorText = book.author)
70+
AddAuthor(authorText = book.author, onCopiedToClipBoard)
6871
AddYear(year = book.year)
6972
AddFormatPagesAndSize(book.extension, book.pages, book.size)
7073
}
@@ -76,8 +79,11 @@ fun Book(
7679

7780
@Composable
7881
fun AddFormatPagesAndSize(extension: String?, pages: String?, size: String?) {
82+
val pagesNumber = if (pages == "0") "" else pages
83+
7984
val pagesText =
80-
if (pages.isNullOrBlank()) "" else "($pages ${stringResource(id = R.string.pages)})"
85+
if (pagesNumber.isNullOrBlank()) "" else "($pages ${stringResource(id = R.string.pages)})"
86+
8187
val extensionText = if (extension.isNullOrBlank()) "" else extension
8288
val sizeText = if (size.isNullOrBlank()) "" else size
8389

@@ -108,14 +114,25 @@ private fun AddYear(year: String?) {
108114
)
109115
}
110116

117+
@OptIn(ExperimentalFoundationApi::class)
111118
@Composable
112119
private fun AddAuthor(
113-
authorText: String?
120+
authorText: String?,
121+
onCopiedToClipBoard: (String) -> Unit
114122
) {
123+
val clipboardManager = LocalClipboardManager.current
124+
val authorCopyRes = stringResource(id = R.string.author_copied_to_clipboard)
115125
Text(
116-
text = authorText ?: stringResource(id = R.string.not_available),
117-
modifier = Modifier.padding(end = 8.dp),
118-
fontStyle = FontStyle.Italic
126+
text = authorText ?: stringResource(id = R.string.not_available),
127+
modifier = Modifier
128+
.padding(end = 8.dp)
129+
.pointerInput(Unit) {
130+
detectTapGestures(onLongPress = {
131+
authorText?.let { clipboardManager.setText(AnnotatedString(it)) }
132+
onCopiedToClipBoard(authorCopyRes)
133+
})
134+
},
135+
fontStyle = FontStyle.Italic
119136
)
120137
}
121138

bookdetails/bookdetailsui/src/main/java/com/funkymuse/aurora/bookdetailsui/BookDetailsUi.kt

+28-28
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ private fun favoritesClick(
187187
detailedBook?.let { bookModel ->
188188
bookDetailsViewModel.addToFavorites(
189189
FavoriteBook(
190-
id = bookModel.md5 ?: bookDetailsViewModel.id,
191-
title = bookModel.title,
192-
realImage = bookModel.coverurl,
193-
author = bookModel.author,
194-
extension = bookModel.extension?.uppercase(),
195-
pages = bookModel.pagesInFile,
196-
favoriteSize = bookModel.fileSize,
197-
year = bookModel.year
190+
id = bookModel.md5?.lowercase() ?: bookDetailsViewModel.id.lowercase(),
191+
title = bookModel.title,
192+
realImage = bookModel.coverurl,
193+
author = bookModel.author,
194+
extension = bookModel.extension?.uppercase(),
195+
pages = bookModel.pagesInFile,
196+
favoriteSize = bookModel.fileSize,
197+
year = bookModel.year
198198
)
199199
)
200200
}
@@ -247,15 +247,15 @@ fun DetailedBook(
247247

248248
Column(
249249
modifier = Modifier
250-
.fillMaxSize()
251-
.verticalScroll(scrollState),
250+
.fillMaxSize()
251+
.verticalScroll(scrollState),
252252
horizontalAlignment = Alignment.CenterHorizontally
253253
) {
254254

255255
val alignment = Modifier.align(Alignment.Start)
256256
val imageModifier = Modifier
257-
.size(width = 200.dp, height = 240.dp)
258-
.padding(top = 16.dp)
257+
.size(width = 200.dp, height = 240.dp)
258+
.padding(top = 16.dp)
259259

260260
when (painter.state) {
261261
is ImagePainter.State.Loading -> {
@@ -274,8 +274,8 @@ fun DetailedBook(
274274

275275
Text(
276276
modifier = Modifier
277-
.fillMaxWidth()
278-
.padding(top = 8.dp, start = 16.dp, end = 16.dp),
277+
.fillMaxWidth()
278+
.padding(top = 8.dp, start = 16.dp, end = 16.dp),
279279
text = book.author ?: stringResource(id = R.string.not_available),
280280
style = TextStyle(
281281
fontWeight = FontWeight.SemiBold,
@@ -285,8 +285,8 @@ fun DetailedBook(
285285

286286
Text(
287287
modifier = Modifier
288-
.fillMaxWidth()
289-
.padding(top = 16.dp, start = 16.dp, end = 16.dp),
288+
.fillMaxWidth()
289+
.padding(top = 16.dp, start = 16.dp, end = 16.dp),
290290
text = book.title ?: stringResource(id = R.string.not_available),
291291
style = TextStyle(
292292
fontWeight = FontWeight.Bold,
@@ -461,15 +461,15 @@ fun TopAppBarBookDetails(
461461
Box(modifier = Modifier.fillMaxSize()) {
462462
BackButton(
463463
modifier = Modifier
464-
.align(Alignment.CenterStart)
465-
.padding(8.dp), onClick = onBackClicked
464+
.align(Alignment.CenterStart)
465+
.padding(8.dp), onClick = onBackClicked
466466
)
467467

468468
if (showFavoritesButton) {
469469
AddToFavorites(
470-
Modifier
471-
.align(Alignment.CenterEnd)
472-
.padding(8.dp), isInFavorites, onFavoritesClicked
470+
Modifier
471+
.align(Alignment.CenterEnd)
472+
.padding(8.dp), isInFavorites, onFavoritesClicked
473473
)
474474
}
475475
}
@@ -505,9 +505,9 @@ fun TitleCardWithContent(modifier: Modifier = Modifier, title: Int, text: String
505505
elevation = 2.dp,
506506
shape = Shapes.medium,
507507
modifier = modifier
508-
.padding(start = 22.dp)
509-
.offset(y = 16.dp)
510-
.zIndex(2f),
508+
.padding(start = 22.dp)
509+
.offset(y = 16.dp)
510+
.zIndex(2f),
511511
backgroundColor = MaterialTheme.colors.primaryVariant
512512
) {
513513
Box(contentAlignment = Alignment.Center) {
@@ -523,15 +523,15 @@ fun TitleCardWithContent(modifier: Modifier = Modifier, title: Int, text: String
523523
}
524524
Card(
525525
modifier = Modifier
526-
.fillMaxWidth()
527-
.padding(horizontal = 16.dp),
526+
.fillMaxWidth()
527+
.padding(horizontal = 16.dp),
528528
shape = Shapes.large
529529
) {
530530
Column {
531531
Text(
532532
modifier = Modifier
533-
.fillMaxWidth()
534-
.padding(start = 16.dp, end = 16.dp, top = 20.dp, bottom = 16.dp),
533+
.fillMaxWidth()
534+
.padding(start = 16.dp, end = 16.dp, top = 20.dp, bottom = 16.dp),
535535
text = text,
536536
fontSize = 18.sp
537537
)

crashes/crashesui/src/main/java/com/funkymuse/aurora/crashesui/CrashesUi.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import com.funkymuse.aurora.extensions.openWebPage
2222
import com.funkymuse.aurora.navigator.AuroraNavigatorViewModel
2323
import com.funkymuse.aurora.scaffolds.ScaffoldWithBack
2424
import com.funkymuse.aurora.toaster.ToasterViewModel
25+
import com.google.accompanist.insets.LocalWindowInsets
26+
import com.google.accompanist.insets.rememberInsetsPaddingValues
2527

2628
/**
2729
* Created by funkymuse on 6/29/21 to long live and prosper !
@@ -44,9 +46,13 @@ fun Crashes() {
4446
navigator.navigateUp()
4547
return
4648
}
49+
val listInsets = rememberInsetsPaddingValues(insets = LocalWindowInsets.current.navigationBars, additionalBottom = 16.dp)
50+
4751

4852
ScaffoldWithBack(onBackClicked = { navigator.navigateUp() }) {
49-
LazyColumn {
53+
LazyColumn(
54+
contentPadding = listInsets
55+
) {
5056
itemsIndexed(crashes) { index, item ->
5157
CrashItem(index + 1, item, showToast)
5258
}

donations/donationsui/src/main/java/com/funkymuse/aurora/donationsui/DonationsUi.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import com.funkymuse.aurora.donationsdata.DonationModel
2525
import com.funkymuse.aurora.donationsdata.DonationsViewModel
2626
import com.funkymuse.aurora.navigator.AuroraNavigatorViewModel
2727
import com.funkymuse.aurora.scaffolds.ScaffoldWithBack
28+
import com.google.accompanist.insets.LocalWindowInsets
29+
import com.google.accompanist.insets.rememberInsetsPaddingValues
2830

2931
/**
3032
* Created by funkymuse on 8/15/21 to long live and prosper !
@@ -66,8 +68,12 @@ fun Donations() {
6668
oneTimePreferencesViewModelFactory.create(USER_DONATED_KEY)
6769
})
6870

71+
val listInsets = rememberInsetsPaddingValues(insets = LocalWindowInsets.current.navigationBars, additionalBottom = 16.dp)
72+
6973
ScaffoldWithBack(onBackClicked = { navigator.navigateUp() }) {
70-
LazyColumn {
74+
LazyColumn(
75+
contentPadding = listInsets
76+
) {
7177
items(adapterList) { item ->
7278
DonationItem(donationResId = item.title, drawableRes = item.drawable) {
7379
viewModel.onItemClick(item)

favoritebook/favoritebookui/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies {
1010

1111
implementation project(path: ':bookdetails:bookdetailsdestination')
1212

13+
implementation project(path: ':toaster')
1314

1415
implementation project(path: ':style:shape')
1516
implementation project(path: ':style:color')

0 commit comments

Comments
 (0)