File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
app/src/main/kotlin/com/byteutility/dev/leetcode/plus/ui/screens/login Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com.byteutility.dev.leetcode.plus.ui.screens.login
2
2
3
3
import android.content.Context
4
+ import android.widget.Toast
4
5
import androidx.lifecycle.ViewModel
5
6
import androidx.lifecycle.viewModelScope
6
7
import com.byteutility.dev.leetcode.plus.data.datastore.UserDatastore
@@ -31,6 +32,10 @@ class UserLoginViewModel @Inject constructor(
31
32
val loginState = _loginState .asStateFlow()
32
33
33
34
fun saveUserName (userName : String , context : Context ) {
35
+ if (userName.isEmpty()) {
36
+ Toast .makeText(context, " Username cannot be empty." , Toast .LENGTH_SHORT ).show()
37
+ return
38
+ }
34
39
viewModelScope.launch {
35
40
_loginState .value = LoginState .Loading
36
41
try {
@@ -41,8 +46,9 @@ class UserLoginViewModel @Inject constructor(
41
46
)
42
47
_loginState .value = LoginState .Success (userName)
43
48
UserDetailsSyncWorker .enqueuePeriodicWork(context)
44
- } catch (_ : Exception ) {
49
+ } catch (e : Exception ) {
45
50
_loginState .value = LoginState .Error (" Failed to retrieve user profile." )
51
+ Toast .makeText(context, " Error: ${e.message} " , Toast .LENGTH_SHORT ).show()
46
52
}
47
53
}
48
54
}
You can’t perform that action at this time.
0 commit comments