mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-10 17:32:22 +00:00
ongoing checkout store
This commit is contained in:
@ -17,6 +17,12 @@
|
||||
android:theme="@style/Theme.Ecommerce_serang"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".ui.order.AddressActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".ui.order.ShippingActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".ui.order.CheckoutActivity"
|
||||
android:exported="false" />
|
||||
|
@ -26,7 +26,7 @@ data class StoreProduct(
|
||||
val storeLocation: String,
|
||||
|
||||
@field:SerializedName("store_image")
|
||||
val storeImage: Any,
|
||||
val storeImage: String? = null,
|
||||
|
||||
@field:SerializedName("status")
|
||||
val status: String
|
||||
|
@ -62,7 +62,7 @@ data class Store(
|
||||
val email: String,
|
||||
|
||||
@field:SerializedName("store_image")
|
||||
val storeImage: Any,
|
||||
val storeImage: String? = null,
|
||||
|
||||
@field:SerializedName("longitude")
|
||||
val longitude: String,
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.alya.ecommerce_serang.data.api.retrofit
|
||||
|
||||
import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.LoginRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.OrderRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.OtpRequest
|
||||
@ -16,7 +17,6 @@ import com.alya.ecommerce_serang.data.api.response.ProfileResponse
|
||||
import com.alya.ecommerce_serang.data.api.response.RegisterResponse
|
||||
import com.alya.ecommerce_serang.data.api.response.ReviewProductResponse
|
||||
import com.alya.ecommerce_serang.data.api.response.StoreResponse
|
||||
import retrofit2.Call
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
@ -71,10 +71,9 @@ interface ApiService {
|
||||
|
||||
@GET("profile/address")
|
||||
suspend fun getAddress(
|
||||
@Body addressRequest: AddressRequest
|
||||
@Body addressRequest: CreateAddressRequest
|
||||
): Response<AddressResponse>
|
||||
|
||||
|
||||
@GET("mystore")
|
||||
fun getStore (): Call<StoreResponse>
|
||||
suspend fun getStore (): Response<StoreResponse>
|
||||
}
|
@ -4,6 +4,7 @@ import android.util.Log
|
||||
import com.alya.ecommerce_serang.data.api.dto.OrderRequest
|
||||
import com.alya.ecommerce_serang.data.api.response.OrderResponse
|
||||
import com.alya.ecommerce_serang.data.api.response.ProductResponse
|
||||
import com.alya.ecommerce_serang.data.api.response.StoreResponse
|
||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
||||
import retrofit2.Response
|
||||
|
||||
@ -27,6 +28,12 @@ class OrderRepository(private val apiService: ApiService) {
|
||||
return apiService.postOrder(orderRequest)
|
||||
}
|
||||
|
||||
suspend fun getStore(): StoreResponse? {
|
||||
val response = apiService.getStore()
|
||||
return if (response.isSuccessful) response.body() else null
|
||||
}
|
||||
|
||||
|
||||
//not yet implement the api service address
|
||||
// suspend fun getAddressDetails(addressId: Int): AddressesItem {
|
||||
// // Simulate API call to get address details
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.alya.ecommerce_serang.ui.order
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.alya.ecommerce_serang.R
|
||||
|
||||
class AddressActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContentView(R.layout.activity_address)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import com.alya.ecommerce_serang.data.api.dto.CheckoutData
|
||||
import com.alya.ecommerce_serang.data.api.dto.OrderRequest
|
||||
import com.alya.ecommerce_serang.data.api.response.AddressesItem
|
||||
import com.alya.ecommerce_serang.data.api.response.OrderResponse
|
||||
import com.alya.ecommerce_serang.data.api.response.PaymentItem
|
||||
import com.alya.ecommerce_serang.data.repository.OrderRepository
|
||||
import com.alya.ecommerce_serang.data.repository.Result
|
||||
import kotlinx.coroutines.launch
|
||||
@ -21,6 +22,9 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
||||
private val _addressDetails = MutableLiveData<AddressesItem>()
|
||||
val addressDetails: LiveData<AddressesItem> = _addressDetails
|
||||
|
||||
private val _storePayments = MutableLiveData<List<PaymentItem>>()
|
||||
val storePayments: LiveData<List<PaymentItem>> = _storePayments
|
||||
|
||||
private val _isLoading = MutableLiveData<Boolean>()
|
||||
val isLoading: LiveData<Boolean> = _isLoading
|
||||
|
||||
@ -31,6 +35,8 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
||||
try {
|
||||
// Load all necessary data
|
||||
val productDetails = repository.fetchProductDetail(orderRequest.productIdItem)
|
||||
val storeDetails = repository.getStoreDetails(productDetails.product.storeId)
|
||||
|
||||
// val addressDetails = repository.getAddressDetails(orderRequest.address_id)
|
||||
|
||||
// Update LiveData objects
|
||||
@ -42,10 +48,15 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
||||
productName = productDetails?.product?.productName,
|
||||
productImageUrl = productDetails.product.image,
|
||||
productPrice = productDetails.product.price,
|
||||
sellerName = productDetails.product.storeId
|
||||
// sellerImageUrl = productDetails.sellerImageUrl,
|
||||
// sellerId = productDetails.sellerId
|
||||
sellerName = storeDetails.store.storeName,
|
||||
sellerImageUrl = storeDetails.store.storeImage,
|
||||
sellerId = productDetails.product.storeId
|
||||
)
|
||||
|
||||
storeDetails?.let {
|
||||
_storePayments.value = it.payment
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
// Handle errors
|
||||
Log.e("CheckoutViewModel", "Error loading checkout data", e)
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.alya.ecommerce_serang.ui.order
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.alya.ecommerce_serang.R
|
||||
|
||||
class ShippingActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContentView(R.layout.activity_shipping)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
}
|
||||
}
|
10
app/src/main/res/layout/activity_address.xml
Normal file
10
app/src/main/res/layout/activity_address.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.order.AddressActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
10
app/src/main/res/layout/activity_shipping.xml
Normal file
10
app/src/main/res/layout/activity_shipping.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.order.ShippingActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Reference in New Issue
Block a user