Commit 3a281beb authored by Mygod's avatar Mygod

Allow hiding inactive subscribed profiles

parent 02a8fbcd
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 29, "version": 29,
"identityHash": "21651212f96d465e6a8f62de17533776", "identityHash": "5b5c55a1277c63e14416316f9198ed43",
"entities": [ "entities": [
{ {
"tableName": "Profile", "tableName": "Profile",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `host` TEXT NOT NULL, `remotePort` INTEGER NOT NULL, `password` TEXT NOT NULL, `method` TEXT NOT NULL, `route` TEXT NOT NULL, `remoteDns` TEXT NOT NULL, `proxyApps` INTEGER NOT NULL, `bypass` INTEGER NOT NULL, `udpdns` INTEGER NOT NULL, `ipv6` INTEGER NOT NULL, `metered` INTEGER NOT NULL, `individual` TEXT NOT NULL, `plugin` TEXT, `udpFallback` INTEGER, `fromSubscription` INTEGER NOT NULL, `tx` INTEGER NOT NULL, `rx` INTEGER NOT NULL, `userOrder` INTEGER NOT NULL)", "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `host` TEXT NOT NULL, `remotePort` INTEGER NOT NULL, `password` TEXT NOT NULL, `method` TEXT NOT NULL, `route` TEXT NOT NULL, `remoteDns` TEXT NOT NULL, `proxyApps` INTEGER NOT NULL, `bypass` INTEGER NOT NULL, `udpdns` INTEGER NOT NULL, `ipv6` INTEGER NOT NULL, `metered` INTEGER NOT NULL, `individual` TEXT NOT NULL, `plugin` TEXT, `udpFallback` INTEGER, `subscription` INTEGER NOT NULL, `tx` INTEGER NOT NULL, `rx` INTEGER NOT NULL, `userOrder` INTEGER NOT NULL)",
"fields": [ "fields": [
{ {
"fieldPath": "id", "fieldPath": "id",
...@@ -105,8 +105,8 @@ ...@@ -105,8 +105,8 @@
"notNull": false "notNull": false
}, },
{ {
"fieldPath": "fromSubscription", "fieldPath": "subscription",
"columnName": "fromSubscription", "columnName": "subscription",
"affinity": "INTEGER", "affinity": "INTEGER",
"notNull": true "notNull": true
}, },
...@@ -174,7 +174,7 @@ ...@@ -174,7 +174,7 @@
"views": [], "views": [],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '21651212f96d465e6a8f62de17533776')" "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5b5c55a1277c63e14416316f9198ed43')"
] ]
} }
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ package com.github.shadowsocks.database ...@@ -23,6 +23,7 @@ package com.github.shadowsocks.database
import androidx.room.Database import androidx.room.Database
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.Migration import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase import androidx.sqlite.db.SupportSQLiteDatabase
import com.github.shadowsocks.Core.app import com.github.shadowsocks.Core.app
...@@ -32,6 +33,7 @@ import kotlinx.coroutines.GlobalScope ...@@ -32,6 +33,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Database(entities = [Profile::class, KeyValuePair::class], version = 29) @Database(entities = [Profile::class, KeyValuePair::class], version = 29)
@TypeConverters(Profile.SubscriptionStatus::class)
abstract class PrivateDatabase : RoomDatabase() { abstract class PrivateDatabase : RoomDatabase() {
companion object { companion object {
private val instance by lazy { private val instance by lazy {
...@@ -73,6 +75,7 @@ abstract class PrivateDatabase : RoomDatabase() { ...@@ -73,6 +75,7 @@ abstract class PrivateDatabase : RoomDatabase() {
} }
object Migration29 : Migration(28, 29) { object Migration29 : Migration(28, 29) {
override fun migrate(database: SupportSQLiteDatabase) = override fun migrate(database: SupportSQLiteDatabase) =
database.execSQL("ALTER TABLE `Profile` ADD COLUMN `fromSubscription` INTEGER NOT NULL DEFAULT 0") database.execSQL("ALTER TABLE `Profile` ADD COLUMN `subscription` INTEGER NOT NULL DEFAULT " +
Profile.SubscriptionStatus.UserConfigured.persistedValue)
} }
} }
...@@ -70,7 +70,7 @@ data class Profile( ...@@ -70,7 +70,7 @@ data class Profile(
var udpFallback: Long? = null, var udpFallback: Long? = null,
// managed fields // managed fields
var fromSubscription: Boolean = false, var subscription: SubscriptionStatus = SubscriptionStatus.UserConfigured,
var tx: Long = 0, var tx: Long = 0,
var rx: Long = 0, var rx: Long = 0,
var userOrder: Long = 0, var userOrder: Long = 0,
...@@ -78,6 +78,25 @@ data class Profile( ...@@ -78,6 +78,25 @@ data class Profile(
@Ignore // not persisted in db, only used by direct boot @Ignore // not persisted in db, only used by direct boot
var dirty: Boolean = false var dirty: Boolean = false
) : Parcelable, Serializable { ) : Parcelable, Serializable {
enum class SubscriptionStatus(val persistedValue: Int) {
UserConfigured(0),
Active(1),
/**
* This profile is no longer present in subscriptions.
*/
Obsolete(2),
;
companion object {
@JvmStatic
@TypeConverter
fun of(value: Int) = values().single { it.persistedValue == value }
@JvmStatic
@TypeConverter
fun toInt(status: SubscriptionStatus) = status.persistedValue
}
}
companion object { companion object {
private const val TAG = "ShadowParser" private const val TAG = "ShadowParser"
private const val serialVersionUID = 1L private const val serialVersionUID = 1L
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment