mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-15 19:37:26 +00:00
Compare commits
26 Commits
97be7a8f62
...
master
Author | SHA1 | Date | |
---|---|---|---|
22122d631b | |||
6efbcde784 | |||
a6d5d10e78 | |||
f373035f8e | |||
8d9815d89f | |||
1f41b4681f | |||
3d8e82e3b5 | |||
d4eacf6c7c | |||
7351f9c5b7 | |||
9fefe1d818 | |||
0a8dac4d23 | |||
77ea5ed90a | |||
c303b419ed | |||
bad456f842 | |||
ed60528049 | |||
a9c2f9c103 | |||
d08f5465d1 | |||
eab3884fd6 | |||
930688f50d | |||
b70c671710 | |||
3ac0461c7c | |||
61e8e1fe3c | |||
39aa079003 | |||
577fb27495 | |||
8b76077a77 | |||
6194dca259 |
13
.idea/deviceManager.xml
generated
Normal file
13
.idea/deviceManager.xml
generated
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DeviceTable">
|
||||||
|
<option name="columnSorters">
|
||||||
|
<list>
|
||||||
|
<ColumnSorterState>
|
||||||
|
<option name="column" value="Name" />
|
||||||
|
<option name="order" value="ASCENDING" />
|
||||||
|
</ColumnSorterState>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -124,7 +124,4 @@ dependencies {
|
|||||||
implementation(platform("com.google.firebase:firebase-bom:33.13.0"))
|
implementation(platform("com.google.firebase:firebase-bom:33.13.0"))
|
||||||
implementation("com.google.firebase:firebase-analytics")
|
implementation("com.google.firebase:firebase-analytics")
|
||||||
implementation("com.google.firebase:firebase-messaging-ktx")
|
implementation("com.google.firebase:firebase-messaging-ktx")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,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.auth.ResetPassActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.profile.mystore.StoreSuspendedActivity"
|
||||||
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.profile.mystore.StoreOnReviewActivity"
|
android:name=".ui.profile.mystore.StoreOnReviewActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
@ -82,12 +88,11 @@
|
|||||||
<!-- android:name="androidx.startup.InitializationProvider" -->
|
<!-- android:name="androidx.startup.InitializationProvider" -->
|
||||||
<!-- android:authorities="${applicationId}.androidx-startup" -->
|
<!-- android:authorities="${applicationId}.androidx-startup" -->
|
||||||
<!-- tools:node="remove" /> -->
|
<!-- tools:node="remove" /> -->
|
||||||
<service
|
<!-- <service -->
|
||||||
android:name=".ui.notif.SimpleWebSocketService"
|
<!-- android:name=".ui.notif.SimpleWebSocketService" -->
|
||||||
android:enabled="true"
|
<!-- android:enabled="true" -->
|
||||||
android:exported="false"
|
<!-- android:exported="false" -->
|
||||||
android:foregroundServiceType="dataSync" />
|
<!-- android:foregroundServiceType="dataSync" /> -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.profile.mystore.chat.ChatStoreActivity"
|
android:name=".ui.profile.mystore.chat.ChatStoreActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
@ -2,30 +2,20 @@ package com.alya.ecommerce_serang.data.api.dto
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
data class City(
|
data class CityResponse(
|
||||||
@SerializedName("city_id")
|
|
||||||
val cityId: String,
|
|
||||||
|
|
||||||
@SerializedName("city_name")
|
@field:SerializedName("cities")
|
||||||
|
val cities: List<City>,
|
||||||
|
|
||||||
|
@field:SerializedName("message")
|
||||||
|
val message: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class City(
|
||||||
|
|
||||||
|
@field:SerializedName("city_name")
|
||||||
val cityName: String,
|
val cityName: String,
|
||||||
|
|
||||||
@SerializedName("province_id")
|
@field:SerializedName("city_id")
|
||||||
val provinceId: String,
|
val cityId: String
|
||||||
|
|
||||||
@SerializedName("province")
|
|
||||||
val provinceName: String,
|
|
||||||
|
|
||||||
@SerializedName("type")
|
|
||||||
val type: String,
|
|
||||||
|
|
||||||
@SerializedName("postal_code")
|
|
||||||
val postalCode: String
|
|
||||||
)
|
|
||||||
|
|
||||||
data class CityResponse(
|
|
||||||
@SerializedName("message")
|
|
||||||
val message: String,
|
|
||||||
|
|
||||||
@SerializedName("cities")
|
|
||||||
val data: List<City>
|
|
||||||
)
|
)
|
@ -2,12 +2,15 @@ package com.alya.ecommerce_serang.data.api.dto
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
data class CreateAddressRequest (
|
data class CreateAddressRequest(
|
||||||
|
@SerializedName("userId")
|
||||||
|
val userId: Int,
|
||||||
|
|
||||||
@SerializedName("latitude")
|
@SerializedName("latitude")
|
||||||
val lat: Double? = null,
|
val lat: Double,
|
||||||
|
|
||||||
@SerializedName("longitude")
|
@SerializedName("longitude")
|
||||||
val long: Double? = null,
|
val long: Double,
|
||||||
|
|
||||||
@SerializedName("street")
|
@SerializedName("street")
|
||||||
val street: String,
|
val street: String,
|
||||||
@ -20,22 +23,22 @@ data class CreateAddressRequest (
|
|||||||
|
|
||||||
@SerializedName("province_id")
|
@SerializedName("province_id")
|
||||||
val provId: Int,
|
val provId: Int,
|
||||||
|
|
||||||
@SerializedName("postal_code")
|
@SerializedName("postal_code")
|
||||||
val postCode: String,
|
val postCode: String,
|
||||||
|
|
||||||
@SerializedName("detail")
|
@SerializedName("village_id")
|
||||||
val detailAddress: String? = null,
|
val idVillage: String?, // nullable for now
|
||||||
|
|
||||||
@SerializedName("user_id")
|
@SerializedName("detail")
|
||||||
val userId: Int,
|
val detailAddress: String,
|
||||||
|
|
||||||
|
@SerializedName("is_store_location")
|
||||||
|
val isStoreLocation: Boolean,
|
||||||
|
|
||||||
@SerializedName("recipient")
|
@SerializedName("recipient")
|
||||||
val recipient: String,
|
val recipient: String,
|
||||||
|
|
||||||
@SerializedName("phone")
|
@SerializedName("phone")
|
||||||
val phone: String,
|
val phone: String
|
||||||
|
|
||||||
@SerializedName("is_store_location")
|
|
||||||
val isStoreLocation: Boolean
|
|
||||||
|
|
||||||
)
|
)
|
@ -90,7 +90,7 @@ data class OrdersItem(
|
|||||||
val orderId: Int,
|
val orderId: Int,
|
||||||
|
|
||||||
@field:SerializedName("city_id")
|
@field:SerializedName("city_id")
|
||||||
val cityId: Int,
|
val cityId: String,
|
||||||
|
|
||||||
var displayStatus: String? = null
|
var displayStatus: String? = null
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.alya.ecommerce_serang.data.api.dto
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class ResetPassReq (
|
||||||
|
@SerializedName("emailOrPhone")
|
||||||
|
val emailOrPhone: String
|
||||||
|
)
|
@ -98,5 +98,5 @@ data class Store(
|
|||||||
val storeDescription: String,
|
val storeDescription: String,
|
||||||
|
|
||||||
@field:SerializedName("city_id")
|
@field:SerializedName("city_id")
|
||||||
val cityId: Int
|
val cityId: String
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.alya.ecommerce_serang.data.api.dto
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class UpdateAddressReq(
|
||||||
|
@SerializedName("street")
|
||||||
|
val street: String? = "",
|
||||||
|
|
||||||
|
@SerializedName("subdistrict")
|
||||||
|
val subdistrict: String? = "",
|
||||||
|
|
||||||
|
@SerializedName("postal_code")
|
||||||
|
val postalCCode: String? = "",
|
||||||
|
|
||||||
|
@SerializedName("detail")
|
||||||
|
val detail: String? = "",
|
||||||
|
|
||||||
|
@SerializedName("city_id")
|
||||||
|
val cityId: String? = "",
|
||||||
|
|
||||||
|
@SerializedName("province_id")
|
||||||
|
val provId: String? = "",
|
||||||
|
|
||||||
|
@SerializedName("phone")
|
||||||
|
val phone: String? = ""
|
||||||
|
|
||||||
|
|
||||||
|
)
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.alya.ecommerce_serang.data.api.response.auth
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class ResetPassResponse(
|
||||||
|
|
||||||
|
@field:SerializedName("message")
|
||||||
|
val message: String
|
||||||
|
)
|
@ -119,7 +119,7 @@ data class Orders(
|
|||||||
val orderId: Int,
|
val orderId: Int,
|
||||||
|
|
||||||
@field:SerializedName("city_id")
|
@field:SerializedName("city_id")
|
||||||
val cityId: Int
|
val cityId: String
|
||||||
)
|
)
|
||||||
|
|
||||||
data class OrderListItemsItem(
|
data class OrderListItemsItem(
|
||||||
|
@ -82,7 +82,8 @@ data class Product(
|
|||||||
|
|
||||||
data class CartItemCheckoutInfo(
|
data class CartItemCheckoutInfo(
|
||||||
val cartItem: CartItemsItem,
|
val cartItem: CartItemsItem,
|
||||||
val isWholesale: Boolean
|
val isWholesale: Boolean,
|
||||||
|
val wholesalePrice: Int? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ data class Store(
|
|||||||
val storeDescription: String,
|
val storeDescription: String,
|
||||||
|
|
||||||
@field:SerializedName("city_id")
|
@field:SerializedName("city_id")
|
||||||
val cityId: Int
|
val cityId: String
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ShippingItem(
|
data class ShippingItem(
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.alya.ecommerce_serang.data.api.response.customer.profile
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class AddressDetailResponse(
|
||||||
|
|
||||||
|
@field:SerializedName("address")
|
||||||
|
val address: AddressDetail,
|
||||||
|
|
||||||
|
@field:SerializedName("message")
|
||||||
|
val message: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class AddressDetail(
|
||||||
|
|
||||||
|
@field:SerializedName("village_id")
|
||||||
|
val villageId: String?,
|
||||||
|
|
||||||
|
@field:SerializedName("is_store_location")
|
||||||
|
val isStoreLocation: Boolean,
|
||||||
|
|
||||||
|
@field:SerializedName("latitude")
|
||||||
|
val latitude: String,
|
||||||
|
|
||||||
|
@field:SerializedName("province_name")
|
||||||
|
val provinceName: String,
|
||||||
|
|
||||||
|
@field:SerializedName("subdistrict_id")
|
||||||
|
val subdistrictId: String,
|
||||||
|
|
||||||
|
@field:SerializedName("city_name")
|
||||||
|
val cityName: String,
|
||||||
|
|
||||||
|
@field:SerializedName("user_id")
|
||||||
|
val userId: Int,
|
||||||
|
|
||||||
|
@field:SerializedName("province_id")
|
||||||
|
val provinceId: String,
|
||||||
|
|
||||||
|
@field:SerializedName("phone")
|
||||||
|
val phone: String?,
|
||||||
|
|
||||||
|
@field:SerializedName("street")
|
||||||
|
val street: String,
|
||||||
|
|
||||||
|
@field:SerializedName("subdistrict")
|
||||||
|
val subdistrict: String,
|
||||||
|
|
||||||
|
@field:SerializedName("recipient")
|
||||||
|
val recipient: String?,
|
||||||
|
|
||||||
|
@field:SerializedName("id")
|
||||||
|
val id: Int,
|
||||||
|
|
||||||
|
@field:SerializedName("detail")
|
||||||
|
val detail: String,
|
||||||
|
|
||||||
|
@field:SerializedName("village_name")
|
||||||
|
val villageName: String,
|
||||||
|
|
||||||
|
@field:SerializedName("postal_code")
|
||||||
|
val postalCode: String,
|
||||||
|
|
||||||
|
@field:SerializedName("longitude")
|
||||||
|
val longitude: String,
|
||||||
|
|
||||||
|
@field:SerializedName("city_id")
|
||||||
|
val cityId: String
|
||||||
|
)
|
@ -13,6 +13,9 @@ data class AddressResponse(
|
|||||||
|
|
||||||
data class AddressesItem(
|
data class AddressesItem(
|
||||||
|
|
||||||
|
@field:SerializedName("village_id")
|
||||||
|
val villageId: String?,
|
||||||
|
|
||||||
@field:SerializedName("is_store_location")
|
@field:SerializedName("is_store_location")
|
||||||
val isStoreLocation: Boolean,
|
val isStoreLocation: Boolean,
|
||||||
|
|
||||||
@ -23,10 +26,10 @@ data class AddressesItem(
|
|||||||
val userId: Int,
|
val userId: Int,
|
||||||
|
|
||||||
@field:SerializedName("province_id")
|
@field:SerializedName("province_id")
|
||||||
val provinceId: Int,
|
val provinceId: String,
|
||||||
|
|
||||||
@field:SerializedName("phone")
|
@field:SerializedName("phone")
|
||||||
val phone: String,
|
val phone: String?,
|
||||||
|
|
||||||
@field:SerializedName("street")
|
@field:SerializedName("street")
|
||||||
val street: String,
|
val street: String,
|
||||||
@ -35,7 +38,7 @@ data class AddressesItem(
|
|||||||
val subdistrict: String,
|
val subdistrict: String,
|
||||||
|
|
||||||
@field:SerializedName("recipient")
|
@field:SerializedName("recipient")
|
||||||
val recipient: String,
|
val recipient: String?,
|
||||||
|
|
||||||
@field:SerializedName("id")
|
@field:SerializedName("id")
|
||||||
val id: Int,
|
val id: Int,
|
||||||
@ -50,5 +53,5 @@ data class AddressesItem(
|
|||||||
val longitude: String,
|
val longitude: String,
|
||||||
|
|
||||||
@field:SerializedName("city_id")
|
@field:SerializedName("city_id")
|
||||||
val cityId: Int
|
val cityId: String
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.alya.ecommerce_serang.data.api.response.customer.profile
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class UpdateAddressResponse(
|
||||||
|
|
||||||
|
@field:SerializedName("address")
|
||||||
|
val address: Address,
|
||||||
|
|
||||||
|
@field:SerializedName("message")
|
||||||
|
val message: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Address(
|
||||||
|
|
||||||
|
@field:SerializedName("village_id")
|
||||||
|
val villageId: String,
|
||||||
|
|
||||||
|
@field:SerializedName("is_store_location")
|
||||||
|
val isStoreLocation: Boolean,
|
||||||
|
|
||||||
|
@field:SerializedName("latitude")
|
||||||
|
val latitude: String,
|
||||||
|
|
||||||
|
@field:SerializedName("user_id")
|
||||||
|
val userId: Int,
|
||||||
|
|
||||||
|
@field:SerializedName("province_id")
|
||||||
|
val provinceId: String,
|
||||||
|
|
||||||
|
@field:SerializedName("phone")
|
||||||
|
val phone: Any,
|
||||||
|
|
||||||
|
@field:SerializedName("street")
|
||||||
|
val street: String,
|
||||||
|
|
||||||
|
@field:SerializedName("subdistrict")
|
||||||
|
val subdistrict: String,
|
||||||
|
|
||||||
|
@field:SerializedName("recipient")
|
||||||
|
val recipient: Any,
|
||||||
|
|
||||||
|
@field:SerializedName("id")
|
||||||
|
val id: Int,
|
||||||
|
|
||||||
|
@field:SerializedName("detail")
|
||||||
|
val detail: String,
|
||||||
|
|
||||||
|
@field:SerializedName("postal_code")
|
||||||
|
val postalCode: String,
|
||||||
|
|
||||||
|
@field:SerializedName("longitude")
|
||||||
|
val longitude: String,
|
||||||
|
|
||||||
|
@field:SerializedName("city_id")
|
||||||
|
val cityId: String
|
||||||
|
)
|
@ -35,7 +35,7 @@ data class Store(
|
|||||||
val detail: String,
|
val detail: String,
|
||||||
@SerializedName("is_store_location") val isStoreLocation: Boolean,
|
@SerializedName("is_store_location") val isStoreLocation: Boolean,
|
||||||
@SerializedName("user_id") val userId: Int,
|
@SerializedName("user_id") val userId: Int,
|
||||||
@SerializedName("city_id") val cityId: Int,
|
@SerializedName("city_id") val cityId: String,
|
||||||
@SerializedName("province_id") val provinceId: Int,
|
@SerializedName("province_id") val provinceId: Int,
|
||||||
val phone: String?,
|
val phone: String?,
|
||||||
val recipient: String?,
|
val recipient: String?,
|
||||||
|
@ -132,5 +132,5 @@ data class Orders(
|
|||||||
val username: String? = null,
|
val username: String? = null,
|
||||||
|
|
||||||
@field:SerializedName("city_id")
|
@field:SerializedName("city_id")
|
||||||
val cityId: Int? = null
|
val cityId: String? = null
|
||||||
)
|
)
|
@ -129,7 +129,7 @@ data class OrdersItem(
|
|||||||
val status: String? = null,
|
val status: String? = null,
|
||||||
|
|
||||||
@field:SerializedName("city_id")
|
@field:SerializedName("city_id")
|
||||||
val cityId: Int? = null,
|
val cityId: String? = null,
|
||||||
|
|
||||||
var displayStatus: String? = null
|
var displayStatus: String? = null
|
||||||
)
|
)
|
||||||
|
@ -19,6 +19,7 @@ import com.alya.ecommerce_serang.data.api.dto.OtpRequest
|
|||||||
import com.alya.ecommerce_serang.data.api.dto.PaymentConfirmRequest
|
import com.alya.ecommerce_serang.data.api.dto.PaymentConfirmRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.ProvinceResponse
|
import com.alya.ecommerce_serang.data.api.dto.ProvinceResponse
|
||||||
import com.alya.ecommerce_serang.data.api.dto.RegisterRequest
|
import com.alya.ecommerce_serang.data.api.dto.RegisterRequest
|
||||||
|
import com.alya.ecommerce_serang.data.api.dto.ResetPassReq
|
||||||
import com.alya.ecommerce_serang.data.api.dto.ReviewProductItem
|
import com.alya.ecommerce_serang.data.api.dto.ReviewProductItem
|
||||||
import com.alya.ecommerce_serang.data.api.dto.SearchRequest
|
import com.alya.ecommerce_serang.data.api.dto.SearchRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.ShippingServiceRequest
|
import com.alya.ecommerce_serang.data.api.dto.ShippingServiceRequest
|
||||||
@ -36,6 +37,7 @@ import com.alya.ecommerce_serang.data.api.response.auth.LoginResponse
|
|||||||
import com.alya.ecommerce_serang.data.api.response.auth.OtpResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.OtpResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.RegisterResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.RegisterResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.RegisterStoreResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.RegisterStoreResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.auth.ResetPassResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.VerifRegisterResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.VerifRegisterResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.chat.ChatHistoryResponse
|
import com.alya.ecommerce_serang.data.api.response.chat.ChatHistoryResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.chat.ChatListResponse
|
import com.alya.ecommerce_serang.data.api.response.chat.ChatListResponse
|
||||||
@ -61,10 +63,12 @@ import com.alya.ecommerce_serang.data.api.response.customer.product.DetailStoreP
|
|||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.ProductResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.product.ProductResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewProductResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewProductResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressDetailResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.CreateAddressResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.CreateAddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.EditProfileResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.EditProfileResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.ProfileResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.ProfileResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.UpdateAddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.order.AddEvidenceResponse
|
import com.alya.ecommerce_serang.data.api.response.order.AddEvidenceResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.order.ComplaintResponse
|
import com.alya.ecommerce_serang.data.api.response.order.ComplaintResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.order.CompletedOrderResponse
|
import com.alya.ecommerce_serang.data.api.response.order.CompletedOrderResponse
|
||||||
@ -391,18 +395,8 @@ interface ApiService {
|
|||||||
@PUT("mystore/edit")
|
@PUT("mystore/edit")
|
||||||
suspend fun updateStoreProfileMultipart(
|
suspend fun updateStoreProfileMultipart(
|
||||||
@Part("store_name") storeName: RequestBody,
|
@Part("store_name") storeName: RequestBody,
|
||||||
@Part("store_status") storeStatus: RequestBody,
|
|
||||||
@Part("store_description") storeDescription: RequestBody,
|
@Part("store_description") storeDescription: RequestBody,
|
||||||
@Part("is_on_leave") isOnLeave: RequestBody,
|
@Part("is_on_leave") isOnLeave: RequestBody,
|
||||||
@Part("city_id") cityId: RequestBody,
|
|
||||||
@Part("province_id") provinceId: RequestBody,
|
|
||||||
@Part("street") street: RequestBody,
|
|
||||||
@Part("subdistrict") subdistrict: RequestBody,
|
|
||||||
@Part("detail") detail: RequestBody,
|
|
||||||
@Part("postal_code") postalCode: RequestBody,
|
|
||||||
@Part("latitude") latitude: RequestBody,
|
|
||||||
@Part("longitude") longitude: RequestBody,
|
|
||||||
@Part("user_phone") userPhone: RequestBody,
|
|
||||||
@Part("store_type_id") storeTypeId: RequestBody,
|
@Part("store_type_id") storeTypeId: RequestBody,
|
||||||
@Part storeimg: MultipartBody.Part?
|
@Part storeimg: MultipartBody.Part?
|
||||||
): Response<StoreDataResponse>
|
): Response<StoreDataResponse>
|
||||||
@ -454,6 +448,12 @@ interface ApiService {
|
|||||||
@Body addressData: HashMap<String, Any?>
|
@Body addressData: HashMap<String, Any?>
|
||||||
): Response<StoreAddressResponse>
|
): Response<StoreAddressResponse>
|
||||||
|
|
||||||
|
@PUT("profile/address/edit/{id}")
|
||||||
|
suspend fun updateAddress(
|
||||||
|
@Path("id") addressId: Int,
|
||||||
|
@Body params: Map<String, @JvmSuppressWildcards Any>
|
||||||
|
): Response<UpdateAddressResponse>
|
||||||
|
|
||||||
@POST("search")
|
@POST("search")
|
||||||
suspend fun saveSearchQuery(
|
suspend fun saveSearchQuery(
|
||||||
@Body searchRequest: SearchRequest
|
@Body searchRequest: SearchRequest
|
||||||
@ -524,4 +524,14 @@ interface ApiService {
|
|||||||
suspend fun getVillages(
|
suspend fun getVillages(
|
||||||
@Path("subdistrictId") subdistrictId: String
|
@Path("subdistrictId") subdistrictId: String
|
||||||
): Response<VillagesResponse>
|
): Response<VillagesResponse>
|
||||||
|
|
||||||
|
@POST("resetpass")
|
||||||
|
suspend fun postResetPass(
|
||||||
|
@Body request: ResetPassReq
|
||||||
|
): Response<ResetPassResponse>
|
||||||
|
|
||||||
|
@GET("address/detail/{id}")
|
||||||
|
suspend fun getDetailAddress(
|
||||||
|
@Path("id") addressId: Int
|
||||||
|
): Response<AddressDetailResponse>
|
||||||
}
|
}
|
@ -1,131 +1,140 @@
|
|||||||
package com.alya.ecommerce_serang.data.repository
|
package com.alya.ecommerce_serang.data.repository
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.alya.ecommerce_serang.data.api.dto.City
|
import com.alya.ecommerce_serang.data.api.dto.CityResponse
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Province
|
import com.alya.ecommerce_serang.data.api.dto.ProvinceResponse
|
||||||
import com.alya.ecommerce_serang.data.api.dto.StoreAddress
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.UpdateAddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
||||||
import com.google.gson.Gson
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.json.JSONObject
|
import retrofit2.Response
|
||||||
|
|
||||||
class AddressRepository(private val apiService: ApiService) {
|
class AddressRepository(private val apiService: ApiService) {
|
||||||
|
|
||||||
private val TAG = "AddressRepository"
|
private val TAG = "AddressRepository"
|
||||||
|
|
||||||
suspend fun getProvinces(): List<Province> = withContext(Dispatchers.IO) {
|
// suspend fun getProvinces(): List<Province> = withContext(Dispatchers.IO) {
|
||||||
Log.d(TAG, "getProvinces() called")
|
// Log.d(TAG, "getProvinces() called")
|
||||||
try {
|
// try {
|
||||||
val response = apiService.getProvinces()
|
// val response = apiService.getProvinces()
|
||||||
Log.d(TAG, "getProvinces() response: isSuccessful=${response.isSuccessful}, code=${response.code()}")
|
// Log.d(TAG, "getProvinces() response: isSuccessful=${response.isSuccessful}, code=${response.code()}")
|
||||||
|
//
|
||||||
|
// // Log the raw response body for debugging
|
||||||
|
// val rawBody = response.raw().toString()
|
||||||
|
// Log.d(TAG, "Raw response: $rawBody")
|
||||||
|
//
|
||||||
|
// if (response.isSuccessful) {
|
||||||
|
// val responseBody = response.body()
|
||||||
|
// Log.d(TAG, "Response body: ${Gson().toJson(responseBody)}")
|
||||||
|
//
|
||||||
|
// val provinces = responseBody?.data ?: emptyList()
|
||||||
|
// Log.d(TAG, "getProvinces() success, got ${provinces.size} provinces")
|
||||||
|
// return@withContext provinces
|
||||||
|
// } else {
|
||||||
|
// val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
||||||
|
// Log.e(TAG, "getProvinces() error: $errorBody")
|
||||||
|
// throw Exception("API Error (${response.code()}): $errorBody")
|
||||||
|
// }
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Exception in getProvinces()", e)
|
||||||
|
// throw Exception("Network error: ${e.message}")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Log the raw response body for debugging
|
// suspend fun getCities(provinceId: String): List<City> = withContext(Dispatchers.IO) {
|
||||||
val rawBody = response.raw().toString()
|
// Log.d(TAG, "getCities() called with provinceId: $provinceId")
|
||||||
Log.d(TAG, "Raw response: $rawBody")
|
// try {
|
||||||
|
// val response = apiService.getCities(provinceId)
|
||||||
|
// Log.d(TAG, "getCities() response: isSuccessful=${response.isSuccessful}, code=${response.code()}")
|
||||||
|
//
|
||||||
|
// if (response.isSuccessful) {
|
||||||
|
// val responseBody = response.body()
|
||||||
|
// Log.d(TAG, "Response body: ${Gson().toJson(responseBody)}")
|
||||||
|
//
|
||||||
|
// val cities = responseBody?.data ?: emptyList()
|
||||||
|
// Log.d(TAG, "getCities() success, got ${cities.size} cities")
|
||||||
|
// return@withContext cities
|
||||||
|
// } else {
|
||||||
|
// val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
||||||
|
// Log.e(TAG, "getCities() error: $errorBody")
|
||||||
|
// throw Exception("API Error (${response.code()}): $errorBody")
|
||||||
|
// }
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Exception in getCities()", e)
|
||||||
|
// throw Exception("Network error: ${e.message}")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
suspend fun getProvinces(): Response<ProvinceResponse> {
|
||||||
val responseBody = response.body()
|
return apiService.getProvinces()
|
||||||
Log.d(TAG, "Response body: ${Gson().toJson(responseBody)}")
|
|
||||||
|
|
||||||
val provinces = responseBody?.data ?: emptyList()
|
|
||||||
Log.d(TAG, "getProvinces() success, got ${provinces.size} provinces")
|
|
||||||
return@withContext provinces
|
|
||||||
} else {
|
|
||||||
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
|
||||||
Log.e(TAG, "getProvinces() error: $errorBody")
|
|
||||||
throw Exception("API Error (${response.code()}): $errorBody")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Exception in getProvinces()", e)
|
|
||||||
throw Exception("Network error: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getCities(provinceId: String): List<City> = withContext(Dispatchers.IO) {
|
suspend fun getCities(provinceId: String): Response<CityResponse> {
|
||||||
Log.d(TAG, "getCities() called with provinceId: $provinceId")
|
return apiService.getCities(provinceId)
|
||||||
try {
|
|
||||||
val response = apiService.getCities(provinceId)
|
|
||||||
Log.d(TAG, "getCities() response: isSuccessful=${response.isSuccessful}, code=${response.code()}")
|
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
val responseBody = response.body()
|
|
||||||
Log.d(TAG, "Response body: ${Gson().toJson(responseBody)}")
|
|
||||||
|
|
||||||
val cities = responseBody?.data ?: emptyList()
|
|
||||||
Log.d(TAG, "getCities() success, got ${cities.size} cities")
|
|
||||||
return@withContext cities
|
|
||||||
} else {
|
|
||||||
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
|
||||||
Log.e(TAG, "getCities() error: $errorBody")
|
|
||||||
throw Exception("API Error (${response.code()}): $errorBody")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Exception in getCities()", e)
|
|
||||||
throw Exception("Network error: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getStoreAddress(): StoreAddress? = withContext(Dispatchers.IO) {
|
// suspend fun getStoreAddress(): StoreAddress? = withContext(Dispatchers.IO) {
|
||||||
Log.d(TAG, "getStoreAddress() called")
|
// Log.d(TAG, "getStoreAddress() called")
|
||||||
try {
|
// try {
|
||||||
val response = apiService.getStoreAddress()
|
// val response = apiService.getStoreAddress()
|
||||||
Log.d(TAG, "getStoreAddress() response: isSuccessful=${response.isSuccessful}, code=${response.code()}")
|
// Log.d(TAG, "getStoreAddress() response: isSuccessful=${response.isSuccessful}, code=${response.code()}")
|
||||||
|
//
|
||||||
if (response.isSuccessful) {
|
// if (response.isSuccessful) {
|
||||||
val responseBody = response.body()
|
// val responseBody = response.body()
|
||||||
val rawJson = Gson().toJson(responseBody)
|
// val rawJson = Gson().toJson(responseBody)
|
||||||
Log.d(TAG, "Response body: $rawJson")
|
// Log.d(TAG, "Response body: $rawJson")
|
||||||
|
//
|
||||||
val address = responseBody?.data
|
// val address = responseBody?.data
|
||||||
Log.d(TAG, "getStoreAddress() success, address: $address")
|
// Log.d(TAG, "getStoreAddress() success, address: $address")
|
||||||
|
//
|
||||||
// Convert numeric strings to proper types if needed
|
// // Convert numeric strings to proper types if needed
|
||||||
address?.let {
|
// address?.let {
|
||||||
// Handle city_id if it's a number
|
// // Handle city_id if it's a number
|
||||||
if (it.cityId.isBlank() && rawJson.contains("city_id")) {
|
// if (it.cityId.isBlank() && rawJson.contains("city_id")) {
|
||||||
try {
|
// try {
|
||||||
val cityId = JSONObject(rawJson).getJSONObject("store").optInt("city_id", 0)
|
// val cityId = JSONObject(rawJson).getJSONObject("store").optInt("city_id", 0)
|
||||||
if (cityId > 0) {
|
// if (cityId > 0) {
|
||||||
it.javaClass.getDeclaredField("cityId").apply {
|
// it.javaClass.getDeclaredField("cityId").apply {
|
||||||
isAccessible = true
|
// isAccessible = true
|
||||||
set(it, cityId.toString())
|
// set(it, cityId.toString())
|
||||||
}
|
// }
|
||||||
Log.d(TAG, "Updated cityId to: ${it.cityId}")
|
// Log.d(TAG, "Updated cityId to: ${it.cityId}")
|
||||||
}
|
// }
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
Log.e(TAG, "Error parsing city_id", e)
|
// Log.e(TAG, "Error parsing city_id", e)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Handle province_id if it's a number
|
// // Handle province_id if it's a number
|
||||||
if (it.provinceId.isBlank() && rawJson.contains("province_id")) {
|
// if (it.provinceId.isBlank() && rawJson.contains("province_id")) {
|
||||||
try {
|
// try {
|
||||||
val provinceId = JSONObject(rawJson).getJSONObject("store").optInt("province_id", 0)
|
// val provinceId = JSONObject(rawJson).getJSONObject("store").optInt("province_id", 0)
|
||||||
if (provinceId > 0) {
|
// if (provinceId > 0) {
|
||||||
it.javaClass.getDeclaredField("provinceId").apply {
|
// it.javaClass.getDeclaredField("provinceId").apply {
|
||||||
isAccessible = true
|
// isAccessible = true
|
||||||
set(it, provinceId.toString())
|
// set(it, provinceId.toString())
|
||||||
}
|
// }
|
||||||
Log.d(TAG, "Updated provinceId to: ${it.provinceId}")
|
// Log.d(TAG, "Updated provinceId to: ${it.provinceId}")
|
||||||
}
|
// }
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
Log.e(TAG, "Error parsing province_id", e)
|
// Log.e(TAG, "Error parsing province_id", e)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return@withContext address
|
// return@withContext address
|
||||||
} else {
|
// } else {
|
||||||
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
// val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
||||||
Log.e(TAG, "getStoreAddress() error: $errorBody")
|
// Log.e(TAG, "getStoreAddress() error: $errorBody")
|
||||||
throw Exception("API Error (${response.code()}): $errorBody")
|
// throw Exception("API Error (${response.code()}): $errorBody")
|
||||||
}
|
// }
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
Log.e(TAG, "Exception in getStoreAddress()", e)
|
// Log.e(TAG, "Exception in getStoreAddress()", e)
|
||||||
throw Exception("Network error: ${e.message}")
|
// throw Exception("Network error: ${e.message}")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
suspend fun saveStoreAddress(
|
suspend fun saveStoreAddress(
|
||||||
provinceId: String,
|
provinceId: String,
|
||||||
@ -171,4 +180,17 @@ class AddressRepository(private val apiService: ApiService) {
|
|||||||
throw Exception("Network error: ${e.message}")
|
throw Exception("Network error: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getStoreAddress(): Response<AddressResponse> {
|
||||||
|
return apiService.getAddress()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun updateAddress(addressId: Int, params: Map<String, Any>): Response<UpdateAddressResponse> {
|
||||||
|
return apiService.updateAddress(addressId, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getListSubdistrict(cityId : String): SubdistrictResponse? {
|
||||||
|
val response = apiService.getSubdistrict(cityId)
|
||||||
|
return if (response.isSuccessful) response.body() else null
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.alya.ecommerce_serang.data.repository
|
package com.alya.ecommerce_serang.data.repository
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.alya.ecommerce_serang.data.api.dto.ProductsItem
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Store
|
import com.alya.ecommerce_serang.data.api.dto.Store
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.ListStoreTypeResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.ListStoreTypeResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse
|
||||||
@ -52,48 +53,49 @@ class MyStoreRepository(private val apiService: ApiService) {
|
|||||||
|
|
||||||
suspend fun updateStoreProfile(
|
suspend fun updateStoreProfile(
|
||||||
storeName: RequestBody,
|
storeName: RequestBody,
|
||||||
storeStatus: RequestBody,
|
|
||||||
storeDescription: RequestBody,
|
storeDescription: RequestBody,
|
||||||
isOnLeave: RequestBody,
|
isOnLeave: RequestBody,
|
||||||
cityId: RequestBody,
|
|
||||||
provinceId: RequestBody,
|
|
||||||
street: RequestBody,
|
|
||||||
subdistrict: RequestBody,
|
|
||||||
detail: RequestBody,
|
|
||||||
postalCode: RequestBody,
|
|
||||||
latitude: RequestBody,
|
|
||||||
longitude: RequestBody,
|
|
||||||
userPhone: RequestBody,
|
|
||||||
storeType: RequestBody,
|
storeType: RequestBody,
|
||||||
storeimg: MultipartBody.Part?
|
storeimg: MultipartBody.Part?
|
||||||
): Response<StoreDataResponse> {
|
): Response<StoreDataResponse>? {
|
||||||
return apiService.updateStoreProfileMultipart(
|
|
||||||
storeName, storeStatus, storeDescription, isOnLeave, cityId, provinceId,
|
return try {
|
||||||
street, subdistrict, detail, postalCode, latitude, longitude, userPhone, storeType, storeimg
|
Log.d(TAG, "storeName: $storeName")
|
||||||
|
Log.d(TAG, "storeDescription: $storeDescription")
|
||||||
|
Log.d(TAG, "isOnLeave: $isOnLeave")
|
||||||
|
Log.d(TAG, "storeType: $storeType")
|
||||||
|
Log.d(TAG, "storeimg: ${storeimg?.headers}")
|
||||||
|
|
||||||
|
apiService.updateStoreProfileMultipart(
|
||||||
|
storeName, storeDescription, isOnLeave, storeType, storeimg
|
||||||
)
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error updating store profile", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSellList(status: String): Result<OrderListResponse> {
|
suspend fun getSellList(status: String): Result<OrderListResponse> {
|
||||||
return try {
|
return try {
|
||||||
Log.d("SellsRepository", "Add Evidence : $status")
|
Log.d(TAG, "Add Evidence : $status")
|
||||||
val response = apiService.getSellList(status)
|
val response = apiService.getSellList(status)
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val allListSell = response.body()
|
val allListSell = response.body()
|
||||||
if (allListSell != null) {
|
if (allListSell != null) {
|
||||||
Log.d("SellsRepository", "Add Evidence successfully: ${allListSell.message}")
|
Log.d(TAG, "Add Evidence successfully: ${allListSell.message}")
|
||||||
Result.Success(allListSell)
|
Result.Success(allListSell)
|
||||||
} else {
|
} else {
|
||||||
Log.e("SellsRepository", "Response body was null")
|
Log.e(TAG, "Response body was null")
|
||||||
Result.Error(Exception("Empty response from server"))
|
Result.Error(Exception("Empty response from server"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
||||||
Log.e("SellsRepository", "Error Add Evidence : $errorBody")
|
Log.e(TAG, "Error Add Evidence : $errorBody")
|
||||||
Result.Error(Exception(errorBody))
|
Result.Error(Exception(errorBody))
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("SellsRepository", "Exception Add Evidence ", e)
|
Log.e(TAG, "Exception Add Evidence ", e)
|
||||||
Result.Error(e)
|
Result.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,11 +120,29 @@ class MyStoreRepository(private val apiService: ApiService) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("MyStoreRepository", "Error fetching balance", e)
|
Log.e(TAG, "Error fetching balance", e)
|
||||||
Result.Error(e)
|
Result.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun fetchMyStoreProducts(): List<ProductsItem> {
|
||||||
|
return try {
|
||||||
|
val response = apiService.getStoreProduct()
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
response.body()?.products?.filterNotNull() ?: emptyList()
|
||||||
|
} else {
|
||||||
|
throw Exception("Failed to fetch store products: ${response.message()}")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error fetching store products", e)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private var TAG = "MyStoreRepository"
|
||||||
|
}
|
||||||
|
|
||||||
// private fun fetchBalance() {
|
// private fun fetchBalance() {
|
||||||
// showLoading(true)
|
// showLoading(true)
|
||||||
// lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
|
@ -20,12 +20,16 @@ import com.alya.ecommerce_serang.data.api.response.customer.order.ListCityRespon
|
|||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.ListProvinceResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.order.ListProvinceResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.OrderDetailResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.order.OrderDetailResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.OrderListResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.order.OrderListResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.VillagesResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.DetailPaymentItem
|
import com.alya.ecommerce_serang.data.api.response.customer.product.DetailPaymentItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.ProductResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.product.ProductResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreItem
|
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressDetailResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.CreateAddressResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.CreateAddressResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.UpdateAddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.order.AddEvidenceResponse
|
import com.alya.ecommerce_serang.data.api.response.order.AddEvidenceResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.order.ComplaintResponse
|
import com.alya.ecommerce_serang.data.api.response.order.ComplaintResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.order.CompletedOrderResponse
|
import com.alya.ecommerce_serang.data.api.response.order.CompletedOrderResponse
|
||||||
@ -294,6 +298,43 @@ class OrderRepository(private val apiService: ApiService) {
|
|||||||
return if (response.isSuccessful) response.body() else null
|
return if (response.isSuccessful) response.body() else null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getListSubdistrict(cityId : String): SubdistrictResponse? {
|
||||||
|
val response = apiService.getSubdistrict(cityId)
|
||||||
|
return if (response.isSuccessful) response.body() else null
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getListVillages(subId: String): VillagesResponse? {
|
||||||
|
val response = apiService.getVillages(subId)
|
||||||
|
return if (response.isSuccessful) response.body() else null
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getAddressDetail(addressId: Int): AddressDetailResponse? {
|
||||||
|
return try {
|
||||||
|
Log.d("Order Repository", "Fetching address detail for ID: $addressId")
|
||||||
|
|
||||||
|
val response = apiService.getDetailAddress(addressId)
|
||||||
|
|
||||||
|
Log.d("Order Repository", "Response code: ${response.code()}")
|
||||||
|
Log.d("Order Repository", "Response message: ${response.message()}")
|
||||||
|
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
val body = response.body()
|
||||||
|
Log.d("Order Repository", "Address detail response body: $body")
|
||||||
|
body
|
||||||
|
} else {
|
||||||
|
Log.w("Order Repository", "Failed to get address detail. Error body: ${response.errorBody()?.string()}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Order Repository", "Error getting address detail", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun updateAddress(addressId: Int, params: Map<String, Any>): Response<UpdateAddressResponse> {
|
||||||
|
return apiService.updateAddress(addressId, params)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun fetchUserProfile(): Result<UserProfile?> {
|
suspend fun fetchUserProfile(): Result<UserProfile?> {
|
||||||
return try {
|
return try {
|
||||||
val response = apiService.getUserProfile()
|
val response = apiService.getUserProfile()
|
||||||
@ -319,6 +360,7 @@ class OrderRepository(private val apiService: ApiService) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
suspend fun uploadPaymentProof(request: AddEvidenceMultipartRequest): Result<AddEvidenceResponse> {
|
suspend fun uploadPaymentProof(request: AddEvidenceMultipartRequest): Result<AddEvidenceResponse> {
|
||||||
return try {
|
return try {
|
||||||
Log.d("OrderRepository", "Uploading payment proof...")
|
Log.d("OrderRepository", "Uploading payment proof...")
|
||||||
|
@ -7,6 +7,7 @@ import com.alya.ecommerce_serang.data.api.dto.FcmReq
|
|||||||
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.OtpRequest
|
import com.alya.ecommerce_serang.data.api.dto.OtpRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.RegisterRequest
|
import com.alya.ecommerce_serang.data.api.dto.RegisterRequest
|
||||||
|
import com.alya.ecommerce_serang.data.api.dto.ResetPassReq
|
||||||
import com.alya.ecommerce_serang.data.api.dto.UserProfile
|
import com.alya.ecommerce_serang.data.api.dto.UserProfile
|
||||||
import com.alya.ecommerce_serang.data.api.dto.VerifRegisReq
|
import com.alya.ecommerce_serang.data.api.dto.VerifRegisReq
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.FcmTokenResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.FcmTokenResponse
|
||||||
@ -18,6 +19,7 @@ import com.alya.ecommerce_serang.data.api.response.auth.NotifstoreItem
|
|||||||
import com.alya.ecommerce_serang.data.api.response.auth.OtpResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.OtpResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.RegisterResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.RegisterResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.RegisterStoreResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.RegisterStoreResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.auth.ResetPassResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.VerifRegisterResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.VerifRegisterResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.ListCityResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.order.ListCityResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.ListProvinceResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.order.ListProvinceResponse
|
||||||
@ -278,6 +280,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)")
|
||||||
@ -485,6 +492,30 @@ class UserRepository(private val apiService: ApiService) {
|
|||||||
Result.Error(e)
|
Result.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun resetPassword(request: ResetPassReq): Result<ResetPassResponse>{
|
||||||
|
return try {
|
||||||
|
val response = apiService.postResetPass(request)
|
||||||
|
|
||||||
|
if (response.isSuccessful){
|
||||||
|
val resetPassResponse = response.body()
|
||||||
|
if (resetPassResponse != null) {
|
||||||
|
Result.Success(resetPassResponse)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Result.Error(Exception("Empty response from server"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
||||||
|
Log.e(TAG, "Error RESET PASS address: $errorBody")
|
||||||
|
Result.Error(Exception(errorBody))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e: Exception){
|
||||||
|
Result.Error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
companion object{
|
companion object{
|
||||||
private const val TAG = "UserRepository"
|
private const val TAG = "UserRepository"
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,11 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
startActivity(Intent(this, RegisterActivity::class.java))
|
startActivity(Intent(this, RegisterActivity::class.java))
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.tvForgetPassword.setOnClickListener {
|
||||||
|
startActivity(Intent(this, ResetPassActivity::class.java))
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeLoginState() {
|
private fun observeLoginState() {
|
||||||
|
@ -0,0 +1,123 @@
|
|||||||
|
package com.alya.ecommerce_serang.ui.auth
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.viewModels
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||||
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
|
import com.alya.ecommerce_serang.data.repository.UserRepository
|
||||||
|
import com.alya.ecommerce_serang.databinding.ActivityResetPassBinding
|
||||||
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
|
import com.alya.ecommerce_serang.utils.viewmodel.LoginViewModel
|
||||||
|
|
||||||
|
class ResetPassActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private val TAG = "ResetPassActivity"
|
||||||
|
private lateinit var binding: ActivityResetPassBinding
|
||||||
|
|
||||||
|
private val loginViewModel: LoginViewModel by viewModels{
|
||||||
|
BaseViewModelFactory {
|
||||||
|
val apiService = ApiConfig.getUnauthenticatedApiService()
|
||||||
|
val userRepository = UserRepository(apiService)
|
||||||
|
LoginViewModel(userRepository, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
binding = ActivityResetPassBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
// enableEdgeToEdge()
|
||||||
|
|
||||||
|
setupToolbar()
|
||||||
|
setupUI()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupToolbar(){
|
||||||
|
binding.headerResetPass.headerLeftIcon.setOnClickListener{
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
binding.headerResetPass.headerTitle.text = "Lupa Password"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupUI(){
|
||||||
|
binding.btnReset.setOnClickListener {
|
||||||
|
val email = binding.etEmail.text.toString().trim()
|
||||||
|
if (email.isNotEmpty()) {
|
||||||
|
loginViewModel.resetPassword(email)
|
||||||
|
} else {
|
||||||
|
binding.etEmail.error = "Masukkan Email Anda"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun observeResetPassword() {
|
||||||
|
loginViewModel.resetPasswordState.observe(this) { result ->
|
||||||
|
when (result) {
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Loading -> {
|
||||||
|
showLoading(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Success -> {
|
||||||
|
showLoading(false)
|
||||||
|
handleSuccess("Silahkan cek email anda untuk melihat password anda.")
|
||||||
|
Log.d(TAG, "Success rest password: ${result.data.message}")
|
||||||
|
}
|
||||||
|
|
||||||
|
is Result.Error -> {
|
||||||
|
showLoading(false)
|
||||||
|
handleError("Email anda salah atau tidak ditemukan.")
|
||||||
|
Log.e(TAG, "Error reset password ${result.exception.message}")
|
||||||
|
}
|
||||||
|
|
||||||
|
null -> {
|
||||||
|
// Initial state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showLoading(isLoading: Boolean) {
|
||||||
|
if (isLoading) {
|
||||||
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
|
binding.btnReset.isEnabled = false
|
||||||
|
binding.etEmail.isEnabled = false
|
||||||
|
} else {
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
binding.btnReset.isEnabled = true
|
||||||
|
binding.etEmail.isEnabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleSuccess(message: String) {
|
||||||
|
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
||||||
|
|
||||||
|
// Show success dialog and navigate back to login
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle("Berhasil Ubah Password")
|
||||||
|
.setMessage(message)
|
||||||
|
.setPositiveButton("OK") { _, _ ->
|
||||||
|
// Navigate back to login activity
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
.setCancelable(false)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleError(errorMessage: String) {
|
||||||
|
Toast.makeText(this, "Error: $errorMessage", Toast.LENGTH_LONG).show()
|
||||||
|
|
||||||
|
// Optionally show error dialog
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle("Gagal Ubah Password")
|
||||||
|
.setMessage(errorMessage)
|
||||||
|
.setPositiveButton("OK", null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,7 @@ import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
|||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
import com.alya.ecommerce_serang.utils.viewmodel.RegisterViewModel
|
import com.alya.ecommerce_serang.utils.viewmodel.RegisterViewModel
|
||||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
|
import com.google.gson.Gson
|
||||||
|
|
||||||
class RegisterStep3Fragment : Fragment() {
|
class RegisterStep3Fragment : Fragment() {
|
||||||
private var _binding: FragmentRegisterStep3Binding? = null
|
private var _binding: FragmentRegisterStep3Binding? = null
|
||||||
@ -237,7 +238,8 @@ class RegisterStep3Fragment : Fragment() {
|
|||||||
|
|
||||||
binding.autoCompleteKecamatan.setOnItemClickListener{ _, _, position, _ ->
|
binding.autoCompleteKecamatan.setOnItemClickListener{ _, _, position, _ ->
|
||||||
val subdistrictId = subdistrictAdapter.getSubdistrictId(position)
|
val subdistrictId = subdistrictAdapter.getSubdistrictId(position)
|
||||||
Log.d(TAG, "Subdistrict selected at position $position, ID: $subdistrictId")
|
val subdistictName = subdistrictAdapter.getSubdistrictName(position)
|
||||||
|
Log.d(TAG, "Subdistrict selected at position $position, ID: $subdistrictId, name: $subdistictName")
|
||||||
|
|
||||||
subdistrictId?.let { id ->
|
subdistrictId?.let { id ->
|
||||||
Log.d(TAG, "Selected subdistrict ID set to: $id")
|
Log.d(TAG, "Selected subdistrict ID set to: $id")
|
||||||
@ -245,11 +247,16 @@ class RegisterStep3Fragment : Fragment() {
|
|||||||
registerViewModel.getVillages(id)
|
registerViewModel.getVillages(id)
|
||||||
binding.autoCompleteDesa.text.clear()
|
binding.autoCompleteDesa.text.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subdistictName?.let { name ->
|
||||||
|
Log.d(TAG, "Selected name subdistrict set to: $name")
|
||||||
|
registerViewModel.subdistrictName = name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ->
|
||||||
@ -257,11 +264,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 ?: "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,11 +377,14 @@ 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.subdistrictName.toString()
|
||||||
val postalCode = registerViewModel.selectedPostalCode.toString()
|
// val postalCode = registerViewModel.selectedPostalCode.toString()
|
||||||
|
|
||||||
|
val villageId = registerViewModel.selectedVillages ?: ""
|
||||||
|
|
||||||
Log.d(TAG, "Address data - Street: $street, SubDistrict: $subDistrict, PostalCode: $postalCode")
|
Log.d(TAG, "Address data - Street: $street, SubDistrict: $subDistrict, PostalCode: $postalCode")
|
||||||
Log.d(TAG, "Address data - Recipient: $recipient, Phone: $phone")
|
Log.d(TAG, "Address data - Recipient: $recipient, Phone: $phone")
|
||||||
@ -383,21 +393,25 @@ class RegisterStep3Fragment : Fragment() {
|
|||||||
|
|
||||||
// Create address request
|
// Create address request
|
||||||
val addressRequest = CreateAddressRequest(
|
val addressRequest = CreateAddressRequest(
|
||||||
|
userId = user.id, // must match the type expected in the DB
|
||||||
lat = defaultLatitude,
|
lat = defaultLatitude,
|
||||||
long = defaultLongitude,
|
long = defaultLongitude,
|
||||||
street = street,
|
street = street,
|
||||||
subDistrict = subDistrict,
|
subDistrict = subDistrict,
|
||||||
cityId = cityId,
|
cityId = cityId, // ⚠️ Make sure this is Int
|
||||||
provId = provinceId,
|
provId = provinceId,
|
||||||
postCode = postalCode,
|
postCode = postalCode,
|
||||||
|
idVillage = villageId, // Or provide a real ID if needed
|
||||||
detailAddress = street,
|
detailAddress = street,
|
||||||
userId = userId,
|
isStoreLocation = false,
|
||||||
recipient = recipient,
|
recipient = recipient,
|
||||||
phone = phone,
|
phone = phone
|
||||||
isStoreLocation = false
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Log.d(TAG, "Address request created: $addressRequest")
|
Log.d(TAG, "Address request created: $addressRequest")
|
||||||
|
val gson = Gson()
|
||||||
|
val jsonString = gson.toJson(addressRequest)
|
||||||
|
Log.d(TAG, "Request JSON: $jsonString")
|
||||||
|
|
||||||
// Show loading
|
// Show loading
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
@ -415,7 +429,7 @@ class RegisterStep3Fragment : Fragment() {
|
|||||||
|
|
||||||
val provinceId = registerViewModel.selectedProvinceId
|
val provinceId = registerViewModel.selectedProvinceId
|
||||||
val cityId = registerViewModel.selectedCityId
|
val cityId = registerViewModel.selectedCityId
|
||||||
val subDistrict = registerViewModel.selectedSubdistrict.toString()
|
val subDistrict = registerViewModel.selectedSubdistrict
|
||||||
val postalCode = registerViewModel.selectedPostalCode
|
val postalCode = registerViewModel.selectedPostalCode
|
||||||
|
|
||||||
Log.d(TAG, "Validating - Street: $street, SubDistrict: $subDistrict, PostalCode: $postalCode")
|
Log.d(TAG, "Validating - Street: $street, SubDistrict: $subDistrict, PostalCode: $postalCode")
|
||||||
@ -454,6 +468,12 @@ class RegisterStep3Fragment : Fragment() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subDistrict == null) {
|
||||||
|
showError("Pilih kota/kabupaten terlebih dahulu")
|
||||||
|
binding.autoCompleteKecamatan.requestFocus()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@ class CartActivity : AppCompatActivity() {
|
|||||||
private lateinit var sessionManager: SessionManager
|
private lateinit var sessionManager: SessionManager
|
||||||
private lateinit var storeAdapter: StoreAdapter
|
private lateinit var storeAdapter: StoreAdapter
|
||||||
|
|
||||||
|
private var TAG = "Cart Activity"
|
||||||
|
|
||||||
private val viewModel: CartViewModel by viewModels {
|
private val viewModel: CartViewModel by viewModels {
|
||||||
BaseViewModelFactory {
|
BaseViewModelFactory {
|
||||||
val apiService = ApiConfig.getApiService(sessionManager)
|
val apiService = ApiConfig.getApiService(sessionManager)
|
||||||
@ -135,18 +137,42 @@ class CartActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startCheckoutWithWholesaleInfo(checkoutItems: List<CartItemCheckoutInfo>) {
|
private fun startCheckoutWithWholesaleInfo(checkoutItems: List<CartItemCheckoutInfo>) {
|
||||||
// Extract cart item IDs and wholesale status
|
val wholesalePriceMap = viewModel.cartItemWholesalePrice.value ?: emptyMap()
|
||||||
val cartItemIds = checkoutItems.map { it.cartItem.cartItemId }
|
|
||||||
val wholesaleArray = checkoutItems.map { it.isWholesale }.toBooleanArray()
|
val updatedItems = checkoutItems.map { info ->
|
||||||
|
val wholesalePrice = wholesalePriceMap[info.cartItem.cartItemId]
|
||||||
|
|
||||||
|
val updatedCartItem = if (info.isWholesale && wholesalePrice != null) {
|
||||||
|
// Replace the price with wholesale price
|
||||||
|
info.cartItem.copy(price = wholesalePrice.toInt())
|
||||||
|
} else {
|
||||||
|
info.cartItem
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug log
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"cartItemId: ${updatedCartItem.cartItemId}, " +
|
||||||
|
"isWholesale: ${info.isWholesale}, " +
|
||||||
|
"wholesalePrice: $wholesalePrice, " +
|
||||||
|
"finalPrice: ${updatedCartItem.price}"
|
||||||
|
)
|
||||||
|
|
||||||
|
info.copy(cartItem = updatedCartItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
val cartItemIds = updatedItems.map { it.cartItem.cartItemId }
|
||||||
|
val wholesaleArray = updatedItems.map { it.isWholesale }.toBooleanArray()
|
||||||
|
|
||||||
// Start checkout activity with the cart items and wholesale info
|
|
||||||
CheckoutActivity.startForCart(this, cartItemIds, wholesaleArray)
|
CheckoutActivity.startForCart(this, cartItemIds, wholesaleArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeViewModel() {
|
private fun observeViewModel() {
|
||||||
viewModel.cartItems.observe(this) { cartItems ->
|
viewModel.cartItems.observe(this) { cartItems ->
|
||||||
if (cartItems.isNullOrEmpty()) {
|
if (cartItems.isNullOrEmpty()) {
|
||||||
|
binding.emptyCart.visibility = View.VISIBLE
|
||||||
showEmptyState(true)
|
showEmptyState(true)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
showEmptyState(false)
|
showEmptyState(false)
|
||||||
storeAdapter.submitList(cartItems)
|
storeAdapter.submitList(cartItems)
|
||||||
@ -231,7 +257,5 @@ class CartActivity : AppCompatActivity() {
|
|||||||
val format = NumberFormat.getCurrencyInstance(Locale("id", "ID"))
|
val format = NumberFormat.getCurrencyInstance(Locale("id", "ID"))
|
||||||
return format.format(amount).replace("Rp", "Rp ")
|
return format.format(amount).replace("Rp", "Rp ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import androidx.core.view.WindowCompat
|
|||||||
import androidx.core.view.WindowInsetsAnimationCompat
|
import androidx.core.view.WindowInsetsAnimationCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
||||||
import com.alya.ecommerce_serang.R
|
import com.alya.ecommerce_serang.R
|
||||||
@ -170,8 +171,7 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// If opened from ChatListFragment with a valid chatRoomId
|
// If opened from ChatListFragment with a valid chatRoomId
|
||||||
if (chatRoomId > 0) {
|
if (chatRoomId > 0) {
|
||||||
// Directly set the chatRoomId and load chat history
|
viewModel.setChatRoomId(chatRoomId)
|
||||||
viewModel._chatRoomId.value = chatRoomId
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +405,8 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.state.observe(this, Observer { state ->
|
lifecycleScope.launchWhenStarted {
|
||||||
|
viewModel.state.collect() { state ->
|
||||||
Log.d(TAG, "State updated - Messages: ${state.messages.size}")
|
Log.d(TAG, "State updated - Messages: ${state.messages.size}")
|
||||||
|
|
||||||
// Update messages
|
// Update messages
|
||||||
@ -434,6 +435,7 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
is String -> {
|
is String -> {
|
||||||
if (img.startsWith("/")) BASE_URL + img.substring(1) else img
|
if (img.startsWith("/")) BASE_URL + img.substring(1) else img
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> R.drawable.placeholder_image
|
else -> R.drawable.placeholder_image
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,7 +468,8 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
Toast.makeText(this@ChatActivity, error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@ChatActivity, error, Toast.LENGTH_SHORT).show()
|
||||||
viewModel.clearError()
|
viewModel.clearError()
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateInputHint(state: ChatUiState) {
|
private fun updateInputHint(state: ChatUiState) {
|
||||||
|
@ -209,7 +209,7 @@ class ChatAdapter(
|
|||||||
binding.tvProductPrice.text = product.productPrice
|
binding.tvProductPrice.text = product.productPrice
|
||||||
|
|
||||||
// Load product image
|
// Load product image
|
||||||
val fullImageUrl = if (product.productImage.startsWith("/")) {
|
val fullImageUrl = if (product.productImage!!.startsWith("/")) {
|
||||||
BASE_URL + product.productImage.substring(1)
|
BASE_URL + product.productImage.substring(1)
|
||||||
} else {
|
} else {
|
||||||
product.productImage
|
product.productImage
|
||||||
@ -246,7 +246,7 @@ class ChatAdapter(
|
|||||||
binding.tvProductPrice.text = product.productPrice
|
binding.tvProductPrice.text = product.productPrice
|
||||||
|
|
||||||
// Load product image
|
// Load product image
|
||||||
val fullImageUrl = if (product.productImage.startsWith("/")) {
|
val fullImageUrl = if (product.productImage!!.startsWith("/")) {
|
||||||
BASE_URL + product.productImage.substring(1)
|
BASE_URL + product.productImage.substring(1)
|
||||||
} else {
|
} else {
|
||||||
product.productImage
|
product.productImage
|
||||||
|
@ -14,6 +14,9 @@ import com.alya.ecommerce_serang.data.repository.Result
|
|||||||
import com.alya.ecommerce_serang.utils.Constants
|
import com.alya.ecommerce_serang.utils.Constants
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@ -56,9 +59,9 @@ class ChatViewModel @Inject constructor(
|
|||||||
// Product attachment flag
|
// Product attachment flag
|
||||||
private var shouldAttachProduct = false
|
private var shouldAttachProduct = false
|
||||||
|
|
||||||
// UI state using LiveData
|
// use state for more seamless responsive
|
||||||
private val _state = MutableLiveData(ChatUiState())
|
private val _state = MutableStateFlow(ChatUiState())
|
||||||
val state: LiveData<ChatUiState> = _state
|
val state: StateFlow<ChatUiState> = _state
|
||||||
|
|
||||||
private val _isLoading = MutableLiveData<Boolean>()
|
private val _isLoading = MutableLiveData<Boolean>()
|
||||||
val isLoading: LiveData<Boolean> = _isLoading
|
val isLoading: LiveData<Boolean> = _isLoading
|
||||||
@ -93,6 +96,8 @@ class ChatViewModel @Inject constructor(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d(TAG, "ChatViewModel initialized")
|
Log.d(TAG, "ChatViewModel initialized")
|
||||||
|
socketService.connect() // 🛠 force connection
|
||||||
|
setupSocketListeners() // 🛠 always listen, even before user data
|
||||||
initializeUser()
|
initializeUser()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +118,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
updateState { it.copy(error = "User authentication error. Please login again.") }
|
updateState { it.copy(error = "User authentication error. Please login again.") }
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Setting up socket listeners...")
|
Log.d(TAG, "Setting up socket listeners...")
|
||||||
|
socketService.connect()
|
||||||
setupSocketListeners()
|
setupSocketListeners()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,26 +237,116 @@ class ChatViewModel @Inject constructor(
|
|||||||
|
|
||||||
if (connectionState is ConnectionState.Connected) {
|
if (connectionState is ConnectionState.Connected) {
|
||||||
Log.d(TAG, "Socket connected, joining room...")
|
Log.d(TAG, "Socket connected, joining room...")
|
||||||
socketService.joinRoom()
|
val roomId = _chatRoomId.value
|
||||||
|
if (roomId != null && roomId > 0) {
|
||||||
|
socketService.joinRoom(roomId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// viewModelScope.launch {
|
||||||
|
// socketService.newMessages.collect { chatLine ->
|
||||||
|
// chatLine?.let {
|
||||||
|
// Log.d(TAG, "NEW message received in ViewModel: ${it.message}")
|
||||||
|
// val updatedMessages = _state.value.messages.toMutableList()
|
||||||
|
// updatedMessages.add(convertChatLineToUiMessage(it))
|
||||||
|
// updateState { it.copy(messages = updatedMessages) }
|
||||||
|
//
|
||||||
|
// if (it.senderId != currentUserId) {
|
||||||
|
// updateMessageStatus(it.id, Constants.STATUS_READ)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
socketService.newMessages.collect { chatLine ->
|
socketService.newMessages.collect { chatLine ->
|
||||||
chatLine?.let {
|
Log.d("ChatViewModel", "Collected new message from SocketIOService: ${chatLine.message}")
|
||||||
Log.d(TAG, "New message received via socket - ID: ${it.id}, SenderID: ${it.senderId}")
|
chatLine?.let { incomingChatLine ->
|
||||||
val currentMessages = _state.value?.messages ?: listOf()
|
// 1. First update: Add the message to the list (potentially without full product info)
|
||||||
val updatedMessages = currentMessages.toMutableList().apply {
|
_state.update { currentState ->
|
||||||
add(convertChatLineToUiMessage(it))
|
val existingMessageIndex =
|
||||||
|
currentState.messages.indexOfFirst { it.id == incomingChatLine.id }
|
||||||
|
val messagesAfterInitialUpdate = if (existingMessageIndex != -1) {
|
||||||
|
// If message exists (e.g., status update), just update it
|
||||||
|
val updatedList = currentState.messages.toMutableList()
|
||||||
|
updatedList[existingMessageIndex] = mapChatLineToUiMessage(
|
||||||
|
incomingChatLine,
|
||||||
|
updatedList[existingMessageIndex].productInfo
|
||||||
|
) // Preserve existing productInfo if any
|
||||||
|
updatedList
|
||||||
|
} else {
|
||||||
|
// New message, add it
|
||||||
|
(currentState.messages + mapChatLineToUiMessage(incomingChatLine)).distinctBy { msg -> msg.id }
|
||||||
|
}
|
||||||
|
// Sort after any update/addition
|
||||||
|
currentState.copy(messages = messagesAfterInitialUpdate.sortedBy { msg ->
|
||||||
|
SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd HH:mm:ss",
|
||||||
|
Locale.getDefault()
|
||||||
|
).parse(msg.createdAt)?.time
|
||||||
|
})
|
||||||
}
|
}
|
||||||
updateState { it.copy(messages = updatedMessages) }
|
|
||||||
|
|
||||||
if (it.senderId != currentUserId) {
|
// 2. If it's a product message and needs details, fetch them
|
||||||
Log.d(TAG, "Marking message as read: ${it.id}")
|
if (incomingChatLine.productId != 0) { // Check if it's a product message
|
||||||
updateMessageStatus(it.id, Constants.STATUS_READ)
|
viewModelScope.launch {
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"Fetching product detail for ID: ${incomingChatLine.productId}"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Call your repository function directly
|
||||||
|
val productResponse =
|
||||||
|
chatRepository.fetchProductDetail(incomingChatLine.productId)
|
||||||
|
|
||||||
|
if (productResponse != null && productResponse.product != null) {
|
||||||
|
val fetchedProduct =
|
||||||
|
productResponse.product // Access the nested product object
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"Successfully fetched product: ${fetchedProduct.productName}"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create a complete ProductInfo object
|
||||||
|
val fullProductInfo = ProductInfo(
|
||||||
|
productId = fetchedProduct.productId,
|
||||||
|
productName = fetchedProduct.productName, // Use productName from fetched data
|
||||||
|
productPrice = fetchedProduct.price, // Use productPrice from fetched data
|
||||||
|
productImage = fetchedProduct.image, // Use productImage from fetched data
|
||||||
|
productRating = fetchedProduct.rating.toFloat(),
|
||||||
|
storeName = fetchedProduct.productName // Use storeName from fetched data
|
||||||
|
)
|
||||||
|
|
||||||
|
// --- PHASE 3: Second UI update (fill in full product info) ---
|
||||||
|
_state.update { currentState ->
|
||||||
|
val updatedMessages = currentState.messages.map { msg ->
|
||||||
|
if (msg.id == incomingChatLine.id) {
|
||||||
|
// Found the message, update its productInfo with full details
|
||||||
|
msg.copy(productInfo = fullProductInfo)
|
||||||
|
} else {
|
||||||
|
msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentState.copy(messages = updatedMessages)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(
|
||||||
|
TAG,
|
||||||
|
"Failed to fetch product detail for ID ${incomingChatLine.productId} or product data is null."
|
||||||
|
)
|
||||||
|
// Optionally, update message status to indicate error in product loading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Your existing logic for clearing typing status etc.
|
||||||
|
// if (incomingChatLine.isTyping == false && incomingChatLine.from?.id != sessionManager.getUserId()?.toIntOrNull()) {
|
||||||
|
// _state.update { it.copy(isOtherUserTyping = false) }
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,10 +367,10 @@ class ChatViewModel @Inject constructor(
|
|||||||
if (roomId <= 0) {
|
if (roomId <= 0) {
|
||||||
Log.e(TAG, "Cannot join room: Invalid room ID")
|
Log.e(TAG, "Cannot join room: Invalid room ID")
|
||||||
return
|
return
|
||||||
}
|
} else if (roomId > 0){
|
||||||
|
|
||||||
Log.d(TAG, "Joining socket room: $roomId")
|
Log.d(TAG, "Joining socket room: $roomId")
|
||||||
socketService.joinRoom()
|
socketService.joinRoom(roomId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendTypingStatus(isTyping: Boolean) {
|
fun sendTypingStatus(isTyping: Boolean) {
|
||||||
@ -958,9 +1054,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
|
|
||||||
// helper function to update live data
|
// helper function to update live data
|
||||||
private fun updateState(update: (ChatUiState) -> ChatUiState) {
|
private fun updateState(update: (ChatUiState) -> ChatUiState) {
|
||||||
_state.value?.let {
|
_state.value = update(_state.value)
|
||||||
_state.value = update(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//clear any error messages
|
//clear any error messages
|
||||||
@ -1053,6 +1147,73 @@ class ChatViewModel @Inject constructor(
|
|||||||
private fun isThisYear(messageCalendar: Calendar, today: Calendar): Boolean {
|
private fun isThisYear(messageCalendar: Calendar, today: Calendar): Boolean {
|
||||||
return messageCalendar.get(Calendar.YEAR) == today.get(Calendar.YEAR)
|
return messageCalendar.get(Calendar.YEAR) == today.get(Calendar.YEAR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setChatRoomId(roomId: Int) {
|
||||||
|
_chatRoomId.value = roomId
|
||||||
|
joinSocketRoom(roomId)
|
||||||
|
loadChatHistory(roomId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertToUiMessage(chatLine: ChatLine): ChatUiMessage {
|
||||||
|
|
||||||
|
val formattedTime = formatTimestamp(chatLine.createdAt)
|
||||||
|
return ChatUiMessage(
|
||||||
|
id = chatLine.id,
|
||||||
|
message = chatLine.message,
|
||||||
|
attachment = chatLine.attachment,
|
||||||
|
status = chatLine.status,
|
||||||
|
time = formattedTime, // or format from createdAt if needed
|
||||||
|
isSentByMe = chatLine.senderId == currentUserId,
|
||||||
|
messageType = MessageType.TEXT, // or detect from chatLine if needed
|
||||||
|
productInfo = null, // optional, if applicable
|
||||||
|
createdAt = chatLine.createdAt
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mapChatLineToUiMessage(chatLine: ChatLine, fetchedProductInfo: ProductInfo? = null): ChatUiMessage {
|
||||||
|
val isSentByMe = chatLine.senderId == sessionManager.getUserId()?.toIntOrNull() // Using senderId now
|
||||||
|
val formattedTime = try {
|
||||||
|
val inputFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()).apply {
|
||||||
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
|
}
|
||||||
|
val outputFormat = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||||
|
val date = inputFormat.parse(chatLine.createdAt)
|
||||||
|
date?.let { outputFormat.format(it) } ?: ""
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("ChatViewModel", "Error parsing date: ${chatLine.createdAt}", e)
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine message type based on what ChatLine provides
|
||||||
|
val messageType = when {
|
||||||
|
chatLine.attachment?.isNotEmpty() == true -> MessageType.IMAGE
|
||||||
|
chatLine.productId != 0 -> MessageType.PRODUCT // If productId is non-zero, it's a product message
|
||||||
|
else -> MessageType.TEXT
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize productInfo: if fetchedProductInfo is provided, use it.
|
||||||
|
// Otherwise, if ChatLine has a productId, create a ProductInfo with just the ID.
|
||||||
|
// If no productId, it's null.
|
||||||
|
val productInfo = fetchedProductInfo ?: if (chatLine.productId != 0) {
|
||||||
|
// Create a placeholder ProductInfo with just the ID for initial display
|
||||||
|
// The full details will be fetched later
|
||||||
|
ProductInfo(productId = chatLine.productId)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
return ChatUiMessage(
|
||||||
|
id = chatLine.id,
|
||||||
|
message = chatLine.message,
|
||||||
|
attachment = chatLine.attachment,
|
||||||
|
status = chatLine.status,
|
||||||
|
time = formattedTime,
|
||||||
|
isSentByMe = isSentByMe,
|
||||||
|
messageType = messageType,
|
||||||
|
productInfo = productInfo, // Use the determined productInfo
|
||||||
|
createdAt = chatLine.createdAt
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class MessageType {
|
enum class MessageType {
|
||||||
@ -1062,12 +1223,12 @@ enum class MessageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class ProductInfo(
|
data class ProductInfo(
|
||||||
val productId: Int,
|
val productId: Int, // Keep productId here
|
||||||
val productName: String,
|
val productName: String? = null, // Make nullable
|
||||||
val productPrice: String,
|
val productPrice: String? = null, // Make nullable
|
||||||
val productImage: String,
|
val productImage: String? = null, // Make nullable
|
||||||
val productRating: Float,
|
val productRating: Float = 0f, // Default value
|
||||||
val storeName: String
|
val storeName: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
// representing chat messages to UI
|
// representing chat messages to UI
|
||||||
@ -1083,8 +1244,6 @@ data class ChatUiMessage(
|
|||||||
val createdAt: String
|
val createdAt: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// representing UI state to screen
|
// representing UI state to screen
|
||||||
data class ChatUiState(
|
data class ChatUiState(
|
||||||
val messages: List<ChatUiMessage> = emptyList(),
|
val messages: List<ChatUiMessage> = emptyList(),
|
||||||
@ -1103,3 +1262,7 @@ data class ChatUiState(
|
|||||||
val productRating: Float = 0f,
|
val productRating: Float = 0f,
|
||||||
val storeName: String = ""
|
val storeName: String = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//data class ChatUiState(
|
||||||
|
// val messages: List<ChatUiMessage> = emptyList()
|
||||||
|
//)
|
||||||
|
@ -10,14 +10,24 @@ import com.alya.ecommerce_serang.utils.SessionManager
|
|||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import io.socket.client.IO
|
import io.socket.client.IO
|
||||||
import io.socket.client.Socket
|
import io.socket.client.Socket
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.net.URISyntaxException
|
import java.net.URISyntaxException
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
class SocketIOService(
|
@Singleton
|
||||||
|
class SocketIOService @Inject constructor(
|
||||||
private val sessionManager: SessionManager
|
private val sessionManager: SessionManager
|
||||||
) {
|
) {
|
||||||
|
private val serviceScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
private val TAG = "SocketIOService"
|
private val TAG = "SocketIOService"
|
||||||
|
|
||||||
// Socket.IO client
|
// Socket.IO client
|
||||||
@ -30,8 +40,8 @@ class SocketIOService(
|
|||||||
private val _connectionState = MutableStateFlow<ConnectionState>(ConnectionState.Disconnected())
|
private val _connectionState = MutableStateFlow<ConnectionState>(ConnectionState.Disconnected())
|
||||||
val connectionState: StateFlow<ConnectionState> = _connectionState
|
val connectionState: StateFlow<ConnectionState> = _connectionState
|
||||||
|
|
||||||
private val _newMessages = MutableStateFlow<ChatLine?>(null)
|
private val _newMessages = MutableSharedFlow<ChatLine>(extraBufferCapacity = 1) // Using extraBufferCapacity for a non-suspending emit
|
||||||
val newMessages: StateFlow<ChatLine?> = _newMessages
|
val newMessages: SharedFlow<ChatLine> = _newMessages
|
||||||
|
|
||||||
private val _typingStatus = MutableStateFlow<TypingStatus?>(null)
|
private val _typingStatus = MutableStateFlow<TypingStatus?>(null)
|
||||||
val typingStatus: StateFlow<TypingStatus?> = _typingStatus
|
val typingStatus: StateFlow<TypingStatus?> = _typingStatus
|
||||||
@ -85,63 +95,95 @@ class SocketIOService(
|
|||||||
* Sets up Socket.IO event listeners
|
* Sets up Socket.IO event listeners
|
||||||
*/
|
*/
|
||||||
private fun setupSocketListeners() {
|
private fun setupSocketListeners() {
|
||||||
socket?.let { socket ->
|
|
||||||
// Connection events
|
|
||||||
socket.on(Socket.EVENT_CONNECT) {
|
|
||||||
Log.d(TAG, "Socket.IO connected")
|
|
||||||
isConnected = true
|
|
||||||
_connectionState.value = ConnectionState.Connected
|
|
||||||
_connectionStateLiveData.postValue(ConnectionState.Connected)
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.on(Socket.EVENT_DISCONNECT) {
|
socket?.on(Constants.EVENT_NEW_MESSAGE) { args -> // Use the event name your server emits
|
||||||
Log.d(TAG, "Socket.IO disconnected")
|
Log.d(TAG, "Raw event received on ${Constants.EVENT_NEW_MESSAGE}: ${args.firstOrNull()}") // Check raw args
|
||||||
isConnected = false
|
|
||||||
_connectionState.value = ConnectionState.Disconnected("Disconnected from server")
|
|
||||||
_connectionStateLiveData.postValue(ConnectionState.Disconnected("Disconnected from server"))
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.on(Socket.EVENT_CONNECT_ERROR) { args ->
|
if (args.isNotEmpty()) {
|
||||||
val error = if (args.isNotEmpty() && args[0] != null) args[0].toString() else "Unknown error"
|
|
||||||
Log.e(TAG, "Socket.IO connection error: $error")
|
|
||||||
isConnected = false
|
|
||||||
_connectionState.value = ConnectionState.Error("Connection error: $error")
|
|
||||||
_connectionStateLiveData.postValue(ConnectionState.Error("Connection error: $error"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chat events
|
|
||||||
socket.on(Constants.EVENT_NEW_MESSAGE) { args ->
|
|
||||||
try {
|
try {
|
||||||
if (args.isNotEmpty() && args[0] != null) {
|
|
||||||
val messageJson = args[0].toString()
|
val messageJson = args[0].toString()
|
||||||
Log.d(TAG, "Received new message: $messageJson")
|
|
||||||
val chatLine = Gson().fromJson(messageJson, ChatLine::class.java)
|
val chatLine = Gson().fromJson(messageJson, ChatLine::class.java)
|
||||||
_newMessages.value = chatLine
|
Log.d(TAG, "Successfully parsed ChatLine: ${chatLine.message}")
|
||||||
_newMessagesLiveData.postValue(chatLine)
|
Log.d(TAG, "Emitting new message to _newMessages SharedFlow...") // New log
|
||||||
|
|
||||||
|
// Use the serviceScope to launch a coroutine for emit()
|
||||||
|
serviceScope.launch {
|
||||||
|
_newMessages.emit(chatLine) // This ensures every message is processed
|
||||||
|
Log.d(TAG, "New message emitted to SharedFlow.") // New log after emit
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error parsing new message event", e)
|
Log.e(TAG, "Error parsing or emitting new message: ${e.message}", e)
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
Log.w(TAG, "Received empty args for ${Constants.EVENT_NEW_MESSAGE}")
|
||||||
socket.on(Constants.EVENT_TYPING) { args ->
|
|
||||||
try {
|
|
||||||
if (args.isNotEmpty() && args[0] != null) {
|
|
||||||
val typingData = args[0] as JSONObject
|
|
||||||
val userId = typingData.getInt("userId")
|
|
||||||
val roomId = typingData.getInt("roomId")
|
|
||||||
val isTyping = typingData.getBoolean("isTyping")
|
|
||||||
|
|
||||||
Log.d(TAG, "Received typing status: User $userId in room $roomId is typing: $isTyping")
|
|
||||||
val status = TypingStatus(userId, roomId, isTyping)
|
|
||||||
_typingStatus.value = status
|
|
||||||
_typingStatusLiveData.postValue(status)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Error parsing typing event", e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// socket?.on(Constants.EVENT_NEW_MESSAGE) { args ->
|
||||||
|
// if (args.isNotEmpty()) {
|
||||||
|
// val messageJson = args[0].toString()
|
||||||
|
// val chatLine = Gson().fromJson(messageJson, ChatLine::class.java)
|
||||||
|
// Log.d("SocketIOService", "Message received: ${chatLine.message}")
|
||||||
|
// _newMessages.value = chatLine
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// socket?.let { socket ->
|
||||||
|
// // Connection events
|
||||||
|
// socket.on(Socket.EVENT_CONNECT) {
|
||||||
|
// Log.d(TAG, "Socket.IO connected")
|
||||||
|
// isConnected = true
|
||||||
|
// _connectionState.value = ConnectionState.Connected
|
||||||
|
// _connectionStateLiveData.postValue(ConnectionState.Connected)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// socket.on(Socket.EVENT_DISCONNECT) {
|
||||||
|
// Log.d(TAG, "Socket.IO disconnected")
|
||||||
|
// isConnected = false
|
||||||
|
// _connectionState.value = ConnectionState.Disconnected("Disconnected from server")
|
||||||
|
// _connectionStateLiveData.postValue(ConnectionState.Disconnected("Disconnected from server"))
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// socket.on(Socket.EVENT_CONNECT_ERROR) { args ->
|
||||||
|
// val error = if (args.isNotEmpty() && args[0] != null) args[0].toString() else "Unknown error"
|
||||||
|
// Log.e(TAG, "Socket.IO connection error: $error")
|
||||||
|
// isConnected = false
|
||||||
|
// _connectionState.value = ConnectionState.Error("Connection error: $error")
|
||||||
|
// _connectionStateLiveData.postValue(ConnectionState.Error("Connection error: $error"))
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Chat events
|
||||||
|
// socket.on(Constants.EVENT_NEW_MESSAGE) { args ->
|
||||||
|
// try {
|
||||||
|
// if (args.isNotEmpty() && args[0] != null) {
|
||||||
|
// val messageJson = args[0].toString()
|
||||||
|
// Log.d(TAG, "Received new message: $messageJson")
|
||||||
|
// val chatLine = Gson().fromJson(messageJson, ChatLine::class.java)
|
||||||
|
// _newMessages.value = chatLine
|
||||||
|
// _newMessagesLiveData.postValue(chatLine)
|
||||||
|
// }
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Error parsing new message event", e)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// socket.on(Constants.EVENT_TYPING) { args ->
|
||||||
|
// try {
|
||||||
|
// if (args.isNotEmpty() && args[0] != null) {
|
||||||
|
// val typingData = args[0] as JSONObject
|
||||||
|
// val userId = typingData.getInt("userId")
|
||||||
|
// val roomId = typingData.getInt("roomId")
|
||||||
|
// val isTyping = typingData.getBoolean("isTyping")
|
||||||
|
//
|
||||||
|
// Log.d(TAG, "Received typing status: User $userId in room $roomId is typing: $isTyping")
|
||||||
|
// val status = TypingStatus(userId, roomId, isTyping)
|
||||||
|
// _typingStatus.value = status
|
||||||
|
// _typingStatusLiveData.postValue(status)
|
||||||
|
// }
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Error parsing typing event", e)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,22 +201,29 @@ class SocketIOService(
|
|||||||
/**
|
/**
|
||||||
* Joins a specific chat room
|
* Joins a specific chat room
|
||||||
*/
|
*/
|
||||||
fun joinRoom() {
|
fun joinRoom(roomId: Int) {
|
||||||
|
// if (!isConnected) {
|
||||||
|
// connect()
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Get user ID from SessionManager
|
||||||
|
// val userId = sessionManager.getUserId()
|
||||||
|
// if (userId.isNullOrEmpty()) {
|
||||||
|
// Log.e(TAG, "Cannot join room: User ID is null or empty")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Join the room using the current user's ID
|
||||||
|
// socket?.emit("joinRoom", roomId) // ✅
|
||||||
|
// Log.d(TAG, "Joined room ID: $roomId")
|
||||||
|
// Log.d(TAG, "Joined room for user: $userId")
|
||||||
if (!isConnected) {
|
if (!isConnected) {
|
||||||
connect()
|
connect()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user ID from SessionManager
|
socket?.emit("joinRoom", roomId)
|
||||||
val userId = sessionManager.getUserId()
|
Log.d(TAG, "Joined room ID: $roomId")
|
||||||
if (userId.isNullOrEmpty()) {
|
|
||||||
Log.e(TAG, "Cannot join room: User ID is null or empty")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Join the room using the current user's ID
|
|
||||||
socket?.emit("joinRoom", userId)
|
|
||||||
Log.d(TAG, "Joined room for user: $userId")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,6 +79,9 @@ class CheckoutActivity : AppCompatActivity() {
|
|||||||
// Determine if this is Buy Now or Cart checkout
|
// Determine if this is Buy Now or Cart checkout
|
||||||
val isBuyNow = intent.hasExtra(EXTRA_PRODUCT_ID) && !intent.hasExtra(EXTRA_CART_ITEM_IDS)
|
val isBuyNow = intent.hasExtra(EXTRA_PRODUCT_ID) && !intent.hasExtra(EXTRA_CART_ITEM_IDS)
|
||||||
val isWholesaleNow = intent.getBooleanExtra(EXTRA_ISWHOLESALE, false)
|
val isWholesaleNow = intent.getBooleanExtra(EXTRA_ISWHOLESALE, false)
|
||||||
|
val wholesalePricesArray = intent.getIntArrayExtra(EXTRA_CART_ITEM_WHOLESALE_PRICES)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (isBuyNow) {
|
if (isBuyNow) {
|
||||||
// Process Buy Now flow
|
// Process Buy Now flow
|
||||||
@ -97,17 +100,39 @@ class CheckoutActivity : AppCompatActivity() {
|
|||||||
val cartItemIds = intent.getIntArrayExtra(EXTRA_CART_ITEM_IDS)?.toList() ?: emptyList()
|
val cartItemIds = intent.getIntArrayExtra(EXTRA_CART_ITEM_IDS)?.toList() ?: emptyList()
|
||||||
val isWholesaleArray = intent.getBooleanArrayExtra(EXTRA_CART_ITEM_WHOLESALE)
|
val isWholesaleArray = intent.getBooleanArrayExtra(EXTRA_CART_ITEM_WHOLESALE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cartItemIds.isNotEmpty()) {
|
if (cartItemIds.isNotEmpty()) {
|
||||||
// Create a map of cart item IDs to wholesale status if available
|
// Build map of cartItemId -> isWholesale
|
||||||
val wholesaleMap = if (isWholesaleArray != null && isWholesaleArray.size == cartItemIds.size) {
|
val isWholesaleMap = if (isWholesaleArray != null && isWholesaleArray.size == cartItemIds.size) {
|
||||||
cartItemIds.mapIndexed { index, id -> id to isWholesaleArray[index] }.toMap()
|
cartItemIds.mapIndexed { index, id ->
|
||||||
|
id to isWholesaleArray[index]
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
emptyMap()
|
emptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.initializeFromCart(cartItemIds, wholesaleMap)
|
|
||||||
|
// Build wholesalePriceMap
|
||||||
|
val wholesalePriceMap = cartItemIds.mapIndexed { index, id ->
|
||||||
|
id to (wholesalePricesArray?.get(index) ?: 0)
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
viewModel.initializeFromCart(
|
||||||
|
cartItemIds,
|
||||||
|
isWholesaleMap,
|
||||||
|
wholesalePriceMap
|
||||||
|
)
|
||||||
|
|
||||||
|
Log.d("CheckoutActivity", "Cart IDs: $cartItemIds")
|
||||||
|
Log.d("CheckoutActivity", "IsWholesaleArray: ${isWholesaleArray?.joinToString()}")
|
||||||
|
Log.d("CheckoutActivity", "WholesalePricesArray: ${wholesalePricesArray?.joinToString()}")
|
||||||
|
Log.d("CheckoutActivity", "IsWholesaleMap: $isWholesaleMap")
|
||||||
|
Log.d("CheckoutActivity", "WholesalePriceMap: $wholesalePriceMap")
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "Error: No cart items specified", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Tidak ada item keranjang", Toast.LENGTH_SHORT).show()
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,6 +441,7 @@ class CheckoutActivity : AppCompatActivity() {
|
|||||||
const val EXTRA_PRICE = "PRICE"
|
const val EXTRA_PRICE = "PRICE"
|
||||||
const val EXTRA_ISWHOLESALE = "ISWHOLESALE"
|
const val EXTRA_ISWHOLESALE = "ISWHOLESALE"
|
||||||
const val EXTRA_CART_ITEM_WHOLESALE = "EXTRA_CART_ITEM_WHOLESALE"
|
const val EXTRA_CART_ITEM_WHOLESALE = "EXTRA_CART_ITEM_WHOLESALE"
|
||||||
|
const val EXTRA_CART_ITEM_WHOLESALE_PRICES = "EXTRA_CART_ITEM_WHOLESALE_PRICES"
|
||||||
|
|
||||||
// Helper methods for starting activity
|
// Helper methods for starting activity
|
||||||
|
|
||||||
@ -449,13 +475,17 @@ class CheckoutActivity : AppCompatActivity() {
|
|||||||
fun startForCart(
|
fun startForCart(
|
||||||
context: Context,
|
context: Context,
|
||||||
cartItemIds: List<Int>,
|
cartItemIds: List<Int>,
|
||||||
isWholesaleArray: BooleanArray? = null
|
isWholesaleArray: BooleanArray? = null,
|
||||||
|
wholesalePrices: IntArray? = null
|
||||||
) {
|
) {
|
||||||
val intent = Intent(context, CheckoutActivity::class.java).apply {
|
val intent = Intent(context, CheckoutActivity::class.java).apply {
|
||||||
putExtra(EXTRA_CART_ITEM_IDS, cartItemIds.toIntArray())
|
putExtra(EXTRA_CART_ITEM_IDS, cartItemIds.toIntArray())
|
||||||
if (isWholesaleArray != null) {
|
if (isWholesaleArray != null) {
|
||||||
putExtra(EXTRA_CART_ITEM_WHOLESALE, isWholesaleArray)
|
putExtra(EXTRA_CART_ITEM_WHOLESALE, isWholesaleArray)
|
||||||
}
|
}
|
||||||
|
if (wholesalePrices != null) {
|
||||||
|
putExtra(EXTRA_CART_ITEM_WHOLESALE_PRICES, wholesalePrices)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
@ -93,30 +93,38 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize checkout from cart
|
// Initialize checkout from cart
|
||||||
fun initializeFromCart(cartItemIds: List<Int>, isWholesaleMap: Map<Int, Boolean> = emptyMap()) {
|
fun initializeFromCart(
|
||||||
|
cartItemIds: List<Int>,
|
||||||
|
isWholesaleMap: Map<Int, Boolean> = emptyMap(),
|
||||||
|
wholesalePriceMap: Map<Int, Int> = emptyMap() // new
|
||||||
|
) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_isLoading.value = true
|
_isLoading.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get cart data
|
|
||||||
val cartResult = repository.getCart()
|
val cartResult = repository.getCart()
|
||||||
|
|
||||||
if (cartResult is Result.Success) {
|
if (cartResult is Result.Success) {
|
||||||
// Find matching cart items
|
|
||||||
val matchingItems = mutableListOf<CartItemsItem>()
|
val matchingItems = mutableListOf<CartItemsItem>()
|
||||||
var storeData: DataItemCart? = null
|
var storeData: DataItemCart? = null
|
||||||
|
|
||||||
for (store in cartResult.data) {
|
for (store in cartResult.data) {
|
||||||
val storeItems = store.cartItems.filter { it.cartItemId in cartItemIds }
|
val storeItems = store.cartItems.filter { it.cartItemId in cartItemIds }
|
||||||
if (storeItems.isNotEmpty()) {
|
if (storeItems.isNotEmpty()) {
|
||||||
matchingItems.addAll(storeItems)
|
// ✅ Override price with wholesale price if exists
|
||||||
|
val updatedItems = storeItems.map { item ->
|
||||||
|
val wholesalePrice = wholesalePriceMap[item.cartItemId]
|
||||||
|
if (wholesalePrice != null) {
|
||||||
|
item.copy(price = wholesalePrice.toInt())
|
||||||
|
} else item
|
||||||
|
}
|
||||||
|
matchingItems.addAll(updatedItems)
|
||||||
storeData = store
|
storeData = store
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchingItems.isNotEmpty() && storeData != null) {
|
if (matchingItems.isNotEmpty() && storeData != null) {
|
||||||
// Create initial OrderRequest object
|
|
||||||
val orderRequest = OrderRequest(
|
val orderRequest = OrderRequest(
|
||||||
addressId = 0,
|
addressId = 0,
|
||||||
paymentMethodId = 0,
|
paymentMethodId = 0,
|
||||||
@ -126,11 +134,9 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
|||||||
isNego = false,
|
isNego = false,
|
||||||
cartItemId = cartItemIds,
|
cartItemId = cartItemIds,
|
||||||
shipEtd = "",
|
shipEtd = "",
|
||||||
// Add a list tracking which items are wholesale
|
isReseller = isWholesaleMap.any { it.value }
|
||||||
isReseller = isWholesaleMap.any { it.value } // Set true if any item is wholesale
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create checkout data
|
|
||||||
_checkoutData.value = CheckoutData(
|
_checkoutData.value = CheckoutData(
|
||||||
orderRequest = orderRequest,
|
orderRequest = orderRequest,
|
||||||
productName = matchingItems.first().productName,
|
productName = matchingItems.first().productName,
|
||||||
@ -138,8 +144,14 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
|||||||
sellerId = storeData.storeId,
|
sellerId = storeData.storeId,
|
||||||
isBuyNow = false,
|
isBuyNow = false,
|
||||||
cartItems = matchingItems,
|
cartItems = matchingItems,
|
||||||
cartItemWholesaleMap = isWholesaleMap // Store the wholesale map
|
cartItemWholesaleMap = isWholesaleMap
|
||||||
)
|
)
|
||||||
|
Log.d(TAG, "CheckoutData initialized: ${_checkoutData.value}")
|
||||||
|
|
||||||
|
Log.d(TAG, "Matching cart items: ${matchingItems.size}")
|
||||||
|
Log.d(TAG, "Cart items: ${matchingItems.map { it.productName to it.price }}")
|
||||||
|
Log.d(TAG, "IsWholesaleMap passed: $isWholesaleMap")
|
||||||
|
Log.d(TAG, "WholesalePriceMap passed: $wholesalePriceMap")
|
||||||
|
|
||||||
calculateSubtotal()
|
calculateSubtotal()
|
||||||
calculateTotal()
|
calculateTotal()
|
||||||
@ -155,6 +167,7 @@ class CheckoutViewModel(private val repository: OrderRepository) : ViewModel() {
|
|||||||
_isLoading.value = false
|
_isLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPaymentMethods() {
|
fun getPaymentMethods() {
|
||||||
|
@ -333,18 +333,19 @@ class AddAddressActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// Create request with all fields
|
// Create request with all fields
|
||||||
val request = CreateAddressRequest(
|
val request = CreateAddressRequest(
|
||||||
|
userId = userId,
|
||||||
lat = latitude!!, // Safe to use !! as we've checked above
|
lat = latitude!!, // Safe to use !! as we've checked above
|
||||||
long = longitude!!,
|
long = longitude!!,
|
||||||
street = street,
|
street = street,
|
||||||
subDistrict = subDistrict,
|
subDistrict = subDistrict,
|
||||||
cityId = cityId,
|
cityId = cityId, // ⚠️ Make sure this is Int
|
||||||
provId = provinceId,
|
provId = provinceId,
|
||||||
postCode = postalCode,
|
postCode = postalCode,
|
||||||
|
idVillage = "", // Or provide a real ID if needed
|
||||||
detailAddress = street,
|
detailAddress = street,
|
||||||
userId = userId,
|
isStoreLocation = false,
|
||||||
recipient = recipient,
|
recipient = recipient,
|
||||||
phone = phone,
|
phone = phone
|
||||||
isStoreLocation = isStoreLocation
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Log.d(TAG, "Form validation successful, submitting address: $request")
|
Log.d(TAG, "Form validation successful, submitting address: $request")
|
||||||
|
@ -10,6 +10,9 @@ import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest
|
|||||||
import com.alya.ecommerce_serang.data.api.dto.UserProfile
|
import com.alya.ecommerce_serang.data.api.dto.UserProfile
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.VillagesItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressDetail
|
||||||
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 com.alya.ecommerce_serang.data.repository.UserRepository
|
import com.alya.ecommerce_serang.data.repository.UserRepository
|
||||||
@ -31,6 +34,18 @@ class AddAddressViewModel(private val repository: OrderRepository, private val u
|
|||||||
private val _citiesState = MutableLiveData<ViewState<List<CitiesItem>>>()
|
private val _citiesState = MutableLiveData<ViewState<List<CitiesItem>>>()
|
||||||
val citiesState: LiveData<ViewState<List<CitiesItem>>> = _citiesState
|
val citiesState: LiveData<ViewState<List<CitiesItem>>> = _citiesState
|
||||||
|
|
||||||
|
private val _subdistrictState = MutableLiveData<Result<List<SubdistrictsItem>>>()
|
||||||
|
val subdistrictState: LiveData<Result<List<SubdistrictsItem>>> = _subdistrictState
|
||||||
|
|
||||||
|
private val _villagesState = MutableLiveData<Result<List<VillagesItem>>>()
|
||||||
|
val villagesState: LiveData<Result<List<VillagesItem>>> = _villagesState
|
||||||
|
|
||||||
|
private val _userAddress = MutableLiveData<AddressDetail>()
|
||||||
|
val userAddress: LiveData<AddressDetail> = _userAddress
|
||||||
|
|
||||||
|
private val _editAddress = MutableLiveData<Boolean>()
|
||||||
|
val editAddress: LiveData<Boolean> get() = _editAddress
|
||||||
|
|
||||||
// Stored in SavedStateHandle for configuration changes
|
// Stored in SavedStateHandle for configuration changes
|
||||||
var selectedProvinceId: Int?
|
var selectedProvinceId: Int?
|
||||||
get() = savedStateHandle.get<Int>("selectedProvinceId")
|
get() = savedStateHandle.get<Int>("selectedProvinceId")
|
||||||
@ -40,6 +55,9 @@ class AddAddressViewModel(private val repository: OrderRepository, private val u
|
|||||||
get() = savedStateHandle.get<String>("selectedCityId")
|
get() = savedStateHandle.get<String>("selectedCityId")
|
||||||
set(value) { savedStateHandle["selectedCityId"] = value }
|
set(value) { savedStateHandle["selectedCityId"] = value }
|
||||||
|
|
||||||
|
var selectedSubdistrict: String? = null
|
||||||
|
var selectedVillages: String? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// Load provinces on initialization
|
// Load provinces on initialization
|
||||||
getProvinces()
|
getProvinces()
|
||||||
@ -86,6 +104,8 @@ class AddAddressViewModel(private val repository: OrderRepository, private val u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun getProvinces() {
|
fun getProvinces() {
|
||||||
_provincesState.value = ViewState.Loading
|
_provincesState.value = ViewState.Loading
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@ -125,24 +145,113 @@ class AddAddressViewModel(private val repository: OrderRepository, private val u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSubdistrict(cityId: String) {
|
||||||
|
_subdistrictState.value = Result.Loading
|
||||||
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
|
||||||
|
selectedSubdistrict = cityId
|
||||||
|
val result = repository.getListSubdistrict(cityId)
|
||||||
|
result?.let {
|
||||||
|
_subdistrictState.postValue(Result.Success(it.subdistricts))
|
||||||
|
Log.d(TAG, "Cities loaded for province $cityId: ${it.subdistricts.size}")
|
||||||
|
} ?: run {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception("Failed to load cities")))
|
||||||
|
Log.e(TAG, "City result was null for province $cityId")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception(e.message ?: "Error loading cities")))
|
||||||
|
Log.e(TAG, "Error fetching cities for province $cityId", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getVillages(subdistrictId: String) {
|
||||||
|
_villagesState.value = Result.Loading
|
||||||
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
|
||||||
|
selectedVillages = subdistrictId
|
||||||
|
val result = repository.getListVillages(subdistrictId)
|
||||||
|
result?.let {
|
||||||
|
_villagesState.postValue(Result.Success(it.villages))
|
||||||
|
Log.d(TAG, "Cities loaded for province $subdistrictId: ${it.villages.size}")
|
||||||
|
} ?: run {
|
||||||
|
_villagesState.postValue(Result.Error(Exception("Failed to load cities")))
|
||||||
|
Log.e(TAG, "City result was null for province $subdistrictId")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_villagesState.postValue(Result.Error(Exception(e.message ?: "Error loading cities")))
|
||||||
|
Log.e(TAG, "Error fetching cities for province $subdistrictId", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setSelectedProvinceId(id: Int) {
|
fun setSelectedProvinceId(id: Int) {
|
||||||
selectedProvinceId = id
|
selectedProvinceId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateSelectedCityId(id: String) {
|
fun detailAddress(addressId: Int){
|
||||||
selectedCityId = id
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
val response = repository.getAddressDetail(addressId)
|
||||||
|
if (response != null){
|
||||||
|
_userAddress.value = response.address
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Failed load address detail")
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e:Exception){
|
||||||
|
Log.e(TAG, "Error fetching address detail: $e", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateAddress(oldAddress: AddressDetail, newAddress: AddressDetail) {
|
||||||
|
val params = buildUpdateBody(oldAddress, newAddress)
|
||||||
|
if (params.isEmpty()) {
|
||||||
|
Log.d(TAG, "No changes detected")
|
||||||
|
_editAddress.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadUserProfile(){
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
when (val result = userRepo.fetchUserProfile()){
|
try {
|
||||||
is Result.Success -> _userProfile.postValue(result.data)
|
val response = repository.updateAddress(oldAddress.id, params)
|
||||||
is Result.Error -> _errorMessageUser.postValue(result.exception.message ?: "Unknown Error")
|
_editAddress.value = response.isSuccessful
|
||||||
is Result.Loading -> null
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error: ${e.message}")
|
||||||
|
_editAddress.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildUpdateBody(oldAddress: AddressDetail, newAddress: AddressDetail): Map<String, Any> {
|
||||||
|
|
||||||
|
val params = mutableMapOf<String, Any>()
|
||||||
|
|
||||||
|
fun addIfChanged(key: String, oldValue: Any?, newValue: Any?) {
|
||||||
|
if (newValue != null && newValue != oldValue) {
|
||||||
|
params[key] = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addIfChanged("street", oldAddress.street, newAddress.street)
|
||||||
|
addIfChanged("province_id", oldAddress.provinceId, newAddress.provinceId)
|
||||||
|
addIfChanged("detail", oldAddress.detail, newAddress.detail)
|
||||||
|
addIfChanged("subdistrict", oldAddress.subdistrict, newAddress.subdistrict)
|
||||||
|
addIfChanged("city_id", oldAddress.cityId, newAddress.cityId)
|
||||||
|
addIfChanged("village_id", oldAddress.villageId, newAddress.villageId)
|
||||||
|
addIfChanged("postal_code", oldAddress.postalCode, newAddress.postalCode)
|
||||||
|
addIfChanged("phone", oldAddress.phone, newAddress.phone)
|
||||||
|
addIfChanged("recipient", oldAddress.recipient, newAddress.recipient)
|
||||||
|
addIfChanged("latitude", oldAddress.latitude, newAddress.latitude)
|
||||||
|
addIfChanged("longitude", oldAddress.longitude, newAddress.longitude)
|
||||||
|
addIfChanged("is_store_location", oldAddress.isStoreLocation, newAddress.isStoreLocation)
|
||||||
|
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "AddAddressViewModel"
|
private const val TAG = "AddAddressViewModel"
|
||||||
}
|
}
|
||||||
|
@ -74,13 +74,17 @@ class AddressActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
adapter = AddressAdapter { address ->
|
adapter = AddressAdapter(
|
||||||
// Select the address in the ViewModel
|
onAddressClick = { address ->
|
||||||
viewModel.selectAddress(address.id)
|
viewModel.selectAddress(address.id)
|
||||||
|
|
||||||
// Return immediately with the selected address
|
|
||||||
returnResultAndFinish(address.id)
|
returnResultAndFinish(address.id)
|
||||||
|
},
|
||||||
|
onEditClick = { address ->
|
||||||
|
val intent = Intent(this, EditAddressActivity::class.java)
|
||||||
|
intent.putExtra(EditAddressActivity.EXTRA_ADDRESS_ID, address.id)
|
||||||
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
binding.rvSellerOrder.apply {
|
binding.rvSellerOrder.apply {
|
||||||
layoutManager = LinearLayoutManager(this@AddressActivity)
|
layoutManager = LinearLayoutManager(this@AddressActivity)
|
||||||
@ -119,6 +123,7 @@ class AddressActivity : AppCompatActivity() {
|
|||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
intent.putExtra(EXTRA_ADDRESS_ID, addressId)
|
intent.putExtra(EXTRA_ADDRESS_ID, addressId)
|
||||||
setResult(RESULT_OK, intent)
|
setResult(RESULT_OK, intent)
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -3,6 +3,7 @@ package com.alya.ecommerce_serang.ui.order.address
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
@ -13,7 +14,8 @@ import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesIte
|
|||||||
import com.google.android.material.card.MaterialCardView
|
import com.google.android.material.card.MaterialCardView
|
||||||
|
|
||||||
class AddressAdapter(
|
class AddressAdapter(
|
||||||
private val onAddressClick: (AddressesItem) -> Unit
|
private val onAddressClick: (AddressesItem) -> Unit,
|
||||||
|
private val onEditClick: (AddressesItem) -> Unit
|
||||||
) : ListAdapter<AddressesItem, AddressAdapter.AddressViewHolder>(DIFF_CALLBACK) {
|
) : ListAdapter<AddressesItem, AddressAdapter.AddressViewHolder>(DIFF_CALLBACK) {
|
||||||
|
|
||||||
private var selectedAddressId: Int? = null
|
private var selectedAddressId: Int? = null
|
||||||
@ -47,18 +49,21 @@ class AddressAdapter(
|
|||||||
// Pass the whole address object to provide more context
|
// Pass the whole address object to provide more context
|
||||||
onAddressClick(address)
|
onAddressClick(address)
|
||||||
}
|
}
|
||||||
|
holder.editButton.setOnClickListener {
|
||||||
|
onEditClick(address)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddressViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
class AddressViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
private val tvName: TextView = itemView.findViewById(R.id.tv_name_address)
|
private val tvName: TextView = itemView.findViewById(R.id.tv_name_address)
|
||||||
private val tvDetail: TextView = itemView.findViewById(R.id.tv_detail_address)
|
private val tvDetail: TextView = itemView.findViewById(R.id.tv_detail_address)
|
||||||
|
val editButton: ImageView = itemView.findViewById(R.id.iv_edit)
|
||||||
private val card: MaterialCardView = itemView as MaterialCardView
|
private val card: MaterialCardView = itemView as MaterialCardView
|
||||||
|
|
||||||
fun bind(address: AddressesItem, isSelected: Boolean) {
|
fun bind(address: AddressesItem, isSelected: Boolean) {
|
||||||
tvName.text = address.recipient
|
tvName.text = address.recipient
|
||||||
tvDetail.text = "${address.street}, ${address.subdistrict}, ${address.phone}"
|
tvDetail.text = "${address.street}, ${address.subdistrict}, ${address.phone}"
|
||||||
|
|
||||||
// Make selection more visible
|
|
||||||
card.strokeWidth = if (isSelected) 3 else 0
|
card.strokeWidth = if (isSelected) 3 else 0
|
||||||
card.strokeColor = if (isSelected)
|
card.strokeColor = if (isSelected)
|
||||||
ContextCompat.getColor(itemView.context, R.color.blue_400)
|
ContextCompat.getColor(itemView.context, R.color.blue_400)
|
||||||
|
@ -21,6 +21,8 @@ class AddressViewModel(private val repository: OrderRepository): ViewModel() {
|
|||||||
val response = repository.getAddress()
|
val response = repository.getAddress()
|
||||||
response?.let {
|
response?.let {
|
||||||
_addresses.value = it.addresses
|
_addresses.value = it.addresses
|
||||||
|
?.filter { address -> address.isStoreLocation == false }
|
||||||
|
?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,418 @@
|
|||||||
package com.alya.ecommerce_serang.ui.order.address
|
package com.alya.ecommerce_serang.ui.order.address
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import com.alya.ecommerce_serang.R
|
import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.VillagesItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressDetail
|
||||||
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||||
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
||||||
|
import com.alya.ecommerce_serang.data.repository.OrderRepository
|
||||||
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
|
import com.alya.ecommerce_serang.data.repository.UserRepository
|
||||||
|
import com.alya.ecommerce_serang.databinding.ActivityEditAddressBinding
|
||||||
|
import com.alya.ecommerce_serang.utils.SavedStateViewModelFactory
|
||||||
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
|
|
||||||
class EditAddressActivity : AppCompatActivity() {
|
class EditAddressActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityEditAddressBinding
|
||||||
|
private lateinit var apiService: ApiService
|
||||||
|
private lateinit var sessionManager: SessionManager
|
||||||
|
|
||||||
|
private var latitude: Double? = null
|
||||||
|
private var longitude: Double? = null
|
||||||
|
private var addressId: Int = -1
|
||||||
|
private var currentAddress: AddressDetail? = null
|
||||||
|
private val provinceAdapter by lazy { ProvinceAdapter(this) }
|
||||||
|
private val cityAdapter by lazy { CityAdapter(this) }
|
||||||
|
private val subdistrictAdapter by lazy { SubdsitrictAdapter(this)}
|
||||||
|
private val villageAdapter by lazy { VillagesAdapter(this)}
|
||||||
|
|
||||||
|
private var provincesList = mutableListOf<ProvincesItem>()
|
||||||
|
private var citiesList = mutableListOf<CitiesItem>()
|
||||||
|
private var subdistrictsList = mutableListOf<SubdistrictsItem>()
|
||||||
|
private var villagesList = mutableListOf<VillagesItem>()
|
||||||
|
|
||||||
|
private val viewModel: AddAddressViewModel by viewModels {
|
||||||
|
SavedStateViewModelFactory(this) { savedStateHandle ->
|
||||||
|
val apiService = ApiConfig.getApiService(sessionManager)
|
||||||
|
val orderRepository = OrderRepository(apiService)
|
||||||
|
val userRepository = UserRepository(apiService)
|
||||||
|
AddAddressViewModel(orderRepository, userRepository, savedStateHandle)
|
||||||
|
}
|
||||||
|
}
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = ActivityEditAddressBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
sessionManager = SessionManager(this)
|
||||||
|
apiService = ApiConfig.getApiService(sessionManager)
|
||||||
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContentView(R.layout.activity_edit_address)
|
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
// Apply insets to your root layout
|
||||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets ->
|
||||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
val systemBars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
insets
|
view.setPadding(
|
||||||
|
systemBars.left,
|
||||||
|
systemBars.top,
|
||||||
|
systemBars.right,
|
||||||
|
systemBars.bottom
|
||||||
|
)
|
||||||
|
windowInsets
|
||||||
|
}
|
||||||
|
|
||||||
|
addressId = intent.getIntExtra(EXTRA_ADDRESS_ID, -1)
|
||||||
|
if (addressId == -1) {
|
||||||
|
Toast.makeText(this, "Gagal mendapatkan alamat pengguna", Toast.LENGTH_SHORT).show()
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setupToolbar()
|
||||||
|
setupAdapters()
|
||||||
|
setupObservers()
|
||||||
|
setupListeners()
|
||||||
|
|
||||||
|
// Load address detail first
|
||||||
|
Log.d(TAG, "Loading address with ID: $addressId")
|
||||||
|
viewModel.detailAddress(addressId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupToolbar() {
|
||||||
|
binding.toolbar.setNavigationOnClickListener {
|
||||||
|
onBackPressedDispatcher.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupAdapters() {
|
||||||
|
// Set custom adapters to AutoCompleteTextViews
|
||||||
|
binding.autoCompleteProvinsi.setAdapter(provinceAdapter)
|
||||||
|
binding.autoCompleteKabupaten.setAdapter(cityAdapter)
|
||||||
|
binding.autoCompleteKecamatan.setAdapter(subdistrictAdapter)
|
||||||
|
binding.autoCompleteDesa.setAdapter(villageAdapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupObservers() {
|
||||||
|
// Observe address detail
|
||||||
|
viewModel.userAddress.observe(this) { address ->
|
||||||
|
currentAddress = address
|
||||||
|
Log.d(TAG, "Address loaded: $address")
|
||||||
|
populateAddressData(address)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Observe provinces
|
||||||
|
viewModel.provincesState.observe(this) { viewState ->
|
||||||
|
when (viewState) {
|
||||||
|
is ViewState.Loading -> {
|
||||||
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
is ViewState.Success -> {
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
provincesList.clear()
|
||||||
|
provincesList.addAll(viewState.data)
|
||||||
|
provinceAdapter.updateData(viewState.data)
|
||||||
|
|
||||||
|
// Set selected province if address is loaded
|
||||||
|
currentAddress?.let { address ->
|
||||||
|
setSelectedProvince(address.provinceId.toInt())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is ViewState.Error -> {
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
Log.e(TAG, "Failed to load province ${viewState.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Observe cities
|
||||||
|
viewModel.citiesState.observe(this) { viewState ->
|
||||||
|
when (viewState) {
|
||||||
|
is ViewState.Loading -> {
|
||||||
|
binding.cityProgressBar.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
is ViewState.Success -> {
|
||||||
|
binding.cityProgressBar.visibility = View.GONE
|
||||||
|
citiesList.clear()
|
||||||
|
citiesList.addAll(viewState.data)
|
||||||
|
cityAdapter.updateData(viewState.data)
|
||||||
|
|
||||||
|
// Set selected city if address is loaded
|
||||||
|
currentAddress?.let { address ->
|
||||||
|
setSelectedCity(address.cityId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is ViewState.Error -> {
|
||||||
|
binding.cityProgressBar.visibility = View.GONE
|
||||||
|
Log.e(TAG, "Failed to load cities ${viewState.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Observe subdistricts
|
||||||
|
viewModel.subdistrictState.observe(this) { result ->
|
||||||
|
when (result) {
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Loading -> {
|
||||||
|
// You can add loading indicator for subdistrict if needed
|
||||||
|
}
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Success -> {
|
||||||
|
subdistrictsList.clear()
|
||||||
|
subdistrictsList.addAll(result.data)
|
||||||
|
subdistrictAdapter.updateData(result.data)
|
||||||
|
|
||||||
|
// Set selected subdistrict if address is loaded
|
||||||
|
currentAddress?.let { address ->
|
||||||
|
setSelectedSubdistrict(address.subdistrict)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Error -> {
|
||||||
|
Log.e(TAG, "Failed to load subdistricy")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Observe villages
|
||||||
|
viewModel.villagesState.observe(this) { result ->
|
||||||
|
when (result) {
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Loading -> {
|
||||||
|
// You can add loading indicator for village if needed
|
||||||
|
}
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Success -> {
|
||||||
|
villagesList.clear()
|
||||||
|
villagesList.addAll(result.data)
|
||||||
|
villageAdapter.updateData(result.data)
|
||||||
|
|
||||||
|
// Set selected village if address is loaded
|
||||||
|
currentAddress?.let { address ->
|
||||||
|
setSelectedVillage(address.villageId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is Result.Error -> {
|
||||||
|
Log.e(TAG, "Failed to load villages")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Observe update result
|
||||||
|
viewModel.editAddress.observe(this) { isSuccess ->
|
||||||
|
binding.submitProgressBar.visibility = View.GONE
|
||||||
|
binding.buttonSimpan.isEnabled = true
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
Log.d(TAG, "Address updated successfully")
|
||||||
|
finish()
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Failed to update address")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupListeners() {
|
||||||
|
// Province selection
|
||||||
|
binding.autoCompleteProvinsi.setOnItemClickListener { _, _, position, _ ->
|
||||||
|
val provinceId = provinceAdapter.getProvinceId(position)
|
||||||
|
provinceId?.let { id ->
|
||||||
|
viewModel.getCities(id)
|
||||||
|
|
||||||
|
// Clear dependent dropdowns
|
||||||
|
clearCitySelection()
|
||||||
|
clearSubdistrictSelection()
|
||||||
|
clearVillageSelection()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// City selection
|
||||||
|
binding.autoCompleteKabupaten.setOnItemClickListener { _, _, position, _ ->
|
||||||
|
val cityId = cityAdapter.getCityId(position)
|
||||||
|
cityId?.let { id ->
|
||||||
|
viewModel.getSubdistrict(id)
|
||||||
|
|
||||||
|
// Clear dependent dropdowns
|
||||||
|
clearSubdistrictSelection()
|
||||||
|
clearVillageSelection()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subdistrict selection
|
||||||
|
binding.autoCompleteKecamatan.setOnItemClickListener { _, _, position, _ ->
|
||||||
|
val subdistrictId = subdistrictAdapter.getSubdistrictId(position)
|
||||||
|
subdistrictId?.let { id ->
|
||||||
|
viewModel.getVillages(id)
|
||||||
|
|
||||||
|
// Clear dependent dropdowns
|
||||||
|
clearVillageSelection()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Village selection - auto-populate postal code
|
||||||
|
binding.autoCompleteDesa.setOnItemClickListener { _, _, position, _ ->
|
||||||
|
// val postalCode = villageAdapter.getPostalCode(position)
|
||||||
|
// postalCode?.let {
|
||||||
|
// binding.etKodePos.setText(it)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save button
|
||||||
|
binding.buttonSimpan.setOnClickListener {
|
||||||
|
saveAddress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun populateAddressData(address: AddressDetail) {
|
||||||
|
binding.etNamaPenerima.setText(address.recipient ?: "")
|
||||||
|
binding.etNomorHp.setText(address.phone ?: "")
|
||||||
|
binding.etDetailAlamat.setText(address.detail ?: "")
|
||||||
|
binding.etKodePos.setText(address.postalCode ?: "")
|
||||||
|
|
||||||
|
// Province will be set when provinces are loaded
|
||||||
|
// City, subdistrict, village will be set in their respective observers
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setSelectedProvince(provinceId: Int?) {
|
||||||
|
provinceId?.let { id ->
|
||||||
|
val position = provincesList.indexOfFirst { it.provinceId?.toIntOrNull() == id }
|
||||||
|
if (position >= 0) {
|
||||||
|
val provinceName = provincesList[position].province
|
||||||
|
binding.autoCompleteProvinsi.setText(provinceName, false)
|
||||||
|
viewModel.getCities(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setSelectedCity(cityId: String?) {
|
||||||
|
cityId?.let { id ->
|
||||||
|
val position = citiesList.indexOfFirst { it.cityId?.toString() == id }
|
||||||
|
if (position >= 0) {
|
||||||
|
val cityName = citiesList[position].cityName
|
||||||
|
binding.autoCompleteKabupaten.setText(cityName, false)
|
||||||
|
viewModel.getSubdistrict(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setSelectedSubdistrict(subdistrictId: String?) {
|
||||||
|
subdistrictId?.let { id ->
|
||||||
|
val position = subdistrictsList.indexOfFirst { it.subdistrictId?.toString() == id }
|
||||||
|
if (position >= 0) {
|
||||||
|
val subdistrictName = subdistrictsList[position].subdistrictName
|
||||||
|
binding.autoCompleteKecamatan.setText(subdistrictName, false)
|
||||||
|
viewModel.getVillages(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setSelectedVillage(villageId: String?) {
|
||||||
|
villageId?.let { id ->
|
||||||
|
val position = villagesList.indexOfFirst { it.villageId?.toString() == id }
|
||||||
|
if (position >= 0) {
|
||||||
|
val villageName = villagesList[position].villageName
|
||||||
|
binding.autoCompleteDesa.setText(villageName, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// private fun populatePostalCodeFromVillage(villageId: String?) {
|
||||||
|
// villageId?.let { id ->
|
||||||
|
// val village = villagesList.find { it.villageId?.toString() == id }
|
||||||
|
// village?.postalCode?.let { postalCode ->
|
||||||
|
// if (binding.etKodePos.text.isNullOrEmpty()) {
|
||||||
|
// binding.etKodePos.setText(postalCode)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
private fun clearCitySelection() {
|
||||||
|
binding.autoCompleteKabupaten.setText("", false)
|
||||||
|
citiesList.clear()
|
||||||
|
cityAdapter.updateData(emptyList())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun clearSubdistrictSelection() {
|
||||||
|
binding.autoCompleteKecamatan.setText("", false)
|
||||||
|
subdistrictsList.clear()
|
||||||
|
subdistrictAdapter.updateData(emptyList())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun clearVillageSelection() {
|
||||||
|
binding.autoCompleteDesa.setText("", false)
|
||||||
|
binding.etKodePos.setText("") // Clear postal code when village is cleared
|
||||||
|
villagesList.clear()
|
||||||
|
villageAdapter.updateData(emptyList())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveAddress() {
|
||||||
|
currentAddress?.let { oldAddress ->
|
||||||
|
val newAddress = createNewAddressFromInputs(oldAddress)
|
||||||
|
|
||||||
|
binding.submitProgressBar.visibility = View.VISIBLE
|
||||||
|
binding.buttonSimpan.isEnabled = false
|
||||||
|
|
||||||
|
viewModel.updateAddress(oldAddress, newAddress)
|
||||||
|
} ?: run {
|
||||||
|
Log.d(TAG, "Address not loaded")
|
||||||
|
Toast.makeText(this, "Gagal mendapatkan alamat", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createNewAddressFromInputs(oldAddress: AddressDetail): AddressDetail {
|
||||||
|
val selectedProvinceId = getSelectedProvinceId()
|
||||||
|
val selectedCityId = getSelectedCityId()
|
||||||
|
val selectedSubdistrictId = getSelectedSubdistrictId()
|
||||||
|
val selectedVillageId = getSelectedVillageId()
|
||||||
|
|
||||||
|
return oldAddress.copy(
|
||||||
|
recipient = binding.etNamaPenerima.text.toString().trim(),
|
||||||
|
phone = binding.etNomorHp.text.toString().trim(),
|
||||||
|
detail = binding.etDetailAlamat.text.toString().trim(),
|
||||||
|
postalCode = binding.etKodePos.text.toString().trim(),
|
||||||
|
provinceId = selectedProvinceId.toString(),
|
||||||
|
cityId = selectedCityId.toString(),
|
||||||
|
subdistrict = selectedSubdistrictId.toString(),
|
||||||
|
villageId = selectedVillageId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSelectedProvinceId(): Int? {
|
||||||
|
val selectedText = binding.autoCompleteProvinsi.text.toString()
|
||||||
|
val position = provincesList.indexOfFirst { it.province == selectedText }
|
||||||
|
return if (position >= 0) provinceAdapter.getProvinceId(position) else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSelectedCityId(): String? {
|
||||||
|
val selectedText = binding.autoCompleteKabupaten.text.toString()
|
||||||
|
val position = citiesList.indexOfFirst { it.cityName == selectedText }
|
||||||
|
return if (position >= 0) cityAdapter.getCityId(position) else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSelectedSubdistrictId(): String? {
|
||||||
|
val selectedText = binding.autoCompleteKecamatan.text.toString()
|
||||||
|
val position = subdistrictsList.indexOfFirst { it.subdistrictName == selectedText }
|
||||||
|
return if (position >= 0) subdistrictAdapter.getSubdistrictId(position) else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSelectedVillageId(): String? {
|
||||||
|
val selectedText = binding.autoCompleteDesa.text.toString()
|
||||||
|
val position = villagesList.indexOfFirst { it.villageName == selectedText }
|
||||||
|
return if (position >= 0) villageAdapter.getVillageId(position) else null
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val EXTRA_ADDRESS_ID = "extra_address_id"
|
||||||
|
private const val TAG = "EditAddressActivity"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ package com.alya.ecommerce_serang.ui.order.address
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.Spinner
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
||||||
@ -14,85 +15,6 @@ class ProvinceAdapter(
|
|||||||
resource: Int = android.R.layout.simple_dropdown_item_1line
|
resource: Int = android.R.layout.simple_dropdown_item_1line
|
||||||
) : ArrayAdapter<String>(context, resource, ArrayList()) {
|
) : ArrayAdapter<String>(context, resource, ArrayList()) {
|
||||||
|
|
||||||
// companion object {
|
|
||||||
// private const val TAG = "ProvinceAdapter"
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // --- Static list of provinces ---------------------------------------------------------------
|
|
||||||
// private val provinces = listOf(
|
|
||||||
// ProvincesItem(1, "Aceh"),
|
|
||||||
// ProvincesItem(2, "Sumatera Utara"),
|
|
||||||
// ProvincesItem(3, "Sumatera Barat"),
|
|
||||||
// ProvincesItem(4, "Riau"),
|
|
||||||
// ProvincesItem(5, "Kepulauan Riau"),
|
|
||||||
// ProvincesItem(6, "Jambi"),
|
|
||||||
// ProvincesItem(7, "Sumatera Selatan"),
|
|
||||||
// ProvincesItem(8, "Kepulauan Bangka Belitung"),
|
|
||||||
// ProvincesItem(9, "Bengkulu"),
|
|
||||||
// ProvincesItem(10, "Lampung"),
|
|
||||||
// ProvincesItem(11, "DKI Jakarta"),
|
|
||||||
// ProvincesItem(12, "Jawa Barat"),
|
|
||||||
// ProvincesItem(13, "Banten"),
|
|
||||||
// ProvincesItem(14, "Jawa Tengah"),
|
|
||||||
// ProvincesItem(15, "Daerah Istimewa Yogyakarta"),
|
|
||||||
// ProvincesItem(16, "Jawa Timur"),
|
|
||||||
// ProvincesItem(17, "Bali"),
|
|
||||||
// ProvincesItem(18, "Nusa Tenggara Barat"),
|
|
||||||
// ProvincesItem(19, "Nusa Tenggara Timur"),
|
|
||||||
// ProvincesItem(20, "Kalimantan Barat"),
|
|
||||||
// ProvincesItem(21, "Kalimantan Tengah"),
|
|
||||||
// ProvincesItem(22, "Kalimantan Selatan"),
|
|
||||||
// ProvincesItem(23, "Kalimantan Timur"),
|
|
||||||
// ProvincesItem(24, "Kalimantan Utara"),
|
|
||||||
// ProvincesItem(25, "Sulawesi Utara"),
|
|
||||||
// ProvincesItem(26, "Gorontalo"),
|
|
||||||
// ProvincesItem(27, "Sulawesi Tengah"),
|
|
||||||
// ProvincesItem(28, "Sulawesi Barat"),
|
|
||||||
// ProvincesItem(29, "Sulawesi Selatan"),
|
|
||||||
// ProvincesItem(30, "Sulawesi Tenggara"),
|
|
||||||
// ProvincesItem(31, "Maluku"),
|
|
||||||
// ProvincesItem(32, "Maluku Utara"),
|
|
||||||
// ProvincesItem(33, "Papua Barat"),
|
|
||||||
// ProvincesItem(34, "Papua"),
|
|
||||||
// ProvincesItem(35, "Papua Tengah"),
|
|
||||||
// ProvincesItem(36, "Papua Pegunungan"),
|
|
||||||
// ProvincesItem(37, "Papua Selatan"),
|
|
||||||
// ProvincesItem(38, "Papua Barat Daya")
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// // --- Init block -----------------------------------------------------------------------------
|
|
||||||
// init {
|
|
||||||
// addAll(getProvinceNames()) // pre‑populate adapter
|
|
||||||
// Log.d(TAG, "Adapter created with ${count} provinces")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // --- Public helper functions ----------------------------------------------------------------
|
|
||||||
// fun updateData(newProvinces: List<ProvincesItem>) {
|
|
||||||
// // If you actually want to replace the list, comment this line
|
|
||||||
// // provinces = newProvinces // (make `provinces` var instead of val)
|
|
||||||
//
|
|
||||||
// clear()
|
|
||||||
// addAll(newProvinces.map { it.province })
|
|
||||||
// notifyDataSetChanged()
|
|
||||||
//
|
|
||||||
// Log.d(TAG, "updateData(): updated with ${newProvinces.size} provinces")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun getProvinceId(position: Int): Int? {
|
|
||||||
// val id = provinces.getOrNull(position)?.provinceId
|
|
||||||
// Log.d(TAG, "getProvinceId(): position=$position, id=$id")
|
|
||||||
// return id
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun getProvinceItem(position: Int): ProvincesItem? {
|
|
||||||
// val item = provinces.getOrNull(position)
|
|
||||||
// Log.d(TAG, "getProvinceItem(): position=$position, item=$item")
|
|
||||||
// return item
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // --- Private helpers ------------------------------------------------------------------------
|
|
||||||
// private fun getProvinceNames(): List<String> = provinces.map { it.province }
|
|
||||||
|
|
||||||
//call from endpoint
|
//call from endpoint
|
||||||
private val provinces = ArrayList<ProvincesItem>()
|
private val provinces = ArrayList<ProvincesItem>()
|
||||||
|
|
||||||
@ -152,6 +74,10 @@ class SubdsitrictAdapter(
|
|||||||
fun getSubdistrictId(position: Int): String? {
|
fun getSubdistrictId(position: Int): String? {
|
||||||
return cities.getOrNull(position)?.subdistrictId?.toString()
|
return cities.getOrNull(position)?.subdistrictId?.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSubdistrictName(position: Int): String? {
|
||||||
|
return cities.getOrNull(position)?.subdistrictName?.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VillagesAdapter(
|
class VillagesAdapter(
|
||||||
@ -177,3 +103,74 @@ class VillagesAdapter(
|
|||||||
return villages.getOrNull(position)?.postalCode
|
return villages.getOrNull(position)?.postalCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BankAdapter(
|
||||||
|
context: Context,
|
||||||
|
resource: Int = android.R.layout.simple_dropdown_item_1line
|
||||||
|
) : ArrayAdapter<String>(context, resource, ArrayList()) {
|
||||||
|
|
||||||
|
data class BankItem(
|
||||||
|
val bankName: String,
|
||||||
|
val bankCode: String? = null,
|
||||||
|
val description: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
private val banks = ArrayList<BankItem>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
loadHardcodedData()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadHardcodedData() {
|
||||||
|
val defaultBanks = listOf(
|
||||||
|
BankItem("Bank Mandiri", "008", "PT Bank Mandiri (Persero) Tbk"),
|
||||||
|
BankItem("Bank BRI", "002", "PT Bank Rakyat Indonesia (Persero) Tbk"),
|
||||||
|
BankItem("Bank BCA", "014", "PT Bank Central Asia Tbk"),
|
||||||
|
BankItem("Bank BNI", "009", "PT Bank Negara Indonesia (Persero) Tbk"),
|
||||||
|
BankItem("Bank BTN", "200", "PT Bank Tabungan Negara (Persero) Tbk"),
|
||||||
|
BankItem("Bank CIMB Niaga", "022", "PT Bank CIMB Niaga Tbk"),
|
||||||
|
BankItem("Bank Danamon", "011", "PT Bank Danamon Indonesia Tbk"),
|
||||||
|
BankItem("Bank Permata", "013", "PT Bank Permata Tbk"),
|
||||||
|
BankItem("Bank OCBC NISP", "028", "PT Bank OCBC NISP Tbk"),
|
||||||
|
BankItem("Bank Maybank", "016", "PT Bank Maybank Indonesia Tbk"),
|
||||||
|
BankItem("Bank Panin", "019", "PT Bank Panin Dubai Syariah Tbk"),
|
||||||
|
BankItem("Bank UOB", "023", "PT Bank UOB Indonesia"),
|
||||||
|
BankItem("Bank Mega", "426", "PT Bank Mega Tbk"),
|
||||||
|
BankItem("Bank Bukopin", "441", "PT Bank Bukopin Tbk"),
|
||||||
|
BankItem("Bank BJB", "110", "PT Bank Pembangunan Daerah Jawa Barat dan Banten Tbk")
|
||||||
|
)
|
||||||
|
updateData(defaultBanks)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateData(newBanks: List<BankItem>) {
|
||||||
|
banks.clear()
|
||||||
|
banks.addAll(newBanks)
|
||||||
|
|
||||||
|
clear()
|
||||||
|
addAll(banks.map { it.bankName })
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBankName(position: Int): String? {
|
||||||
|
return banks.getOrNull(position)?.bankName
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBankItem(position: Int): BankItem? {
|
||||||
|
return banks.getOrNull(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBankCode(position: Int): String? {
|
||||||
|
return banks.getOrNull(position)?.bankCode
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findPositionByName(bankName: String): Int {
|
||||||
|
return banks.indexOfFirst { it.bankName == bankName }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setDefaultSelection(spinner: Spinner, defaultBankName: String) {
|
||||||
|
val position = findPositionByName(defaultBankName)
|
||||||
|
if (position >= 0) {
|
||||||
|
spinner.setSelection(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ import com.google.android.material.button.MaterialButton
|
|||||||
import com.google.android.material.textfield.TextInputLayout
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.text.NumberFormat
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@ -88,7 +89,8 @@ class OrderHistoryAdapter(
|
|||||||
tvStoreName.text = storeName
|
tvStoreName.text = storeName
|
||||||
|
|
||||||
// Set total amount
|
// Set total amount
|
||||||
tvTotalAmount.text = order.totalAmount
|
tvTotalAmount.text = formatCurrency(order.totalAmount.toDouble())
|
||||||
|
|
||||||
|
|
||||||
// Set item count
|
// Set item count
|
||||||
val itemCount = order.orderItems.size
|
val itemCount = order.orderItems.size
|
||||||
@ -599,6 +601,11 @@ class OrderHistoryAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun formatCurrency(amount: Double): String {
|
||||||
|
val formatter = NumberFormat.getCurrencyInstance(Locale("in", "ID"))
|
||||||
|
return formatter.format(amount).replace(",00", "")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -10,6 +10,8 @@ import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
|||||||
import com.alya.ecommerce_serang.R
|
import com.alya.ecommerce_serang.R
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.OrderItemsItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.OrderItemsItem
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
|
import java.text.NumberFormat
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class OrderProductAdapter : RecyclerView.Adapter<OrderProductAdapter.ProductViewHolder>() {
|
class OrderProductAdapter : RecyclerView.Adapter<OrderProductAdapter.ProductViewHolder>() {
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ class OrderProductAdapter : RecyclerView.Adapter<OrderProductAdapter.ProductView
|
|||||||
tvQuantity.text = "${product.quantity} buah"
|
tvQuantity.text = "${product.quantity} buah"
|
||||||
|
|
||||||
// Set price with currency format
|
// Set price with currency format
|
||||||
tvProductPrice.text = formatCurrency(product.price)
|
tvProductPrice.text = formatCurrency(product.price.toDouble())
|
||||||
|
|
||||||
val fullImageUrl = when (val img = product.productImage) {
|
val fullImageUrl = when (val img = product.productImage) {
|
||||||
is String -> {
|
is String -> {
|
||||||
@ -65,10 +67,9 @@ class OrderProductAdapter : RecyclerView.Adapter<OrderProductAdapter.ProductView
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun formatCurrency(amount: Int): String {
|
private fun formatCurrency(amount: Double): String {
|
||||||
// In a real app, you would use NumberFormat for proper currency formatting
|
val formatter = NumberFormat.getCurrencyInstance(Locale("in", "ID"))
|
||||||
// For simplicity, just return a basic formatted string
|
return formatter.format(amount).replace(",00", "")
|
||||||
return "Rp${amount}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ import com.alya.ecommerce_serang.ui.order.address.AddressActivity
|
|||||||
import com.alya.ecommerce_serang.ui.order.history.HistoryActivity
|
import com.alya.ecommerce_serang.ui.order.history.HistoryActivity
|
||||||
import com.alya.ecommerce_serang.ui.profile.mystore.MyStoreActivity
|
import com.alya.ecommerce_serang.ui.profile.mystore.MyStoreActivity
|
||||||
import com.alya.ecommerce_serang.ui.profile.mystore.StoreOnReviewActivity
|
import com.alya.ecommerce_serang.ui.profile.mystore.StoreOnReviewActivity
|
||||||
|
import com.alya.ecommerce_serang.ui.profile.mystore.StoreSuspendedActivity
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
import com.alya.ecommerce_serang.utils.viewmodel.MyStoreViewModel
|
import com.alya.ecommerce_serang.utils.viewmodel.MyStoreViewModel
|
||||||
@ -73,13 +74,11 @@ class ProfileFragment : Fragment() {
|
|||||||
|
|
||||||
observeUserProfile()
|
observeUserProfile()
|
||||||
|
|
||||||
|
observeStoreStatus()
|
||||||
|
|
||||||
viewModel.loadUserProfile()
|
viewModel.loadUserProfile()
|
||||||
viewModel.checkStoreUser()
|
viewModel.checkStoreUser()
|
||||||
|
|
||||||
val hasStore = viewModel.checkStore.value
|
|
||||||
Log.d("Profile Fragment", "Check store $hasStore")
|
|
||||||
binding.tvBukaToko.text = if (hasStore == true) "Toko Saya" else "Buka Toko"
|
|
||||||
|
|
||||||
binding.cardBukaToko.setOnClickListener{
|
binding.cardBukaToko.setOnClickListener{
|
||||||
// if (hasStore == true) startActivity(Intent(requireContext(), MyStoreActivity::class.java))
|
// if (hasStore == true) startActivity(Intent(requireContext(), MyStoreActivity::class.java))
|
||||||
// else startActivity(Intent(requireContext(), RegisterStoreActivity::class.java))
|
// else startActivity(Intent(requireContext(), RegisterStoreActivity::class.java))
|
||||||
@ -88,8 +87,11 @@ class ProfileFragment : Fragment() {
|
|||||||
myStoreViewModel.myStoreProfile.observe(viewLifecycleOwner) { store ->
|
myStoreViewModel.myStoreProfile.observe(viewLifecycleOwner) { store ->
|
||||||
store?.let {
|
store?.let {
|
||||||
when (store.storeStatus) {
|
when (store.storeStatus) {
|
||||||
|
"process" -> startActivity(Intent(requireContext(), StoreOnReviewActivity::class.java))
|
||||||
"active" -> startActivity(Intent(requireContext(), MyStoreActivity::class.java))
|
"active" -> startActivity(Intent(requireContext(), MyStoreActivity::class.java))
|
||||||
else -> startActivity(Intent(requireContext(), StoreOnReviewActivity::class.java))
|
"inactive" -> startActivity(Intent(requireContext(), MyStoreActivity::class.java))
|
||||||
|
"suspended" -> startActivity(Intent(requireContext(), StoreSuspendedActivity::class.java))
|
||||||
|
else -> startActivity(Intent(requireContext(), RegisterStoreActivity::class.java))
|
||||||
}
|
}
|
||||||
} ?: run {
|
} ?: run {
|
||||||
Toast.makeText(requireContext(), "Gagal memuat data toko", Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), "Gagal memuat data toko", Toast.LENGTH_SHORT).show()
|
||||||
@ -132,6 +134,12 @@ class ProfileFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun observeStoreStatus() {
|
||||||
|
viewModel.checkStore.observe(viewLifecycleOwner) { hasStore ->
|
||||||
|
binding.tvBukaToko.text = if (hasStore) "Toko Saya" else "Buka Toko"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateUI(user: UserProfile) = with(binding){
|
private fun updateUI(user: UserProfile) = with(binding){
|
||||||
val fullImageUrl = when (val img = user.image) {
|
val fullImageUrl = when (val img = user.image) {
|
||||||
is String -> {
|
is String -> {
|
||||||
|
@ -21,7 +21,6 @@ import com.alya.ecommerce_serang.ui.profile.mystore.chat.ChatListStoreActivity
|
|||||||
import com.alya.ecommerce_serang.ui.profile.mystore.product.ProductActivity
|
import com.alya.ecommerce_serang.ui.profile.mystore.product.ProductActivity
|
||||||
import com.alya.ecommerce_serang.ui.profile.mystore.profile.DetailStoreProfileActivity
|
import com.alya.ecommerce_serang.ui.profile.mystore.profile.DetailStoreProfileActivity
|
||||||
import com.alya.ecommerce_serang.ui.profile.mystore.review.ReviewActivity
|
import com.alya.ecommerce_serang.ui.profile.mystore.review.ReviewActivity
|
||||||
import com.alya.ecommerce_serang.ui.profile.mystore.review.ReviewFragment
|
|
||||||
import com.alya.ecommerce_serang.ui.profile.mystore.sells.SellsActivity
|
import com.alya.ecommerce_serang.ui.profile.mystore.sells.SellsActivity
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
@ -52,14 +51,16 @@ class MyStoreActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
binding.header.headerTitle.text = "Toko Saya"
|
|
||||||
|
|
||||||
binding.header.headerLeftIcon.setOnClickListener {
|
binding.headerMyStore.headerTitle.text = "Toko Saya"
|
||||||
|
|
||||||
|
binding.headerMyStore.headerLeftIcon.setOnClickListener {
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.loadMyStore()
|
viewModel.loadMyStore()
|
||||||
|
viewModel.loadMyStoreProducts()
|
||||||
|
|
||||||
viewModel.myStoreProfile.observe(this){ user ->
|
viewModel.myStoreProfile.observe(this){ user ->
|
||||||
user?.let { myStoreProfileOverview(it) }
|
user?.let { myStoreProfileOverview(it) }
|
||||||
@ -68,9 +69,9 @@ class MyStoreActivity : AppCompatActivity() {
|
|||||||
viewModel.errorMessage.observe(this) { error ->
|
viewModel.errorMessage.observe(this) { error ->
|
||||||
Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
setUpClickListeners()
|
setUpClickListeners()
|
||||||
getCountOrder()
|
getCountOrder()
|
||||||
|
observeViewModel()
|
||||||
viewModel.fetchBalance()
|
viewModel.fetchBalance()
|
||||||
fetchBalance()
|
fetchBalance()
|
||||||
}
|
}
|
||||||
@ -170,13 +171,11 @@ class MyStoreActivity : AppCompatActivity() {
|
|||||||
when (result) {
|
when (result) {
|
||||||
is com.alya.ecommerce_serang.data.repository.Result.Loading ->
|
is com.alya.ecommerce_serang.data.repository.Result.Loading ->
|
||||||
null
|
null
|
||||||
// binding.progressBar.isVisible = true
|
|
||||||
is com.alya.ecommerce_serang.data.repository.Result.Success ->
|
is com.alya.ecommerce_serang.data.repository.Result.Success ->
|
||||||
viewModel.formattedBalance.observe(this) {
|
viewModel.formattedBalance.observe(this) {
|
||||||
binding.tvBalance.text = it
|
binding.tvBalance.text = it
|
||||||
}
|
}
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
// binding.progressBar.isVisible = false
|
|
||||||
Log.e(
|
Log.e(
|
||||||
"MyStoreActivity",
|
"MyStoreActivity",
|
||||||
"Gagal memuat saldo: ${result.exception.localizedMessage}"
|
"Gagal memuat saldo: ${result.exception.localizedMessage}"
|
||||||
@ -186,15 +185,29 @@ class MyStoreActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun observeViewModel() {
|
||||||
|
viewModel.productList.observe(this) { result ->
|
||||||
|
when (result) {
|
||||||
|
is Result.Loading -> {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
is Result.Success -> {
|
||||||
|
val productList = result.data
|
||||||
|
val count = productList.size
|
||||||
|
Log.d("MyStoreActivty", "You have $count products")
|
||||||
|
|
||||||
|
// Example: update UI
|
||||||
|
binding.tvNumProduct.text = "$count produk"
|
||||||
|
}
|
||||||
|
is Result.Error -> {
|
||||||
|
Log.e("MyStoreActivity", "Failed load product : ${result.exception.message}" )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PROFILE_REQUEST_CODE = 100
|
private const val PROFILE_REQUEST_CODE = 100
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun navigateToSellsFragment(status: String) {
|
|
||||||
// val sellsFragment = SellsListFragment.newInstance(status)
|
|
||||||
// supportFragmentManager.beginTransaction()
|
|
||||||
// .replace(android.R.id.content, sellsFragment)
|
|
||||||
// .addToBackStack(null)
|
|
||||||
// .commit()
|
|
||||||
// }
|
|
||||||
}
|
}
|
@ -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
|
||||||
@ -32,8 +30,10 @@ import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
|||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import com.alya.ecommerce_serang.data.repository.UserRepository
|
import com.alya.ecommerce_serang.data.repository.UserRepository
|
||||||
import com.alya.ecommerce_serang.databinding.ActivityRegisterStoreBinding
|
import com.alya.ecommerce_serang.databinding.ActivityRegisterStoreBinding
|
||||||
|
import com.alya.ecommerce_serang.ui.order.address.BankAdapter
|
||||||
import com.alya.ecommerce_serang.ui.order.address.CityAdapter
|
import com.alya.ecommerce_serang.ui.order.address.CityAdapter
|
||||||
import com.alya.ecommerce_serang.ui.order.address.ProvinceAdapter
|
import com.alya.ecommerce_serang.ui.order.address.ProvinceAdapter
|
||||||
|
import com.alya.ecommerce_serang.ui.order.address.SubdsitrictAdapter
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
import com.alya.ecommerce_serang.utils.viewmodel.RegisterStoreViewModel
|
import com.alya.ecommerce_serang.utils.viewmodel.RegisterStoreViewModel
|
||||||
@ -45,6 +45,9 @@ class RegisterStoreActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private lateinit var provinceAdapter: ProvinceAdapter
|
private lateinit var provinceAdapter: ProvinceAdapter
|
||||||
private lateinit var cityAdapter: CityAdapter
|
private lateinit var cityAdapter: CityAdapter
|
||||||
|
private lateinit var subdistrictAdapter: SubdsitrictAdapter
|
||||||
|
private lateinit var bankAdapter: BankAdapter
|
||||||
|
|
||||||
// Request codes for file picking
|
// Request codes for file picking
|
||||||
private val PICK_STORE_IMAGE_REQUEST = 1001
|
private val PICK_STORE_IMAGE_REQUEST = 1001
|
||||||
private val PICK_KTP_REQUEST = 1002
|
private val PICK_KTP_REQUEST = 1002
|
||||||
@ -88,6 +91,8 @@ class RegisterStoreActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
provinceAdapter = ProvinceAdapter(this)
|
provinceAdapter = ProvinceAdapter(this)
|
||||||
cityAdapter = CityAdapter(this)
|
cityAdapter = CityAdapter(this)
|
||||||
|
subdistrictAdapter = SubdsitrictAdapter(this)
|
||||||
|
bankAdapter = BankAdapter(this)
|
||||||
Log.d(TAG, "onCreate: Adapters initialized")
|
Log.d(TAG, "onCreate: Adapters initialized")
|
||||||
|
|
||||||
setupDataBinding()
|
setupDataBinding()
|
||||||
@ -101,8 +106,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 +170,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))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +235,28 @@ class RegisterStoreActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.subdistrictState.observe(this) { state ->
|
||||||
|
when (state) {
|
||||||
|
is Result.Loading -> {
|
||||||
|
Log.d(TAG, "setupobservers: Loading Subdistrict...")
|
||||||
|
binding.subdistrictProgressBar.visibility = View.VISIBLE
|
||||||
|
binding.spinnerSubdistrict.isEnabled = false
|
||||||
|
}
|
||||||
|
is Result.Success -> {
|
||||||
|
Log.d(TAG, "setupobservers: Subdistrict loaded successfullti: ${state.data.size} subdistrict")
|
||||||
|
binding.subdistrictProgressBar.visibility = View.GONE
|
||||||
|
binding.spinnerSubdistrict.isEnabled = true
|
||||||
|
|
||||||
|
subdistrictAdapter.updateData(state.data)
|
||||||
|
}
|
||||||
|
is Result.Error -> {
|
||||||
|
Log.e(TAG, "setupObservers: Error loading subdistrict: ${state.exception.message}")
|
||||||
|
binding.subdistrictProgressBar.visibility = View.GONE
|
||||||
|
binding.spinnerCity.isEnabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Observe registration state
|
// Observe registration state
|
||||||
viewModel.registerState.observe(this) { result ->
|
viewModel.registerState.observe(this) { result ->
|
||||||
when (result) {
|
when (result) {
|
||||||
@ -395,6 +427,11 @@ class RegisterStoreActivity : AppCompatActivity() {
|
|||||||
if (cityId != null) {
|
if (cityId != null) {
|
||||||
Log.d(TAG, "Setting city ID: $cityId")
|
Log.d(TAG, "Setting city ID: $cityId")
|
||||||
viewModel.cityId.value = cityId
|
viewModel.cityId.value = cityId
|
||||||
|
Log.d(TAG, "Fetching subdistrict for city ID: $cityId")
|
||||||
|
viewModel.getSubdistrict(cityId)
|
||||||
|
|
||||||
|
subdistrictAdapter.clear()
|
||||||
|
binding.spinnerSubdistrict.setSelection(0)
|
||||||
viewModel.selectedCityId = cityId
|
viewModel.selectedCityId = cityId
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Invalid city ID for position: $position")
|
Log.e(TAG, "Invalid city ID for position: $position")
|
||||||
@ -406,6 +443,61 @@ class RegisterStoreActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Setup Subdistrict spinner
|
||||||
|
binding.spinnerSubdistrict.adapter = subdistrictAdapter
|
||||||
|
binding.spinnerSubdistrict.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
|
Log.d(TAG, "Subdistrict selected at position: $position")
|
||||||
|
val subdistrictId = subdistrictAdapter.getSubdistrictId(position)
|
||||||
|
if (subdistrictId != null) {
|
||||||
|
Log.d(TAG, "Setting subdistrict ID: $subdistrictId")
|
||||||
|
viewModel.subdistrict.value = subdistrictId
|
||||||
|
viewModel.selectedSubdistrict = subdistrictId
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Invalid subdistrict ID for position: $position")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
|
Log.d(TAG, "No city selected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.spinnerBankName.adapter = bankAdapter
|
||||||
|
binding.spinnerBankName.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(
|
||||||
|
parent: AdapterView<*>?,
|
||||||
|
view: View?,
|
||||||
|
position: Int,
|
||||||
|
id: Long
|
||||||
|
) {
|
||||||
|
Log.d(TAG, "Bank selected at position: $position")
|
||||||
|
val bankName = bankAdapter.getBankName(position)
|
||||||
|
if (bankName != null) {
|
||||||
|
Log.d(TAG, "Setting bank name: $bankName")
|
||||||
|
viewModel.bankName.value = bankName
|
||||||
|
viewModel.selectedBankName = bankName
|
||||||
|
|
||||||
|
// Optional: Log the selected bank details
|
||||||
|
val selectedBank = bankAdapter.getBankItem(position)
|
||||||
|
selectedBank?.let {
|
||||||
|
Log.d(TAG, "Selected bank: ${it.bankName} (Code: ${it.bankCode})")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide progress bar if it was showing
|
||||||
|
binding.bankNameProgressBar.visibility = View.GONE
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Invalid bank name for position: $position")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
|
Log.d(TAG, "No bank selected")
|
||||||
|
viewModel.selectedBankName = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add initial hints to the spinners
|
// Add initial hints to the spinners
|
||||||
if (provinceAdapter.isEmpty) {
|
if (provinceAdapter.isEmpty) {
|
||||||
Log.d(TAG, "Adding default province hint")
|
Log.d(TAG, "Adding default province hint")
|
||||||
@ -417,6 +509,16 @@ class RegisterStoreActivity : AppCompatActivity() {
|
|||||||
cityAdapter.add("Pilih Kabupaten/Kota")
|
cityAdapter.add("Pilih Kabupaten/Kota")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subdistrictAdapter.isEmpty) {
|
||||||
|
Log.d(TAG, "Adding default kecamatan hint")
|
||||||
|
subdistrictAdapter.add("Pilih Kecamatan")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bankAdapter.isEmpty) {
|
||||||
|
Log.d(TAG, "Adding default bank hint")
|
||||||
|
bankAdapter.add("Pilih Bank")
|
||||||
|
}
|
||||||
|
|
||||||
Log.d(TAG, "setupSpinners: Province and city spinners setup completed")
|
Log.d(TAG, "setupSpinners: Province and city spinners setup completed")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,44 +602,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")
|
||||||
@ -617,25 +719,36 @@ class RegisterStoreActivity : AppCompatActivity() {
|
|||||||
validateRequiredFields()
|
validateRequiredFields()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
//
|
||||||
|
// binding.etSubdistrict.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.subdistrict.value = s.toString()
|
||||||
|
// Log.d(TAG, "Subdistrict updated: ${s.toString()}")
|
||||||
|
// validateRequiredFields()
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
binding.etSubdistrict.addTextChangedListener(object : TextWatcher {
|
// binding.etBankName.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.bankName.value = s.toString()
|
||||||
|
// Log.d(TAG, "Bank name updated: ${s.toString()}")
|
||||||
|
// validateRequiredFields()
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
|
binding.etAccountName.addTextChangedListener(object : TextWatcher {
|
||||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
||||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
|
||||||
override fun afterTextChanged(s: Editable?) {
|
override fun afterTextChanged(s: Editable?) {
|
||||||
viewModel.subdistrict.value = s.toString()
|
viewModel.accountName.value = s.toString()
|
||||||
Log.d(TAG, "Subdistrict updated: ${s.toString()}")
|
Log.d(TAG, "Account Name updated: ${s.toString()}")
|
||||||
validateRequiredFields()
|
validateRequiredFields()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
binding.etBankName.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.bankName.value = s.toString()
|
|
||||||
Log.d(TAG, "Bank 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")
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.alya.ecommerce_serang.ui.profile.mystore
|
||||||
|
|
||||||
|
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
|
||||||
|
import com.alya.ecommerce_serang.databinding.ActivityStoreSuspendedBinding
|
||||||
|
|
||||||
|
class StoreSuspendedActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityStoreSuspendedBinding
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = ActivityStoreSuspendedBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
binding.header.headerTitle.text = "Toko Dinonaktifkan"
|
||||||
|
binding.header.headerLeftIcon.setOnClickListener {
|
||||||
|
onBackPressedDispatcher.onBackPressed()
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,11 +15,15 @@ import android.widget.Spinner
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.widget.doAfterTextChanged
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.alya.ecommerce_serang.R
|
import com.alya.ecommerce_serang.R
|
||||||
import com.alya.ecommerce_serang.data.api.response.store.profile.Payment
|
import com.alya.ecommerce_serang.data.api.response.store.profile.Payment
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||||
|
import com.alya.ecommerce_serang.utils.ImageUtils.compressImage
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
@ -38,6 +42,8 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
private lateinit var spinnerPaymentMethod: Spinner
|
private lateinit var spinnerPaymentMethod: Spinner
|
||||||
private lateinit var edtTransactionDate: EditText
|
private lateinit var edtTransactionDate: EditText
|
||||||
private lateinit var datePickerIcon: ImageView
|
private lateinit var datePickerIcon: ImageView
|
||||||
|
private lateinit var layoutMBankingInstructions: View
|
||||||
|
private lateinit var layoutATMInstructions: View
|
||||||
private lateinit var btnSend: Button
|
private lateinit var btnSend: Button
|
||||||
private lateinit var sessionManager: SessionManager
|
private lateinit var sessionManager: SessionManager
|
||||||
|
|
||||||
@ -52,7 +58,22 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
val imageUri = result.data?.data
|
val imageUri = result.data?.data
|
||||||
imageUri?.let {
|
imageUri?.let {
|
||||||
selectedImageUri = it
|
selectedImageUri = it
|
||||||
imgPreview.setImageURI(it)
|
|
||||||
|
// Compress the image before displaying it
|
||||||
|
val compressedFile = compressImage(
|
||||||
|
context = this,
|
||||||
|
uri = it,
|
||||||
|
filename = "topup_img",
|
||||||
|
maxWidth = 1024,
|
||||||
|
maxHeight = 1024,
|
||||||
|
quality = 80
|
||||||
|
)
|
||||||
|
|
||||||
|
// Display the compressed image
|
||||||
|
selectedImageUri = Uri.fromFile(compressedFile)
|
||||||
|
imgPreview.setImageURI(Uri.fromFile(compressedFile))
|
||||||
|
|
||||||
|
validateForm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,6 +92,8 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
spinnerPaymentMethod = findViewById(R.id.spinner_metode_bayar)
|
spinnerPaymentMethod = findViewById(R.id.spinner_metode_bayar)
|
||||||
edtTransactionDate = findViewById(R.id.edt_tgl_transaksi)
|
edtTransactionDate = findViewById(R.id.edt_tgl_transaksi)
|
||||||
datePickerIcon = findViewById(R.id.img_date_picker)
|
datePickerIcon = findViewById(R.id.img_date_picker)
|
||||||
|
layoutMBankingInstructions = findViewById(R.id.layout_mbanking_instructions)
|
||||||
|
layoutATMInstructions = findViewById(R.id.layout_atm_instructions)
|
||||||
btnSend = findViewById(R.id.btn_send)
|
btnSend = findViewById(R.id.btn_send)
|
||||||
|
|
||||||
// Setup header title
|
// Setup header title
|
||||||
@ -98,10 +121,27 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
// Fetch payment methods
|
// Fetch payment methods
|
||||||
fetchPaymentMethods()
|
fetchPaymentMethods()
|
||||||
|
|
||||||
|
setupClickListeners("1234567890")
|
||||||
|
|
||||||
// Setup submit button
|
// Setup submit button
|
||||||
btnSend.setOnClickListener {
|
btnSend.setOnClickListener {
|
||||||
submitForm()
|
submitForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate form when any input changes
|
||||||
|
edtNominal.doAfterTextChanged { validateForm() }
|
||||||
|
edtTransactionDate.doAfterTextChanged { validateForm() }
|
||||||
|
spinnerPaymentMethod.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
|
selectedPaymentId = paymentMethods[position].id
|
||||||
|
validateForm()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
|
selectedPaymentId = -1
|
||||||
|
validateForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openGallery() {
|
private fun openGallery() {
|
||||||
@ -200,6 +240,24 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun validateForm() {
|
||||||
|
val isNominalFilled = edtNominal.text.toString().trim().isNotEmpty()
|
||||||
|
val isPaymentMethodSelected = selectedPaymentId != -1
|
||||||
|
val isTransactionDateFilled = edtTransactionDate.text.toString().trim().isNotEmpty()
|
||||||
|
val isImageSelected = selectedImageUri != null
|
||||||
|
|
||||||
|
val valid = isNominalFilled && isPaymentMethodSelected && isTransactionDateFilled && isImageSelected
|
||||||
|
btnSend.isEnabled = valid
|
||||||
|
btnSend.setTextColor(
|
||||||
|
if (valid) ContextCompat.getColor(this, R.color.white)
|
||||||
|
else ContextCompat.getColor(this, R.color.black_300)
|
||||||
|
)
|
||||||
|
btnSend.setBackgroundResource(
|
||||||
|
if (valid) R.drawable.bg_button_active
|
||||||
|
else R.drawable.bg_button_disabled
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun submitForm() {
|
private fun submitForm() {
|
||||||
// Prevent multiple clicks
|
// Prevent multiple clicks
|
||||||
if (!btnSend.isEnabled) {
|
if (!btnSend.isEnabled) {
|
||||||
@ -316,7 +374,7 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// Show a dialog with the success message
|
// Show a dialog with the success message
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
androidx.appcompat.app.AlertDialog.Builder(this@BalanceTopUpActivity)
|
AlertDialog.Builder(this@BalanceTopUpActivity)
|
||||||
.setTitle("Berhasil")
|
.setTitle("Berhasil")
|
||||||
.setMessage(successMessage)
|
.setMessage(successMessage)
|
||||||
.setPositiveButton("OK") { dialog, _ ->
|
.setPositiveButton("OK") { dialog, _ ->
|
||||||
@ -350,7 +408,7 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// Show a dialog with the error message
|
// Show a dialog with the error message
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
androidx.appcompat.app.AlertDialog.Builder(this@BalanceTopUpActivity)
|
AlertDialog.Builder(this@BalanceTopUpActivity)
|
||||||
.setTitle("Error Response")
|
.setTitle("Error Response")
|
||||||
.setMessage(errorMessage)
|
.setMessage(errorMessage)
|
||||||
.setPositiveButton("OK") { dialog, _ ->
|
.setPositiveButton("OK") { dialog, _ ->
|
||||||
@ -392,4 +450,46 @@ class BalanceTopUpActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
return tempFile
|
return tempFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupClickListeners(bankAccountNumber: String) {
|
||||||
|
// Instructions clicks
|
||||||
|
layoutMBankingInstructions.setOnClickListener {
|
||||||
|
showInstructions("mBanking", bankAccountNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
layoutATMInstructions.setOnClickListener {
|
||||||
|
showInstructions("ATM", bankAccountNumber)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showInstructions(type: String, bankAccountNumber: String) {
|
||||||
|
// Implementasi tampilkan instruksi
|
||||||
|
val instructions = when (type) {
|
||||||
|
"mBanking" -> listOf(
|
||||||
|
"1. Login ke aplikasi mobile banking",
|
||||||
|
"2. Pilih menu Transfer",
|
||||||
|
"3. Pilih menu Antar Rekening",
|
||||||
|
"4. Masukkan nomor rekening tujuan: $bankAccountNumber",
|
||||||
|
"5. Masukkan nominal saldo yang ingin diisi",
|
||||||
|
"6. Konfirmasi dan selesaikan transfer"
|
||||||
|
)
|
||||||
|
"ATM" -> listOf(
|
||||||
|
"1. Masukkan kartu ATM dan PIN",
|
||||||
|
"2. Pilih menu Transfer",
|
||||||
|
"3. Pilih menu Antar Rekening",
|
||||||
|
"4. Masukkan kode bank dan nomor rekening tujuan: $bankAccountNumber",
|
||||||
|
"5. Masukkan nominal saldo yang ingin diisi",
|
||||||
|
"6. Konfirmasi dan selesaikan transfer"
|
||||||
|
)
|
||||||
|
else -> emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tampilkan instruksi dalam dialog
|
||||||
|
val dialog = AlertDialog.Builder(this)
|
||||||
|
.setTitle("Petunjuk Transfer $type")
|
||||||
|
.setItems(instructions.toTypedArray(), null)
|
||||||
|
.setPositiveButton("Tutup", null)
|
||||||
|
.create()
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ import androidx.core.view.ViewCompat
|
|||||||
import androidx.core.view.WindowInsetsAnimationCompat
|
import androidx.core.view.WindowInsetsAnimationCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
||||||
import com.alya.ecommerce_serang.R
|
import com.alya.ecommerce_serang.R
|
||||||
@ -373,7 +374,8 @@ class ChatStoreActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.state.observe(this, Observer { state ->
|
lifecycleScope.launchWhenStarted {
|
||||||
|
viewModel.state.collect { state ->
|
||||||
Log.d(TAG, "State updated - Messages: ${state.messages.size}")
|
Log.d(TAG, "State updated - Messages: ${state.messages.size}")
|
||||||
|
|
||||||
// Update messages
|
// Update messages
|
||||||
@ -434,7 +436,8 @@ class ChatStoreActivity : AppCompatActivity() {
|
|||||||
Toast.makeText(this@ChatStoreActivity, error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@ChatStoreActivity, error, Toast.LENGTH_SHORT).show()
|
||||||
viewModel.clearError()
|
viewModel.clearError()
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showOptionsMenu() {
|
private fun showOptionsMenu() {
|
||||||
|
@ -12,36 +12,37 @@ import android.view.View
|
|||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import com.alya.ecommerce_serang.R
|
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import androidx.core.widget.doAfterTextChanged
|
||||||
|
import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
||||||
|
import com.alya.ecommerce_serang.R
|
||||||
import com.alya.ecommerce_serang.data.api.dto.CategoryItem
|
import com.alya.ecommerce_serang.data.api.dto.CategoryItem
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Preorder
|
import com.alya.ecommerce_serang.data.api.dto.Preorder
|
||||||
|
import com.alya.ecommerce_serang.data.api.dto.Wholesale
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||||
import com.alya.ecommerce_serang.data.repository.ProductRepository
|
import com.alya.ecommerce_serang.data.repository.ProductRepository
|
||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import com.alya.ecommerce_serang.databinding.ActivityDetailStoreProductBinding
|
import com.alya.ecommerce_serang.databinding.ActivityDetailStoreProductBinding
|
||||||
import com.alya.ecommerce_serang.utils.viewmodel.ProductViewModel
|
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
|
import com.alya.ecommerce_serang.utils.FileUtils.compressFile
|
||||||
|
import com.alya.ecommerce_serang.utils.ImageUtils.compressImage
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
|
import com.alya.ecommerce_serang.utils.viewmodel.ProductViewModel
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import kotlin.getValue
|
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.core.widget.doAfterTextChanged
|
|
||||||
import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Wholesale
|
|
||||||
|
|
||||||
class DetailStoreProductActivity : AppCompatActivity() {
|
class DetailStoreProductActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityDetailStoreProductBinding
|
private lateinit var binding: ActivityDetailStoreProductBinding
|
||||||
private lateinit var sessionManager: SessionManager
|
private lateinit var sessionManager: SessionManager
|
||||||
private lateinit var categoryList: List<CategoryItem>
|
private var categoryList: List<CategoryItem> = emptyList()
|
||||||
private var imageUri: Uri? = null
|
private var imageUri: Uri? = null
|
||||||
private var sppirtUri: Uri? = null
|
private var sppirtUri: Uri? = null
|
||||||
private var halalUri: Uri? = null
|
private var halalUri: Uri? = null
|
||||||
@ -61,7 +62,10 @@ class DetailStoreProductActivity : AppCompatActivity() {
|
|||||||
if (result.resultCode == Activity.RESULT_OK) {
|
if (result.resultCode == Activity.RESULT_OK) {
|
||||||
imageUri = result.data?.data
|
imageUri = result.data?.data
|
||||||
imageUri?.let {
|
imageUri?.let {
|
||||||
binding.ivPreviewFoto.setImageURI(it)
|
compressImage(this, it, "productimg").let { compressedImageFile ->
|
||||||
|
binding.ivPreviewFoto.setImageURI(Uri.fromFile(compressedImageFile))
|
||||||
|
imageUri = Uri.fromFile(compressedImageFile)
|
||||||
|
}
|
||||||
binding.switcherFotoProduk.showNext()
|
binding.switcherFotoProduk.showNext()
|
||||||
hasImage = true
|
hasImage = true
|
||||||
}
|
}
|
||||||
@ -71,19 +75,23 @@ class DetailStoreProductActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private val sppirtLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
private val sppirtLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
||||||
if (uri != null && isValidFile(uri)) {
|
if (uri != null && isValidFile(uri)) {
|
||||||
sppirtUri = uri
|
compressFile(this, uri).let { compressedFile ->
|
||||||
binding.tvSppirtName.text = getFileName(uri)
|
sppirtUri = compressedFile?.toUri()
|
||||||
|
binding.tvSppirtName.text = getFileName(sppirtUri!!)
|
||||||
binding.switcherSppirt.showNext()
|
binding.switcherSppirt.showNext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val halalLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
private val halalLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
||||||
if (uri != null && isValidFile(uri)) {
|
if (uri != null && isValidFile(uri)) {
|
||||||
halalUri = uri
|
compressFile(this, uri).let { compressedFile ->
|
||||||
binding.tvHalalName.text = getFileName(uri)
|
halalUri = compressedFile?.toUri()
|
||||||
|
binding.tvHalalName.text = getFileName(halalUri!!)
|
||||||
binding.switcherHalal.showNext()
|
binding.switcherHalal.showNext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -93,7 +101,7 @@ class DetailStoreProductActivity : AppCompatActivity() {
|
|||||||
val isEditing = intent.getBooleanExtra("is_editing", false)
|
val isEditing = intent.getBooleanExtra("is_editing", false)
|
||||||
productId = intent.getIntExtra("product_id", -1)
|
productId = intent.getIntExtra("product_id", -1)
|
||||||
|
|
||||||
binding.header.headerTitle.text = if (isEditing) "Ubah Produk" else "Tambah Produk"
|
binding.headerStoreProduct.headerTitle.text = if (isEditing) "Ubah Produk" else "Tambah Produk"
|
||||||
|
|
||||||
if (isEditing && productId != null && productId != -1) {
|
if (isEditing && productId != null && productId != -1) {
|
||||||
viewModel.loadProductDetail(productId!!)
|
viewModel.loadProductDetail(productId!!)
|
||||||
@ -140,7 +148,7 @@ class DetailStoreProductActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.header.headerLeftIcon.setOnClickListener {
|
binding.headerStoreProduct.headerLeftIcon.setOnClickListener {
|
||||||
onBackPressedDispatcher.onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
|||||||
import com.alya.ecommerce_serang.data.repository.ProductRepository
|
import com.alya.ecommerce_serang.data.repository.ProductRepository
|
||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import com.alya.ecommerce_serang.databinding.ActivityProductBinding
|
import com.alya.ecommerce_serang.databinding.ActivityProductBinding
|
||||||
import com.alya.ecommerce_serang.utils.viewmodel.ProductViewModel
|
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
|
import com.alya.ecommerce_serang.utils.viewmodel.ProductViewModel
|
||||||
|
|
||||||
class ProductActivity : AppCompatActivity() {
|
class ProductActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@ -94,14 +94,14 @@ class ProductActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupHeader() {
|
private fun setupHeader() {
|
||||||
binding.header.headerTitle.text = "Produk Saya"
|
binding.headerListProduct.headerTitle.text = "Produk Saya"
|
||||||
binding.header.headerRightText.visibility = View.VISIBLE
|
binding.headerListProduct.headerRightText.visibility = View.VISIBLE
|
||||||
|
|
||||||
binding.header.headerLeftIcon.setOnClickListener {
|
binding.headerListProduct.headerLeftIcon.setOnClickListener {
|
||||||
onBackPressedDispatcher.onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.header.headerRightText.setOnClickListener {
|
binding.headerListProduct.headerRightText.setOnClickListener {
|
||||||
val intent = Intent(this, DetailStoreProductActivity::class.java)
|
val intent = Intent(this, DetailStoreProductActivity::class.java)
|
||||||
intent.putExtra("is_editing", false)
|
intent.putExtra("is_editing", false)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
@ -111,4 +111,6 @@ class ProductActivity : AppCompatActivity() {
|
|||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
binding.rvStoreProduct.layoutManager = LinearLayoutManager(this)
|
binding.rvStoreProduct.layoutManager = LinearLayoutManager(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package com.alya.ecommerce_serang.ui.profile.mystore.profile.address
|
package com.alya.ecommerce_serang.ui.profile.mystore.profile.address
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -14,13 +13,16 @@ import com.alya.ecommerce_serang.BuildConfig
|
|||||||
import com.alya.ecommerce_serang.R
|
import com.alya.ecommerce_serang.R
|
||||||
import com.alya.ecommerce_serang.data.api.dto.City
|
import com.alya.ecommerce_serang.data.api.dto.City
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Province
|
import com.alya.ecommerce_serang.data.api.dto.Province
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesItem
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
||||||
import com.alya.ecommerce_serang.data.repository.AddressRepository
|
import com.alya.ecommerce_serang.data.repository.AddressRepository
|
||||||
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import com.alya.ecommerce_serang.databinding.ActivityDetailStoreAddressBinding
|
import com.alya.ecommerce_serang.databinding.ActivityDetailStoreAddressBinding
|
||||||
import com.alya.ecommerce_serang.utils.viewmodel.AddressViewModel
|
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
|
import com.alya.ecommerce_serang.utils.viewmodel.AddressViewModel
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
|
||||||
class DetailStoreAddressActivity : AppCompatActivity() {
|
class DetailStoreAddressActivity : AppCompatActivity() {
|
||||||
@ -30,10 +32,15 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private var selectedProvinceId: String? = null
|
private var selectedProvinceId: String? = null
|
||||||
private var selectedCityId: String? = null
|
private var selectedCityId: String? = null
|
||||||
|
private var selectedSubdistrict: String? = null
|
||||||
private var provinces: List<Province> = emptyList()
|
private var provinces: List<Province> = emptyList()
|
||||||
private var cities: List<City> = emptyList()
|
private var cities: List<City> = emptyList()
|
||||||
|
private var subdistrict: List<SubdistrictsItem> = emptyList()
|
||||||
|
private var currentAddress: AddressesItem? = null
|
||||||
|
|
||||||
private val TAG = "StoreAddressActivity"
|
// private lateinit var subdistrictAdapter: SubdsitrictAdapter
|
||||||
|
|
||||||
|
private val TAG = "DetailStoreAddressActivity"
|
||||||
|
|
||||||
private val viewModel: AddressViewModel by viewModels {
|
private val viewModel: AddressViewModel by viewModels {
|
||||||
BaseViewModelFactory {
|
BaseViewModelFactory {
|
||||||
@ -58,13 +65,15 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
binding.tvError.visibility = View.GONE
|
binding.tvError.visibility = View.GONE
|
||||||
|
|
||||||
// Set up header title
|
// Set up header title
|
||||||
binding.header.headerTitle.text = "Atur Alamat Toko"
|
binding.headerAddressStore.headerTitle.text = "Atur Alamat Toko"
|
||||||
|
|
||||||
// Set up back button
|
// Set up back button
|
||||||
binding.header.headerLeftIcon.setOnClickListener {
|
binding.headerAddressStore.headerLeftIcon.setOnClickListener {
|
||||||
onBackPressedDispatcher.onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// subdistrictAdapter = SubdsitrictAdapter(this)
|
||||||
|
|
||||||
setupSpinners()
|
setupSpinners()
|
||||||
setupObservers()
|
setupObservers()
|
||||||
setupSaveButton()
|
setupSaveButton()
|
||||||
@ -113,11 +122,26 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
binding.spinnerCity.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
binding.spinnerCity.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
selectedCityId = if (position > 0) cities[position - 1].cityId else null
|
selectedCityId = if (position > 0) cities[position - 1].cityId else null
|
||||||
|
|
||||||
|
viewModel.getSubdistrict(selectedCityId.toString())
|
||||||
|
|
||||||
checkAllFieldsFilled()
|
checkAllFieldsFilled()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNothingSelected(p0: AdapterView<*>?) {}
|
override fun onNothingSelected(p0: AdapterView<*>?) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.spinnerSubdistrict.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
|
selectedSubdistrict = if (position > 0) subdistrict[position - 1].subdistrictName else null
|
||||||
|
|
||||||
|
checkAllFieldsFilled()
|
||||||
|
|
||||||
|
}
|
||||||
|
override fun onNothingSelected(p0: AdapterView<*>?) {}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupObservers() {
|
private fun setupObservers() {
|
||||||
@ -176,19 +200,58 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.subdistrictState.observe(this) { result ->
|
||||||
|
when (result) {
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Loading -> {
|
||||||
|
showSubLoading(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
is com.alya.ecommerce_serang.data.repository.Result.Success -> {
|
||||||
|
showSubLoading(false)
|
||||||
|
|
||||||
|
subdistrict = result.data
|
||||||
|
val subdistrictNames = mutableListOf("Pilih Kecamatan")
|
||||||
|
subdistrictNames.addAll(result.data.map { it.subdistrictName })
|
||||||
|
|
||||||
|
val adapter = ArrayAdapter(
|
||||||
|
this,
|
||||||
|
android.R.layout.simple_spinner_item,
|
||||||
|
subdistrictNames
|
||||||
|
)
|
||||||
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||||
|
binding.spinnerSubdistrict.adapter = adapter
|
||||||
|
|
||||||
|
// Compare by name, since stored value is the subdistrict name
|
||||||
|
viewModel.storeAddress.value?.let { address ->
|
||||||
|
val index = subdistrict.indexOfFirst { it.subdistrictName == address.subdistrict }
|
||||||
|
if (index != -1) {
|
||||||
|
binding.spinnerSubdistrict.setSelection(index + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is Result.Error -> {
|
||||||
|
showSubLoading(false)
|
||||||
|
Log.e(TAG, "Error: ${result.exception.message}", result.exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Observe store address data
|
// Observe store address data
|
||||||
viewModel.storeAddress.observe(this) { address ->
|
viewModel.storeAddress.observe(this) { address ->
|
||||||
|
currentAddress = address
|
||||||
Log.d(TAG, "Received store address: $address")
|
Log.d(TAG, "Received store address: $address")
|
||||||
address?.let {
|
address?.let {
|
||||||
// Set the fields
|
// Set the fields
|
||||||
binding.edtStreet.setText(it.street)
|
binding.edtStreet.setText(it.street)
|
||||||
binding.edtSubdistrict.setText(it.subdistrict)
|
// binding.edtSubdistrict.setText(it.subdistrict)
|
||||||
binding.edtDetailAddress.setText(it.detail ?: "")
|
binding.edtDetailAddress.setText(it.detail ?: "")
|
||||||
binding.edtPostalCode.setText(it.postalCode)
|
binding.edtPostalCode.setText(it.postalCode)
|
||||||
binding.edtLatitude.setText(it.latitude.toString())
|
binding.edtLatitude.setText(it.latitude.toString())
|
||||||
binding.edtLongitude.setText(it.longitude.toString())
|
binding.edtLongitude.setText(it.longitude.toString())
|
||||||
selectedProvinceId = it.provinceId
|
selectedProvinceId = it.provinceId
|
||||||
selectedCityId = it.cityId
|
selectedCityId = it.cityId
|
||||||
|
selectedSubdistrict = it.subdistrict
|
||||||
|
|
||||||
// Find province index and select it after provinces are loaded
|
// Find province index and select it after provinces are loaded
|
||||||
if (provinces.isNotEmpty()) {
|
if (provinces.isNotEmpty()) {
|
||||||
@ -214,11 +277,12 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Observe save success
|
// Observe save success
|
||||||
viewModel.saveSuccess.observe(this) {
|
viewModel.saveSuccess.observe(this) { success ->
|
||||||
if (it) {
|
if (success) {
|
||||||
Toast.makeText(this, "Alamat berhasil disimpan", Toast.LENGTH_SHORT).show()
|
Log.d(TAG, "Address updated successfully")
|
||||||
setResult(Activity.RESULT_OK)
|
|
||||||
finish()
|
finish()
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Failed to update address")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,14 +290,15 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
private fun setupSaveButton() {
|
private fun setupSaveButton() {
|
||||||
binding.btnSaveAddress.setOnClickListener {
|
binding.btnSaveAddress.setOnClickListener {
|
||||||
val street = binding.edtStreet.text.toString()
|
val street = binding.edtStreet.text.toString()
|
||||||
val subdistrict = binding.edtSubdistrict.text.toString()
|
|
||||||
val detail = binding.edtDetailAddress.text.toString()
|
val detail = binding.edtDetailAddress.text.toString()
|
||||||
val postalCode = binding.edtPostalCode.text.toString()
|
val postalCode = binding.edtPostalCode.text.toString()
|
||||||
val latitude = binding.edtLatitude.text.toString().toDoubleOrNull() ?: 0.0
|
val latitude = binding.edtLatitude.text.toString()
|
||||||
val longitude = binding.edtLongitude.text.toString().toDoubleOrNull() ?: 0.0
|
val longitude = binding.edtLongitude.text.toString()
|
||||||
|
|
||||||
val city = cities.find { it.cityId == selectedCityId }
|
val city = cities.find { it.cityId == selectedCityId }
|
||||||
val province = provinces.find { it.provinceId == selectedProvinceId }
|
val province = provinces.find { it.provinceId == selectedProvinceId }
|
||||||
|
val subdistrictName = subdistrict.find { it.subdistrictName == selectedSubdistrict }?.subdistrictName.toString()
|
||||||
|
Log.d(TAG, "Subdistrict name: $subdistrictName")
|
||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if (selectedProvinceId.isNullOrEmpty() || city == null || street.isEmpty() || subdistrict.isEmpty() || postalCode.isEmpty()) {
|
if (selectedProvinceId.isNullOrEmpty() || city == null || street.isEmpty() || subdistrict.isEmpty() || postalCode.isEmpty()) {
|
||||||
@ -241,19 +306,35 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save address
|
val oldAddress = currentAddress ?: return@setOnClickListener
|
||||||
viewModel.saveStoreAddress(
|
val newAddress = oldAddress.copy(
|
||||||
provinceId = selectedProvinceId!!,
|
provinceId = selectedProvinceId!!,
|
||||||
provinceName = province?.provinceName ?: "",
|
|
||||||
cityId = city.cityId,
|
cityId = city.cityId,
|
||||||
cityName = city.cityName,
|
|
||||||
street = street,
|
street = street,
|
||||||
subdistrict = subdistrict,
|
subdistrict = subdistrictName,
|
||||||
detail = detail,
|
detail = detail,
|
||||||
postalCode = postalCode,
|
postalCode = postalCode,
|
||||||
latitude = latitude,
|
latitude = latitude,
|
||||||
longitude = longitude
|
longitude = longitude,
|
||||||
|
phone = oldAddress.phone,
|
||||||
|
recipient = oldAddress.recipient ?: "",
|
||||||
|
isStoreLocation = oldAddress.isStoreLocation,
|
||||||
|
villageId = oldAddress.villageId
|
||||||
)
|
)
|
||||||
|
viewModel.saveStoreAddress(oldAddress, newAddress)
|
||||||
|
// Save address
|
||||||
|
// viewModel.saveStoreAddress(
|
||||||
|
// provinceId = selectedProvinceId!!,
|
||||||
|
// provinceName = province?.provinceName ?: "",
|
||||||
|
// cityId = city.cityId,
|
||||||
|
// cityName = city.cityName,
|
||||||
|
// street = street,
|
||||||
|
// subdistrict = subdistrict,
|
||||||
|
// detail = detail,
|
||||||
|
// postalCode = postalCode,
|
||||||
|
// latitude = latitude,
|
||||||
|
// longitude = longitude
|
||||||
|
// )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,15 +345,14 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
|
||||||
}
|
}
|
||||||
binding.edtStreet.addTextChangedListener(watcher)
|
binding.edtStreet.addTextChangedListener(watcher)
|
||||||
binding.edtSubdistrict.addTextChangedListener(watcher)
|
|
||||||
binding.edtPostalCode.addTextChangedListener(watcher)
|
binding.edtPostalCode.addTextChangedListener(watcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAllFieldsFilled() {
|
private fun checkAllFieldsFilled() {
|
||||||
val allValid = !selectedProvinceId.isNullOrEmpty()
|
val allValid = !selectedProvinceId.isNullOrEmpty()
|
||||||
&& !selectedCityId.isNullOrEmpty()
|
&& !selectedCityId.isNullOrEmpty()
|
||||||
|
&& !selectedSubdistrict.isNullOrEmpty()
|
||||||
&& binding.edtStreet.text.isNotBlank()
|
&& binding.edtStreet.text.isNotBlank()
|
||||||
&& binding.edtSubdistrict.text.isNotBlank()
|
|
||||||
&& binding.edtPostalCode.text.isNotBlank()
|
&& binding.edtPostalCode.text.isNotBlank()
|
||||||
|
|
||||||
binding.btnSaveAddress.let {
|
binding.btnSaveAddress.let {
|
||||||
@ -284,6 +364,7 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
it.isEnabled = false
|
it.isEnabled = false
|
||||||
it.setBackgroundResource(R.drawable.bg_button_disabled)
|
it.setBackgroundResource(R.drawable.bg_button_disabled)
|
||||||
it.setTextColor(getColor(R.color.black_300))
|
it.setTextColor(getColor(R.color.black_300))
|
||||||
|
Toast.makeText(this, "Periksa dan lenkapi alamat anda", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,6 +379,12 @@ class DetailStoreAddressActivity : AppCompatActivity() {
|
|||||||
binding.spinnerCity.visibility = if (isLoading) View.GONE else View.VISIBLE
|
binding.spinnerCity.visibility = if (isLoading) View.GONE else View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showSubLoading(isLoading: Boolean) {
|
||||||
|
binding.subdistrictProgressBar.visibility = if (isLoading) View.VISIBLE else View.GONE
|
||||||
|
binding.spinnerSubdistrict.visibility = if (isLoading) View.GONE else View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun showError(message: String) {
|
private fun showError(message: String) {
|
||||||
binding.progressBar.visibility = View.GONE
|
binding.progressBar.visibility = View.GONE
|
||||||
binding.tvError.visibility = View.VISIBLE
|
binding.tvError.visibility = View.VISIBLE
|
||||||
|
@ -6,9 +6,12 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.AdapterView
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import android.widget.ProgressBar
|
||||||
|
import android.widget.Spinner
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -18,6 +21,7 @@ import com.alya.ecommerce_serang.data.api.dto.PaymentInfo
|
|||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||||
import com.alya.ecommerce_serang.data.repository.PaymentInfoRepository
|
import com.alya.ecommerce_serang.data.repository.PaymentInfoRepository
|
||||||
import com.alya.ecommerce_serang.databinding.ActivityPaymentInfoBinding
|
import com.alya.ecommerce_serang.databinding.ActivityPaymentInfoBinding
|
||||||
|
import com.alya.ecommerce_serang.ui.order.address.BankAdapter
|
||||||
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
||||||
import com.alya.ecommerce_serang.utils.SessionManager
|
import com.alya.ecommerce_serang.utils.SessionManager
|
||||||
import com.alya.ecommerce_serang.utils.UriToFileConverter
|
import com.alya.ecommerce_serang.utils.UriToFileConverter
|
||||||
@ -32,6 +36,7 @@ class PaymentInfoActivity : AppCompatActivity() {
|
|||||||
private lateinit var sessionManager: SessionManager
|
private lateinit var sessionManager: SessionManager
|
||||||
private var selectedQrisImageUri: Uri? = null
|
private var selectedQrisImageUri: Uri? = null
|
||||||
private var selectedQrisImageFile: File? = null
|
private var selectedQrisImageFile: File? = null
|
||||||
|
private lateinit var bankAdapter: BankAdapter
|
||||||
|
|
||||||
// Store form data between dialog reopenings
|
// Store form data between dialog reopenings
|
||||||
private var savedBankName: String = ""
|
private var savedBankName: String = ""
|
||||||
@ -95,6 +100,7 @@ class PaymentInfoActivity : AppCompatActivity() {
|
|||||||
onBackPressedDispatcher.onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bankAdapter = BankAdapter(this)
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
setupObservers()
|
setupObservers()
|
||||||
|
|
||||||
@ -173,10 +179,47 @@ class PaymentInfoActivity : AppCompatActivity() {
|
|||||||
builder.setView(dialogView)
|
builder.setView(dialogView)
|
||||||
|
|
||||||
val dialog = builder.create()
|
val dialog = builder.create()
|
||||||
|
val spinnerBankName = dialogView.findViewById<Spinner>(R.id.spinner_bank_name)
|
||||||
|
val progressBarBank = dialogView.findViewById<ProgressBar>(R.id.bank_name_progress_bar)
|
||||||
|
|
||||||
|
spinnerBankName.adapter = bankAdapter
|
||||||
|
spinnerBankName.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(
|
||||||
|
parent: AdapterView<*>?,
|
||||||
|
view: View?,
|
||||||
|
position: Int,
|
||||||
|
id: Long
|
||||||
|
) {
|
||||||
|
Log.d(TAG, "Bank selected at position: $position")
|
||||||
|
val bankName = bankAdapter.getBankName(position)
|
||||||
|
if (bankName != null) {
|
||||||
|
Log.d(TAG, "Setting bank name: $bankName")
|
||||||
|
viewModel.bankName.value = bankName
|
||||||
|
viewModel.selectedBankName = bankName
|
||||||
|
|
||||||
|
// Optional: Log the selected bank details
|
||||||
|
val selectedBank = bankAdapter.getBankItem(position)
|
||||||
|
selectedBank?.let {
|
||||||
|
Log.d(TAG, "Selected bank: ${it.bankName} (Code: ${it.bankCode})")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide progress bar if it was showing
|
||||||
|
progressBarBank.visibility = View.GONE
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Invalid bank name for position: $position")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
|
Log.d(TAG, "No bank selected")
|
||||||
|
viewModel.selectedBankName = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get references to views in the dialog
|
// Get references to views in the dialog
|
||||||
val btnAddQris = dialogView.findViewById<Button>(R.id.btn_add_qris)
|
val btnAddQris = dialogView.findViewById<Button>(R.id.btn_add_qris)
|
||||||
val bankNameEditText = dialogView.findViewById<EditText>(R.id.edt_bank_name)
|
// val spinnerBankName = dialogView.findViewById<Spinner>(R.id.spinner_bank_name)
|
||||||
val bankNumberEditText = dialogView.findViewById<EditText>(R.id.edt_bank_number)
|
val bankNumberEditText = dialogView.findViewById<EditText>(R.id.edt_bank_number)
|
||||||
val accountNameEditText = dialogView.findViewById<EditText>(R.id.edt_account_name)
|
val accountNameEditText = dialogView.findViewById<EditText>(R.id.edt_account_name)
|
||||||
val qrisPreview = dialogView.findViewById<ImageView>(R.id.iv_qris_preview)
|
val qrisPreview = dialogView.findViewById<ImageView>(R.id.iv_qris_preview)
|
||||||
@ -185,7 +228,10 @@ class PaymentInfoActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// When reopening, restore the previously entered values
|
// When reopening, restore the previously entered values
|
||||||
if (isReopened) {
|
if (isReopened) {
|
||||||
bankNameEditText.setText(savedBankName)
|
val savedPosition = bankAdapter.findPositionByName(savedBankName)
|
||||||
|
if (savedPosition >= 0) {
|
||||||
|
spinnerBankName.setSelection(savedPosition)
|
||||||
|
}
|
||||||
bankNumberEditText.setText(savedBankNumber)
|
bankNumberEditText.setText(savedBankNumber)
|
||||||
accountNameEditText.setText(savedAccountName)
|
accountNameEditText.setText(savedAccountName)
|
||||||
|
|
||||||
@ -199,7 +245,7 @@ class PaymentInfoActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
btnAddQris.setOnClickListener {
|
btnAddQris.setOnClickListener {
|
||||||
// Save the current values before dismissing
|
// Save the current values before dismissing
|
||||||
savedBankName = bankNameEditText.text.toString().trim()
|
savedBankName = viewModel.selectedBankName ?: ""
|
||||||
savedBankNumber = bankNumberEditText.text.toString().trim()
|
savedBankNumber = bankNumberEditText.text.toString().trim()
|
||||||
savedAccountName = accountNameEditText.text.toString().trim()
|
savedAccountName = accountNameEditText.text.toString().trim()
|
||||||
|
|
||||||
@ -212,13 +258,13 @@ class PaymentInfoActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
btnSave.setOnClickListener {
|
btnSave.setOnClickListener {
|
||||||
val bankName = bankNameEditText.text.toString().trim()
|
val bankName = viewModel.selectedBankName ?: ""
|
||||||
val bankNumber = bankNumberEditText.text.toString().trim()
|
val bankNumber = bankNumberEditText.text.toString().trim()
|
||||||
val accountName = accountNameEditText.text.toString().trim()
|
val accountName = accountNameEditText.text.toString().trim()
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
if (bankName.isEmpty()) {
|
if (bankName.isEmpty()) {
|
||||||
showSnackbar("Nama bank tidak boleh kosong")
|
showSnackbar("Pilih nama bank terlebih dahulu")
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,13 +8,46 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
|||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody.Companion.asRequestBody
|
import okhttp3.RequestBody.Companion.asRequestBody
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
import java.util.zip.GZIPOutputStream
|
||||||
|
|
||||||
object FileUtils {
|
object FileUtils {
|
||||||
private const val TAG = "FileUtils"
|
private const val TAG = "FileUtils"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a temporary file from a URI in the app's cache directory
|
* Compress a file to GZIP format to reduce its size to below 1MB
|
||||||
|
* @param context The context
|
||||||
|
* @param uri The URI of the file to compress
|
||||||
|
* @param maxSize The target size limit in bytes (1MB = 1048576 bytes)
|
||||||
|
* @return The compressed file, or null if compression failed
|
||||||
|
*/
|
||||||
|
fun compressFile(context: Context, uri: Uri, maxSize: Long = 1048576L): File? {
|
||||||
|
try {
|
||||||
|
// Create a temporary file for compressed content
|
||||||
|
val originalFile = createTempFileFromUri(context, uri, "compressed")
|
||||||
|
val compressedFile = File(context.cacheDir, "compressed_${System.currentTimeMillis()}.gz")
|
||||||
|
|
||||||
|
// Compress the original file into the GZIP file
|
||||||
|
compressToGZIP(originalFile, compressedFile)
|
||||||
|
|
||||||
|
// Check if the compressed file is larger than the allowed size
|
||||||
|
if (compressedFile.length() <= maxSize) {
|
||||||
|
Log.d(TAG, "Compression successful. Compressed file size: ${compressedFile.length()} bytes.")
|
||||||
|
return compressedFile
|
||||||
|
} else {
|
||||||
|
// If the file is still too large, you can handle it by reducing quality or adjusting compression logic
|
||||||
|
Log.e(TAG, "Compressed file exceeds the size limit. Size: ${compressedFile.length()} bytes.")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error during file compression: ${e.message}", e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a temporary file from the URI in the app's cache directory.
|
||||||
*/
|
*/
|
||||||
fun createTempFileFromUri(context: Context, uri: Uri, prefix: String = "temp"): File? {
|
fun createTempFileFromUri(context: Context, uri: Uri, prefix: String = "temp"): File? {
|
||||||
try {
|
try {
|
||||||
@ -41,6 +74,23 @@ object FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compress the input file into a GZIP file.
|
||||||
|
*/
|
||||||
|
private fun compressToGZIP(inputFile: File?, outputFile: File) {
|
||||||
|
FileInputStream(inputFile).use { inputStream ->
|
||||||
|
FileOutputStream(outputFile).use { fileOutputStream ->
|
||||||
|
GZIPOutputStream(fileOutputStream).use { gzipOutputStream ->
|
||||||
|
val buffer = ByteArray(1024)
|
||||||
|
var bytesRead: Int
|
||||||
|
while (inputStream.read(buffer).also { bytesRead = it } != -1) {
|
||||||
|
gzipOutputStream.write(buffer, 0, bytesRead)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the file extension from a URI using ContentResolver
|
* Gets the file extension from a URI using ContentResolver
|
||||||
*/
|
*/
|
||||||
|
@ -7,8 +7,10 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.alya.ecommerce_serang.data.api.dto.City
|
import com.alya.ecommerce_serang.data.api.dto.City
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Province
|
import com.alya.ecommerce_serang.data.api.dto.Province
|
||||||
import com.alya.ecommerce_serang.data.api.dto.StoreAddress
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesItem
|
||||||
import com.alya.ecommerce_serang.data.repository.AddressRepository
|
import com.alya.ecommerce_serang.data.repository.AddressRepository
|
||||||
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class AddressViewModel(private val addressRepository: AddressRepository) : ViewModel() {
|
class AddressViewModel(private val addressRepository: AddressRepository) : ViewModel() {
|
||||||
@ -21,8 +23,8 @@ class AddressViewModel(private val addressRepository: AddressRepository) : ViewM
|
|||||||
private val _cities = MutableLiveData<List<City>>()
|
private val _cities = MutableLiveData<List<City>>()
|
||||||
val cities: LiveData<List<City>> = _cities
|
val cities: LiveData<List<City>> = _cities
|
||||||
|
|
||||||
private val _storeAddress = MutableLiveData<StoreAddress?>()
|
private val _storeAddress = MutableLiveData<AddressesItem?>()
|
||||||
val storeAddress: LiveData<StoreAddress?> = _storeAddress
|
val storeAddress: LiveData<AddressesItem?> get() = _storeAddress
|
||||||
|
|
||||||
private val _isLoading = MutableLiveData<Boolean>()
|
private val _isLoading = MutableLiveData<Boolean>()
|
||||||
val isLoading: LiveData<Boolean> = _isLoading
|
val isLoading: LiveData<Boolean> = _isLoading
|
||||||
@ -31,99 +33,249 @@ class AddressViewModel(private val addressRepository: AddressRepository) : ViewM
|
|||||||
val errorMessage: LiveData<String> = _errorMessage
|
val errorMessage: LiveData<String> = _errorMessage
|
||||||
|
|
||||||
private val _saveSuccess = MutableLiveData<Boolean>()
|
private val _saveSuccess = MutableLiveData<Boolean>()
|
||||||
val saveSuccess: LiveData<Boolean> = _saveSuccess
|
val saveSuccess: LiveData<Boolean> get() = _saveSuccess
|
||||||
|
|
||||||
|
private val _subdistrictState = MutableLiveData<Result<List<SubdistrictsItem>>>()
|
||||||
|
val subdistrictState: LiveData<Result<List<SubdistrictsItem>>> = _subdistrictState
|
||||||
|
|
||||||
|
|
||||||
|
var selectedSubdistrict: String? = null
|
||||||
|
val subdistrict = MutableLiveData<String>()
|
||||||
|
|
||||||
fun fetchProvinces() {
|
fun fetchProvinces() {
|
||||||
Log.d(TAG, "fetchProvinces() called")
|
|
||||||
_isLoading.value = true
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "Calling addressRepository.getProvinces()")
|
|
||||||
val response = addressRepository.getProvinces()
|
val response = addressRepository.getProvinces()
|
||||||
Log.d(TAG, "Received provinces response: ${response.size} provinces")
|
if (response.isSuccessful) {
|
||||||
_provinces.value = response
|
_provinces.value = response.body()?.data ?: emptyList()
|
||||||
_isLoading.value = false
|
} else {
|
||||||
|
Log.e("EditAddressVM", "Failed to get provinces: ${response.message()}")
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error fetching provinces", e)
|
Log.e("EditAddressVM", "Error getting provinces: ${e.message}")
|
||||||
_errorMessage.value = "Failed to load provinces: ${e.message}"
|
|
||||||
_isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchCities(provinceId: String) {
|
fun fetchCities(provinceId: String) {
|
||||||
Log.d(TAG, "fetchCities() called with provinceId: $provinceId")
|
|
||||||
_isLoading.value = true
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "Calling addressRepository.getCities()")
|
|
||||||
val response = addressRepository.getCities(provinceId)
|
val response = addressRepository.getCities(provinceId)
|
||||||
Log.d(TAG, "Received cities response: ${response.size} cities")
|
if (response.isSuccessful) {
|
||||||
_cities.value = response
|
_cities.value = response.body()?.cities ?: emptyList()
|
||||||
_isLoading.value = false
|
} else {
|
||||||
|
Log.e("EditAddressVM", "Failed to get cities: ${response.message()}")
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error fetching cities", e)
|
Log.e("EditAddressVM", "Error getting cities: ${e.message}")
|
||||||
_errorMessage.value = "Failed to load cities: ${e.message}"
|
|
||||||
_isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSubdistrict(cityId: String) {
|
||||||
|
_subdistrictState.value = Result.Loading
|
||||||
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
|
||||||
|
selectedSubdistrict = cityId
|
||||||
|
val result = addressRepository.getListSubdistrict(cityId)
|
||||||
|
result?.let {
|
||||||
|
_subdistrictState.postValue(Result.Success(it.subdistricts))
|
||||||
|
Log.d(TAG, "Cities loaded for province $cityId: ${it.subdistricts.size}")
|
||||||
|
} ?: run {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception("Failed to load cities")))
|
||||||
|
Log.e(TAG, "City result was null for province $cityId")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception(e.message ?: "Error loading cities")))
|
||||||
|
Log.e(TAG, "Error fetching cities for province $cityId", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// fun fetchProvinces() {
|
||||||
|
// Log.d(TAG, "fetchProvinces() called")
|
||||||
|
// _isLoading.value = true
|
||||||
|
// viewModelScope.launch {
|
||||||
|
// try {
|
||||||
|
// Log.d(TAG, "Calling addressRepository.getProvinces()")
|
||||||
|
// val response = addressRepository.getProvinces()
|
||||||
|
// Log.d(TAG, "Received provinces response: ${response.size} provinces")
|
||||||
|
// _provinces.value = response
|
||||||
|
// _isLoading.value = false
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Error fetching provinces", e)
|
||||||
|
// _errorMessage.value = "Failed to load provinces: ${e.message}"
|
||||||
|
// _isLoading.value = false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fun fetchCities(provinceId: String) {
|
||||||
|
// Log.d(TAG, "fetchCities() called with provinceId: $provinceId")
|
||||||
|
// _isLoading.value = true
|
||||||
|
// viewModelScope.launch {
|
||||||
|
// try {
|
||||||
|
// selecte
|
||||||
|
// Log.d(TAG, "Calling addressRepository.getCities()")
|
||||||
|
// val response = addressRepository.getCities(provinceId)
|
||||||
|
// Log.d(TAG, "Received cities response: ${response.size} cities")
|
||||||
|
// _cities.value = response
|
||||||
|
// _isLoading.value = false
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Error fetching cities", e)
|
||||||
|
// _errorMessage.value = "Failed to load cities: ${e.message}"
|
||||||
|
// _isLoading.value = false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fun fetchStoreAddress() {
|
||||||
|
// Log.d(TAG, "fetchStoreAddress() called")
|
||||||
|
// _isLoading.value = true
|
||||||
|
// viewModelScope.launch {
|
||||||
|
// try {
|
||||||
|
// Log.d(TAG, "Calling addressRepository.getStoreAddress()")
|
||||||
|
// val response = addressRepository.getStoreAddress()
|
||||||
|
// Log.d(TAG, "Received store address response: $response")
|
||||||
|
// _storeAddress.value = response
|
||||||
|
// _isLoading.value = false
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Error fetching store address", e)
|
||||||
|
// _errorMessage.value = "Failed to load store address: ${e.message}"
|
||||||
|
// _isLoading.value = false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fun fetchStoreAddress() {
|
||||||
|
// viewModelScope.launch {
|
||||||
|
// try {
|
||||||
|
// val response = addressRepository.getStoreAddress()
|
||||||
|
// if (response.isSuccessful) {
|
||||||
|
// val storeAddress = response.body()?.addresses
|
||||||
|
// ?.firstOrNull { it.isStoreLocation == true }
|
||||||
|
//
|
||||||
|
// if (storeAddress != null) {
|
||||||
|
// _storeAddress.value = storeAddress
|
||||||
|
// } else {
|
||||||
|
// Log.d("EditAddressVM", "No store address found")
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// Log.e("EditAddressVM", "Failed to get addresses: ${response.message()}")
|
||||||
|
// }
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e("EditAddressVM", "Error: ${e.message}")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
fun fetchStoreAddress() {
|
fun fetchStoreAddress() {
|
||||||
Log.d(TAG, "fetchStoreAddress() called")
|
|
||||||
_isLoading.value = true
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "Calling addressRepository.getStoreAddress()")
|
|
||||||
val response = addressRepository.getStoreAddress()
|
val response = addressRepository.getStoreAddress()
|
||||||
Log.d(TAG, "Received store address response: $response")
|
if (response.isSuccessful) {
|
||||||
_storeAddress.value = response
|
val storeAddress = response.body()?.addresses
|
||||||
_isLoading.value = false
|
?.firstOrNull { it.isStoreLocation == true }
|
||||||
|
|
||||||
|
if (storeAddress != null) {
|
||||||
|
_storeAddress.value = storeAddress
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "No store address found")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Failed to get addresses: ${response.message()}")
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error fetching store address", e)
|
Log.e(TAG, "Error: ${e.message}")
|
||||||
_errorMessage.value = "Failed to load store address: ${e.message}"
|
|
||||||
_isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveStoreAddress(
|
// fun saveStoreAddress(
|
||||||
provinceId: String,
|
// provinceId: String,
|
||||||
provinceName: String,
|
// provinceName: String,
|
||||||
cityId: String,
|
// cityId: String,
|
||||||
cityName: String,
|
// cityName: String,
|
||||||
street: String,
|
// street: String,
|
||||||
subdistrict: String,
|
// subdistrict: String,
|
||||||
detail: String,
|
// detail: String,
|
||||||
postalCode: String,
|
// postalCode: String,
|
||||||
latitude: Double,
|
// latitude: Double,
|
||||||
longitude: Double
|
// longitude: Double
|
||||||
) {
|
// ) {
|
||||||
Log.d(TAG, "saveStoreAddress() called with provinceId: $provinceId, cityId: $cityId")
|
// Log.d(TAG, "saveStoreAddress() called with provinceId: $provinceId, cityId: $cityId")
|
||||||
_isLoading.value = true
|
// _isLoading.value = true
|
||||||
|
// viewModelScope.launch {
|
||||||
|
// try {
|
||||||
|
// Log.d(TAG, "Calling addressRepository.saveStoreAddress()")
|
||||||
|
// val success = addressRepository.saveStoreAddress(
|
||||||
|
// provinceId = provinceId,
|
||||||
|
// provinceName = provinceName,
|
||||||
|
// cityId = cityId,
|
||||||
|
// cityName = cityName,
|
||||||
|
// street = street,
|
||||||
|
// subdistrict = subdistrict,
|
||||||
|
// detail = detail,
|
||||||
|
// postalCode = postalCode,
|
||||||
|
// latitude = latitude,
|
||||||
|
// longitude = longitude
|
||||||
|
// )
|
||||||
|
// Log.d(TAG, "Save store address result: $success")
|
||||||
|
// _saveSuccess.value = success
|
||||||
|
// _isLoading.value = false
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e(TAG, "Error saving store address", e)
|
||||||
|
// _errorMessage.value = "Failed to save address: ${e.message}"
|
||||||
|
// _isLoading.value = false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
fun saveStoreAddress(oldAddress: AddressesItem, newAddress: AddressesItem) {
|
||||||
|
val params = buildUpdateBody(oldAddress, newAddress)
|
||||||
|
if (params.isEmpty()) {
|
||||||
|
Log.d(TAG, "No changes detected")
|
||||||
|
_saveSuccess.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "Calling addressRepository.saveStoreAddress()")
|
val response = addressRepository.updateAddress(oldAddress.id, params)
|
||||||
val success = addressRepository.saveStoreAddress(
|
_saveSuccess.value = response.isSuccessful
|
||||||
provinceId = provinceId,
|
|
||||||
provinceName = provinceName,
|
|
||||||
cityId = cityId,
|
|
||||||
cityName = cityName,
|
|
||||||
street = street,
|
|
||||||
subdistrict = subdistrict,
|
|
||||||
detail = detail,
|
|
||||||
postalCode = postalCode,
|
|
||||||
latitude = latitude,
|
|
||||||
longitude = longitude
|
|
||||||
)
|
|
||||||
Log.d(TAG, "Save store address result: $success")
|
|
||||||
_saveSuccess.value = success
|
|
||||||
_isLoading.value = false
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error saving store address", e)
|
Log.e(TAG, "Error: ${e.message}")
|
||||||
_errorMessage.value = "Failed to save address: ${e.message}"
|
_saveSuccess.value = false
|
||||||
_isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildUpdateBody(oldAddress: AddressesItem, newAddress: AddressesItem): Map<String, Any> {
|
||||||
|
|
||||||
|
val params = mutableMapOf<String, Any>()
|
||||||
|
|
||||||
|
fun addIfChanged(key: String, oldValue: Any?, newValue: Any?) {
|
||||||
|
if (newValue != null && newValue != oldValue) {
|
||||||
|
params[key] = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addIfChanged("street", oldAddress.street, newAddress.street)
|
||||||
|
addIfChanged("province_id", oldAddress.provinceId, newAddress.provinceId)
|
||||||
|
addIfChanged("detail", oldAddress.detail, newAddress.detail)
|
||||||
|
addIfChanged("subdistrict", oldAddress.subdistrict, newAddress.subdistrict)
|
||||||
|
addIfChanged("city_id", oldAddress.cityId, newAddress.cityId)
|
||||||
|
addIfChanged("village_id", oldAddress.villageId, newAddress.villageId)
|
||||||
|
addIfChanged("postal_code", oldAddress.postalCode, newAddress.postalCode)
|
||||||
|
addIfChanged("phone", oldAddress.phone, newAddress.phone)
|
||||||
|
addIfChanged("recipient", oldAddress.recipient, newAddress.recipient)
|
||||||
|
addIfChanged("latitude", oldAddress.latitude, newAddress.latitude)
|
||||||
|
addIfChanged("longitude", oldAddress.longitude, newAddress.longitude)
|
||||||
|
addIfChanged("is_store_location", oldAddress.isStoreLocation, newAddress.isStoreLocation)
|
||||||
|
|
||||||
|
return params
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,8 +7,10 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.alya.ecommerce_serang.data.api.dto.FcmReq
|
import com.alya.ecommerce_serang.data.api.dto.FcmReq
|
||||||
|
import com.alya.ecommerce_serang.data.api.dto.ResetPassReq
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.FcmTokenResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.FcmTokenResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.LoginResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.LoginResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.auth.ResetPassResponse
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
@ -27,6 +29,10 @@ class LoginViewModel(private val repository: UserRepository, private val context
|
|||||||
private val _message = MutableLiveData<String>()
|
private val _message = MutableLiveData<String>()
|
||||||
val message: LiveData<String> = _message
|
val message: LiveData<String> = _message
|
||||||
|
|
||||||
|
private val _resetPasswordState = MutableLiveData<Result<ResetPassResponse>?>()
|
||||||
|
val resetPasswordState: LiveData<Result<ResetPassResponse>?> = _resetPasswordState
|
||||||
|
|
||||||
|
|
||||||
private val sessionManager by lazy { SessionManager(context) }
|
private val sessionManager by lazy { SessionManager(context) }
|
||||||
|
|
||||||
private fun getAuthenticatedApiService(): ApiService {
|
private fun getAuthenticatedApiService(): ApiService {
|
||||||
@ -69,4 +75,19 @@ class LoginViewModel(private val repository: UserRepository, private val context
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetPassword(email: String) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_resetPasswordState.value = Result.Loading
|
||||||
|
|
||||||
|
val request = ResetPassReq(emailOrPhone = email)
|
||||||
|
val result = repository.resetPassword(request)
|
||||||
|
|
||||||
|
_resetPasswordState.value = result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearState() {
|
||||||
|
_resetPasswordState.value = null
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.map
|
import androidx.lifecycle.map
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.alya.ecommerce_serang.data.api.dto.ProductsItem
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Store
|
import com.alya.ecommerce_serang.data.api.dto.Store
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.StoreTypesItem
|
import com.alya.ecommerce_serang.data.api.response.auth.StoreTypesItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.store.StoreResponse
|
import com.alya.ecommerce_serang.data.api.response.store.StoreResponse
|
||||||
@ -20,6 +21,8 @@ import java.text.NumberFormat
|
|||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
||||||
|
private var TAG = "MyStoreViewModel"
|
||||||
|
|
||||||
private val _myStoreProfile = MutableLiveData<Store?>()
|
private val _myStoreProfile = MutableLiveData<Store?>()
|
||||||
val myStoreProfile: LiveData<Store?> = _myStoreProfile
|
val myStoreProfile: LiveData<Store?> = _myStoreProfile
|
||||||
|
|
||||||
@ -38,6 +41,9 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
private val _balanceResult = MutableLiveData<Result<StoreResponse>>()
|
private val _balanceResult = MutableLiveData<Result<StoreResponse>>()
|
||||||
val balanceResult: LiveData<Result<StoreResponse>> get() = _balanceResult
|
val balanceResult: LiveData<Result<StoreResponse>> get() = _balanceResult
|
||||||
|
|
||||||
|
private val _productList = MutableLiveData<Result<List<ProductsItem>>>()
|
||||||
|
val productList: LiveData<Result<List<ProductsItem>>> get() = _productList
|
||||||
|
|
||||||
fun loadMyStore(){
|
fun loadMyStore(){
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
when (val result = repository.fetchMyStoreProfile()){
|
when (val result = repository.fetchMyStoreProfile()){
|
||||||
@ -80,30 +86,40 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
|
|
||||||
if (store == null) {
|
if (store == null) {
|
||||||
_errorMessage.postValue("Data toko tidak tersedia")
|
_errorMessage.postValue("Data toko tidak tersedia")
|
||||||
|
Log.e(TAG, "Store data is null")
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d("UpdateStoreProfileVM", "Calling repository with params:")
|
||||||
|
Log.d("UpdateStoreProfileVM", "storeName: $storeName")
|
||||||
|
Log.d("UpdateStoreProfileVM", "description: $description")
|
||||||
|
Log.d("UpdateStoreProfileVM", "isOnLeave: $isOnLeave")
|
||||||
|
Log.d("UpdateStoreProfileVM", "storeType: $storeType")
|
||||||
|
Log.d("UpdateStoreProfileVM", "storeImage: ${storeImage?.headers}")
|
||||||
|
|
||||||
val response = repository.updateStoreProfile(
|
val response = repository.updateStoreProfile(
|
||||||
storeName = storeName,
|
storeName = storeName,
|
||||||
storeStatus = "active".toRequestBody(),
|
|
||||||
storeDescription = description,
|
storeDescription = description,
|
||||||
isOnLeave = isOnLeave,
|
isOnLeave = isOnLeave,
|
||||||
cityId = store.cityId.toString().toRequestBody(),
|
|
||||||
provinceId = store.provinceId.toString().toRequestBody(),
|
|
||||||
street = store.street.toRequestBody(),
|
|
||||||
subdistrict = store.subdistrict.toRequestBody(),
|
|
||||||
detail = store.detail.toRequestBody(),
|
|
||||||
postalCode = store.postalCode.toRequestBody(),
|
|
||||||
latitude = store.latitude.toRequestBody(),
|
|
||||||
longitude = store.longitude.toRequestBody(),
|
|
||||||
userPhone = store.phone.toRequestBody(),
|
|
||||||
storeType = storeType,
|
storeType = storeType,
|
||||||
storeimg = storeImage
|
storeimg = storeImage
|
||||||
)
|
)
|
||||||
if (response.isSuccessful) _updateStoreProfileResult.postValue(response.body())
|
|
||||||
else _errorMessage.postValue("Gagal memperbarui profil")
|
if (response != null) {
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
_updateStoreProfileResult.postValue(response.body())
|
||||||
|
Log.d(TAG, "Update successful: ${response.body()}")
|
||||||
|
} else {
|
||||||
|
_errorMessage.postValue("Gagal memperbarui profil")
|
||||||
|
Log.e(TAG, "Update failed: ${response.errorBody()?.string()}")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_errorMessage.postValue("Terjadi kesalahan jaringan atau server")
|
||||||
|
Log.e(TAG, "Repository returned null response")
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_errorMessage.postValue(e.message ?: "Unexpected error")
|
_errorMessage.postValue(e.message ?: "Unexpected error")
|
||||||
|
Log.e(TAG, "Exception updating store profile", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,13 +132,13 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
result.data.orders.size ?: 0
|
result.data.orders.size ?: 0
|
||||||
}
|
}
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
Log.e("SellsViewModel", "Error getting orders count: ${result.exception.message}")
|
Log.e(TAG, "Error getting orders count: ${result.exception.message}")
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
is Result.Loading -> 0
|
is Result.Loading -> 0
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("SellsViewModel", "Exception getting orders count", e)
|
Log.e(TAG, "Exception getting orders count", e)
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +150,7 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
|
|
||||||
statuses.forEach { status ->
|
statuses.forEach { status ->
|
||||||
counts[status] = getTotalOrdersByStatus(status)
|
counts[status] = getTotalOrdersByStatus(status)
|
||||||
Log.d("SellsViewModel", "Status: $status, countOrder=${counts[status]}")
|
Log.d(TAG, "Status: $status, countOrder=${counts[status]}")
|
||||||
}
|
}
|
||||||
|
|
||||||
return counts
|
return counts
|
||||||
@ -158,6 +174,18 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun loadMyStoreProducts() {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_productList.value = Result.Loading
|
||||||
|
try {
|
||||||
|
val result = repository.fetchMyStoreProducts()
|
||||||
|
_productList.value = Result.Success(result)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_productList.value = Result.Error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun String.toRequestBody(): RequestBody =
|
private fun String.toRequestBody(): RequestBody =
|
||||||
RequestBody.create("text/plain".toMediaTypeOrNull(), this)
|
RequestBody.create("text/plain".toMediaTypeOrNull(), this)
|
||||||
}
|
}
|
@ -30,6 +30,9 @@ class PaymentInfoViewModel(private val repository: PaymentInfoRepository) : View
|
|||||||
private val _deletePaymentSuccess = MutableLiveData<Boolean>()
|
private val _deletePaymentSuccess = MutableLiveData<Boolean>()
|
||||||
val deletePaymentSuccess: LiveData<Boolean> = _deletePaymentSuccess
|
val deletePaymentSuccess: LiveData<Boolean> = _deletePaymentSuccess
|
||||||
|
|
||||||
|
var selectedBankName: String? = null
|
||||||
|
val bankName = MutableLiveData<String>()
|
||||||
|
|
||||||
fun getPaymentInfo() {
|
fun getPaymentInfo() {
|
||||||
_isLoading.value = true
|
_isLoading.value = true
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
@ -47,15 +47,15 @@ class ProfileViewModel(private val userRepository: UserRepository) : ViewModel()
|
|||||||
val response: HasStoreResponse = userRepository.checkStore()
|
val response: HasStoreResponse = userRepository.checkStore()
|
||||||
|
|
||||||
// Log and store success message
|
// Log and store success message
|
||||||
Log.d("RegisterViewModel", "OTP Response: ${response.hasStore}")
|
Log.d("ProfileViewModel", "Has store: ${response.hasStore}")
|
||||||
_checkStore.value = response.hasStore // Store the message for UI feedback
|
_checkStore.postValue(response.hasStore) // Store the message for UI feedback
|
||||||
|
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
// Handle any errors and update state
|
// Handle any errors and update state
|
||||||
_checkStore.value = false
|
_checkStore.postValue(false)
|
||||||
|
|
||||||
// Log the error for debugging
|
// Log the error for debugging
|
||||||
Log.e("RegisterViewModel", "Error:", exception)
|
Log.e(":ProfileViewModel", "Error:", exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ import com.alya.ecommerce_serang.data.api.response.auth.RegisterStoreResponse
|
|||||||
import com.alya.ecommerce_serang.data.api.response.auth.StoreTypesItem
|
import com.alya.ecommerce_serang.data.api.response.auth.StoreTypesItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem
|
import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.VillagesItem
|
||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import com.alya.ecommerce_serang.data.repository.UserRepository
|
import com.alya.ecommerce_serang.data.repository.UserRepository
|
||||||
import com.alya.ecommerce_serang.utils.ImageUtils
|
import com.alya.ecommerce_serang.utils.ImageUtils
|
||||||
@ -41,8 +43,17 @@ class RegisterStoreViewModel(
|
|||||||
private val _citiesState = MutableLiveData<Result<List<CitiesItem>>>()
|
private val _citiesState = MutableLiveData<Result<List<CitiesItem>>>()
|
||||||
val citiesState: LiveData<Result<List<CitiesItem>>> = _citiesState
|
val citiesState: LiveData<Result<List<CitiesItem>>> = _citiesState
|
||||||
|
|
||||||
|
private val _subdistrictState = MutableLiveData<Result<List<SubdistrictsItem>>>()
|
||||||
|
val subdistrictState: LiveData<Result<List<SubdistrictsItem>>> = _subdistrictState
|
||||||
|
|
||||||
|
private val _villagesState = MutableLiveData<Result<List<VillagesItem>>>()
|
||||||
|
val villagesState: LiveData<Result<List<VillagesItem>>> = _villagesState
|
||||||
|
|
||||||
var selectedProvinceId: Int? = null
|
var selectedProvinceId: Int? = null
|
||||||
var selectedCityId: String? = null
|
var selectedCityId: String? = null
|
||||||
|
var selectedSubdistrict: String? = null
|
||||||
|
var selectedVillages: String? = null
|
||||||
|
var selectedBankName: String? = null
|
||||||
|
|
||||||
// Form fields
|
// Form fields
|
||||||
val storeName = MutableLiveData<String>()
|
val storeName = MutableLiveData<String>()
|
||||||
@ -72,47 +83,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 +192,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 +217,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
|
||||||
@ -235,6 +276,52 @@ class RegisterStoreViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSubdistrict(cityId: String) {
|
||||||
|
_subdistrictState.value = Result.Loading
|
||||||
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
|
||||||
|
selectedSubdistrict = cityId
|
||||||
|
val result = repository.getListSubdistrict(cityId)
|
||||||
|
result?.let {
|
||||||
|
_subdistrictState.postValue(Result.Success(it.subdistricts))
|
||||||
|
Log.d(TAG, "Cities loaded for province $cityId: ${it.subdistricts.size}")
|
||||||
|
} ?: run {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception("Failed to load cities")))
|
||||||
|
Log.e(TAG, "City result was null for province $cityId")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception(e.message ?: "Error loading cities")))
|
||||||
|
Log.e(TAG, "Error fetching cities for province $cityId", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getVillages(subdistrictId: String) {
|
||||||
|
_villagesState.value = Result.Loading
|
||||||
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
|
||||||
|
selectedVillages = subdistrictId
|
||||||
|
val result = repository.getListVillages(subdistrictId)
|
||||||
|
result?.let {
|
||||||
|
_villagesState.postValue(Result.Success(it.villages))
|
||||||
|
Log.d(TAG, "Cities loaded for province $subdistrictId: ${it.villages.size}")
|
||||||
|
} ?: run {
|
||||||
|
_villagesState.postValue(Result.Error(Exception("Failed to load cities")))
|
||||||
|
Log.e(TAG, "City result was null for province $subdistrictId")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_villagesState.postValue(Result.Error(Exception(e.message ?: "Error loading cities")))
|
||||||
|
Log.e(TAG, "Error fetching cities for province $subdistrictId", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isBankSelected(): Boolean {
|
||||||
|
return !selectedBankName.isNullOrEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "RegisterStoreUserViewModel"
|
private const val TAG = "RegisterStoreUserViewModel"
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest
|
import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.RegisterRequest
|
import com.alya.ecommerce_serang.data.api.dto.RegisterRequest
|
||||||
|
import com.alya.ecommerce_serang.data.api.dto.ResetPassReq
|
||||||
import com.alya.ecommerce_serang.data.api.dto.VerifRegisReq
|
import com.alya.ecommerce_serang.data.api.dto.VerifRegisReq
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.LoginResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.LoginResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.auth.OtpResponse
|
import com.alya.ecommerce_serang.data.api.response.auth.OtpResponse
|
||||||
@ -71,6 +72,7 @@ class RegisterViewModel(private val repository: UserRepository, private val orde
|
|||||||
var selectedProvinceId: Int? = null
|
var selectedProvinceId: Int? = null
|
||||||
var selectedCityId: String? = null
|
var selectedCityId: String? = null
|
||||||
var selectedSubdistrict: String? = null
|
var selectedSubdistrict: String? = null
|
||||||
|
var subdistrictName: String? = null
|
||||||
var selectedVillages: String? = null
|
var selectedVillages: String? = null
|
||||||
var selectedPostalCode: String? = null
|
var selectedPostalCode: String? = null
|
||||||
|
|
||||||
@ -382,6 +384,10 @@ class RegisterViewModel(private val repository: UserRepository, private val orde
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetPass(request: ResetPassReq){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "RegisterViewModel"
|
private const val TAG = "RegisterViewModel"
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,14 @@
|
|||||||
android:paddingHorizontal="@dimen/horizontal_safe_area"
|
android:paddingHorizontal="@dimen/horizontal_safe_area"
|
||||||
android:layout_marginTop="19dp">
|
android:layout_marginTop="19dp">
|
||||||
|
|
||||||
<!-- Foto Produk -->
|
<!-- Bukti Bayar -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_marginBottom="24dp">
|
android:layout_marginBottom="24dp">
|
||||||
|
|
||||||
<!-- Label Foto Produk -->
|
<!-- Label Bukti Bayar -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -42,7 +42,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="Foto Produk"
|
android:text="Bukti Pembayaran"
|
||||||
style="@style/body_medium"
|
style="@style/body_medium"
|
||||||
android:layout_marginEnd="4dp"/>
|
android:layout_marginEnd="4dp"/>
|
||||||
|
|
||||||
@ -275,12 +275,73 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Petunjuk -->
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:background="#E0E0E0" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/layout_mbanking_instructions"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Petunjuk Transfer mBanking"
|
||||||
|
style="@style/body_medium" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:src="@drawable/ic_arrow_right" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="#E0E0E0" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/layout_atm_instructions"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Petunjuk Transfer ATM"
|
||||||
|
style="@style/body_medium" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:src="@drawable/ic_arrow_right" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="#E0E0E0" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_send"
|
android:id="@+id/btn_send"
|
||||||
android:text="Kirim"
|
android:text="Kirim"
|
||||||
style="@style/button.large.disabled.long"
|
style="@style/button.large.disabled.long"
|
||||||
|
android:enabled="false"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -122,12 +122,14 @@
|
|||||||
android:src="@drawable/outline_shopping_cart_24" />
|
android:src="@drawable/outline_shopping_cart_24" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/emptyCart"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:text="Keranjang Anda kosong"
|
android:visibility="gone"
|
||||||
|
android:text="Keranjang anda kosong"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:textSize="18sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
tools:context=".ui.profile.mystore.profile.address.DetailStoreAddressActivity">
|
tools:context=".ui.profile.mystore.profile.address.DetailStoreAddressActivity">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/header"
|
android:id="@+id/header_address_store"
|
||||||
layout="@layout/header" />
|
layout="@layout/header" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
@ -154,6 +154,58 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Kecamatan -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_marginBottom="24dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Kecamatan"
|
||||||
|
style="@style/body_medium"
|
||||||
|
android:layout_marginEnd="4dp"/>
|
||||||
|
|
||||||
|
<!-- Spinner Dropdown dengan Chevron -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:background="@drawable/bg_text_field"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginTop="10dp">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spinner_subdistrict"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="8dp"
|
||||||
|
style="@style/body_small"
|
||||||
|
android:background="@null"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/subdistrict_progress_bar"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<!-- Chevron Down Icon -->
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:src="@drawable/ic_down"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:contentDescription="Chevron Down" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<!-- Jalan -->
|
<!-- Jalan -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -180,32 +232,6 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Kecamatan -->
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_marginBottom="24dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Kecamatan"
|
|
||||||
style="@style/body_medium"
|
|
||||||
android:layout_marginEnd="4dp"/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/edt_subdistrict"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="@drawable/bg_text_field"
|
|
||||||
android:padding="8dp"
|
|
||||||
style="@style/body_small"
|
|
||||||
android:hint="Isi nama kecamatan di sini"
|
|
||||||
android:layout_marginTop="10dp"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<!-- Kode Pos -->
|
<!-- Kode Pos -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -301,7 +327,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_marginEnd="8dp">
|
android:layout_marginEnd="8dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -327,7 +354,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_marginStart="8dp">
|
android:layout_marginStart="8dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
tools:context=".ui.profile.mystore.product.DetailStoreProductActivity">
|
tools:context=".ui.profile.mystore.product.DetailStoreProductActivity">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/header"
|
android:id="@+id/headerStoreProduct"
|
||||||
layout="@layout/header" />
|
layout="@layout/header" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
@ -5,6 +5,257 @@
|
|||||||
android:id="@+id/main"
|
android:id="@+id/main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.order.address.EditAddressActivity">
|
android:background="@android:color/white"
|
||||||
|
tools:context=".ui.order.address.AddAddressActivity">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:navigationIcon="@drawable/ic_back_24"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:title="Ubah Alamat" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="#E0E0E0"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/buttonSimpan"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/divider">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Nama Penerima"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etNamaPenerima"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@drawable/edit_text_background"
|
||||||
|
android:hint="Isi nama penerima"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Nomor Hp"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etNomorHp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@drawable/edit_text_background"
|
||||||
|
android:hint="Isi nomor handphone aktif"
|
||||||
|
android:inputType="phone"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Detail Alamat"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etDetailAlamat"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@drawable/edit_text_background"
|
||||||
|
android:gravity="top"
|
||||||
|
android:hint="Isi detail alamat (nomor rumah, lantai, dll)"
|
||||||
|
android:inputType="textMultiLine"
|
||||||
|
android:lines="3"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<!-- Provinsi -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Provinsi"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:hint="Pilih Provinsi"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/autoCompleteProvinsi"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none"
|
||||||
|
android:focusable="false"
|
||||||
|
android:clickable="true"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Kabupaten / Kota -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Kabupaten / Kota"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:hint="Pilih Kota / Kabupaten"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/autoCompleteKabupaten"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none"
|
||||||
|
android:focusable="false"
|
||||||
|
android:clickable="true"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/cityProgressBar"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<!-- Kecamatan -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Kecamatan"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:hint="Pilih Kecamatan"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/autoCompleteKecamatan"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none"
|
||||||
|
android:focusable="false"
|
||||||
|
android:clickable="true"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Desa"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:hint="Pilih Desa"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/autoCompleteDesa"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none"
|
||||||
|
android:focusable="false"
|
||||||
|
android:clickable="true"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Kode Pos"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etKodePos"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@drawable/edit_text_background"
|
||||||
|
android:hint="Isi jawaban Anda di sini"
|
||||||
|
android:inputType="number"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonSimpan"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:background="@drawable/button_address_background"
|
||||||
|
android:text="Simpan"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="16sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/submitProgressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/buttonSimpan"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"/>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -98,7 +98,7 @@
|
|||||||
android:textAlignment="textEnd"
|
android:textAlignment="textEnd"
|
||||||
android:textColor="@android:color/holo_red_light"
|
android:textColor="@android:color/holo_red_light"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:visibility="gone"
|
android:layout_marginTop="8dp"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/til_login_password" />
|
app:layout_constraintTop_toBottomOf="@id/til_login_password" />
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
tools:context=".ui.profile.mystore.MyStoreActivity">
|
tools:context=".ui.profile.mystore.MyStoreActivity">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/header"
|
android:id="@+id/headerMyStore"
|
||||||
layout="@layout/header" />
|
layout="@layout/header" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
@ -422,6 +422,7 @@
|
|||||||
android:background="@color/black_50"/>
|
android:background="@color/black_50"/>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:visibility="gone"
|
||||||
android:id="@+id/layout_help"
|
android:id="@+id/layout_help"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/header"
|
android:id="@+id/headerListProduct"
|
||||||
layout="@layout/header" />
|
layout="@layout/header" />
|
||||||
|
|
||||||
<!-- Search Bar -->
|
<!-- Search Bar -->
|
||||||
|
@ -344,12 +344,6 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Kecamatan -->
|
<!-- Kecamatan -->
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_marginBottom="24dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -373,15 +367,37 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<EditText
|
<LinearLayout
|
||||||
android:id="@+id/et_subdistrict"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
android:background="@drawable/bg_text_field"
|
android:background="@drawable/bg_text_field"
|
||||||
android:hint="Isi kecamatan tempat toko Anda di sini"
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginTop="10dp">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spinner_subdistrict"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
style="@style/body_small"
|
style="@style/body_small"
|
||||||
android:layout_marginTop="10dp"/>
|
android:background="@null"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/subdistrict_progress_bar"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<!-- Chevron Down Icon -->
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:src="@drawable/ic_down"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:contentDescription="Chevron Down" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@ -503,7 +519,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_marginBottom="24dp">
|
android:layout_marginBottom="24dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -540,6 +557,74 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Nama Bank-->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_marginBottom="24dp">
|
||||||
|
|
||||||
|
<!-- Label Jenis UMKM -->
|
||||||
|
<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="10. Bank"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<!-- Spinner Dropdown dengan Chevron -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:background="@drawable/bg_text_field"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginTop="10dp">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spinner_bank_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="8dp"
|
||||||
|
style="@style/body_small"
|
||||||
|
android:background="@null"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/bank_name_progress_bar"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<!-- Chevron Down Icon -->
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:src="@drawable/ic_down"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:contentDescription="Chevron Down" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Nomor Rekening -->
|
<!-- Nomor Rekening -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -583,6 +668,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 +725,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 +778,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 +834,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 +901,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 +968,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 +1023,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 +1044,26 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/checkbox_approve"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Saya telah membaca dan menyetujui Syarat dan Ketentuan aplikasi" />
|
||||||
|
|
||||||
|
</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 +1075,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" />
|
||||||
|
47
app/src/main/res/layout/activity_reset_pass.xml
Normal file
47
app/src/main/res/layout/activity_reset_pass.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:gravity="top">
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/header_reset_pass"
|
||||||
|
layout="@layout/header" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Masukkan alamat email anda. Periksa email anda untuk mendapatkan password baru"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:layout_marginVertical="24dp"/>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/et_email"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Co: 123@gmail.com"
|
||||||
|
android:inputType="textEmailAddress" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_reset"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Kirim Password Baru"
|
||||||
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_bar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
39
app/src/main/res/layout/activity_store_suspended.xml
Normal file
39
app/src/main/res/layout/activity_store_suspended.xml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout 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.profile.mystore.StoreSuspendedActivity"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:fitsSystemWindows="true">
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/header"
|
||||||
|
layout="@layout/header" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:src="@drawable/ic_settings"
|
||||||
|
app:tint="@color/blue_500"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Toko Anda telah dinonaktifkan oleh Admin. Harap hubungi Admin untuk melakukan reaktivasi."
|
||||||
|
style="@style/body_large"
|
||||||
|
android:fontFamily="@font/dmsans_extrabold"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -14,18 +14,39 @@
|
|||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:layout_marginBottom="16dp" />
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="8dp"
|
android:orientation="horizontal"
|
||||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
android:background="@drawable/bg_text_field"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginTop="10dp">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<Spinner
|
||||||
android:id="@+id/edt_bank_name"
|
android:id="@+id/spinner_bank_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Nama Bank" />
|
android:layout_weight="1"
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
android:padding="8dp"
|
||||||
|
style="@style/body_small"
|
||||||
|
android:background="@null"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/bank_name_progress_bar"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<!-- Chevron Down Icon -->
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:src="@drawable/ic_down"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:contentDescription="Chevron Down" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -48,8 +48,8 @@
|
|||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:text="Keranjang Anda kosong"
|
android:text="Pesan anda kosong"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:textSize="18sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -245,6 +245,19 @@
|
|||||||
android:textColor="@color/blue1"
|
android:textColor="@color/blue1"
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/checkbox_approve"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Saya telah membaca dan menyetujui Syarat dan Ketentuan aplikasi" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<!-- Register Button -->
|
<!-- Register Button -->
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/baseline_edit_24"
|
android:src="@drawable/baseline_edit_24"
|
||||||
|
android:focusable="true"
|
||||||
|
android:clickable="true"
|
||||||
|
android:visibility="gone"
|
||||||
android:layout_marginHorizontal="16dp"
|
android:layout_marginHorizontal="16dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Bisa UMKM</string>
|
<string name="app_name">PasarKlik</string>
|
||||||
|
|
||||||
|
|
||||||
<!--Placeholder-->
|
<!--Placeholder-->
|
||||||
@ -146,5 +146,30 @@
|
|||||||
<string name="typing">User is typing...</string>
|
<string name="typing">User is typing...</string>
|
||||||
<string name="buka_toko_desc">Mohon untuk melengkapi formulir pendaftaran ini agar dapat mengakses fitur penjual pada aplikasi.</string>
|
<string name="buka_toko_desc">Mohon untuk melengkapi formulir pendaftaran ini agar dapat mengakses fitur penjual pada aplikasi.</string>
|
||||||
|
|
||||||
|
<!-- List Bank -->
|
||||||
|
<string-array name="bank_name_array">
|
||||||
|
<item>Allo Bank Indonesia</item>
|
||||||
|
<item>Bank Digital BCA</item>
|
||||||
|
<item>Bank Central Asia (BCA)</item>
|
||||||
|
<item>Bank BCA Syariah</item>
|
||||||
|
<item>Bank Jago</item>
|
||||||
|
<item>Bank Mandiri </item>
|
||||||
|
<item>Bank Kb Bukopi</item>
|
||||||
|
<item>Bank Jabar Banten Syariah</item>
|
||||||
|
<item> Bank Mandiri Taspen</item>
|
||||||
|
<item>Bank Maybank Indonesia </item>
|
||||||
|
<item>Bank Negara Indonesia (BNI)</item>
|
||||||
|
<item>Bank Permata</item>
|
||||||
|
<item>Bank Rakyat Indonesia (BRI)</item>
|
||||||
|
<item>Bank Saqu Indonesia</item>
|
||||||
|
<item>Bank Seabank Indonesia</item>
|
||||||
|
<item>Bank Sinarmas </item>
|
||||||
|
<item>Bank Syariah Indonesia (BSI)</item>
|
||||||
|
<item>Bank Tabungan Negara (BTN)</item>
|
||||||
|
<item>Bank UOB Indonesia</item>
|
||||||
|
<item>BPD Jawa Barat dan Banten</item>
|
||||||
|
<item>Super Bank Indonesia</item>
|
||||||
|
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Wed Oct 16 14:37:43 ICT 2024
|
#Wed Oct 16 14:37:43 ICT 2024
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
BIN
pasarKlik.apk
Normal file
BIN
pasarKlik.apk
Normal file
Binary file not shown.
BIN
unduh/bisaUMKM.apk
Normal file
BIN
unduh/bisaUMKM.apk
Normal file
Binary file not shown.
BIN
unduh/bisaUMKM_v1.apk
Normal file
BIN
unduh/bisaUMKM_v1.apk
Normal file
Binary file not shown.
BIN
unduh/bisaUMKM_v2.apk
Normal file
BIN
unduh/bisaUMKM_v2.apk
Normal file
Binary file not shown.
Reference in New Issue
Block a user