Redesign RepoDetailsActivity

This commit is contained in:
Thore Goebel
2025-01-16 01:38:48 +01:00
parent 921f8ad374
commit 927621f364
12 changed files with 764 additions and 762 deletions

View File

@@ -202,6 +202,14 @@ public data class Repository internal constructor(
}.ifEmpty { listOf(org.fdroid.download.Mirror(address)) }
}
public fun getAllUserMirrors(): List<org.fdroid.download.Mirror> {
return userMirrors.map { org.fdroid.download.Mirror(it) }
}
public fun getAllOfficialMirrors(): List<org.fdroid.download.Mirror> {
return getAllMirrors(false)
}
/**
* Returns all mirrors, including [disabledMirrors].
*/

View File

@@ -22,6 +22,7 @@ import org.fdroid.database.Repository
import org.fdroid.database.RepositoryDaoInt
import org.fdroid.download.DownloaderFactory
import org.fdroid.download.HttpManager
import org.fdroid.download.Mirror
import org.fdroid.repo.AddRepoState
import org.fdroid.repo.RepoAdder
import org.fdroid.repo.RepoUriGetter
@@ -238,4 +239,36 @@ public class RepoManager @JvmOverloads constructor(
return uri != null && RepoUriGetter.isSwapUri(uri)
}
public fun setMirrorEnabled(repoId: Long, mirror: Mirror, enabled: Boolean) {
val repo = repositoryDao.getRepository(repoId) ?: return
val disabled = repo.disabledMirrors.toMutableList()
if (enabled) {
if (disabled.contains(mirror.baseUrl)) {
disabled.remove(mirror.baseUrl)
repositoryDao.updateDisabledMirrors(repoId, disabled)
}
} else {
if (!disabled.contains(mirror.baseUrl)) {
disabled.add(mirror.baseUrl)
if (disabled.size == repo.getAllMirrors().size) {
// if all mirrors are disabled, re-enable canonical repo as mirror
disabled.remove(repo.address)
}
repositoryDao.updateDisabledMirrors(repoId, disabled)
}
}
}
public fun deleteUserMirror(repoId: Long, mirror: Mirror) {
val repo = repositoryDao.getRepository(repoId) ?: return
val user = repo.userMirrors.toMutableList()
if (user.contains(mirror.baseUrl)) {
user.remove(mirror.baseUrl)
repositoryDao.updateUserMirrors(repoId, user)
}
}
}