Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ dependencies {
implementation(libs.accompanist)
implementation(libs.opencsv)
implementation(libs.koin.compose)
implementation(libs.zxing.scanner)
ktlint(libs.ktlint)
implementation("dev.chrisbanes.haze:haze:1.6.9")
implementation("dev.chrisbanes.haze:haze-materials:1.6.9")
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".DeeprApplication"
Expand All @@ -23,6 +24,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="screenOrientation" />
</application>

</manifest>
50 changes: 41 additions & 9 deletions app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -53,11 +54,12 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.journeyapps.barcodescanner.ScanOptions
import com.yogeshpaliyal.deepr.Deepr
import com.yogeshpaliyal.deepr.ui.components.CreateShortcutDialog
import com.yogeshpaliyal.deepr.ui.components.EditDeeplinkDialog
import com.yogeshpaliyal.deepr.ui.components.QrCodeDialog
import com.yogeshpaliyal.deepr.util.QRScanner
import com.yogeshpaliyal.deepr.util.hasShortcut
import com.yogeshpaliyal.deepr.util.isShortcutSupported
import com.yogeshpaliyal.deepr.util.isValidDeeplink
Expand Down Expand Up @@ -100,6 +102,22 @@ fun HomeScreen(
var isSearchActive by remember { mutableStateOf(false) }
var searchQuery by remember { mutableStateOf("") }
val hazeState = rememberHazeState()
val context = LocalContext.current
val qrScanner =
rememberLauncherForActivityResult(
QRScanner(),
) { result ->
if (result.contents == null) {
Toast.makeText(context, "No Data found", Toast.LENGTH_SHORT).show()
} else {
if (isValidDeeplink(result.contents)) {
viewModel.insertAccount(result.contents, false)
Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(context, "Invalid deeplink", Toast.LENGTH_SHORT).show()
}
}
}

Scaffold(
modifier = modifier.fillMaxSize(),
Expand Down Expand Up @@ -130,10 +148,17 @@ fun HomeScreen(
contentDescription = if (isSearchActive) "Close search" else "Search",
)
}
IconButton(onClick = {
qrScanner.launch(ScanOptions())
}) {
Icon(
TablerIcons.Qrcode,
contentDescription = "QR Scanner",
)
}
FilterMenu(onSortOrderChange = {
viewModel.setSortOrder(it)
})

IconButton(onClick = {
backStack.add(Settings)
}) {
Expand Down Expand Up @@ -174,6 +199,7 @@ fun HomeScreen(
}
}

@OptIn(ExperimentalHazeMaterialsApi::class)
@Composable
fun BottomContent(
hazeState: HazeState,
Expand All @@ -191,8 +217,10 @@ fun BottomContent(
RoundedCornerShape(
topStart = 12.dp,
),
).hazeEffect(state = hazeState, style = HazeMaterials.thin())
.fillMaxWidth(),
).hazeEffect(
state = hazeState,
style = HazeMaterials.thin(),
).fillMaxWidth(),
) {
Column(
modifier =
Expand Down Expand Up @@ -229,8 +257,11 @@ fun BottomContent(
if (isValidDeeplink(inputText.value)) {
viewModel.insertAccount(inputText.value, false)
Toast
.makeText(context, "Saved", Toast.LENGTH_SHORT)
.show()
.makeText(
context,
"Saved",
Toast.LENGTH_SHORT,
).show()
inputText.value = ""
} else {
isError = true
Expand Down Expand Up @@ -527,9 +558,10 @@ fun DeeprItem(
modifier
.fillMaxWidth()
.padding(vertical = 4.dp)
.combinedClickable(onClick = { onItemClick?.invoke(account) }, onLongClick = {
onItemLongClick?.invoke(account)
}),
.combinedClickable(
onClick = { onItemClick?.invoke(account) },
onLongClick = { onItemLongClick?.invoke(account) },
),
) {
Row(
modifier =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberPermissionState
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/yogeshpaliyal/deepr/util/QRScanner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.yogeshpaliyal.deepr.util

import android.content.Context
import android.content.Intent
import androidx.activity.result.contract.ActivityResultContract
import com.journeyapps.barcodescanner.CaptureActivity
import com.journeyapps.barcodescanner.ScanIntentResult
import com.journeyapps.barcodescanner.ScanOptions

class QRScanner : ActivityResultContract<ScanOptions, ScanIntentResult>() {
override fun createIntent(
context: Context,
input: ScanOptions,
): Intent = Intent(context, CaptureActivity::class.java)

override fun parseResult(
resultCode: Int,
intent: Intent?,
): ScanIntentResult = ScanIntentResult.parseActivityResult(resultCode, intent)
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/yogeshpaliyal/deepr/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ fun openDeeplink(
fun isValidDeeplink(link: String): Boolean {
if (link.isBlank()) return false
return try {
link.toUri()
return true
} catch (e: Exception) {
val uri = link.toUri()
uri.scheme != null && uri.scheme!!.isNotBlank()
} catch (_: Exception) {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.yogeshpaliyal.deepr.Deepr
import com.yogeshpaliyal.deepr.DeeprQueries
import com.yogeshpaliyal.deepr.backup.ExportRepository
import com.yogeshpaliyal.deepr.backup.ImportRepository
import com.yogeshpaliyal.deepr.backup.ImportResult
import com.yogeshpaliyal.deepr.preference.AppPreferenceDataStore
import com.yogeshpaliyal.deepr.util.RequestResult
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -119,7 +118,7 @@ class AccountViewModel(
viewModelScope.launch {
val result = exportRepository.exportToCsv()
when (result) {
is RequestResult.Success<String> -> {
is RequestResult.Success -> {
exportResultChannel.send("Export completed: ${result.data}")
}

Expand All @@ -136,7 +135,7 @@ class AccountViewModel(
val result = importRepository.importFromCsv(uri)

when (result) {
is RequestResult.Success<ImportResult> -> {
is RequestResult.Success -> {
importResultChannel.send(
"Import complete! Added: ${result.data.importedCount}, Skipped (duplicates): ${result.data.skippedCount}",
)
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lifecycleViewmodelNav3 = "1.0.0-alpha01"
dataStore = "1.1.7"
accompanist = "0.34.0"
opencsv = "4.6"
zxing = "4.3.0"

[libraries]
android-driver = { module = "app.cash.sqldelight:android-driver", version.ref = "androidDriver" }
Expand Down Expand Up @@ -53,6 +54,7 @@ accompanist = { group = "com.google.accompanist", name = "accompanist-permission
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "nav3Core" }
androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "nav3Core" }
androidx-lifecycle-viewmodel-navigation3 = { module = "androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "lifecycleViewmodelNav3" }
zxing-scanner = { group = "com.journeyapps", name = "zxing-android-embedded", version.ref = "zxing" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down