mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-10 09:22:21 +00:00
not fixed order seller
This commit is contained in:
@ -100,6 +100,10 @@ class SellsAdapter(
|
||||
|
||||
tvSellsQty.text = "${sells.orderItems?.size} produk"
|
||||
tvSellsPrice.text = "Rp${sells.totalAmount}"
|
||||
//
|
||||
// itemView.setOnClickListener {
|
||||
// onOrderClickListener(sells)
|
||||
// }
|
||||
|
||||
adjustDisplay(fragmentStatus, sells)
|
||||
}
|
||||
@ -108,7 +112,7 @@ class SellsAdapter(
|
||||
Log.d("SellsAdapter", "Adjusting display for status: $status")
|
||||
|
||||
when (status) {
|
||||
"pending" -> {
|
||||
"pending", "unpaid" -> {
|
||||
layoutOrders.visibility = View.VISIBLE
|
||||
layoutPayments.visibility = View.GONE
|
||||
layoutShipments.visibility = View.GONE
|
||||
@ -125,6 +129,20 @@ class SellsAdapter(
|
||||
tvSellsPrice = itemView.findViewById(R.id.tv_order_price)
|
||||
|
||||
tvSellsDue.text = formatDueDate(sells.updatedAt.toString(), 1)
|
||||
|
||||
val product = sells.orderItems?.get(0)
|
||||
product?.let {
|
||||
tvSellsProductName.text = it.productName
|
||||
tvSellsProductQty.text = "x${it.quantity}"
|
||||
tvSellsProductPrice.text = "Rp${it.price}"
|
||||
Glide.with(itemView.context)
|
||||
.load(it.productImage)
|
||||
.placeholder(R.drawable.placeholder_image)
|
||||
.into(ivSellsProduct)
|
||||
}
|
||||
|
||||
tvSellsQty.text = "${sells.orderItems?.size} produk"
|
||||
tvSellsPrice.text = "Rp${sells.totalAmount}"
|
||||
}
|
||||
"paid" -> {
|
||||
layoutOrders.visibility = View.GONE
|
||||
@ -133,11 +151,18 @@ class SellsAdapter(
|
||||
|
||||
tvSellsDue.text = formatDueDate(sells.updatedAt.toString(), 2)
|
||||
btnConfirmPayment.setOnClickListener {
|
||||
|
||||
val context = itemView.context
|
||||
val intent = Intent(context, DetailPaymentActivity::class.java)
|
||||
intent.putExtra("sells_data", Gson().toJson(sells))
|
||||
context.startActivity(intent)
|
||||
viewModel.refreshOrders()
|
||||
}
|
||||
|
||||
tvSellsTitle.text = "Pesanan Telah Dibayar"
|
||||
tvSellsDueDesc.text = "Konfirmasi pembayaran sebelum:"
|
||||
tvSellsDue.text = formatDueDate(sells.updatedAt.toString(), 2)
|
||||
|
||||
}
|
||||
"processed" -> {
|
||||
layoutOrders.visibility = View.GONE
|
||||
@ -160,6 +185,12 @@ class SellsAdapter(
|
||||
intent.putExtra("sells_data", Gson().toJson(sells))
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
tvSellsTitle.text = "Pesanan Perlu Dikirim"
|
||||
tvSellsNumber.text = "No. Pesanan: ${sells.orderId}"
|
||||
tvSellsLocation.text = sells.subdistrict
|
||||
tvSellsCustomer.text = sells.username
|
||||
tvSellsDue.text = formatDueDate(sells.updatedAt.toString(), 2)
|
||||
}
|
||||
"shipped" -> {
|
||||
layoutOrders.visibility = View.GONE
|
||||
|
@ -1,14 +1,16 @@
|
||||
package com.alya.ecommerce_serang.ui.profile.mystore.sells
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.alya.ecommerce_serang.R
|
||||
import com.alya.ecommerce_serang.databinding.FragmentSellsBinding
|
||||
import com.alya.ecommerce_serang.utils.SessionManager
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
|
||||
class SellsFragment : Fragment() {
|
||||
|
||||
@ -30,27 +32,62 @@ class SellsFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
sessionManager = SessionManager(requireContext())
|
||||
|
||||
setupViewPager()
|
||||
}
|
||||
|
||||
private fun setupViewPager() {
|
||||
viewPagerAdapter = SellsViewPagerAdapter(requireActivity())
|
||||
binding.viewPagerSells.adapter = viewPagerAdapter
|
||||
|
||||
val tabs = listOf(
|
||||
"Semua Pesanan",
|
||||
"Pesanan Masuk",
|
||||
"Konfirmasi Pembayaran",
|
||||
"Perlu Dikirim",
|
||||
"Dikirim",
|
||||
"Selesai",
|
||||
"Pembatalan",
|
||||
"Klaim Pembayaran"
|
||||
)
|
||||
|
||||
TabLayoutMediator(binding.tabLayoutSells, binding.viewPagerSells) { tab, position ->
|
||||
tab.text = tabs[position]
|
||||
TabLayoutMediator(binding.tabLayoutSells, binding.viewPagerSells) {tab, position ->
|
||||
tab.text = when(position){
|
||||
0 -> getString(R.string.all_orders)
|
||||
1 -> getString(R.string.pending_orders)
|
||||
2 -> getString(R.string.unpaid_orders)
|
||||
3 -> getString(R.string.processed_orders)
|
||||
4 -> getString(R.string.paid_orders)
|
||||
5 -> getString(R.string.shipped_orders)
|
||||
6 -> getString(R.string.completed_orders)
|
||||
7 -> getString(R.string.canceled_orders)
|
||||
else -> "Tab $position"
|
||||
}
|
||||
}.attach()
|
||||
|
||||
binding.viewPagerSells.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
super.onPageSelected(position)
|
||||
|
||||
val statusList = listOf("all", "pending", "unpaid", "processed", "paid", "shipped", "completed", "canceled")
|
||||
val selectedStatus = statusList.getOrNull(position) ?: "unknown"
|
||||
val tabText = when(position) {
|
||||
0 -> getString(R.string.all_orders)
|
||||
1 -> getString(R.string.pending_orders)
|
||||
2 -> getString(R.string.unpaid_orders)
|
||||
3 -> getString(R.string.processed_orders)
|
||||
4 -> getString(R.string.paid_orders)
|
||||
5 -> getString(R.string.shipped_orders)
|
||||
6 -> getString(R.string.completed_orders)
|
||||
7 -> getString(R.string.canceled_orders)
|
||||
else -> "Tab $position"
|
||||
}
|
||||
|
||||
Log.d(TAG, "🔄 *** TAB SWITCHED ***")
|
||||
Log.d(TAG, "Selected position: $position")
|
||||
Log.d(TAG, "Tab text: '$tabText'")
|
||||
Log.d(TAG, "Status for this tab: '$selectedStatus'")
|
||||
Log.d(TAG, "*** This should trigger SellsListFragment for '$selectedStatus' ***")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SellsListFragment"
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.alya.ecommerce_serang.ui.profile.mystore.sells
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -34,6 +35,23 @@ class SellsListFragment : Fragment() {
|
||||
private lateinit var sellsAdapter: SellsAdapter
|
||||
private var status: String = "all"
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SellsListFragment"
|
||||
private const val ARG_STATUS = "status"
|
||||
|
||||
fun newInstance(status: String): SellsListFragment {
|
||||
Log.d(TAG, "=== Creating new instance ===")
|
||||
Log.d(TAG, "Status: '$status'")
|
||||
|
||||
return SellsListFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_STATUS, status)
|
||||
}
|
||||
Log.d(TAG, "Fragment instance created with status: '$status'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
sessionManager = SessionManager(requireContext())
|
||||
@ -63,33 +81,29 @@ class SellsListFragment : Fragment() {
|
||||
_binding = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ARG_STATUS = "status"
|
||||
|
||||
fun newInstance(status: String): SellsListFragment {
|
||||
return SellsListFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_STATUS, status)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
sellsAdapter = SellsAdapter(
|
||||
onOrderClickListener = { sells ->
|
||||
// Handle order click
|
||||
Log.d(TAG, "Order clicked: ${sells.orderId} in status '$status'")
|
||||
navigateToSellsDetail(sells)
|
||||
},
|
||||
viewModel = viewModel
|
||||
)
|
||||
|
||||
Log.d(TAG, "Setting adapter fragment status to: '$status'")
|
||||
sellsAdapter.setFragmentStatus(status)
|
||||
|
||||
binding.rvSells.apply {
|
||||
layoutManager = LinearLayoutManager(requireContext())
|
||||
adapter = sellsAdapter
|
||||
Log.d(TAG, "RecyclerView configured with LinearLayoutManager and adapter")
|
||||
}
|
||||
|
||||
// Log RecyclerView visibility and properties
|
||||
Log.d(TAG, "RecyclerView visibility: ${binding.rvSells.visibility}")
|
||||
Log.d(TAG, "RecyclerView parent: ${binding.rvSells.parent}")
|
||||
}
|
||||
|
||||
private fun observeSellsList() {
|
||||
@ -104,7 +118,21 @@ class SellsListFragment : Fragment() {
|
||||
} else {
|
||||
binding.tvEmptyState.visibility = View.GONE
|
||||
binding.rvSells.visibility = View.VISIBLE
|
||||
result.data.forEachIndexed { index, order ->
|
||||
Log.d(TAG, "Order $index:")
|
||||
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: ${order.orderItems?.size ?: 0}")
|
||||
}
|
||||
sellsAdapter.submitList(result.data)
|
||||
|
||||
Log.d(TAG, "Final UI state:")
|
||||
Log.d(TAG, " - ProgressBar visibility: ${binding.progressBar.visibility}")
|
||||
Log.d(TAG, " - EmptyState visibility: ${binding.tvEmptyState.visibility}")
|
||||
Log.d(TAG, " - RecyclerView visibility: ${binding.rvSells.visibility}")
|
||||
Log.d(TAG, " - Adapter item count: ${sellsAdapter.itemCount}")
|
||||
}
|
||||
}
|
||||
is ViewState.Error -> {
|
||||
@ -113,13 +141,16 @@ class SellsListFragment : Fragment() {
|
||||
Toast.makeText(requireContext(), result.message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
is ViewState.Loading -> {
|
||||
null
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
binding.rvSells.visibility = View.GONE
|
||||
binding.tvEmptyState.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadSells() {
|
||||
Log.d(TAG, "Calling viewModel.getSellList('$status')")
|
||||
viewModel.getSellList(status)
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,53 @@
|
||||
package com.alya.ecommerce_serang.ui.profile.mystore.sells
|
||||
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import io.ktor.client.utils.EmptyContent.status
|
||||
|
||||
class SellsViewPagerAdapter(fragmentActivity: FragmentActivity)
|
||||
: FragmentStateAdapter(fragmentActivity) {
|
||||
|
||||
private val sellsStatuses = listOf(
|
||||
"all", // Semua Pesanan
|
||||
"pending", // Pesanan Masuk
|
||||
"processed", // Konfirmasi Pembayaran
|
||||
"paid", // Perlu Dikirim
|
||||
"shipped", // Dikirim
|
||||
"completed", // Selesai
|
||||
"canceled", // Dibatalkan
|
||||
"payment_onhold"
|
||||
"all", // Position 0: "Semua Pesanan"
|
||||
"pending", // Position 1: "Menunggu Tagihan"
|
||||
"unpaid", // Position 2: "Konfirmasi Bayar"
|
||||
"paid", // Position 3: "Diproses"
|
||||
"processed", // Position 4: "Sudah Dibayar"
|
||||
"shipped", // Position 5: "Dikirim"
|
||||
"completed", // Position 6: "Selesai"
|
||||
"canceled" // Position 7: "Dibatalkan"
|
||||
)
|
||||
|
||||
init {
|
||||
Log.d(TAG, "=== ViewPager Status Mapping ===")
|
||||
sellsStatuses.forEachIndexed { index, status ->
|
||||
val tabText = when(index) {
|
||||
0 -> "Semua Pesanan"
|
||||
1 -> "Menunggu Tagihan"
|
||||
2 -> "Konfirmasi Bayar"
|
||||
3 -> "Diproses"
|
||||
4 -> "Sudah Dibayar"
|
||||
5 -> "Dikirim"
|
||||
6 -> "Selesai"
|
||||
7 -> "Dibatalkan"
|
||||
else -> "Tab $index"
|
||||
}
|
||||
Log.d(TAG, "Position $index: '$tabText' → Status: '$status'")
|
||||
}
|
||||
Log.d(TAG, "=== End Mapping ===")
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int = sellsStatuses.size
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
Log.d(TAG, "Creating fragment for position $position with status: '$status'")
|
||||
return SellsListFragment.newInstance(sellsStatuses[position])
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SellsViewPagerAdapter"
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
val sells: LiveData<ViewState<List<OrdersItem>>> = _sells
|
||||
|
||||
fun getSellList(status: String) {
|
||||
Log.d(TAG, "Requested status: '$status'")
|
||||
_sells.value = ViewState.Loading
|
||||
|
||||
viewModelScope.launch {
|
||||
@ -29,6 +30,20 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
try {
|
||||
when (val result = repository.getSellList(status)) {
|
||||
is Result.Success -> {
|
||||
val orders = result.data.orders
|
||||
Log.d(TAG, "Orders list: $orders")
|
||||
Log.d(TAG, "Orders count: ${orders?.size ?: 0}")
|
||||
|
||||
// Log individual order details
|
||||
orders?.forEachIndexed { index, order ->
|
||||
Log.d(TAG, "Order $index:")
|
||||
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, " - Updated at: ${order.updatedAt}")
|
||||
}
|
||||
_sells.value = ViewState.Success(result.data.orders)
|
||||
Log.d("SellsViewModel", "Sells loaded successfully: ${result.data.orders?.size} items")
|
||||
}
|
||||
@ -58,4 +73,13 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshOrders(status: String = "all") {
|
||||
Log.d(TAG, "Refreshing orders with status: $status")
|
||||
// Clear current orders before fetching new ones
|
||||
_sells.value = ViewState.Loading
|
||||
|
||||
// Re-fetch the orders with the current status
|
||||
getSellList(status)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user