Skip to content

Commit ec97b21

Browse files
authored
Merge branch 'develop' into feat/create-chat-flow
2 parents 11c4779 + 94e4c95 commit ec97b21

10 files changed

Lines changed: 316 additions & 304 deletions

File tree

api/src/main/java/com/getcode/network/BalanceController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ open class BalanceController @Inject constructor(
183183
transactionReceiver.receiveFromIncoming(organizer)
184184
transactionRepository.swapIfNeeded(organizer)
185185
} catch (ex: Exception) {
186-
Timber.i("Error: ${ex.javaClass.simpleName} ${ex.cause}")
186+
Timber.i("Error: ${ex.javaClass.simpleName} ${ex.message}")
187187
val organizer =
188188
SessionManager.getOrganizer() ?: throw IllegalStateException("Missing Organizer")
189189

api/src/main/java/com/getcode/utils/Logging.kt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,37 @@ fun <T> timedTrace(
110110
result = block()
111111
}
112112

113-
val newMessage = "$message took ${time.inWholeMilliseconds}ms"
114-
trace(newMessage, tag, type, metadata, error)
113+
val timedMetadata: MetadataBuilder.() -> Unit = {
114+
// Add the original metadata
115+
metadata()
116+
"duration" to time.inWholeMilliseconds
117+
}
118+
119+
trace(message, tag, type, timedMetadata, error)
120+
121+
return result
122+
}
123+
124+
suspend fun <T> timedTraceSuspend(
125+
message: String,
126+
tag: String? = null,
127+
type: TraceType = TraceType.Log,
128+
metadata: MetadataBuilder.() -> Unit = {},
129+
error: Throwable? = null,
130+
block: suspend () -> T
131+
): T {
132+
var result: T
133+
val time = measureTime {
134+
result = block()
135+
}
136+
137+
val timedMetadata: MetadataBuilder.() -> Unit = {
138+
// Add the original metadata
139+
metadata()
140+
"duration" to time.inWholeMilliseconds
141+
}
142+
143+
trace(message, tag, type, timedMetadata, error)
115144

116145
return result
117146
}

api/src/main/java/com/getcode/utils/Timber.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ suspend fun <T> timberTimerSuspend(message: String, block: suspend () -> T): T {
2929
val result = block()
3030
Timber.d(
3131
"$message took ${
32-
(System.nanoTime() - start).toDouble().div(1000000).roundToLong()
32+
(System.nanoTime() - start).toDouble().div(1_000_000).roundToLong()
3333
}ms",
3434
)
3535
result

app/src/main/java/com/getcode/Session.kt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,12 @@ data class SessionState(
170170
UiElement.BALANCE
171171
),
172172
val tipCardConnected: Boolean = false,
173-
val fullScreenLoading: Boolean = false,
174173
)
175174

176175
sealed interface SessionEvent {
177176
data object PresentTipEntry : SessionEvent
178-
data object RequestNotificationPermissions: SessionEvent
179-
data class SendIntent(val intent: Intent): SessionEvent
177+
data object RequestNotificationPermissions : SessionEvent
178+
data class SendIntent(val intent: Intent) : SessionEvent
180179
}
181180

182181
enum class RestrictionType {
@@ -225,7 +224,7 @@ class Session @Inject constructor(
225224
appSettings.observe()
226225
.map { it.cameraStartByDefault }
227226
.distinctUntilChanged()
228-
.onEach {cameraAutoStart ->
227+
.onEach { cameraAutoStart ->
229228
uiFlow.update {
230229
it.copy(autoStartCamera = cameraAutoStart)
231230
}
@@ -630,12 +629,12 @@ class Session @Inject constructor(
630629
delay(5.seconds.inWholeMilliseconds)
631630
}
632631
withContext(Dispatchers.Main) {
633-
uiFlow.update {
634-
it.copy(
635-
billState = it.billState.copy(showToast = false)
636-
)
637-
}
632+
uiFlow.update {
633+
it.copy(
634+
billState = it.billState.copy(showToast = false)
635+
)
638636
}
637+
}
639638
}
640639
}
641640

@@ -768,6 +767,7 @@ class Session @Inject constructor(
768767
)
769768
attemptLogin(codePayload)
770769
}
770+
771771
Kind.Tip -> {
772772
trace(
773773
tag = "Bill",
@@ -868,6 +868,7 @@ class Session @Inject constructor(
868868
_eventFlow.emit(SessionEvent.RequestNotificationPermissions)
869869
}
870870
}
871+
871872
else -> {
872873
@SuppressLint("NewApi")
873874
channel?.importance = NotificationManager.IMPORTANCE_DEFAULT
@@ -1464,16 +1465,18 @@ class Session @Inject constructor(
14641465
fun onImageSelected(
14651466
uri: Uri
14661467
) {
1467-
var scanning = false
1468-
codeAnalyzer.onCodeScanned = {
1469-
scanning = false
1468+
fun onScanningStop() {
1469+
codeAnalyzer.onCodeScanned = {}
1470+
codeAnalyzer.onNoCodeFound = {}
1471+
}
14701472

1471-
uiFlow.update { state -> state.copy(fullScreenLoading = false) }
1473+
codeAnalyzer.onCodeScanned = {
1474+
onScanningStop()
14721475
onCodeScan(it)
14731476
}
1477+
14741478
codeAnalyzer.onNoCodeFound = {
1475-
scanning = false
1476-
uiFlow.update { state -> state.copy(fullScreenLoading = false) }
1479+
onScanningStop()
14771480

14781481
TopBarManager.showMessage(
14791482
TopBarManager.TopBarMessage(
@@ -1484,14 +1487,6 @@ class Session @Inject constructor(
14841487
}
14851488

14861489
codeAnalyzer.analyze(uri)
1487-
scanning = true
1488-
1489-
viewModelScope.launch {
1490-
delay(300)
1491-
if (scanning) {
1492-
uiFlow.update { it.copy(fullScreenLoading = true) }
1493-
}
1494-
}
14951490
}
14961491

14971492
fun onCodeScan(
@@ -1568,7 +1563,8 @@ class Session @Inject constructor(
15681563
private fun shareTipCard() = viewModelScope.launch {
15691564
val connectedAccount = tipController.connectedAccount.value ?: return@launch
15701565
withContext(Dispatchers.Main) {
1571-
val shareIntent = IntentUtils.tipCard(connectedAccount.username, connectedAccount.platform)
1566+
val shareIntent =
1567+
IntentUtils.tipCard(connectedAccount.username, connectedAccount.platform)
15721568

15731569
_eventFlow.emit(SessionEvent.SendIntent(shareIntent))
15741570
}
@@ -1669,6 +1665,7 @@ class Session @Inject constructor(
16691665
attemptPayment(payload, request)
16701666
}
16711667
}
1668+
16721669
request.loginRequest != null -> {
16731670
val payload = CodePayload(
16741671
kind = Kind.Login,
@@ -1684,6 +1681,7 @@ class Session @Inject constructor(
16841681
scannedRendezvous.add(payload.rendezvous.publicKey)
16851682
attemptLogin(payload, request)
16861683
}
1684+
16871685
request.tipRequest != null -> {
16881686
val payload = CodePayload(
16891687
kind = Kind.Tip,

app/src/main/java/com/getcode/view/main/scanner/ScannerScreen.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fun ScanScreen(
128128
request = request,
129129
)
130130

131-
val notificationPermissionChecker = notificationPermissionCheck { }
131+
val notificationPermissionChecker = notificationPermissionCheck { }
132132
val context = LocalContext.current
133133
LaunchedEffect(session) {
134134
session.eventFlow
@@ -189,7 +189,13 @@ private fun ScannerContent(
189189
}
190190

191191
val biometricsState = LocalBiometricsState.current
192-
LaunchedEffect(biometricsState, previewing, dataState.balance, cashLinkSaved, requestPayloadSaved) {
192+
LaunchedEffect(
193+
biometricsState,
194+
previewing,
195+
dataState.balance,
196+
cashLinkSaved,
197+
requestPayloadSaved
198+
) {
193199
if (previewing) {
194200
focusManager.clearFocus()
195201
}
@@ -206,11 +212,12 @@ private fun ScannerContent(
206212
}
207213
}
208214

209-
val pickPhoto = rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
210-
if (uri != null) {
211-
session.onImageSelected(uri)
215+
val pickPhoto =
216+
rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
217+
if (uri != null) {
218+
session.onImageSelected(uri)
219+
}
212220
}
213-
}
214221

215222
fun handleAction(action: UiElement) {
216223
scope.launch {
@@ -263,9 +270,6 @@ private fun ScannerContent(
263270
onAction = { handleAction(it) },
264271
)
265272

266-
FullScreenProgressSpinner(dataState.fullScreenLoading)
267-
KeepScreenOn(dataState.fullScreenLoading)
268-
269273
OnLifecycleEvent { _, event ->
270274
when (event) {
271275
Lifecycle.Event.ON_START -> {
@@ -358,6 +362,7 @@ private fun BillContainer(
358362
LocalBiometricsState.current.isAwaitingAuthentication -> {
359363
// waiting for result
360364
}
365+
361366
dataState.isCameraPermissionGranted == true || dataState.isCameraPermissionGranted == null -> {
362367
if (dataState.autoStartCamera == null) {
363368
// waiting for result
@@ -369,6 +374,7 @@ private fun BillContainer(
369374
scannerView()
370375
}
371376
}
377+
372378
else -> {
373379
PermissionsBlockingView(
374380
modifier = Modifier.fillMaxSize(),
@@ -408,7 +414,7 @@ private fun BillContainer(
408414
}
409415
}
410416

411-
// Composable animation for the side bar sheet
417+
// Composable animation for the decor
412418
AnimatedVisibility(
413419
visible = updatedState.billState.bill == null || billDismissState.targetValue != DismissValue.Default,
414420
enter = fadeIn(),

app/src/main/java/com/getcode/view/main/scanner/camera/CodeScanner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fun CodeScanner(
8989
var autoFocusPoint by remember { mutableStateOf(Offset.Unspecified) }
9090
var gestureController by remember { mutableStateOf<CameraGestureController?>(null) }
9191

92-
val kikCodeAnalyzer = rememberKikCodeAnalyzer(context, scanner, onCodeScanned)
92+
val kikCodeAnalyzer = rememberKikCodeAnalyzer(scanner, onCodeScanned)
9393

9494
val biometricsState = LocalBiometricsState.current
9595

app/src/main/java/com/getcode/view/main/scanner/views/CameraDisabledView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal fun CameraDisabledView(
2626
onClick: () -> Unit
2727
) {
2828
Box(
29-
modifier = modifier.background(Color.Black),
29+
modifier = modifier.background(CodeTheme.colors.background),
3030
contentAlignment = Alignment.Center
3131
) {
3232
Column(Modifier.fillMaxWidth(0.85f)) {

0 commit comments

Comments
 (0)