From 07a4f6bc0a9a1004f16f4426e74c56322ac3862c Mon Sep 17 00:00:00 2001 From: Rohit Jakhar Date: Wed, 30 Jun 2021 21:42:36 +0530 Subject: [PATCH] Optimise code --- app/build.gradle | 9 ++ app/src/main/AndroidManifest.xml | 11 +-- .../rohit/quizzon/data/RemoteRepository.kt | 5 +- .../quizzon/ui/fragment/PlayQuizFragment.kt | 32 +------ .../quizzon/ui/fragment/SignupFragment.kt | 79 ++++++++++------ .../quizzon/ui/viewmodels/SignUpViewModel.kt | 4 +- .../main/res/layout/fragment_play_quiz.xml | 90 +++++++++++-------- app/src/main/res/layout/fragment_signup.xml | 1 + app/src/main/res/xml/my_backup_rule.xml | 4 + gradle.properties | 5 +- 10 files changed, 130 insertions(+), 110 deletions(-) create mode 100644 app/src/main/res/xml/my_backup_rule.xml diff --git a/app/build.gradle b/app/build.gradle index d31b94a..1ff25d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,6 +9,14 @@ plugins { } android { + signingConfigs { + release { + storeFile file('/home/rohit/Documents/Quizzon/quizzonkey.jks') + storePassword storePassword + keyAlias keyAlias + keyPassword keyPassword + } + } compileSdkVersion 30 buildToolsVersion "30.0.3" @@ -22,6 +30,7 @@ android { buildConfigField("String", "USERNAME", username) buildConfigField("String", "PASSWORD", password) testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + signingConfig signingConfigs.release } buildFeatures { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c6e9b85..4f6377f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,11 +5,12 @@ - + - - - - - - + android:windowSoftInputMode="adjustResize" /> > { emit(NetworkResponse.Loading()) val response = firebaseAuth.createUserWithEmailAndPassword(email, password).await() response.user?.let { - Log.d("userImage", it.photoUrl.toString()) it.sendEmailVerification() val userProfileBody = UserProfileBody( user_id = it.uid, diff --git a/app/src/main/java/com/rohit/quizzon/ui/fragment/PlayQuizFragment.kt b/app/src/main/java/com/rohit/quizzon/ui/fragment/PlayQuizFragment.kt index 4b74668..bba7822 100644 --- a/app/src/main/java/com/rohit/quizzon/ui/fragment/PlayQuizFragment.kt +++ b/app/src/main/java/com/rohit/quizzon/ui/fragment/PlayQuizFragment.kt @@ -28,7 +28,6 @@ class PlayQuizFragment : Fragment() { private var rightAnswer = 0 private var wrongAnswer = 0 private lateinit var quizData: QuizResponse - private var selectedOptionText = "" private var isCheckedAnswer = false @SuppressLint("SetTextI18n") @@ -113,42 +112,13 @@ class PlayQuizFragment : Fragment() { private fun updateView() { loadQuestionAnimation() binding.apply { + textQuizTitle.text = quizData.quizTitle textQuestionStatement.text = quizData.questionList[currentPosition].questionStatement radioOption1.text = quizData.questionList[currentPosition].option1 radioOption2.text = quizData.questionList[currentPosition].option2 radioOption3.text = quizData.questionList[currentPosition].option3 radioOption4.text = quizData.questionList[currentPosition].option4 } -// binding.apply { -// optionChipGroup.clearCheck() -// textQuestionStatement.text = quizData.questionList[currentPosition].questionStatement -// chipOption1.text = quizData.questionList[currentPosition].option1 -// chipOption2.text = quizData.questionList[currentPosition].option2 -// chipOption3.text = quizData.questionList[currentPosition].option3 -// chipOption4.text = quizData.questionList[currentPosition].option4 -// optionChipGroup.clearCheck() -// } - } - - private fun finishQuestionAnimation() = binding.apply { - radioOption1.animate() - .alpha(0f) - .duration = 400L - radioOption2.animate() - .alpha(0f) - .duration = 400L - radioOption3.animate() - .alpha(0f) - .duration = 400L - radioOption4.animate() - .alpha(0f) - .duration = 400L - btnCheckAnswer.animate() - .alpha(0f) - .duration = 400L - textQuestionStatement.animate() - .alpha(0f) - .duration = 400L } private fun loadQuestionAnimation() = binding.apply { diff --git a/app/src/main/java/com/rohit/quizzon/ui/fragment/SignupFragment.kt b/app/src/main/java/com/rohit/quizzon/ui/fragment/SignupFragment.kt index b987307..33b1e58 100644 --- a/app/src/main/java/com/rohit/quizzon/ui/fragment/SignupFragment.kt +++ b/app/src/main/java/com/rohit/quizzon/ui/fragment/SignupFragment.kt @@ -42,49 +42,72 @@ class SignupFragment : Fragment() { savedInstanceState: Bundle? ): View { binding = FragmentSignupBinding.inflate(inflater, container, false) + initSpannableString() + initClickListener() + initView() + return binding.root + } - val signupText = resources.getString(R.string.login_line) - val spanableString = SpannableStringBuilder(signupText) + private fun initView() = binding.apply { + btnUserSignup.setDisableViews( + listOf( + userNameInputLayout, + userConfirmPasswordInputLayout, + userPasswordInputLayout, + userEmailInputLayout, + textLogin, + fabBackButton + ) + ) + } + private fun initClickListener() { + binding.btnUserSignup.setOnClickListener { + val userName = binding.userNameInputLayout.editText?.text.toString().trim() + val userEmail = binding.userEmailInputLayout.editText?.text.toString().trim() + val password = binding.userPasswordInputLayout.editText?.text.toString().trim() + val confirmPassword = + binding.userConfirmPasswordInputLayout.editText?.text.toString().trim() + if (validateUserInput( + userName, + userEmail, + password, + confirmPassword + ) + ) { + binding.btnUserSignup.activate() + signupViewModel.registerUser( + username = userName, + userEmail = userEmail, + userPassword = password + ) + checkStatus() + } else return@setOnClickListener + } + } + + private fun initSpannableString() { + val signupText = resources.getString(R.string.login_line) + val spannableStringBuilder = SpannableStringBuilder(signupText) val signUpClick = object : ClickableSpan() { override fun onClick(widget: View) { findNavController().navigate(SignupFragmentDirections.actionSignupFragmentToLoginFragment()) } } - spanableString.setSpan( + spannableStringBuilder.setSpan( signUpClick, 25, (signupText.length), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE ) - spanableString.setSpan( + spannableStringBuilder.setSpan( object : ForegroundColorSpan(Color.parseColor("#00AB5C")) {}, 25, (signupText.length), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE ) binding.textLogin.movementMethod = LinkMovementMethod.getInstance() - binding.textLogin.setText(spanableString, TextView.BufferType.SPANNABLE) - binding.btnUserSignup.setOnClickListener { - val userName = binding.userNameInputLayout.editText?.text.toString().trim() - val userEmail = binding.userEmailInputLayout.editText?.text.toString().trim() - val password = binding.userPasswordInputLayout.editText?.text.toString().trim() - val confirmPassword = - binding.userConfirmPasswordInputLayout.editText?.text.toString().trim() - if (validateUserInput( - userName, - userEmail, - password, - confirmPassword - ) - ) signupViewModel.registerUser( - username = userName, - userEmail = userEmail, - userPassword = password - ) - checkStatus() - } - return binding.root + binding.textLogin.setText(spannableStringBuilder, TextView.BufferType.SPANNABLE) } private fun checkStatus() { @@ -92,6 +115,7 @@ class SignupFragment : Fragment() { signupViewModel.registerState.collectLatest { value -> when (value) { is NetworkResponse.Success -> { + binding.btnUserSignup.finished() binding.root.snack("We sent verification link to your email") { action("Ok") { findNavController().navigate(SignupFragmentDirections.actionSignupFragmentToLoginFragment()) @@ -100,13 +124,14 @@ class SignupFragment : Fragment() { findNavController().navigate(SignupFragmentDirections.actionSignupFragmentToLoginFragment()) } is NetworkResponse.Failure -> { - binding.root.snack("We sent verification link to your email") { + binding.btnUserSignup.reset() + binding.root.snack("${value.message}") { action("Ok") { } } } is NetworkResponse.Loading -> { - // TODO show loading + binding.btnUserSignup.activate() } } } diff --git a/app/src/main/java/com/rohit/quizzon/ui/viewmodels/SignUpViewModel.kt b/app/src/main/java/com/rohit/quizzon/ui/viewmodels/SignUpViewModel.kt index 8b39c61..d474b9a 100644 --- a/app/src/main/java/com/rohit/quizzon/ui/viewmodels/SignUpViewModel.kt +++ b/app/src/main/java/com/rohit/quizzon/ui/viewmodels/SignUpViewModel.kt @@ -3,7 +3,6 @@ package com.rohit.quizzon.ui.viewmodels import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.rohit.quizzon.data.RemoteRepository -import com.rohit.quizzon.data.model.body.User import com.rohit.quizzon.data.model.response.DataInsertResponse import com.rohit.quizzon.utils.NetworkResponse import dagger.hilt.android.lifecycle.HiltViewModel @@ -29,8 +28,7 @@ class SignUpViewModel @Inject constructor( remoteRepository.registerUser( username = username, email = userEmail, - password = userPassword, - gender = "Male" + password = userPassword ).collect { status -> _registerState.value = status } diff --git a/app/src/main/res/layout/fragment_play_quiz.xml b/app/src/main/res/layout/fragment_play_quiz.xml index b2daf41..37ab774 100644 --- a/app/src/main/res/layout/fragment_play_quiz.xml +++ b/app/src/main/res/layout/fragment_play_quiz.xml @@ -9,16 +9,15 @@ + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/cvQuizTitle"> + + + + - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_signup.xml b/app/src/main/res/layout/fragment_signup.xml index b8ba7f7..d99a85d 100644 --- a/app/src/main/res/layout/fragment_signup.xml +++ b/app/src/main/res/layout/fragment_signup.xml @@ -151,6 +151,7 @@ android:layout_marginStart="16dp" android:layout_marginEnd="16dp" app:default_text="@string/sign_up" + app:finish_text="Account Created!" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/userConfirmPasswordInputLayout" /> diff --git a/app/src/main/res/xml/my_backup_rule.xml b/app/src/main/res/xml/my_backup_rule.xml new file mode 100644 index 0000000..bfa7569 --- /dev/null +++ b/app/src/main/res/xml/my_backup_rule.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e3dc282..00554ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,7 @@ android.useAndroidX=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official username="HB_QUIZ_ADMIN" -password="Rohit@940" \ No newline at end of file +password="Rohit@940" +storePassword="Z3DRZX7VpWjLnG35" +keyPassword="Z3DRZX7VpWjLnG35" +keyAlias="key1" \ No newline at end of file