Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Don't use medzik-android-utils because crashing
Browse files Browse the repository at this point in the history
also, if you can, don't use unstable dependencies
  • Loading branch information
M3DZIK committed Oct 29, 2023
1 parent 2aef21d commit 168f6be
Show file tree
Hide file tree
Showing 28 changed files with 1,546 additions and 56 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ dependencies {
implementation(libs.google.accompanist.systemuicontroller)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.librepass.client)
implementation(libs.medzik.android.components)
implementation(libs.medzik.android.crypto)
implementation(libs.medzik.android.utils)
implementation(libs.process.phoenix)

// local modules
implementation(project(":components"))
implementation(project(":crypto"))
implementation(project(":utils"))

// for splash screen with material3 and dynamic color
implementation(libs.google.material)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.medzik.librepass.android.ui.components
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.MoreHoriz
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -102,7 +102,7 @@ fun TopBarTwoColorPreview() {
fun TopBarBackIcon(navController: NavController) {
IconButton(onClick = { navController.popBackStack() }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
imageVector = Icons.Default.ArrowBack,
contentDescription = null
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.medzik.librepass.android.ui.screens.settings

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Logout
import androidx.compose.material.icons.filled.Logout
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
Expand All @@ -20,21 +20,22 @@ fun SettingsAccountScreen(navController: NavController) {

val repository = context.getRepository()

fun logout() = runBlocking {
val credentials = repository.credentials.get()!!
fun logout() =
runBlocking {
val credentials = repository.credentials.get()!!

repository.credentials.drop()
repository.cipher.drop(credentials.userId)
repository.credentials.drop()
repository.cipher.drop(credentials.userId)

navController.navigate(
screen = Screen.Welcome,
disableBack = true
)
}
navController.navigate(
screen = Screen.Welcome,
disableBack = true
)
}

PreferenceEntry(
title = stringResource(R.string.Settings_Logout),
icon = { Icon(Icons.AutoMirrored.Filled.Logout, contentDescription = null) },
icon = { Icon(Icons.Default.Logout, contentDescription = null) },
onClick = { logout() },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.History
import androidx.compose.material.icons.filled.OpenInNew
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material3.FloatingActionButton
Expand Down Expand Up @@ -55,22 +55,25 @@ import java.util.UUID

@Composable
fun CipherViewScreen(navController: NavController) {
val cipherId = navController.getString(Argument.CipherId)
?: return
val cipherId =
navController.getString(Argument.CipherId)
?: return

val context = LocalContext.current

val userSecrets = context.getUserSecrets()
?: return
val userSecrets =
context.getUserSecrets()
?: return

val cipher = context.getRepository().cipher.get(UUID.fromString(cipherId))!!.encryptedCipher
val cipherData = try {
Cipher(cipher, userSecrets.secretKey).loginData!!
} catch (e: Exception) {
// handle decryption error
DecryptionError(navController, e)
return
}
val cipherData =
try {
Cipher(cipher, userSecrets.secretKey).loginData!!
} catch (e: Exception) {
// handle decryption error
DecryptionError(navController, e)
return
}

Scaffold(
topBar = {
Expand All @@ -94,10 +97,11 @@ fun CipherViewScreen(navController: NavController) {
}
) { innerPadding ->
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
.padding(horizontal = 16.dp)
modifier =
Modifier
.fillMaxSize()
.padding(innerPadding)
.padding(horizontal = 16.dp)
) {
item {
CipherField(
Expand Down Expand Up @@ -155,9 +159,10 @@ fun CipherViewScreen(navController: NavController) {
Text(
text = parser.format(passwords[i].lastUsed),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.6f
)
color =
MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.6f
)
)

Text(
Expand Down Expand Up @@ -290,7 +295,7 @@ fun CipherField(
}
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.OpenInNew,
imageVector = Icons.Default.OpenInNew,
contentDescription = null
)
}
Expand All @@ -309,7 +314,10 @@ fun CipherField(
}

@Composable
fun DecryptionError(navController: NavController, e: Exception) {
fun DecryptionError(
navController: NavController,
e: Exception
) {
Scaffold(
topBar = {
TopBar(
Expand Down
1 change: 1 addition & 0 deletions components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions components/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
}

android {
namespace = "dev.medzik.android.components"
compileSdk = libs.versions.android.sdk.compile.get().toInt()

defaultConfig {
minSdk = libs.versions.android.sdk.min.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

buildFeatures {
compose = true
buildConfig = false
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}
}

dependencies {
compileOnly(libs.androidx.material3)
compileOnly(libs.androidx.navigation.compose)

debugImplementation(libs.androidx.material3)
debugImplementation(libs.androidx.navigation.compose)

androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.ui.test.junit4)

testImplementation(libs.androidx.junit)
// testImplementation(libs.androidx.compose.runtime)

debugImplementation(libs.androidx.ui.test.manifest)

// for preview support
debugImplementation(libs.androidx.ui.tooling)
implementation(libs.androidx.ui.tooling.preview)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package dev.medzik.android.components

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import org.junit.Rule
import org.junit.Test

enum class Argument : NavArgument {
ID,
Name
}

enum class Screen(override val args: Array<NavArgument>? = null) : NavScreen {
Home,
Example(arrayOf(Argument.ID, Argument.Name))
}

class NavigationTests {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testNavigation() {
composeTestRule.setContent {
val navController = rememberNavController()

NavHost(navController = navController, startDestination = Screen.Home.getRoute()) {
composable(Screen.Home.getRoute()) {
Column {
Text("Home Screen")

Button(onClick = {
navController.navigate(
screen = Screen.Example,
args =
arrayOf(
Argument.ID to "test id",
Argument.Name to "test name"
)
)
}) {
Text("Click me to go to Example screen")
}
}
}

composable(Screen.Example.getRoute()) {
val id = navController.getString(Argument.ID)
val name = navController.getString(Argument.Name)

Column {
Text("Example Screen")
Text("ID: $id")
Text("Name: $name")
}
}
}
}

composeTestRule.onNodeWithText("Home Screen").assertExists()

// go to example screen
composeTestRule.onNodeWithText("Click me to go to Example screen").performClick()
composeTestRule.onNodeWithText("Example Screen").assertExists()

// check arguments
composeTestRule.onNodeWithText("ID: test id").assertExists()
composeTestRule.onNodeWithText("Name: test name").assertExists()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package dev.medzik.android.components

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import org.junit.Rule
import org.junit.Test

class RememberTests {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testRememberMutable() {
composeTestRule.setContent {
var clicked by rememberMutable(0)

Column {
Text(text = "Clicked: $clicked")

Button(onClick = { clicked++ }) {
Text(text = "Click me")
}
}
}

// click the button two times
repeat(2) {
composeTestRule.onNodeWithText("Click me").performClick()
}

// check if the text changed
composeTestRule.onNodeWithText("Clicked: 2").assertExists()
}

@Test
fun testRememberMutableString() {
composeTestRule.setContent {
var value by rememberMutableString()

Column {
Text(text = "Current Value: $value")

Button(onClick = { value = "test" }) {
Text(text = "Click me")
}
}
}

// click button
composeTestRule.onNodeWithText("Click me").performClick()
// check if the text changed
composeTestRule.onNodeWithText("Current Value: test").assertExists()
}

@Test
fun testRememberMutableBoolean() {
composeTestRule.setContent {
var value by rememberMutableBoolean()

Column {
Text(text = "Current Value: $value")

Button(onClick = { value = true }) {
Text(text = "Click me")
}
}
}

// click button
composeTestRule.onNodeWithText("Click me").performClick()
// check if the text changed
composeTestRule.onNodeWithText("Current Value: true").assertExists()
}
}
Loading

0 comments on commit 168f6be

Please sign in to comment.