@@ -52,19 +52,7 @@ class CheckoutActivity : AppCompatActivity() {
5252 observeLoading()
5353
5454 checkoutViewModel.getCartItems()
55- user = checkoutViewModel.getUser()
56- if (user.address.isEmpty()) {
57- btnAddDeliveryAddress.visibility = View .VISIBLE
58- btnChangeDeliveryAddress.visibility = View .GONE
59- tvDeliveryAddress.visibility = View .GONE
60- } else {
61- btnAddDeliveryAddress.visibility = View .GONE
62- btnChangeDeliveryAddress.visibility = View .VISIBLE
63- tvDeliveryAddress.visibility = View .VISIBLE
64-
65- deliveryAddress = user.address[0 ]
66- tvDeliveryAddress.text = deliveryAddress!! .streetAddress
67- }
55+ loadAddressList()
6856
6957 btnChangeDeliveryAddress.setOnClickListener {
7058 showChangeDeliveryAddressDialog()
@@ -96,8 +84,7 @@ class CheckoutActivity : AppCompatActivity() {
9684 btnChangeDeliveryAddress.visibility = View .VISIBLE
9785 tvDeliveryAddress.visibility = View .VISIBLE
9886
99- deliveryAddress = address
100- tvDeliveryAddress.text = deliveryAddress!! .streetAddress
87+ loadAddressList()
10188 }
10289 is Resource .Failure -> toast(resource.message)
10390 }
@@ -122,6 +109,22 @@ class CheckoutActivity : AppCompatActivity() {
122109 })
123110 }
124111
112+ private fun loadAddressList (){
113+ user = checkoutViewModel.getUser()
114+ if (user.address.isEmpty()) {
115+ btnAddDeliveryAddress.visibility = View .VISIBLE
116+ btnChangeDeliveryAddress.visibility = View .GONE
117+ tvDeliveryAddress.visibility = View .GONE
118+ } else {
119+ btnAddDeliveryAddress.visibility = View .GONE
120+ btnChangeDeliveryAddress.visibility = View .VISIBLE
121+ tvDeliveryAddress.visibility = View .VISIBLE
122+
123+ deliveryAddress = user.address[0 ]
124+ tvDeliveryAddress.text = deliveryAddress!! .streetAddress
125+ }
126+ }
127+
125128 private fun showChangeDeliveryAddressDialog () {
126129 val addresses = user.address.map { it.streetAddress }.toTypedArray()
127130 AlertDialog .Builder (this )
0 commit comments