Skip to content

Commit 9099904

Browse files
committed
Improve the design for created/updated at
1 parent ae65efe commit 9099904

2 files changed

Lines changed: 92 additions & 27 deletions

File tree

app/src/main/java/com/amrdeveloper/linkhub/ui/link/LinkScreen.kt

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package com.amrdeveloper.linkhub.ui.link
33
import android.webkit.URLUtil
44
import androidx.activity.compose.BackHandler
55
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.Row
7+
import androidx.compose.foundation.layout.Spacer
68
import androidx.compose.foundation.layout.fillMaxWidth
79
import androidx.compose.foundation.layout.height
810
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.layout.size
912
import androidx.compose.foundation.rememberScrollState
1013
import androidx.compose.foundation.verticalScroll
1114
import androidx.compose.material3.Icon
@@ -18,6 +21,7 @@ import androidx.compose.runtime.getValue
1821
import androidx.compose.runtime.mutableStateOf
1922
import androidx.compose.runtime.remember
2023
import androidx.compose.runtime.setValue
24+
import androidx.compose.ui.Alignment
2125
import androidx.compose.ui.Modifier
2226
import androidx.compose.ui.graphics.Color
2327
import androidx.compose.ui.res.painterResource
@@ -90,7 +94,8 @@ fun LinkScreen(
9094

9195
BackHandler(enabled = true) {
9296
if (uiPreferences.isAutoSavingEnabled()
93-
&& linkTitleErrorMessage.isEmpty() && linkUrlErrorMessage.isEmpty()) {
97+
&& linkTitleErrorMessage.isEmpty() && linkUrlErrorMessage.isEmpty()
98+
) {
9499
createOrUpdateLink()
95100
return@BackHandler
96101
}
@@ -178,20 +183,25 @@ fun LinkScreen(
178183
if (selectedFolderDry) {
179184
if (uiPreferences.isDefaultFolderEnabled()) {
180185
val defFolderId = uiPreferences.getDefaultFolderId()
181-
selectedFolder = folders.find { it.id == defFolderId } ?: folders.find { it.id == link.folderId } ?: folders[0]
186+
selectedFolder = folders.find { it.id == defFolderId }
187+
?: folders.find { it.id == link.folderId } ?: folders[0]
182188
} else {
183189
selectedFolder = folders.find { it.id == link.folderId } ?: folders[0]
184190
}
185191
}
186192

187193
// Check if user created a new folder for this link and suggest it as the current link folder
188194
val newFolderCreatedName =
189-
navController.currentBackStackEntry?.savedStateHandle?.get<String>(CREATED_FOLDER_NAME_KEY)
195+
navController.currentBackStackEntry?.savedStateHandle?.get<String>(
196+
CREATED_FOLDER_NAME_KEY
197+
)
190198
if (newFolderCreatedName != null) {
191199
selectedFolder =
192200
folders.find { it.name == newFolderCreatedName } ?: selectedFolder
193201
link.folderId = selectedFolder.id
194-
navController.currentBackStackEntry?.savedStateHandle?.remove<String>(CREATED_FOLDER_NAME_KEY)
202+
navController.currentBackStackEntry?.savedStateHandle?.remove<String>(
203+
CREATED_FOLDER_NAME_KEY
204+
)
195205
}
196206

197207
FolderSelector(selectedFolder = selectedFolder, folders = folders) {
@@ -210,26 +220,7 @@ fun LinkScreen(
210220
}
211221

212222
// Link metadata
213-
if (currentLink != null) {
214-
val dateFormatter = DateFormat.getDateTimeInstance()
215-
Text(
216-
text = "Created at ${dateFormatter.format(currentLink.createdTime)}",
217-
textAlign = TextAlign.Center,
218-
modifier = Modifier
219-
.fillMaxWidth()
220-
.padding(4.dp)
221-
)
222-
223-
if (currentLink.isUpdated) {
224-
Text(
225-
text = "Updated at ${dateFormatter.format(currentLink.lastUpdatedTime)}",
226-
textAlign = TextAlign.Center,
227-
modifier = Modifier
228-
.fillMaxWidth()
229-
.padding(4.dp)
230-
)
231-
}
232-
}
223+
currentLink?.let { LinkCreatedAndUpdatedTime(it) }
233224

234225
when (taskState) {
235226
TaskState.Success -> {
@@ -255,7 +246,7 @@ private fun isValidURI(url: String) =
255246
URLUtil.isValidUrl(url) && runCatching { URI(url) }.isSuccess
256247

257248
@Composable
258-
fun LinkHeaderIcon() {
249+
private fun LinkHeaderIcon() {
259250
Icon(
260251
painter = painterResource(R.drawable.ic_link),
261252
contentDescription = "Link Icon",
@@ -267,7 +258,7 @@ fun LinkHeaderIcon() {
267258
}
268259

269260
@Composable
270-
fun LinkInputField(
261+
private fun LinkInputField(
271262
label: String,
272263
value: String,
273264
errorMessage: String,
@@ -304,4 +295,63 @@ fun LinkInputField(
304295
Text(text = errorMessage)
305296
}
306297
})
307-
}
298+
}
299+
300+
@Composable
301+
private fun LinkCreatedAndUpdatedTime(link: Link) {
302+
val dateFormatter = DateFormat.getDateTimeInstance()
303+
304+
Row(
305+
modifier = Modifier.padding(8.dp),
306+
verticalAlignment = Alignment.CenterVertically
307+
) {
308+
Icon(
309+
painter = painterResource(R.drawable.ic_clock),
310+
contentDescription = "Time Icon",
311+
tint = Color.Unspecified,
312+
modifier = Modifier
313+
.size(20.dp)
314+
.padding(4.dp)
315+
)
316+
317+
Text(
318+
text = "Created at: ",
319+
textAlign = TextAlign.Center,
320+
)
321+
322+
Spacer(modifier = Modifier.weight(1f))
323+
324+
Text(
325+
text = "${dateFormatter.format(link.createdTime)}",
326+
textAlign = TextAlign.Center,
327+
)
328+
}
329+
330+
if (link.lastUpdatedTime == -1L) return
331+
332+
Row(
333+
modifier = Modifier.padding(8.dp),
334+
verticalAlignment = Alignment.CenterVertically
335+
) {
336+
Icon(
337+
painter = painterResource(R.drawable.ic_clock),
338+
contentDescription = "Time Icon",
339+
tint = Color.Unspecified,
340+
modifier = Modifier
341+
.size(20.dp)
342+
.padding(4.dp)
343+
)
344+
345+
Text(
346+
text = "Updated at: ",
347+
textAlign = TextAlign.Center,
348+
)
349+
350+
Spacer(modifier = Modifier.weight(1f))
351+
352+
Text(
353+
text = "${dateFormatter.format(link.lastUpdatedTime)}",
354+
textAlign = TextAlign.Center,
355+
)
356+
}
357+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="1111" android:viewportWidth="1111" android:width="25dp">
2+
3+
<path android:fillColor="#0C92F2" android:pathData="M972.8,592.1c0,-222.4 -179.9,-402.3 -402.3,-402.3s-402.3,179.9 -402.3,402.3 179.9,402.3 402.3,402.3 402.3,-179.9 402.3,-402.3zM256,592.1c0,-173.3 141.2,-314.5 314.5,-314.5s314.5,141.2 314.5,314.5 -141.2,314.5 -314.5,314.5 -314.5,-141.2 -314.5,-314.5z"/>
4+
5+
<path android:fillColor="#0C92F2" android:pathData="M526.6,255.6h87.8v117h-87.8zM526.6,811.5h87.8v117h-87.8zM424.2,145.9c-32.9,-32.2 -77.5,-49.7 -125.1,-49 -97.3,1.5 -174.1,81.9 -172.6,178.5 0.7,46.8 20.5,91.4 53.4,122.9 8,8 17.6,15.4 27.1,21.2l47.5,-73.9c-5.1,-2.9 -9.5,-6.6 -13.2,-11 -16.8,-16.1 -26.3,-38 -27.1,-61.4 -0.7,-48.3 38,-88.5 86.3,-89.2 23.4,-0.7 46.1,8.8 62.2,24.9 8,8 14.6,17.6 19.7,27.8l87.8,-35.1c-8.8,-20.5 -29.3,-39.5 -46.1,-55.6zM943.5,416.5c9.5,-6.6 18.3,-13.9 26.3,-21.9 32.2,-32.9 49.7,-77.5 49,-125.1 -1.5,-97.3 -81.9,-174.1 -178.5,-172.6 -46.8,0.7 -91.4,20.5 -122.9,53.4 -10.2,10.2 -31.5,43.9 -37.3,57.8l81.9,32.2c0.7,-0.7 1.5,-2.2 2.2,-3.7 2.2,-2.9 4.4,-7.3 7.3,-11 2.9,-4.4 5.1,-8 7.3,-11 0.7,-1.5 2.2,-2.9 2.2,-3.7 16.1,-16.1 38,-26.3 61.4,-26.3 48.3,-0.7 88.5,38 89.2,86.3 0.7,23.4 -8.8,46.1 -24.9,62.2 -3.7,4.4 -8,8 -13.2,11 -2.2,1.5 -5.1,2.9 -7.3,4.4l42.4,76.8c5.1,-2.2 10.2,-5.1 14.6,-8.8z"/>
6+
7+
<path android:fillColor="#a0caca" android:pathData="M570.5,592.1m-131.7,0a131.7,131.7 0,1 0,263.3 0,131.7 131.7,0 1,0 -263.3,0Z"/>
8+
9+
<path android:fillColor="#61B6F2" android:pathData="M457.9,524c-1.5,2.2 -7.3,13.2 -8.8,17.6 -6.6,15.4 -10.2,32.2 -10.2,50.5 0,72.4 59.2,131.7 131.7,131.7v-131.7"/>
10+
11+
<path android:fillColor="#ff2a2a" android:pathData="M570.5,723.7c73.1,0 131.7,-59.2 131.7,-131.7 0,-17.6 -13.2,-58.5 -15.4,-62.2 -0.7,-2.2 -2.2,-3.7 -2.9,-5.9 -0.7,-1.5 -112.6,68 -112.6,68l-0.7,131.7z"/>
12+
13+
<path android:fillColor="#0C92F2" android:pathData="M310.9,774.9l62.2,62.2s0,4.4 -135.3,135.3c-54.9,51.9 -113.4,-11 -113.4,-11l186.5,-186.5zM782.6,852.5l62.2,-62.2 171.9,171.9s-45.3,52.7 -113.4,11c-120.7,-118.5 -120.7,-120.7 -120.7,-120.7zM241.4,548.2h109.7v87.8h-109.7zM789.9,548.2h117v87.8h-117z"/>
14+
15+
</vector>

0 commit comments

Comments
 (0)