@@ -17,9 +17,11 @@ import androidx.compose.foundation.layout.padding
17
17
import androidx.compose.foundation.layout.size
18
18
import androidx.compose.foundation.lazy.LazyColumn
19
19
import androidx.compose.foundation.lazy.items
20
+ import androidx.compose.material3.BottomAppBar
20
21
import androidx.compose.material3.ContainedLoadingIndicator
21
22
import androidx.compose.material3.ExperimentalMaterial3Api
22
23
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
24
+ import androidx.compose.material3.FloatingActionButton
23
25
import androidx.compose.material3.Icon
24
26
import androidx.compose.material3.IconButton
25
27
import androidx.compose.material3.MaterialTheme
@@ -46,7 +48,6 @@ import com.journeyapps.barcodescanner.ScanOptions
46
48
import com.yogeshpaliyal.deepr.Deepr
47
49
import com.yogeshpaliyal.deepr.DeeprQueries
48
50
import com.yogeshpaliyal.deepr.ui.components.CreateShortcutDialog
49
- import com.yogeshpaliyal.deepr.ui.components.EditDeeplinkDialog
50
51
import com.yogeshpaliyal.deepr.ui.components.QrCodeDialog
51
52
import com.yogeshpaliyal.deepr.ui.screens.Settings
52
53
import com.yogeshpaliyal.deepr.util.QRScanner
@@ -55,6 +56,7 @@ import com.yogeshpaliyal.deepr.util.openDeeplink
55
56
import com.yogeshpaliyal.deepr.viewmodel.AccountViewModel
56
57
import compose.icons.TablerIcons
57
58
import compose.icons.tablericons.Link
59
+ import compose.icons.tablericons.Plus
58
60
import compose.icons.tablericons.Qrcode
59
61
import compose.icons.tablericons.Search
60
62
import compose.icons.tablericons.Settings
@@ -93,7 +95,7 @@ fun HomeScreen(
93
95
Toast .makeText(context, " No Data found" , Toast .LENGTH_SHORT ).show()
94
96
} else {
95
97
if (isValidDeeplink(result.contents)) {
96
- saveDialogInfo = SaveDialogInfo (result.contents, false )
98
+ saveDialogInfo = SaveDialogInfo (Deepr ( 0 , result.contents, " " , " " , 0 ) , false )
97
99
} else {
98
100
Toast .makeText(context, " Invalid deeplink" , Toast .LENGTH_SHORT ).show()
99
101
}
@@ -104,7 +106,7 @@ fun HomeScreen(
104
106
LaunchedEffect (sharedText) {
105
107
if (! sharedText.isNullOrBlank() && saveDialogInfo == null ) {
106
108
if (isValidDeeplink(sharedText)) {
107
- saveDialogInfo = SaveDialogInfo (sharedText, false )
109
+ saveDialogInfo = SaveDialogInfo (Deepr ( 0 , sharedText, " " , " " , 0 ) , false )
108
110
} else {
109
111
Toast
110
112
.makeText(context, " Invalid deeplink from shared content" , Toast .LENGTH_SHORT )
@@ -142,25 +144,9 @@ fun HomeScreen(
142
144
contentDescription = if (isSearchActive) " Close search" else " Search" ,
143
145
)
144
146
}
145
- IconButton (onClick = {
146
- qrScanner.launch(ScanOptions ())
147
- }) {
148
- Icon (
149
- TablerIcons .Qrcode ,
150
- contentDescription = " QR Scanner" ,
151
- )
152
- }
153
147
FilterMenu (onSortOrderChange = {
154
148
viewModel.setSortOrder(it)
155
149
})
156
- IconButton (onClick = {
157
- backStack.add(Settings )
158
- }) {
159
- Icon (
160
- TablerIcons .Settings ,
161
- contentDescription = " Settings" ,
162
- )
163
- }
164
150
},
165
151
)
166
152
AnimatedVisibility (visible = isSearchActive) {
@@ -180,16 +166,43 @@ fun HomeScreen(
180
166
}
181
167
},
182
168
bottomBar = {
183
- HomeBottomContent (
184
- hazeState = hazeState,
185
- saveDialogInfo = saveDialogInfo,
186
- deeprQueries = deeprQueries,
187
- ) {
188
- saveDialogInfo = it
189
- if (it == null ) {
190
- resetSharedText()
191
- }
192
- }
169
+ BottomAppBar (
170
+ modifier =
171
+ Modifier .hazeEffect(
172
+ state = hazeState,
173
+ style = HazeMaterials .ultraThin(),
174
+ ),
175
+ containerColor = Color .Transparent ,
176
+ actions = {
177
+ IconButton (onClick = {
178
+ qrScanner.launch(ScanOptions ())
179
+ }) {
180
+ Icon (
181
+ TablerIcons .Qrcode ,
182
+ contentDescription = " QR Scanner" ,
183
+ )
184
+ }
185
+ IconButton (onClick = {
186
+ // Settings action
187
+ backStack.add(Settings )
188
+ }) {
189
+ Icon (
190
+ TablerIcons .Settings ,
191
+ contentDescription = " Settings" ,
192
+ )
193
+ }
194
+ },
195
+ floatingActionButton = {
196
+ FloatingActionButton (onClick = {
197
+ saveDialogInfo = SaveDialogInfo (createDeeprObject(), true )
198
+ }) {
199
+ Icon (
200
+ TablerIcons .Plus ,
201
+ contentDescription = " Add Link" ,
202
+ )
203
+ }
204
+ },
205
+ )
193
206
},
194
207
) { contentPadding ->
195
208
Column (
@@ -200,9 +213,34 @@ fun HomeScreen(
200
213
Content (
201
214
hazeState = hazeState,
202
215
contentPaddingValues = contentPadding,
203
- deeprQueries = deeprQueries,
216
+ editDeepr = {
217
+ saveDialogInfo = SaveDialogInfo (it, false )
218
+ },
204
219
)
205
220
}
221
+
222
+ saveDialogInfo?.let {
223
+ HomeBottomContent (
224
+ deeprQueries = deeprQueries,
225
+ saveDialogInfo = it,
226
+ ) { updatedValue ->
227
+ if (updatedValue != null ) {
228
+ if (updatedValue.deepr.id == 0L ) {
229
+ // New Account
230
+ viewModel.insertAccount(updatedValue.deepr.link, updatedValue.deepr.name, updatedValue.executeAfterSave)
231
+ } else {
232
+ // Edit
233
+ viewModel.updateDeeplink(updatedValue.deepr.id, updatedValue.deepr.link, updatedValue.deepr.name)
234
+ }
235
+
236
+ if (updatedValue.executeAfterSave) {
237
+ openDeeplink(context, updatedValue.deepr.link)
238
+ }
239
+ }
240
+ saveDialogInfo = null
241
+ resetSharedText()
242
+ }
243
+ }
206
244
}
207
245
}
208
246
@@ -211,9 +249,9 @@ fun HomeScreen(
211
249
fun Content (
212
250
hazeState : HazeState ,
213
251
contentPaddingValues : PaddingValues ,
214
- deeprQueries : DeeprQueries ,
215
252
modifier : Modifier = Modifier ,
216
253
viewModel : AccountViewModel = koinViewModel(),
254
+ editDeepr : (Deepr ) -> Unit = {},
217
255
) {
218
256
val accounts by viewModel.accounts.collectAsStateWithLifecycle()
219
257
@@ -230,7 +268,6 @@ fun Content(
230
268
val context = LocalContext .current
231
269
var showShortcutDialog by remember { mutableStateOf<Deepr ?>(null ) }
232
270
var showQrCodeDialog by remember { mutableStateOf<Deepr ?>(null ) }
233
- var showEditDialog by remember { mutableStateOf<Deepr ?>(null ) }
234
271
235
272
showShortcutDialog?.let { deepr ->
236
273
CreateShortcutDialog (
@@ -245,24 +282,6 @@ fun Content(
245
282
}
246
283
}
247
284
248
- showEditDialog?.let { deepr ->
249
- EditDeeplinkDialog (
250
- deepr = deepr,
251
- onDismiss = { showEditDialog = null },
252
- onSave = { newLink, newName ->
253
- if (deeprQueries.getDeeprByLink(newLink).executeAsOneOrNull() != null ) {
254
- Toast
255
- .makeText(context, " Deeplink already exists" , Toast .LENGTH_SHORT )
256
- .show()
257
- } else {
258
- viewModel.updateDeeplink(deepr.id, newLink, newName)
259
- Toast .makeText(context, " Deeplink updated" , Toast .LENGTH_SHORT ).show()
260
- }
261
- showEditDialog = null
262
- },
263
- )
264
- }
265
-
266
285
DeeprList (
267
286
modifier =
268
287
Modifier
@@ -282,9 +301,7 @@ fun Content(
282
301
onShortcutClick = {
283
302
showShortcutDialog = it
284
303
},
285
- onEditClick = {
286
- showEditDialog = it
287
- },
304
+ onEditClick = editDeepr,
288
305
onItemLongClick = {
289
306
val clipboard =
290
307
context.getSystemService(Context .CLIPBOARD_SERVICE ) as ClipboardManager
0 commit comments