@@ -29,13 +29,15 @@ class MainViewModel @Inject constructor(
2929 private val _isAttendanceStart = MutableLiveData <Boolean >()
3030 private val _btnEnableLogin = MutableLiveData <Boolean >()
3131 private val _showToastError = MutableLiveData <String >()
32+ private val _isProgressbar = MutableLiveData <Boolean >()
3233
3334 val isAdmin: LiveData <Boolean > = _isAdmin
3435 val isAttendanceNumber: LiveData <Int > = _isAttendanceNumber
3536 val isAttendanceStart: LiveData <Boolean > = _isAttendanceStart
3637 val editNumberAttendance = ObservableField <String >()
3738 val btnEnableAttendance: LiveData <Boolean > get() = _btnEnableLogin
3839 val showToastError: LiveData <String > get() = _showToastError
40+ val progressbar: LiveData <Boolean > = _isProgressbar
3941
4042 val showDDDDialog = SingleLiveEvent <Pair <UserType , String >>()
4143 val expireToken = SingleLiveEvent <String >()
@@ -98,46 +100,45 @@ class MainViewModel @Inject constructor(
98100
99101 // 출석 버튼 클릭
100102 fun attendance () {
103+ _isProgressbar .value = true
101104 GlobalScope .launch {
102105 try {
103106 if (isAdmin.value == true ) {
104107 if (_isAttendanceStart .value == null || _isAttendanceStart .value == false ) attendanceStart()
105108 else attendanceEnd()
106109 } else attendanceCheck()
107110 } catch (e: IOException ) {
111+ _isProgressbar .postValue(false )
108112 _showToastError .postValue(MSG_ATTENDANCE_END )
109113 }
110114 }
111115 }
112116 // 관리자 출첵 시작
113117 private suspend fun attendanceStart () {
114118 val response = attendanceRepository.attendanceStart()
119+ _isProgressbar .postValue(false )
115120 if (response.isSuccessful) attendanceStartUI(response.body())
116121 else errorParsingDialog(response.errorBody()?.string())
122+
117123 }
118124
119125 // 관리자 출첵 종료
120126 private suspend fun attendanceEnd () {
121127 val response = attendanceRepository.attendsEnd()
128+ _isProgressbar .postValue(false )
122129 if (response.isSuccessful) {
123130 attendanceEndUI()
124131 } else _showToastError .postValue(MSG_ALREADY_START )
125132 }
126133
127134 // 일반 팀원 출첵
128135 private suspend fun attendanceCheck () {
129- GlobalScope .launch {
130- try {
131- val response = attendanceRepository.attendanceCheck(
132- userRepository.getUsers()[0 ].id.toString(),
133- editNumberAttendance.get() ? : " "
134- )
135- if (response.isSuccessful) showDDDDialog(MSG_ATTENDANCE_SUCCESS )
136- else errorParsingDialog(response.errorBody()?.string())
137- } catch (e: Exception ) {
138- e.printStackTrace()
139- }
140- }
136+ val response = attendanceRepository.attendanceCheck(
137+ userRepository.getUsers()[0 ].id.toString(), editNumberAttendance.get() ? : " "
138+ )
139+ _isProgressbar .postValue(false )
140+ if (response.isSuccessful) showDDDDialog(MSG_ATTENDANCE_SUCCESS )
141+ else errorParsingDialog(response.errorBody()?.string())
141142 }
142143
143144 // 토큰 리프레시
@@ -146,6 +147,7 @@ class MainViewModel @Inject constructor(
146147 try {
147148 val user = userRepository.getUsers()[0 ]
148149 val response = userRepository.refreshToken(user.refreshToken)
150+ _isProgressbar .postValue(false )
149151 if (response.isSuccessful) {
150152 val body = response.body()
151153 userRepository.saveUsers(
@@ -163,6 +165,7 @@ class MainViewModel @Inject constructor(
163165 expireToken.postValue(MSG_LOG_OUT )
164166 }
165167 } catch (e: Exception ) {
168+ _isProgressbar .postValue(false )
166169 e.printStackTrace()
167170 }
168171 }
0 commit comments