Skip to content

Commit 9dc6cd0

Browse files
Added Clear input fields, handled fav icon filled unfilled issue (#182)
* Added Clear input fields, handled fav icon filled unfilled issue * Replaced drawables with Icon.Rounded icons --------- Co-authored-by: Yogesh Choudhary Paliyal <[email protected]>
1 parent bf81948 commit 9dc6cd0

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ dependencies {
110110
implementation(libs.androidx.ui.graphics)
111111
implementation(libs.androidx.ui.tooling.preview)
112112
implementation(libs.androidx.material3)
113+
implementation(libs.androidx.compose.material.icons.extended)
113114
testImplementation(libs.junit)
114115
testImplementation(libs.ktor.client.mock)
115116
testImplementation(libs.kotlinx.coroutines.test)

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/DeeprItem.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import androidx.compose.foundation.layout.Spacer
1414
import androidx.compose.foundation.layout.fillMaxWidth
1515
import androidx.compose.foundation.layout.height
1616
import androidx.compose.foundation.layout.padding
17+
import androidx.compose.foundation.layout.size
18+
import androidx.compose.material.icons.Icons
19+
import androidx.compose.material.icons.rounded.Star
20+
import androidx.compose.material.icons.rounded.StarBorder
1721
import androidx.compose.material3.Card
1822
import androidx.compose.material3.CardDefaults
1923
import androidx.compose.material3.DropdownMenu
@@ -43,8 +47,6 @@ import compose.icons.tablericons.Copy
4347
import compose.icons.tablericons.DotsVertical
4448
import compose.icons.tablericons.Edit
4549
import compose.icons.tablericons.Refresh
46-
import compose.icons.tablericons.Star
47-
import compose.icons.tablericons.StarOff
4850
import compose.icons.tablericons.Trash
4951
import java.text.DateFormat
5052
import java.text.SimpleDateFormat
@@ -97,9 +99,7 @@ fun DeeprItem(
9799
val selectedTags =
98100
remember(account.tagsNames) { account.tagsNames?.split(",")?.toMutableList() }
99101

100-
// Extract string resources at Composable level
101-
val copyLinkText = stringResource(R.string.copy_link)
102-
val linkCopiedText = stringResource(R.string.link_copied)
102+
val linkCopied = stringResource(R.string.link_copied)
103103

104104
Card(
105105
colors =
@@ -114,9 +114,9 @@ fun DeeprItem(
114114
onLongClick = {
115115
val clipboard =
116116
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
117-
val clip = ClipData.newPlainText(linkCopiedText, account.link)
117+
val clip = ClipData.newPlainText(linkCopied, account.link)
118118
clipboard.setPrimaryClip(clip)
119-
Toast.makeText(context, linkCopiedText, Toast.LENGTH_SHORT).show()
119+
Toast.makeText(context, linkCopied, Toast.LENGTH_SHORT).show()
120120
},
121121
),
122122
) {
@@ -161,11 +161,12 @@ fun DeeprItem(
161161
onItemClick(MenuItem.FavouriteClick(account))
162162
}) {
163163
Icon(
164-
if (account.isFavourite == 1L) {
165-
TablerIcons.StarOff
166-
} else {
167-
TablerIcons.Star
168-
},
164+
imageVector =
165+
if (account.isFavourite == 1L) {
166+
Icons.Rounded.Star
167+
} else {
168+
Icons.Rounded.StarBorder
169+
},
169170
contentDescription =
170171
if (account.isFavourite == 1L) {
171172
stringResource(R.string.remove_from_favourites)
@@ -178,6 +179,7 @@ fun DeeprItem(
178179
} else {
179180
MaterialTheme.colorScheme.onSurface
180181
},
182+
modifier = Modifier.size(28.dp),
181183
)
182184
}
183185

@@ -193,21 +195,21 @@ fun DeeprItem(
193195
onDismissRequest = { expanded = false },
194196
) {
195197
DropdownMenuItem(
196-
text = { Text(copyLinkText) },
198+
text = { Text(stringResource(R.string.copy_link)) },
197199
onClick = {
198200
val clipboard =
199201
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
200-
val clip = ClipData.newPlainText(linkCopiedText, account.link)
202+
val clip = ClipData.newPlainText(linkCopied, account.link)
201203
clipboard.setPrimaryClip(clip)
202204
Toast
203-
.makeText(context, linkCopiedText, Toast.LENGTH_SHORT)
205+
.makeText(context, linkCopied, Toast.LENGTH_SHORT)
204206
.show()
205207
expanded = false
206208
},
207209
leadingIcon = {
208210
Icon(
209211
TablerIcons.Copy,
210-
contentDescription = copyLinkText,
212+
contentDescription = stringResource(R.string.copy_link),
211213
)
212214
},
213215
)
@@ -216,10 +218,7 @@ fun DeeprItem(
216218
DropdownMenuItem(
217219
text = {
218220
Text(
219-
stringResource(
220-
R.string.last_opened,
221-
formatDateTime(account.lastOpenedAt),
222-
),
221+
stringResource(R.string.last_opened, formatDateTime(account.lastOpenedAt)),
223222
style = MaterialTheme.typography.bodySmall,
224223
color = MaterialTheme.colorScheme.onSurfaceVariant,
225224
)
@@ -252,11 +251,12 @@ fun DeeprItem(
252251
},
253252
leadingIcon = {
254253
Icon(
255-
if (account.isFavourite == 1L) {
256-
TablerIcons.StarOff
257-
} else {
258-
TablerIcons.Star
259-
},
254+
imageVector =
255+
if (account.isFavourite == 1L) {
256+
Icons.Rounded.Star
257+
} else {
258+
Icons.Rounded.StarBorder
259+
},
260260
contentDescription =
261261
if (account.isFavourite == 1L) {
262262
stringResource(R.string.remove_from_favourites)

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/Home.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.padding
2020
import androidx.compose.foundation.layout.size
2121
import androidx.compose.foundation.lazy.LazyColumn
2222
import androidx.compose.foundation.lazy.items
23+
import androidx.compose.foundation.text.input.clearText
2324
import androidx.compose.foundation.text.input.rememberTextFieldState
2425
import androidx.compose.material3.AppBarWithSearch
2526
import androidx.compose.material3.ContainedLoadingIndicator
@@ -69,6 +70,7 @@ import com.yogeshpaliyal.deepr.GetLinksAndTags
6970
import com.yogeshpaliyal.deepr.R
7071
import com.yogeshpaliyal.deepr.SharedLink
7172
import com.yogeshpaliyal.deepr.Tags
73+
import com.yogeshpaliyal.deepr.ui.components.ClearInputIconButton
7274
import com.yogeshpaliyal.deepr.ui.components.CreateShortcutDialog
7375
import com.yogeshpaliyal.deepr.ui.components.DeleteConfirmationDialog
7476
import com.yogeshpaliyal.deepr.ui.components.QrCodeDialog
@@ -224,6 +226,14 @@ fun HomeScreen(
224226
viewModel.setSortOrder(it)
225227
})
226228
}
229+
} else {
230+
if (textFieldState.text.isNotEmpty()) {
231+
ClearInputIconButton(
232+
onClick = {
233+
textFieldState.clearText()
234+
},
235+
)
236+
}
227237
}
228238
},
229239
)

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/TagSelectionBottomSheet.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ fun TagSelectionBottomSheet(
216216
label = { Text(stringResource(R.string.new_tag)) },
217217
singleLine = true,
218218
textStyle = MaterialTheme.typography.bodyLarge,
219+
suffix =
220+
if (newTagName.isNotBlank()) {
221+
{
222+
ClearInputIconButton(
223+
onClick = {
224+
newTagName = ""
225+
},
226+
)
227+
}
228+
} else {
229+
null
230+
},
219231
)
220232

221233
Spacer(modifier = Modifier.width(8.dp))
@@ -280,7 +292,7 @@ fun TagSelectionBottomSheet(
280292
},
281293
)
282294
}
283-
items(tagsWithCount) { tag ->
295+
items(tagsWithCount.sortedBy { it.name }) { tag ->
284296
ListItem(
285297
modifier =
286298
Modifier.clickable {

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ firebaseCrashlytics = "3.0.6"
3333

3434
[libraries]
3535
android-driver = { module = "app.cash.sqldelight:android-driver", version.ref = "androidDriver" }
36+
androidx-compose-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
3637
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
3738
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleRuntimeKtx" }
3839
compose-qr-code = { module = "com.lightspark:compose-qr-code", version.ref = "composeQrCode" }

0 commit comments

Comments
 (0)