Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating state #32

Merged
merged 5 commits into from
Dec 6, 2023
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
16 changes: 0 additions & 16 deletions .github/workflows/lint-action.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: testing
on: [pull_request]
jobs:
test:
name: Running Unit Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Clone repo
uses: actions/checkout@master
with:
fetch-depth: 1
- run: "./gradlew :shared:testDebugUnitTest"

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public open class OutlinedTextFieldMolecule(
override val unFocusedBorderColor: AtomikColor = focusedBorderColor,
override val radius: Int,
) : TextFieldMolecule(
textAtom,
backgroundColorAtom,
hintTextAtom,
errorTextAtom,
disabledColorAtom,
cursorColor,
errorColor,
),
textAtom,
backgroundColorAtom,
hintTextAtom,
errorTextAtom,
disabledColorAtom,
cursorColor,
errorColor,
),
BorderedAtom,
RoundedAtom {
@Composable
Expand All @@ -56,26 +56,26 @@ public open class OutlinedTextFieldMolecule(
textColor = textColor,
backgroundColor = backgroundColor,
placeholderColor =
hintTextAtom?.textColor?.composeColor ?: backgroundColor.copy(
ContentAlpha.medium,
),
hintTextAtom?.textColor?.composeColor ?: backgroundColor.copy(
ContentAlpha.medium,
),
cursorColor = cursorColor?.composeColor ?: textColor,
focusedBorderColor = focusedBorderColor.composeColor,
unfocusedBorderColor = unFocusedBorderColor.composeColor,
disabledTextColor =
disabledColorAtom?.color?.composeColor
?: textColor.copy(ContentAlpha.disabled),
disabledColorAtom?.color?.composeColor
?: textColor.copy(ContentAlpha.disabled),
disabledBorderColor = disabledColorAtom?.color?.composeColor ?: disabledBackgroundColor,
disabledLabelColor = disabledColorAtom?.color?.composeColor ?: disabledBackgroundColor,
disabledLeadingIconColor =
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledPlaceholderColor =
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledTrailingIconColor =
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
errorCursorColor = errorColor?.composeColor ?: errorTextColor,
errorBorderColor = errorColor?.composeColor ?: errorTextColor,
errorLabelColor = errorColor?.composeColor ?: errorTextColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ public open class TextFieldMolecule(
textColor = textColor,
backgroundColor = backgroundColor,
placeholderColor =
hintTextAtom?.textColor?.composeColor ?: backgroundColor.copy(
ContentAlpha.medium,
),
hintTextAtom?.textColor?.composeColor ?: backgroundColor.copy(
ContentAlpha.medium,
),
cursorColor = cursorColor?.composeColor ?: textColor,
disabledTextColor =
disabledColorAtom?.color?.composeColor
?: textColor.copy(ContentAlpha.disabled),
disabledColorAtom?.color?.composeColor
?: textColor.copy(ContentAlpha.disabled),
disabledIndicatorColor =
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledLabelColor = disabledColorAtom?.color?.composeColor ?: disabledBackgroundColor,
disabledLeadingIconColor =
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledPlaceholderColor =
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledTrailingIconColor =
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
disabledColorAtom?.color?.composeColor
?: disabledBackgroundColor,
errorCursorColor = errorColor?.composeColor ?: errorTextColor,
errorIndicatorColor = errorColor?.composeColor ?: errorTextColor,
errorLabelColor = errorColor?.composeColor ?: errorTextColor,
Expand Down

This file was deleted.

8 changes: 5 additions & 3 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ kotlin {
applyDefaultHierarchyTemplate()
androidTarget()
jvm("desktop")
listOf(
/*
listOf( TODO re-add
iosX64(),
iosArm64(),
iosSimulatorArm64(),
Expand All @@ -19,7 +20,7 @@ kotlin {
baseName = "shared"
isStatic = true
}
}
}*/

sourceSets {
val commonMain by getting {
Expand Down Expand Up @@ -70,6 +71,7 @@ kotlin {
implementation("io.github.kevinschildhorn:atomik:0.0.6")
}
}
/*
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
Expand All @@ -79,7 +81,7 @@ kotlin {
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
resources.srcDirs("src/commonMain/resources")
}
}*/
val desktopMain by getting {
dependsOn(jvmMain)
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import com.kevinschildhorn.fotopresenter.ui.compose.common.TitleView
import com.kevinschildhorn.fotopresenter.ui.compose.login.FotoPasswordTextField
import com.kevinschildhorn.fotopresenter.ui.compose.login.FotoTextField
import com.kevinschildhorn.fotopresenter.ui.compose.login.LoginScreenForm
import com.kevinschildhorn.fotopresenter.ui.state.LoginUiState
import com.kevinschildhorn.fotopresenter.ui.state.LoginScreenState
import com.kevinschildhorn.fotopresenter.ui.state.State
import com.kevinschildhorn.fotopresenter.ui.state.UiState

@Preview
@Composable
Expand Down Expand Up @@ -38,8 +39,8 @@ fun FotoTextFieldPreview() {
@Composable
fun LoginScreenFormPreview() {
LoginScreenForm(
LoginUiState(
state = State.ERROR("No Internet"),
LoginScreenState(
state = UiState.ERROR("No Internet"),
),
{},
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ val commonModule =
single { ImageRepository(get()) }

// Domain
factory { ConnectToServerUseCase(get()) }
factory { ChangeDirectoryUseCase(get()) }
factory { AutoConnectUseCase(get(), get()) }
factory { ConnectToServerUseCase(get(), baseLogger.withTag("ConnectToServerUseCase")) }
factory { ChangeDirectoryUseCase(get(), baseLogger.withTag("ChangeDirectoryUseCase")) }
factory { AutoConnectUseCase(get(), get(), baseLogger.withTag("AutoConnectUseCase")) }
factory { SaveCredentialsUseCase(get(), baseLogger.withTag("SaveCredentialsUseCase")) }
factory { RetrieveDirectoryContentsUseCase(get(), get()) }
factory {
RetrieveDirectoryContentsUseCase(
get(),
get(),
baseLogger.withTag("RetrieveDirectoryContentsUseCase"),
)
}

// UI
single { LoginViewModel(baseLogger.withTag("LoginViewModel"), get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kevinschildhorn.fotopresenter.domain

import co.touchlab.kermit.Logger
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandler
import com.kevinschildhorn.fotopresenter.data.repositories.CredentialsRepository

Expand All @@ -9,6 +10,7 @@ Automatically connect to the server using saved credentials
class AutoConnectUseCase(
private val client: NetworkHandler,
private val repository: CredentialsRepository,
private val logger: Logger,
) {
suspend operator fun invoke(): Boolean =
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.kevinschildhorn.fotopresenter.domain

import com.kevinschildhorn.fotopresenter.data.network.NetworkHandler
import co.touchlab.kermit.Logger
import com.kevinschildhorn.fotopresenter.data.datasources.DirectoryDataSource
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandlerException
import kotlin.coroutines.cancellation.CancellationException

class ChangeDirectoryUseCase(
private val client: NetworkHandler,
private val dataSource: DirectoryDataSource,
private val logger: Logger,
) {
@Throws(NetworkHandlerException::class, CancellationException::class)
suspend operator fun invoke(path: String) =
try {
client.openDirectory(path)
dataSource.changeDirectory(path)
} catch (e: Exception) {
throw NetworkHandlerException(e.message ?: "")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kevinschildhorn.fotopresenter.domain

import co.touchlab.kermit.Logger
import com.kevinschildhorn.fotopresenter.data.LoginCredentials
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandler

Expand All @@ -8,11 +9,14 @@ Connect to Server using FTPS
**/
class ConnectToServerUseCase(
private val client: NetworkHandler,
private val logger: Logger,
) {
suspend operator fun invoke(credentials: LoginCredentials): Boolean =
try {
logger.i { "Connecting to Client" }
client.connect(credentials)
} catch (e: Exception) {
logger.e(e) { "Something went wrong" }
false
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package com.kevinschildhorn.fotopresenter.domain

import co.touchlab.kermit.Logger
import com.kevinschildhorn.fotopresenter.data.DirectoryContents
import com.kevinschildhorn.fotopresenter.data.ImageDirectoryContent
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectory
import com.kevinschildhorn.fotopresenter.data.repositories.DirectoryRepository
import com.kevinschildhorn.fotopresenter.data.repositories.ImageRepository
import com.kevinschildhorn.fotopresenter.ui.SharedImage

/**
Retrieving Directories from Location
**/
class RetrieveDirectoryContentsUseCase(
private val directoryRepository: DirectoryRepository,
private val imageRepository: ImageRepository,
private val logger: Logger,
) {
suspend operator fun invoke(path: String): DirectoryContents {
val directoryContents = directoryRepository.getDirectoryContents(path)
val imageDirectories =
directoryContents.images.map {
ImageDirectoryContent(it.directory, image = imageRepository.getImage(it.directory))
}
return directoryContents.copy(images = imageDirectories)
return directoryContents.updateImages {
imageRepository.getImage(it)
}
}
}

private suspend fun DirectoryContents.updateImages(block: suspend (NetworkDirectory) -> SharedImage?): DirectoryContents =
this.copy(
images =
images.map {
ImageDirectoryContent(it.directory, image = block(it.directory))
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ object LoginScreenAtoms {
disabledColor = FotoColors.disabled,
radius = 15,
textAtom =
SimpleTextAtom(
textColor = FotoColors.primaryText,
typography = FotoTypography.button,
fontFamily = null,
),
SimpleTextAtom(
textColor = FotoColors.primaryText,
typography = FotoTypography.button,
fontFamily = null,
),
)
val textFieldMolecule =
OutlinedTextFieldMolecule(
Expand Down
Loading