feat: Implement setup screen and login logic

- Add SetupScreen with UI for server URL, username, and password input.
- Make SetupScreen the initial screen in the navigation graph.
- Implement secure credential storage using EncryptedSharedPreferences.
- Create CredentialsRepository and AuthRepository to manage credentials and auth tokens.
- Add LoginUseCase to handle the business logic for logging in.
- Implement a temporary Retrofit client in ItemRepository to handle login against a user-provided URL.
- Integrate login logic into SetupViewModel.
- Update all relevant project documentation and DI modules.
This commit is contained in:
2025-08-08 20:17:50 +03:00
parent 01e9b7bb00
commit 2853b5a47e
23 changed files with 602 additions and 23 deletions

View File

@@ -0,0 +1,18 @@
// [PACKAGE] com.homebox.lens.domain.model
// [FILE] Credentials.kt
package com.homebox.lens.domain.model
/**
* [CONTRACT]
* Data class to hold server credentials.
* @property serverUrl The URL of the Homebox server.
* @property username The username for authentication.
* @property password The password for authentication.
*/
data class Credentials(
val serverUrl: String,
val username: String,
val password: String
)
// [END_FILE_Credentials.kt]

View File

@@ -0,0 +1,27 @@
// [PACKAGE] com.homebox.lens.domain.repository
// [FILE] AuthRepository.kt
package com.homebox.lens.domain.repository
import kotlinx.coroutines.flow.Flow
/**
* [CONTRACT]
* Repository for managing authentication tokens.
*/
interface AuthRepository {
/**
* [CONTRACT]
* Saves the authentication token.
* @param token The token to save.
*/
suspend fun saveToken(token: String)
/**
* [CONTRACT]
* Retrieves the authentication token.
* @return A Flow emitting the token, or null if not found.
*/
fun getToken(): Flow<String?>
}
// [END_FILE_AuthRepository.kt]

View File

@@ -0,0 +1,28 @@
// [PACKAGE] com.homebox.lens.domain.repository
// [FILE] CredentialsRepository.kt
package com.homebox.lens.domain.repository
import com.homebox.lens.domain.model.Credentials
import kotlinx.coroutines.flow.Flow
/**
* [CONTRACT]
* Repository for managing user credentials.
*/
interface CredentialsRepository {
/**
* [CONTRACT]
* Saves the user credentials securely.
* @param credentials The credentials to save.
*/
suspend fun saveCredentials(credentials: Credentials)
/**
* [CONTRACT]
* Retrieves the saved user credentials.
* @return A Flow emitting the saved [Credentials], or null if none are saved.
*/
fun getCredentials(): Flow<Credentials?>
}
// [END_FILE_CredentialsRepository.kt]

View File

@@ -12,6 +12,7 @@ import com.homebox.lens.domain.model.*
* Определяет контракт, которому должен следовать слой данных.
*/
interface ItemRepository {
suspend fun login(credentials: Credentials): Result<Unit>
suspend fun createItem(newItemData: ItemCreate): ItemSummary
suspend fun getItemDetails(itemId: String): ItemOut
suspend fun updateItem(itemId: String, item: ItemUpdate): ItemOut

View File

@@ -0,0 +1,29 @@
// [PACKAGE] com.homebox.lens.domain.usecase
// [FILE] LoginUseCase.kt
package com.homebox.lens.domain.usecase
import com.homebox.lens.domain.model.Credentials
import com.homebox.lens.domain.repository.ItemRepository
import javax.inject.Inject
import com.homebox.lens.domain.model.Result
/**
* [CONTRACT]
* Use case for user login.
* @param itemRepository The repository to handle item and auth operations.
*/
class LoginUseCase @Inject constructor(
private val itemRepository: ItemRepository
) {
/**
* [CONTRACT]
* Executes the login process.
* @param credentials The user's credentials.
* @return A [Result] object indicating success or failure.
*/
suspend operator fun invoke(credentials: Credentials): Result<Unit> {
return itemRepository.login(credentials)
}
}
// [END_FILE_LoginUseCase.kt]