mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-04 02:09:19 +02:00
Add column for block all notifications
This commit is contained in:
parent
e3bada121d
commit
9dc8a6caab
8 changed files with 673 additions and 10 deletions
|
@ -85,4 +85,10 @@ object DatabaseMigrations {
|
|||
database.execSQL("ALTER TABLE `user` ADD COLUMN `mail_notification_flags` INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATE_TO_V12 = object: Migration(11, 12) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE `category` ADD COLUMN `block_all_notifications` INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import io.timelimit.android.data.model.*
|
|||
ConfigurationItem::class,
|
||||
TemporarilyAllowedApp::class,
|
||||
PendingSyncAction::class
|
||||
], version = 11)
|
||||
], version = 12)
|
||||
abstract class RoomDatabase: RoomDatabase(), io.timelimit.android.data.Database {
|
||||
companion object {
|
||||
private val lock = Object()
|
||||
|
@ -77,7 +77,8 @@ abstract class RoomDatabase: RoomDatabase(), io.timelimit.android.data.Database
|
|||
DatabaseMigrations.MIGRATE_TO_V8,
|
||||
DatabaseMigrations.MIGRATE_TO_V9,
|
||||
DatabaseMigrations.MIGRATE_TO_V10,
|
||||
DatabaseMigrations.MIGRATE_TO_V11
|
||||
DatabaseMigrations.MIGRATE_TO_V11,
|
||||
DatabaseMigrations.MIGRATE_TO_V12
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -52,8 +52,10 @@ data class Category(
|
|||
@ColumnInfo(name = "usedtimes_version")
|
||||
val usedTimesVersion: String,
|
||||
@ColumnInfo(name = "parent_category_id")
|
||||
val parentCategoryId: String
|
||||
): JsonSerializable {
|
||||
val parentCategoryId: String,
|
||||
@ColumnInfo(name = "block_all_notifications")
|
||||
val blockAllNotifications: Boolean
|
||||
): JsonSerializable {
|
||||
companion object {
|
||||
const val MINUTES_PER_DAY = 60 * 24
|
||||
const val BLOCKED_MINUTES_IN_WEEK_LENGTH = MINUTES_PER_DAY * 7
|
||||
|
@ -69,6 +71,7 @@ data class Category(
|
|||
private const val RULES_VERSION = "vr"
|
||||
private const val USED_TIMES_VERSION = "vu"
|
||||
private const val PARENT_CATEGORY_ID = "pc"
|
||||
private const val BlOCK_ALL_NOTIFICATIONS = "ban"
|
||||
|
||||
fun parse(reader: JsonReader): Category {
|
||||
var id: String? = null
|
||||
|
@ -83,6 +86,7 @@ data class Category(
|
|||
var usedTimesVersion: String? = null
|
||||
// this field was added later so it has got a default value
|
||||
var parentCategoryId = ""
|
||||
var blockAllNotifications = false
|
||||
|
||||
reader.beginObject()
|
||||
|
||||
|
@ -99,6 +103,7 @@ data class Category(
|
|||
RULES_VERSION -> timeLimitRulesVersion = reader.nextString()
|
||||
USED_TIMES_VERSION -> usedTimesVersion = reader.nextString()
|
||||
PARENT_CATEGORY_ID -> parentCategoryId = reader.nextString()
|
||||
BlOCK_ALL_NOTIFICATIONS -> blockAllNotifications = reader.nextBoolean()
|
||||
else -> reader.skipValue()
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +121,8 @@ data class Category(
|
|||
assignedAppsVersion = assignedAppsVersion!!,
|
||||
timeLimitRulesVersion = timeLimitRulesVersion!!,
|
||||
usedTimesVersion = usedTimesVersion!!,
|
||||
parentCategoryId = parentCategoryId
|
||||
parentCategoryId = parentCategoryId,
|
||||
blockAllNotifications = blockAllNotifications
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -148,6 +154,7 @@ data class Category(
|
|||
writer.name(RULES_VERSION).value(timeLimitRulesVersion)
|
||||
writer.name(USED_TIMES_VERSION).value(usedTimesVersion)
|
||||
writer.name(PARENT_CATEGORY_ID).value(parentCategoryId)
|
||||
writer.name(BlOCK_ALL_NOTIFICATIONS).value(blockAllNotifications)
|
||||
|
||||
writer.endObject()
|
||||
}
|
||||
|
|
|
@ -164,7 +164,8 @@ class AppSetupLogic(private val appLogic: AppLogic) {
|
|||
assignedAppsVersion = "",
|
||||
timeLimitRulesVersion = "",
|
||||
usedTimesVersion = "",
|
||||
parentCategoryId = ""
|
||||
parentCategoryId = "",
|
||||
blockAllNotifications = false
|
||||
))
|
||||
|
||||
appLogic.database.category().addCategory(Category(
|
||||
|
@ -178,7 +179,8 @@ class AppSetupLogic(private val appLogic: AppLogic) {
|
|||
assignedAppsVersion = "",
|
||||
timeLimitRulesVersion = "",
|
||||
usedTimesVersion = "",
|
||||
parentCategoryId = ""
|
||||
parentCategoryId = "",
|
||||
blockAllNotifications = false
|
||||
))
|
||||
|
||||
// add default allowed apps
|
||||
|
|
|
@ -274,6 +274,7 @@ object ApplyServerDataStatus {
|
|||
blockedMinutesInWeek = newCategory.blockedMinutesInWeek,
|
||||
extraTimeInMillis = newCategory.extraTimeInMillis,
|
||||
temporarilyBlocked = newCategory.temporarilyBlocked,
|
||||
blockAllNotifications = newCategory.blockAllNotifications,
|
||||
baseVersion = newCategory.baseDataVersion,
|
||||
assignedAppsVersion = "",
|
||||
timeLimitRulesVersion = "",
|
||||
|
@ -287,6 +288,7 @@ object ApplyServerDataStatus {
|
|||
blockedMinutesInWeek = newCategory.blockedMinutesInWeek,
|
||||
extraTimeInMillis = newCategory.extraTimeInMillis,
|
||||
temporarilyBlocked = newCategory.temporarilyBlocked,
|
||||
blockAllNotifications = newCategory.blockAllNotifications,
|
||||
baseVersion = newCategory.baseDataVersion,
|
||||
parentCategoryId = newCategory.parentCategoryId
|
||||
)
|
||||
|
|
|
@ -78,7 +78,8 @@ object LocalDatabaseParentActionDispatcher {
|
|||
assignedAppsVersion = "",
|
||||
timeLimitRulesVersion = "",
|
||||
usedTimesVersion = "",
|
||||
parentCategoryId = ""
|
||||
parentCategoryId = "",
|
||||
blockAllNotifications = false
|
||||
))
|
||||
}
|
||||
is DeleteCategoryAction -> {
|
||||
|
|
|
@ -300,7 +300,8 @@ data class ServerUpdatedCategoryBaseData(
|
|||
val extraTimeInMillis: Long,
|
||||
val temporarilyBlocked: Boolean,
|
||||
val baseDataVersion: String,
|
||||
val parentCategoryId: String
|
||||
val parentCategoryId: String,
|
||||
val blockAllNotifications: Boolean
|
||||
) {
|
||||
companion object {
|
||||
private const val CATEGORY_ID = "categoryId"
|
||||
|
@ -311,6 +312,7 @@ data class ServerUpdatedCategoryBaseData(
|
|||
private const val TEMPORARILY_BLOCKED = "tempBlocked"
|
||||
private const val BASE_DATA_VERSION = "version"
|
||||
private const val PARENT_CATEGORY_ID = "parentCategoryId"
|
||||
private const val BLOCK_ALL_NOTIFICATIONS = "blockAllNotifications"
|
||||
|
||||
fun parse(reader: JsonReader): ServerUpdatedCategoryBaseData {
|
||||
var categoryId: String? = null
|
||||
|
@ -321,6 +323,8 @@ data class ServerUpdatedCategoryBaseData(
|
|||
var temporarilyBlocked: Boolean? = null
|
||||
var baseDataVersion: String? = null
|
||||
var parentCategoryId: String? = null
|
||||
// added later -> default values
|
||||
var blockAllNotifications = false
|
||||
|
||||
reader.beginObject()
|
||||
while (reader.hasNext()) {
|
||||
|
@ -333,6 +337,7 @@ data class ServerUpdatedCategoryBaseData(
|
|||
TEMPORARILY_BLOCKED -> temporarilyBlocked = reader.nextBoolean()
|
||||
BASE_DATA_VERSION -> baseDataVersion = reader.nextString()
|
||||
PARENT_CATEGORY_ID -> parentCategoryId = reader.nextString()
|
||||
BLOCK_ALL_NOTIFICATIONS -> blockAllNotifications = reader.nextBoolean()
|
||||
else -> reader.skipValue()
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +351,8 @@ data class ServerUpdatedCategoryBaseData(
|
|||
extraTimeInMillis = extraTimeInMillis!!,
|
||||
temporarilyBlocked = temporarilyBlocked!!,
|
||||
baseDataVersion = baseDataVersion!!,
|
||||
parentCategoryId = parentCategoryId!!
|
||||
parentCategoryId = parentCategoryId!!,
|
||||
blockAllNotifications = blockAllNotifications
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue