@@ -9,6 +9,7 @@ import androidx.compose.foundation.combinedClickable
9
9
import androidx.compose.foundation.layout.Arrangement
10
10
import androidx.compose.foundation.layout.Box
11
11
import androidx.compose.foundation.layout.Column
12
+ import androidx.compose.foundation.layout.FlowRow
12
13
import androidx.compose.foundation.layout.Row
13
14
import androidx.compose.foundation.layout.Spacer
14
15
import androidx.compose.foundation.layout.fillMaxWidth
@@ -19,6 +20,7 @@ import androidx.compose.material3.DropdownMenu
19
20
import androidx.compose.material3.DropdownMenuItem
20
21
import androidx.compose.material3.Icon
21
22
import androidx.compose.material3.IconButton
23
+ import androidx.compose.material3.InputChip
22
24
import androidx.compose.material3.MaterialTheme
23
25
import androidx.compose.material3.Text
24
26
import androidx.compose.runtime.Composable
@@ -31,7 +33,8 @@ import androidx.compose.ui.Modifier
31
33
import androidx.compose.ui.platform.LocalContext
32
34
import androidx.compose.ui.text.style.TextOverflow
33
35
import androidx.compose.ui.unit.dp
34
- import com.yogeshpaliyal.deepr.Deepr
36
+ import com.yogeshpaliyal.deepr.GetLinksAndTags
37
+ import com.yogeshpaliyal.deepr.Tags
35
38
import compose.icons.TablerIcons
36
39
import compose.icons.tablericons.Copy
37
40
import compose.icons.tablericons.DotsVertical
@@ -45,17 +48,21 @@ import java.util.TimeZone
45
48
@OptIn(ExperimentalFoundationApi ::class )
46
49
@Composable
47
50
fun DeeprItem (
48
- account : Deepr ,
51
+ account : GetLinksAndTags ,
52
+ selectedTag : Tags ? ,
49
53
modifier : Modifier = Modifier ,
50
- onItemClick : ((Deepr ) -> Unit )? = null,
51
- onRemoveClick : ((Deepr ) -> Unit )? = null,
52
- onShortcutClick : ((Deepr ) -> Unit )? = null,
53
- onQrCodeClick : ((Deepr ) -> Unit )? = null,
54
- onEditClick : ((Deepr ) -> Unit )? = null,
55
- onItemLongClick : ((Deepr ) -> Unit )? = null,
54
+ onItemClick : ((GetLinksAndTags ) -> Unit )? = null,
55
+ onRemoveClick : ((GetLinksAndTags ) -> Unit )? = null,
56
+ onShortcutClick : ((GetLinksAndTags ) -> Unit )? = null,
57
+ onQrCodeClick : ((GetLinksAndTags ) -> Unit )? = null,
58
+ onEditClick : ((GetLinksAndTags ) -> Unit )? = null,
59
+ onItemLongClick : ((GetLinksAndTags ) -> Unit )? = null,
60
+ onTagClick : ((String ) -> Unit )? = null,
56
61
) {
57
62
var expanded by remember { mutableStateOf(false ) }
58
63
val context = LocalContext .current
64
+ val selectedTags =
65
+ remember(account.tagsNames) { account.tagsNames?.split(" ," )?.toMutableList() }
59
66
60
67
Card (
61
68
modifier =
@@ -81,95 +88,112 @@ fun DeeprItem(
81
88
.weight(1f )
82
89
.padding(end = 8 .dp),
83
90
) {
84
- if (account.name.isNotEmpty()) {
85
- Text (
86
- text = account.name,
87
- maxLines = 1 ,
88
- overflow = TextOverflow .Ellipsis ,
89
- style = MaterialTheme .typography.labelLarge,
90
- )
91
- }
92
- Text (
93
- text = account.link,
94
- maxLines = 1 ,
95
- overflow = TextOverflow .Ellipsis ,
96
- style = MaterialTheme .typography.bodySmall,
97
- )
98
- Spacer (modifier = Modifier .height(4 .dp))
99
- Row (verticalAlignment = Alignment .CenterVertically ) {
100
- Text (
101
- text = formatDateTime(account.createdAt),
102
- style = MaterialTheme .typography.bodySmall,
103
- color = MaterialTheme .colorScheme.onSurfaceVariant,
104
- )
105
- Spacer (modifier = Modifier .weight(1f ))
106
- Text (
107
- text = " Opened: ${account.openedCount} " ,
108
- style = MaterialTheme .typography.bodySmall,
109
- color = MaterialTheme .colorScheme.onSurfaceVariant,
110
- )
111
- }
112
- }
113
- Box {
114
- IconButton (onClick = { expanded = true }) {
115
- Icon (TablerIcons .DotsVertical , contentDescription = " More options" )
116
- }
91
+ Row (modifier = Modifier .fillMaxWidth()) {
92
+ Column (modifier = Modifier .weight(1f )) {
93
+ if (account.name.isNotEmpty()) {
94
+ Text (
95
+ text = account.name,
96
+ maxLines = 1 ,
97
+ overflow = TextOverflow .Ellipsis ,
98
+ style = MaterialTheme .typography.labelLarge,
99
+ )
100
+ }
101
+ Text (
102
+ text = account.link,
103
+ maxLines = 1 ,
104
+ overflow = TextOverflow .Ellipsis ,
105
+ style = MaterialTheme .typography.bodySmall,
106
+ )
107
+ Spacer (modifier = Modifier .height(4 .dp))
108
+ Row (verticalAlignment = Alignment .CenterVertically ) {
109
+ Text (
110
+ text = formatDateTime(account.createdAt),
111
+ style = MaterialTheme .typography.bodySmall,
112
+ color = MaterialTheme .colorScheme.onSurfaceVariant,
113
+ )
114
+ Spacer (modifier = Modifier .weight(1f ))
115
+ Text (
116
+ text = " Opened: ${account.openedCount} " ,
117
+ style = MaterialTheme .typography.bodySmall,
118
+ color = MaterialTheme .colorScheme.onSurfaceVariant,
119
+ )
120
+ }
121
+ }
122
+ Box {
123
+ IconButton (onClick = { expanded = true }) {
124
+ Icon (TablerIcons .DotsVertical , contentDescription = " More options" )
125
+ }
117
126
118
- DropdownMenu (
119
- expanded = expanded,
120
- onDismissRequest = { expanded = false },
121
- ) {
122
- DropdownMenuItem (
123
- text = { Text (" Copy link" ) },
124
- onClick = {
125
- val clipboard =
126
- context.getSystemService(Context .CLIPBOARD_SERVICE ) as ClipboardManager
127
- val clip = ClipData .newPlainText(" Link copied" , account.link)
128
- clipboard.setPrimaryClip(clip)
129
- Toast .makeText(context, " Link copied" , Toast .LENGTH_SHORT ).show()
130
- expanded = false
131
- },
132
- leadingIcon = {
133
- Icon (
134
- TablerIcons .Copy ,
135
- contentDescription = " Copy link" ,
127
+ DropdownMenu (
128
+ expanded = expanded,
129
+ onDismissRequest = { expanded = false },
130
+ ) {
131
+ DropdownMenuItem (
132
+ text = { Text (" Copy link" ) },
133
+ onClick = {
134
+ val clipboard =
135
+ context.getSystemService(Context .CLIPBOARD_SERVICE ) as ClipboardManager
136
+ val clip = ClipData .newPlainText(" Link copied" , account.link)
137
+ clipboard.setPrimaryClip(clip)
138
+ Toast .makeText(context, " Link copied" , Toast .LENGTH_SHORT ).show()
139
+ expanded = false
140
+ },
141
+ leadingIcon = {
142
+ Icon (
143
+ TablerIcons .Copy ,
144
+ contentDescription = " Copy link" ,
145
+ )
146
+ },
136
147
)
137
- },
138
- )
139
- ShortcutMenuItem (account, {
140
- onShortcutClick?.invoke(it )
141
- expanded = false
142
- } )
143
- ShowQRCodeMenuItem (account, {
144
- onQrCodeClick?.invoke(it )
145
- expanded = false
146
- })
147
- DropdownMenuItem (
148
- text = { Text ( " Edit " ) },
149
- onClick = {
150
- onEditClick?.invoke(account)
151
- expanded = false
152
- },
153
- leadingIcon = {
154
- Icon (
155
- TablerIcons . Edit ,
156
- contentDescription = " Edit " ,
148
+ ShortcutMenuItem (account, {
149
+ onShortcutClick?.invoke(it )
150
+ expanded = false
151
+ } )
152
+ ShowQRCodeMenuItem (account, {
153
+ onQrCodeClick?.invoke(it )
154
+ expanded = false
155
+ } )
156
+ DropdownMenuItem (
157
+ text = { Text ( " Edit " ) },
158
+ onClick = {
159
+ onEditClick?.invoke(account)
160
+ expanded = false
161
+ },
162
+ leadingIcon = {
163
+ Icon (
164
+ TablerIcons . Edit ,
165
+ contentDescription = " Edit " ,
166
+ )
167
+ } ,
157
168
)
158
- },
159
- )
160
- DropdownMenuItem (
161
- text = { Text ( " Delete " ) },
162
- onClick = {
163
- onRemoveClick?.invoke(account)
164
- expanded = false
165
- },
166
- leadingIcon = {
167
- Icon (
168
- TablerIcons . Trash ,
169
- contentDescription = " Delete " ,
169
+ DropdownMenuItem (
170
+ text = { Text ( " Delete " ) },
171
+ onClick = {
172
+ onRemoveClick?.invoke(account)
173
+ expanded = false
174
+ },
175
+ leadingIcon = {
176
+ Icon (
177
+ TablerIcons . Trash ,
178
+ contentDescription = " Delete " ,
179
+ )
180
+ } ,
170
181
)
171
- },
172
- )
182
+ }
183
+ }
184
+ }
185
+
186
+ FlowRow (
187
+ modifier = Modifier .fillMaxWidth(),
188
+ horizontalArrangement = Arrangement .spacedBy(4 .dp),
189
+ ) {
190
+ selectedTags?.forEach { tag ->
191
+ InputChip (
192
+ selected = selectedTag?.name == tag.trim(),
193
+ onClick = { onTagClick?.invoke(tag.trim()) },
194
+ label = { Text (tag.trim()) },
195
+ )
196
+ }
173
197
}
174
198
}
175
199
}
0 commit comments