-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix api version, add basic architecture structure
- Loading branch information
Showing
14 changed files
with
132 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ork/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.stslex.aproselection.core.network.clients.auth | ||
|
||
import com.stslex.aproselection.core.network.clients.auth.model.HelloRequestModel | ||
|
||
interface AuthNetworkClient { | ||
|
||
suspend fun getHello(): HelloRequestModel | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClientImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.stslex.aproselection.core.network.clients.auth | ||
|
||
import com.stslex.aproselection.core.network.client.NetworkClient | ||
import com.stslex.aproselection.core.network.clients.auth.model.HelloRequestModel | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.http.appendPathSegments | ||
|
||
class AuthNetworkClientImpl( | ||
private val networkClient: NetworkClient | ||
) : AuthNetworkClient { | ||
|
||
override suspend fun getHello(): HelloRequestModel = networkClient | ||
.apiClient | ||
.get { | ||
url.appendPathSegments("hello") | ||
} | ||
.body() | ||
} |
10 changes: 10 additions & 0 deletions
10
...c/main/java/com/stslex/aproselection/core/network/clients/auth/model/HelloRequestModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.stslex.aproselection.core.network.clients.auth.model | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class HelloRequestModel( | ||
@SerialName("text") | ||
val text: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
core/ui/src/main/java/com/stslex/aproselection/core/ui/base/BaseViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.stslex.aproselection.core.ui.base | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.stateIn | ||
|
||
open class BaseViewModel : ViewModel() { | ||
|
||
fun <T> Flow<T>.stateIn( | ||
initialValue: T | ||
): StateFlow<T> = this.stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.Lazily, | ||
initialValue = initialValue | ||
) | ||
|
||
fun handleError(throwable: Throwable) { | ||
Log.e(javaClass.simpleName, throwable.message, throwable) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
plugins { | ||
id("aproselection.android.library") | ||
id("aproselection.android.library.compose") | ||
kotlin("plugin.serialization") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":core:ui")) | ||
implementation(project(":core:network")) | ||
implementation(libs.bundles.ktor) | ||
implementation(libs.bundles.okhttp) | ||
} | ||
|
||
android.namespace = "com.stslex.aproselection.feature.auth" |
8 changes: 8 additions & 0 deletions
8
...uth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.stslex.aproselection.feature.auth.data.repository | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface AuthRepository { | ||
|
||
val hello: Flow<String> | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.stslex.aproselection.feature.auth.data.repository | ||
|
||
import com.stslex.aproselection.core.network.clients.auth.AuthNetworkClient | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
|
||
class AuthRepositoryImpl( | ||
private val networkClient: AuthNetworkClient | ||
) : AuthRepository { | ||
|
||
override val hello: Flow<String> = flow { | ||
val helloResponse = networkClient.getHello().text | ||
emit(helloResponse) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
feature/auth/src/main/java/com/stslex/aproselection/feature/auth/di/ModuleFeatureAuth.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package com.stslex.aproselection.feature.auth.di | ||
|
||
import com.stslex.aproselection.feature.auth.data.repository.AuthRepository | ||
import com.stslex.aproselection.feature.auth.data.repository.AuthRepositoryImpl | ||
import com.stslex.aproselection.feature.auth.domain.interactor.AuthInteractor | ||
import com.stslex.aproselection.feature.auth.domain.interactor.AuthInteractorImpl | ||
import com.stslex.aproselection.feature.auth.ui.AuthViewModel | ||
import org.koin.androidx.viewmodel.dsl.viewModelOf | ||
import org.koin.core.module.dsl.bind | ||
import org.koin.core.module.dsl.factoryOf | ||
import org.koin.dsl.module | ||
|
||
object ModuleFeatureAuth { | ||
|
||
val moduleFeatureAuth = module { | ||
viewModelOf(::AuthViewModel) | ||
factoryOf(::AuthInteractorImpl) { bind<AuthInteractor>() } | ||
factoryOf(::AuthRepositoryImpl) { bind<AuthRepository>() } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...h/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.stslex.aproselection.feature.auth.domain.interactor | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface AuthInteractor { | ||
|
||
val hello: Flow<String> | ||
} |
12 changes: 12 additions & 0 deletions
12
...c/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.stslex.aproselection.feature.auth.domain.interactor | ||
|
||
import com.stslex.aproselection.feature.auth.data.repository.AuthRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class AuthInteractorImpl( | ||
private val repository: AuthRepository | ||
) : AuthInteractor { | ||
|
||
override val hello: Flow<String> | ||
get() = repository.hello | ||
} |
40 changes: 9 additions & 31 deletions
40
feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,19 @@ | ||
package com.stslex.aproselection.feature.auth.ui | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.stslex.aproselection.core.network.client.NetworkClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.http.appendPathSegments | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import com.stslex.aproselection.core.ui.base.BaseViewModel | ||
import com.stslex.aproselection.feature.auth.domain.interactor.AuthInteractor | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.stateIn | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
class AuthViewModel( | ||
private val networkClient: NetworkClient | ||
) : ViewModel() { | ||
private val interactor: AuthInteractor | ||
) : BaseViewModel() { | ||
|
||
val text: StateFlow<String> | ||
get() = flow { | ||
val result = networkClient.apiClient.get { | ||
url.appendPathSegments("hello") | ||
get() = interactor | ||
.hello | ||
.catch { throwable -> | ||
handleError(throwable) | ||
} | ||
.body<HelloRequest>() | ||
.hello | ||
emit(result) | ||
} | ||
.catch { | ||
Log.e(javaClass.simpleName, it.message, it) | ||
} | ||
.stateIn(viewModelScope, SharingStarted.Lazily, "") | ||
.stateIn("") | ||
} | ||
|
||
@Serializable | ||
data class HelloRequest( | ||
@SerialName("text") | ||
val hello: String | ||
) |