Skip to content

Commit 3756272

Browse files
committed
login response type 추가및 progress bar 처리 완료
1 parent 3b6fba3 commit 3756272

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

app/src/main/java/com/ddd/attendance/check/db/entity/User.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class User(
99
@PrimaryKey val id: Int,
1010
@ColumnInfo(name = "name") val name: String,
1111
@ColumnInfo(name = "account") val account: String,
12+
@ColumnInfo(name = "type") val type: Int,
1213
@ColumnInfo(name = "accessToken") val accessToken: String,
1314
@ColumnInfo(name = "refreshToken") val refreshToken: String
1415
)

app/src/main/java/com/ddd/attendance/check/model/LoginReponse.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ data class LoginResponse(
1111
data class User(
1212
val account: String,
1313
val id: Int,
14-
val name: String
14+
val name: String,
15+
val type: Int
1516
)

app/src/main/java/com/ddd/attendance/check/vm/LoginViewModel.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.ddd.attendance.check.vm
22

33
import androidx.databinding.ObservableField
44
import androidx.lifecycle.LiveData
5-
import androidx.lifecycle.MutableLiveData
65
import androidx.lifecycle.ViewModel
76
import com.ddd.attendance.check.common.NetworkHelper
87
import com.ddd.attendance.check.common.NetworkHelper.SUCCESS
@@ -19,13 +18,14 @@ class LoginViewModel @Inject constructor(
1918
private val loginRepository: LoginRepository,
2019
private val userRepository: UserRepository
2120
) : ViewModel() {
22-
23-
private val _error = MutableLiveData<String>()
24-
private val _btnEnableLogin = MutableLiveData<Boolean>()
21+
private val _progressbar = SingleLiveEvent<Boolean>()
22+
private val _error = SingleLiveEvent<String>()
23+
private val _btnEnableLogin = SingleLiveEvent<Boolean>()
2524
private val _startActivity = SingleLiveEvent<Class<MainActivity>>()
2625

2726
val editID = ObservableField<String>()
2827
val editPW = ObservableField<String>()
28+
val progressbar: LiveData<Boolean> get() = _progressbar
2929
val btnEnableLogin: LiveData<Boolean> get() = _btnEnableLogin
3030
val error: LiveData<String> get() = _error
3131
val startActivity: LiveData<Class<MainActivity>> get() = _startActivity
@@ -45,8 +45,10 @@ class LoginViewModel @Inject constructor(
4545
}
4646

4747
fun login() {
48+
_progressbar.value = true
4849
GlobalScope.launch {
4950
try {
51+
_progressbar.postValue(false)
5052
val response = loginRepository.login(editID.get() ?: EMPTY_ID, editPW.get()
5153
?: EMPTY_PW)
5254
response.body()?.let { result ->
@@ -56,6 +58,7 @@ class LoginViewModel @Inject constructor(
5658
result.user.id,
5759
result.user.name,
5860
result.user.account,
61+
result.user.type,
5962
result.accessToken,
6063
result.refreshToken
6164
)
@@ -66,6 +69,7 @@ class LoginViewModel @Inject constructor(
6669
}
6770
}
6871
} catch (throwable: Throwable) {
72+
_progressbar.postValue(false)
6973
_error.postValue(NetworkHelper.ERROR_MSG)
7074
}
7175
}

app/src/main/res/layout/activity_login.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
33
<data>
4+
<import type="android.view.View"/>
45
<variable name="loginViewModel" type="com.ddd.attendance.check.vm.LoginViewModel"/>
56
</data>
67

@@ -13,7 +14,14 @@
1314
android:paddingStart="35dp"
1415
android:paddingEnd="35dp"
1516
tools:context=".ui.LoginActivity">
16-
17+
<ProgressBar
18+
android:visibility="@{loginViewModel.progressbar? View.VISIBLE : View.GONE}"
19+
android:layout_width="wrap_content"
20+
app:layout_constraintBottom_toBottomOf="parent"
21+
app:layout_constraintTop_toTopOf="parent"
22+
app:layout_constraintRight_toRightOf="parent"
23+
app:layout_constraintLeft_toLeftOf="parent"
24+
android:layout_height="wrap_content"/>
1725
<TextView
1826
android:id="@+id/tvSpecialTitle"
1927
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)