From 588a1f9edf94fffbe4dfdef4413626b0325d0fa7 Mon Sep 17 00:00:00 2001 From: Rahul Patel Date: Fri, 12 Jul 2024 21:42:05 +0530 Subject: [PATCH] Remove non-functional pages - EditorChoise, Library, PurchaseHistory - Will adapt GPlayApi to new API & re-implement --- .../store/data/model/PaginatedAppList.kt | 8 + .../store/view/ui/all/AppsGamesFragment.kt | 6 +- .../store/view/ui/all/LibraryAppsFragment.kt | 106 ------------- .../view/ui/all/PurchasedAppsFragment.kt | 98 ------------ .../view/ui/apps/AppsContainerFragment.kt | 9 -- .../view/ui/commons/EditorChoiceFragment.kt | 77 ---------- .../ui/commons/EditorStreamBrowseFragment.kt | 139 ------------------ .../view/ui/games/GamesContainerFragment.kt | 9 -- .../store/view/ui/sale/AppSalesFragment.kt | 2 +- .../viewmodel/all/LibraryAppsViewModel.kt | 81 ---------- .../store/viewmodel/all/PurchasedViewModel.kt | 83 ----------- .../editorschoice/EditorBrowseViewModel.kt | 74 ---------- .../editorschoice/EditorChoiceViewModel.kt | 66 --------- .../store/viewmodel/sale/AppSalesViewModel.kt | 2 +- 14 files changed, 11 insertions(+), 749 deletions(-) create mode 100644 app/src/main/java/com/aurora/store/data/model/PaginatedAppList.kt delete mode 100644 app/src/main/java/com/aurora/store/view/ui/all/LibraryAppsFragment.kt delete mode 100644 app/src/main/java/com/aurora/store/view/ui/all/PurchasedAppsFragment.kt delete mode 100644 app/src/main/java/com/aurora/store/view/ui/commons/EditorChoiceFragment.kt delete mode 100644 app/src/main/java/com/aurora/store/view/ui/commons/EditorStreamBrowseFragment.kt delete mode 100644 app/src/main/java/com/aurora/store/viewmodel/all/LibraryAppsViewModel.kt delete mode 100644 app/src/main/java/com/aurora/store/viewmodel/all/PurchasedViewModel.kt delete mode 100644 app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorBrowseViewModel.kt delete mode 100644 app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorChoiceViewModel.kt diff --git a/app/src/main/java/com/aurora/store/data/model/PaginatedAppList.kt b/app/src/main/java/com/aurora/store/data/model/PaginatedAppList.kt new file mode 100644 index 000000000..186da0fdc --- /dev/null +++ b/app/src/main/java/com/aurora/store/data/model/PaginatedAppList.kt @@ -0,0 +1,8 @@ +package com.aurora.store.data.model + +import com.aurora.gplayapi.data.models.App + +data class PaginatedAppList( + val appList: MutableList = mutableListOf(), + var hasMore: Boolean +) \ No newline at end of file diff --git a/app/src/main/java/com/aurora/store/view/ui/all/AppsGamesFragment.kt b/app/src/main/java/com/aurora/store/view/ui/all/AppsGamesFragment.kt index a4b118032..22e6eb2db 100644 --- a/app/src/main/java/com/aurora/store/view/ui/all/AppsGamesFragment.kt +++ b/app/src/main/java/com/aurora/store/view/ui/all/AppsGamesFragment.kt @@ -65,8 +65,6 @@ class AppsGamesFragment : BaseFragment() { ) { tab: TabLayout.Tab, position: Int -> when (position) { 0 -> tab.text = getString(R.string.title_installed) - 1 -> tab.text = getString(R.string.title_library) - 2 -> tab.text = getString(R.string.title_purchase_history) else -> {} } }.attach() @@ -81,14 +79,12 @@ class AppsGamesFragment : BaseFragment() { override fun createFragment(position: Int): Fragment { return when (position) { 0 -> InstalledAppsFragment.newInstance() - 1 -> LibraryAppsFragment.newInstance() - 2 -> PurchasedAppsFragment.newInstance() else -> Fragment() } } override fun getItemCount(): Int { - return if (isAnonymous) 1 else 3 + return 1 } } } diff --git a/app/src/main/java/com/aurora/store/view/ui/all/LibraryAppsFragment.kt b/app/src/main/java/com/aurora/store/view/ui/all/LibraryAppsFragment.kt deleted file mode 100644 index aa4155620..000000000 --- a/app/src/main/java/com/aurora/store/view/ui/all/LibraryAppsFragment.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.view.ui.all - -import android.os.Bundle -import android.view.View -import androidx.fragment.app.viewModels -import com.aurora.gplayapi.data.models.StreamCluster -import com.aurora.store.R -import com.aurora.store.databinding.FragmentAppsBinding -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.shimmer.AppListViewShimmerModel_ -import com.aurora.store.view.ui.commons.BaseFragment -import com.aurora.store.viewmodel.all.LibraryAppsViewModel -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class LibraryAppsFragment : BaseFragment() { - private val viewModel: LibraryAppsViewModel by viewModels() - - companion object { - @JvmStatic - fun newInstance(): LibraryAppsFragment { - return LibraryAppsFragment().apply { - - } - } - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val endlessRecyclerOnScrollListener = object : EndlessRecyclerOnScrollListener() { - override fun onLoadMore(currentPage: Int) { - viewModel.observe() - } - } - binding.recycler.addOnScrollListener(endlessRecyclerOnScrollListener) - - viewModel.liveData.observe(viewLifecycleOwner) { - updateController(it) - } - - updateController(null) - } - - private fun updateController(streamCluster: StreamCluster?) { - binding.recycler.withModels { - setFilterDuplicates(true) - if (streamCluster == null) { - for (i in 1..10) { - add( - AppListViewShimmerModel_() - .id(i) - ) - } - } else { - add( - HeaderViewModel_() - .id("header") - .title( - if (streamCluster.clusterTitle.isEmpty()) - getString(R.string.title_apps_library) - else - streamCluster.clusterTitle - ) - ) - streamCluster.clusterAppList.forEach { app -> - add( - AppListViewModel_() - .id(app.id) - .app(app) - .click { _ -> openDetailsFragment(app.packageName, app) } - ) - } - - if (streamCluster.hasNext()) { - add( - AppProgressViewModel_() - .id("progress") - ) - } - } - } - } -} diff --git a/app/src/main/java/com/aurora/store/view/ui/all/PurchasedAppsFragment.kt b/app/src/main/java/com/aurora/store/view/ui/all/PurchasedAppsFragment.kt deleted file mode 100644 index bd8893765..000000000 --- a/app/src/main/java/com/aurora/store/view/ui/all/PurchasedAppsFragment.kt +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.view.ui.all - -import android.os.Bundle -import android.view.View -import androidx.fragment.app.viewModels -import com.aurora.store.R -import com.aurora.store.databinding.FragmentAppsBinding -import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener -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.all.PaginatedAppList -import com.aurora.store.viewmodel.all.PurchasedViewModel -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class PurchasedAppsFragment : BaseFragment() { - private val viewModel: PurchasedViewModel by viewModels() - - companion object { - @JvmStatic - fun newInstance(): PurchasedAppsFragment { - return PurchasedAppsFragment() - } - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val endlessRecyclerOnScrollListener = object : EndlessRecyclerOnScrollListener(8) { - override fun onLoadMore(currentPage: Int) { - viewModel.observe() - } - } - - binding.recycler.addOnScrollListener(endlessRecyclerOnScrollListener) - - viewModel.liveData.observe(viewLifecycleOwner) { - updateController(it) - } - - updateController(null) - } - - private fun updateController(paginatedAppList: PaginatedAppList?) { - binding.recycler.withModels { - setFilterDuplicates(true) - if (paginatedAppList == null) { - for (i in 1..10) { - add( - AppListViewShimmerModel_() - .id(i) - ) - } - } else { - paginatedAppList.appList.forEach { app -> - add( - AppListViewModel_() - .id(app.id) - .app(app) - .click { _ -> openDetailsFragment(app.packageName, app) } - .longClick { _ -> - openAppMenuSheet(app) - false - } - ) - } - - if (paginatedAppList.hasMore) { - add( - AppProgressViewModel_() - .id("progress") - ) - } - } - } - } -} diff --git a/app/src/main/java/com/aurora/store/view/ui/apps/AppsContainerFragment.kt b/app/src/main/java/com/aurora/store/view/ui/apps/AppsContainerFragment.kt index a9f887574..ea529f1ad 100644 --- a/app/src/main/java/com/aurora/store/view/ui/apps/AppsContainerFragment.kt +++ b/app/src/main/java/com/aurora/store/view/ui/apps/AppsContainerFragment.kt @@ -33,7 +33,6 @@ import com.aurora.store.databinding.FragmentAppsGamesBinding import com.aurora.store.util.Preferences import com.aurora.store.view.ui.commons.BaseFragment 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 @@ -92,10 +91,6 @@ class AppsContainerFragment : BaseFragment() { add(getString(R.string.tab_top_charts)) add(getString(R.string.tab_categories)) - - if (!authProvider.isAnonymous) { - add(getString(R.string.tab_editor_choice)) - } } TabLayoutMediator( @@ -130,10 +125,6 @@ class AppsContainerFragment : BaseFragment() { } add(TopChartContainerFragment.newInstance(0)) add(CategoryFragment.newInstance(0)) - - if (isGoogleAccount) { - add(EditorChoiceFragment.newInstance(0)) - } } override fun createFragment(position: Int): Fragment { diff --git a/app/src/main/java/com/aurora/store/view/ui/commons/EditorChoiceFragment.kt b/app/src/main/java/com/aurora/store/view/ui/commons/EditorChoiceFragment.kt deleted file mode 100644 index 676128e83..000000000 --- a/app/src/main/java/com/aurora/store/view/ui/commons/EditorChoiceFragment.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.view.ui.commons - -import android.os.Bundle -import android.view.View -import androidx.fragment.app.viewModels -import com.aurora.Constants -import com.aurora.gplayapi.data.models.editor.EditorChoiceCluster -import com.aurora.gplayapi.helpers.contracts.StreamContract -import com.aurora.store.databinding.FragmentForYouBinding -import com.aurora.store.view.epoxy.controller.EditorChoiceController -import com.aurora.store.viewmodel.editorschoice.EditorChoiceViewModel -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class EditorChoiceFragment : BaseFragment(), - EditorChoiceController.Callbacks { - private val viewModel: EditorChoiceViewModel by viewModels() - - companion object { - @JvmStatic - fun newInstance(pageType: Int): EditorChoiceFragment { - return EditorChoiceFragment().apply { - arguments = Bundle().apply { - putInt(Constants.PAGE_TYPE, pageType) - } - } - } - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - var pageType = 0 - val bundle = arguments - if (bundle != null) { - pageType = bundle.getInt(Constants.PAGE_TYPE, 0) - } - - val editorChoiceController = EditorChoiceController(this) - binding.recycler.setController(editorChoiceController) - - when (pageType) { - 0 -> viewModel.getEditorChoiceStream(StreamContract.Category.APPLICATION) - 1 -> viewModel.getEditorChoiceStream(StreamContract.Category.GAME) - } - - viewModel.liveData.observe(viewLifecycleOwner) { - editorChoiceController.setData(it) - } - } - - override fun onClick(editorChoiceCluster: EditorChoiceCluster) { - openEditorStreamBrowseFragment( - editorChoiceCluster.clusterBrowseUrl, - editorChoiceCluster.clusterTitle - ) - } -} diff --git a/app/src/main/java/com/aurora/store/view/ui/commons/EditorStreamBrowseFragment.kt b/app/src/main/java/com/aurora/store/view/ui/commons/EditorStreamBrowseFragment.kt deleted file mode 100644 index 5f1a4371a..000000000 --- a/app/src/main/java/com/aurora/store/view/ui/commons/EditorStreamBrowseFragment.kt +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.view.ui.commons - -import android.os.Bundle -import android.view.View -import androidx.fragment.app.viewModels -import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs -import com.airbnb.epoxy.EpoxyModel -import com.aurora.gplayapi.data.models.App -import com.aurora.store.databinding.FragmentGenericWithToolbarBinding -import com.aurora.store.view.epoxy.groups.CarouselHorizontalModel_ -import com.aurora.store.view.epoxy.views.EditorHeadViewModel_ -import com.aurora.store.view.epoxy.views.HorizontalDividerViewModel_ -import com.aurora.store.view.epoxy.views.app.AppListViewModel_ -import com.aurora.store.view.epoxy.views.details.MiniScreenshotView -import com.aurora.store.view.epoxy.views.details.MiniScreenshotViewModel_ -import com.aurora.store.view.epoxy.views.shimmer.AppListViewShimmerModel_ -import com.aurora.store.viewmodel.editorschoice.EditorBrowseViewModel -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class EditorStreamBrowseFragment : BaseFragment() { - private val args: EditorStreamBrowseFragmentArgs by navArgs() - private val viewModel: EditorBrowseViewModel by viewModels() - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - // Toolbar - binding.layoutToolbarAction.apply { - txtTitle.text = args.title - imgActionPrimary.setOnClickListener { - findNavController().navigateUp() - } - } - - viewModel.liveData.observe(viewLifecycleOwner) { - updateController(it) - } - - viewModel.getEditorStreamBundle(args.browseUrl) - updateController(null) - } - - private fun updateController(appList: MutableList?) { - binding.recycler.withModels { - setFilterDuplicates(true) - if (appList == null) { - for (i in 1..6) { - add( - AppListViewShimmerModel_() - .id(i) - ) - } - } else { - appList.forEach { app -> - val screenshotsViewModels = mutableListOf>() - - for ((position, artwork) in app.screenshots.withIndex()) { - screenshotsViewModels.add( - MiniScreenshotViewModel_() - .id(artwork.url) - .position(position) - .artwork(artwork) - .callback(object : MiniScreenshotView.ScreenshotCallback { - override fun onClick(position: Int) { - openScreenshotFragment(app, position) - } - }) - ) - } - - add( - AppListViewModel_() - .id("app_${app.id}") - .app(app) - .click { _ -> openDetailsFragment(app.packageName, app) } - ) - - app.editorReason?.let { editorReason -> - add( - EditorHeadViewModel_() - .id("bulletin_${app.id}") - .title( - editorReason.bulletins - .joinToString(transform = { "\n• $it" }) - .substringAfter(delimiter = "\n") - ) - .click { _ -> openDetailsFragment(app.packageName, app) } - ) - } - - if (screenshotsViewModels.isNotEmpty()) { - add( - CarouselHorizontalModel_() - .id("screenshots_${app.id}") - .models(screenshotsViewModels) - ) - } - - app.editorReason?.let { editorReason -> - if (editorReason.description.isNotEmpty()) { - add( - EditorHeadViewModel_() - .id("description_${app.id}") - .title(editorReason.description) - .click { _ -> openDetailsFragment(app.packageName, app) } - ) - } - } - - add( - HorizontalDividerViewModel_() - .id("divider_${app.id}") - ) - } - } - } - } -} diff --git a/app/src/main/java/com/aurora/store/view/ui/games/GamesContainerFragment.kt b/app/src/main/java/com/aurora/store/view/ui/games/GamesContainerFragment.kt index 0e574f1cb..cc5fa5ee3 100644 --- a/app/src/main/java/com/aurora/store/view/ui/games/GamesContainerFragment.kt +++ b/app/src/main/java/com/aurora/store/view/ui/games/GamesContainerFragment.kt @@ -33,7 +33,6 @@ import com.aurora.store.databinding.FragmentAppsGamesBinding import com.aurora.store.util.Preferences import com.aurora.store.view.ui.commons.BaseFragment 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 @@ -91,10 +90,6 @@ class GamesContainerFragment : BaseFragment() { add(getString(R.string.tab_top_charts)) add(getString(R.string.tab_categories)) - - if (!authProvider.isAnonymous) { - add(getString(R.string.tab_editor_choice)) - } } TabLayoutMediator( @@ -129,10 +124,6 @@ class GamesContainerFragment : BaseFragment() { add(TopChartContainerFragment.newInstance(1)) add(CategoryFragment.newInstance(1)) - - if (isGoogleAccount) { - add(EditorChoiceFragment.newInstance(1)) - } } override fun createFragment(position: Int): Fragment { diff --git a/app/src/main/java/com/aurora/store/view/ui/sale/AppSalesFragment.kt b/app/src/main/java/com/aurora/store/view/ui/sale/AppSalesFragment.kt index dc03a3316..50dedacb2 100644 --- a/app/src/main/java/com/aurora/store/view/ui/sale/AppSalesFragment.kt +++ b/app/src/main/java/com/aurora/store/view/ui/sale/AppSalesFragment.kt @@ -24,6 +24,7 @@ import android.view.View import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.aurora.store.R +import com.aurora.store.data.model.PaginatedAppList import com.aurora.store.databinding.FragmentGenericWithToolbarBinding import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener import com.aurora.store.view.epoxy.views.AppProgressViewModel_ @@ -32,7 +33,6 @@ 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 import dagger.hilt.android.AndroidEntryPoint diff --git a/app/src/main/java/com/aurora/store/viewmodel/all/LibraryAppsViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/all/LibraryAppsViewModel.kt deleted file mode 100644 index 4574e72ce..000000000 --- a/app/src/main/java/com/aurora/store/viewmodel/all/LibraryAppsViewModel.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.viewmodel.all - -import android.annotation.SuppressLint -import android.content.Context -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.aurora.gplayapi.data.models.StreamCluster -import com.aurora.gplayapi.helpers.ClusterHelper -import com.aurora.store.data.network.HttpClient -import com.aurora.store.data.providers.AuthProvider -import dagger.hilt.android.lifecycle.HiltViewModel -import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.supervisorScope -import javax.inject.Inject - -@HiltViewModel -@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 -class LibraryAppsViewModel @Inject constructor( - @ApplicationContext private val context: Context, - private val authProvider: AuthProvider -) : ViewModel() { - - private val clusterHelper: ClusterHelper = ClusterHelper(authProvider.authData) - .using(HttpClient.getPreferredClient(context)) - - val liveData: MutableLiveData = MutableLiveData() - var streamCluster: StreamCluster = StreamCluster() - - fun observe() { - viewModelScope.launch(Dispatchers.IO) { - supervisorScope { - try { - when { - streamCluster.clusterAppList.isEmpty() -> { - val newCluster = - clusterHelper.getCluster(ClusterHelper.Type.MY_APPS_LIBRARY) - updateCluster(newCluster) - liveData.postValue(streamCluster) - } - streamCluster.hasNext() -> { - val newCluster = clusterHelper.next(streamCluster.clusterNextPageUrl) - updateCluster(newCluster) - liveData.postValue(streamCluster) - } - else -> {} - } - } catch (_: Exception) { - } - } - } - } - - private fun updateCluster(newCluster: StreamCluster) { - streamCluster.apply { - clusterAppList.addAll(newCluster.clusterAppList) - clusterNextPageUrl = newCluster.clusterNextPageUrl - } - } -} diff --git a/app/src/main/java/com/aurora/store/viewmodel/all/PurchasedViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/all/PurchasedViewModel.kt deleted file mode 100644 index a5bb01b7a..000000000 --- a/app/src/main/java/com/aurora/store/viewmodel/all/PurchasedViewModel.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.viewmodel.all - -import android.annotation.SuppressLint -import android.content.Context -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.aurora.gplayapi.data.models.App -import com.aurora.gplayapi.helpers.PurchaseHelper -import com.aurora.store.data.network.HttpClient -import com.aurora.store.data.providers.AuthProvider -import dagger.hilt.android.lifecycle.HiltViewModel -import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.supervisorScope -import javax.inject.Inject - -data class PaginatedAppList( - var appList: MutableList = mutableListOf(), - var hasMore: Boolean -) - -@HiltViewModel -@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 -class PurchasedViewModel @Inject constructor( - @ApplicationContext private val context: Context, - private val authProvider: AuthProvider -) : ViewModel() { - - private val purchaseHelper = PurchaseHelper(authProvider.authData) - .using(HttpClient.getPreferredClient(context)) - - private var appList: MutableList = mutableListOf() - - val liveData: MutableLiveData = MutableLiveData() - - fun observe() { - viewModelScope.launch(Dispatchers.IO) { - supervisorScope { - try { - val nextAppList = purchaseHelper.getPurchaseHistory(appList.size) - .filter { it.displayName.isNotEmpty() } - - if (nextAppList.isEmpty()) { - liveData.postValue(PaginatedAppList( - appList, - false - )) - } else { - appList.addAll(nextAppList) - liveData.postValue( - PaginatedAppList( - appList, - true - ) - ) - } - } catch (_: Exception) { - } - } - } - } -} diff --git a/app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorBrowseViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorBrowseViewModel.kt deleted file mode 100644 index b408566c3..000000000 --- a/app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorBrowseViewModel.kt +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.viewmodel.editorschoice - -import android.annotation.SuppressLint -import android.content.Context -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.aurora.gplayapi.data.models.App -import com.aurora.gplayapi.helpers.StreamHelper -import com.aurora.store.data.network.HttpClient -import com.aurora.store.data.providers.AuthProvider -import dagger.hilt.android.lifecycle.HiltViewModel -import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.supervisorScope -import javax.inject.Inject - -@HiltViewModel -@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 -class EditorBrowseViewModel @Inject constructor( - @ApplicationContext private val context: Context, - private val authProvider: AuthProvider -) : ViewModel() { - - private val streamHelper: StreamHelper = StreamHelper(authProvider.authData) - .using(HttpClient.getPreferredClient(context)) - - val liveData: MutableLiveData> = MutableLiveData() - val appList: MutableList = mutableListOf() - - fun getEditorStreamBundle(browseUrl: String) { - viewModelScope.launch(Dispatchers.IO) { - supervisorScope { - try { - 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) - - } catch (_: Exception) { - } - } - } - } -} diff --git a/app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorChoiceViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorChoiceViewModel.kt deleted file mode 100644 index 5e516ea40..000000000 --- a/app/src/main/java/com/aurora/store/viewmodel/editorschoice/EditorChoiceViewModel.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2021, Rahul Kumar Patel - * - * 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 . - * - */ - -package com.aurora.store.viewmodel.editorschoice - -import android.annotation.SuppressLint -import android.content.Context -import android.util.Log -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.aurora.gplayapi.data.models.editor.EditorChoiceBundle -import com.aurora.gplayapi.helpers.StreamHelper -import com.aurora.gplayapi.helpers.contracts.StreamContract -import com.aurora.store.data.network.HttpClient -import com.aurora.store.data.providers.AuthProvider -import dagger.hilt.android.lifecycle.HiltViewModel -import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.supervisorScope -import javax.inject.Inject - -@HiltViewModel -@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 -class EditorChoiceViewModel @Inject constructor( - @ApplicationContext private val context: Context, - private val authProvider: AuthProvider -) : ViewModel() { - - private val TAG = EditorChoiceViewModel::class.java.simpleName - - private val streamHelper: StreamHelper = StreamHelper(authProvider.authData) - .using(HttpClient.getPreferredClient(context)) - - val liveData: MutableLiveData> = MutableLiveData() - - fun getEditorChoiceStream(category: StreamContract.Category) { - viewModelScope.launch(Dispatchers.IO) { - supervisorScope { - try { - val editorChoiceBundle = streamHelper.getEditorChoiceStream(category) - liveData.postValue(editorChoiceBundle) - } catch (exception: Exception) { - Log.e(TAG, "Failed fetching list of categories", exception) - } - } - } - } -} diff --git a/app/src/main/java/com/aurora/store/viewmodel/sale/AppSalesViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/sale/AppSalesViewModel.kt index 9d4ca4db3..e7b7bb911 100644 --- a/app/src/main/java/com/aurora/store/viewmodel/sale/AppSalesViewModel.kt +++ b/app/src/main/java/com/aurora/store/viewmodel/sale/AppSalesViewModel.kt @@ -26,9 +26,9 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.helpers.AppSalesHelper +import com.aurora.store.data.model.PaginatedAppList import com.aurora.store.data.network.HttpClient import com.aurora.store.data.providers.AuthProvider -import com.aurora.store.viewmodel.all.PaginatedAppList import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.Dispatchers