update shipping address
This commit is contained in:
parent
df9ae110d8
commit
6977c0fc85
@ -7,6 +7,7 @@ import me.gilo.raison.ui.user.onboarding.SignInActivity
|
|||||||
import me.gilo.raison.ui.user.onboarding.SignUpActivity
|
import me.gilo.raison.ui.user.onboarding.SignUpActivity
|
||||||
import me.gilo.wc.ui.customer.BasicCustomerDetailsActivity
|
import me.gilo.wc.ui.customer.BasicCustomerDetailsActivity
|
||||||
import me.gilo.wc.ui.customer.BillingAddressActivity
|
import me.gilo.wc.ui.customer.BillingAddressActivity
|
||||||
|
import me.gilo.wc.ui.customer.ShippingAddressActivity
|
||||||
import me.gilo.wc.ui.home.HomeActivity
|
import me.gilo.wc.ui.home.HomeActivity
|
||||||
import me.gilo.wc.ui.product.ProductActivity
|
import me.gilo.wc.ui.product.ProductActivity
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
startActivity(Intent(baseContext, BillingAddressActivity::class.java))
|
startActivity(Intent(baseContext, ShippingAddressActivity::class.java))
|
||||||
|
|
||||||
// val intent = Intent(baseContext, ProductActivity::class.java)
|
// val intent = Intent(baseContext, ProductActivity::class.java)
|
||||||
// intent.putExtra("productId", 63)
|
// intent.putExtra("productId", 63)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import com.google.firebase.auth.FirebaseAuth
|
||||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||||
import kotlinx.android.synthetic.main.customer_billing_address.*
|
import kotlinx.android.synthetic.main.customer_billing_address.*
|
||||||
import kotlinx.android.synthetic.main.drawer_filter.view.*
|
import kotlinx.android.synthetic.main.drawer_filter.view.*
|
||||||
@ -107,6 +108,8 @@ class BillingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
customer.billingAddress.country = country
|
customer.billingAddress.country = country
|
||||||
customer.billingAddress.phone = phone
|
customer.billingAddress.phone = phone
|
||||||
|
|
||||||
|
customer.billingAddress.email = FirebaseAuth.getInstance().currentUser!!.email
|
||||||
|
|
||||||
viewModel.update(customer.id, customer).observe(this, Observer {
|
viewModel.update(customer.id, customer).observe(this, Observer {
|
||||||
response->
|
response->
|
||||||
when (response!!.status()){
|
when (response!!.status()){
|
||||||
|
|||||||
@ -1,16 +1,23 @@
|
|||||||
package me.gilo.wc.ui.customer
|
package me.gilo.wc.ui.customer
|
||||||
|
|
||||||
|
import android.arch.lifecycle.Observer
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.widget.Toast
|
||||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||||
import kotlinx.android.synthetic.main.activity_shipping_address.*
|
import kotlinx.android.synthetic.main.customer_shipping_address.*
|
||||||
import me.gilo.wc.R
|
import me.gilo.wc.R
|
||||||
|
import me.gilo.wc.common.Status
|
||||||
import me.gilo.wc.ui.WooDroidActivity
|
import me.gilo.wc.ui.WooDroidActivity
|
||||||
import me.gilo.wc.viewmodels.CustomerViewModel
|
import me.gilo.wc.viewmodels.CustomerViewModel
|
||||||
|
import me.gilo.woodroid.models.Customer
|
||||||
|
import me.gilo.woodroid.models.ShippingAddress
|
||||||
|
|
||||||
class ShippingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
class ShippingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
||||||
|
|
||||||
override lateinit var viewModel : CustomerViewModel
|
override lateinit var viewModel : CustomerViewModel
|
||||||
|
lateinit var customer : Customer
|
||||||
|
|
||||||
override fun attachBaseContext(newBase: Context) {
|
override fun attachBaseContext(newBase: Context) {
|
||||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
||||||
@ -21,8 +28,160 @@ class ShippingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
setContentView(R.layout.activity_shipping_address)
|
setContentView(R.layout.activity_shipping_address)
|
||||||
|
|
||||||
viewModel = getViewModel(CustomerViewModel::class.java)
|
viewModel = getViewModel(CustomerViewModel::class.java)
|
||||||
title = "Shipping Address"
|
title = "Billing Address"
|
||||||
|
|
||||||
|
customer()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun customer() {
|
||||||
|
viewModel.currentCustomer().observe(this, Observer {
|
||||||
|
response->
|
||||||
|
when (response!!.status()){
|
||||||
|
Status.LOADING ->{
|
||||||
|
showLoading("Retrieve customer details", "This will only take a short while")
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.SUCCESS ->{
|
||||||
|
stopShowingLoading()
|
||||||
|
customer = response.data()[0]
|
||||||
|
|
||||||
|
if (customer.shippingAddress != null) {
|
||||||
|
etFirstName.setText(customer.shippingAddress.firstName)
|
||||||
|
etLastName.setText(customer.shippingAddress.firstName)
|
||||||
|
etCompany.setText(customer.shippingAddress.company)
|
||||||
|
etStreetAddress.setText(customer.shippingAddress.address1)
|
||||||
|
etStreetAddress2.setText(customer.shippingAddress.address2)
|
||||||
|
etCity.setText(customer.shippingAddress.city)
|
||||||
|
etState.setText(customer.shippingAddress.state)
|
||||||
|
etZipcode.setText(customer.shippingAddress.postcode)
|
||||||
|
etCountry.setText(customer.shippingAddress.country)
|
||||||
|
}else{
|
||||||
|
etFirstName.setText(customer.firstName)
|
||||||
|
etLastName.setText(customer.firstName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.ERROR ->{
|
||||||
|
stopShowingLoading()
|
||||||
|
Toast.makeText(baseContext, response.error().message.toString(), Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.EMPTY ->{
|
||||||
|
stopShowingLoading()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
flSave.setOnClickListener{save()}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun save() {
|
||||||
|
if (validates()) {
|
||||||
|
val firstName = etFirstName.text.toString()
|
||||||
|
val lastName = etLastName.text.toString()
|
||||||
|
val company = etCompany.text.toString()
|
||||||
|
val streetAddress = etStreetAddress.text.toString()
|
||||||
|
val streetAddress2 = etStreetAddress2.text.toString()
|
||||||
|
val city = etCity.text.toString()
|
||||||
|
val state = etState.text.toString()
|
||||||
|
val zipcode = etZipcode.text.toString()
|
||||||
|
val country = etCountry.text.toString()
|
||||||
|
|
||||||
|
customer.shippingAddress = ShippingAddress()
|
||||||
|
|
||||||
|
customer.shippingAddress.firstName = firstName
|
||||||
|
customer.shippingAddress.lastName = lastName
|
||||||
|
customer.shippingAddress.company = company
|
||||||
|
customer.shippingAddress.address1 = streetAddress
|
||||||
|
customer.shippingAddress.address2 = streetAddress2
|
||||||
|
|
||||||
|
customer.shippingAddress.city = city
|
||||||
|
customer.shippingAddress.state = state
|
||||||
|
customer.shippingAddress.postcode = zipcode
|
||||||
|
customer.shippingAddress.country = country
|
||||||
|
|
||||||
|
viewModel.update(customer.id, customer).observe(this, Observer {
|
||||||
|
response->
|
||||||
|
when (response!!.status()){
|
||||||
|
Status.LOADING ->{
|
||||||
|
showLoading("Uploading account details", "This will only take a short while")
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.SUCCESS ->{
|
||||||
|
stopShowingLoading()
|
||||||
|
startActivity(Intent(baseContext, BillingAddressActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.ERROR ->{
|
||||||
|
stopShowingLoading()
|
||||||
|
Toast.makeText(baseContext, response.error().message.toString(), Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.EMPTY ->{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Please correct the information entered", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validates(): Boolean {
|
||||||
|
tilFirstName.isErrorEnabled = false
|
||||||
|
tilLastName.isErrorEnabled = false
|
||||||
|
tilStreetAddress.isErrorEnabled = false
|
||||||
|
tilCity.isErrorEnabled = false
|
||||||
|
tilZipcode.isErrorEnabled = false
|
||||||
|
tilCountry.isErrorEnabled = false
|
||||||
|
|
||||||
|
var validation = true
|
||||||
|
|
||||||
|
val firstName = etFirstName.text.toString()
|
||||||
|
val lastName = etLastName.text.toString()
|
||||||
|
val streetAddress = etStreetAddress.text.toString()
|
||||||
|
val city = etCity.text.toString()
|
||||||
|
val zipcode = etZipcode.text.toString()
|
||||||
|
val country = etCountry.text.toString()
|
||||||
|
|
||||||
|
if (firstName.isEmpty()) {
|
||||||
|
tilFirstName.error = "Please fill this"
|
||||||
|
validation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastName.isEmpty()) {
|
||||||
|
tilLastName.error = "Please fill this"
|
||||||
|
validation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (streetAddress.isEmpty()) {
|
||||||
|
tilStreetAddress.error = "Please fill this"
|
||||||
|
validation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (city.isEmpty()) {
|
||||||
|
tilCity.error = "Please fill this"
|
||||||
|
validation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zipcode.isEmpty()) {
|
||||||
|
tilZipcode.error = "Please fill this"
|
||||||
|
validation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (country.isEmpty()) {
|
||||||
|
tilCountry.error = "Please fill this"
|
||||||
|
validation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return validation
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -126,7 +126,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Company"
|
android:hint="Company"
|
||||||
android:id="@+id/etCompany"
|
android:id="@+id/etCompany"
|
||||||
android:inputType="textEmailAddress"
|
android:inputType="text"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
@ -151,7 +151,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Street Address"
|
android:hint="Street Address"
|
||||||
android:id="@+id/etStreetAddress"
|
android:id="@+id/etStreetAddress"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPostalAddress"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
@ -174,7 +174,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Street Address 2"
|
android:hint="Street Address 2"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPostalAddress"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:id="@+id/etStreetAddress2"
|
android:id="@+id/etStreetAddress2"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
@ -206,7 +206,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="City"
|
android:hint="City"
|
||||||
android:id="@+id/etCity"
|
android:id="@+id/etCity"
|
||||||
android:inputType="textPassword"
|
android:inputType="text"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
@ -231,7 +231,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="State"
|
android:hint="State"
|
||||||
android:id="@+id/etState"
|
android:id="@+id/etState"
|
||||||
android:inputType="textPassword"
|
android:inputType="text"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
@ -264,7 +264,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Zip code"
|
android:hint="Zip code"
|
||||||
android:id="@+id/etZipcode"
|
android:id="@+id/etZipcode"
|
||||||
android:inputType="textPassword"
|
android:inputType="number"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
@ -298,7 +298,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Country"
|
android:hint="Country"
|
||||||
android:id="@+id/etCountry"
|
android:id="@+id/etCountry"
|
||||||
android:inputType="textPassword"
|
android:inputType="text"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
@ -308,7 +308,6 @@
|
|||||||
|
|
||||||
</android.support.design.widget.TextInputLayout>
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</android.support.v4.widget.NestedScrollView>
|
</android.support.v4.widget.NestedScrollView>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user