Loading app/build.gradle +6 −0 Original line number Diff line number Diff line Loading @@ -136,4 +136,10 @@ dependencies { def coroutines_version = "1.6.0" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" // Room def roomVersion = "2.4.1" kapt "androidx.room:room-compiler:$roomVersion" implementation "androidx.room:room-ktx:$roomVersion" implementation "androidx.room:room-runtime:$roomVersion" } No newline at end of file app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +2 −0 Original line number Diff line number Diff line Loading @@ -22,9 +22,11 @@ import android.app.Application import dagger.hilt.android.HiltAndroidApp import foundation.e.apps.manager.pkg.PkgManagerBR import foundation.e.apps.manager.pkg.PkgManagerModule import kotlinx.coroutines.DelicateCoroutinesApi import javax.inject.Inject @HiltAndroidApp @DelicateCoroutinesApi class AppLoungeApplication : Application() { @Inject Loading app/src/main/java/foundation/e/apps/MainActivity.kt +16 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import androidx.navigation.NavOptions import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.api.fused.data.Status import foundation.e.apps.databinding.ActivityMainBinding import foundation.e.apps.utils.USER Loading Loading @@ -117,5 +118,20 @@ class MainActivity : AppCompatActivity() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { viewModel.createNotificationChannels() } // Observe and handle downloads viewModel.downloadList.observe(this) { val installInProgress = it.any { app -> app.status == Status.DOWNLOADING || app.status == Status.INSTALLING } if (!installInProgress && it.isNotEmpty()) { for (item in it) { if (item.status == Status.QUEUED) { viewModel.downloadAndInstallApp(item) break } } } } } } app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +15 −8 Original line number Diff line number Diff line Loading @@ -18,8 +18,6 @@ package foundation.e.apps import android.app.NotificationChannel import android.app.NotificationManager import android.os.Build import androidx.annotation.RequiresApi import androidx.lifecycle.LiveData Loading @@ -31,19 +29,18 @@ import com.aurora.gplayapi.data.models.AuthData import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.manager.database.fused.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.utils.DataStoreModule import kotlinx.coroutines.launch import javax.inject.Inject import javax.inject.Named @HiltViewModel class MainActivityViewModel @Inject constructor( private val fusedAPIRepository: FusedAPIRepository, private val dataStoreModule: DataStoreModule, private val gson: Gson, private val notificationManager: NotificationManager, @Named("download") private val downloadNotificationChannel: NotificationChannel, @Named("update") private val updateNotificationChannel: NotificationChannel private val fusedManagerRepository: FusedManagerRepository ) : ViewModel() { val authDataJson: LiveData<String> = dataStoreModule.authData.asLiveData() Loading @@ -55,6 +52,10 @@ class MainActivityViewModel @Inject constructor( val authValidity: MutableLiveData<Boolean> = MutableLiveData() var authRequestRunning = false // Downloads val downloadList = fusedManagerRepository.getDownloadList() var isInstallInProgress = false fun getAuthData() { if (!authRequestRunning) { authRequestRunning = true Loading Loading @@ -85,7 +86,13 @@ class MainActivityViewModel @Inject constructor( @RequiresApi(Build.VERSION_CODES.O) fun createNotificationChannels() { notificationManager.createNotificationChannel(downloadNotificationChannel) notificationManager.createNotificationChannel(updateNotificationChannel) fusedManagerRepository.createNotificationChannels() } fun downloadAndInstallApp(fusedDownload: FusedDownload) { isInstallInProgress = true viewModelScope.launch { fusedManagerRepository.downloadAndInstallApp(fusedDownload) } } } app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +6 −29 Original line number Diff line number Diff line Loading @@ -18,11 +18,8 @@ package foundation.e.apps.api.fused import android.app.DownloadManager import android.content.Context import android.net.Uri import android.text.format.Formatter import android.util.Log import com.aurora.gplayapi.SearchSuggestEntry import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.Artwork Loading @@ -45,7 +42,6 @@ import foundation.e.apps.api.fused.utils.CategoryUtils import foundation.e.apps.api.gplay.GPlayAPIRepository import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.PreferenceManagerModule import java.io.File import javax.inject.Inject import javax.inject.Named import javax.inject.Singleton Loading @@ -54,7 +50,6 @@ import javax.inject.Singleton class FusedAPIImpl @Inject constructor( private val cleanAPKRepository: CleanAPKRepository, private val gPlayAPIRepository: GPlayAPIRepository, private val downloadManager: DownloadManager, private val pkgManagerModule: PkgManagerModule, private val preferenceManagerModule: PreferenceManagerModule, @ApplicationContext private val context: Context, Loading Loading @@ -154,24 +149,19 @@ class FusedAPIImpl @Inject constructor( return gPlayAPIRepository.validateAuthData(authData) } suspend fun getApplication( suspend fun getDownloadLink( id: String, name: String, packageName: String, versionCode: Int, offerType: Int, authData: AuthData, origin: Origin ): Long { ): String { var downloadLink = String() when (origin) { Origin.CLEANAPK -> { val downloadInfo = cleanAPKRepository.getDownloadInfo(id).body() val downloadLink = downloadInfo?.download_data?.download_link if (downloadLink != null) { return downloadApp(name, packageName, downloadLink) } else { Log.d(TAG, "Download link was null, exiting!") } downloadInfo?.download_data?.download_link?.let { downloadLink = it } } Origin.GPLAY -> { val downloadList = gPlayAPIRepository.getDownloadInfo( Loading @@ -181,12 +171,12 @@ class FusedAPIImpl @Inject constructor( authData ) // TODO: DEAL WITH MULTIPLE PACKAGES return downloadApp(name, packageName, downloadList[0].url) downloadLink = downloadList[0].url } Origin.GITLAB -> { } } return 0 return downloadLink } suspend fun listApps(category: String, browseUrl: String, authData: AuthData): List<FusedApp>? { Loading Loading @@ -493,19 +483,6 @@ class FusedAPIImpl @Inject constructor( } } /* * Download-related internal functions */ private fun downloadApp(name: String, packageName: String, url: String): Long { val packagePath = File(cacheDir, "$packageName.apk") if (packagePath.exists()) packagePath.delete() // Delete old download if-exists val request = DownloadManager.Request(Uri.parse(url)) .setTitle(name) .setDestinationUri(Uri.fromFile(packagePath)) return downloadManager.enqueue(request) } /* * Home screen-related internal functions */ Loading Loading
app/build.gradle +6 −0 Original line number Diff line number Diff line Loading @@ -136,4 +136,10 @@ dependencies { def coroutines_version = "1.6.0" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" // Room def roomVersion = "2.4.1" kapt "androidx.room:room-compiler:$roomVersion" implementation "androidx.room:room-ktx:$roomVersion" implementation "androidx.room:room-runtime:$roomVersion" } No newline at end of file
app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +2 −0 Original line number Diff line number Diff line Loading @@ -22,9 +22,11 @@ import android.app.Application import dagger.hilt.android.HiltAndroidApp import foundation.e.apps.manager.pkg.PkgManagerBR import foundation.e.apps.manager.pkg.PkgManagerModule import kotlinx.coroutines.DelicateCoroutinesApi import javax.inject.Inject @HiltAndroidApp @DelicateCoroutinesApi class AppLoungeApplication : Application() { @Inject Loading
app/src/main/java/foundation/e/apps/MainActivity.kt +16 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import androidx.navigation.NavOptions import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.api.fused.data.Status import foundation.e.apps.databinding.ActivityMainBinding import foundation.e.apps.utils.USER Loading Loading @@ -117,5 +118,20 @@ class MainActivity : AppCompatActivity() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { viewModel.createNotificationChannels() } // Observe and handle downloads viewModel.downloadList.observe(this) { val installInProgress = it.any { app -> app.status == Status.DOWNLOADING || app.status == Status.INSTALLING } if (!installInProgress && it.isNotEmpty()) { for (item in it) { if (item.status == Status.QUEUED) { viewModel.downloadAndInstallApp(item) break } } } } } }
app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +15 −8 Original line number Diff line number Diff line Loading @@ -18,8 +18,6 @@ package foundation.e.apps import android.app.NotificationChannel import android.app.NotificationManager import android.os.Build import androidx.annotation.RequiresApi import androidx.lifecycle.LiveData Loading @@ -31,19 +29,18 @@ import com.aurora.gplayapi.data.models.AuthData import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.manager.database.fused.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.utils.DataStoreModule import kotlinx.coroutines.launch import javax.inject.Inject import javax.inject.Named @HiltViewModel class MainActivityViewModel @Inject constructor( private val fusedAPIRepository: FusedAPIRepository, private val dataStoreModule: DataStoreModule, private val gson: Gson, private val notificationManager: NotificationManager, @Named("download") private val downloadNotificationChannel: NotificationChannel, @Named("update") private val updateNotificationChannel: NotificationChannel private val fusedManagerRepository: FusedManagerRepository ) : ViewModel() { val authDataJson: LiveData<String> = dataStoreModule.authData.asLiveData() Loading @@ -55,6 +52,10 @@ class MainActivityViewModel @Inject constructor( val authValidity: MutableLiveData<Boolean> = MutableLiveData() var authRequestRunning = false // Downloads val downloadList = fusedManagerRepository.getDownloadList() var isInstallInProgress = false fun getAuthData() { if (!authRequestRunning) { authRequestRunning = true Loading Loading @@ -85,7 +86,13 @@ class MainActivityViewModel @Inject constructor( @RequiresApi(Build.VERSION_CODES.O) fun createNotificationChannels() { notificationManager.createNotificationChannel(downloadNotificationChannel) notificationManager.createNotificationChannel(updateNotificationChannel) fusedManagerRepository.createNotificationChannels() } fun downloadAndInstallApp(fusedDownload: FusedDownload) { isInstallInProgress = true viewModelScope.launch { fusedManagerRepository.downloadAndInstallApp(fusedDownload) } } }
app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +6 −29 Original line number Diff line number Diff line Loading @@ -18,11 +18,8 @@ package foundation.e.apps.api.fused import android.app.DownloadManager import android.content.Context import android.net.Uri import android.text.format.Formatter import android.util.Log import com.aurora.gplayapi.SearchSuggestEntry import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.Artwork Loading @@ -45,7 +42,6 @@ import foundation.e.apps.api.fused.utils.CategoryUtils import foundation.e.apps.api.gplay.GPlayAPIRepository import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.PreferenceManagerModule import java.io.File import javax.inject.Inject import javax.inject.Named import javax.inject.Singleton Loading @@ -54,7 +50,6 @@ import javax.inject.Singleton class FusedAPIImpl @Inject constructor( private val cleanAPKRepository: CleanAPKRepository, private val gPlayAPIRepository: GPlayAPIRepository, private val downloadManager: DownloadManager, private val pkgManagerModule: PkgManagerModule, private val preferenceManagerModule: PreferenceManagerModule, @ApplicationContext private val context: Context, Loading Loading @@ -154,24 +149,19 @@ class FusedAPIImpl @Inject constructor( return gPlayAPIRepository.validateAuthData(authData) } suspend fun getApplication( suspend fun getDownloadLink( id: String, name: String, packageName: String, versionCode: Int, offerType: Int, authData: AuthData, origin: Origin ): Long { ): String { var downloadLink = String() when (origin) { Origin.CLEANAPK -> { val downloadInfo = cleanAPKRepository.getDownloadInfo(id).body() val downloadLink = downloadInfo?.download_data?.download_link if (downloadLink != null) { return downloadApp(name, packageName, downloadLink) } else { Log.d(TAG, "Download link was null, exiting!") } downloadInfo?.download_data?.download_link?.let { downloadLink = it } } Origin.GPLAY -> { val downloadList = gPlayAPIRepository.getDownloadInfo( Loading @@ -181,12 +171,12 @@ class FusedAPIImpl @Inject constructor( authData ) // TODO: DEAL WITH MULTIPLE PACKAGES return downloadApp(name, packageName, downloadList[0].url) downloadLink = downloadList[0].url } Origin.GITLAB -> { } } return 0 return downloadLink } suspend fun listApps(category: String, browseUrl: String, authData: AuthData): List<FusedApp>? { Loading Loading @@ -493,19 +483,6 @@ class FusedAPIImpl @Inject constructor( } } /* * Download-related internal functions */ private fun downloadApp(name: String, packageName: String, url: String): Long { val packagePath = File(cacheDir, "$packageName.apk") if (packagePath.exists()) packagePath.delete() // Delete old download if-exists val request = DownloadManager.Request(Uri.parse(url)) .setTitle(name) .setDestinationUri(Uri.fromFile(packagePath)) return downloadManager.enqueue(request) } /* * Home screen-related internal functions */ Loading