This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finish implementing the sources system (#70)
- Loading branch information
Showing
60 changed files
with
1,544 additions
and
1,059 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/app/revanced/manager/data/platform/NetworkInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.revanced.manager.data.platform | ||
|
||
import android.app.Application | ||
import android.net.ConnectivityManager | ||
import android.net.NetworkCapabilities | ||
import androidx.core.content.getSystemService | ||
|
||
class NetworkInfo(app: Application) { | ||
private val connectivityManager = app.getSystemService<ConnectivityManager>()!! | ||
|
||
private fun getCapabilities() = connectivityManager.activeNetwork?.let { connectivityManager.getNetworkCapabilities(it) } | ||
fun isConnected() = connectivityManager.activeNetwork != null | ||
fun isUnmetered() = getCapabilities()?.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) ?: true | ||
|
||
/** | ||
* Returns true if it is safe to download large files. | ||
*/ | ||
fun isSafe() = isConnected() && isUnmetered() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 3 additions & 6 deletions
9
app/src/main/java/app/revanced/manager/data/room/Converters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/app/revanced/manager/data/room/bundles/PatchBundleDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package app.revanced.manager.data.room.bundles | ||
|
||
import androidx.room.* | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface PatchBundleDao { | ||
@Query("SELECT * FROM patch_bundles") | ||
suspend fun all(): List<PatchBundleEntity> | ||
|
||
@Query("SELECT version, integrations_version, auto_update FROM patch_bundles WHERE uid = :uid") | ||
fun getPropsById(uid: Int): Flow<BundleProperties> | ||
|
||
@Query("UPDATE patch_bundles SET version = :patches, integrations_version = :integrations WHERE uid = :uid") | ||
suspend fun updateVersion(uid: Int, patches: String?, integrations: String?) | ||
|
||
@Query("UPDATE patch_bundles SET auto_update = :value WHERE uid = :uid") | ||
suspend fun setAutoUpdate(uid: Int, value: Boolean) | ||
|
||
@Query("DELETE FROM patch_bundles WHERE uid != 0") | ||
suspend fun purgeCustomBundles() | ||
|
||
@Transaction | ||
suspend fun reset() { | ||
purgeCustomBundles() | ||
updateVersion(0, null, null) // Reset the main source | ||
} | ||
|
||
@Query("DELETE FROM patch_bundles WHERE uid = :uid") | ||
suspend fun remove(uid: Int) | ||
|
||
@Insert | ||
suspend fun add(source: PatchBundleEntity) | ||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/app/revanced/manager/data/room/bundles/PatchBundleEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package app.revanced.manager.data.room.bundles | ||
|
||
import androidx.room.* | ||
import io.ktor.http.* | ||
|
||
sealed class Source { | ||
object Local : Source() { | ||
const val SENTINEL = "local" | ||
|
||
override fun toString() = SENTINEL | ||
} | ||
|
||
object API : Source() { | ||
const val SENTINEL = "api" | ||
|
||
override fun toString() = SENTINEL | ||
} | ||
|
||
data class Remote(val url: Url) : Source() { | ||
override fun toString() = url.toString() | ||
} | ||
|
||
companion object { | ||
fun from(value: String) = when(value) { | ||
Local.SENTINEL -> Local | ||
API.SENTINEL -> API | ||
else -> Remote(Url(value)) | ||
} | ||
} | ||
} | ||
|
||
data class VersionInfo( | ||
@ColumnInfo(name = "version") val patches: String? = null, | ||
@ColumnInfo(name = "integrations_version") val integrations: String? = null, | ||
) | ||
|
||
@Entity(tableName = "patch_bundles", indices = [Index(value = ["name"], unique = true)]) | ||
data class PatchBundleEntity( | ||
@PrimaryKey val uid: Int, | ||
@ColumnInfo(name = "name") val name: String, | ||
@Embedded val versionInfo: VersionInfo, | ||
@ColumnInfo(name = "source") val source: Source, | ||
@ColumnInfo(name = "auto_update") val autoUpdate: Boolean | ||
) | ||
|
||
data class BundleProperties( | ||
@Embedded val versionInfo: VersionInfo, | ||
@ColumnInfo(name = "auto_update") val autoUpdate: Boolean | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.