diff --git a/app/src/main/java/foundation/e/apps/manager/database/DatabaseModule.kt b/app/src/main/java/foundation/e/apps/manager/database/DatabaseModule.kt index 678c91003e2b3d3e659c9f5a0cd2d45c13a627af..d2cf3fd03a4d8efc18f104f1809df5559a0c9f27 100644 --- a/app/src/main/java/foundation/e/apps/manager/database/DatabaseModule.kt +++ b/app/src/main/java/foundation/e/apps/manager/database/DatabaseModule.kt @@ -1,7 +1,6 @@ package foundation.e.apps.manager.database import android.content.Context -import androidx.room.Room import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -13,17 +12,10 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object DatabaseModule { - - private const val DATABASE_NAME = "fused_database" - @Singleton @Provides fun provideDatabaseInstance(@ApplicationContext context: Context): FusedDatabase { - return Room.databaseBuilder( - context, - FusedDatabase::class.java, - DATABASE_NAME - ).fallbackToDestructiveMigration().build() + return FusedDatabase.getInstance(context) } @Singleton diff --git a/app/src/main/java/foundation/e/apps/manager/database/FusedDatabase.kt b/app/src/main/java/foundation/e/apps/manager/database/FusedDatabase.kt index 51f106117d9c4efafdcc4ff51e2eb8c6c42da032..c8b4c080c32f4ad90fb9ccbd575150299398ccc2 100644 --- a/app/src/main/java/foundation/e/apps/manager/database/FusedDatabase.kt +++ b/app/src/main/java/foundation/e/apps/manager/database/FusedDatabase.kt @@ -1,14 +1,33 @@ package foundation.e.apps.manager.database +import android.content.Context import androidx.room.Database +import androidx.room.Room import androidx.room.RoomDatabase import androidx.room.TypeConverters +import foundation.e.apps.api.database.AppDatabase import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.database.fusedDownload.FusedDownloadDAO @Database(entities = [FusedDownload::class], version = 2, exportSchema = false) @TypeConverters(FusedConverter::class) abstract class FusedDatabase : RoomDatabase() { - abstract fun fusedDownloadDao(): FusedDownloadDAO + + companion object { + private lateinit var INSTANCE: FusedDatabase + private const val DATABASE_NAME = "fused_database" + + fun getInstance(context: Context): FusedDatabase { + if (!Companion::INSTANCE.isInitialized) { + synchronized(AppDatabase::class) { + INSTANCE = + Room.databaseBuilder(context, FusedDatabase::class.java, DATABASE_NAME) + .fallbackToDestructiveMigration() + .build() + } + } + return INSTANCE + } + } } diff --git a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt index bd2dc6fd36534658f40642cd4cd5076bcd582de3..70ead846ce3033e223a281d155ef3ad937bde113 100644 --- a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt +++ b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt @@ -14,7 +14,6 @@ import androidx.preference.PreferenceManager import androidx.work.CoroutineWorker import androidx.work.WorkerParameters import com.aurora.gplayapi.data.models.AuthData -import com.aurora.gplayapi.helpers.PurchaseHelper import com.google.gson.Gson import dagger.assisted.Assisted import dagger.assisted.AssistedInject @@ -117,13 +116,8 @@ class UpdatesWorker @AssistedInject constructor( authData: AuthData ) { appsNeededToUpdate.forEach { fusedApp -> - if (!fusedApp.isFree) { - val purchaseHelper = PurchaseHelper(authData) - purchaseHelper.purchase( - fusedApp.package_name, - fusedApp.latest_version_code, - fusedApp.offer_type - ) + if (!fusedApp.isFree && authData.isAnonymous) { + return@forEach } val iconBase64 = getIconImageToBase64(fusedApp) @@ -144,7 +138,12 @@ class UpdatesWorker @AssistedInject constructor( fusedApp.originalSize ) - updateFusedDownloadWithAppDownloadLink(fusedApp, authData, fusedDownload) + try { + updateFusedDownloadWithAppDownloadLink(fusedApp, authData, fusedDownload) + } catch (e: Exception) { + e.printStackTrace() + return@forEach + } fusedManagerRepository.addDownload(fusedDownload) fusedManagerRepository.updateAwaiting(fusedDownload)