update billing address
This commit is contained in:
parent
c5304e76d2
commit
df9ae110d8
@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity
|
|||||||
import me.gilo.raison.ui.user.onboarding.SignInActivity
|
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.home.HomeActivity
|
import me.gilo.wc.ui.home.HomeActivity
|
||||||
import me.gilo.wc.ui.product.ProductActivity
|
import me.gilo.wc.ui.product.ProductActivity
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
startActivity(Intent(baseContext, BasicCustomerDetailsActivity::class.java))
|
startActivity(Intent(baseContext, BillingAddressActivity::class.java))
|
||||||
|
|
||||||
// val intent = Intent(baseContext, ProductActivity::class.java)
|
// val intent = Intent(baseContext, ProductActivity::class.java)
|
||||||
// intent.putExtra("productId", 63)
|
// intent.putExtra("productId", 63)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package me.gilo.wc.repo;
|
package me.gilo.wc.repo;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.firebase.auth.FirebaseAuth;
|
||||||
import me.gilo.wc.common.WooLiveData;
|
import me.gilo.wc.common.WooLiveData;
|
||||||
import me.gilo.woodroid.Woocommerce;
|
import me.gilo.woodroid.Woocommerce;
|
||||||
import me.gilo.woodroid.models.Customer;
|
import me.gilo.woodroid.models.Customer;
|
||||||
@ -27,6 +28,15 @@ public class CustomerRepository {
|
|||||||
return callBack;
|
return callBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WooLiveData<List<Customer>> currentCustomer() {
|
||||||
|
final WooLiveData<List<Customer>> callBack = new WooLiveData();
|
||||||
|
CustomerFilter customerFilter = new CustomerFilter();
|
||||||
|
customerFilter.setEmail(FirebaseAuth.getInstance().getCurrentUser().getEmail());
|
||||||
|
|
||||||
|
woocommerce.CustomerRepository().customers(customerFilter).enqueue(callBack);
|
||||||
|
return callBack;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public WooLiveData<Customer> customer(int id) {
|
public WooLiveData<Customer> customer(int id) {
|
||||||
final WooLiveData<Customer> callBack = new WooLiveData();
|
final WooLiveData<Customer> callBack = new WooLiveData();
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import android.arch.lifecycle.Observer
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v4.content.ContextCompat.startActivity
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.google.firebase.auth.FirebaseAuth
|
import com.google.firebase.auth.FirebaseAuth
|
||||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||||
@ -36,12 +37,46 @@ class BasicCustomerDetailsActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
viewModel = getViewModel(CustomerViewModel::class.java)
|
viewModel = getViewModel(CustomerViewModel::class.java)
|
||||||
title = "Basic Details"
|
title = "Basic Details"
|
||||||
|
|
||||||
etEmail.setText(FirebaseAuth.getInstance().currentUser!!.email)
|
customer()
|
||||||
|
|
||||||
flSave.setOnClickListener{save()}
|
flSave.setOnClickListener{save()}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
var customer = response.data()[0]
|
||||||
|
|
||||||
|
etEmail.setText(customer.email)
|
||||||
|
etFirstName.setText(customer.firstName)
|
||||||
|
etLastName.setText(customer.lastName)
|
||||||
|
etUsername.setText(customer.username)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.ERROR ->{
|
||||||
|
stopShowingLoading()
|
||||||
|
Toast.makeText(baseContext, response.error().message.toString(), Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.EMPTY ->{
|
||||||
|
stopShowingLoading()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun save() {
|
private fun save() {
|
||||||
if (validates()) {
|
if (validates()) {
|
||||||
val email = etEmail.text.toString()
|
val email = etEmail.text.toString()
|
||||||
|
|||||||
@ -1,16 +1,24 @@
|
|||||||
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_billing_address.*
|
import kotlinx.android.synthetic.main.customer_billing_address.*
|
||||||
|
import kotlinx.android.synthetic.main.drawer_filter.view.*
|
||||||
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.BillingAddress
|
||||||
|
import me.gilo.woodroid.models.Customer
|
||||||
|
|
||||||
class BillingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
class BillingAddressActivity : 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))
|
||||||
@ -23,6 +31,169 @@ class BillingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
viewModel = getViewModel(CustomerViewModel::class.java)
|
viewModel = getViewModel(CustomerViewModel::class.java)
|
||||||
title = "Billing 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.billingAddress != null) {
|
||||||
|
etFirstName.setText(customer.billingAddress.firstName)
|
||||||
|
etLastName.setText(customer.billingAddress.firstName)
|
||||||
|
etCompany.setText(customer.billingAddress.company)
|
||||||
|
etStreetAddress.setText(customer.billingAddress.address1)
|
||||||
|
etStreetAddress2.setText(customer.billingAddress.address2)
|
||||||
|
etCity.setText(customer.billingAddress.city)
|
||||||
|
etState.setText(customer.billingAddress.state)
|
||||||
|
etZipcode.setText(customer.billingAddress.postcode)
|
||||||
|
etCountry.setText(customer.billingAddress.country)
|
||||||
|
etPhone.setText(customer.billingAddress.phone)
|
||||||
|
}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()
|
||||||
|
val phone = etPhone.text.toString()
|
||||||
|
|
||||||
|
customer.billingAddress = BillingAddress()
|
||||||
|
|
||||||
|
customer.billingAddress.firstName = firstName
|
||||||
|
customer.billingAddress.lastName = lastName
|
||||||
|
customer.billingAddress.company = company
|
||||||
|
customer.billingAddress.address1 = streetAddress
|
||||||
|
customer.billingAddress.address2 = streetAddress2
|
||||||
|
|
||||||
|
customer.billingAddress.city = city
|
||||||
|
customer.billingAddress.state = state
|
||||||
|
customer.billingAddress.postcode = zipcode
|
||||||
|
customer.billingAddress.country = country
|
||||||
|
customer.billingAddress.phone = phone
|
||||||
|
|
||||||
|
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
|
||||||
|
tilPhone.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()
|
||||||
|
val phone = etPhone.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
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phone.isEmpty()) {
|
||||||
|
tilPhone.error = "Please fill this"
|
||||||
|
validation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return validation
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package me.gilo.wc.viewmodels;
|
package me.gilo.wc.viewmodels;
|
||||||
|
|
||||||
import android.arch.lifecycle.ViewModel;
|
import android.arch.lifecycle.ViewModel;
|
||||||
|
import com.google.firebase.auth.FirebaseAuth;
|
||||||
import me.gilo.wc.common.WooLiveData;
|
import me.gilo.wc.common.WooLiveData;
|
||||||
import me.gilo.wc.repo.CustomerRepository;
|
import me.gilo.wc.repo.CustomerRepository;
|
||||||
import me.gilo.woodroid.models.Customer;
|
import me.gilo.woodroid.models.Customer;
|
||||||
@ -28,6 +29,10 @@ public final class CustomerViewModel extends ViewModel {
|
|||||||
return customerRepository.customer(id);
|
return customerRepository.customer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WooLiveData<List<Customer>> currentCustomer() {
|
||||||
|
return customerRepository.currentCustomer();
|
||||||
|
}
|
||||||
|
|
||||||
public WooLiveData<List<Customer>> customers() {
|
public WooLiveData<List<Customer>> customers() {
|
||||||
return customerRepository.customers();
|
return customerRepository.customers();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -156,7 +156,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Username"
|
android:hint="Username"
|
||||||
android:id="@+id/etUsername"
|
android:id="@+id/etUsername"
|
||||||
android:inputType="textPassword"
|
android:inputType="text"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
|
|||||||
@ -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"
|
||||||
@ -322,7 +322,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Phone"
|
android:hint="Phone"
|
||||||
android:id="@+id/etPhone"
|
android:id="@+id/etPhone"
|
||||||
android:inputType="textEmailAddress"
|
android:inputType="phone"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:textColor="#5f6368"
|
android:textColor="#5f6368"
|
||||||
android:textColorHint="#9e9e9e"
|
android:textColorHint="#9e9e9e"
|
||||||
|
|||||||
@ -27,9 +27,9 @@ public class Customer implements Serializable{
|
|||||||
public String totalSpent;
|
public String totalSpent;
|
||||||
@SerializedName("avatar_url")
|
@SerializedName("avatar_url")
|
||||||
public String avatarUrl;
|
public String avatarUrl;
|
||||||
@SerializedName("billing_address")
|
@SerializedName("billing")
|
||||||
public BillingAddress billingAddress;
|
public BillingAddress billingAddress;
|
||||||
@SerializedName("shipping_address")
|
@SerializedName("shipping")
|
||||||
public ShippingAddress shippingAddress;
|
public ShippingAddress shippingAddress;
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user