mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-09 08:52:21 +00:00
@ -129,5 +129,7 @@ data class OrdersItem(
|
||||
val status: String? = null,
|
||||
|
||||
@field:SerializedName("city_id")
|
||||
val cityId: Int? = null
|
||||
val cityId: Int? = null,
|
||||
|
||||
var displayStatus: String? = null
|
||||
)
|
||||
|
@ -5,56 +5,47 @@ import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import com.alya.ecommerce_serang.R
|
||||
import com.alya.ecommerce_serang.data.api.dto.ProductsItem
|
||||
import com.alya.ecommerce_serang.databinding.FragmentChangePriceBottomSheetBinding
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private const val ARG_PARAM1 = "param1"
|
||||
private const val ARG_PARAM2 = "param2"
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass.
|
||||
* Use the [ChangePriceBottomSheetFragment.newInstance] factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class ChangePriceBottomSheetFragment : Fragment() {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
param1 = it.getString(ARG_PARAM1)
|
||||
param2 = it.getString(ARG_PARAM2)
|
||||
}
|
||||
}
|
||||
class ChangePriceBottomSheetFragment(
|
||||
private val product: ProductsItem,
|
||||
private val onSave: (productId: Int, newPrice: Int) -> Unit
|
||||
) : BottomSheetDialogFragment() {
|
||||
private var _binding: FragmentChangePriceBottomSheetBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_change_price_bottom_sheet, container, false)
|
||||
): View {
|
||||
_binding = FragmentChangePriceBottomSheetBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.header.headerTitle.text = "Atur Harga"
|
||||
binding.header.headerLeftIcon.setImageResource(R.drawable.ic_close)
|
||||
binding.header.headerLeftIcon.setOnClickListener { dismiss() }
|
||||
|
||||
binding.edtPrice.setText(product.price)
|
||||
|
||||
binding.btnSave.setOnClickListener {
|
||||
val newPrice = binding.edtPrice.text.toString().replace(".", "").toIntOrNull()
|
||||
if (newPrice != null && newPrice > 0) {
|
||||
onSave(product.id, newPrice)
|
||||
dismiss()
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Masukkan harga yang valid", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment ChangePriceBottomSheetFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
@JvmStatic
|
||||
fun newInstance(param1: String, param2: String) =
|
||||
ChangePriceBottomSheetFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_PARAM1, param1)
|
||||
putString(ARG_PARAM2, param2)
|
||||
}
|
||||
}
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.alya.ecommerce_serang.ui.profile.mystore.product
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.alya.ecommerce_serang.R
|
||||
import com.alya.ecommerce_serang.data.api.dto.ProductsItem
|
||||
import com.alya.ecommerce_serang.databinding.FragmentChangeStockBottomSheetBinding
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
|
||||
class ChangeStockBottomSheetFragment(
|
||||
private val product: ProductsItem,
|
||||
private val onSave: (productId: Int, newStock: Int) -> Unit
|
||||
): BottomSheetDialogFragment() {
|
||||
private var _binding: FragmentChangeStockBottomSheetBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var stock = 0
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentChangeStockBottomSheetBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.header.headerTitle.text = "Atur Stok"
|
||||
binding.header.headerLeftIcon.setImageResource(R.drawable.ic_close)
|
||||
binding.header.headerLeftIcon.setOnClickListener { dismiss() }
|
||||
|
||||
stock = product.stock
|
||||
updateStock()
|
||||
|
||||
binding.btnMinus.setOnClickListener {
|
||||
if (stock > 0) stock--
|
||||
updateStock()
|
||||
}
|
||||
|
||||
binding.btnPlus.setOnClickListener {
|
||||
stock++
|
||||
updateStock()
|
||||
}
|
||||
|
||||
binding.btnSave.setOnClickListener {
|
||||
onSave(product.id, stock)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun updateStock() {
|
||||
binding.edtStock.setText(stock.toString())
|
||||
if (stock == 0) {
|
||||
binding.btnMinus.isEnabled = false
|
||||
binding.btnMinus.setColorFilter(ContextCompat.getColor(requireContext(), R.color.black_100))
|
||||
} else {
|
||||
binding.btnMinus.isEnabled = true
|
||||
binding.btnMinus.setColorFilter(ContextCompat.getColor(requireContext(), R.color.blue_500))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
@ -20,9 +20,10 @@ class ProductActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityProductBinding
|
||||
private lateinit var sessionManager: SessionManager
|
||||
|
||||
private lateinit var productAdapter: ProductAdapter
|
||||
|
||||
private val viewModel: ProductViewModel by viewModels {
|
||||
BaseViewModelFactory {
|
||||
sessionManager = SessionManager(this)
|
||||
val apiService = ApiConfig.getApiService(sessionManager)
|
||||
val productRepository = ProductRepository(apiService)
|
||||
ProductViewModel(productRepository)
|
||||
@ -30,6 +31,8 @@ class ProductActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
sessionManager = SessionManager(this)
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityProductBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
@ -56,9 +59,18 @@ class ProductActivity : AppCompatActivity() {
|
||||
is Result.Success -> {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
val products = result.data
|
||||
binding.rvStoreProduct.adapter = ProductAdapter(products) {
|
||||
Toast.makeText(this, "Produk: ${it.name}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
productAdapter = ProductAdapter(
|
||||
products,
|
||||
onItemClick = { products ->
|
||||
Toast.makeText(this, "Produk ${products.name} diklik", Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
onUpdateProduct = { productId, updatedFields ->
|
||||
viewModel.updateProduct(productId, updatedFields)
|
||||
}
|
||||
)
|
||||
|
||||
binding.rvStoreProduct.adapter = productAdapter
|
||||
}
|
||||
is Result.Error -> {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
@ -66,6 +78,19 @@ class ProductActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.productUpdateResult.observe(this) { result ->
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
Toast.makeText(this, "Produk berhasil diperbarui", Toast.LENGTH_SHORT).show()
|
||||
viewModel.loadMyStoreProducts()
|
||||
}
|
||||
is Result.Error -> {
|
||||
Toast.makeText(this, "Gagal memperbarui produk", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupHeader() {
|
||||
|
@ -3,6 +3,7 @@ package com.alya.ecommerce_serang.ui.profile.mystore.product
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
@ -15,10 +16,14 @@ import com.alya.ecommerce_serang.R
|
||||
import com.alya.ecommerce_serang.data.api.dto.Product
|
||||
import com.alya.ecommerce_serang.data.api.dto.ProductsItem
|
||||
import com.bumptech.glide.Glide
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
|
||||
class ProductAdapter(
|
||||
private val products: List<ProductsItem>,
|
||||
private val onItemClick: (ProductsItem) -> Unit
|
||||
private val onItemClick: (ProductsItem) -> Unit,
|
||||
private val onUpdateProduct: (productId: Int, updatedFields: Map<String, RequestBody>) -> Unit
|
||||
) : RecyclerView.Adapter<ProductAdapter.ProductViewHolder>() {
|
||||
|
||||
inner class ProductViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
@ -28,6 +33,8 @@ class ProductAdapter(
|
||||
private val tvProductStock: TextView = itemView.findViewById(R.id.tv_product_stock)
|
||||
private val tvProductStatus: TextView = itemView.findViewById(R.id.tv_product_status)
|
||||
private val ivMenu: ImageView = itemView.findViewById(R.id.iv_menu)
|
||||
private val btnChangePrice: Button = itemView.findViewById(R.id.btn_change_price)
|
||||
private val btnChangeStock: Button = itemView.findViewById(R.id.btn_change_stock)
|
||||
|
||||
fun bind(product: ProductsItem) {
|
||||
tvProductName.text = product.name
|
||||
@ -55,7 +62,6 @@ class ProductAdapter(
|
||||
.into(ivProduct)
|
||||
|
||||
ivMenu.setOnClickListener {
|
||||
// Show Bottom Sheet when menu is clicked
|
||||
val bottomSheetFragment = ProductOptionsBottomSheetFragment(product)
|
||||
bottomSheetFragment.show(
|
||||
(itemView.context as FragmentActivity).supportFragmentManager,
|
||||
@ -63,6 +69,36 @@ class ProductAdapter(
|
||||
)
|
||||
}
|
||||
|
||||
btnChangePrice.setOnClickListener {
|
||||
val bottomSheetFragment = ChangePriceBottomSheetFragment(product) { id, newPrice ->
|
||||
val body = mapOf(
|
||||
"product_id" to id.toString().toRequestBody("text/plain".toMediaTypeOrNull()),
|
||||
"price" to newPrice.toString().toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
)
|
||||
onUpdateProduct(id, body)
|
||||
Toast.makeText(itemView.context, "Harga berhasil diubah", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
bottomSheetFragment.show(
|
||||
(itemView.context as FragmentActivity).supportFragmentManager,
|
||||
bottomSheetFragment.tag
|
||||
)
|
||||
}
|
||||
|
||||
btnChangeStock.setOnClickListener {
|
||||
val bottomSheetFragment = ChangeStockBottomSheetFragment(product) { id, newStock ->
|
||||
val body = mapOf(
|
||||
"product_id" to id.toString().toRequestBody("text/plain".toMediaTypeOrNull()),
|
||||
"stock" to newStock.toString().toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
)
|
||||
onUpdateProduct(id, body)
|
||||
Toast.makeText(itemView.context, "Stok berhasil diubah", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
bottomSheetFragment.show(
|
||||
(itemView.context as FragmentActivity).supportFragmentManager,
|
||||
bottomSheetFragment.tag
|
||||
)
|
||||
}
|
||||
|
||||
itemView.setOnClickListener {
|
||||
onItemClick(product)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ class SellsAdapter(
|
||||
Log.d("SellsAdapter", "=== ViewHolder.bind() called ===")
|
||||
Log.d("SellsAdapter", "Binding order: ${order.orderId} with status: ${order.status}")
|
||||
|
||||
val actualStatus = if (fragmentStatus == "all") order.status ?: "" else fragmentStatus
|
||||
val actualStatus = if (fragmentStatus == "all") order.displayStatus ?: "" else fragmentStatus
|
||||
adjustDisplay(actualStatus, order)
|
||||
|
||||
tvSellsNumber.text = "No. Pesanan: ${order.orderId}"
|
||||
|
@ -6,6 +6,7 @@ import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.alya.ecommerce_serang.data.api.response.store.sells.Orders
|
||||
import com.alya.ecommerce_serang.data.api.response.store.sells.OrdersItem
|
||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||
@ -13,6 +14,7 @@ import com.alya.ecommerce_serang.data.repository.AddressRepository
|
||||
import com.alya.ecommerce_serang.data.repository.SellsRepository
|
||||
import com.alya.ecommerce_serang.databinding.ActivityDetailShipmentBinding
|
||||
import com.alya.ecommerce_serang.ui.profile.mystore.sells.SellsProductAdapter
|
||||
import com.alya.ecommerce_serang.ui.profile.mystore.sells.payment.DetailPaymentActivity
|
||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||
import com.alya.ecommerce_serang.utils.SessionManager
|
||||
import com.alya.ecommerce_serang.utils.viewmodel.AddressViewModel
|
||||
@ -51,6 +53,12 @@ class DetailShipmentActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
productAdapter = SellsProductAdapter()
|
||||
binding.rvProductItems.apply {
|
||||
adapter = productAdapter
|
||||
layoutManager = LinearLayoutManager(this@DetailShipmentActivity)
|
||||
}
|
||||
|
||||
val sellsJson = intent.getStringExtra("sells_data")
|
||||
if (sellsJson != null) {
|
||||
try {
|
||||
|
@ -111,9 +111,9 @@ class ProductViewModel(private val repository: ProductRepository) : ViewModel()
|
||||
fun updateProduct(
|
||||
productId: Int?,
|
||||
data: Map<String, RequestBody>,
|
||||
image: MultipartBody.Part?,
|
||||
halal: MultipartBody.Part?,
|
||||
sppirt: MultipartBody.Part?
|
||||
image: MultipartBody.Part? = null,
|
||||
halal: MultipartBody.Part? = null,
|
||||
sppirt: MultipartBody.Part? = null
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
_productUpdateResult.postValue(Result.Loading)
|
||||
|
@ -14,7 +14,12 @@ import com.alya.ecommerce_serang.data.api.response.store.sells.PaymentConfirmati
|
||||
import com.alya.ecommerce_serang.data.repository.Result
|
||||
import com.alya.ecommerce_serang.data.repository.SellsRepository
|
||||
import com.alya.ecommerce_serang.ui.order.address.ViewState
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
|
||||
@ -59,79 +64,128 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
Log.d(TAG, "Coroutine launched successfully")
|
||||
|
||||
try {
|
||||
Log.d(TAG, "Calling repository.getSellList(status='$status')")
|
||||
val startTime = System.currentTimeMillis()
|
||||
if(status == "all") {
|
||||
Log.d(TAG, "Status is 'all', calling repository.getSellList()")
|
||||
val allStatuses = listOf("pending", "unpaid", "processed", "shipped")
|
||||
val allSells = mutableListOf<OrdersItem>()
|
||||
|
||||
when (val result = repository.getSellList(status)) {
|
||||
is Result.Success -> {
|
||||
val endTime = System.currentTimeMillis()
|
||||
Log.d(TAG, "Repository call completed in ${endTime - startTime}ms")
|
||||
Log.d(TAG, "Result.Success received from repository")
|
||||
|
||||
// Log the entire result data structure
|
||||
Log.d(TAG, "Raw result data: ${result.data}")
|
||||
Log.d(TAG, "Result data class: ${result.data.javaClass.simpleName}")
|
||||
|
||||
val orders = result.data.orders
|
||||
Log.d(TAG, "Extracted orders list: $orders")
|
||||
Log.d(TAG, "Orders list class: ${orders.javaClass.simpleName}")
|
||||
Log.d(TAG, "Orders count: ${orders.size}")
|
||||
|
||||
// Check if orders list is null or empty
|
||||
if (false) {
|
||||
Log.w(TAG, "⚠️ Orders list is NULL")
|
||||
} else if (orders.isEmpty()) {
|
||||
Log.w(TAG, "⚠️ Orders list is EMPTY")
|
||||
} else {
|
||||
Log.d(TAG, "✅ Orders list contains ${orders.size} items")
|
||||
|
||||
// Log individual order details with more comprehensive info
|
||||
orders.forEachIndexed { index, order ->
|
||||
Log.d(TAG, "--- Order ${index + 1}/${orders.size} ---")
|
||||
Log.d(TAG, " Order object: $order")
|
||||
Log.d(TAG, " Order class: ${order.javaClass.simpleName}")
|
||||
Log.d(TAG, " - ID: ${order.orderId}")
|
||||
Log.d(TAG, " - Status: '${order.status}'")
|
||||
Log.d(TAG, " - Customer: '${order.username}'")
|
||||
Log.d(TAG, " - Total: ${order.totalAmount}")
|
||||
Log.d(TAG, " - Items count: ${order.orderItems?.size ?: 0}")
|
||||
Log.d(TAG, " - Created at: ${order.createdAt}")
|
||||
Log.d(TAG, " - Updated at: ${order.updatedAt}")
|
||||
|
||||
// Log order items if available
|
||||
order.orderItems?.let { items ->
|
||||
Log.d(TAG, " Order items:")
|
||||
items.forEachIndexed { itemIndex, item ->
|
||||
Log.d(TAG, " Item ${itemIndex + 1}: ${item?.productName} (Qty: ${item?.quantity})")
|
||||
coroutineScope {
|
||||
val deferreds = allStatuses.map { status ->
|
||||
async {
|
||||
when (val result = repository.getSellList(status)) {
|
||||
is Result.Success -> {
|
||||
result.data.orders.onEach { it.displayStatus = status }
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error loading orders for status $status",
|
||||
result.exception
|
||||
)
|
||||
emptyList<OrdersItem>()
|
||||
}
|
||||
|
||||
is Result.Loading -> emptyList<OrdersItem>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the ViewState to Success
|
||||
_sells.value = ViewState.Success(orders)
|
||||
Log.d(TAG, "✅ ViewState.Success set with ${orders.size} orders")
|
||||
deferreds.awaitAll().forEach { orders ->
|
||||
allSells.addAll(orders)
|
||||
}
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
val endTime = System.currentTimeMillis()
|
||||
Log.e(TAG, "Repository call failed in ${endTime - startTime}ms")
|
||||
Log.e(TAG, "❌ Result.Error received from repository")
|
||||
Log.e(TAG, "Error message: ${result.exception.message}")
|
||||
Log.e(TAG, "Exception type: ${result.exception.javaClass.simpleName}")
|
||||
Log.e(TAG, "Exception stack trace:", result.exception)
|
||||
|
||||
val errorMessage = result.exception.message ?: "Unknown error occurred"
|
||||
_sells.value = ViewState.Error(errorMessage)
|
||||
Log.d(TAG, "ViewState.Error set with message: '$errorMessage'")
|
||||
val sortedSells = allSells.sortedByDescending { order ->
|
||||
try {
|
||||
SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
|
||||
Locale.getDefault()
|
||||
).parse(order.createdAt)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
is Result.Loading -> {
|
||||
Log.d(TAG, "Result.Loading received from repository (this is unusual)")
|
||||
// Keep the current loading state
|
||||
_sells.value = ViewState.Success(sortedSells)
|
||||
Log.d(TAG, "All orders loaded successfully: ${sortedSells.size} items")
|
||||
} else {
|
||||
Log.d(TAG, "Calling repository.getSellList(status='$status')")
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
when (val result = repository.getSellList(status)) {
|
||||
is Result.Success -> {
|
||||
val endTime = System.currentTimeMillis()
|
||||
Log.d(TAG, "Repository call completed in ${endTime - startTime}ms")
|
||||
Log.d(TAG, "Result.Success received from repository")
|
||||
|
||||
// Log the entire result data structure
|
||||
Log.d(TAG, "Raw result data: ${result.data}")
|
||||
Log.d(TAG, "Result data class: ${result.data.javaClass.simpleName}")
|
||||
|
||||
val orders = result.data.orders
|
||||
Log.d(TAG, "Extracted orders list: $orders")
|
||||
Log.d(TAG, "Orders list class: ${orders.javaClass.simpleName}")
|
||||
Log.d(TAG, "Orders count: ${orders.size}")
|
||||
|
||||
// Check if orders list is null or empty
|
||||
if (false) {
|
||||
Log.w(TAG, "⚠️ Orders list is NULL")
|
||||
} else if (orders.isEmpty()) {
|
||||
Log.w(TAG, "⚠️ Orders list is EMPTY")
|
||||
} else {
|
||||
Log.d(TAG, "✅ Orders list contains ${orders.size} items")
|
||||
|
||||
// Log individual order details with more comprehensive info
|
||||
orders.forEachIndexed { index, order ->
|
||||
Log.d(TAG, "--- Order ${index + 1}/${orders.size} ---")
|
||||
Log.d(TAG, " Order object: $order")
|
||||
Log.d(TAG, " Order class: ${order.javaClass.simpleName}")
|
||||
Log.d(TAG, " - ID: ${order.orderId}")
|
||||
Log.d(TAG, " - Status: '${order.status}'")
|
||||
Log.d(TAG, " - Customer: '${order.username}'")
|
||||
Log.d(TAG, " - Total: ${order.totalAmount}")
|
||||
Log.d(TAG, " - Items count: ${order.orderItems?.size ?: 0}")
|
||||
Log.d(TAG, " - Created at: ${order.createdAt}")
|
||||
Log.d(TAG, " - Updated at: ${order.updatedAt}")
|
||||
|
||||
// Log order items if available
|
||||
order.orderItems?.let { items ->
|
||||
Log.d(TAG, " Order items:")
|
||||
items.forEachIndexed { itemIndex, item ->
|
||||
Log.d(
|
||||
TAG,
|
||||
" Item ${itemIndex + 1}: ${item?.productName} (Qty: ${item?.quantity})"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the ViewState to Success
|
||||
_sells.value = ViewState.Success(orders)
|
||||
Log.d(TAG, "✅ ViewState.Success set with ${orders.size} orders")
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
val endTime = System.currentTimeMillis()
|
||||
Log.e(TAG, "Repository call failed in ${endTime - startTime}ms")
|
||||
Log.e(TAG, "❌ Result.Error received from repository")
|
||||
Log.e(TAG, "Error message: ${result.exception.message}")
|
||||
Log.e(TAG, "Exception type: ${result.exception.javaClass.simpleName}")
|
||||
Log.e(TAG, "Exception stack trace:", result.exception)
|
||||
|
||||
val errorMessage = result.exception.message ?: "Unknown error occurred"
|
||||
_sells.value = ViewState.Error(errorMessage)
|
||||
Log.d(TAG, "ViewState.Error set with message: '$errorMessage'")
|
||||
}
|
||||
|
||||
is Result.Loading -> {
|
||||
Log.d(TAG, "Result.Loading received from repository (this is unusual)")
|
||||
// Keep the current loading state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Exception caught in getSellList")
|
||||
Log.e(TAG, "Exception type: ${e.javaClass.simpleName}")
|
||||
|
BIN
app/src/main/res/drawable/ic_add.png
Normal file
BIN
app/src/main/res/drawable/ic_add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 261 B |
BIN
app/src/main/res/drawable/ic_minus.png
Normal file
BIN
app/src/main/res/drawable/ic_minus.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 187 B |
@ -1,14 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.profile.mystore.product.ChangePriceBottomSheetFragment">
|
||||
tools:context=".ui.profile.mystore.product.ChangePriceBottomSheetFragment"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
<include
|
||||
android:id="@+id/header"
|
||||
layout="@layout/header" />
|
||||
|
||||
<!-- Input Harga dengan Prefix "Rp" -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:background="@drawable/bg_text_field"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginHorizontal="16dp">
|
||||
|
||||
</FrameLayout>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Rp"
|
||||
style="@style/label_medium_prominent"
|
||||
android:textColor="@color/black_300"
|
||||
android:padding="8dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edt_price"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:hint="Isi harga produk di sini"
|
||||
android:inputType="number"
|
||||
android:padding="8dp"
|
||||
style="@style/body_small" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_save"
|
||||
android:text="Simpan"
|
||||
style="@style/button.large.active.long"
|
||||
android:enabled="true"
|
||||
android:layout_marginVertical="16dp"
|
||||
android:layout_marginHorizontal="16dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.profile.mystore.product.ChangeStockBottomSheetFragment"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/header"
|
||||
layout="@layout/header" />
|
||||
|
||||
<!-- Input Harga dengan Prefix "Rp" -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:background="@drawable/bg_text_field"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_minus"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_margin="5dp"
|
||||
android:src="@drawable/ic_minus"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edt_stock"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:hint="Isi stok produk di sini"
|
||||
android:inputType="number"
|
||||
android:padding="8dp"
|
||||
style="@style/body_small" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_plus"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_margin="5dp"
|
||||
android:src="@drawable/ic_add"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_save"
|
||||
android:text="Simpan"
|
||||
style="@style/button.large.active.long"
|
||||
android:enabled="true"
|
||||
android:layout_marginVertical="16dp"
|
||||
android:layout_marginHorizontal="16dp"/>
|
||||
|
||||
</LinearLayout>
|
Reference in New Issue
Block a user