Use WebCategoryStream helper to fetch bundles as default
This commit is contained in:
@@ -47,7 +47,7 @@ class CarouselModelGroup(
|
|||||||
val models = ArrayList<EpoxyModel<*>>()
|
val models = ArrayList<EpoxyModel<*>>()
|
||||||
val clusterViewModels = mutableListOf<EpoxyModel<*>>()
|
val clusterViewModels = mutableListOf<EpoxyModel<*>>()
|
||||||
|
|
||||||
val idPrefix = streamCluster.id
|
val idPrefix = streamCluster.clusterTitle.hashCode()
|
||||||
|
|
||||||
models.add(
|
models.add(
|
||||||
HeaderViewModel_()
|
HeaderViewModel_()
|
||||||
|
|||||||
@@ -28,20 +28,21 @@ import com.aurora.gplayapi.data.models.App
|
|||||||
import com.aurora.gplayapi.data.models.StreamBundle
|
import com.aurora.gplayapi.data.models.StreamBundle
|
||||||
import com.aurora.gplayapi.data.models.StreamCluster
|
import com.aurora.gplayapi.data.models.StreamCluster
|
||||||
import com.aurora.gplayapi.helpers.contracts.StreamContract
|
import com.aurora.gplayapi.helpers.contracts.StreamContract
|
||||||
|
import com.aurora.gplayapi.utils.CategoryUtil
|
||||||
import com.aurora.store.data.model.ViewState
|
import com.aurora.store.data.model.ViewState
|
||||||
import com.aurora.store.data.model.ViewState.Loading.getDataAs
|
import com.aurora.store.data.model.ViewState.Loading.getDataAs
|
||||||
import com.aurora.store.databinding.FragmentGenericWithToolbarBinding
|
import com.aurora.store.databinding.FragmentGenericWithToolbarBinding
|
||||||
import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener
|
import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener
|
||||||
import com.aurora.store.view.epoxy.controller.CategoryCarouselController
|
import com.aurora.store.view.epoxy.controller.CategoryCarouselController
|
||||||
import com.aurora.store.view.epoxy.controller.GenericCarouselController
|
import com.aurora.store.view.epoxy.controller.GenericCarouselController
|
||||||
import com.aurora.store.viewmodel.subcategory.SubCategoryClusterViewModel
|
import com.aurora.store.viewmodel.subcategory.CategoryStreamViewModel
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class CategoryBrowseFragment : BaseFragment<FragmentGenericWithToolbarBinding>(),
|
class CategoryBrowseFragment : BaseFragment<FragmentGenericWithToolbarBinding>(),
|
||||||
GenericCarouselController.Callbacks {
|
GenericCarouselController.Callbacks {
|
||||||
private val args: CategoryBrowseFragmentArgs by navArgs()
|
private val args: CategoryBrowseFragmentArgs by navArgs()
|
||||||
private val viewModel: SubCategoryClusterViewModel by activityViewModels()
|
private val viewModel: CategoryStreamViewModel by activityViewModels()
|
||||||
|
|
||||||
private lateinit var category: StreamContract.Category
|
private lateinit var category: StreamContract.Category
|
||||||
private var streamBundle: StreamBundle? = StreamBundle()
|
private var streamBundle: StreamBundle? = StreamBundle()
|
||||||
@@ -49,8 +50,7 @@ class CategoryBrowseFragment : BaseFragment<FragmentGenericWithToolbarBinding>()
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val rawCategory = args.browseUrl.split("/").last()
|
category = CategoryUtil.getCategoryFromUrl(args.browseUrl)
|
||||||
category = StreamContract.Category.NONE.apply { value = rawCategory }
|
|
||||||
|
|
||||||
val genericCarouselController = CategoryCarouselController(this)
|
val genericCarouselController = CategoryCarouselController(this)
|
||||||
|
|
||||||
@@ -68,6 +68,7 @@ class CategoryBrowseFragment : BaseFragment<FragmentGenericWithToolbarBinding>()
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewModel.getStreamBundle(category)
|
||||||
viewModel.liveData.observe(viewLifecycleOwner) {
|
viewModel.liveData.observe(viewLifecycleOwner) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is ViewState.Loading -> {
|
is ViewState.Loading -> {
|
||||||
@@ -84,8 +85,6 @@ class CategoryBrowseFragment : BaseFragment<FragmentGenericWithToolbarBinding>()
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.observe(category)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onHeaderClicked(streamCluster: StreamCluster) {
|
override fun onHeaderClicked(streamCluster: StreamCluster) {
|
||||||
|
|||||||
@@ -67,27 +67,18 @@ class ForYouFragment : BaseFragment<FragmentForYouBinding>(),
|
|||||||
pageType = bundle.getInt(Constants.PAGE_TYPE, 0)
|
pageType = bundle.getInt(Constants.PAGE_TYPE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (pageType) {
|
category = if (pageType == 0) Category.APPLICATION else Category.GAME
|
||||||
0 -> {
|
|
||||||
category = Category.APPLICATION
|
|
||||||
viewModel.getStreamBundle(category, Type.HOME)
|
|
||||||
}
|
|
||||||
|
|
||||||
1 -> {
|
|
||||||
category = Category.GAME
|
|
||||||
viewModel.getStreamBundle(category, Type.HOME)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.recycler.setController(genericCarouselController)
|
binding.recycler.setController(genericCarouselController)
|
||||||
binding.recycler.addOnScrollListener(
|
binding.recycler.addOnScrollListener(
|
||||||
object : EndlessRecyclerOnScrollListener() {
|
object : EndlessRecyclerOnScrollListener(visibleThreshold = 4) {
|
||||||
override fun onLoadMore(currentPage: Int) {
|
override fun onLoadMore(currentPage: Int) {
|
||||||
viewModel.observe(category, Type.HOME)
|
viewModel.observe(category, Type.HOME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
viewModel.getStreamBundle(category, Type.HOME)
|
||||||
viewModel.liveData.observe(viewLifecycleOwner) {
|
viewModel.liveData.observe(viewLifecycleOwner) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is ViewState.Loading -> {
|
is ViewState.Loading -> {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import com.aurora.gplayapi.data.models.Category
|
import com.aurora.gplayapi.data.models.Category
|
||||||
import com.aurora.gplayapi.helpers.CategoryHelper
|
import com.aurora.gplayapi.helpers.CategoryHelper
|
||||||
import com.aurora.gplayapi.helpers.contracts.CategoryContract
|
import com.aurora.gplayapi.helpers.contracts.CategoryContract
|
||||||
import com.aurora.gplayapi.helpers.web.WebCategoryHelper
|
|
||||||
import com.aurora.store.CategoryStash
|
import com.aurora.store.CategoryStash
|
||||||
import com.aurora.store.data.model.ViewState
|
import com.aurora.store.data.model.ViewState
|
||||||
import com.aurora.store.data.network.HttpClient
|
import com.aurora.store.data.network.HttpClient
|
||||||
@@ -50,9 +49,6 @@ class CategoryViewModel @Inject constructor(
|
|||||||
private val categoryHelper: CategoryHelper = CategoryHelper(authProvider.authData)
|
private val categoryHelper: CategoryHelper = CategoryHelper(authProvider.authData)
|
||||||
.using(HttpClient.getPreferredClient(context))
|
.using(HttpClient.getPreferredClient(context))
|
||||||
|
|
||||||
private val webCategoryHelper: CategoryContract = WebCategoryHelper()
|
|
||||||
.using(HttpClient.getPreferredClient(context))
|
|
||||||
|
|
||||||
private var stash: CategoryStash = mutableMapOf(
|
private var stash: CategoryStash = mutableMapOf(
|
||||||
Category.Type.APPLICATION to emptyList(),
|
Category.Type.APPLICATION to emptyList(),
|
||||||
Category.Type.GAME to emptyList()
|
Category.Type.GAME to emptyList()
|
||||||
@@ -61,11 +57,7 @@ class CategoryViewModel @Inject constructor(
|
|||||||
val liveData = MutableLiveData<ViewState>()
|
val liveData = MutableLiveData<ViewState>()
|
||||||
|
|
||||||
private fun contract(): CategoryContract {
|
private fun contract(): CategoryContract {
|
||||||
return if (authProvider.isAnonymous) {
|
return categoryHelper
|
||||||
webCategoryHelper
|
|
||||||
} else {
|
|
||||||
categoryHelper
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCategoryList(type: Category.Type) {
|
fun getCategoryList(type: Category.Type) {
|
||||||
@@ -74,10 +66,11 @@ class CategoryViewModel @Inject constructor(
|
|||||||
|
|
||||||
if (categories.isNotEmpty()) {
|
if (categories.isNotEmpty()) {
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stash[type] = contract().getAllCategoriesList(type)
|
stash[type] = contract().getAllCategories(type)
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Log.e(TAG, "Failed fetching list of categories", exception)
|
Log.e(TAG, "Failed fetching list of categories", exception)
|
||||||
|
|||||||
@@ -41,10 +41,11 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||||
class StreamViewModel @Inject constructor(@ApplicationContext private val context: Context) :
|
class StreamViewModel @Inject constructor(
|
||||||
ViewModel() {
|
@ApplicationContext private val context: Context
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
private var webStreamHelper: StreamContract = WebStreamHelper()
|
private var webStreamHelper = WebStreamHelper()
|
||||||
.using(HttpClient.getPreferredClient(context))
|
.using(HttpClient.getPreferredClient(context))
|
||||||
|
|
||||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||||
@@ -64,7 +65,7 @@ class StreamViewModel @Inject constructor(@ApplicationContext private val contex
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
val bundle = targetBundle(category)
|
val bundle = targetBundle(category)
|
||||||
if (bundle.streamClusters.isNotEmpty()) {
|
if (bundle.hasCluster()) {
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,13 +73,13 @@ class StreamViewModel @Inject constructor(@ApplicationContext private val contex
|
|||||||
if (!bundle.hasCluster() || bundle.hasNext()) {
|
if (!bundle.hasCluster() || bundle.hasNext()) {
|
||||||
|
|
||||||
//Fetch new stream bundle
|
//Fetch new stream bundle
|
||||||
val newBundle = if (bundle.streamClusters.isEmpty()) {
|
val newBundle = if (bundle.hasCluster()) {
|
||||||
contract().fetch(type, category)
|
|
||||||
} else {
|
|
||||||
contract().nextStreamBundle(
|
contract().nextStreamBundle(
|
||||||
category,
|
category,
|
||||||
bundle.streamNextPageUrl
|
bundle.streamNextPageUrl
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
contract().fetch(type, category)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update old bundle
|
//Update old bundle
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.aurora.gplayapi.data.models.StreamBundle
|
import com.aurora.gplayapi.data.models.StreamBundle
|
||||||
import com.aurora.gplayapi.data.models.StreamCluster
|
import com.aurora.gplayapi.data.models.StreamCluster
|
||||||
|
import com.aurora.gplayapi.helpers.contracts.CategoryStreamContract
|
||||||
import com.aurora.gplayapi.helpers.contracts.StreamContract
|
import com.aurora.gplayapi.helpers.contracts.StreamContract
|
||||||
import com.aurora.gplayapi.helpers.web.WebStreamHelper
|
import com.aurora.gplayapi.helpers.web.WebCategoryStreamHelper
|
||||||
import com.aurora.store.data.model.ViewState
|
import com.aurora.store.data.model.ViewState
|
||||||
import com.aurora.store.data.network.HttpClient
|
import com.aurora.store.data.network.HttpClient
|
||||||
import com.aurora.store.util.Log
|
import com.aurora.store.util.Log
|
||||||
@@ -40,24 +41,24 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||||
class SubCategoryClusterViewModel @Inject constructor(@ApplicationContext private val context: Context) :
|
class CategoryStreamViewModel @Inject constructor(
|
||||||
ViewModel() {
|
@ApplicationContext private val context: Context
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
var contract: StreamContract = WebStreamHelper()
|
private var webCategoryStreamHelper = WebCategoryStreamHelper()
|
||||||
.using(HttpClient.getPreferredClient(context))
|
.using(HttpClient.getPreferredClient(context))
|
||||||
|
|
||||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||||
|
|
||||||
private var stash: MutableMap<String, StreamBundle> = mutableMapOf()
|
private var stash: MutableMap<String, StreamBundle> = mutableMapOf()
|
||||||
|
|
||||||
private fun getCategoryStreamBundle(
|
fun contract(): CategoryStreamContract {
|
||||||
category: StreamContract.Category,
|
return webCategoryStreamHelper
|
||||||
nextPageUrl: String
|
}
|
||||||
): StreamBundle {
|
|
||||||
return if (targetBundle(category).streamClusters.isEmpty())
|
fun getStreamBundle(category: StreamContract.Category) {
|
||||||
contract.fetch(StreamContract.Type.HOME, category)
|
liveData.postValue(ViewState.Loading)
|
||||||
else
|
observe(category)
|
||||||
contract.nextStreamBundle(category, nextPageUrl)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observe(category: StreamContract.Category) {
|
fun observe(category: StreamContract.Category) {
|
||||||
@@ -65,18 +66,22 @@ class SubCategoryClusterViewModel @Inject constructor(@ApplicationContext privat
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
val bundle = targetBundle(category)
|
val bundle = targetBundle(category)
|
||||||
|
|
||||||
if (bundle.streamClusters.isNotEmpty()) {
|
if (bundle.streamClusters.isNotEmpty()) {
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!bundle.hasCluster() || bundle.hasNext()) {
|
if (!bundle.hasCluster() || bundle.hasNext()) {
|
||||||
|
|
||||||
//Fetch new stream bundle
|
//Fetch new stream bundle
|
||||||
val newBundle = getCategoryStreamBundle(
|
val newBundle = if (bundle.streamClusters.isEmpty()) {
|
||||||
category,
|
contract().fetch(category.value)
|
||||||
bundle.streamNextPageUrl
|
} else {
|
||||||
)
|
contract().nextStreamBundle(
|
||||||
|
category,
|
||||||
|
bundle.streamNextPageUrl
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
//Update old bundle
|
//Update old bundle
|
||||||
bundle.apply {
|
bundle.apply {
|
||||||
@@ -102,7 +107,7 @@ class SubCategoryClusterViewModel @Inject constructor(@ApplicationContext privat
|
|||||||
try {
|
try {
|
||||||
if (streamCluster.hasNext()) {
|
if (streamCluster.hasNext()) {
|
||||||
val newCluster =
|
val newCluster =
|
||||||
contract.nextStreamCluster(streamCluster.clusterNextPageUrl)
|
contract().nextStreamCluster(streamCluster.clusterNextPageUrl)
|
||||||
updateCluster(category, streamCluster.id, newCluster)
|
updateCluster(category, streamCluster.id, newCluster)
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
} else {
|
} else {
|
||||||
@@ -7,7 +7,7 @@ composeBom = "2024.06.00"
|
|||||||
coreVersion = "1.13.1"
|
coreVersion = "1.13.1"
|
||||||
epoxyVersion = "5.1.4"
|
epoxyVersion = "5.1.4"
|
||||||
espressoVersion = "3.6.1"
|
espressoVersion = "3.6.1"
|
||||||
gplayapiVersion = "3.3.0"
|
gplayapiVersion = "3.3.1"
|
||||||
gsonVersion = "2.10.1"
|
gsonVersion = "2.10.1"
|
||||||
hiddenapibypassVersion = "4.3"
|
hiddenapibypassVersion = "4.3"
|
||||||
hiltVersion = "2.51.1"
|
hiltVersion = "2.51.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user