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