AuthProvider: Inject it via hilt where needed
- Merge validation function in it as well instead of using it as an extension - Use dedicated preference to check if we are anonymous or not instead of authData Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.Context
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.AuthValidator
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
suspend fun AuthData.isValid(context: Context): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
AuthValidator(this@isValid)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
.isValid()
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,34 +20,54 @@
|
||||
package com.aurora.store.data.providers
|
||||
|
||||
import android.content.Context
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.store.data.SingletonHolder
|
||||
import com.aurora.gplayapi.helpers.AuthValidator
|
||||
import com.aurora.store.AccountType
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_AUTH_DATA
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.lang.reflect.Modifier
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class AuthProvider private constructor(var context: Context) {
|
||||
@Singleton
|
||||
class AuthProvider @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val gson: Gson
|
||||
) {
|
||||
|
||||
companion object : SingletonHolder<AuthProvider, Context>(::AuthProvider)
|
||||
val authData: AuthData get() = getSavedAuthData()
|
||||
|
||||
private var gson: Gson = GsonBuilder()
|
||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||
.create()
|
||||
val isAnonymous: Boolean
|
||||
get() {
|
||||
val name = Preferences.getString(context, Constants.ACCOUNT_TYPE, AccountType.GOOGLE.name)
|
||||
return AccountType.valueOf(name) == AccountType.ANONYMOUS
|
||||
}
|
||||
|
||||
fun getAuthData(): AuthData {
|
||||
return getSavedAuthData()
|
||||
suspend fun isAuthDataValid(): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
AuthValidator(getSavedAuthData())
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
.isValid()
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSavedAuthData(): AuthData {
|
||||
Log.i("Loading saved AuthData")
|
||||
|
||||
val rawAuth: String = Preferences.getString(context, PREFERENCE_AUTH_DATA)
|
||||
return if (rawAuth.isNotEmpty())
|
||||
return if (rawAuth.isNotEmpty()) {
|
||||
gson.fromJson(rawAuth, AuthData::class.java)
|
||||
else
|
||||
} else {
|
||||
AuthData("", "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ class DownloadWorker @AssistedInject constructor(
|
||||
private val downloadDao: DownloadDao,
|
||||
private val gson: Gson,
|
||||
private val appInstaller: AppInstaller,
|
||||
private val authProvider: AuthProvider,
|
||||
@Assisted private val appContext: Context,
|
||||
@Assisted workerParams: WorkerParameters
|
||||
) : CoroutineWorker(appContext, workerParams) {
|
||||
@@ -98,8 +99,7 @@ class DownloadWorker @AssistedInject constructor(
|
||||
setForeground(getForegroundInfo())
|
||||
|
||||
// Purchase the app (free apps needs to be purchased too)
|
||||
val authData = AuthProvider.with(appContext).getAuthData()
|
||||
purchaseHelper = PurchaseHelper(authData)
|
||||
purchaseHelper = PurchaseHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(appContext))
|
||||
|
||||
notificationManager =
|
||||
|
||||
@@ -14,7 +14,6 @@ import androidx.work.WorkManager
|
||||
import androidx.work.WorkerParameters
|
||||
import com.aurora.extensions.isIgnoringBatteryOptimizations
|
||||
import com.aurora.extensions.isMAndAbove
|
||||
import com.aurora.extensions.isValid
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.util.AppUtil
|
||||
import com.aurora.store.util.DownloadWorkerUtil
|
||||
@@ -35,6 +34,7 @@ import java.util.concurrent.TimeUnit.MINUTES
|
||||
class UpdateWorker @AssistedInject constructor(
|
||||
private val downloadWorkerUtil: DownloadWorkerUtil,
|
||||
private val gson: Gson,
|
||||
private val authProvider: AuthProvider,
|
||||
@Assisted private val appContext: Context,
|
||||
@Assisted workerParams: WorkerParameters
|
||||
) : CoroutineWorker(appContext, workerParams) {
|
||||
@@ -97,7 +97,7 @@ class UpdateWorker @AssistedInject constructor(
|
||||
}
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
if (!AuthProvider.with(appContext).getAuthData().isValid(appContext)) {
|
||||
if (!authProvider.isAuthDataValid()) {
|
||||
Log.i(TAG, "AuthData is not valid, retrying later!")
|
||||
return@withContext Result.retry()
|
||||
}
|
||||
@@ -105,6 +105,7 @@ class UpdateWorker @AssistedInject constructor(
|
||||
try {
|
||||
val updatesList = AppUtil.getUpdatableApps(
|
||||
context = appContext,
|
||||
authData = authProvider.authData,
|
||||
gson = gson,
|
||||
verifyCert = true,
|
||||
selfUpdate = false
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.util.Log
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.AppDetailsHelper
|
||||
import com.aurora.store.BuildConfig
|
||||
import com.aurora.store.data.model.SelfUpdate
|
||||
@@ -23,12 +24,13 @@ object AppUtil {
|
||||
|
||||
suspend fun getUpdatableApps(
|
||||
context: Context,
|
||||
authData: AuthData,
|
||||
gson: Gson,
|
||||
verifyCert: Boolean,
|
||||
selfUpdate: Boolean = true
|
||||
): List<App> {
|
||||
val packageInfoMap = PackageUtil.getPackageInfoMap(context)
|
||||
val appUpdatesList = getFilteredInstalledApps(context, packageInfoMap).filter {
|
||||
val appUpdatesList = getFilteredInstalledApps(context, authData, packageInfoMap).filter {
|
||||
val packageInfo = packageInfoMap[it.packageName]
|
||||
if (packageInfo != null) {
|
||||
it.versionCode.toLong() > PackageInfoCompat.getLongVersionCode(packageInfo)
|
||||
@@ -58,13 +60,13 @@ object AppUtil {
|
||||
|
||||
suspend fun getFilteredInstalledApps(
|
||||
context: Context,
|
||||
authData: AuthData,
|
||||
packageInfoMap: MutableMap<String, PackageInfo>? = null
|
||||
): List<App> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val authData = AuthProvider.with(context).getAuthData()
|
||||
val blackList = BlacklistProvider.with(context).getBlackList()
|
||||
val appDetailsHelper =
|
||||
AppDetailsHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
val appDetailsHelper = AppDetailsHelper(authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
(packageInfoMap ?: PackageUtil.getPackageInfoMap(context)).keys.let { packages ->
|
||||
val filtersPackages = packages.filter { !blackList.contains(it) }
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.aurora.store.data.providers.AccountProvider
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.databinding.FragmentAccountBinding
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AccountFragment : Fragment(R.layout.fragment_account) {
|
||||
@@ -42,12 +43,13 @@ class AccountFragment : Fragment(R.layout.fragment_account) {
|
||||
private val binding: FragmentAccountBinding
|
||||
get() = _binding!!
|
||||
|
||||
@Inject
|
||||
lateinit var authProvider: AuthProvider
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentAccountBinding.bind(view)
|
||||
|
||||
val authData = AuthProvider.with(view.context).getAuthData()
|
||||
|
||||
// Toolbar
|
||||
binding.layoutToolbarAction.txtTitle.text = getString(R.string.title_account_manager)
|
||||
binding.layoutToolbarAction.imgActionPrimary.setOnClickListener {
|
||||
@@ -61,14 +63,14 @@ class AccountFragment : Fragment(R.layout.fragment_account) {
|
||||
binding.chipTos.setOnClickListener { browse(URL_TOS) }
|
||||
}
|
||||
|
||||
authData.userProfile?.let {
|
||||
val avatar = if (authData.isAnonymous) R.mipmap.ic_launcher else it.artwork.url
|
||||
authProvider.authData.userProfile?.let {
|
||||
val avatar = if (authProvider.isAnonymous) R.mipmap.ic_launcher else it.artwork.url
|
||||
binding.imgAvatar.load(avatar) {
|
||||
placeholder(R.drawable.bg_placeholder)
|
||||
transformations(RoundedCornersTransformation(32F))
|
||||
}
|
||||
binding.txtName.text = if (authData.isAnonymous) "Anonymous" else it.name
|
||||
binding.txtEmail.text = if (authData.isAnonymous) "anonymous@gmail.com" else it.email
|
||||
binding.txtName.text = if (authProvider.isAnonymous) "Anonymous" else it.name
|
||||
binding.txtEmail.text = if (authProvider.isAnonymous) "anonymous@gmail.com" else it.email
|
||||
}
|
||||
|
||||
binding.btnLogout.addOnClickListener {
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.aurora.store.databinding.ActivityGenericPagerBinding
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AppsGamesFragment : Fragment(R.layout.activity_generic_pager) {
|
||||
@@ -41,12 +42,13 @@ class AppsGamesFragment : Fragment(R.layout.activity_generic_pager) {
|
||||
private val binding: ActivityGenericPagerBinding
|
||||
get() = _binding!!
|
||||
|
||||
@Inject
|
||||
lateinit var authProvider: AuthProvider
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = ActivityGenericPagerBinding.bind(view)
|
||||
|
||||
val authData = AuthProvider.with(view.context).getAuthData()
|
||||
|
||||
// Toolbar
|
||||
binding.layoutActionToolbar.toolbar.apply {
|
||||
elevation = 0f
|
||||
@@ -58,7 +60,7 @@ class AppsGamesFragment : Fragment(R.layout.activity_generic_pager) {
|
||||
// ViewPager
|
||||
binding.pager.apply {
|
||||
isUserInputEnabled = false
|
||||
adapter = ViewPagerAdapter(childFragmentManager, lifecycle, authData.isAnonymous)
|
||||
adapter = ViewPagerAdapter(childFragmentManager, lifecycle, authProvider.isAnonymous)
|
||||
}
|
||||
|
||||
TabLayoutMediator(
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.aurora.store.view.ui.commons.TopChartContainerFragment
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AppsContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
@@ -45,6 +46,9 @@ class AppsContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
private var _binding: FragmentAppsGamesBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
@Inject
|
||||
lateinit var authProvider: AuthProvider
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentAppsGamesBinding.bind(view)
|
||||
@@ -73,12 +77,10 @@ class AppsContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
Preferences.PREFERENCE_FOR_YOU
|
||||
)
|
||||
|
||||
val isGoogleAccount = !AuthProvider.with(requireContext()).getAuthData().isAnonymous
|
||||
|
||||
binding.pager.adapter = ViewPagerAdapter(
|
||||
childFragmentManager,
|
||||
viewLifecycleOwner.lifecycle,
|
||||
isGoogleAccount,
|
||||
!authProvider.isAnonymous,
|
||||
isForYouEnabled
|
||||
)
|
||||
|
||||
@@ -93,7 +95,7 @@ class AppsContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
add(getString(R.string.tab_top_charts))
|
||||
add(getString(R.string.tab_categories))
|
||||
|
||||
if (isGoogleAccount) {
|
||||
if (!authProvider.isAnonymous) {
|
||||
add(getString(R.string.tab_editor_choice))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,15 @@ import com.aurora.store.R
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.view.theme.AuroraTheme
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MoreDialogFragment : DialogFragment() {
|
||||
|
||||
@Inject
|
||||
lateinit var authProvider: AuthProvider
|
||||
|
||||
private data class Option(
|
||||
@StringRes val title: Int,
|
||||
@DrawableRes val icon: Int,
|
||||
@@ -171,7 +177,6 @@ class MoreDialogFragment : DialogFragment() {
|
||||
|
||||
@Composable
|
||||
private fun AccountHeader(backgroundColor: Color) {
|
||||
val authData = AuthProvider.with(LocalContext.current).getAuthData()
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -193,7 +198,7 @@ class MoreDialogFragment : DialogFragment() {
|
||||
) {
|
||||
SubcomposeAsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(if (authData.isAnonymous) R.mipmap.ic_launcher else authData.userProfile?.artwork?.url)
|
||||
.data(if (authProvider.isAnonymous) R.mipmap.ic_launcher else authProvider.authData.userProfile?.artwork?.url)
|
||||
.placeholder(R.drawable.ic_account)
|
||||
.crossfade(true)
|
||||
.build(),
|
||||
@@ -208,12 +213,12 @@ class MoreDialogFragment : DialogFragment() {
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
Text(
|
||||
text = if (authData.isAnonymous) "anonymous" else authData.userProfile!!.name,
|
||||
text = if (authProvider.isAnonymous) "anonymous" else authProvider.authData.userProfile!!.name,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontSize = 16.sp
|
||||
)
|
||||
Text(
|
||||
text = if (authData.isAnonymous) "anonymous@gmail.com" else authData.userProfile!!.email,
|
||||
text = if (authProvider.isAnonymous) "anonymous@gmail.com" else authProvider.authData.userProfile!!.email,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 14.sp
|
||||
)
|
||||
|
||||
@@ -93,6 +93,7 @@ import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.filter
|
||||
|
||||
@@ -108,6 +109,9 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
|
||||
private val args: AppDetailsFragmentArgs by navArgs()
|
||||
|
||||
@Inject
|
||||
lateinit var authProvider: AuthProvider
|
||||
|
||||
private lateinit var bottomSheetBehavior: BottomSheetBehavior<LinearLayout>
|
||||
|
||||
private val startForStorageManagerResult =
|
||||
@@ -129,7 +133,6 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var authData: AuthData
|
||||
private lateinit var app: App
|
||||
|
||||
private var isExternal = false
|
||||
@@ -205,9 +208,6 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentDetailsBinding.bind(view)
|
||||
|
||||
// TODO: Move to viewModel
|
||||
authData = AuthProvider.with(view.context).getAuthData()
|
||||
|
||||
if (args.app != null) {
|
||||
app = args.app!!
|
||||
inflatePartialApp()
|
||||
@@ -511,7 +511,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
inflateAppPrivacy(app)
|
||||
inflateAppPermission(binding.layoutDetailsPermissions, app)
|
||||
|
||||
if (!authData.isAnonymous) {
|
||||
if (!authProvider.isAnonymous) {
|
||||
app.testingProgram?.let {
|
||||
if (it.isAvailable && it.isSubscribed) {
|
||||
binding.layoutDetailsApp.txtLine1.text = it.displayName
|
||||
@@ -631,7 +631,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
}
|
||||
|
||||
btn.addOnClickListener {
|
||||
if (authData.isAnonymous && !app.isFree) {
|
||||
if (authProvider.isAnonymous && !app.isFree) {
|
||||
toast(R.string.toast_purchase_blocked)
|
||||
} else {
|
||||
btn.setText(R.string.download_metadata)
|
||||
@@ -764,12 +764,10 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
B.averageRating.text = String.format(Locale.getDefault(), "%.1f", app.rating.average)
|
||||
B.txtReviewCount.text = app.rating.abbreviatedLabel
|
||||
|
||||
val authData = AuthProvider.with(requireContext()).getAuthData()
|
||||
|
||||
B.layoutUserReview.visibility = if (authData.isAnonymous) View.GONE else View.VISIBLE
|
||||
B.layoutUserReview.visibility = if (authProvider.isAnonymous) View.GONE else View.VISIBLE
|
||||
|
||||
B.btnPostReview.setOnClickListener {
|
||||
if (authData.isAnonymous) {
|
||||
if (authProvider.isAnonymous) {
|
||||
toast(R.string.toast_anonymous_restriction)
|
||||
} else {
|
||||
addOrUpdateReview(app, Review().apply {
|
||||
|
||||
@@ -61,7 +61,7 @@ class DetailsMoreFragment : BaseFragment(R.layout.fragment_details_more) {
|
||||
|
||||
inflateDescription(args.app)
|
||||
inflateFiles(args.app)
|
||||
viewModel.fetchDependentApps(view.context, args.app)
|
||||
viewModel.fetchDependentApps(args.app)
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
viewModel.dependentApps.collect { list ->
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.aurora.store.view.ui.commons.TopChartContainerFragment
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class GamesContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
@@ -45,6 +46,9 @@ class GamesContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
private var _binding: FragmentAppsGamesBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
@Inject
|
||||
lateinit var authProvider: AuthProvider
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentAppsGamesBinding.bind(view)
|
||||
@@ -73,12 +77,10 @@ class GamesContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
Preferences.PREFERENCE_FOR_YOU
|
||||
)
|
||||
|
||||
val isGoogleAccount = !AuthProvider.with(requireContext()).getAuthData().isAnonymous
|
||||
|
||||
binding.pager.adapter = ViewPagerAdapter(
|
||||
childFragmentManager,
|
||||
viewLifecycleOwner.lifecycle,
|
||||
isGoogleAccount,
|
||||
!authProvider.isAnonymous,
|
||||
isForYouEnabled
|
||||
)
|
||||
|
||||
@@ -92,7 +94,7 @@ class GamesContainerFragment : Fragment(R.layout.fragment_apps_games) {
|
||||
add(getString(R.string.tab_top_charts))
|
||||
add(getString(R.string.tab_categories))
|
||||
|
||||
if (isGoogleAccount) {
|
||||
if (!authProvider.isAnonymous) {
|
||||
add(getString(R.string.tab_editor_choice))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,18 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.util.AppUtil
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
class InstalledViewModel : ViewModel() {
|
||||
@HiltViewModel
|
||||
class InstalledViewModel @Inject constructor(
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = InstalledViewModel::class.java.simpleName
|
||||
|
||||
@@ -40,7 +46,7 @@ class InstalledViewModel : ViewModel() {
|
||||
fun getInstalledApps(context: Context) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
appList = AppUtil.getFilteredInstalledApps(context).toMutableList()
|
||||
appList = AppUtil.getFilteredInstalledApps(context, authProvider.authData).toMutableList()
|
||||
liveData.postValue(appList.sortedBy { it.displayName.lowercase(Locale.getDefault()) })
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to get installed apps", exception)
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.helpers.ClusterHelper
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
@@ -39,12 +38,12 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class LibraryAppsViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private val clusterHelper: ClusterHelper =
|
||||
ClusterHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
private val clusterHelper: ClusterHelper = ClusterHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<StreamCluster> = MutableLiveData()
|
||||
var streamCluster: StreamCluster = StreamCluster()
|
||||
|
||||
@@ -43,12 +43,12 @@ data class PaginatedAppList(
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class PurchasedViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData = AuthProvider.with(context).getAuthData()
|
||||
|
||||
private val purchaseHelper = PurchaseHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
private val purchaseHelper = PurchaseHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
private var appList: MutableList<App> = mutableListOf()
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.util.Log
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.util.AppUtil
|
||||
import com.aurora.store.util.DownloadWorkerUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
@@ -43,7 +44,8 @@ import kotlinx.coroutines.launch
|
||||
class UpdatesViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val gson: Gson,
|
||||
private val downloadWorkerUtil: DownloadWorkerUtil
|
||||
private val downloadWorkerUtil: DownloadWorkerUtil,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = UpdatesViewModel::class.java.simpleName
|
||||
@@ -61,9 +63,12 @@ class UpdatesViewModel @Inject constructor(
|
||||
val isExtendedUpdateEnabled = Preferences.getBoolean(
|
||||
context, Preferences.PREFERENCE_UPDATES_EXTENDED
|
||||
)
|
||||
val updates =
|
||||
AppUtil.getUpdatableApps(context, gson, !isExtendedUpdateEnabled)
|
||||
.sortedBy { it.displayName.lowercase(Locale.getDefault()) }
|
||||
val updates = AppUtil.getUpdatableApps(
|
||||
context,
|
||||
authProvider.authData,
|
||||
gson,
|
||||
!isExtendedUpdateEnabled
|
||||
).sortedBy { it.displayName.lowercase(Locale.getDefault()) }
|
||||
_updates.emit(updates)
|
||||
} catch (exception: Exception) {
|
||||
Log.d(TAG, "Failed to get updates", exception)
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.helpers.ExpandedBrowseHelper
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
@@ -40,11 +39,11 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class ExpandedStreamBrowseViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private val streamHelper: ExpandedBrowseHelper = ExpandedBrowseHelper(authData)
|
||||
private val streamHelper: ExpandedBrowseHelper = ExpandedBrowseHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<StreamCluster> = MutableLiveData()
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.helpers.StreamHelper
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
@@ -40,11 +39,11 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class StreamBrowseViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private val streamHelper: StreamHelper = StreamHelper(authData)
|
||||
private val streamHelper: StreamHelper = StreamHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<StreamCluster> = MutableLiveData()
|
||||
|
||||
@@ -39,16 +39,13 @@ import kotlinx.coroutines.launch
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class CategoryViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = CategoryViewModel::class.java.simpleName
|
||||
|
||||
private val authData: AuthData = AuthProvider
|
||||
.with(context)
|
||||
.getAuthData()
|
||||
|
||||
private val streamHelper: CategoryHelper = CategoryHelper(authData)
|
||||
private val streamHelper: CategoryHelper = CategoryHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<List<Category>> = MutableLiveData()
|
||||
|
||||
@@ -26,7 +26,8 @@ import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AppDetailsViewModel @Inject constructor(
|
||||
private val downloadWorkerUtil: DownloadWorkerUtil
|
||||
private val downloadWorkerUtil: DownloadWorkerUtil,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = AppDetailsViewModel::class.java.simpleName
|
||||
@@ -54,9 +55,9 @@ class AppDetailsViewModel @Inject constructor(
|
||||
fun fetchAppDetails(context: Context, packageName: String) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val authData = AuthProvider.with(context).getAuthData()
|
||||
_app.emit(
|
||||
AppDetailsHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
AppDetailsHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
.getAppByPackageName(packageName)
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
@@ -69,8 +70,8 @@ class AppDetailsViewModel @Inject constructor(
|
||||
fun fetchAppReviews(context: Context, packageName: String) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val authData = AuthProvider.with(context).getAuthData()
|
||||
_reviews.emit(ReviewsHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
_reviews.emit(ReviewsHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
.getReviewSummary(packageName))
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to fetch app reviews", exception)
|
||||
@@ -82,8 +83,7 @@ class AppDetailsViewModel @Inject constructor(
|
||||
fun postAppReview(context: Context, packageName: String, review: Review, isBeta: Boolean) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val authData = AuthProvider.with(context).getAuthData()
|
||||
_userReview.emit(ReviewsHelper(authData)
|
||||
_userReview.emit(ReviewsHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
.addOrEditReview(
|
||||
packageName,
|
||||
@@ -122,9 +122,8 @@ class AppDetailsViewModel @Inject constructor(
|
||||
fun fetchTestingProgramStatus(context: Context, packageName: String, subscribe: Boolean) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val authData = AuthProvider.with(context).getAuthData()
|
||||
_testingProgramStatus.emit(
|
||||
AppDetailsHelper(authData).testingProgram(
|
||||
AppDetailsHelper(authProvider.authData).testingProgram(
|
||||
packageName,
|
||||
subscribe
|
||||
)
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamBundle
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.helpers.AppDetailsHelper
|
||||
@@ -43,12 +42,13 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class DetailsClusterViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private var authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private var appDetailsHelper = AppDetailsHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
private var streamHelper = StreamHelper(authData)
|
||||
private var appDetailsHelper = AppDetailsHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
private var streamHelper = StreamHelper(authProvider.authData)
|
||||
|
||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||
var streamBundle: StreamBundle = StreamBundle()
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
package com.aurora.store.viewmodel.details
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.AppDetailsHelper
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class DetailsMoreViewModel : ViewModel() {
|
||||
@HiltViewModel
|
||||
class DetailsMoreViewModel @Inject constructor(
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = DetailsMoreViewModel::class.java.simpleName
|
||||
|
||||
private val _dependentApps = MutableSharedFlow<List<App>>()
|
||||
val dependentApps = _dependentApps.asSharedFlow()
|
||||
|
||||
fun fetchDependentApps(context: Context, app: App) {
|
||||
fun fetchDependentApps(app: App) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
_dependentApps.emit(AppDetailsHelper(authData)
|
||||
_dependentApps.emit(AppDetailsHelper(authProvider.authData)
|
||||
.getAppByPackageName(app.dependencies.dependentPackages))
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to fetch dependencies", exception)
|
||||
|
||||
@@ -44,12 +44,13 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class DevProfileViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private var authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private var appDetailsHelper = AppDetailsHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
private var streamHelper = StreamHelper(authData)
|
||||
private var appDetailsHelper = AppDetailsHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
private var streamHelper = StreamHelper(authProvider.authData)
|
||||
|
||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||
var devStream:DevStream = DevStream()
|
||||
|
||||
@@ -39,11 +39,11 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class EditorBrowseViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private val streamHelper: StreamHelper = StreamHelper(authData)
|
||||
private val streamHelper: StreamHelper = StreamHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<MutableList<App>> = MutableLiveData()
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.util.Log
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.editor.EditorChoiceBundle
|
||||
import com.aurora.gplayapi.helpers.StreamHelper
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
@@ -40,16 +39,13 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class EditorChoiceViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = EditorChoiceViewModel::class.java.simpleName
|
||||
|
||||
private val authData: AuthData = AuthProvider
|
||||
.with(context)
|
||||
.getAuthData()
|
||||
|
||||
private val streamHelper: StreamHelper = StreamHelper(authData)
|
||||
private val streamHelper: StreamHelper = StreamHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<List<EditorChoiceBundle>> = MutableLiveData()
|
||||
|
||||
@@ -42,13 +42,12 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class BaseClusterViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
var authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
|
||||
var streamHelper: StreamHelper =
|
||||
StreamHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
var streamHelper: StreamHelper = StreamHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||
var streamBundle: StreamBundle = StreamBundle()
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.Review
|
||||
import com.aurora.gplayapi.data.models.ReviewCluster
|
||||
import com.aurora.gplayapi.helpers.ReviewsHelper
|
||||
@@ -40,14 +39,11 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class ReviewViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
var authData: AuthData = AuthProvider
|
||||
.with(context)
|
||||
.getAuthData()
|
||||
|
||||
var reviewsHelper: ReviewsHelper = ReviewsHelper(authData)
|
||||
var reviewsHelper: ReviewsHelper = ReviewsHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<ReviewCluster> = MutableLiveData()
|
||||
|
||||
@@ -25,7 +25,6 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.AppSalesHelper
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
@@ -40,12 +39,12 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class AppSalesViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private val appSalesHelper: AppSalesHelper =
|
||||
AppSalesHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
private val appSalesHelper: AppSalesHelper = AppSalesHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
private var page: Int = 0
|
||||
private val appList: MutableList<App> = mutableListOf()
|
||||
|
||||
@@ -26,7 +26,6 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.extensions.flushAndAdd
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.SearchBundle
|
||||
import com.aurora.gplayapi.helpers.SearchHelper
|
||||
import com.aurora.gplayapi.helpers.WebSearchHelper
|
||||
@@ -44,16 +43,14 @@ import kotlinx.coroutines.supervisorScope
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class SearchResultViewModel @Inject constructor(
|
||||
val filterProvider: FilterProvider,
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = SearchResultViewModel::class.java.simpleName
|
||||
private val authData: AuthData = AuthProvider
|
||||
.with(context)
|
||||
.getAuthData()
|
||||
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper(authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authData)
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper(authProvider.authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<SearchBundle> = MutableLiveData()
|
||||
@@ -61,7 +58,7 @@ class SearchResultViewModel @Inject constructor(
|
||||
private var searchBundle: SearchBundle = SearchBundle()
|
||||
|
||||
fun helper(): SearchHelper {
|
||||
return if (authData.isAnonymous) {
|
||||
return if (authProvider.isAnonymous) {
|
||||
webSearchHelper
|
||||
} else {
|
||||
searchHelper
|
||||
|
||||
@@ -19,33 +19,37 @@
|
||||
|
||||
package com.aurora.store.viewmodel.search
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.SearchSuggestEntry
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.SearchHelper
|
||||
import com.aurora.gplayapi.helpers.WebSearchHelper
|
||||
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 javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class SearchSuggestionViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class SearchSuggestionViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData: AuthData = AuthProvider
|
||||
.with(application)
|
||||
.getAuthData()
|
||||
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper(authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authData)
|
||||
.using(HttpClient.getPreferredClient(application))
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper(authProvider.authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveSearchSuggestions: MutableLiveData<List<SearchSuggestEntry>> = MutableLiveData()
|
||||
|
||||
fun helper(): SearchHelper {
|
||||
return if (authData.isAnonymous) {
|
||||
return if (authProvider.isAnonymous) {
|
||||
webSearchHelper
|
||||
} else {
|
||||
searchHelper
|
||||
|
||||
@@ -10,13 +10,18 @@ import com.aurora.gplayapi.helpers.PurchaseHelper
|
||||
import com.aurora.store.data.event.BusEvent
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.util.ApkCopier
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class SheetsViewModel : ViewModel() {
|
||||
@HiltViewModel
|
||||
class SheetsViewModel @Inject constructor(
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val TAG = SheetsViewModel::class.java.simpleName
|
||||
|
||||
@@ -26,7 +31,7 @@ class SheetsViewModel : ViewModel() {
|
||||
fun purchase(context: Context, app: App, customVersion: Int) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val purchaseHelper = PurchaseHelper(AuthProvider.with(context).getAuthData())
|
||||
val purchaseHelper = PurchaseHelper(authProvider.authData)
|
||||
val files = purchaseHelper.purchase(app.packageName, customVersion, app.offerType)
|
||||
if (files.isNotEmpty()) {
|
||||
EventBus.getDefault()
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamBundle
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.helpers.CategoryHelper
|
||||
@@ -42,11 +41,11 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class SubCategoryClusterViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
var authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
var categoryHelper: CategoryHelper = CategoryHelper(authData)
|
||||
var categoryHelper: CategoryHelper = CategoryHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.helpers.TopChartsHelper
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
@@ -39,12 +38,12 @@ import kotlinx.coroutines.supervisorScope
|
||||
@HiltViewModel
|
||||
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
|
||||
class TopChartViewModel @Inject constructor(
|
||||
@ApplicationContext private val context: Context
|
||||
@ApplicationContext private val context: Context,
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val authData: AuthData = AuthProvider.with(context).getAuthData()
|
||||
private val topChartsHelper: TopChartsHelper =
|
||||
TopChartsHelper(authData).using(HttpClient.getPreferredClient(context))
|
||||
private val topChartsHelper: TopChartsHelper = TopChartsHelper(authProvider.authData)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<StreamCluster> = MutableLiveData()
|
||||
var streamCluster: StreamCluster = StreamCluster()
|
||||
|
||||
Reference in New Issue
Block a user