-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement: simple LoginPage, LoginViewModel, LoginUseCase
- Loading branch information
1 parent
f1ee4bd
commit 5c46289
Showing
8 changed files
with
156 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
android/app/src/main/java/com/goliath/emojihub/usecases/LoginUseCase.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,16 @@ | ||
package com.goliath.emojihub.usecases | ||
|
||
import com.goliath.emojihub.models.User | ||
import com.goliath.emojihub.models.UserDto | ||
import com.goliath.emojihub.viewmodels.Resource | ||
|
||
class LoginUseCase { | ||
fun login(username: String, password: String): Resource<User>? { | ||
val dummyUser = User(UserDto( | ||
userId = "1", | ||
likedEmojiList = arrayOf(), | ||
createdEmojiList = arrayOf() | ||
)) | ||
return Resource.Success(dummyUser); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
android/app/src/main/java/com/goliath/emojihub/viewmodels/LoginViewModel.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,30 @@ | ||
package com.goliath.emojihub.viewmodels | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.goliath.emojihub.models.User | ||
import com.goliath.emojihub.usecases.LoginUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class LoginViewModel @Inject constructor( | ||
private val loginUseCase: LoginUseCase | ||
) { | ||
|
||
private val _loginState = MutableLiveData<Resource<User>>() | ||
val loginState: LiveData<Resource<User>> = _loginState | ||
|
||
fun onLoginClicked(username: String, password: String) { | ||
_loginState.value = loginUseCase.login(username, password) // Hand | ||
} | ||
} | ||
|
||
sealed class Resource<out T> { | ||
object Loading : Resource<Nothing>() | ||
open class Success<out T>(val data: T) : Resource<T>() | ||
open class Error(val exception: Throwable) : Resource<Nothing>() | ||
} |
67 changes: 67 additions & 0 deletions
67
android/app/src/main/java/com/goliath/emojihub/views/LoginPage.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,67 @@ | ||
package com.goliath.emojihub.views | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextField | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun PreviewLoginView() { | ||
LoginPage(onLoginClicked = { _, _ -> }, | ||
onCreateAccountClicked = {}) | ||
} | ||
|
||
@Composable | ||
fun LoginPage( | ||
onLoginClicked: (String, String) -> Unit, | ||
onCreateAccountClicked: () -> Unit | ||
) { | ||
var username by remember { mutableStateOf("") } | ||
var password by remember { mutableStateOf("") } | ||
|
||
// Your UI components here | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(all = 16.dp) | ||
) { | ||
Text("EmojiHub") | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
TextField( | ||
value = username, | ||
onValueChange = { username = it }, | ||
label = { Text("Username") } | ||
) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
TextField( | ||
value = password, | ||
onValueChange = { password = it }, | ||
label = { Text("Password") } | ||
) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
Button( | ||
onClick = { onLoginClicked(username, password) } | ||
) { | ||
Text("로그인") | ||
} | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
Button( | ||
onClick = { onCreateAccountClicked() } | ||
) { | ||
Text("계정 생성") | ||
} | ||
} | ||
} |