mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 02:39:34 +02:00
Add field for category for unassigned apps
This commit is contained in:
parent
9b3bf3f376
commit
b8f5612231
6 changed files with 473 additions and 6 deletions
|
@ -0,0 +1,12 @@
|
|||
package io.timelimit.android.data
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
object DatabaseMigrations {
|
||||
val MIGRATE_TO_V2 = object: Migration(1, 2) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE `user` ADD COLUMN `category_for_not_assigned_apps` TEXT NOT NULL DEFAULT \"\"")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ import io.timelimit.android.data.model.*
|
|||
TimeLimitRule::class,
|
||||
ConfigurationItem::class,
|
||||
TemporarilyAllowedApp::class
|
||||
], version = 1)
|
||||
], version = 2)
|
||||
abstract class RoomDatabase: RoomDatabase(), io.timelimit.android.data.Database {
|
||||
companion object {
|
||||
private val lock = Object()
|
||||
|
@ -66,6 +66,9 @@ abstract class RoomDatabase: RoomDatabase(), io.timelimit.android.data.Database
|
|||
)
|
||||
.setJournalMode(JournalMode.TRUNCATE)
|
||||
.fallbackToDestructiveMigration()
|
||||
.addMigrations(
|
||||
DatabaseMigrations.MIGRATE_TO_V2
|
||||
)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,10 @@ data class User(
|
|||
val timeZone: String,
|
||||
// 0 = time limits enabled
|
||||
@ColumnInfo(name = "disable_limits_until")
|
||||
val disableLimitsUntil: Long
|
||||
val disableLimitsUntil: Long,
|
||||
@ColumnInfo(name = "category_for_not_assigned_apps")
|
||||
// empty or invalid = no category
|
||||
val categoryForNotAssignedApps: String
|
||||
): JsonSerializable {
|
||||
companion object {
|
||||
private const val ID = "id"
|
||||
|
@ -46,6 +49,7 @@ data class User(
|
|||
private const val TYPE = "type"
|
||||
private const val TIMEZONE = "timeZone"
|
||||
private const val DISABLE_LIMITS_UNTIL = "disableLimitsUntil"
|
||||
private const val CATEGORY_FOR_NOT_ASSIGNED_APPS = "categoryForNotAssignedApps"
|
||||
|
||||
fun parse(reader: JsonReader): User {
|
||||
var id: String? = null
|
||||
|
@ -54,6 +58,7 @@ data class User(
|
|||
var type: UserType? = null
|
||||
var timeZone: String? = null
|
||||
var disableLimitsUntil: Long? = null
|
||||
var categoryForNotAssignedApps = ""
|
||||
|
||||
reader.beginObject()
|
||||
while (reader.hasNext()) {
|
||||
|
@ -64,6 +69,7 @@ data class User(
|
|||
TYPE -> type = UserTypeJson.parse(reader.nextString())
|
||||
TIMEZONE -> timeZone = reader.nextString()
|
||||
DISABLE_LIMITS_UNTIL -> disableLimitsUntil = reader.nextLong()
|
||||
CATEGORY_FOR_NOT_ASSIGNED_APPS -> categoryForNotAssignedApps = reader.nextString()
|
||||
else -> reader.skipValue()
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +81,8 @@ data class User(
|
|||
password = password!!,
|
||||
type = type!!,
|
||||
timeZone = timeZone!!,
|
||||
disableLimitsUntil = disableLimitsUntil!!
|
||||
disableLimitsUntil = disableLimitsUntil!!,
|
||||
categoryForNotAssignedApps = categoryForNotAssignedApps
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +101,10 @@ data class User(
|
|||
if (timeZone.isEmpty()) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
if (categoryForNotAssignedApps.isNotEmpty()) {
|
||||
IdGenerator.assertIdValid(categoryForNotAssignedApps)
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(writer: JsonWriter) {
|
||||
|
@ -105,6 +116,7 @@ data class User(
|
|||
writer.name(TYPE).value(UserTypeJson.serialize(type))
|
||||
writer.name(TIMEZONE).value(timeZone)
|
||||
writer.name(DISABLE_LIMITS_UNTIL).value(disableLimitsUntil)
|
||||
writer.name(CATEGORY_FOR_NOT_ASSIGNED_APPS).value(categoryForNotAssignedApps)
|
||||
|
||||
writer.endObject()
|
||||
}
|
||||
|
|
|
@ -97,7 +97,8 @@ class AppSetupLogic(private val appLogic: AppLogic) {
|
|||
password = "",
|
||||
type = UserType.Child,
|
||||
timeZone = timeZone,
|
||||
disableLimitsUntil = 0
|
||||
disableLimitsUntil = 0,
|
||||
categoryForNotAssignedApps = ""
|
||||
)
|
||||
|
||||
appLogic.database.user().addUserSync(child)
|
||||
|
@ -112,7 +113,8 @@ class AppSetupLogic(private val appLogic: AppLogic) {
|
|||
password = PasswordHashing.hashSync(parentPassword),
|
||||
type = UserType.Parent,
|
||||
timeZone = timeZone,
|
||||
disableLimitsUntil = 0
|
||||
disableLimitsUntil = 0,
|
||||
categoryForNotAssignedApps = ""
|
||||
)
|
||||
|
||||
appLogic.database.user().addUserSync(parent)
|
||||
|
|
|
@ -128,7 +128,8 @@ object LocalDatabaseParentActionDispatcher {
|
|||
type = action.userType,
|
||||
timeZone = action.timeZone,
|
||||
password = if (action.password == null) "" else action.password,
|
||||
disableLimitsUntil = 0
|
||||
disableLimitsUntil = 0,
|
||||
categoryForNotAssignedApps = ""
|
||||
))
|
||||
}
|
||||
is UpdateCategoryBlockedTimesAction -> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue