Improve AppSales page & clearly indicate source
This commit is contained in:
@@ -23,14 +23,16 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.databinding.ActivityGenericRecyclerBinding
|
||||
import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener
|
||||
import com.aurora.store.view.epoxy.views.AppProgressViewModel_
|
||||
import com.aurora.store.view.epoxy.views.HeaderViewModel_
|
||||
import com.aurora.store.view.epoxy.views.app.AppListViewModel_
|
||||
import com.aurora.store.view.epoxy.views.app.NoAppViewModel_
|
||||
import com.aurora.store.view.epoxy.views.shimmer.AppListViewShimmerModel_
|
||||
import com.aurora.store.view.ui.commons.BaseFragment
|
||||
import com.aurora.store.viewmodel.all.PaginatedAppList
|
||||
import com.aurora.store.viewmodel.sale.AppSalesViewModel
|
||||
|
||||
|
||||
@@ -57,13 +59,13 @@ class AppSalesFragment : BaseFragment(R.layout.activity_generic_recycler) {
|
||||
|
||||
endlessRecyclerOnScrollListener = object : EndlessRecyclerOnScrollListener() {
|
||||
override fun onLoadMore(currentPage: Int) {
|
||||
VM.next()
|
||||
VM.observe()
|
||||
}
|
||||
}
|
||||
binding.recycler.addOnScrollListener(endlessRecyclerOnScrollListener)
|
||||
updateController(null)
|
||||
|
||||
VM.liveAppList.observe(viewLifecycleOwner) {
|
||||
VM.liveData.observe(viewLifecycleOwner) {
|
||||
updateController(it)
|
||||
}
|
||||
}
|
||||
@@ -73,11 +75,11 @@ class AppSalesFragment : BaseFragment(R.layout.activity_generic_recycler) {
|
||||
_binding = null
|
||||
}
|
||||
|
||||
private fun updateController(appList: List<App>?) {
|
||||
private fun updateController(paginatedAppList: PaginatedAppList?) {
|
||||
binding.recycler
|
||||
.withModels {
|
||||
setFilterDuplicates(true)
|
||||
if (appList == null) {
|
||||
if (paginatedAppList == null) {
|
||||
for (i in 1..6) {
|
||||
add(
|
||||
AppListViewShimmerModel_()
|
||||
@@ -85,7 +87,13 @@ class AppSalesFragment : BaseFragment(R.layout.activity_generic_recycler) {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
appList
|
||||
add(
|
||||
HeaderViewModel_()
|
||||
.id("header")
|
||||
.title(getString(R.string.title_apps_sale_provider))
|
||||
)
|
||||
|
||||
paginatedAppList.appList
|
||||
.filter { it.packageName.isNotEmpty() }
|
||||
.forEach {
|
||||
add(
|
||||
@@ -97,12 +105,21 @@ class AppSalesFragment : BaseFragment(R.layout.activity_generic_recycler) {
|
||||
setFilterDuplicates(true)
|
||||
}
|
||||
|
||||
if (appList.isNotEmpty()) {
|
||||
if (paginatedAppList.hasMore) {
|
||||
add(
|
||||
AppProgressViewModel_()
|
||||
.id("progress")
|
||||
)
|
||||
}
|
||||
|
||||
if (!paginatedAppList.hasMore && paginatedAppList.appList.isEmpty()) {
|
||||
add(
|
||||
NoAppViewModel_()
|
||||
.id("no_app_sale")
|
||||
.icon(R.drawable.ic_apps)
|
||||
.message(getString(R.string.details_no_apps_on_sale))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,52 +20,74 @@
|
||||
package com.aurora.store.viewmodel.sale
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.AppSalesHelper
|
||||
import com.aurora.store.data.RequestState
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.viewmodel.BaseAndroidViewModel
|
||||
import com.aurora.store.viewmodel.all.PaginatedAppList
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
|
||||
class AppSalesViewModel(application: Application) : AndroidViewModel(application) {
|
||||
class AppSalesViewModel(application: Application) : BaseAndroidViewModel(application) {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(application).getAuthData()
|
||||
private val appSalesHelper: AppSalesHelper =
|
||||
AppSalesHelper(authData).using(HttpClient.getPreferredClient())
|
||||
|
||||
val liveAppList: MutableLiveData<List<App>> = MutableLiveData()
|
||||
|
||||
private var page: Int = 0
|
||||
private val appList: MutableList<App> = mutableListOf()
|
||||
|
||||
val liveData: MutableLiveData<PaginatedAppList> = MutableLiveData()
|
||||
|
||||
init {
|
||||
observeAppSales()
|
||||
requestState = RequestState.Init
|
||||
observe()
|
||||
}
|
||||
|
||||
private fun observeAppSales() {
|
||||
appList.clear()
|
||||
override fun observe() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
appList.addAll(getSearchResults())
|
||||
liveAppList.postValue(appList)
|
||||
supervisorScope {
|
||||
requestState = try {
|
||||
val nextAppList = getSearchResults()
|
||||
|
||||
if (nextAppList.isEmpty()) {
|
||||
liveData.postValue(
|
||||
PaginatedAppList(
|
||||
appList,
|
||||
hasMore = false
|
||||
)
|
||||
)
|
||||
} else {
|
||||
appList.addAll(nextAppList)
|
||||
liveData.postValue(
|
||||
PaginatedAppList(
|
||||
appList,
|
||||
hasMore = true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
RequestState.Complete
|
||||
} catch (e: Exception) {
|
||||
RequestState.Pending
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSearchResults(
|
||||
): List<App> {
|
||||
return appSalesHelper.getAppsOnSale(page = page++, offer = 100)
|
||||
}
|
||||
|
||||
fun next() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val newAppList = getSearchResults()
|
||||
if (newAppList.isNotEmpty()) {
|
||||
appList.addAll(getSearchResults())
|
||||
liveAppList.postValue(appList)
|
||||
}
|
||||
return try {
|
||||
appSalesHelper.getAppsOnSale(page = page++, offer = 100)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
<string name="details_no_dependencies">"No Dependencies"</string>
|
||||
<string name="details_no_permission">"No permissions"</string>
|
||||
<string name="details_no_updates">"No updates available"</string>
|
||||
<string name="details_no_apps_on_sale">"No apps found on sale"</string>
|
||||
<string name="details_paid">"Paid"</string>
|
||||
<string name="details_permission">"Permission"</string>
|
||||
<string name="details_privacy">"Privacy"</string>
|
||||
@@ -281,6 +282,7 @@
|
||||
<string name="title_apps_games">"My apps & games"</string>
|
||||
<string name="title_apps_library">"Apps in library"</string>
|
||||
<string name="title_apps_sale">"Apps on sale"</string>
|
||||
<string name="title_apps_sale_provider">"Provider - bestappsales.com"</string>
|
||||
<string name="title_blacklist_manager">"Blacklist manager"</string>
|
||||
<string name="title_device">"Device"</string>
|
||||
<string name="title_download_manager">"Downloads"</string>
|
||||
|
||||
Reference in New Issue
Block a user