Fix top charts issue
This commit is contained in:
@@ -35,6 +35,7 @@ import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.view.ui.commons.CategoryFragment
|
||||
import com.aurora.store.view.ui.commons.EditorChoiceFragment
|
||||
import com.aurora.store.view.ui.commons.ForYouFragment
|
||||
import com.aurora.store.view.ui.commons.TopChartContainerFragment
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
|
||||
@@ -112,8 +113,7 @@ class AppsContainerFragment : Fragment() {
|
||||
if (isForYouEnabled) {
|
||||
add(ForYouFragment.newInstance(0))
|
||||
}
|
||||
|
||||
add(TopChartContainerFragment())
|
||||
add(TopChartContainerFragment.newInstance(0))
|
||||
add(CategoryFragment.newInstance(0))
|
||||
|
||||
if (isGoogleAccount) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.apps
|
||||
package com.aurora.store.view.ui.commons
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
@@ -28,6 +28,7 @@ import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
@@ -41,6 +42,19 @@ class TopChartContainerFragment : Fragment() {
|
||||
|
||||
private lateinit var authData: AuthData
|
||||
|
||||
private var chartType = 0
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance(chartType: Int): TopChartContainerFragment {
|
||||
return TopChartContainerFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putInt(Constants.TOP_CHART_TYPE, chartType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -53,6 +67,12 @@ class TopChartContainerFragment : Fragment() {
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
val bundle = arguments
|
||||
if (bundle != null) {
|
||||
chartType = bundle.getInt(Constants.TOP_CHART_TYPE, 0)
|
||||
}
|
||||
|
||||
return B.root
|
||||
}
|
||||
|
||||
@@ -63,7 +83,7 @@ class TopChartContainerFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun setupViewPager() {
|
||||
B.pager.adapter = ViewPagerAdapter(childFragmentManager, lifecycle)
|
||||
B.pager.adapter = ViewPagerAdapter(childFragmentManager, lifecycle, chartType)
|
||||
B.topTabGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||
when (checkedId) {
|
||||
R.id.tab_top_free -> B.pager.setCurrentItem(0, true)
|
||||
@@ -86,13 +106,17 @@ class TopChartContainerFragment : Fragment() {
|
||||
})
|
||||
}
|
||||
|
||||
internal class ViewPagerAdapter(fragment: FragmentManager, lifecycle: Lifecycle) :
|
||||
internal class ViewPagerAdapter(
|
||||
fragment: FragmentManager,
|
||||
lifecycle: Lifecycle,
|
||||
chartType: Int
|
||||
) :
|
||||
FragmentStateAdapter(fragment, lifecycle) {
|
||||
private val tabFragments: MutableList<TopChartFragment> = mutableListOf(
|
||||
TopChartFragment.newInstance(0, 0),
|
||||
TopChartFragment.newInstance(0, 1),
|
||||
TopChartFragment.newInstance(0, 2),
|
||||
TopChartFragment.newInstance(0, 3)
|
||||
TopChartFragment.newInstance(chartType, 0),
|
||||
TopChartFragment.newInstance(chartType, 1),
|
||||
TopChartFragment.newInstance(chartType, 2),
|
||||
TopChartFragment.newInstance(chartType, 3)
|
||||
)
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
@@ -35,6 +35,7 @@ import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.view.ui.commons.CategoryFragment
|
||||
import com.aurora.store.view.ui.commons.EditorChoiceFragment
|
||||
import com.aurora.store.view.ui.commons.ForYouFragment
|
||||
import com.aurora.store.view.ui.commons.TopChartContainerFragment
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
|
||||
@@ -112,7 +113,7 @@ class GamesContainerFragment : Fragment() {
|
||||
add(ForYouFragment.newInstance(1))
|
||||
}
|
||||
|
||||
add(TopChartContainerFragment())
|
||||
add(TopChartContainerFragment.newInstance(1))
|
||||
add(CategoryFragment.newInstance(1))
|
||||
|
||||
if (isGoogleAccount) {
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* 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.games
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.databinding.FragmentTopChartBinding
|
||||
|
||||
|
||||
class TopChartContainerFragment : Fragment() {
|
||||
|
||||
private lateinit var B: FragmentTopChartBinding
|
||||
|
||||
private lateinit var authData: AuthData
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
B = FragmentTopChartBinding.bind(
|
||||
inflater.inflate(
|
||||
R.layout.fragment_top_chart,
|
||||
container,
|
||||
false
|
||||
)
|
||||
)
|
||||
return B.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
authData = AuthProvider.with(requireContext()).getAuthData()
|
||||
setupViewPager()
|
||||
}
|
||||
|
||||
private fun setupViewPager() {
|
||||
B.pager.adapter = ViewPagerAdapter(childFragmentManager, lifecycle)
|
||||
B.topTabGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||
when (checkedId) {
|
||||
R.id.tab_top_free -> B.pager.setCurrentItem(0, true)
|
||||
R.id.tab_top_grossing -> B.pager.setCurrentItem(1, true)
|
||||
R.id.tab_trending -> B.pager.setCurrentItem(2, true)
|
||||
R.id.tab_top_paid -> B.pager.setCurrentItem(3, true)
|
||||
}
|
||||
}
|
||||
|
||||
B.pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
super.onPageSelected(position)
|
||||
when (position) {
|
||||
0 -> B.topTabGroup.check(R.id.tab_top_free)
|
||||
1 -> B.topTabGroup.check(R.id.tab_top_grossing)
|
||||
2 -> B.topTabGroup.check(R.id.tab_trending)
|
||||
3 -> B.topTabGroup.check(R.id.tab_top_paid)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
internal class ViewPagerAdapter(fragment: FragmentManager, lifecycle: Lifecycle) :
|
||||
FragmentStateAdapter(fragment, lifecycle) {
|
||||
|
||||
private val tabFragments: MutableList<TopChartFragment> = mutableListOf(
|
||||
TopChartFragment.newInstance(1, 0),
|
||||
TopChartFragment.newInstance(1, 1),
|
||||
TopChartFragment.newInstance(1, 2),
|
||||
TopChartFragment.newInstance(1, 3)
|
||||
)
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return tabFragments[position]
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return tabFragments.size
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,8 @@ import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.databinding.FragmentTopContainerBinding
|
||||
import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener
|
||||
import com.aurora.store.view.epoxy.views.app.AppListViewModel_
|
||||
import com.aurora.store.view.epoxy.views.AppProgressViewModel_
|
||||
import com.aurora.store.view.epoxy.views.app.AppListViewModel_
|
||||
import com.aurora.store.view.epoxy.views.shimmer.AppListViewShimmerModel_
|
||||
import com.aurora.store.view.ui.commons.BaseFragment
|
||||
import com.aurora.store.viewmodel.topchart.*
|
||||
@@ -40,7 +40,7 @@ class TopChartFragment : BaseFragment() {
|
||||
private lateinit var VM: BaseChartViewModel
|
||||
private lateinit var B: FragmentTopContainerBinding
|
||||
|
||||
private var chartType = 1
|
||||
private var chartType = 0
|
||||
private var chartCategory = 0
|
||||
|
||||
companion object {
|
||||
@@ -74,17 +74,32 @@ class TopChartFragment : BaseFragment() {
|
||||
chartCategory = bundle.getInt(Constants.TOP_CHART_CATEGORY, 0)
|
||||
}
|
||||
|
||||
when (chartCategory) {
|
||||
0 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopFreeGameChartViewModel::class.java)
|
||||
1 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopGrossingGameChartViewModel::class.java)
|
||||
2 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TrendingGameChartViewModel::class.java)
|
||||
3 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopPaidGameChartViewModel::class.java)
|
||||
when (chartType) {
|
||||
0 -> when (chartCategory) {
|
||||
0 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopFreeAppChartViewModel::class.java)
|
||||
1 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopGrossingAppChartViewModel::class.java)
|
||||
2 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TrendingAppChartViewModel::class.java)
|
||||
3 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopPaidAppChartViewModel::class.java)
|
||||
}
|
||||
|
||||
1 -> when (chartCategory) {
|
||||
0 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopFreeGameChartViewModel::class.java)
|
||||
1 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopGrossingGameChartViewModel::class.java)
|
||||
2 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TrendingGameChartViewModel::class.java)
|
||||
3 -> VM =
|
||||
ViewModelProvider(requireActivity()).get(TopPaidGameChartViewModel::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return B.root
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user