mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-16 11:42:16 -04:00
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.details.ScreenshotActivity" />
|
||||
<activity android:name=".view.ui.commons.CategoryBrowseActivity" />
|
||||
<activity android:name=".view.ui.details.DetailsMoreActivity" />
|
||||
<activity android:name=".view.ui.details.DetailsReviewActivity" />
|
||||
<activity android:name=".view.ui.account.GoogleActivity" />
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package com.aurora.store.view.ui.commons
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Intent
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -51,11 +50,12 @@ open class BaseFragment : Fragment {
|
||||
}
|
||||
|
||||
fun openCategoryBrowseActivity(category: Category) {
|
||||
val intent = Intent(context, CategoryBrowseActivity::class.java)
|
||||
intent.putExtra(Constants.STRING_EXTRA, category.title)
|
||||
intent.putExtra(Constants.BROWSE_EXTRA, category.browseUrl)
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(requireActivity())
|
||||
startActivity(intent, options.toBundle())
|
||||
findNavController().navigate(
|
||||
MobileNavigationDirections.actionGlobalCategoryBrowseFragment(
|
||||
category.title,
|
||||
category.browseUrl
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun openStreamBrowseActivity(browseUrl: String, title: String = "") {
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
package com.aurora.store.view.ui.commons
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
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.StreamBundle
|
||||
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
|
||||
|
||||
|
||||
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 VM: SubCategoryClusterViewModel
|
||||
|
||||
lateinit var endlessRecyclerOnScrollListener: EndlessRecyclerOnScrollListener
|
||||
|
||||
lateinit var title: String
|
||||
lateinit var homeUrl: String
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
override fun onConnected() {
|
||||
hideNetworkConnectivitySheet()
|
||||
}
|
||||
|
||||
override fun onDisconnected() {
|
||||
showNetworkConnectivitySheet()
|
||||
}
|
||||
|
||||
override fun onReconnected() {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
B = ActivityGenericRecyclerBinding.inflate(layoutInflater)
|
||||
_binding = ActivityGenericRecyclerBinding.bind(view)
|
||||
C = CategoryCarouselController(this)
|
||||
VM = ViewModelProvider(this)[SubCategoryClusterViewModel::class.java]
|
||||
|
||||
setContentView(B.root)
|
||||
|
||||
attachToolbar()
|
||||
attachRecycler()
|
||||
|
||||
intent.apply {
|
||||
homeUrl = getStringExtra(Constants.BROWSE_EXTRA).toString()
|
||||
title = getStringExtra(Constants.STRING_EXTRA).toString()
|
||||
VM.observeCategory(homeUrl)
|
||||
updateTitle(title)
|
||||
// Toolbar
|
||||
binding.layoutToolbarAction.apply {
|
||||
txtTitle.text = args.title
|
||||
imgActionPrimary.setOnClickListener { findNavController().navigateUp() }
|
||||
}
|
||||
|
||||
updateController(null)
|
||||
}
|
||||
// RecyclerView
|
||||
binding.recycler.setController(C)
|
||||
|
||||
private fun updateTitle(title: String) {
|
||||
B.layoutToolbarAction.txtTitle.text = title
|
||||
}
|
||||
|
||||
private fun attachToolbar() {
|
||||
B.layoutToolbarAction.imgActionPrimary.setOnClickListener {
|
||||
finishAfterTransition()
|
||||
}
|
||||
}
|
||||
|
||||
private fun attachRecycler() {
|
||||
|
||||
B.recycler.setController(C)
|
||||
|
||||
VM.liveData.observe(this) {
|
||||
VM.liveData.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is ViewState.Empty -> {
|
||||
}
|
||||
|
||||
is ViewState.Loading -> {
|
||||
updateController(null)
|
||||
}
|
||||
|
||||
is ViewState.Error -> {
|
||||
|
||||
}
|
||||
|
||||
is ViewState.Success<*> -> {
|
||||
updateController(it.data as StreamBundle)
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
@@ -120,8 +97,15 @@ class CategoryBrowseActivity : BaseActivity(), GenericCarouselController.Callbac
|
||||
}
|
||||
|
||||
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?) {
|
||||
@@ -134,7 +118,11 @@ class CategoryBrowseActivity : BaseActivity(), GenericCarouselController.Callbac
|
||||
if (streamCluster.clusterBrowseUrl.isNotEmpty())
|
||||
openStreamBrowseActivity(streamCluster.clusterBrowseUrl)
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -147,6 +135,6 @@ class CategoryBrowseActivity : BaseActivity(), GenericCarouselController.Callbac
|
||||
}
|
||||
|
||||
override fun onAppLongClick(app: App) {
|
||||
AppPeekDialogSheet.newInstance(app).show(supportFragmentManager, "APDS")
|
||||
AppPeekDialogSheet.newInstance(app).show(childFragmentManager, "APDS")
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@
|
||||
<fragment
|
||||
android:id="@+id/appDetailsFragment"
|
||||
android:name="com.aurora.store.view.ui.details.AppDetailsFragment"
|
||||
tools:layout="@layout/fragment_details" >
|
||||
tools:layout="@layout/fragment_details">
|
||||
<argument
|
||||
android:name="packageName"
|
||||
app:argType="string" />
|
||||
@@ -109,7 +109,21 @@
|
||||
app:action="android.intent.action.VIEW"
|
||||
app:uri="play.google.com/store/apps/details?id={packageName}" />
|
||||
</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
|
||||
android:id="@+id/action_global_appDetailsFragment"
|
||||
app:destination="@id/appDetailsFragment" />
|
||||
<action
|
||||
android:id="@+id/action_global_categoryBrowseFragment"
|
||||
app:destination="@id/categoryBrowseFragment" />
|
||||
</navigation>
|
||||
|
||||
Reference in New Issue
Block a user