Complete customer edit functions
This commit is contained in:
parent
b395c4e6e0
commit
37e1147615
@ -8,6 +8,7 @@ import me.gilo.wc.MainActivity;
|
|||||||
import me.gilo.wc.ui.WooDroidActivity;
|
import me.gilo.wc.ui.WooDroidActivity;
|
||||||
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.ProfileActivity;
|
||||||
import me.gilo.wc.ui.customer.ShippingAddressActivity;
|
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;
|
||||||
@ -43,4 +44,7 @@ abstract class ActivitiesModule {
|
|||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
abstract ShippingAddressActivity contributesShippingAddressActivity();
|
abstract ShippingAddressActivity contributesShippingAddressActivity();
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract ProfileActivity contributesProfileActivity();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ class BasicCustomerDetailsActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
override lateinit var viewModel : CustomerViewModel
|
override lateinit var viewModel : CustomerViewModel
|
||||||
private val pattern = Pattern.compile(EMAIL_PATTERN)
|
private val pattern = Pattern.compile(EMAIL_PATTERN)
|
||||||
private var matcher: Matcher? = null
|
private var matcher: Matcher? = null
|
||||||
|
lateinit var customer: Customer
|
||||||
|
|
||||||
override fun attachBaseContext(newBase: Context) {
|
override fun attachBaseContext(newBase: Context) {
|
||||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
||||||
@ -54,7 +55,7 @@ class BasicCustomerDetailsActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
|
|
||||||
Status.SUCCESS ->{
|
Status.SUCCESS ->{
|
||||||
stopShowingLoading()
|
stopShowingLoading()
|
||||||
var customer = response.data()[0]
|
customer = response.data()[0]
|
||||||
|
|
||||||
etEmail.setText(customer.email)
|
etEmail.setText(customer.email)
|
||||||
etFirstName.setText(customer.firstName)
|
etFirstName.setText(customer.firstName)
|
||||||
@ -84,13 +85,12 @@ class BasicCustomerDetailsActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
val lastName = etLastName.text.toString()
|
val lastName = etLastName.text.toString()
|
||||||
val username = etUsername.text.toString()
|
val username = etUsername.text.toString()
|
||||||
|
|
||||||
var customer = Customer()
|
|
||||||
customer.email = email
|
customer.email = email
|
||||||
customer.firstName = firstName
|
customer.firstName = firstName
|
||||||
customer.lastName = lastName
|
customer.lastName = lastName
|
||||||
customer.username = username
|
customer.username = username
|
||||||
|
|
||||||
viewModel.create(customer).observe(this, Observer {
|
viewModel.update(customer.id, customer).observe(this, Observer {
|
||||||
response->
|
response->
|
||||||
when (response!!.status()){
|
when (response!!.status()){
|
||||||
Status.LOADING ->{
|
Status.LOADING ->{
|
||||||
@ -99,7 +99,7 @@ class BasicCustomerDetailsActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
|
|
||||||
Status.SUCCESS ->{
|
Status.SUCCESS ->{
|
||||||
stopShowingLoading()
|
stopShowingLoading()
|
||||||
startActivity(Intent(baseContext, BillingAddressActivity::class.java))
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
Status.ERROR ->{
|
Status.ERROR ->{
|
||||||
|
|||||||
@ -119,7 +119,7 @@ class BillingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
|
|
||||||
Status.SUCCESS ->{
|
Status.SUCCESS ->{
|
||||||
stopShowingLoading()
|
stopShowingLoading()
|
||||||
startActivity(Intent(baseContext, BillingAddressActivity::class.java))
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
Status.ERROR ->{
|
Status.ERROR ->{
|
||||||
|
|||||||
@ -2,20 +2,16 @@ package me.gilo.wc.ui.customer
|
|||||||
|
|
||||||
import android.arch.lifecycle.Observer
|
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.support.design.widget.Snackbar
|
|
||||||
import android.support.v7.app.AppCompatActivity
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||||
import me.gilo.wc.R
|
|
||||||
|
|
||||||
import kotlinx.android.synthetic.main.activity_profile.*
|
import kotlinx.android.synthetic.main.activity_profile.*
|
||||||
import kotlinx.android.synthetic.main.customer_basic_details.*
|
import kotlinx.android.synthetic.main.content_profile.*
|
||||||
|
import me.gilo.wc.R
|
||||||
import me.gilo.wc.common.Status
|
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 java.util.regex.Matcher
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
class ProfileActivity : WooDroidActivity<CustomerViewModel>() {
|
class ProfileActivity : WooDroidActivity<CustomerViewModel>() {
|
||||||
|
|
||||||
@ -29,12 +25,21 @@ class ProfileActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_profile)
|
setContentView(R.layout.activity_profile)
|
||||||
|
|
||||||
viewModel = getViewModel(CustomerViewModel::class.java)
|
setSupportActionBar(toolbar)
|
||||||
|
|
||||||
title = "Profile"
|
title = "Profile"
|
||||||
|
|
||||||
|
tvBasicDetailsEdit.setOnClickListener{startActivity(Intent(baseContext, BasicCustomerDetailsActivity::class.java))}
|
||||||
|
tvBillingAddressEdit.setOnClickListener{startActivity(Intent(baseContext, BillingAddressActivity::class.java))}
|
||||||
|
tvShippingAddressEdit.setOnClickListener{startActivity(Intent(baseContext, ShippingAddressActivity::class.java))}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
viewModel = getViewModel(CustomerViewModel::class.java)
|
||||||
customer()
|
customer()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +55,13 @@ class ProfileActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
stopShowingLoading()
|
stopShowingLoading()
|
||||||
var customer = response.data()[0]
|
var customer = response.data()[0]
|
||||||
|
|
||||||
|
tvBasicDetailsName.text = customer.firstName + " " + customer.lastName
|
||||||
|
|
||||||
|
tvEmail.text = "Email : " + customer.email
|
||||||
|
tvUsername.text = "Username : " + customer.username
|
||||||
|
|
||||||
|
tvShippingAddress.text = customer.shippingAddress.toString()
|
||||||
|
tvBillingAddress.text = customer.billingAddress.toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -112,7 +112,7 @@ class ShippingAddressActivity : WooDroidActivity<CustomerViewModel>() {
|
|||||||
|
|
||||||
Status.SUCCESS ->{
|
Status.SUCCESS ->{
|
||||||
stopShowingLoading()
|
stopShowingLoading()
|
||||||
startActivity(Intent(baseContext, BillingAddressActivity::class.java))
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
Status.ERROR ->{
|
Status.ERROR ->{
|
||||||
|
|||||||
@ -1,11 +1,16 @@
|
|||||||
package me.gilo.wc.ui.home
|
package me.gilo.wc.ui.home
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import com.google.firebase.auth.FirebaseAuth
|
||||||
|
import kotlinx.android.synthetic.main.fragment_profile.*
|
||||||
|
import me.gilo.raison.ui.user.onboarding.SignUpActivity
|
||||||
import me.gilo.wc.R
|
import me.gilo.wc.R
|
||||||
|
import me.gilo.wc.ui.customer.ProfileActivity
|
||||||
import me.gilo.wc.viewmodels.ProductViewModel
|
import me.gilo.wc.viewmodels.ProductViewModel
|
||||||
|
|
||||||
|
|
||||||
@ -32,6 +37,13 @@ class ProfileFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
llMyProfile.setOnClickListener{
|
||||||
|
if (FirebaseAuth.getInstance().currentUser != null) {
|
||||||
|
startActivity(Intent(activity, ProfileActivity::class.java))
|
||||||
|
}else{
|
||||||
|
startActivity(Intent(activity, SignUpActivity::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,7 @@
|
|||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/tvBasicDetailsName"
|
||||||
fontPath="@string/font_regular"
|
fontPath="@string/font_regular"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -64,15 +65,41 @@
|
|||||||
android:textColor="@color/text_black_2"
|
android:textColor="@color/text_black_2"
|
||||||
android:textSize="16sp"/>
|
android:textSize="16sp"/>
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/tvEmail"
|
||||||
fontPath="@string/font_regular"
|
fontPath="@string/font_regular"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="left"
|
android:gravity="left"
|
||||||
android:text="@string/dummy_address"
|
android:text="Email : john@mail.com"
|
||||||
android:maxLines="6"
|
android:maxLines="6"
|
||||||
android:lineSpacingMultiplier="1.2"
|
android:lineSpacingMultiplier="1.2"
|
||||||
android:textColor="@color/text_black_5"
|
android:textColor="@color/text_black_5"
|
||||||
android:textSize="16sp"/>
|
android:textSize="16sp"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvUsername"
|
||||||
|
fontPath="@string/font_regular"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="left"
|
||||||
|
android:text="Username : john"
|
||||||
|
android:maxLines="6"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
|
android:textColor="@color/text_black_5"
|
||||||
|
android:textSize="16sp"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBasicDetailsEdit"
|
||||||
|
fontPath="@string/font_regular"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="Edit"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
|
android:textColor="@color/colorPrimary"
|
||||||
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@ -115,26 +142,33 @@
|
|||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/tvBillingAddress"
|
||||||
fontPath="@string/font_regular"
|
fontPath="@string/font_regular"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="left"
|
|
||||||
android:text="Gilbert Kimutai"
|
|
||||||
android:maxLines="6"
|
|
||||||
android:lineSpacingMultiplier="1.2"
|
|
||||||
android:textColor="@color/text_black_2"
|
|
||||||
android:textSize="16sp"/>
|
|
||||||
<TextView
|
|
||||||
fontPath="@string/font_regular"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="left"
|
android:gravity="left"
|
||||||
|
android:layout_weight="1"
|
||||||
android:text="@string/dummy_address"
|
android:text="@string/dummy_address"
|
||||||
android:maxLines="6"
|
android:maxLines="6"
|
||||||
android:lineSpacingMultiplier="1.2"
|
android:lineSpacingMultiplier="1.2"
|
||||||
android:textColor="@color/text_black_5"
|
android:textColor="@color/text_black_5"
|
||||||
android:textSize="16sp"/>
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBillingAddressEdit"
|
||||||
|
fontPath="@string/font_regular"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="Edit"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
|
android:textColor="@color/colorPrimary"
|
||||||
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -175,16 +209,7 @@
|
|||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
fontPath="@string/font_regular"
|
android:id="@+id/tvShippingAddress"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="left"
|
|
||||||
android:text="Gilbert Kimutai"
|
|
||||||
android:maxLines="6"
|
|
||||||
android:lineSpacingMultiplier="1.2"
|
|
||||||
android:textColor="@color/text_black_2"
|
|
||||||
android:textSize="16sp"/>
|
|
||||||
<TextView
|
|
||||||
fontPath="@string/font_regular"
|
fontPath="@string/font_regular"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -196,6 +221,20 @@
|
|||||||
android:textSize="16sp"/>
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvShippingAddressEdit"
|
||||||
|
fontPath="@string/font_regular"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="Edit"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
|
android:textColor="@color/colorPrimary"
|
||||||
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@ -242,6 +242,7 @@
|
|||||||
>
|
>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/llMyProfile"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
|||||||
@ -117,4 +117,14 @@ public class BillingAddress implements Serializable{
|
|||||||
public void setPhone(String phone) {
|
public void setPhone(String phone) {
|
||||||
this.phone = phone;
|
this.phone = phone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return firstName + " " + lastName + "\n"
|
||||||
|
+ address1 + " " + address2 + "\n"
|
||||||
|
+ city + ", " + state + " " + postcode + "\n"
|
||||||
|
+ country + "\n"
|
||||||
|
+ phone
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,4 +151,6 @@ public class Customer implements Serializable{
|
|||||||
public void setBillingAddress(BillingAddress billingAddress) {
|
public void setBillingAddress(BillingAddress billingAddress) {
|
||||||
this.billingAddress = billingAddress;
|
this.billingAddress = billingAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,4 +97,12 @@ public class ShippingAddress {
|
|||||||
public void setCountry(String country) {
|
public void setCountry(String country) {
|
||||||
this.country = country;
|
this.country = country;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return firstName + " " + lastName + "\n" +
|
||||||
|
address1 + " " + address2 + "\n"
|
||||||
|
+ city + ", " + state + " " + postcode + "\n"
|
||||||
|
+ country;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user