Compare commits

...

4 Commits

Author SHA1 Message Date
ed60528049 add account name 2025-08-12 00:44:35 +07:00
a9c2f9c103 fix validation file upliad 2025-08-11 22:47:00 +07:00
eab3884fd6 Merge remote-tracking branch 'origin/master' 2025-08-11 20:32:11 +07:00
930688f50d update postalcode 2025-08-11 20:31:45 +07:00
5 changed files with 169 additions and 74 deletions

View File

@ -278,6 +278,11 @@ class UserRepository(private val apiService: ApiService) {
val requestFile = compressedFile.asRequestBody(mimeType.toMediaTypeOrNull()) val requestFile = compressedFile.asRequestBody(mimeType.toMediaTypeOrNull())
Log.d(TAG, "$formName compressed size: ${compressedFile.length() / 1024} KB") Log.d(TAG, "$formName compressed size: ${compressedFile.length() / 1024} KB")
val compressedSizeMB = compressedFile.length().toDouble() / (1024 * 1024)
if (compressedSizeMB > 1) {
throw IllegalArgumentException("$formName lebih dari 1 MB setelah kompresi")
}
MultipartBody.Part.createFormData(formName, compressedFile.name, requestFile) MultipartBody.Part.createFormData(formName, compressedFile.name, requestFile)
} else { } else {
throw IllegalArgumentException("$formName harus berupa file gambar (JPEG, JPG, atau PNG)") throw IllegalArgumentException("$formName harus berupa file gambar (JPEG, JPG, atau PNG)")

View File

@ -250,7 +250,7 @@ class RegisterStep3Fragment : Fragment() {
binding.autoCompleteDesa.setOnItemClickListener{ _, _, position, _ -> binding.autoCompleteDesa.setOnItemClickListener{ _, _, position, _ ->
val villageId = villagesAdapter.getVillageId(position) val villageId = villagesAdapter.getVillageId(position)
val postalCode = villagesAdapter.getPostalCode(position) // val postalCode = villagesAdapter.getPostalCode(position)
Log.d(TAG, "Village selected at position $position, ID: $villageId") Log.d(TAG, "Village selected at position $position, ID: $villageId")
villageId?.let { id -> villageId?.let { id ->
@ -258,11 +258,11 @@ class RegisterStep3Fragment : Fragment() {
registerViewModel.selectedVillages = id registerViewModel.selectedVillages = id
} }
postalCode?.let { postCode -> // postalCode?.let { postCode ->
registerViewModel.selectedPostalCode = postCode // registerViewModel.selectedPostalCode = postCode
} // }
binding.etKodePos.setText(registerViewModel.selectedPostalCode ?: "") // binding.etKodePos.setText(registerViewModel.selectedPostalCode ?: "")
} }
} }
@ -371,11 +371,12 @@ class RegisterStep3Fragment : Fragment() {
val street = binding.etDetailAlamat.text.toString().trim() val street = binding.etDetailAlamat.text.toString().trim()
val recipient = binding.etNamaPenerima.text.toString().trim() val recipient = binding.etNamaPenerima.text.toString().trim()
val phone = binding.etNomorHp.text.toString().trim() val phone = binding.etNomorHp.text.toString().trim()
val postalCode = binding.etKodePos.text.toString().trim()
val provinceId = registerViewModel.selectedProvinceId?.toInt() ?: 0 val provinceId = registerViewModel.selectedProvinceId?.toInt() ?: 0
val cityId = registerViewModel.selectedCityId.toString() val cityId = registerViewModel.selectedCityId.toString()
val subDistrict = registerViewModel.selectedSubdistrict.toString() val subDistrict = registerViewModel.selectedSubdistrict.toString()
val postalCode = registerViewModel.selectedPostalCode.toString() // val postalCode = registerViewModel.selectedPostalCode.toString()
val villageId = registerViewModel.selectedVillages ?: "" val villageId = registerViewModel.selectedVillages ?: ""

View File

@ -1,6 +1,5 @@
package com.alya.ecommerce_serang.ui.profile.mystore package com.alya.ecommerce_serang.ui.profile.mystore
import android.Manifest
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
@ -20,7 +19,6 @@ import android.widget.Toast
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toDrawable import androidx.core.graphics.drawable.toDrawable
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
@ -101,8 +99,12 @@ class RegisterStoreActivity : AppCompatActivity() {
setupObservers() setupObservers()
Log.d(TAG, "onCreate: Observers setup completed") Log.d(TAG, "onCreate: Observers setup completed")
setupMap() viewModel.latitude.value = "-6.2088"
Log.d(TAG, "onCreate: Map setup completed") viewModel.longitude.value = "106.8456"
Log.d(TAG, "Location permission granted, setting default location")
// Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show()
Log.d(TAG, "Default location set - Lat: ${viewModel.latitude.value}, Long: ${viewModel.longitude.value}")
// Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show()
setupDocumentUploads() setupDocumentUploads()
Log.d(TAG, "onCreate: Document uploads setup completed") Log.d(TAG, "onCreate: Document uploads setup completed")
@ -161,16 +163,17 @@ class RegisterStoreActivity : AppCompatActivity() {
viewModel.ktpUri != null && viewModel.ktpUri != null &&
viewModel.nibUri != null && viewModel.nibUri != null &&
viewModel.npwpUri != null && viewModel.npwpUri != null &&
viewModel.selectedCouriers.isNotEmpty() viewModel.selectedCouriers.isNotEmpty() &&
!viewModel.accountName.value.isNullOrBlank()
binding.btnRegister.isEnabled = isFormValid
binding.btnRegister.isEnabled = true
if (isFormValid) { if (isFormValid) {
binding.btnRegister.setBackgroundResource(R.drawable.bg_button_active) binding.btnRegister.setBackgroundResource(R.drawable.bg_button_active)
binding.btnRegister.setTextColor(ContextCompat.getColor(this, R.color.white)) binding.btnRegister.setTextColor(ContextCompat.getColor(this, R.color.white))
} else { } else {
binding.btnRegister.setBackgroundResource(R.drawable.bg_button_disabled) binding.btnRegister.setBackgroundResource(R.drawable.bg_button_disabled)
binding.btnRegister.setTextColor(ContextCompat.getColor(this, R.color.black_300)) binding.btnRegister.setTextColor(ContextCompat.getColor(this, R.color.black_300))
} }
} }
@ -500,44 +503,44 @@ class RegisterStoreActivity : AppCompatActivity() {
validateRequiredFields() validateRequiredFields()
} }
private fun setupMap() { // private fun setupMap() {
Log.d(TAG, "setupMap: Setting up map container") // Log.d(TAG, "setupMap: Setting up map container")
// This would typically integrate with Google Maps SDK // // This would typically integrate with Google Maps SDK
// For simplicity, we're just using a placeholder // // For simplicity, we're just using a placeholder
binding.mapContainer.setOnClickListener { // binding.mapContainer.setOnClickListener {
Log.d(TAG, "Map container clicked, checking location permission") // Log.d(TAG, "Map container clicked, checking location permission")
// Request location permission if not granted // // Request location permission if not granted
if (ContextCompat.checkSelfPermission( // if (ContextCompat.checkSelfPermission(
this, // this,
Manifest.permission.ACCESS_FINE_LOCATION // Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED // ) != PackageManager.PERMISSION_GRANTED
) { // ) {
Log.d(TAG, "Location permission not granted, requesting permission") // Log.d(TAG, "Location permission not granted, requesting permission")
ActivityCompat.requestPermissions( // ActivityCompat.requestPermissions(
this, // this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), // arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
LOCATION_PERMISSION_REQUEST // LOCATION_PERMISSION_REQUEST
) // )
viewModel.latitude.value = "-6.2088" // viewModel.latitude.value = "-6.2088"
viewModel.longitude.value = "106.8456" // viewModel.longitude.value = "106.8456"
Log.d(TAG, "Location permission granted, setting default location") // Log.d(TAG, "Location permission granted, setting default location")
Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show() // Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show()
Log.d(TAG, "Default location set - Lat: ${viewModel.latitude.value}, Long: ${viewModel.longitude.value}") // Log.d(TAG, "Default location set - Lat: ${viewModel.latitude.value}, Long: ${viewModel.longitude.value}")
Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show() // Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show()
} else { // } else {
Log.d(TAG, "Location permission already granted, setting location") // Log.d(TAG, "Location permission already granted, setting location")
// Show map selection UI // // Show map selection UI
// This would typically launch Maps UI for location selection // // This would typically launch Maps UI for location selection
// For now, we'll just set some dummy coordinates // // For now, we'll just set some dummy coordinates
viewModel.latitude.value = "-6.2088" // viewModel.latitude.value = "-6.2088"
viewModel.longitude.value = "106.8456" // viewModel.longitude.value = "106.8456"
Log.d(TAG, "Location set - Lat: ${viewModel.latitude.value}, Long: ${viewModel.longitude.value}") // Log.d(TAG, "Location set - Lat: ${viewModel.latitude.value}, Long: ${viewModel.longitude.value}")
Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show() // Toast.makeText(this, "Lokasi dipilih", Toast.LENGTH_SHORT).show()
} // }
} // }
//
Log.d(TAG, "setupMap: Map container setup completed") // Log.d(TAG, "setupMap: Map container setup completed")
} // }
private fun setupDataBinding() { private fun setupDataBinding() {
Log.d(TAG, "setupDataBinding: Setting up two-way data binding for text fields") Log.d(TAG, "setupDataBinding: Setting up two-way data binding for text fields")
@ -638,6 +641,17 @@ class RegisterStoreActivity : AppCompatActivity() {
} }
}) })
binding.etAccountName.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable?) {
viewModel.accountName.value = s.toString()
Log.d(TAG, "Account Name updated: ${s.toString()}")
validateRequiredFields()
}
})
Log.d(TAG, "setupDataBinding: Text field data binding setup completed") Log.d(TAG, "setupDataBinding: Text field data binding setup completed")
} }

View File

@ -72,47 +72,89 @@ class RegisterStoreViewModel(
val selectedCouriers = mutableListOf<String>() val selectedCouriers = mutableListOf<String>()
fun registerStore(context: Context) { fun registerStore(context: Context) {
Log.d(TAG, "Starting registerStore()")
val allowedFileTypes = Regex("^(jpeg|jpg|png|pdf)$", RegexOption.IGNORE_CASE) val allowedFileTypes = Regex("^(jpeg|jpg|png|pdf)$", RegexOption.IGNORE_CASE)
// Check each file if present fun logFileInfo(label: String, uri: Uri?) {
if (uri == null) {
Log.d(TAG, "$label URI: null")
return
}
Log.d(TAG, "$label URI: $uri")
try {
val fileSizeBytes = context.contentResolver.openFileDescriptor(uri, "r")?.use {
it.statSize
} ?: -1
Log.d(TAG, "$label original size: ${fileSizeBytes / 1024} KB")
} catch (e: Exception) {
Log.e(TAG, "Error getting size for $label", e)
}
}
// Log all file info before validation
logFileInfo("Store Image", storeImageUri)
logFileInfo("KTP", ktpUri)
logFileInfo("NPWP", npwpUri)
logFileInfo("NIB", nibUri)
logFileInfo("Persetujuan", persetujuanUri)
logFileInfo("QRIS", qrisUri)
// Check file types
if (storeImageUri != null && !ImageUtils.isAllowedFileType(context, storeImageUri, allowedFileTypes)) { if (storeImageUri != null && !ImageUtils.isAllowedFileType(context, storeImageUri, allowedFileTypes)) {
_errorMessage.value = "Foto toko harus berupa file JPEG, JPG, atau PNG" _errorMessage.value = "Foto toko harus berupa file JPEG, JPG, atau PNG"
Log.e(TAG, _errorMessage.value ?: "Invalid file type for store image")
_registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type")) _registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type"))
return return
} }
if (ktpUri != null && !ImageUtils.isAllowedFileType(context, ktpUri, allowedFileTypes)) { if (ktpUri != null && !ImageUtils.isAllowedFileType(context, ktpUri, allowedFileTypes)) {
_errorMessage.value = "KTP harus berupa file JPEG, JPG, atau PNG" _errorMessage.value = "KTP harus berupa file JPEG, JPG, atau PNG"
Log.e(TAG, _errorMessage.value ?: "Invalid file type for KTP")
_registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type")) _registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type"))
return return
} }
if (npwpUri != null && !ImageUtils.isAllowedFileType(context, npwpUri, allowedFileTypes)) { if (npwpUri != null && !ImageUtils.isAllowedFileType(context, npwpUri, allowedFileTypes)) {
_errorMessage.value = "NPWP harus berupa file JPEG, JPG, PNG, atau PDF" _errorMessage.value = "NPWP harus berupa file JPEG, JPG, PNG, atau PDF"
Log.e(TAG, _errorMessage.value ?: "Invalid file type for NPWP")
_registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type")) _registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type"))
return return
} }
if (nibUri != null && !ImageUtils.isAllowedFileType(context, nibUri, allowedFileTypes)) { if (nibUri != null && !ImageUtils.isAllowedFileType(context, nibUri, allowedFileTypes)) {
_errorMessage.value = "NIB harus berupa file JPEG, JPG, PNG, atau PDF" _errorMessage.value = "NIB harus berupa file JPEG, JPG, PNG, atau PDF"
Log.e(TAG, _errorMessage.value ?: "Invalid file type for NIB")
_registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type")) _registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type"))
return return
} }
if (persetujuanUri != null && !ImageUtils.isAllowedFileType(context, persetujuanUri, allowedFileTypes)) { if (persetujuanUri != null && !ImageUtils.isAllowedFileType(context, persetujuanUri, allowedFileTypes)) {
_errorMessage.value = "Persetujuan harus berupa file JPEG, JPG, PNG, atau PDF" _errorMessage.value = "Persetujuan harus berupa file JPEG, JPG, PNG, atau PDF"
Log.e(TAG, _errorMessage.value ?: "Invalid file type for Persetujuan")
_registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type")) _registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type"))
return return
} }
if (qrisUri != null && !ImageUtils.isAllowedFileType(context, qrisUri, allowedFileTypes)) { if (qrisUri != null && !ImageUtils.isAllowedFileType(context, qrisUri, allowedFileTypes)) {
_errorMessage.value = "QRIS harus berupa file JPEG, JPG, PNG, atau PDF" _errorMessage.value = "QRIS harus berupa file JPEG, JPG, PNG, atau PDF"
Log.e(TAG, _errorMessage.value ?: "Invalid file type for QRIS")
_registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type")) _registerState.value = Result.Error(Exception(_errorMessage.value ?: "Invalid file type"))
return return
} }
Log.d(TAG, "File type checks passed. Starting repository.registerStoreUser() call.")
viewModelScope.launch { viewModelScope.launch {
try { try {
_registerState.value = Result.Loading _registerState.value = Result.Loading
Log.d(TAG, "Register store request payload: " +
"storeName=${storeName.value}, storeTypeId=${storeTypeId.value}, " +
"lat=${latitude.value}, long=${longitude.value}, " +
"street=${street.value}, subdistrict=${subdistrict.value}, " +
"cityId=${cityId.value}, provinceId=${provinceId.value}, postalCode=${postalCode.value}, " +
"bankName=${bankName.value}, bankNum=${bankNumber.value}, accountName=${accountName.value}, " +
"selectedCouriers=$selectedCouriers")
val result = repository.registerStoreUser( val result = repository.registerStoreUser(
context = context, context = context,
@ -139,25 +181,15 @@ class RegisterStoreViewModel(
accountName = accountName.value ?: "" accountName = accountName.value ?: ""
) )
Log.d(TAG, "Repository returned result: $result")
_registerState.value = result _registerState.value = result
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Exception during registerStore", e)
_registerState.value = Result.Error(e) _registerState.value = Result.Error(e)
} }
} }
} }
// // Helper function to convert Uri to File
// private fun getFileFromUri(context: Context, uri: Uri): File {
// val inputStream = context.contentResolver.openInputStream(uri)
// val tempFile = File(context.cacheDir, "temp_file_${System.currentTimeMillis()}")
// inputStream?.use { input ->
// tempFile.outputStream().use { output ->
// input.copyTo(output)
// }
// }
// return tempFile
// }
fun validateForm(): Boolean { fun validateForm(): Boolean {
// Implement form validation logic // Implement form validation logic
return !(storeName.value.isNullOrEmpty() || return !(storeName.value.isNullOrEmpty() ||
@ -174,8 +206,6 @@ class RegisterStoreViewModel(
nibUri == null) nibUri == null)
} }
// Function to fetch store types // Function to fetch store types
fun fetchStoreTypes() { fun fetchStoreTypes() {
_isLoadingType.value = true _isLoadingType.value = true

View File

@ -583,6 +583,48 @@
</LinearLayout> </LinearLayout>
<!-- Nama Pemilik Rekening -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="24dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12. Nama Pemilik Rekening"
style="@style/body_medium"
android:layout_marginEnd="4dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*"
style="@style/body_medium"
android:textColor="@color/red_required"
android:layout_gravity="end"/>
</LinearLayout>
<EditText
android:id="@+id/et_account_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_text_field"
android:hint="Isi nama pemilik rekening"
android:padding="8dp"
style="@style/body_small"
android:layout_marginTop="10dp"/>
</LinearLayout>
<!-- Kurir --> <!-- Kurir -->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -598,7 +640,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="12. Pilih Kurir Pengiriman" android:text="13. Pilih Kurir Pengiriman"
style="@style/body_medium" style="@style/body_medium"
android:layout_marginEnd="4dp"/> android:layout_marginEnd="4dp"/>
@ -651,7 +693,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="13. Foto Profil Toko" android:text="14. Foto Profil Toko"
style="@style/body_medium" style="@style/body_medium"
android:layout_marginEnd="4dp"/> android:layout_marginEnd="4dp"/>
@ -707,7 +749,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="14. Dokumen KTP" android:text="15. Dokumen KTP"
style="@style/body_medium" style="@style/body_medium"
android:layout_marginEnd="4dp"/> android:layout_marginEnd="4dp"/>
@ -774,7 +816,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="15. Dokumen NIB" android:text="16. Dokumen NIB"
style="@style/body_medium" style="@style/body_medium"
android:layout_marginEnd="4dp"/> android:layout_marginEnd="4dp"/>
@ -841,7 +883,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="16. Dokumen NPWP" android:text="17. Dokumen NPWP"
style="@style/body_medium" style="@style/body_medium"
android:layout_marginEnd="4dp"/> android:layout_marginEnd="4dp"/>
@ -896,7 +938,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal"
android:visibility="gone">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -916,12 +959,14 @@
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout
android:id="@+id/map_container" android:id="@+id/map_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="200dp" android:layout_height="200dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:background="@android:color/darker_gray"> android:background="@android:color/darker_gray"
android:visibility="gone">
<ImageView <ImageView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -933,7 +978,7 @@
<Button <Button
android:id="@+id/btn_register" android:id="@+id/btn_register"
style="@style/button.large.disabled.long" style="@style/button.large.disabled.long"
android:enabled="false" android:enabled="true"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:text="Daftar" /> android:text="Daftar" />