Skip to content

Commit 88a480a

Browse files
Different view types | List | Grid | Compat (#233)
* Refactor metadata fetching logic to use a dedicated function and trigger on link selection * Enhance search functionality by including notes in query conditions and refactor API documentation layout * Add thumbnail support to Deepr entries and update related functionality * Implement view type selection with list, grid, and compact layouts in home screen * Refactor view types and enhance item display with swipe functionality
1 parent 0167f14 commit 88a480a

File tree

11 files changed

+817
-181
lines changed

11 files changed

+817
-181
lines changed

app/src/main/java/com/yogeshpaliyal/deepr/preference/AppPreferenceDataStore.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import androidx.datastore.core.DataStore
55
import androidx.datastore.preferences.core.Preferences
66
import androidx.datastore.preferences.core.booleanPreferencesKey
77
import androidx.datastore.preferences.core.edit
8+
import androidx.datastore.preferences.core.intPreferencesKey
89
import androidx.datastore.preferences.core.longPreferencesKey
910
import androidx.datastore.preferences.core.stringPreferencesKey
1011
import androidx.datastore.preferences.preferencesDataStore
12+
import com.yogeshpaliyal.deepr.ui.screens.home.ViewType
1113
import com.yogeshpaliyal.deepr.viewmodel.SortType
1214
import kotlinx.coroutines.flow.Flow
1315
import kotlinx.coroutines.flow.map
@@ -31,13 +33,19 @@ class AppPreferenceDataStore(
3133
private val DEFAULT_PAGE_FAVOURITES = booleanPreferencesKey("default_page_favourites")
3234
private val IS_THUMBNAIL_ENABLE = booleanPreferencesKey("is_thumbnail_enable")
3335
private val SERVER_PORT = stringPreferencesKey("server_port")
36+
private val VIEW_TYPE = intPreferencesKey("view_type")
3437
}
3538

3639
val getSortingOrder: Flow<@SortType String> =
3740
context.appDataStore.data.map { preferences ->
3841
preferences[SORTING_ORDER] ?: SortType.SORT_CREATED_BY_DESC
3942
}
4043

44+
val viewType: Flow<@ViewType Int> =
45+
context.appDataStore.data.map { preferences ->
46+
preferences[VIEW_TYPE] ?: ViewType.LIST
47+
}
48+
4149
val getUseLinkBasedIcons: Flow<Boolean> =
4250
context.appDataStore.data.map { preferences ->
4351
preferences[USE_LINK_BASED_ICONS] ?: true // Default to link-based icons
@@ -111,6 +119,12 @@ class AppPreferenceDataStore(
111119
}
112120
}
113121

122+
suspend fun setViewType(viewType: @ViewType Int) {
123+
context.appDataStore.edit { prefs ->
124+
prefs[VIEW_TYPE] = viewType
125+
}
126+
}
127+
114128
suspend fun setSyncFilePath(path: String) {
115129
context.appDataStore.edit { prefs ->
116130
prefs[SYNC_FILE_PATH] = path
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.yogeshpaliyal.deepr.ui
2+
3+
import androidx.compose.material3.MaterialTheme
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.graphics.Color
6+
7+
@Composable
8+
fun getDeeprItemBackgroundColor(isFavourite: Long): Color =
9+
if (isFavourite == 1L) MaterialTheme.colorScheme.surfaceContainerHighest else MaterialTheme.colorScheme.surfaceContainer
10+
11+
@Composable
12+
fun getDeeprItemTextColor(isFavourite: Long): Color =
13+
if (isFavourite == 1L) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.onSurfaceVariant

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

Lines changed: 13 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ import androidx.compose.foundation.ExperimentalFoundationApi
88
import androidx.compose.foundation.background
99
import androidx.compose.foundation.combinedClickable
1010
import androidx.compose.foundation.layout.Arrangement
11-
import androidx.compose.foundation.layout.Box
1211
import androidx.compose.foundation.layout.Column
1312
import androidx.compose.foundation.layout.FlowRow
1413
import androidx.compose.foundation.layout.PaddingValues
1514
import androidx.compose.foundation.layout.Row
1615
import androidx.compose.foundation.layout.Spacer
1716
import androidx.compose.foundation.layout.aspectRatio
18-
import androidx.compose.foundation.layout.fillMaxSize
1917
import androidx.compose.foundation.layout.fillMaxWidth
2018
import androidx.compose.foundation.layout.height
2119
import androidx.compose.foundation.layout.padding
2220
import androidx.compose.foundation.layout.size
23-
import androidx.compose.foundation.shape.RoundedCornerShape
2421
import androidx.compose.material.icons.Icons
2522
import androidx.compose.material.icons.rounded.Star
2623
import androidx.compose.material.icons.rounded.StarBorder
@@ -30,38 +27,30 @@ import androidx.compose.material3.FilterChip
3027
import androidx.compose.material3.Icon
3128
import androidx.compose.material3.IconButton
3229
import androidx.compose.material3.MaterialTheme
33-
import androidx.compose.material3.SwipeToDismissBox
34-
import androidx.compose.material3.SwipeToDismissBoxDefaults
35-
import androidx.compose.material3.SwipeToDismissBoxValue
3630
import androidx.compose.material3.Text
37-
import androidx.compose.material3.rememberSwipeToDismissBoxState
3831
import androidx.compose.runtime.Composable
3932
import androidx.compose.runtime.getValue
4033
import androidx.compose.runtime.mutableStateOf
4134
import androidx.compose.runtime.remember
42-
import androidx.compose.runtime.rememberCoroutineScope
4335
import androidx.compose.runtime.setValue
4436
import androidx.compose.ui.Alignment
4537
import androidx.compose.ui.Modifier
4638
import androidx.compose.ui.draw.clip
47-
import androidx.compose.ui.graphics.Color
4839
import androidx.compose.ui.layout.ContentScale
4940
import androidx.compose.ui.platform.LocalContext
5041
import androidx.compose.ui.platform.testTag
5142
import androidx.compose.ui.res.stringResource
5243
import androidx.compose.ui.text.font.FontWeight
5344
import androidx.compose.ui.text.style.TextOverflow
54-
import androidx.compose.ui.tooling.preview.Preview
5545
import androidx.compose.ui.unit.dp
5646
import coil3.compose.AsyncImage
5747
import com.yogeshpaliyal.deepr.GetLinksAndTags
5848
import com.yogeshpaliyal.deepr.R
5949
import com.yogeshpaliyal.deepr.Tags
50+
import com.yogeshpaliyal.deepr.ui.getDeeprItemBackgroundColor
51+
import com.yogeshpaliyal.deepr.ui.getDeeprItemTextColor
6052
import compose.icons.TablerIcons
6153
import compose.icons.tablericons.DotsVertical
62-
import compose.icons.tablericons.Edit
63-
import compose.icons.tablericons.Trash
64-
import kotlinx.coroutines.launch
6554
import java.text.DateFormat
6655
import java.text.SimpleDateFormat
6756
import 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
125101
fun 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

Comments
 (0)