Integrated all shops apis into repository and viewmodel.
Created MVVM architecture for shop module.
This commit is contained in:
@@ -65,7 +65,7 @@
|
||||
android:exported="false"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".shop.MyOrdersActivity"
|
||||
android:name=".shop.views.MyOrdersActivity"
|
||||
android:exported="false"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
|
||||
@@ -9,15 +9,19 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp
|
||||
import com.woka.audiobooks.views.AudioBooksActivity
|
||||
import com.woka.databinding.FragmentHome2Binding
|
||||
import com.woka.home.viewmodels.HomeViewModel
|
||||
import com.woka.home.views.FMActivity
|
||||
import com.woka.karaoke.views.KaraokeActivity
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.players.views.LiveStreamPlayerActivity
|
||||
import com.woka.userPreference.UserType
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.show
|
||||
import com.woka.webseries.views.WebSeriesActivity
|
||||
import com.woka.wokagames.views.GamesActivity
|
||||
|
||||
class Home2Fragment : Fragment() {
|
||||
|
||||
@@ -96,6 +100,30 @@ class Home2Fragment : Fragment() {
|
||||
startActivity(Intent(it, FMActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
webSeries.setOnClickListener {
|
||||
activity?.let {
|
||||
startActivity(Intent(it, WebSeriesActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
audioBooks.setOnClickListener {
|
||||
activity?.let {
|
||||
startActivity(Intent(it, AudioBooksActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
playGames.setOnClickListener {
|
||||
activity?.let {
|
||||
startActivity(Intent(it, GamesActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
karaoke.setOnClickListener {
|
||||
activity?.let {
|
||||
startActivity(Intent(it, KaraokeActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,14 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.woka.R
|
||||
import com.woka.audiobooks.views.AudioBooksActivity
|
||||
import com.woka.databinding.ActivityExploreWokaBinding
|
||||
import com.woka.karaoke.views.KaraokeActivity
|
||||
import com.woka.players.views.LiveStreamPlayerActivity
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
import com.woka.utils.lightStatusBar
|
||||
import com.woka.webseries.views.WebSeriesActivity
|
||||
import com.woka.wokagames.views.GamesActivity
|
||||
|
||||
class ExploreWokaActivity : WokaBaseActivity() {
|
||||
|
||||
@@ -61,6 +65,22 @@ class ExploreWokaActivity : WokaBaseActivity() {
|
||||
startActivity(Intent(this@ExploreWokaActivity, FMActivity::class.java))
|
||||
}
|
||||
|
||||
webSeries.setOnClickListener {
|
||||
startActivity(Intent(this@ExploreWokaActivity, WebSeriesActivity::class.java))
|
||||
}
|
||||
|
||||
audioBooks.setOnClickListener {
|
||||
startActivity(Intent(this@ExploreWokaActivity, AudioBooksActivity::class.java))
|
||||
}
|
||||
|
||||
games.setOnClickListener {
|
||||
startActivity(Intent(this@ExploreWokaActivity, GamesActivity::class.java))
|
||||
}
|
||||
|
||||
karaoke.setOnClickListener {
|
||||
startActivity(Intent(this@ExploreWokaActivity, KaraokeActivity::class.java))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ import com.woka.onboard.views.OnboardActivity
|
||||
import com.woka.onboard.views.OnboardActivity.Companion.ADD_CHILD_INTENT
|
||||
import com.woka.onboard.views.OnboardActivity.Companion.LOG_IN_INTENT
|
||||
import com.woka.onboard.views.OnboardActivity.Companion.ONBOARD_ACTIVITY_INTENT
|
||||
import com.woka.shop.MyOrdersActivity
|
||||
import com.woka.shop.views.MyOrdersActivity
|
||||
import com.woka.utils.DecisionDialog
|
||||
import com.woka.utils.LOCALE_ENGLISH
|
||||
import com.woka.utils.LOCALE_HINDI
|
||||
|
||||
22
app/src/main/java/com/woka/shop/ShopApiService.kt
Normal file
22
app/src/main/java/com/woka/shop/ShopApiService.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.woka.shop
|
||||
|
||||
import com.woka.networking.ApiResponse
|
||||
import com.woka.shop.models.categorylisting.CategoryResponse
|
||||
import com.woka.shop.models.subcategorylisting.SubCategoryResponse
|
||||
import com.woka.shop.models.superlisting.SuperCategoryResponse
|
||||
import okhttp3.FormBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.POST
|
||||
|
||||
interface ShopApiService {
|
||||
|
||||
@POST("super_category_listing")
|
||||
suspend fun superCategoryListing(@Body formBody: FormBody): Response<ApiResponse<SuperCategoryResponse>>
|
||||
|
||||
@POST("category_listing")
|
||||
suspend fun categoryListing(@Body formBody: FormBody): Response<ApiResponse<CategoryResponse>>
|
||||
|
||||
@POST("sub_category_listing")
|
||||
suspend fun subcategoryListing(@Body formBody: FormBody): Response<ApiResponse<SubCategoryResponse>>
|
||||
}
|
||||
44
app/src/main/java/com/woka/shop/ShopRepository.kt
Normal file
44
app/src/main/java/com/woka/shop/ShopRepository.kt
Normal file
@@ -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<SuperCategoryResponse> {
|
||||
return handleApiCall{
|
||||
apiService.superCategoryListing(
|
||||
FormBody.Builder()
|
||||
.add("module_id", "5")
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun categoryListing(superCategoryId: String): ApiResult<CategoryResponse> {
|
||||
return handleApiCall{
|
||||
apiService.categoryListing(
|
||||
FormBody.Builder()
|
||||
.add("module_id", "5")
|
||||
.add("super_category_id", superCategoryId)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun subCategoryListing(categoryId: String): ApiResult<SubCategoryResponse> {
|
||||
return handleApiCall{
|
||||
apiService.subcategoryListing(
|
||||
FormBody.Builder()
|
||||
.add("category_id", categoryId)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.woka.shop.models.categorylisting
|
||||
|
||||
data class CategoryData(
|
||||
val category_name: String?,
|
||||
val category_thumbnail: String?,
|
||||
val id: Int?
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.woka.shop.models.categorylisting
|
||||
|
||||
data class CategoryResponse(
|
||||
val result: List<CategoryData?>?,
|
||||
val total_records: Int?
|
||||
)
|
||||
@@ -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?
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.woka.shop.models.subcategorylisting
|
||||
|
||||
data class SubCategoryResponse(
|
||||
val subCategory: List<SubCategoryData?>?,
|
||||
val total_records: Int?
|
||||
)
|
||||
@@ -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?
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.woka.shop.models.superlisting
|
||||
|
||||
data class SuperCategoryResponse(
|
||||
val result: List<SuperCategory?>?,
|
||||
val total_records: Int?
|
||||
)
|
||||
93
app/src/main/java/com/woka/shop/viewmodels/ShopViewModel.kt
Normal file
93
app/src/main/java/com/woka/shop/viewmodels/ShopViewModel.kt
Normal file
@@ -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<ApiResult<MutableList<SuperCategory>>>()
|
||||
val superCategoryLiveData: LiveData<ApiResult<MutableList<SuperCategory>>>
|
||||
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<ApiResult<MutableList<CategoryData>>>()
|
||||
val categoryLiveData: LiveData<ApiResult<MutableList<CategoryData>>>
|
||||
get() = _categoryLiveData
|
||||
|
||||
private val categoryDataMap = HashMap<String, MutableList<CategoryData>>()
|
||||
|
||||
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<ApiResult<MutableList<SubCategoryData>>>()
|
||||
val subcategoryLiveData: LiveData<ApiResult<MutableList<SubCategoryData>>>
|
||||
get() = _subcategoryLiveData
|
||||
|
||||
private val subcategoryDataMap = HashMap<String, MutableList<SubCategoryData>>()
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.woka.shop
|
||||
package com.woka.shop.views
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
@@ -85,6 +85,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/web_series"
|
||||
android:layout_width="@dimen/_180sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
@@ -115,6 +116,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/games"
|
||||
android:layout_width="@dimen/_180sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
@@ -145,6 +147,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/audio_books"
|
||||
android:layout_width="@dimen/_180sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
@@ -175,6 +178,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/blogs"
|
||||
android:layout_width="@dimen/_180sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
@@ -205,6 +209,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/karaoke"
|
||||
android:layout_width="@dimen/_180sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
@@ -235,6 +240,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/shop"
|
||||
android:layout_width="@dimen/_180sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#D3EFF8"
|
||||
tools:context=".shop.MyOrdersActivity">
|
||||
tools:context=".shop.views.MyOrdersActivity">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_btn"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="-15dp"
|
||||
tools:context=".shop.MyOrdersActivity">
|
||||
tools:context=".shop.views.MyOrdersActivity">
|
||||
|
||||
<LinearLayout android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user