Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,230 changes: 2,230 additions & 0 deletions schemas/com.machiav3lli.fdroid.data.database.DatabaseX/1209.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import java.io.File
DownloadStats::class,
DownloadStatsFileMetadata::class,
],
version = 1208,
version = 1209,
exportSchema = true,
views = [
PackageSum::class,
Expand Down Expand Up @@ -313,6 +313,11 @@ import java.io.File
from = 1207,
to = 1208,
),
AutoMigration(
from = 1208,
to = 1209,
spec = DatabaseX.Companion.ProductsCleanupKeepDownloaded::class
),
]
)
@TypeConverters(Converters::class)
Expand Down Expand Up @@ -537,6 +542,22 @@ abstract class DatabaseX : RoomDatabase() {
}
}

class ProductsCleanupKeepDownloaded : AutoMigrationSpec {
override fun onPostMigrate(db: SupportSQLiteDatabase) {
super.onPostMigrate(db)
GlobalScope.launch(Dispatchers.IO) {
get<DatabaseX>(DatabaseX::class.java).apply {
withTransaction {
getProductDao().emptyTable()
getCategoryDao().emptyTable()
getReleaseDao().emptyTable()
getRepositoryDao().forgetLastModifications()
}
}
}
}
}

class ProductsCleanup : AutoMigrationSpec {
override fun onPostMigrate(db: SupportSQLiteDatabase) {
super.onPostMigrate(db)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ open class IndexProduct(
}.toMutableList()

val predicate: (Release) -> Boolean = {
unstable || (!it.releaseChannels.contains("Beta") && suggestedVersionCode <= 0) ||
it.versionCode <= suggestedVersionCode
unstable || it.isStable
}
val firstCompatibleReleaseIndex =
releasePairs.indexOfFirst { it.second.isEmpty() && predicate(it.first) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ data class EmbeddedProduct(
}.toImmutableList()

val predicate: (Release) -> Boolean = {
unstable || (!it.releaseChannels.contains("Beta") && product.suggestedVersionCode <= 0) ||
it.versionCode <= product.suggestedVersionCode
unstable || it.isStable
}
val firstCompatibleReleaseIndex =
releasePairs.indexOfFirst { it.second.isEmpty() && predicate(it.first) }
Expand Down Expand Up @@ -328,4 +327,4 @@ data class ProductIconDetails(
val repositoryId: Long,
val icon: String,
val metadataIcon: String
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ open class Release(
val isCompatible: Boolean,
@ColumnInfo(defaultValue = "[]")
val releaseChannels: List<String> = emptyList(),
@ColumnInfo(defaultValue = "0")
val isStable: Boolean,
) {
@Serializable
sealed class Incompatibility {
Expand Down Expand Up @@ -140,6 +142,7 @@ open class Release(
incompatibilities = incompatibilities,
isCompatible = incompatibilities.isEmpty(),
releaseChannels = releaseChannels,
isStable = isStable,
)
}

Expand Down Expand Up @@ -172,6 +175,7 @@ class ReleaseTemp(
incompatibilities: List<Incompatibility>,
isCompatible: Boolean,
releaseChannels: List<String>,
isStable: Boolean,
) : Release(
packageName = packageName,
repositoryId = repositoryId,
Expand Down Expand Up @@ -200,6 +204,7 @@ class ReleaseTemp(
incompatibilities = incompatibilities,
isCompatible = isCompatible,
releaseChannels = releaseChannels,
isStable = isStable,
)

fun Release.asReleaseTemp() = ReleaseTemp(
Expand Down Expand Up @@ -230,4 +235,5 @@ fun Release.asReleaseTemp() = ReleaseTemp(
incompatibilities = incompatibilities,
isCompatible = isCompatible,
releaseChannels = releaseChannels,
isStable = isStable,
)
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class IndexV0Parser(private val repositoryId: Long, private val callback: Callba
var obbMainHash = ""
var obbPatch = ""
var obbPatchHash = ""
var isStable = false
val permissions = linkedSetOf<String>()
val features = linkedSetOf<String>()
val platforms = linkedSetOf<String>()
Expand Down Expand Up @@ -170,6 +171,7 @@ class IndexV0Parser(private val repositoryId: Long, private val callback: Callba
platforms = platforms.toList(),
incompatibilities = emptyList(),
isCompatible = true,
isStable = isStable,
)
}
}
Expand Down Expand Up @@ -338,8 +340,11 @@ class IndexV0Parser(private val repositoryId: Long, private val callback: Callba
-> releaseBuilder.version = readText()

"versioncode"
-> releaseBuilder.versionCode =
readText().toLongOrNull() ?: 0L
-> {
releaseBuilder.versionCode = readText().toLongOrNull() ?: 0L
releaseBuilder.isStable = productBuilder.suggestedVersionCode
.let { it <= 0 || releaseBuilder.versionCode <= it }
}

"added"
-> releaseBuilder.added = readText().parseDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ internal fun IndexV1.App.toProduct(repositoryId: Long) = IndexProduct(

internal fun IndexV1.Package.toRelease(
repositoryId: Long,
packageName: String
product: IndexV1.App
) = Release(
packageName = packageName,
packageName = product.packageName,
repositoryId = repositoryId,
selected = false,
version = versionName,
Expand Down Expand Up @@ -112,6 +112,8 @@ internal fun IndexV1.Package.toRelease(
platforms = nativecode,
incompatibilities = emptyList(),
isCompatible = true,
isStable = product.suggestedVersionCode.toLongOrDefault(0L)
.let { it <= 0 || versionCode <= it },
)

internal fun Map<String, IndexV1.Localized>.findLocalizedString(
Expand Down Expand Up @@ -204,4 +206,4 @@ private fun <T> Map<String, IndexV1.Localized>.getAndCall(
callback: (String, IndexV1.Localized) -> T?,
): T? {
return this[key]?.let { callback(key, it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class IndexV1Parser(private val repositoryId: Long, private val callback: Callba

indexV1.apps.forEach { product ->
callback.onProduct(product.toProduct(repositoryId))
}

indexV1.packages.forEach { (packageName, releases) ->
callback.onReleases(
packageName,
releases.map { it.toRelease(repositoryId, packageName) },
)
indexV1.packages[product.packageName]?.let { releases ->
callback.onReleases(
product.packageName,
releases.map { it.toRelease(repositoryId, product) },
)
}
}
} catch (e: Exception) {
throw ParsingException("Error parsing index", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ internal fun IndexV2.Version.toRelease(
incompatibilities = emptyList(),
isCompatible = true,
releaseChannels = releaseChannels,
isStable = releaseChannels.isEmpty(),
)

internal fun <T> Localized<T>?.findLocalized(fallback: T): T =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import androidx.core.content.res.ResourcesCompat
import androidx.core.net.toUri
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.machiav3lli.fdroid.BuildConfig
import com.machiav3lli.fdroid.NeoApp
import com.machiav3lli.fdroid.R
import com.machiav3lli.fdroid.data.content.Preferences
import com.machiav3lli.fdroid.data.content.SAFFile
Expand All @@ -57,6 +56,7 @@ import com.machiav3lli.fdroid.ui.components.prefs.BasePreference
import com.machiav3lli.fdroid.ui.components.prefs.PreferenceGroup
import com.machiav3lli.fdroid.ui.compose.icons.Phosphor
import com.machiav3lli.fdroid.ui.compose.icons.phosphor.CircleWavyWarning
import com.machiav3lli.fdroid.utils.Utils.startUpdate
import com.machiav3lli.fdroid.utils.currentTimestamp
import com.machiav3lli.fdroid.utils.extension.koinNeoViewModel
import com.machiav3lli.fdroid.utils.isDefaultAppHandler
Expand Down Expand Up @@ -169,17 +169,19 @@ fun PrefsOtherPage(
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)

val repos = pageState.repos.associateBy { it.id }
SAFFile(context, resultUri).read()
?.split(">")
?.filterNot { pageState.installedMap.keys.contains(it) }
?.forEach { packageName ->
scope.launch(Dispatchers.IO) {
productRepo.loadProduct(packageName)
.maxByOrNull { it.product.suggestedVersionCode }?.toItem()?.let {
NeoApp.wm.install(
Pair(it.packageName, it.repositoryId)
)
}
startUpdate(
packageName,
null,
productRepo.loadProduct(packageName).mapNotNull { ep ->
repos[ep.product.repositoryId]?.let { Pair(ep, it) }
},
)
}
}
// TODO add notification about success or failure
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/machiav3lli/fdroid/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ object Utils {
}

private fun List<Release>.getBestRelease(installedVersionCode: Long): Release? {
filter { it.versionCode > installedVersionCode }
filter { it.versionCode > installedVersionCode && (Preferences[Preferences.Key.UpdateUnstable] || it.isStable) }
.apply {
if (isEmpty()) return null
if (size == 1) return first()
Expand Down