@@ -25,13 +25,21 @@ class FirstStartDialogFragment : DialogFragment() {
25
25
override fun onTabSelected (tab : TabLayout .Tab ) {
26
26
when (tab.position) {
27
27
POSITION_SIGNUP -> {
28
- binding.layoutSignIn.isVisible = false
29
28
binding.layoutSignUp.isVisible = true
29
+ binding.layoutSignIn.isVisible = false
30
+ binding.layoutSignInByCode.isVisible = false
30
31
}
31
32
32
33
POSITION_SIGNIN -> {
34
+ binding.layoutSignUp.isVisible = false
33
35
binding.layoutSignIn.isVisible = true
36
+ binding.layoutSignInByCode.isVisible = false
37
+ }
38
+
39
+ POSITION_SIGNIN_BY_CODE -> {
34
40
binding.layoutSignUp.isVisible = false
41
+ binding.layoutSignIn.isVisible = false
42
+ binding.layoutSignInByCode.isVisible = true
35
43
}
36
44
}
37
45
}
@@ -47,6 +55,7 @@ class FirstStartDialogFragment : DialogFragment() {
47
55
when (binding.tabLayout.selectedTabPosition) {
48
56
POSITION_SIGNUP -> actionSignUp()
49
57
POSITION_SIGNIN -> actionSignIn()
58
+ POSITION_SIGNIN_BY_CODE -> actionSignInByCode()
50
59
}
51
60
}
52
61
@@ -67,6 +76,16 @@ class FirstStartDialogFragment : DialogFragment() {
67
76
super .onDestroyView()
68
77
}
69
78
79
+ private fun actionSignUp () {
80
+ setFragmentResult(
81
+ REQUEST_KEY ,
82
+ Bundle ().apply {
83
+ putString(KEY_RESULT_CODE , Result .SignUp .name)
84
+ }
85
+ )
86
+ dismiss()
87
+ }
88
+
70
89
private fun actionSignIn () {
71
90
val username = binding.editUsername.text.toString()
72
91
val password = binding.editPassword.text.toString()
@@ -95,11 +114,21 @@ class FirstStartDialogFragment : DialogFragment() {
95
114
dismiss()
96
115
}
97
116
98
- private fun actionSignUp () {
117
+ private fun actionSignInByCode () {
118
+ val code = binding.editCode.text.toString()
119
+
120
+ binding.editCodeLayout.error = null
121
+
122
+ if (code.isEmpty()) {
123
+ binding.editCodeLayout.error = " Required"
124
+ return
125
+ }
126
+
99
127
setFragmentResult(
100
128
REQUEST_KEY ,
101
129
Bundle ().apply {
102
- putString(KEY_RESULT_CODE , Result .SignUp .name)
130
+ putString(KEY_RESULT_CODE , Result .SignInByCode .name)
131
+ putString(KEY_CODE , code)
103
132
}
104
133
)
105
134
dismiss()
@@ -117,19 +146,22 @@ class FirstStartDialogFragment : DialogFragment() {
117
146
118
147
enum class Result {
119
148
Canceled ,
120
- SignIn ,
121
149
SignUp ,
150
+ SignIn ,
151
+ SignInByCode ,
122
152
}
123
153
124
154
companion object {
125
155
const val REQUEST_KEY = " FirstStartDialogFragment"
126
156
127
157
private const val POSITION_SIGNUP = 0
128
158
private const val POSITION_SIGNIN = 1
159
+ private const val POSITION_SIGNIN_BY_CODE = 2
129
160
130
161
private const val KEY_RESULT_CODE = " result_code"
131
162
private const val KEY_USERNAME = " username"
132
163
private const val KEY_PASSWORD = " password"
164
+ private const val KEY_CODE = " code"
133
165
134
166
fun newInstance (): FirstStartDialogFragment = FirstStartDialogFragment ()
135
167
@@ -138,5 +170,7 @@ class FirstStartDialogFragment : DialogFragment() {
138
170
139
171
fun getUsername (data : Bundle ): String = requireNotNull(data.getString(KEY_USERNAME ))
140
172
fun getPassword (data : Bundle ): String = requireNotNull(data.getString(KEY_PASSWORD ))
173
+
174
+ fun getCode (data : Bundle ): String = requireNotNull(data.getString(KEY_CODE ))
141
175
}
142
176
}
0 commit comments