Migrate CategoryBrowseActivity to fragment
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -109,7 +109,6 @@
|
|||||||
|
|
||||||
<activity android:name=".view.ui.commons.StreamBrowseActivity" />
|
<activity android:name=".view.ui.commons.StreamBrowseActivity" />
|
||||||
<activity android:name=".view.ui.details.ScreenshotActivity" />
|
<activity android:name=".view.ui.details.ScreenshotActivity" />
|
||||||
<activity android:name=".view.ui.commons.CategoryBrowseActivity" />
|
|
||||||
<activity android:name=".view.ui.details.DetailsMoreActivity" />
|
<activity android:name=".view.ui.details.DetailsMoreActivity" />
|
||||||
<activity android:name=".view.ui.details.DetailsReviewActivity" />
|
<activity android:name=".view.ui.details.DetailsReviewActivity" />
|
||||||
<activity android:name=".view.ui.account.GoogleActivity" />
|
<activity android:name=".view.ui.account.GoogleActivity" />
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package com.aurora.store.view.ui.commons
|
package com.aurora.store.view.ui.commons
|
||||||
|
|
||||||
import android.app.ActivityOptions
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
@@ -51,11 +50,12 @@ open class BaseFragment : Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun openCategoryBrowseActivity(category: Category) {
|
fun openCategoryBrowseActivity(category: Category) {
|
||||||
val intent = Intent(context, CategoryBrowseActivity::class.java)
|
findNavController().navigate(
|
||||||
intent.putExtra(Constants.STRING_EXTRA, category.title)
|
MobileNavigationDirections.actionGlobalCategoryBrowseFragment(
|
||||||
intent.putExtra(Constants.BROWSE_EXTRA, category.browseUrl)
|
category.title,
|
||||||
val options = ActivityOptions.makeSceneTransitionAnimation(requireActivity())
|
category.browseUrl
|
||||||
startActivity(intent, options.toBundle())
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openStreamBrowseActivity(browseUrl: String, title: String = "") {
|
fun openStreamBrowseActivity(browseUrl: String, title: String = "") {
|
||||||
|
|||||||
@@ -20,9 +20,11 @@
|
|||||||
package com.aurora.store.view.ui.commons
|
package com.aurora.store.view.ui.commons
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.aurora.Constants
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import androidx.navigation.fragment.navArgs
|
||||||
import com.aurora.gplayapi.data.models.App
|
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
|
||||||
@@ -36,78 +38,53 @@ import com.aurora.store.view.ui.sheets.AppPeekDialogSheet
|
|||||||
import com.aurora.store.viewmodel.subcategory.SubCategoryClusterViewModel
|
import com.aurora.store.viewmodel.subcategory.SubCategoryClusterViewModel
|
||||||
|
|
||||||
|
|
||||||
class CategoryBrowseActivity : BaseActivity(), GenericCarouselController.Callbacks {
|
class CategoryBrowseFragment : BaseFragment(R.layout.activity_generic_recycler),
|
||||||
|
GenericCarouselController.Callbacks {
|
||||||
|
|
||||||
|
private var _binding: ActivityGenericRecyclerBinding? = null
|
||||||
|
private val binding: ActivityGenericRecyclerBinding
|
||||||
|
get() = _binding!!
|
||||||
|
|
||||||
|
private val args: CategoryBrowseFragmentArgs by navArgs()
|
||||||
|
|
||||||
lateinit var B: ActivityGenericRecyclerBinding
|
|
||||||
lateinit var C: GenericCarouselController
|
lateinit var C: GenericCarouselController
|
||||||
lateinit var VM: SubCategoryClusterViewModel
|
lateinit var VM: SubCategoryClusterViewModel
|
||||||
|
|
||||||
lateinit var endlessRecyclerOnScrollListener: EndlessRecyclerOnScrollListener
|
lateinit var endlessRecyclerOnScrollListener: EndlessRecyclerOnScrollListener
|
||||||
|
|
||||||
lateinit var title: String
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
lateinit var homeUrl: String
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
override fun onConnected() {
|
_binding = ActivityGenericRecyclerBinding.bind(view)
|
||||||
hideNetworkConnectivitySheet()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDisconnected() {
|
|
||||||
showNetworkConnectivitySheet()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onReconnected() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
|
|
||||||
B = ActivityGenericRecyclerBinding.inflate(layoutInflater)
|
|
||||||
C = CategoryCarouselController(this)
|
C = CategoryCarouselController(this)
|
||||||
VM = ViewModelProvider(this)[SubCategoryClusterViewModel::class.java]
|
VM = ViewModelProvider(this)[SubCategoryClusterViewModel::class.java]
|
||||||
|
|
||||||
setContentView(B.root)
|
// Toolbar
|
||||||
|
binding.layoutToolbarAction.apply {
|
||||||
attachToolbar()
|
txtTitle.text = args.title
|
||||||
attachRecycler()
|
imgActionPrimary.setOnClickListener { findNavController().navigateUp() }
|
||||||
|
|
||||||
intent.apply {
|
|
||||||
homeUrl = getStringExtra(Constants.BROWSE_EXTRA).toString()
|
|
||||||
title = getStringExtra(Constants.STRING_EXTRA).toString()
|
|
||||||
VM.observeCategory(homeUrl)
|
|
||||||
updateTitle(title)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateController(null)
|
// RecyclerView
|
||||||
}
|
binding.recycler.setController(C)
|
||||||
|
|
||||||
private fun updateTitle(title: String) {
|
VM.liveData.observe(viewLifecycleOwner) {
|
||||||
B.layoutToolbarAction.txtTitle.text = title
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun attachToolbar() {
|
|
||||||
B.layoutToolbarAction.imgActionPrimary.setOnClickListener {
|
|
||||||
finishAfterTransition()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun attachRecycler() {
|
|
||||||
|
|
||||||
B.recycler.setController(C)
|
|
||||||
|
|
||||||
VM.liveData.observe(this) {
|
|
||||||
when (it) {
|
when (it) {
|
||||||
is ViewState.Empty -> {
|
is ViewState.Empty -> {
|
||||||
}
|
}
|
||||||
|
|
||||||
is ViewState.Loading -> {
|
is ViewState.Loading -> {
|
||||||
updateController(null)
|
updateController(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ViewState.Error -> {
|
is ViewState.Error -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is ViewState.Success<*> -> {
|
is ViewState.Success<*> -> {
|
||||||
updateController(it.data as StreamBundle)
|
updateController(it.data as StreamBundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,8 +97,15 @@ class CategoryBrowseActivity : BaseActivity(), GenericCarouselController.Callbac
|
|||||||
}
|
}
|
||||||
|
|
||||||
endlessRecyclerOnScrollListener.disable()
|
endlessRecyclerOnScrollListener.disable()
|
||||||
|
binding.recycler.addOnScrollListener(endlessRecyclerOnScrollListener)
|
||||||
|
|
||||||
B.recycler.addOnScrollListener(endlessRecyclerOnScrollListener)
|
VM.observeCategory(args.browseUrl)
|
||||||
|
updateController(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
_binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateController(streamBundle: StreamBundle?) {
|
private fun updateController(streamBundle: StreamBundle?) {
|
||||||
@@ -134,7 +118,11 @@ class CategoryBrowseActivity : BaseActivity(), GenericCarouselController.Callbac
|
|||||||
if (streamCluster.clusterBrowseUrl.isNotEmpty())
|
if (streamCluster.clusterBrowseUrl.isNotEmpty())
|
||||||
openStreamBrowseActivity(streamCluster.clusterBrowseUrl)
|
openStreamBrowseActivity(streamCluster.clusterBrowseUrl)
|
||||||
else
|
else
|
||||||
Toast.makeText(this, getString(R.string.toast_page_unavailable), Toast.LENGTH_SHORT)
|
Toast.makeText(
|
||||||
|
requireContext(),
|
||||||
|
getString(R.string.toast_page_unavailable),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +135,6 @@ class CategoryBrowseActivity : BaseActivity(), GenericCarouselController.Callbac
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onAppLongClick(app: App) {
|
override fun onAppLongClick(app: App) {
|
||||||
AppPeekDialogSheet.newInstance(app).show(supportFragmentManager, "APDS")
|
AppPeekDialogSheet.newInstance(app).show(childFragmentManager, "APDS")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/appDetailsFragment"
|
android:id="@+id/appDetailsFragment"
|
||||||
android:name="com.aurora.store.view.ui.details.AppDetailsFragment"
|
android:name="com.aurora.store.view.ui.details.AppDetailsFragment"
|
||||||
tools:layout="@layout/fragment_details" >
|
tools:layout="@layout/fragment_details">
|
||||||
<argument
|
<argument
|
||||||
android:name="packageName"
|
android:name="packageName"
|
||||||
app:argType="string" />
|
app:argType="string" />
|
||||||
@@ -109,7 +109,21 @@
|
|||||||
app:action="android.intent.action.VIEW"
|
app:action="android.intent.action.VIEW"
|
||||||
app:uri="play.google.com/store/apps/details?id={packageName}" />
|
app:uri="play.google.com/store/apps/details?id={packageName}" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/categoryBrowseFragment"
|
||||||
|
android:name="com.aurora.store.view.ui.commons.CategoryBrowseFragment"
|
||||||
|
tools:layout="@layout/activity_generic_recycler" >
|
||||||
|
<argument
|
||||||
|
android:name="title"
|
||||||
|
app:argType="string" />
|
||||||
|
<argument
|
||||||
|
android:name="browseUrl"
|
||||||
|
app:argType="string" />
|
||||||
|
</fragment>
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_global_appDetailsFragment"
|
android:id="@+id/action_global_appDetailsFragment"
|
||||||
app:destination="@id/appDetailsFragment" />
|
app:destination="@id/appDetailsFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_categoryBrowseFragment"
|
||||||
|
app:destination="@id/categoryBrowseFragment" />
|
||||||
</navigation>
|
</navigation>
|
||||||
|
|||||||
Reference in New Issue
Block a user