-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract authentication and add some fragments for MainActivity
- Loading branch information
1 parent
bb1d83b
commit 5e2f6be
Showing
46 changed files
with
814 additions
and
260 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.
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
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
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
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
49 changes: 0 additions & 49 deletions
49
app/src/main/kotlin/id/shaderboi/koffie/ui/auth/VerifyFragment.kt
This file was deleted.
Oops, something went wrong.
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
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
100 changes: 100 additions & 0 deletions
100
app/src/main/kotlin/id/shaderboi/koffie/ui/auth/verify/VerifyFragment.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,100 @@ | ||
package id.shaderboi.koffie.ui.auth.verify | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.widget.doOnTextChanged | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.navigation.fragment.findNavController | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import id.shaderboi.koffie.databinding.FragmentVerifyBinding | ||
import id.shaderboi.koffie.ui.common.view_model.AuthEvent | ||
import id.shaderboi.koffie.ui.common.view_model.AuthViewModel | ||
|
||
@AndroidEntryPoint | ||
class VerifyFragment : Fragment() { | ||
private var _binding: FragmentVerifyBinding? = null | ||
val binding get() = _binding!! | ||
|
||
private val signInViewModel by activityViewModels<AuthViewModel>() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentVerifyBinding.inflate(inflater, container, false) | ||
|
||
setupView() | ||
|
||
return binding.root | ||
} | ||
|
||
private fun setupView() { | ||
binding.editTextVerificationCode1.requestFocus() | ||
binding.editTextVerificationCode1.doOnTextChanged { text, start, before, count -> | ||
if (count > 0) { | ||
binding.editTextVerificationCode2.requestFocus() | ||
} | ||
} | ||
binding.editTextVerificationCode2.doOnTextChanged { text, start, before, count -> | ||
if (count == 0) { | ||
binding.editTextVerificationCode1.requestFocus() | ||
} else { | ||
binding.editTextVerificationCode3.requestFocus() | ||
} | ||
} | ||
binding.editTextVerificationCode3.doOnTextChanged { text, start, before, count -> | ||
if (count == 0) { | ||
binding.editTextVerificationCode2.requestFocus() | ||
} else { | ||
binding.editTextVerificationCode4.requestFocus() | ||
} | ||
} | ||
binding.editTextVerificationCode4.doOnTextChanged { text, start, before, count -> | ||
if (count == 0) { | ||
binding.editTextVerificationCode3.requestFocus() | ||
} else { | ||
binding.editTextVerificationCode5.requestFocus() | ||
} | ||
} | ||
binding.editTextVerificationCode5.doOnTextChanged { text, start, before, count -> | ||
if (count == 0) { | ||
binding.editTextVerificationCode4.requestFocus() | ||
} else { | ||
binding.editTextVerificationCode6.requestFocus() | ||
} | ||
} | ||
binding.editTextVerificationCode6.doOnTextChanged { text, start, before, count -> | ||
if (count == 0) { | ||
binding.editTextVerificationCode5.requestFocus() | ||
} else { | ||
verify() | ||
} | ||
} | ||
|
||
binding.buttonVerify.setOnClickListener { | ||
verify() | ||
} | ||
} | ||
|
||
private fun verify() { | ||
val navController = findNavController() | ||
|
||
val verificationCode = binding.editTextVerificationCode1.text.toString() + | ||
binding.editTextVerificationCode2.text.toString() + | ||
binding.editTextVerificationCode3.text.toString() + | ||
binding.editTextVerificationCode4.text.toString() + | ||
binding.editTextVerificationCode5.text.toString() + | ||
binding.editTextVerificationCode6.text.toString() | ||
signInViewModel.onEvent( | ||
AuthEvent.Verify( | ||
verificationCode, | ||
requireActivity(), | ||
navController | ||
) | ||
) | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
app/src/main/kotlin/id/shaderboi/koffie/ui/auth/view_model/SignInEvent.kt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
app/src/main/kotlin/id/shaderboi/koffie/ui/common/view_model/AuthEvent.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,17 @@ | ||
package id.shaderboi.koffie.ui.common.view_model | ||
|
||
import android.app.Activity | ||
import androidx.navigation.NavController | ||
|
||
sealed class AuthEvent { | ||
class Auth(val phoneNumber: String, val activity: Activity, val onSent: () -> Unit) : | ||
AuthEvent() | ||
|
||
class Verify( | ||
val verificationCode: String, | ||
val activity: Activity, | ||
val navController: NavController | ||
) : AuthEvent() | ||
|
||
object SignOut : AuthEvent() | ||
} |
Oops, something went wrong.