Improve editors choice stream
This commit is contained in:
@@ -24,6 +24,7 @@ import com.aurora.gplayapi.data.models.editor.EditorChoiceBundle
|
||||
import com.aurora.gplayapi.data.models.editor.EditorChoiceCluster
|
||||
import com.aurora.store.view.epoxy.groups.EditorChoiceModelGroup
|
||||
import com.aurora.store.view.epoxy.views.EditorHeadViewModel_
|
||||
import com.aurora.store.view.epoxy.views.HeaderViewModel_
|
||||
|
||||
class EditorChoiceController(private val callbacks: Callbacks) :
|
||||
TypedEpoxyController<List<EditorChoiceBundle>>() {
|
||||
@@ -37,7 +38,7 @@ class EditorChoiceController(private val callbacks: Callbacks) :
|
||||
val idPrefix = editorChoiceBundle.id
|
||||
|
||||
add(
|
||||
EditorHeadViewModel_()
|
||||
HeaderViewModel_()
|
||||
.id("header_${idPrefix}")
|
||||
.title(editorChoiceBundle.bundleTitle)
|
||||
)
|
||||
|
||||
@@ -24,8 +24,8 @@ import com.airbnb.epoxy.EpoxyModelGroup
|
||||
import com.aurora.gplayapi.data.models.editor.EditorChoiceCluster
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.view.epoxy.controller.EditorChoiceController
|
||||
import com.aurora.store.view.epoxy.views.EditorHeadViewModel_
|
||||
import com.aurora.store.view.epoxy.views.EditorImageViewModel_
|
||||
import com.aurora.store.view.epoxy.views.HeaderViewModel_
|
||||
|
||||
class EditorChoiceModelGroup(
|
||||
editorChoiceCluster: EditorChoiceCluster,
|
||||
@@ -49,11 +49,9 @@ class EditorChoiceModelGroup(
|
||||
val idPrefix = editorChoiceCluster.id
|
||||
|
||||
models.add(
|
||||
HeaderViewModel_()
|
||||
EditorHeadViewModel_()
|
||||
.id("header_${idPrefix}")
|
||||
.title(editorChoiceCluster.clusterTitle)
|
||||
.browseUrl(editorChoiceCluster.clusterBrowseUrl)
|
||||
.click { _ -> callbacks.onClick(editorChoiceCluster) }
|
||||
)
|
||||
|
||||
editorChoiceCluster.clusterArtwork.forEach {
|
||||
@@ -61,6 +59,8 @@ class EditorChoiceModelGroup(
|
||||
EditorImageViewModel_()
|
||||
.id("artwork_${idPrefix}")
|
||||
.artwork(it)
|
||||
.click { _ -> callbacks.onClick(editorChoiceCluster) }
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.aurora.store.view.epoxy.views
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import com.airbnb.epoxy.CallbackProp
|
||||
import com.airbnb.epoxy.ModelProp
|
||||
import com.airbnb.epoxy.ModelView
|
||||
import com.airbnb.epoxy.OnViewRecycled
|
||||
@@ -83,6 +84,11 @@ class EditorImageView : RelativeLayout {
|
||||
}
|
||||
}
|
||||
|
||||
@CallbackProp
|
||||
fun click(onClickListener: OnClickListener?) {
|
||||
B.root.setOnClickListener(onClickListener)
|
||||
}
|
||||
|
||||
@OnViewRecycled
|
||||
fun clear() {
|
||||
B.img.clear()
|
||||
|
||||
@@ -79,4 +79,14 @@ open class BaseFragment : Fragment() {
|
||||
ViewUtil.getEmptyActivityBundle(requireContext())
|
||||
)
|
||||
}
|
||||
|
||||
fun openEditorStreamBrowseActivity(browseUrl: String, title: String = "") {
|
||||
val intent = Intent(requireContext(), EditorStreamBrowseActivity::class.java)
|
||||
intent.putExtra(Constants.BROWSE_EXTRA, browseUrl)
|
||||
intent.putExtra(Constants.STRING_EXTRA, title)
|
||||
startActivity(
|
||||
intent,
|
||||
ViewUtil.getEmptyActivityBundle(requireContext())
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.editor.EditorChoiceBundle
|
||||
@@ -35,7 +34,7 @@ import com.aurora.store.viewmodel.editorschoice.AppEditorChoiceViewModel
|
||||
import com.aurora.store.viewmodel.editorschoice.BaseEditorChoiceViewModel
|
||||
import com.aurora.store.viewmodel.editorschoice.GameEditorChoiceViewModel
|
||||
|
||||
class EditorChoiceFragment : Fragment(), EditorChoiceController.Callbacks {
|
||||
class EditorChoiceFragment : BaseFragment(), EditorChoiceController.Callbacks {
|
||||
|
||||
private lateinit var B: FragmentForYouBinding
|
||||
private lateinit var C: EditorChoiceController
|
||||
@@ -97,6 +96,9 @@ class EditorChoiceFragment : Fragment(), EditorChoiceController.Callbacks {
|
||||
}
|
||||
|
||||
override fun onClick(editorChoiceCluster: EditorChoiceCluster) {
|
||||
|
||||
openEditorStreamBrowseActivity(
|
||||
editorChoiceCluster.clusterBrowseUrl,
|
||||
editorChoiceCluster.clusterTitle
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.commons
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.databinding.ActivityGenericRecyclerBinding
|
||||
import com.aurora.store.util.extensions.close
|
||||
import com.aurora.store.view.epoxy.views.app.AppListViewModel_
|
||||
import com.aurora.store.view.epoxy.views.shimmer.AppListViewShimmerModel_
|
||||
import com.aurora.store.viewmodel.editorschoice.EditorBrowseViewModel
|
||||
|
||||
|
||||
class EditorStreamBrowseActivity : BaseActivity() {
|
||||
|
||||
lateinit var B: ActivityGenericRecyclerBinding
|
||||
lateinit var VM: EditorBrowseViewModel
|
||||
lateinit var title: String
|
||||
|
||||
override fun onConnected() {
|
||||
hideNetworkConnectivitySheet()
|
||||
}
|
||||
|
||||
override fun onDisconnected() {
|
||||
showNetworkConnectivitySheet()
|
||||
}
|
||||
|
||||
override fun onReconnected() {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
B = ActivityGenericRecyclerBinding.inflate(layoutInflater)
|
||||
VM = ViewModelProvider(this).get(EditorBrowseViewModel::class.java)
|
||||
|
||||
setContentView(B.root)
|
||||
|
||||
attachToolbar()
|
||||
|
||||
VM.liveData.observe(this, {
|
||||
updateController(it)
|
||||
})
|
||||
|
||||
intent.apply {
|
||||
getStringExtra(Constants.BROWSE_EXTRA)?.let {
|
||||
VM.getEditorStreamBundle(it)
|
||||
}
|
||||
getStringExtra(Constants.STRING_EXTRA)?.let {
|
||||
B.layoutToolbarAction.txtTitle.text = it
|
||||
}
|
||||
}
|
||||
|
||||
updateController(null)
|
||||
}
|
||||
|
||||
private fun attachToolbar() {
|
||||
B.layoutToolbarAction.imgActionPrimary.setOnClickListener {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateController(appList: MutableList<App>?) {
|
||||
B.recycler.withModels {
|
||||
setFilterDuplicates(true)
|
||||
if (appList == null) {
|
||||
for (i in 1..6) {
|
||||
add(
|
||||
AppListViewShimmerModel_()
|
||||
.id(i)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
appList.forEach {
|
||||
|
||||
add(
|
||||
AppListViewModel_()
|
||||
.id(it.packageName.hashCode())
|
||||
.app(it)
|
||||
.click { _ -> openDetailsActivity(it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.viewmodel.editorschoice
|
||||
|
||||
import android.app.Application
|
||||
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.StreamHelper
|
||||
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 kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
|
||||
class EditorBrowseViewModel(application: Application) : BaseAndroidViewModel(application) {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(application).getAuthData()
|
||||
private val streamHelper: StreamHelper = StreamHelper(authData)
|
||||
.using(HttpClient.getPreferredClient())
|
||||
|
||||
val liveData: MutableLiveData<MutableList<App>> = MutableLiveData()
|
||||
val appList: MutableList<App> = mutableListOf()
|
||||
|
||||
override fun observe() {
|
||||
requestState = RequestState.Init
|
||||
}
|
||||
|
||||
fun getEditorStreamBundle(
|
||||
browseUrl: String
|
||||
) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
supervisorScope {
|
||||
try {
|
||||
|
||||
requestState = RequestState.Init
|
||||
|
||||
val browseResponse = streamHelper.getBrowseStreamResponse(browseUrl)
|
||||
val listResponse =
|
||||
streamHelper.getNextStreamResponse(browseResponse.browseTab.listUrl)
|
||||
|
||||
listResponse.itemList.forEach {
|
||||
it?.let{
|
||||
it.subItemList.forEach {
|
||||
appList.addAll(streamHelper.getAppsFromItem(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
liveData.postValue(appList)
|
||||
requestState = RequestState.Complete
|
||||
|
||||
} catch (e: Exception) {
|
||||
requestState = RequestState.Pending
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user