mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-13 10:42:21 +00:00
ongoing checkout store
This commit is contained in:
@ -17,6 +17,12 @@
|
|||||||
android:theme="@style/Theme.Ecommerce_serang"
|
android:theme="@style/Theme.Ecommerce_serang"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".ui.order.AddressActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.order.ShippingActivity"
|
||||||
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.order.CheckoutActivity"
|
android:name=".ui.order.CheckoutActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
@ -26,7 +26,7 @@ data class StoreProduct(
|
|||||||
val storeLocation: String,
|
val storeLocation: String,
|
||||||
|
|
||||||
@field:SerializedName("store_image")
|
@field:SerializedName("store_image")
|
||||||
val storeImage: Any,
|
val storeImage: String? = null,
|
||||||
|
|
||||||
@field:SerializedName("status")
|
@field:SerializedName("status")
|
||||||
val status: String
|
val status: String
|
||||||
|
@ -62,7 +62,7 @@ data class Store(
|
|||||||
val email: String,
|
val email: String,
|
||||||
|
|
||||||
@field:SerializedName("store_image")
|
@field:SerializedName("store_image")
|
||||||
val storeImage: Any,
|
val storeImage: String? = null,
|
||||||
|
|
||||||
@field:SerializedName("longitude")
|
@field:SerializedName("longitude")
|
||||||
val longitude: String,
|
val longitude: String,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.alya.ecommerce_serang.data.api.retrofit
|
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.LoginRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.OrderRequest
|
import com.alya.ecommerce_serang.data.api.dto.OrderRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.OtpRequest
|
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.RegisterResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.ReviewProductResponse
|
import com.alya.ecommerce_serang.data.api.response.ReviewProductResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.StoreResponse
|
import com.alya.ecommerce_serang.data.api.response.StoreResponse
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@ -71,10 +71,9 @@ interface ApiService {
|
|||||||
|
|
||||||
@GET("profile/address")
|
@GET("profile/address")
|
||||||
suspend fun getAddress(
|
suspend fun getAddress(
|
||||||
@Body addressRequest: AddressRequest
|
@Body addressRequest: CreateAddressRequest
|
||||||
): Response<AddressResponse>
|
): Response<AddressResponse>
|
||||||
|
|
||||||
|
|
||||||
@GET("mystore")
|
@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.dto.OrderRequest
|
||||||
import com.alya.ecommerce_serang.data.api.response.OrderResponse
|
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.ProductResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.StoreResponse
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
|
||||||
@ -27,6 +28,12 @@ class OrderRepository(private val apiService: ApiService) {
|
|||||||
return apiService.postOrder(orderRequest)
|
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
|
//not yet implement the api service address
|
||||||
// suspend fun getAddressDetails(addressId: Int): AddressesItem {
|
// suspend fun getAddressDetails(addressId: Int): AddressesItem {
|
||||||
// // Simulate API call to get address details
|
// // 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.dto.OrderRequest
|
||||||
import com.alya.ecommerce_serang.data.api.response.AddressesItem
|
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.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.OrderRepository
|
||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -21,6 +22,9 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
|||||||
private val _addressDetails = MutableLiveData<AddressesItem>()
|
private val _addressDetails = MutableLiveData<AddressesItem>()
|
||||||
val addressDetails: LiveData<AddressesItem> = _addressDetails
|
val addressDetails: LiveData<AddressesItem> = _addressDetails
|
||||||
|
|
||||||
|
private val _storePayments = MutableLiveData<List<PaymentItem>>()
|
||||||
|
val storePayments: LiveData<List<PaymentItem>> = _storePayments
|
||||||
|
|
||||||
private val _isLoading = MutableLiveData<Boolean>()
|
private val _isLoading = MutableLiveData<Boolean>()
|
||||||
val isLoading: LiveData<Boolean> = _isLoading
|
val isLoading: LiveData<Boolean> = _isLoading
|
||||||
|
|
||||||
@ -31,6 +35,8 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
|||||||
try {
|
try {
|
||||||
// Load all necessary data
|
// Load all necessary data
|
||||||
val productDetails = repository.fetchProductDetail(orderRequest.productIdItem)
|
val productDetails = repository.fetchProductDetail(orderRequest.productIdItem)
|
||||||
|
val storeDetails = repository.getStoreDetails(productDetails.product.storeId)
|
||||||
|
|
||||||
// val addressDetails = repository.getAddressDetails(orderRequest.address_id)
|
// val addressDetails = repository.getAddressDetails(orderRequest.address_id)
|
||||||
|
|
||||||
// Update LiveData objects
|
// Update LiveData objects
|
||||||
@ -42,10 +48,15 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
|||||||
productName = productDetails?.product?.productName,
|
productName = productDetails?.product?.productName,
|
||||||
productImageUrl = productDetails.product.image,
|
productImageUrl = productDetails.product.image,
|
||||||
productPrice = productDetails.product.price,
|
productPrice = productDetails.product.price,
|
||||||
sellerName = productDetails.product.storeId
|
sellerName = storeDetails.store.storeName,
|
||||||
// sellerImageUrl = productDetails.sellerImageUrl,
|
sellerImageUrl = storeDetails.store.storeImage,
|
||||||
// sellerId = productDetails.sellerId
|
sellerId = productDetails.product.storeId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
storeDetails?.let {
|
||||||
|
_storePayments.value = it.payment
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Handle errors
|
// Handle errors
|
||||||
Log.e("CheckoutViewModel", "Error loading checkout data", e)
|
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