@@ -8,19 +8,16 @@ import androidx.compose.foundation.ExperimentalFoundationApi
88import androidx.compose.foundation.background
99import androidx.compose.foundation.combinedClickable
1010import androidx.compose.foundation.layout.Arrangement
11- import androidx.compose.foundation.layout.Box
1211import androidx.compose.foundation.layout.Column
1312import androidx.compose.foundation.layout.FlowRow
1413import androidx.compose.foundation.layout.PaddingValues
1514import androidx.compose.foundation.layout.Row
1615import androidx.compose.foundation.layout.Spacer
1716import androidx.compose.foundation.layout.aspectRatio
18- import androidx.compose.foundation.layout.fillMaxSize
1917import androidx.compose.foundation.layout.fillMaxWidth
2018import androidx.compose.foundation.layout.height
2119import androidx.compose.foundation.layout.padding
2220import androidx.compose.foundation.layout.size
23- import androidx.compose.foundation.shape.RoundedCornerShape
2421import androidx.compose.material.icons.Icons
2522import androidx.compose.material.icons.rounded.Star
2623import androidx.compose.material.icons.rounded.StarBorder
@@ -30,38 +27,30 @@ import androidx.compose.material3.FilterChip
3027import androidx.compose.material3.Icon
3128import androidx.compose.material3.IconButton
3229import androidx.compose.material3.MaterialTheme
33- import androidx.compose.material3.SwipeToDismissBox
34- import androidx.compose.material3.SwipeToDismissBoxDefaults
35- import androidx.compose.material3.SwipeToDismissBoxValue
3630import androidx.compose.material3.Text
37- import androidx.compose.material3.rememberSwipeToDismissBoxState
3831import androidx.compose.runtime.Composable
3932import androidx.compose.runtime.getValue
4033import androidx.compose.runtime.mutableStateOf
4134import androidx.compose.runtime.remember
42- import androidx.compose.runtime.rememberCoroutineScope
4335import androidx.compose.runtime.setValue
4436import androidx.compose.ui.Alignment
4537import androidx.compose.ui.Modifier
4638import androidx.compose.ui.draw.clip
47- import androidx.compose.ui.graphics.Color
4839import androidx.compose.ui.layout.ContentScale
4940import androidx.compose.ui.platform.LocalContext
5041import androidx.compose.ui.platform.testTag
5142import androidx.compose.ui.res.stringResource
5243import androidx.compose.ui.text.font.FontWeight
5344import androidx.compose.ui.text.style.TextOverflow
54- import androidx.compose.ui.tooling.preview.Preview
5545import androidx.compose.ui.unit.dp
5646import coil3.compose.AsyncImage
5747import com.yogeshpaliyal.deepr.GetLinksAndTags
5848import com.yogeshpaliyal.deepr.R
5949import com.yogeshpaliyal.deepr.Tags
50+ import com.yogeshpaliyal.deepr.ui.getDeeprItemBackgroundColor
51+ import com.yogeshpaliyal.deepr.ui.getDeeprItemTextColor
6052import compose.icons.TablerIcons
6153import compose.icons.tablericons.DotsVertical
62- import compose.icons.tablericons.Edit
63- import compose.icons.tablericons.Trash
64- import kotlinx.coroutines.launch
6554import java.text.DateFormat
6655import java.text.SimpleDateFormat
6756import java.util.Locale
@@ -74,6 +63,10 @@ sealed class MenuItem(
7463 item : GetLinksAndTags ,
7564 ) : MenuItem(item)
7665
66+ class Copy (
67+ item : GetLinksAndTags ,
68+ ) : MenuItem(item)
69+
7770 class Shortcut (
7871 item : GetLinksAndTags ,
7972 ) : MenuItem(item)
@@ -103,23 +96,6 @@ sealed class MenuItem(
10396 ) : MenuItem(item)
10497}
10598
106- @Composable
107- @Preview
108- private fun DeeprItemPreview () {
109- DeeprItem (
110- account =
111- createDeeprObject(
112- name = " Yogesh Paliyal" ,
113- link = " https://yogeshpaliyal.com" ,
114- thumbnail = " https://yogeshpaliyal.com/og.png" ,
115- ),
116- {},
117- {},
118- listOf (),
119- isThumbnailEnable = true ,
120- )
121- }
122-
12399@OptIn(ExperimentalFoundationApi ::class )
124100@Composable
125101fun DeeprItem (
@@ -138,94 +114,11 @@ fun DeeprItem(
138114
139115 val linkCopied = stringResource(R .string.link_copied)
140116
141- val dismissState =
142- rememberSwipeToDismissBoxState(
143- initialValue = SwipeToDismissBoxValue .Settled ,
144- positionalThreshold = SwipeToDismissBoxDefaults .positionalThreshold,
145- )
146-
147- val scope = rememberCoroutineScope()
148-
149- SwipeToDismissBox (
150- modifier =
151- modifier
152- .fillMaxSize()
153- .clip(RoundedCornerShape (8 .dp)),
154- state = dismissState,
155- onDismiss = {
156- scope.launch {
157- dismissState.reset()
158- }
159- when (it) {
160- SwipeToDismissBoxValue .EndToStart -> {
161- onItemClick(MenuItem .Delete (account))
162- false
163- }
164-
165- SwipeToDismissBoxValue .StartToEnd -> {
166- onItemClick(MenuItem .Edit (account))
167- false
168- }
169-
170- else -> {
171- false
172- }
173- }
174- },
175- backgroundContent = {
176- when (dismissState.dismissDirection) {
177- SwipeToDismissBoxValue .StartToEnd -> {
178- Box (
179- modifier =
180- Modifier
181- .background(
182- Color .Gray .copy(alpha = 0.5f ),
183- ).fillMaxSize()
184- .clip(
185- RoundedCornerShape (8 .dp),
186- ),
187- contentAlignment = Alignment .CenterStart ,
188- ) {
189- Icon (
190- imageVector = TablerIcons .Edit ,
191- contentDescription = stringResource(R .string.edit),
192- tint = Color .White ,
193- modifier = Modifier .padding(16 .dp),
194- )
195- }
196- }
197-
198- SwipeToDismissBoxValue .EndToStart -> {
199- Box (
200- modifier =
201- Modifier
202- .background(
203- Color .Red .copy(alpha = 0.5f ),
204- ).fillMaxSize()
205- .clip(
206- RoundedCornerShape (8 .dp),
207- ),
208- contentAlignment = Alignment .CenterEnd ,
209- ) {
210- Icon (
211- imageVector = TablerIcons .Trash ,
212- contentDescription = stringResource(R .string.delete),
213- tint = Color .White ,
214- modifier = Modifier .padding(16 .dp),
215- )
216- }
217- }
218-
219- else -> {
220- Color .White
221- }
222- }
223- },
224- ) {
117+ DeeprItemSwipable (account, onItemClick, modifier) {
225118 Card (
226119 colors =
227120 CardDefaults .cardColors(
228- containerColor = MaterialTheme .colorScheme.surfaceContainerHighest ,
121+ containerColor = getDeeprItemBackgroundColor(account.isFavourite) ,
229122 ),
230123 modifier =
231124 Modifier
@@ -278,20 +171,22 @@ fun DeeprItem(
278171 maxLines = 1 ,
279172 overflow = TextOverflow .Ellipsis ,
280173 style = MaterialTheme .typography.labelLarge,
174+ color = getDeeprItemTextColor(account.isFavourite),
281175 )
282176 }
283177 Text (
284178 text = account.link,
285179 maxLines = 1 ,
286180 overflow = TextOverflow .Ellipsis ,
287181 style = MaterialTheme .typography.bodySmall,
182+ color = getDeeprItemTextColor(account.isFavourite),
288183 )
289184 Spacer (modifier = Modifier .height(4 .dp))
290185 Row (verticalAlignment = Alignment .CenterVertically ) {
291186 Text (
292187 text = formatDateTime(account.createdAt),
293188 style = MaterialTheme .typography.bodySmall,
294- color = MaterialTheme .colorScheme.onSurfaceVariant ,
189+ color = getDeeprItemTextColor(account.isFavourite) ,
295190 )
296191 }
297192 }
@@ -313,12 +208,7 @@ fun DeeprItem(
313208 } else {
314209 stringResource(R .string.add_to_favourites)
315210 },
316- tint =
317- if (account.isFavourite == 1L ) {
318- MaterialTheme .colorScheme.primary
319- } else {
320- MaterialTheme .colorScheme.onSurface
321- },
211+ tint = getDeeprItemTextColor(account.isFavourite),
322212 modifier = Modifier .size(28 .dp),
323213 )
324214 }
@@ -340,7 +230,7 @@ fun DeeprItem(
340230 Text (
341231 text = stringResource(R .string.opened_count, account.openedCount),
342232 style = MaterialTheme .typography.bodySmall,
343- color = MaterialTheme .colorScheme.onSurfaceVariant ,
233+ color = getDeeprItemTextColor(account.isFavourite) ,
344234 )
345235 }
346236 }
0 commit comments