diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 29cffec..c75c7c6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -65,7 +65,7 @@ android:exported="false" android:screenOrientation="portrait" /> > + + @POST("category_listing") + suspend fun categoryListing(@Body formBody: FormBody): Response> + + @POST("sub_category_listing") + suspend fun subcategoryListing(@Body formBody: FormBody): Response> +} \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/ShopRepository.kt b/app/src/main/java/com/woka/shop/ShopRepository.kt new file mode 100644 index 0000000..58e09e2 --- /dev/null +++ b/app/src/main/java/com/woka/shop/ShopRepository.kt @@ -0,0 +1,44 @@ +package com.woka.shop + +import com.woka.networking.ApiResult +import com.woka.networking.RetrofitHelper +import com.woka.networking.RetrofitHelper.handleApiCall +import com.woka.shop.models.categorylisting.CategoryResponse +import com.woka.shop.models.subcategorylisting.SubCategoryResponse +import com.woka.shop.models.superlisting.SuperCategoryResponse +import okhttp3.FormBody + +object ShopRepository { + private val apiService = RetrofitHelper.getRetrofit().create(ShopApiService::class.java) + + suspend fun superCategoryListing(): ApiResult { + return handleApiCall{ + apiService.superCategoryListing( + FormBody.Builder() + .add("module_id", "5") + .build() + ) + } + } + + suspend fun categoryListing(superCategoryId: String): ApiResult { + return handleApiCall{ + apiService.categoryListing( + FormBody.Builder() + .add("module_id", "5") + .add("super_category_id", superCategoryId) + .build() + ) + } + } + + suspend fun subCategoryListing(categoryId: String): ApiResult { + return handleApiCall{ + apiService.subcategoryListing( + FormBody.Builder() + .add("category_id", categoryId) + .build() + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/models/categorylisting/CategoryData.kt b/app/src/main/java/com/woka/shop/models/categorylisting/CategoryData.kt new file mode 100644 index 0000000..01ab4d9 --- /dev/null +++ b/app/src/main/java/com/woka/shop/models/categorylisting/CategoryData.kt @@ -0,0 +1,7 @@ +package com.woka.shop.models.categorylisting + +data class CategoryData( + val category_name: String?, + val category_thumbnail: String?, + val id: Int? +) \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/models/categorylisting/CategoryResponse.kt b/app/src/main/java/com/woka/shop/models/categorylisting/CategoryResponse.kt new file mode 100644 index 0000000..e73b4d4 --- /dev/null +++ b/app/src/main/java/com/woka/shop/models/categorylisting/CategoryResponse.kt @@ -0,0 +1,6 @@ +package com.woka.shop.models.categorylisting + +data class CategoryResponse( + val result: List?, + val total_records: Int? +) \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/models/subcategorylisting/SubCategoryData.kt b/app/src/main/java/com/woka/shop/models/subcategorylisting/SubCategoryData.kt new file mode 100644 index 0000000..b0d5870 --- /dev/null +++ b/app/src/main/java/com/woka/shop/models/subcategorylisting/SubCategoryData.kt @@ -0,0 +1,8 @@ +package com.woka.shop.models.subcategorylisting + +data class SubCategoryData( + val category_master_id: Int?, + val id: Int?, + val sub_category_name: String?, + val sub_category_thumbnail: String? +) \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/models/subcategorylisting/SubCategoryResponse.kt b/app/src/main/java/com/woka/shop/models/subcategorylisting/SubCategoryResponse.kt new file mode 100644 index 0000000..e3f1a08 --- /dev/null +++ b/app/src/main/java/com/woka/shop/models/subcategorylisting/SubCategoryResponse.kt @@ -0,0 +1,6 @@ +package com.woka.shop.models.subcategorylisting + +data class SubCategoryResponse( + val subCategory: List?, + val total_records: Int? +) \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/models/superlisting/SuperCategory.kt b/app/src/main/java/com/woka/shop/models/superlisting/SuperCategory.kt new file mode 100644 index 0000000..4ced9bb --- /dev/null +++ b/app/src/main/java/com/woka/shop/models/superlisting/SuperCategory.kt @@ -0,0 +1,7 @@ +package com.woka.shop.models.superlisting + +data class SuperCategory( + val id: Int?, + val super_category_name: String?, + val super_category_thumbnail: String? +) \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/models/superlisting/SuperCategoryResponse.kt b/app/src/main/java/com/woka/shop/models/superlisting/SuperCategoryResponse.kt new file mode 100644 index 0000000..11b6e61 --- /dev/null +++ b/app/src/main/java/com/woka/shop/models/superlisting/SuperCategoryResponse.kt @@ -0,0 +1,6 @@ +package com.woka.shop.models.superlisting + +data class SuperCategoryResponse( + val result: List?, + val total_records: Int? +) \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/viewmodels/ShopViewModel.kt b/app/src/main/java/com/woka/shop/viewmodels/ShopViewModel.kt new file mode 100644 index 0000000..0d891d7 --- /dev/null +++ b/app/src/main/java/com/woka/shop/viewmodels/ShopViewModel.kt @@ -0,0 +1,93 @@ +package com.woka.shop.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.woka.networking.ApiResult +import com.woka.shop.ShopRepository +import com.woka.shop.models.categorylisting.CategoryData +import com.woka.shop.models.subcategorylisting.SubCategoryData +import com.woka.shop.models.superlisting.SuperCategory +import kotlinx.coroutines.launch + +class ShopViewModel: ViewModel() { + + private val repository = ShopRepository + + // super category listing + private val _superCategoryLiveData = MutableLiveData>>() + val superCategoryLiveData: LiveData>> + get() = _superCategoryLiveData + + fun loadSuperCategories(){ + viewModelScope.launch { + _superCategoryLiveData.postValue(ApiResult.Loading()) + when (val response = repository.superCategoryListing()){ + is ApiResult.Error -> _superCategoryLiveData.postValue(ApiResult.Error(response.errorMessage, response.error)) + is ApiResult.Loading -> {} + is ApiResult.Success -> { + response.data?.result?.filterNotNull()?.toMutableList()?.let { + _superCategoryLiveData.postValue(ApiResult.Success(it)) + } + } + } + } + } + + // category listing + private val _categoryLiveData = MutableLiveData>>() + val categoryLiveData: LiveData>> + get() = _categoryLiveData + + private val categoryDataMap = HashMap>() + + fun loadCategories(superCategoryId: String){ + if (categoryDataMap.containsKey(superCategoryId)){ + _categoryLiveData.postValue(ApiResult.Success(categoryDataMap[superCategoryId])) + return + } + + viewModelScope.launch { + _categoryLiveData.postValue(ApiResult.Loading()) + when (val response = repository.categoryListing(superCategoryId)){ + is ApiResult.Error -> _categoryLiveData.postValue(ApiResult.Error(response.errorMessage, response.error)) + is ApiResult.Loading -> {} + is ApiResult.Success -> { + response.data?.result?.filterNotNull()?.toMutableList()?.let { + categoryDataMap[superCategoryId] = it + _categoryLiveData.postValue(ApiResult.Success(it)) + } + } + } + } + } + + // sub category listing + private val _subcategoryLiveData = MutableLiveData>>() + val subcategoryLiveData: LiveData>> + get() = _subcategoryLiveData + + private val subcategoryDataMap = HashMap>() + + fun loadSubCategories(categoryId: String){ + if (subcategoryDataMap.containsKey(categoryId)){ + _subcategoryLiveData.postValue(ApiResult.Success(subcategoryDataMap[categoryId])) + return + } + + viewModelScope.launch { + _subcategoryLiveData.postValue(ApiResult.Loading()) + when (val response = repository.subCategoryListing(categoryId)){ + is ApiResult.Error -> _subcategoryLiveData.postValue(ApiResult.Error(response.errorMessage, response.error)) + is ApiResult.Loading -> {} + is ApiResult.Success -> { + response.data?.subCategory?.filterNotNull()?.toMutableList()?.let { + subcategoryDataMap[categoryId] = it + _subcategoryLiveData.postValue(ApiResult.Success(it)) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/woka/shop/MyOrdersActivity.kt b/app/src/main/java/com/woka/shop/views/MyOrdersActivity.kt similarity index 97% rename from app/src/main/java/com/woka/shop/MyOrdersActivity.kt rename to app/src/main/java/com/woka/shop/views/MyOrdersActivity.kt index 9184ab1..1940ead 100644 --- a/app/src/main/java/com/woka/shop/MyOrdersActivity.kt +++ b/app/src/main/java/com/woka/shop/views/MyOrdersActivity.kt @@ -1,4 +1,4 @@ -package com.woka.shop +package com.woka.shop.views import android.os.Bundle import androidx.activity.enableEdgeToEdge diff --git a/app/src/main/res/layout/activity_explore_woka.xml b/app/src/main/res/layout/activity_explore_woka.xml index c7a0249..a820053 100644 --- a/app/src/main/res/layout/activity_explore_woka.xml +++ b/app/src/main/res/layout/activity_explore_woka.xml @@ -85,6 +85,7 @@ + tools:context=".shop.views.MyOrdersActivity"> + tools:context=".shop.views.MyOrdersActivity">