ktlint: Format all viewmodels

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-12-30 16:32:43 +08:00
parent 303a03377c
commit 6af3aa2152
23 changed files with 102 additions and 91 deletions

View File

@@ -20,6 +20,7 @@ import com.aurora.store.data.room.favourite.FavouriteDao
import com.aurora.store.data.room.favourite.ImportExport import com.aurora.store.data.room.favourite.ImportExport
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
@@ -29,7 +30,6 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class FavouriteViewModel @Inject constructor( class FavouriteViewModel @Inject constructor(

View File

@@ -33,12 +33,12 @@ import com.aurora.store.data.providers.BlacklistProvider
import com.aurora.store.util.PackageUtil import com.aurora.store.util.PackageUtil
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class InstalledViewModel @Inject constructor( class InstalledViewModel @Inject constructor(
@@ -76,5 +76,4 @@ class InstalledViewModel @Inject constructor(
.onEach { _apps.value = it } .onEach { _apps.value = it }
.launchIn(viewModelScope) .launchIn(viewModelScope)
} }
} }

View File

@@ -25,13 +25,13 @@ import com.aurora.store.data.helper.DownloadHelper
import com.aurora.store.data.helper.UpdateHelper import com.aurora.store.data.helper.UpdateHelper
import com.aurora.store.data.room.update.Update import com.aurora.store.data.room.update.Update
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlinx.coroutines.launch
@HiltViewModel @HiltViewModel
class UpdatesViewModel @Inject constructor( class UpdatesViewModel @Inject constructor(
val updateHelper: UpdateHelper, val updateHelper: UpdateHelper,
private val downloadHelper: DownloadHelper, private val downloadHelper: DownloadHelper
) : ViewModel() { ) : ViewModel() {
var updateAllEnqueued: Boolean = false var updateAllEnqueued: Boolean = false

View File

@@ -38,13 +38,13 @@ import com.aurora.store.util.AC2DMTask
import com.aurora.store.util.Preferences import com.aurora.store.util.Preferences
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import java.net.ConnectException
import java.net.UnknownHostException
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.net.ConnectException
import java.net.UnknownHostException
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class AuthViewModel @Inject constructor( class AuthViewModel @Inject constructor(
@@ -135,6 +135,7 @@ class AuthViewModel @Inject constructor(
// Generate and validate new auth // Generate and validate new auth
when (AccountProvider.getAccountType(context)) { when (AccountProvider.getAccountType(context)) {
AccountType.ANONYMOUS -> buildAnonymousAuthData() AccountType.ANONYMOUS -> buildAnonymousAuthData()
AccountType.GOOGLE -> { AccountType.GOOGLE -> {
val email = AccountProvider.getLoginEmail(context) val email = AccountProvider.getLoginEmail(context)
val tokenPair = AccountProvider.getLoginToken(context) val tokenPair = AccountProvider.getLoginToken(context)
@@ -149,7 +150,8 @@ class AuthViewModel @Inject constructor(
} }
AuthHelper.Token.AUTH -> { AuthHelper.Token.AUTH -> {
_authState.value = AuthState.PendingAccountManager(email, tokenPair.first) _authState.value =
AuthState.PendingAccountManager(email, tokenPair.first)
} }
} }
} }

View File

@@ -22,12 +22,12 @@ import com.aurora.store.util.PackageUtil
import com.aurora.store.util.Preferences import com.aurora.store.util.Preferences
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class BlacklistViewModel @Inject constructor( class BlacklistViewModel @Inject constructor(
@@ -44,7 +44,7 @@ class BlacklistViewModel @Inject constructor(
private val isExtendedUpdateEnabled = private val isExtendedUpdateEnabled =
Preferences.getBoolean(context, Preferences.PREFERENCE_UPDATES_EXTENDED) Preferences.getBoolean(context, Preferences.PREFERENCE_UPDATES_EXTENDED)
private val _packages = MutableStateFlow<List<PackageInfo>?>(null) private val packages = MutableStateFlow<List<PackageInfo>?>(null)
private val _filteredPackages = MutableStateFlow<List<PackageInfo>?>(null) private val _filteredPackages = MutableStateFlow<List<PackageInfo>?>(null)
val filteredPackages = _filteredPackages.asStateFlow() val filteredPackages = _filteredPackages.asStateFlow()
@@ -58,7 +58,7 @@ class BlacklistViewModel @Inject constructor(
private fun fetchApps() { private fun fetchApps() {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
_packages.value = PackageUtil.getAllValidPackages(context).also { pkgList -> packages.value = PackageUtil.getAllValidPackages(context).also { pkgList ->
_filteredPackages.value = pkgList _filteredPackages.value = pkgList
} }
} catch (exception: Exception) { } catch (exception: Exception) {
@@ -69,22 +69,27 @@ class BlacklistViewModel @Inject constructor(
fun search(query: String) { fun search(query: String) {
if (query.isNotBlank()) { if (query.isNotBlank()) {
_filteredPackages.value = _packages.value!! _filteredPackages.value = packages.value!!
.filter { it.applicationInfo!!.loadLabel(context.packageManager) .filter {
.contains(query, true) || it.packageName.contains(query, true) it.applicationInfo!!.loadLabel(context.packageManager)
.contains(query, true) || it.packageName.contains(query, true)
} }
} else { } else {
_filteredPackages.value = _packages.value _filteredPackages.value = packages.value
} }
} }
fun isFiltered(packageInfo: PackageInfo): Boolean { fun isFiltered(packageInfo: PackageInfo): Boolean = when {
return when { !isExtendedUpdateEnabled && !packageInfo.applicationInfo!!.enabled -> true
!isExtendedUpdateEnabled && !packageInfo.applicationInfo!!.enabled -> true
isAuroraOnlyFilterEnabled -> !CertUtil.isAuroraStoreApp(context, packageInfo.packageName) isAuroraOnlyFilterEnabled -> !CertUtil.isAuroraStoreApp(
isFDroidFilterEnabled -> CertUtil.isFDroidApp(context, packageInfo.packageName) context,
else -> false packageInfo.packageName
} )
isFDroidFilterEnabled -> CertUtil.isFDroidApp(context, packageInfo.packageName)
else -> false
} }
fun blacklist(packageName: String) { fun blacklist(packageName: String) {
@@ -94,7 +99,7 @@ class BlacklistViewModel @Inject constructor(
} }
fun blacklistAll() { fun blacklistAll() {
blacklistProvider.blacklist = _packages.value!!.map { it.packageName }.toMutableSet() blacklistProvider.blacklist = packages.value!!.map { it.packageName }.toMutableSet()
blacklist.apply { blacklist.apply {
clear() clear()
addAll(blacklistProvider.blacklist) addAll(blacklistProvider.blacklist)
@@ -121,7 +126,7 @@ class BlacklistViewModel @Inject constructor(
) )
val validImportedSet = importedSet val validImportedSet = importedSet
.filter { pkgName -> _packages.value!!.any { it.packageName == pkgName } } .filter { pkgName -> packages.value!!.any { it.packageName == pkgName } }
blacklistProvider.blacklist.addAll(validImportedSet) blacklistProvider.blacklist.addAll(validImportedSet)
blacklist.apply { blacklist.apply {
clear() clear()

View File

@@ -27,10 +27,10 @@ import com.aurora.extensions.TAG
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 dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope import kotlinx.coroutines.supervisorScope
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class ExpandedStreamBrowseViewModel @Inject constructor( class ExpandedStreamBrowseViewModel @Inject constructor(

View File

@@ -27,9 +27,9 @@ import com.aurora.extensions.TAG
import com.aurora.gplayapi.data.models.StreamCluster import com.aurora.gplayapi.data.models.StreamCluster
import com.aurora.gplayapi.helpers.web.WebStreamHelper import com.aurora.gplayapi.helpers.web.WebStreamHelper
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class StreamBrowseViewModel @Inject constructor( class StreamBrowseViewModel @Inject constructor(

View File

@@ -30,9 +30,9 @@ import com.aurora.gplayapi.helpers.contracts.CategoryContract
import com.aurora.store.CategoryStash import com.aurora.store.CategoryStash
import com.aurora.store.data.model.ViewState import com.aurora.store.data.model.ViewState
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class CategoryViewModel @Inject constructor( class CategoryViewModel @Inject constructor(
@@ -46,9 +46,7 @@ class CategoryViewModel @Inject constructor(
val liveData = MutableLiveData<ViewState>() val liveData = MutableLiveData<ViewState>()
private fun contract(): CategoryContract { private fun contract(): CategoryContract = categoryHelper
return categoryHelper
}
fun getCategoryList(type: Category.Type) { fun getCategoryList(type: Category.Type) {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
@@ -68,9 +66,7 @@ class CategoryViewModel @Inject constructor(
} }
} }
private fun getCategories(type: Category.Type): List<Category> { private fun getCategories(type: Category.Type): List<Category> = stash.getOrPut(type) {
return stash.getOrPut(type) { mutableListOf()
mutableListOf()
}
} }
} }

View File

@@ -10,9 +10,9 @@ import androidx.lifecycle.ViewModel
import com.aurora.store.data.providers.PermissionProvider import com.aurora.store.data.providers.PermissionProvider
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class PermissionRationaleViewModel @Inject constructor( class PermissionRationaleViewModel @Inject constructor(

View File

@@ -16,6 +16,7 @@ import com.aurora.extensions.TAG
import com.aurora.extensions.requiresGMS import com.aurora.extensions.requiresGMS
import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.App
import com.aurora.gplayapi.data.models.Review import com.aurora.gplayapi.data.models.Review
import com.aurora.gplayapi.data.models.datasafety.Report as DataSafetyReport
import com.aurora.gplayapi.data.models.details.TestingProgramStatus import com.aurora.gplayapi.data.models.details.TestingProgramStatus
import com.aurora.gplayapi.helpers.AppDetailsHelper import com.aurora.gplayapi.helpers.AppDetailsHelper
import com.aurora.gplayapi.helpers.ReviewsHelper import com.aurora.gplayapi.helpers.ReviewsHelper
@@ -40,6 +41,7 @@ import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_EXTENDED import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_EXTENDED
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
@@ -53,8 +55,6 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject
import com.aurora.gplayapi.data.models.datasafety.Report as DataSafetyReport
@HiltViewModel @HiltViewModel
class AppDetailsViewModel @Inject constructor( class AppDetailsViewModel @Inject constructor(
@@ -232,7 +232,7 @@ class AppDetailsViewModel @Inject constructor(
displayName = app.displayName, displayName = app.displayName,
iconURL = app.iconArtwork.url, iconURL = app.iconArtwork.url,
mode = Favourite.Mode.MANUAL, mode = Favourite.Mode.MANUAL,
added = System.currentTimeMillis(), added = System.currentTimeMillis()
) )
) )
} }
@@ -260,7 +260,9 @@ class AppDetailsViewModel @Inject constructor(
) )
DownloadStatus.QUEUED -> AppState.Queued DownloadStatus.QUEUED -> AppState.Queued
DownloadStatus.PURCHASING -> AppState.Purchasing DownloadStatus.PURCHASING -> AppState.Purchasing
else -> defaultAppState else -> defaultAppState
} }
}.launchIn(viewModelScope) }.launchIn(viewModelScope)
@@ -275,7 +277,6 @@ class AppDetailsViewModel @Inject constructor(
_featuredReviews.value = emptyList() _featuredReviews.value = emptyList()
} }
} }
} }
private fun fetchFavourite(packageName: String) { private fun fetchFavourite(packageName: String) {
@@ -350,7 +351,7 @@ class AppDetailsViewModel @Inject constructor(
} }
private fun getPlexusReport(packageName: String): PlexusReport? { private fun getPlexusReport(packageName: String): PlexusReport? {
val url = "${Constants.PLEXUS_API_URL}/${packageName}/?scores=true" val url = "${Constants.PLEXUS_API_URL}/$packageName/?scores=true"
val playResponse = httpClient.get(url, emptyMap()) val playResponse = httpClient.get(url, emptyMap())
return json.decodeFromString<PlexusReport>(String(playResponse.responseBytes)) return json.decodeFromString<PlexusReport>(String(playResponse.responseBytes))
} }

View File

@@ -32,10 +32,10 @@ import com.aurora.gplayapi.helpers.StreamHelper
import com.aurora.gplayapi.helpers.contracts.StreamContract import com.aurora.gplayapi.helpers.contracts.StreamContract
import com.aurora.store.data.model.ViewState import com.aurora.store.data.model.ViewState
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope import kotlinx.coroutines.supervisorScope
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class DevProfileViewModel @Inject constructor( class DevProfileViewModel @Inject constructor(
@@ -44,7 +44,7 @@ class DevProfileViewModel @Inject constructor(
) : ViewModel() { ) : ViewModel() {
val liveData: MutableLiveData<ViewState> = MutableLiveData() val liveData: MutableLiveData<ViewState> = MutableLiveData()
var devStream:DevStream = DevStream() var devStream: DevStream = DevStream()
var streamBundle: StreamBundle = StreamBundle() var streamBundle: StreamBundle = StreamBundle()
lateinit var type: StreamContract.Type lateinit var type: StreamContract.Type
@@ -69,7 +69,9 @@ class DevProfileViewModel @Inject constructor(
supervisorScope { supervisorScope {
try { try {
if (streamCluster.hasNext()) { if (streamCluster.hasNext()) {
val newCluster = streamHelper.getNextStreamCluster(streamCluster.clusterNextPageUrl) val newCluster = streamHelper.getNextStreamCluster(
streamCluster.clusterNextPageUrl
)
updateCluster(newCluster) updateCluster(newCluster)
devStream = devStream.copy(streamBundle = streamBundle) devStream = devStream.copy(streamBundle = streamBundle)
liveData.postValue(ViewState.Success(devStream)) liveData.postValue(ViewState.Success(devStream))

View File

@@ -10,12 +10,12 @@ import androidx.lifecycle.viewModelScope
import com.aurora.store.data.model.ExodusTracker import com.aurora.store.data.model.ExodusTracker
import com.aurora.store.data.model.Report import com.aurora.store.data.model.Report
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class ExodusViewModel @Inject constructor( class ExodusViewModel @Inject constructor(

View File

@@ -21,7 +21,7 @@ import kotlinx.coroutines.flow.asStateFlow
class PermissionViewModel @AssistedInject constructor( class PermissionViewModel @AssistedInject constructor(
@Assisted private val permissions: List<String>, @Assisted private val permissions: List<String>,
@ApplicationContext private val context: Context @ApplicationContext private val context: Context
): ViewModel() { ) : ViewModel() {
@AssistedFactory @AssistedFactory
interface Factory { interface Factory {
@@ -42,11 +42,9 @@ class PermissionViewModel @AssistedInject constructor(
}.toMap() }.toMap()
} }
private fun getPermissionInfo(permissionName: String): PermissionInfo? { private fun getPermissionInfo(permissionName: String): PermissionInfo? = try {
return try { context.packageManager.getPermissionInfo(permissionName, 0)
context.packageManager.getPermissionInfo(permissionName, 0) } catch (_: PackageManager.NameNotFoundException) {
} catch (_: PackageManager.NameNotFoundException) { null
null
}
} }
} }

View File

@@ -20,6 +20,7 @@ import com.aurora.store.data.room.download.Download
import com.aurora.store.data.work.ExportWorker import com.aurora.store.data.work.ExportWorker
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
@@ -27,7 +28,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class DownloadsViewModel @Inject constructor( class DownloadsViewModel @Inject constructor(

View File

@@ -31,11 +31,11 @@ import com.aurora.gplayapi.helpers.web.WebStreamHelper
import com.aurora.store.HomeStash import com.aurora.store.HomeStash
import com.aurora.store.data.model.ViewState import com.aurora.store.data.model.ViewState
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class StreamViewModel @Inject constructor( class StreamViewModel @Inject constructor(
@@ -69,7 +69,6 @@ class StreamViewModel @Inject constructor(
} }
if (!bundle.hasCluster() || bundle.hasNext()) { if (!bundle.hasCluster() || bundle.hasNext()) {
// Fetch new stream bundle // Fetch new stream bundle
val newBundle = if (bundle.hasCluster()) { val newBundle = if (bundle.hasCluster()) {
streamContract.nextStreamBundle( streamContract.nextStreamBundle(
@@ -157,7 +156,8 @@ class StreamViewModel @Inject constructor(
stash[category] = bundle.copy(streamClusters = updatedClusters) stash[category] = bundle.copy(streamClusters = updatedClusters)
} }
private fun targetBundle(category: StreamContract.Category): StreamBundle { private fun targetBundle(category: StreamContract.Category): StreamBundle =
return stash.getOrPut(category) { StreamBundle() } stash.getOrPut(category) {
} StreamBundle()
}
} }

View File

@@ -21,11 +21,11 @@ import com.aurora.store.data.room.suite.ExternalApk
import com.aurora.store.util.PackageUtil import com.aurora.store.util.PackageUtil
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject
data class MicroGUIState( data class MicroGUIState(
var isDownloading: Boolean = false, var isDownloading: Boolean = false,
@@ -40,18 +40,26 @@ class MicroGViewModel @Inject constructor(
) : ViewModel() { ) : ViewModel() {
companion object { companion object {
private const val MICROG_DOWNLOAD_URL = private const val BASE_URL =
"https://github.com/microg/GmsCore/releases/download" "https://github.com/microg/GmsCore/releases/download"
private const val MICROG_VERSION = "v0.3.11.250932" private const val MICROG_VERSION = "v0.3.11.250932"
private const val GMS_VERSION_CODE = 250932022 private const val GMS_VERSION_CODE = 250932022
private const val COMPANION_VERSION_CODE = 84022622 private const val COMPANION_VERSION_CODE = 84022622
private const val MICROG_DOWNLOAD_URL =
"$BASE_URL/$MICROG_VERSION/$PACKAGE_NAME_GMS-$GMS_VERSION_CODE-hw.apk"
private const val FAKE_STORE_DOWNLOAD_URL =
"$BASE_URL/$MICROG_VERSION/$PACKAGE_NAME_PLAY_STORE-$COMPANION_VERSION_CODE-hw.apk"
private const val ICON_BASE_URL = "https://raw.githubusercontent.com/microg"
private const val ICON_FILE_PATH = "src/main/res/mipmap-xxxhdpi/ic_app.png"
} }
init { init {
AuroraApp.events.installerEvent.onEach { AuroraApp.events.installerEvent.onEach {
when (it) { when (it) {
is InstallerEvent.Installed -> confirmBundleInstall(it.packageName) is InstallerEvent.Installed -> confirmBundleInstall()
else -> {} else -> {}
} }
}.launchIn(AuroraApp.scope) }.launchIn(AuroraApp.scope)
} }
@@ -64,11 +72,11 @@ class MicroGViewModel @Inject constructor(
versionCode = GMS_VERSION_CODE.toLong(), versionCode = GMS_VERSION_CODE.toLong(),
versionName = MICROG_VERSION, versionName = MICROG_VERSION,
displayName = "microG Services", displayName = "microG Services",
iconURL = "https://raw.githubusercontent.com/microg/GmsCore/refs/heads/master/play-services-core/src/main/res/mipmap-xxxhdpi/ic_app.png", iconURL = "$ICON_BASE_URL/GmsCore/refs/heads/master/play-services-core/$ICON_FILE_PATH",
developerName = "microG Team", developerName = "microG Team",
fileList = listOf( fileList = listOf(
PlayFile( PlayFile(
url = "$MICROG_DOWNLOAD_URL/$MICROG_VERSION/$PACKAGE_NAME_GMS-$GMS_VERSION_CODE-hw.apk", url = MICROG_DOWNLOAD_URL,
name = "$PACKAGE_NAME_GMS-$GMS_VERSION_CODE-hw.apk", name = "$PACKAGE_NAME_GMS-$GMS_VERSION_CODE-hw.apk",
size = 92386474, size = 92386474,
sha256 = "2894a93544a8d7ca8f6ca96e7cc697647a7e0862165b6a02f8cd26822759b9cc" sha256 = "2894a93544a8d7ca8f6ca96e7cc697647a7e0862165b6a02f8cd26822759b9cc"
@@ -81,11 +89,11 @@ class MicroGViewModel @Inject constructor(
versionCode = COMPANION_VERSION_CODE.toLong(), versionCode = COMPANION_VERSION_CODE.toLong(),
versionName = MICROG_VERSION, versionName = MICROG_VERSION,
displayName = "microG Companion", displayName = "microG Companion",
iconURL = "https://raw.githubusercontent.com/microg/FakeStore/refs/heads/main/fake-store/src/main/res/mipmap-xxxhdpi/ic_app.png", iconURL = "$ICON_BASE_URL/FakeStore/refs/heads/main/fake-store/$ICON_FILE_PATH",
developerName = "microG Team", developerName = "microG Team",
fileList = listOf( fileList = listOf(
PlayFile( PlayFile(
url = "$MICROG_DOWNLOAD_URL/$MICROG_VERSION/$PACKAGE_NAME_PLAY_STORE-$COMPANION_VERSION_CODE-hw.apk", url = FAKE_STORE_DOWNLOAD_URL,
name = "$PACKAGE_NAME_PLAY_STORE-$COMPANION_VERSION_CODE-hw.apk", name = "$PACKAGE_NAME_PLAY_STORE-$COMPANION_VERSION_CODE-hw.apk",
size = 4626291, size = 4626291,
sha256 = "b9623b8da8791c7e887efca941434b20e517c8a42ca4fda713625957edcc84eb" sha256 = "b9623b8da8791c7e887efca941434b20e517c8a42ca4fda713625957edcc84eb"
@@ -111,7 +119,7 @@ class MicroGViewModel @Inject constructor(
} }
} }
fun confirmBundleInstall(packageName: String) { private fun confirmBundleInstall() {
if (PackageUtil.isMicroGBundleInstalled(context)) { if (PackageUtil.isMicroGBundleInstalled(context)) {
uiState = uiState.copy(isInstalled = true, isDownloading = false) uiState = uiState.copy(isInstalled = true, isDownloading = false)
} }

View File

@@ -44,9 +44,9 @@ import com.aurora.store.util.save
import com.jakewharton.processphoenix.ProcessPhoenix import com.jakewharton.processphoenix.ProcessPhoenix
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import javax.inject.Inject
data class OnboardingUiState( data class OnboardingUiState(
val isMicroBundleChecked: Boolean = false, val isMicroBundleChecked: Boolean = false,
@@ -69,7 +69,7 @@ class OnboardingViewModel @Inject constructor(
AuroraApp.events.installerEvent.onEach { AuroraApp.events.installerEvent.onEach {
when (it) { when (it) {
is InstallerEvent.Installed -> confirmBundleInstall() is InstallerEvent.Installed -> confirmBundleInstall()
else -> {} else -> {}
} }
}.launchIn(AuroraApp.scope) }.launchIn(AuroraApp.scope)
} }
@@ -104,8 +104,8 @@ class OnboardingViewModel @Inject constructor(
private fun setupAutoUpdates() { private fun setupAutoUpdates() {
val updateMode = when { val updateMode = when {
context.isIgnoringBatteryOptimizations() -> UpdateMode.CHECK_AND_INSTALL context.isIgnoringBatteryOptimizations() -> UpdateMode.CHECK_AND_INSTALL
context.areNotificationsEnabled() -> UpdateMode.CHECK_AND_NOTIFY context.areNotificationsEnabled() -> UpdateMode.CHECK_AND_NOTIFY
else -> UpdateMode.DISABLED else -> UpdateMode.DISABLED
} }
context.save(PREFERENCE_UPDATES_AUTO, updateMode.ordinal) context.save(PREFERENCE_UPDATES_AUTO, updateMode.ordinal)

View File

@@ -23,17 +23,19 @@ import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
import com.aurora.store.util.save import com.aurora.store.util.save
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
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 rikka.shizuku.Shizuku import rikka.shizuku.Shizuku
import rikka.sui.Sui import rikka.sui.Sui
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class InstallerViewModel @Inject constructor( class InstallerViewModel @Inject constructor(
@ApplicationContext private val context: Context @ApplicationContext private val context: Context
) : ViewModel(), Shizuku.OnBinderReceivedListener, Shizuku.OnBinderDeadListener, ) : ViewModel(),
Shizuku.OnBinderReceivedListener,
Shizuku.OnBinderDeadListener,
Shizuku.OnRequestPermissionResultListener { Shizuku.OnRequestPermissionResultListener {
private val sharedPreferences = Preferences.getPrefs(context) private val sharedPreferences = Preferences.getPrefs(context)

View File

@@ -7,8 +7,8 @@ package com.aurora.store.viewmodel.preferences
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.serialization.json.Json
import javax.inject.Inject import javax.inject.Inject
import kotlinx.serialization.json.Json
@HiltViewModel @HiltViewModel
class ProxyURLViewModel @Inject constructor(val json: Json) : ViewModel() class ProxyURLViewModel @Inject constructor(val json: Json) : ViewModel()

View File

@@ -24,6 +24,7 @@ import com.aurora.store.data.model.SearchFilter
import com.aurora.store.data.paging.GenericPagingSource.Companion.manualPager import com.aurora.store.data.paging.GenericPagingSource.Companion.manualPager
import com.aurora.store.data.providers.AuthProvider import com.aurora.store.data.providers.AuthProvider
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
@@ -34,7 +35,6 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class SearchViewModel @Inject constructor( class SearchViewModel @Inject constructor(
@@ -72,14 +72,12 @@ class SearchViewModel @Inject constructor(
var nextBundleUrl: String? = null var nextBundleUrl: String? = null
val nextStreamUrls = mutableSetOf<String>() val nextStreamUrls = mutableSetOf<String>()
fun Collection<StreamCluster>.flatClusters(): List<App> { fun Collection<StreamCluster>.flatClusters(): List<App> = this.flatMap { streamCluster ->
return this.flatMap { streamCluster -> if (streamCluster.hasNext()) {
if (streamCluster.hasNext()) { nextStreamUrls.add(streamCluster.clusterNextPageUrl)
nextStreamUrls.add(streamCluster.clusterNextPageUrl) }
} streamCluster.clusterAppList
streamCluster.clusterAppList }.distinctBy { app -> app.packageName }
}.distinctBy { app -> app.packageName }
}
manualPager { page -> manualPager { page ->
try { try {

View File

@@ -10,11 +10,11 @@ import com.aurora.store.data.providers.SpoofProvider
import com.aurora.store.util.PathUtil import com.aurora.store.util.PathUtil
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import java.util.Locale import java.util.Locale
import java.util.Properties import java.util.Properties
import javax.inject.Inject import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
@HiltViewModel @HiltViewModel
class SpoofViewModel @Inject constructor( class SpoofViewModel @Inject constructor(

View File

@@ -31,10 +31,10 @@ import com.aurora.gplayapi.helpers.contracts.StreamContract
import com.aurora.gplayapi.helpers.web.WebCategoryStreamHelper import com.aurora.gplayapi.helpers.web.WebCategoryStreamHelper
import com.aurora.store.data.model.ViewState import com.aurora.store.data.model.ViewState
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope import kotlinx.coroutines.supervisorScope
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class CategoryStreamViewModel @Inject constructor( class CategoryStreamViewModel @Inject constructor(
@@ -64,7 +64,7 @@ class CategoryStreamViewModel @Inject constructor(
try { try {
if (!bundle.hasCluster() || bundle.hasNext()) { if (!bundle.hasCluster() || bundle.hasNext()) {
//Fetch new stream bundle // Fetch new stream bundle
val newBundle = if (bundle.streamClusters.isEmpty()) { val newBundle = if (bundle.streamClusters.isEmpty()) {
categoryStreamContract.fetch(browseUrl) categoryStreamContract.fetch(browseUrl)
} else { } else {
@@ -74,14 +74,14 @@ class CategoryStreamViewModel @Inject constructor(
) )
} }
//Update old bundle // Update old bundle
val mergedBundle = bundle.copy( val mergedBundle = bundle.copy(
streamClusters = bundle.streamClusters + newBundle.streamClusters, streamClusters = bundle.streamClusters + newBundle.streamClusters,
streamNextPageUrl = newBundle.streamNextPageUrl streamNextPageUrl = newBundle.streamNextPageUrl
) )
stash[browseUrl] = mergedBundle stash[browseUrl] = mergedBundle
//Post updated to UI // Post updated to UI
liveData.postValue(ViewState.Success(stash)) liveData.postValue(ViewState.Success(stash))
} else { } else {
Log.i(TAG, "End of Bundle") Log.i(TAG, "End of Bundle")

View File

@@ -28,15 +28,15 @@ import com.aurora.gplayapi.helpers.web.WebTopChartsHelper
import com.aurora.store.TopChartStash import com.aurora.store.TopChartStash
import com.aurora.store.data.model.ViewState import com.aurora.store.data.model.ViewState
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope import kotlinx.coroutines.supervisorScope
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class TopChartViewModel @Inject constructor( class TopChartViewModel @Inject constructor(
private val webTopChartsHelper: WebTopChartsHelper private val webTopChartsHelper: WebTopChartsHelper
): ViewModel() { ) : ViewModel() {
private var stash: TopChartStash = mutableMapOf() private var stash: TopChartStash = mutableMapOf()