2635 | Reyaz | Make dob field as per business requirement
This commit is contained in:
@@ -95,6 +95,7 @@ dependencies {
|
||||
|
||||
// for firebase push notification
|
||||
implementation 'com.google.firebase:firebase-messaging:20.1.0'
|
||||
implementation group: 'joda-time', name: 'joda-time', version: '2.10.5'
|
||||
|
||||
// AndroidJUnitRunner and JUnit Rules
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
|
||||
@@ -41,4 +41,9 @@ object Constants {
|
||||
const val API_POLL_RETRY_COUNT_SECONDS = 2
|
||||
const val FCM_UPDATE_PERIOD = 24 * 60 * 60 * 1000 // 24 hrs in milli seconds
|
||||
const val ZIP_CODE_LENGTH = 6
|
||||
|
||||
const val DATE_FORMAT = "dd/MM/yyyy"
|
||||
const val DAY_OF_MONTH_FORMAT = "d"
|
||||
const val MONTH_OF_YEAR_FORMAT = "MMMM"
|
||||
const val YEAR_FORMAT = "yyyy"
|
||||
}
|
||||
@@ -84,4 +84,14 @@ fun toggleKeyboard(context: Context) {
|
||||
|
||||
fun dpToPx(inpDp: Int): Int {
|
||||
return (inpDp * Resources.getSystem().displayMetrics.density).toInt()
|
||||
}
|
||||
|
||||
fun String.getOrdinal(): String {
|
||||
val number = this.toInt()
|
||||
val suffixes =
|
||||
arrayOf("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")
|
||||
return when (number % 100) {
|
||||
11, 12, 13 -> this + "th"
|
||||
else -> this + suffixes[number % 10]
|
||||
}
|
||||
}
|
||||
112
app/src/main/java/com/navi/welcomejourney/custom/DobEditText.kt
Normal file
112
app/src/main/java/com/navi/welcomejourney/custom/DobEditText.kt
Normal file
@@ -0,0 +1,112 @@
|
||||
package com.navi.welcomejourney.custom
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import com.navi.R
|
||||
import com.navi.databinding.DobActionViewLayoutBinding
|
||||
import com.navi.utils.Constants
|
||||
import com.navi.utils.Constants.DATE_FORMAT
|
||||
import com.navi.utils.Constants.DAY_OF_MONTH_FORMAT
|
||||
import com.navi.utils.Constants.MONTH_OF_YEAR_FORMAT
|
||||
import com.navi.utils.Constants.YEAR_FORMAT
|
||||
import com.navi.utils.getOrdinal
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
|
||||
class DobActionView(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs) {
|
||||
private val binding: DobActionViewLayoutBinding
|
||||
private var outputTextView: TextView? = null
|
||||
|
||||
init {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.dob_action_view_layout, this, true)
|
||||
initListeners()
|
||||
}
|
||||
|
||||
fun attachOutputTextView(textView: TextView) {
|
||||
this.outputTextView = textView
|
||||
}
|
||||
|
||||
fun setError() {
|
||||
binding.dateEt.setErrorWithoutIcon()
|
||||
binding.monthEt.setErrorWithoutIcon()
|
||||
binding.yearEt.setErrorWithoutIcon()
|
||||
}
|
||||
|
||||
private fun setDateToOutput() {
|
||||
try {
|
||||
var date =
|
||||
if (binding.dateEt.text.toString().length == DAY_LENGTH) binding.dateEt.text.toString() else SAMPLE_DATE
|
||||
var month =
|
||||
if (binding.monthEt.text.toString().length == MONTH_LENGTH) binding.monthEt.text.toString() else SAMPLE_MONTH
|
||||
var year =
|
||||
if (binding.yearEt.text.toString().length == YEAR_LENGTH) binding.yearEt.text.toString() else SAMPLE_YEAR
|
||||
val dateTime =
|
||||
DateTime.parse("${date}/$month/$year", DateTimeFormat.forPattern(DATE_FORMAT))
|
||||
date =
|
||||
if (binding.dateEt.text.toString().length == DAY_LENGTH) dateTime.toString(
|
||||
DAY_OF_MONTH_FORMAT
|
||||
).getOrdinal() else Constants.EMPTY
|
||||
month =
|
||||
if (binding.monthEt.text.toString().length == MONTH_LENGTH) dateTime.toString(
|
||||
MONTH_OF_YEAR_FORMAT
|
||||
) else Constants.EMPTY
|
||||
year =
|
||||
if (binding.yearEt.text.toString().length == YEAR_LENGTH) dateTime.toString(
|
||||
YEAR_FORMAT
|
||||
) else Constants.EMPTY
|
||||
outputTextView?.text = context.getString(R.string.date_format, date, month, year)
|
||||
} catch (ex: Exception) {
|
||||
outputTextView?.text = context.getString(R.string.wrong_date)
|
||||
}
|
||||
}
|
||||
|
||||
fun isFilledCorrectly() =
|
||||
binding.dateEt.text.toString().length == DAY_LENGTH
|
||||
&& binding.monthEt.text.length == MONTH_LENGTH
|
||||
&& binding.yearEt.text.length == YEAR_LENGTH
|
||||
&& outputTextView?.text != context.getString(R.string.wrong_date)
|
||||
|
||||
private fun initListeners() {
|
||||
binding.dateEt.addTextChangedListener {
|
||||
if (it?.length == DAY_LENGTH) {
|
||||
binding.monthEt.requestFocus()
|
||||
}
|
||||
setDateToOutput()
|
||||
}
|
||||
binding.monthEt.addTextChangedListener {
|
||||
if (it?.length == MONTH_LENGTH) {
|
||||
binding.yearEt.requestFocus()
|
||||
} else if (it?.length == 0) {
|
||||
binding.dateEt.requestFocus()
|
||||
}
|
||||
setDateToOutput()
|
||||
}
|
||||
binding.yearEt.addTextChangedListener {
|
||||
if (it?.length == 0) {
|
||||
binding.monthEt.requestFocus()
|
||||
}
|
||||
setDateToOutput()
|
||||
}
|
||||
}
|
||||
|
||||
fun setDependentFormTextView(formTextView: FormTextView) {
|
||||
binding.dateEt.setDependentFormTextView(formTextView)
|
||||
binding.monthEt.setDependentFormTextView(formTextView)
|
||||
binding.yearEt.setDependentFormTextView(formTextView)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DAY_LENGTH = 2
|
||||
private const val MONTH_LENGTH = 2
|
||||
private const val YEAR_LENGTH = 4
|
||||
private const val SAMPLE_DATE = "06"
|
||||
private const val SAMPLE_MONTH = "05"
|
||||
private const val SAMPLE_YEAR = "1985"
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,11 @@ class FormEditText(context: Context, attrs: AttributeSet) : EditText(context, at
|
||||
formTextView?.setError()
|
||||
}
|
||||
|
||||
fun setErrorWithoutIcon() {
|
||||
backgroundTintList = ColorStateList.valueOf(context.resources.getColor(R.color.red))
|
||||
formTextView?.setError()
|
||||
}
|
||||
|
||||
fun setDependentFormTextView(formTextView: FormTextView) {
|
||||
this.formTextView = formTextView
|
||||
}
|
||||
|
||||
@@ -30,12 +30,14 @@ class CreateYourProfileFragment : BaseFragment(), View.OnClickListener {
|
||||
binding.fullNameLayout.lastNameEt.setDependentFormTextView(binding.fullNameLayout.fullNameTag)
|
||||
binding.emailLayout.personalEmailIdEt.setDependentFormTextView(binding.emailLayout.personalEmailIdTag)
|
||||
binding.dobLayout.dobEt.setDependentFormTextView(binding.dobLayout.dobTag)
|
||||
binding.dobLayout.dobEt.attachOutputTextView(binding.dobLayout.dobOutputTv)
|
||||
binding.genderLayout.genderRadio.setDependentFormTextView(binding.genderLayout.genderTag)
|
||||
binding.pincodeLayout.pincodeEt.setDependentFormTextView(binding.pincodeLayout.pincodeTag)
|
||||
}
|
||||
|
||||
private fun initUi() {
|
||||
binding.doneBtn.setProperties(getString(R.string.done))
|
||||
binding.dobLayout
|
||||
}
|
||||
|
||||
private fun submitProfileDetails() {
|
||||
@@ -58,7 +60,7 @@ class CreateYourProfileFragment : BaseFragment(), View.OnClickListener {
|
||||
binding.fullNameLayout.lastNameEt.setError()
|
||||
validated = false
|
||||
}
|
||||
if (binding.dobLayout.dobEt.text.toString().isBlank()) {
|
||||
if (binding.dobLayout.dobEt.isFilledCorrectly().not()) {
|
||||
binding.dobLayout.dobEt.setError()
|
||||
validated = false
|
||||
}
|
||||
|
||||
51
app/src/main/res/layout/dob_action_view_layout.xml
Normal file
51
app/src/main/res/layout/dob_action_view_layout.xml
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/date_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/layout_dp_12"
|
||||
android:backgroundTint="@color/black"
|
||||
android:ems="2"
|
||||
android:hint="@string/dd"
|
||||
android:inputType="number"
|
||||
android:maxLength="2"
|
||||
android:textAlignment="center"
|
||||
tools:ignore="TextFields" />
|
||||
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/month_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/layout_dp_12"
|
||||
android:layout_toEndOf="@id/date_et"
|
||||
android:backgroundTint="@color/black"
|
||||
android:ems="2"
|
||||
android:hint="@string/mm"
|
||||
android:inputType="number"
|
||||
android:maxLength="2"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/year_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/layout_dp_12"
|
||||
android:layout_toEndOf="@id/month_et"
|
||||
android:backgroundTint="@color/black"
|
||||
android:ems="4"
|
||||
android:hint="@string/yyyy"
|
||||
android:inputType="number"
|
||||
android:maxLength="4"
|
||||
android:textAlignment="center" />
|
||||
</RelativeLayout>
|
||||
</layout>
|
||||
@@ -28,7 +28,7 @@
|
||||
app:layout_constraintStart_toEndOf="@id/dob_iv"
|
||||
app:layout_constraintTop_toTopOf="@id/dob_iv" />
|
||||
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
<com.navi.welcomejourney.custom.DobActionView
|
||||
android:id="@+id/dob_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="0dp"
|
||||
@@ -40,5 +40,16 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@id/dob_tag"
|
||||
app:layout_constraintTop_toBottomOf="@id/dob_tag" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dob_output_tv"
|
||||
style="@style/CaptionFontStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/layout_dp_6"
|
||||
android:text="@string/dob_example"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@id/dob_et"
|
||||
app:layout_constraintTop_toBottomOf="@id/dob_et" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
@@ -34,6 +34,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/layout_dp_12"
|
||||
android:hint="@string/email"
|
||||
android:backgroundTint="@color/black"
|
||||
android:inputType="textEmailAddress"
|
||||
android:letterSpacing="0.03"
|
||||
|
||||
@@ -256,5 +256,10 @@
|
||||
<string name="pincode_of_current_residence_address">Pincode of current residence address</string>
|
||||
<string name="eg_560075">eg: 560075</string>
|
||||
<string name="done">Done</string>
|
||||
|
||||
<string name="dob_example">For 6th May’1985, type 06/05/85</string>
|
||||
<string name="dd">dd</string>
|
||||
<string name="mm">mm</string>
|
||||
<string name="yyyy">yyyy</string>
|
||||
<string name="wrong_date">Wrong date</string>
|
||||
<string name="date_format">%1$s %2$s %3$s</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user