mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-14 11:02:21 +00:00
@ -4,10 +4,14 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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
|
||||
|
||||
@ -22,27 +26,37 @@ class ProductAdapter(
|
||||
private val tvProductPrice: TextView = itemView.findViewById(R.id.tv_product_price)
|
||||
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)
|
||||
|
||||
fun bind(product: ProductsItem) {
|
||||
tvProductName.text = product.name
|
||||
tvProductPrice.text = "Rp${product.price}"
|
||||
tvProductStock.text = "Stok: ${product.stock}"
|
||||
tvProductStatus.text = product.status
|
||||
|
||||
// Change color depending on status
|
||||
tvProductStatus.setTextColor(
|
||||
ContextCompat.getColor(
|
||||
itemView.context,
|
||||
if (product.status.equals("active", true))
|
||||
R.color.darkblue_500 else R.color.black_500
|
||||
)
|
||||
)
|
||||
if (product.status.equals("active",true)) {
|
||||
tvProductStatus.text = "Aktif"
|
||||
tvProductStatus.setTextColor(ContextCompat.getColor(itemView.context, R.color.darkblue_500))
|
||||
tvProductStatus.background = ContextCompat.getDrawable(itemView.context, R.drawable.bg_product_active)
|
||||
} else {
|
||||
tvProductStatus.text = "Nonaktif"
|
||||
tvProductStatus.setTextColor(ContextCompat.getColor(itemView.context, R.color.black_500))
|
||||
tvProductStatus.background = ContextCompat.getDrawable(itemView.context, R.drawable.bg_product_inactive)
|
||||
}
|
||||
|
||||
Glide.with(itemView.context)
|
||||
.load(product.image)
|
||||
.placeholder(R.drawable.placeholder_image)
|
||||
.into(ivProduct)
|
||||
|
||||
ivMenu.setOnClickListener {
|
||||
// Show Bottom Sheet when menu is clicked
|
||||
val bottomSheetFragment = ProductOptionsBottomSheetFragment(product)
|
||||
bottomSheetFragment.show(
|
||||
(itemView.context as FragmentActivity).supportFragmentManager,
|
||||
bottomSheetFragment.tag
|
||||
)
|
||||
}
|
||||
|
||||
itemView.setOnClickListener {
|
||||
onItemClick(product)
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
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 com.alya.ecommerce_serang.R
|
||||
import com.alya.ecommerce_serang.data.api.dto.ProductsItem
|
||||
import com.alya.ecommerce_serang.databinding.FragmentProductOptionsBottomSheetBinding
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
|
||||
class ProductOptionsBottomSheetFragment(private val product: ProductsItem) : BottomSheetDialogFragment() {
|
||||
|
||||
private var _binding: FragmentProductOptionsBottomSheetBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentProductOptionsBottomSheetBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.btnEditProduct.setOnClickListener {
|
||||
// Handle editing product
|
||||
// Example: Open the edit activity or fragment
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.btnDeleteProduct.setOnClickListener {
|
||||
// Handle deleting product
|
||||
// Example: Show confirmation dialog
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
@ -188,14 +188,14 @@ class StoreProductDetailActivity : AppCompatActivity() {
|
||||
val status = if (binding.switchIsActive.isChecked) "active" else "inactive"
|
||||
val categoryId = categoryList.getOrNull(binding.spinnerKategoriProduk.selectedItemPosition)?.id ?: 0
|
||||
|
||||
val imageFile = imageUri?.let { File(it.path) }
|
||||
val imageFile = imageUri?.let { uriToNamedFile(it, this, "productimg") }
|
||||
val sppirtFile = sppirtUri?.let { uriToNamedFile(it, this, "sppirt") }
|
||||
val halalFile = halalUri?.let { uriToNamedFile(it, this, "halal") }
|
||||
|
||||
Log.d("File URI", "SPPIRT URI: ${sppirtUri.toString()}")
|
||||
Log.d("File URI", "Halal URI: ${halalUri.toString()}")
|
||||
|
||||
val imagePart = imageFile?.let { createPartFromFile("image", it) }
|
||||
val imagePart = imageFile?.let { createPartFromFile("productimg", it) }
|
||||
val sppirtPart = sppirtFile?.let { createPartFromFile("sppirt", it) }
|
||||
val halalPart = halalFile?.let { createPartFromFile("halal", it) }
|
||||
|
||||
@ -219,9 +219,20 @@ class StoreProductDetailActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getMimeType(file: File): String {
|
||||
val extension = file.extension
|
||||
return when (extension.lowercase()) {
|
||||
"jpg", "jpeg" -> "image/jpeg"
|
||||
"png" -> "image/png"
|
||||
"pdf" -> "application/pdf"
|
||||
else -> "application/octet-stream"
|
||||
}
|
||||
}
|
||||
|
||||
fun createPartFromFile(field: String, file: File?): MultipartBody.Part? {
|
||||
return file?.let {
|
||||
val requestBody = RequestBody.create("application/octet-stream".toMediaTypeOrNull(), it)
|
||||
val mimeType = getMimeType(it).toMediaTypeOrNull()
|
||||
val requestBody = RequestBody.create(mimeType, it)
|
||||
MultipartBody.Part.createFormData(field, it.name, requestBody)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user