Update model and view data
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package com.navi.medici.android_customer_app.login
|
||||
|
||||
object Login {
|
||||
const val createNewAccount: String = "Create New Account"
|
||||
const val phoneLabel: String = "Enter your mobile number to register with Navi"
|
||||
const val countryCode: String = "+91"
|
||||
const val termsAndConditions: String =
|
||||
"By proceeding, you agree to our Terms & Conditions & Privacy Policy. Standard operator charges may apply for sms."
|
||||
data class Login(
|
||||
val id: Int? = 0,
|
||||
val userId: Int? = 0,
|
||||
val title: String? = ""
|
||||
) {
|
||||
var phoneNumber: String = ""
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class LoginActivity : AppCompatActivity() {
|
||||
loginViewModel = ViewModelProviders.of(this).get(LoginViewModel::class.java)
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_login)
|
||||
|
||||
binding.login = Login
|
||||
binding.loginViewData = LoginViewData()
|
||||
|
||||
binding.phoneEdit.addTextChangedListener { loginViewModel.onChangePhoneNumber(it.toString()) }
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ private val gsonConverterFactory = GsonConverterFactory.create()
|
||||
|
||||
interface LoginApi {
|
||||
@GET("posts/1")
|
||||
suspend fun submitPhoneNumber(): Response<LoginResponse>
|
||||
suspend fun submitPhoneNumber(): Response<Login>
|
||||
|
||||
companion object {
|
||||
operator fun invoke(): LoginApi {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.navi.medici.android_customer_app.login
|
||||
|
||||
data class LoginResponse(
|
||||
val id: Int?,
|
||||
val title: String?,
|
||||
val body: String?,
|
||||
val userId: Int?
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.navi.medici.android_customer_app.login
|
||||
|
||||
data class LoginViewData(
|
||||
val createNewAccount: String = "Create New Account",
|
||||
val phoneLabel: String = "Enter your mobile number to register with Navi",
|
||||
val countryCode: String = "+91",
|
||||
val termsAndConditions: String =
|
||||
"By proceeding, you agree to our Terms & Conditions & Privacy Policy. Standard operator charges may apply for sms."
|
||||
)
|
||||
@@ -7,23 +7,23 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class LoginViewModel : ViewModel() {
|
||||
private var phoneNumber: String = Login.phoneNumber
|
||||
private val login = Login()
|
||||
private val loginRepository = LoginRepository(LoginApi())
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Main)
|
||||
|
||||
fun onChangePhoneNumber(phoneNumber: String) {
|
||||
this.phoneNumber = phoneNumber
|
||||
if (isValidPhoneNumber()) {
|
||||
if (isValidPhoneNumber(phoneNumber)) {
|
||||
login.phoneNumber = phoneNumber
|
||||
submitPhoneNumber()
|
||||
}
|
||||
}
|
||||
|
||||
private fun submitPhoneNumber() {
|
||||
coroutineScope.launch {
|
||||
val response = loginRepository.submitPhoneNumber(phoneNumber)
|
||||
val response = loginRepository.submitPhoneNumber(login.phoneNumber)
|
||||
Log.i("login response", response.toString())
|
||||
}
|
||||
}
|
||||
|
||||
private fun isValidPhoneNumber(): Boolean = phoneNumber.length == 10
|
||||
private fun isValidPhoneNumber(phoneNumber: String): Boolean = phoneNumber.length == 10
|
||||
}
|
||||
@@ -5,8 +5,8 @@
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="login"
|
||||
type="com.navi.medici.android_customer_app.login.Login" />
|
||||
name="loginViewData"
|
||||
type="com.navi.medici.android_customer_app.login.LoginViewData" />
|
||||
|
||||
</data>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:text="@{login.countryCode}"
|
||||
android:text="@{loginViewData.countryCode}"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/phone_edit"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@@ -50,7 +50,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:text="@{login.phoneLabel}"
|
||||
android:text="@{loginViewData.phoneLabel}"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/phone_edit"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
@@ -60,7 +60,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="56dp"
|
||||
android:text="@{login.createNewAccount}"
|
||||
android:text="@{loginViewData.createNewAccount}"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/phone_label_text"
|
||||
@@ -72,7 +72,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="80dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:text="@{login.termsAndConditions}"
|
||||
android:text="@{loginViewData.termsAndConditions}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/country_code_text"
|
||||
app:layout_constraintTop_toBottomOf="@+id/phone_edit" />
|
||||
|
||||
Reference in New Issue
Block a user