[new] new project
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Compose Resources 自动生成的产物
|
||||
src/commonMain/composeResources/files/offline_schools.zip
|
||||
src/commonMain/composeResources/files/aboutlibraries.json
|
||||
@@ -0,0 +1,121 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.kotlin.multiplatform)
|
||||
alias(libs.plugins.android.multiplatform.library)
|
||||
alias(libs.plugins.compose.multiplatform)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
alias(libs.plugins.ksp)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
alias(libs.plugins.koin.compiler)
|
||||
alias(libs.plugins.androidx.room3)
|
||||
alias(libs.plugins.wire)
|
||||
}
|
||||
|
||||
compose {
|
||||
resources {
|
||||
packageOfResClass = "shiguangschedule.shared.generated.resources"
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
android {
|
||||
namespace = "com.xingheyuzhuan.shiguangschedule.shared"
|
||||
compileSdk = libs.versions.android.compileSdk.get().toInt()
|
||||
minSdk = libs.versions.android.minSdk.get().toInt()
|
||||
|
||||
compilerOptions {
|
||||
jvmTarget = JvmTarget.JVM_21
|
||||
}
|
||||
androidResources {
|
||||
enable = true
|
||||
}
|
||||
withHostTest {
|
||||
isIncludeAndroidResources = true
|
||||
}
|
||||
withDeviceTestBuilder {
|
||||
sourceSetTreeName = "test"
|
||||
}.configure {
|
||||
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation(libs.compose.runtime)
|
||||
implementation(libs.compose.foundation)
|
||||
implementation(libs.compose.material3)
|
||||
implementation(libs.compose.material3.adaptive)
|
||||
implementation(libs.compose.material3.adaptive.navigation.suite)
|
||||
implementation(libs.compose.ui)
|
||||
implementation(libs.compose.animation)
|
||||
implementation(libs.compose.components.resources)
|
||||
implementation(libs.compose.ui.tooling.preview)
|
||||
|
||||
implementation(libs.material.kolor)
|
||||
|
||||
implementation(libs.androidx.lifecycle.viewmodel.compose)
|
||||
implementation(libs.androidx.lifecycle.runtime.compose)
|
||||
implementation(libs.androidx.navigation3.ui)
|
||||
implementation(libs.androidx.lifecycle.viewmodel.navigation3)
|
||||
|
||||
implementation(libs.coil.compose)
|
||||
|
||||
implementation(project.dependencies.platform(libs.koin.bom))
|
||||
implementation(libs.koin.core)
|
||||
implementation(libs.koin.compose)
|
||||
implementation(libs.koin.compose.viewmodel)
|
||||
implementation(libs.koin.compose.navigation3)
|
||||
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
implementation(libs.kotlinx.serialization.cbor)
|
||||
implementation(libs.kotlinx.datetime)
|
||||
implementation(libs.okio)
|
||||
|
||||
implementation(libs.ktor.client.core)
|
||||
implementation(libs.ktor.client.logging)
|
||||
implementation(libs.ktor.client.content.negotiation)
|
||||
implementation(libs.ktor.serialization.kotlinx.json)
|
||||
implementation(libs.ktor.client.auth)
|
||||
implementation(libs.koin.annotations)
|
||||
|
||||
implementation(libs.androidx.room3.runtime)
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
implementation(libs.androidx.datastore.core)
|
||||
|
||||
implementation(libs.wire.runtime)
|
||||
}
|
||||
}
|
||||
|
||||
androidMain.dependencies {
|
||||
implementation(libs.androidx.sqlite.framework)
|
||||
implementation(libs.ktor.client.cio)
|
||||
}
|
||||
|
||||
commonTest.dependencies {
|
||||
implementation(libs.kotlin.test)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
androidRuntimeClasspath(libs.compose.ui.tooling)
|
||||
add("kspAndroid", libs.androidx.room3.compiler)
|
||||
}
|
||||
|
||||
room3 {
|
||||
schemaDirectory("$projectDir/schemas")
|
||||
}
|
||||
|
||||
wire {
|
||||
sourcePath {
|
||||
srcDir("src/commonMain/proto")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
escapeKotlinKeywords = true
|
||||
enumMode = "enum_class"
|
||||
rpcRole = "none"
|
||||
}
|
||||
}
|
||||
+395
@@ -0,0 +1,395 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 3,
|
||||
"identityHash": "c905b75c896ca5b015b51d869b8c6986",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "course_tables",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "createdAt",
|
||||
"columnName": "createdAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "courses",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `courseTableId` TEXT NOT NULL, `name` TEXT NOT NULL, `teacher` TEXT NOT NULL, `position` TEXT NOT NULL, `day` INTEGER NOT NULL, `startSection` INTEGER, `endSection` INTEGER, `isCustomTime` INTEGER NOT NULL, `customStartTime` TEXT, `customEndTime` TEXT, `colorInt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "teacher",
|
||||
"columnName": "teacher",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "position",
|
||||
"columnName": "position",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "day",
|
||||
"columnName": "day",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "startSection",
|
||||
"columnName": "startSection",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "endSection",
|
||||
"columnName": "endSection",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isCustomTime",
|
||||
"columnName": "isCustomTime",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "customStartTime",
|
||||
"columnName": "customStartTime",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "customEndTime",
|
||||
"columnName": "customEndTime",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "colorInt",
|
||||
"columnName": "colorInt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_courses_courseTableId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_courses_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "course_weeks",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseId` TEXT NOT NULL, `weekNumber` INTEGER NOT NULL, PRIMARY KEY(`courseId`, `weekNumber`), FOREIGN KEY(`courseId`) REFERENCES `courses`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "courseId",
|
||||
"columnName": "courseId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "weekNumber",
|
||||
"columnName": "weekNumber",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"courseId",
|
||||
"weekNumber"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_course_weeks_courseId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_course_weeks_courseId` ON `${TABLE_NAME}` (`courseId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_course_weeks_weekNumber",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"weekNumber"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_course_weeks_weekNumber` ON `${TABLE_NAME}` (`weekNumber`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "courses",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "time_slots",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`number` INTEGER NOT NULL, `startTime` TEXT NOT NULL, `endTime` TEXT NOT NULL, `courseTableId` TEXT NOT NULL, PRIMARY KEY(`number`, `courseTableId`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "number",
|
||||
"columnName": "number",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "startTime",
|
||||
"columnName": "startTime",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "endTime",
|
||||
"columnName": "endTime",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"number",
|
||||
"courseTableId"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_time_slots_courseTableId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_time_slots_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "app_settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `currentCourseTableId` TEXT, `reminderEnabled` INTEGER NOT NULL, `remindBeforeMinutes` INTEGER NOT NULL, `skippedDates` TEXT, `autoModeEnabled` INTEGER NOT NULL, `autoControlMode` TEXT NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "currentCourseTableId",
|
||||
"columnName": "currentCourseTableId",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "reminderEnabled",
|
||||
"columnName": "reminderEnabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "remindBeforeMinutes",
|
||||
"columnName": "remindBeforeMinutes",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "skippedDates",
|
||||
"columnName": "skippedDates",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoModeEnabled",
|
||||
"columnName": "autoModeEnabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoControlMode",
|
||||
"columnName": "autoControlMode",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "course_table_config",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseTableId` TEXT NOT NULL, `showWeekends` INTEGER NOT NULL, `semesterStartDate` TEXT, `semesterTotalWeeks` INTEGER NOT NULL, `defaultClassDuration` INTEGER NOT NULL, `defaultBreakDuration` INTEGER NOT NULL, `firstDayOfWeek` INTEGER NOT NULL, PRIMARY KEY(`courseTableId`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "showWeekends",
|
||||
"columnName": "showWeekends",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "semesterStartDate",
|
||||
"columnName": "semesterStartDate",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "semesterTotalWeeks",
|
||||
"columnName": "semesterTotalWeeks",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "defaultClassDuration",
|
||||
"columnName": "defaultClassDuration",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "defaultBreakDuration",
|
||||
"columnName": "defaultBreakDuration",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "firstDayOfWeek",
|
||||
"columnName": "firstDayOfWeek",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_course_table_config_courseTableId",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_course_table_config_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"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, 'c905b75c896ca5b015b51d869b8c6986')"
|
||||
]
|
||||
}
|
||||
}
|
||||
+400
@@ -0,0 +1,400 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 4,
|
||||
"identityHash": "bfd7ba659c9050e7f115c415fb977fef",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "course_tables",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "createdAt",
|
||||
"columnName": "createdAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "courses",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `courseTableId` TEXT NOT NULL, `name` TEXT NOT NULL, `teacher` TEXT NOT NULL, `position` TEXT NOT NULL, `day` INTEGER NOT NULL, `startSection` INTEGER, `endSection` INTEGER, `isCustomTime` INTEGER NOT NULL, `customStartTime` TEXT, `customEndTime` TEXT, `colorInt` INTEGER NOT NULL, `remark` TEXT, PRIMARY KEY(`id`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "teacher",
|
||||
"columnName": "teacher",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "position",
|
||||
"columnName": "position",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "day",
|
||||
"columnName": "day",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "startSection",
|
||||
"columnName": "startSection",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "endSection",
|
||||
"columnName": "endSection",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isCustomTime",
|
||||
"columnName": "isCustomTime",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "customStartTime",
|
||||
"columnName": "customStartTime",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "customEndTime",
|
||||
"columnName": "customEndTime",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "colorInt",
|
||||
"columnName": "colorInt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "remark",
|
||||
"columnName": "remark",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_courses_courseTableId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_courses_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "course_weeks",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseId` TEXT NOT NULL, `weekNumber` INTEGER NOT NULL, PRIMARY KEY(`courseId`, `weekNumber`), FOREIGN KEY(`courseId`) REFERENCES `courses`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "courseId",
|
||||
"columnName": "courseId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "weekNumber",
|
||||
"columnName": "weekNumber",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"courseId",
|
||||
"weekNumber"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_course_weeks_courseId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_course_weeks_courseId` ON `${TABLE_NAME}` (`courseId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_course_weeks_weekNumber",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"weekNumber"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_course_weeks_weekNumber` ON `${TABLE_NAME}` (`weekNumber`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "courses",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "time_slots",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`number` INTEGER NOT NULL, `startTime` TEXT NOT NULL, `endTime` TEXT NOT NULL, `courseTableId` TEXT NOT NULL, PRIMARY KEY(`number`, `courseTableId`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "number",
|
||||
"columnName": "number",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "startTime",
|
||||
"columnName": "startTime",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "endTime",
|
||||
"columnName": "endTime",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"number",
|
||||
"courseTableId"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_time_slots_courseTableId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_time_slots_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "app_settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `currentCourseTableId` TEXT, `reminderEnabled` INTEGER NOT NULL, `remindBeforeMinutes` INTEGER NOT NULL, `skippedDates` TEXT, `autoModeEnabled` INTEGER NOT NULL, `autoControlMode` TEXT NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "currentCourseTableId",
|
||||
"columnName": "currentCourseTableId",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "reminderEnabled",
|
||||
"columnName": "reminderEnabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "remindBeforeMinutes",
|
||||
"columnName": "remindBeforeMinutes",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "skippedDates",
|
||||
"columnName": "skippedDates",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoModeEnabled",
|
||||
"columnName": "autoModeEnabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoControlMode",
|
||||
"columnName": "autoControlMode",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "course_table_config",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseTableId` TEXT NOT NULL, `showWeekends` INTEGER NOT NULL, `semesterStartDate` TEXT, `semesterTotalWeeks` INTEGER NOT NULL, `defaultClassDuration` INTEGER NOT NULL, `defaultBreakDuration` INTEGER NOT NULL, `firstDayOfWeek` INTEGER NOT NULL, PRIMARY KEY(`courseTableId`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "showWeekends",
|
||||
"columnName": "showWeekends",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "semesterStartDate",
|
||||
"columnName": "semesterStartDate",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "semesterTotalWeeks",
|
||||
"columnName": "semesterTotalWeeks",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "defaultClassDuration",
|
||||
"columnName": "defaultClassDuration",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "defaultBreakDuration",
|
||||
"columnName": "defaultBreakDuration",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "firstDayOfWeek",
|
||||
"columnName": "firstDayOfWeek",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_course_table_config_courseTableId",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_course_table_config_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"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, 'bfd7ba659c9050e7f115c415fb977fef')"
|
||||
]
|
||||
}
|
||||
}
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 5,
|
||||
"identityHash": "c6593ec7c98ef0a0cfcdf50d5969e456",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "course_tables",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "createdAt",
|
||||
"columnName": "createdAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "courses",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `courseTableId` TEXT NOT NULL, `name` TEXT NOT NULL, `teacher` TEXT NOT NULL, `position` TEXT NOT NULL, `day` INTEGER NOT NULL, `startSection` INTEGER, `endSection` INTEGER, `isCustomTime` INTEGER NOT NULL, `customStartTime` TEXT, `customEndTime` TEXT, `colorInt` INTEGER NOT NULL, `remark` TEXT, PRIMARY KEY(`id`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "teacher",
|
||||
"columnName": "teacher",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "position",
|
||||
"columnName": "position",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "day",
|
||||
"columnName": "day",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "startSection",
|
||||
"columnName": "startSection",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "endSection",
|
||||
"columnName": "endSection",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isCustomTime",
|
||||
"columnName": "isCustomTime",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "customStartTime",
|
||||
"columnName": "customStartTime",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "customEndTime",
|
||||
"columnName": "customEndTime",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "colorInt",
|
||||
"columnName": "colorInt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "remark",
|
||||
"columnName": "remark",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_courses_courseTableId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_courses_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "course_weeks",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseId` TEXT NOT NULL, `weekNumber` INTEGER NOT NULL, PRIMARY KEY(`courseId`, `weekNumber`), FOREIGN KEY(`courseId`) REFERENCES `courses`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "courseId",
|
||||
"columnName": "courseId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "weekNumber",
|
||||
"columnName": "weekNumber",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"courseId",
|
||||
"weekNumber"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_course_weeks_courseId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_course_weeks_courseId` ON `${TABLE_NAME}` (`courseId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_course_weeks_weekNumber",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"weekNumber"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_course_weeks_weekNumber` ON `${TABLE_NAME}` (`weekNumber`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "courses",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "time_slots",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`number` INTEGER NOT NULL, `startTime` TEXT NOT NULL, `endTime` TEXT NOT NULL, `courseTableId` TEXT NOT NULL, `alias` TEXT, PRIMARY KEY(`number`, `courseTableId`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "number",
|
||||
"columnName": "number",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "startTime",
|
||||
"columnName": "startTime",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "endTime",
|
||||
"columnName": "endTime",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "alias",
|
||||
"columnName": "alias",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"number",
|
||||
"courseTableId"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_time_slots_courseTableId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_time_slots_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "course_table_config",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseTableId` TEXT NOT NULL, `showWeekends` INTEGER NOT NULL, `semesterStartDate` TEXT, `semesterTotalWeeks` INTEGER NOT NULL, `defaultClassDuration` INTEGER NOT NULL, `defaultBreakDuration` INTEGER NOT NULL, `firstDayOfWeek` INTEGER NOT NULL, PRIMARY KEY(`courseTableId`), FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "courseTableId",
|
||||
"columnName": "courseTableId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "showWeekends",
|
||||
"columnName": "showWeekends",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "semesterStartDate",
|
||||
"columnName": "semesterStartDate",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "semesterTotalWeeks",
|
||||
"columnName": "semesterTotalWeeks",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "defaultClassDuration",
|
||||
"columnName": "defaultClassDuration",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "defaultBreakDuration",
|
||||
"columnName": "defaultBreakDuration",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "firstDayOfWeek",
|
||||
"columnName": "firstDayOfWeek",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_course_table_config_courseTableId",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"courseTableId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_course_table_config_courseTableId` ON `${TABLE_NAME}` (`courseTableId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "course_tables",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"courseTableId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"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, 'c6593ec7c98ef0a0cfcdf50d5969e456')"
|
||||
]
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room3.Room
|
||||
import androidx.sqlite.driver.AndroidSQLiteDriver
|
||||
import com.xingheyuzhuan.shiguangschedule.data.di.AppStorage
|
||||
import org.koin.mp.KoinPlatform
|
||||
|
||||
actual fun createMainDatabase(appStorage: AppStorage): MainAppDatabase {
|
||||
val context = KoinPlatform.getKoin().get<Context>()
|
||||
val dbPath = appStorage.getDatabasePath("main_app_database")
|
||||
return Room.databaseBuilder<MainAppDatabase>(
|
||||
context = context,
|
||||
name = dbPath,
|
||||
factory = { MainAppDatabaseConstructor.initialize() }
|
||||
)
|
||||
.addMigrations(*ALL_MIGRATIONS)
|
||||
.setDriver(AndroidSQLiteDriver())
|
||||
.build()
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.widget
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room3.Room
|
||||
import androidx.sqlite.driver.AndroidSQLiteDriver
|
||||
import com.xingheyuzhuan.shiguangschedule.data.di.AppStorage
|
||||
import org.koin.mp.KoinPlatform
|
||||
|
||||
actual fun createWidgetDatabase(appStorage: AppStorage): WidgetDatabase {
|
||||
val context = KoinPlatform.getKoin().get<Context>()
|
||||
val dbPath = appStorage.getDatabasePath("widget_database")
|
||||
return Room.databaseBuilder<WidgetDatabase>(
|
||||
context = context,
|
||||
name = dbPath,
|
||||
factory = { WidgetDatabaseConstructor.initialize() }
|
||||
)
|
||||
.fallbackToDestructiveMigration(true)
|
||||
.setDriver(AndroidSQLiteDriver())
|
||||
.build()
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.di
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import okio.Path
|
||||
import okio.Path.Companion.toOkioPath
|
||||
import org.koin.core.annotation.Named
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Single
|
||||
class AndroidAppStorage(private val context: Context) : AppStorage {
|
||||
override val filesDir: Path
|
||||
get() = context.filesDir.toOkioPath()
|
||||
|
||||
override val cacheDir: Path
|
||||
get() = context.cacheDir.toOkioPath()
|
||||
|
||||
override fun getDatabasePath(dbName: String): String {
|
||||
return context.getDatabasePath(dbName).absolutePath
|
||||
}
|
||||
}
|
||||
|
||||
// --- 通过 Android 原生 Context 获取版本信息 ---
|
||||
|
||||
@Single
|
||||
@Named("AppVersionCode")
|
||||
fun provideAppVersionCode(context: Context): Int {
|
||||
val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
packageInfo.longVersionCode.toInt()
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
packageInfo.versionCode
|
||||
}
|
||||
}
|
||||
|
||||
@Single
|
||||
@Named("AppVersionName")
|
||||
fun provideAppVersionName(context: Context): String {
|
||||
val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
return packageInfo.versionName ?: "1.0.0"
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.tool
|
||||
|
||||
import android.graphics.BitmapFactory
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.PickVisualMediaRequest
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class AndroidFileManager(
|
||||
private val onPickImage: () -> Unit,
|
||||
private val onImportFile: (List<String>) -> Unit,
|
||||
private val onExportFile: (String, ByteArray) -> Unit
|
||||
) : FileManager {
|
||||
override fun pickImage() = onPickImage()
|
||||
override fun importFile(allowedExtensions: List<String>) = onImportFile(allowedExtensions)
|
||||
override fun exportFile(defaultFileName: String, bytes: ByteArray) = onExportFile(defaultFileName, bytes)
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun rememberFileManager(callbacks: FileManagerCallbacks): FileManager {
|
||||
val context = LocalContext.current
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
// 使用 rememberUpdatedState 保证在重绘时始终能拿到最新的回调
|
||||
val currentCallbacks by rememberUpdatedState(callbacks)
|
||||
|
||||
// 1. 图片选择器 (PickVisualMedia)
|
||||
val imageLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.PickVisualMedia()
|
||||
) { uri ->
|
||||
if (uri == null) {
|
||||
currentCallbacks.onImagePicked?.invoke(null)
|
||||
return@rememberLauncherForActivityResult
|
||||
}
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val bitmap = try {
|
||||
context.contentResolver.openInputStream(uri)?.use { stream ->
|
||||
BitmapFactory.decodeStream(stream)?.asImageBitmap()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
currentCallbacks.onImagePicked?.invoke(bitmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 文件导入器 (GetContent)
|
||||
val importLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.GetContent()
|
||||
) { uri ->
|
||||
if (uri == null) {
|
||||
currentCallbacks.onFileImported?.invoke(null, null)
|
||||
return@rememberLauncherForActivityResult
|
||||
}
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val bytes = try {
|
||||
context.contentResolver.openInputStream(uri)?.use { it.readBytes() }
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
currentCallbacks.onFileImported?.invoke(bytes, uri.lastPathSegment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 文件导出器 (CreateDocument)
|
||||
var pendingExportBytes by remember { mutableStateOf<ByteArray?>(null) }
|
||||
|
||||
val exportLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.CreateDocument("*/*")
|
||||
) { uri ->
|
||||
val bytesToWrite = pendingExportBytes
|
||||
if (uri == null || bytesToWrite == null) {
|
||||
currentCallbacks.onFileExported?.invoke(false)
|
||||
return@rememberLauncherForActivityResult
|
||||
}
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val success = try {
|
||||
context.contentResolver.openOutputStream(uri)?.use { stream ->
|
||||
stream.write(bytesToWrite)
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
false
|
||||
}
|
||||
pendingExportBytes = null
|
||||
withContext(Dispatchers.Main) {
|
||||
currentCallbacks.onFileExported?.invoke(success)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remember {
|
||||
AndroidFileManager(
|
||||
onPickImage = {
|
||||
imageLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
|
||||
},
|
||||
onImportFile = { extensions ->
|
||||
// 如果传入了限定后缀(如 json),转换对应的 mimeType,否则降级为 */*
|
||||
val mimeType = if (extensions.isNotEmpty()) {
|
||||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extensions.first().lowercase()) ?: "*/*"
|
||||
} else {
|
||||
"*/*"
|
||||
}
|
||||
importLauncher.launch(mimeType)
|
||||
},
|
||||
onExportFile = { fileName, bytes ->
|
||||
pendingExportBytes = bytes
|
||||
exportLauncher.launch(fileName)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.tool
|
||||
|
||||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyProperties
|
||||
import android.util.Base64
|
||||
import org.koin.core.annotation.Single
|
||||
import java.security.KeyStore
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.spec.GCMParameterSpec
|
||||
@Single
|
||||
actual class SecureCrypto {
|
||||
|
||||
private val alias = "ShiguangApiCryptoKeyAlias"
|
||||
private val provider = "AndroidKeyStore"
|
||||
private val transformation = "AES/GCM/NoPadding"
|
||||
|
||||
private fun getSecretKey(): SecretKey {
|
||||
val keyStore = KeyStore.getInstance(provider).apply { load(null) }
|
||||
keyStore.getKey(alias, null)?.let { return it as SecretKey }
|
||||
|
||||
val keyGenerator = KeyGenerator.getInstance(
|
||||
KeyProperties.KEY_ALGORITHM_AES, provider
|
||||
)
|
||||
val spec = KeyGenParameterSpec.Builder(
|
||||
alias,
|
||||
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
|
||||
).setBlockModes(KeyProperties.BLOCK_MODE_GCM)
|
||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
||||
.build()
|
||||
|
||||
keyGenerator.init(spec)
|
||||
return keyGenerator.generateKey()
|
||||
}
|
||||
|
||||
actual fun encrypt(data: String): CryptoResult? {
|
||||
if (data.isEmpty()) return null
|
||||
return try {
|
||||
val cipher = Cipher.getInstance(transformation)
|
||||
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey())
|
||||
val encryptedBytes = cipher.doFinal(data.toByteArray(Charsets.UTF_8))
|
||||
|
||||
CryptoResult(
|
||||
encryptedData = Base64.encodeToString(encryptedBytes, Base64.NO_WRAP),
|
||||
iv = Base64.encodeToString(cipher.iv, Base64.NO_WRAP)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
actual fun decrypt(encryptedData: String, ivString: String): String? {
|
||||
if (encryptedData.isEmpty() || ivString.isEmpty()) return null
|
||||
return try {
|
||||
val cipher = Cipher.getInstance(transformation)
|
||||
val ivBytes = Base64.decode(ivString, Base64.NO_WRAP)
|
||||
val gcmSpec = GCMParameterSpec(128, ivBytes)
|
||||
|
||||
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(), gcmSpec)
|
||||
val decryptedBytes = cipher.doFinal(Base64.decode(encryptedData, Base64.NO_WRAP))
|
||||
String(decryptedBytes, Charsets.UTF_8)
|
||||
.replace("\u0000", "")
|
||||
.trim()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.tool
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
actual object ZipUtils {
|
||||
actual fun createZip(entries: Map<String, ByteArray>): ByteArray {
|
||||
val baos = ByteArrayOutputStream()
|
||||
ZipOutputStream(baos.buffered()).use { zos ->
|
||||
entries.forEach { (filename, bytes) ->
|
||||
zos.putNextEntry(ZipEntry(filename))
|
||||
zos.write(bytes)
|
||||
zos.closeEntry()
|
||||
}
|
||||
}
|
||||
return baos.toByteArray()
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.components
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asAndroidBitmap
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
/**
|
||||
* Android 平台开启裁切预览 UI 弹窗
|
||||
*/
|
||||
actual val isCropWindowEnabled: Boolean = true
|
||||
|
||||
/**
|
||||
* Android 平台实现:利用系统底层驱动进行物理裁剪并直接压缩为 ByteArray 字节流
|
||||
*/
|
||||
actual suspend fun cropImageBitmapNative(
|
||||
source: ImageBitmap,
|
||||
srcLeft: Int,
|
||||
srcTop: Int,
|
||||
cropWidth: Int,
|
||||
cropHeight: Int
|
||||
): ByteArray = withContext(Dispatchers.Default) {
|
||||
val androidBitmap = source.asAndroidBitmap()
|
||||
|
||||
// 边界安全处理,防止坐标出界引发崩溃
|
||||
val safeLeft = srcLeft.coerceIn(0, androidBitmap.width - 1)
|
||||
val safeTop = srcTop.coerceIn(0, androidBitmap.height - 1)
|
||||
val safeWidth = cropWidth.coerceAtLeast(1).coerceAtMost(androidBitmap.width - safeLeft)
|
||||
val safeHeight = cropHeight.coerceAtLeast(1).coerceAtMost(androidBitmap.height - safeTop)
|
||||
|
||||
// 1. 裁剪 Bitmap
|
||||
val croppedBitmap = Bitmap.createBitmap(
|
||||
androidBitmap,
|
||||
safeLeft,
|
||||
safeTop,
|
||||
safeWidth,
|
||||
safeHeight
|
||||
)
|
||||
|
||||
// 2. 将裁剪后的 Bitmap 压缩为 JPEG 字节数组直接输出给 Common/ViewModel
|
||||
ByteArrayOutputStream().use { stream ->
|
||||
croppedBitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream)
|
||||
stream.toByteArray()
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.components
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.core.content.FileProvider
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okio.Path.Companion.toPath
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import org.koin.core.context.GlobalContext
|
||||
import shiguangschedule.shared.generated.resources.Res
|
||||
import shiguangschedule.shared.generated.resources.action_share
|
||||
|
||||
actual val isShareDialogSupported: Boolean = true
|
||||
|
||||
actual fun platformShareFile(filePath: String, mimeType: String) {
|
||||
val context = GlobalContext.get().get<android.content.Context>()
|
||||
|
||||
val file = filePath.toPath().toFile()
|
||||
if (!file.exists()) return
|
||||
|
||||
val uri = FileProvider.getUriForFile(
|
||||
context,
|
||||
"${context.packageName}.fileprovider",
|
||||
file
|
||||
)
|
||||
|
||||
val shareIntent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
type = mimeType
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
|
||||
val chooserTitle = runBlocking { getString(Res.string.action_share) }
|
||||
|
||||
val chooser = Intent.createChooser(shareIntent, chooserTitle).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
context.startActivity(chooser)
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.components
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
private object AndroidToastHelper : KoinComponent {
|
||||
val context: Context by inject()
|
||||
}
|
||||
|
||||
actual fun showPlatformToast(message: String) {
|
||||
Toast.makeText(
|
||||
AndroidToastHelper.context,
|
||||
message,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.schoolselection.web
|
||||
|
||||
/**
|
||||
* Android 平台专属:拦截 XHR, Fetch 和 Form POST 请求的 JS 脚本
|
||||
*/
|
||||
val JS_INTERCEPT_POST = """
|
||||
(function() {
|
||||
var bridge = window.WebPostService;
|
||||
if (!bridge || window._postInterceptInjected) return;
|
||||
window._postInterceptInjected = true;
|
||||
|
||||
var requestIdHeader = 'X-WebView-Post-Id';
|
||||
var requestIdParam = '_webview_post_id';
|
||||
|
||||
function register(id, body, contentType) {
|
||||
try {
|
||||
if (window.WebPostService && window.WebPostService.register) {
|
||||
window.WebPostService.register(id, body, contentType || '');
|
||||
}
|
||||
} catch(e) {
|
||||
console.error("WebPostService register error:", e);
|
||||
}
|
||||
}
|
||||
|
||||
// --- 1. XMLHttpRequest Interception ---
|
||||
var oldOpen = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function(method, url) {
|
||||
this._method = method;
|
||||
this._url = url;
|
||||
this._headers = {};
|
||||
return oldOpen.apply(this, arguments);
|
||||
};
|
||||
|
||||
var oldSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
|
||||
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
|
||||
try {
|
||||
if (this._headers && header) {
|
||||
this._headers[header] = value;
|
||||
}
|
||||
if (header && header.toLowerCase() === 'x-requested-with') return;
|
||||
} catch(e) {
|
||||
console.error("XHR setRequestHeader error:", e);
|
||||
}
|
||||
return oldSetRequestHeader.apply(this, arguments);
|
||||
};
|
||||
|
||||
var oldSend = XMLHttpRequest.prototype.send;
|
||||
XMLHttpRequest.prototype.send = function(body) {
|
||||
try {
|
||||
if (this._method && this._method.toUpperCase() !== 'GET' && body) {
|
||||
var id = 'xhr_' + Date.now() + '_' + Math.random().toString(36).substr(2);
|
||||
var contentType = (this._headers && (this._headers['Content-Type'] || this._headers['content-type'])) || '';
|
||||
|
||||
var bodyStr = '';
|
||||
if (typeof body === 'string') {
|
||||
bodyStr = body;
|
||||
} else if (window.FormData && body instanceof FormData) {
|
||||
if (window.URLSearchParams) {
|
||||
var params = new URLSearchParams();
|
||||
for (var pair of body.entries()) {
|
||||
params.append(pair[0], pair[1]);
|
||||
}
|
||||
bodyStr = params.toString();
|
||||
}
|
||||
if (!contentType) contentType = 'application/x-www-form-urlencoded';
|
||||
} else if (window.URLSearchParams && body instanceof URLSearchParams) {
|
||||
bodyStr = body.toString();
|
||||
if (!contentType) contentType = 'application/x-www-form-urlencoded';
|
||||
}
|
||||
|
||||
if (bodyStr) {
|
||||
register(id, bodyStr, contentType);
|
||||
this.setRequestHeader(requestIdHeader, id);
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.error("XHR send intercept error:", e);
|
||||
}
|
||||
return oldSend.apply(this, arguments);
|
||||
};
|
||||
|
||||
// --- 2. Fetch API Interception ---
|
||||
if (window.fetch) {
|
||||
var oldFetch = window.fetch;
|
||||
window.fetch = function(input, init) {
|
||||
try {
|
||||
var options = init || {};
|
||||
var method = options.method;
|
||||
|
||||
if (!method && input && typeof input === 'object' && input.method) {
|
||||
method = input.method;
|
||||
}
|
||||
if (!method) method = 'GET';
|
||||
|
||||
var body = options.body;
|
||||
|
||||
if (method.toUpperCase() !== 'GET' && body) {
|
||||
var id = 'fetch_' + Date.now() + '_' + Math.random().toString(36).substr(2);
|
||||
var contentType = '';
|
||||
|
||||
// 提取 Content-Type
|
||||
var headers = options.headers || (input && typeof input === 'object' ? input.headers : null);
|
||||
if (headers) {
|
||||
if (window.Headers && headers instanceof Headers) {
|
||||
contentType = headers.get('Content-Type') || headers.get('content-type') || '';
|
||||
} else if (Array.isArray(headers)) {
|
||||
for (var i = 0; i < headers.length; i++) {
|
||||
if (headers[i] && headers[i][0] && headers[i][0].toLowerCase() === 'content-type') {
|
||||
contentType = headers[i][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (typeof headers === 'object') {
|
||||
contentType = headers['Content-Type'] || headers['content-type'] || '';
|
||||
}
|
||||
}
|
||||
|
||||
var bodyStr = '';
|
||||
if (typeof body === 'string') {
|
||||
bodyStr = body;
|
||||
} else if (window.URLSearchParams && body instanceof URLSearchParams) {
|
||||
bodyStr = body.toString();
|
||||
if (!contentType) contentType = 'application/x-www-form-urlencoded';
|
||||
} else if (window.FormData && body instanceof FormData) {
|
||||
if (window.URLSearchParams) {
|
||||
var p = new URLSearchParams();
|
||||
for (var pair of body.entries()) {
|
||||
p.append(pair[0], pair[1]);
|
||||
}
|
||||
bodyStr = p.toString();
|
||||
}
|
||||
if (!contentType) contentType = 'application/x-www-form-urlencoded';
|
||||
}
|
||||
|
||||
if (bodyStr) {
|
||||
register(id, bodyStr, contentType);
|
||||
|
||||
// 注入 Request ID Header
|
||||
if (!options.headers) options.headers = {};
|
||||
if (window.Headers && options.headers instanceof Headers) {
|
||||
options.headers.set(requestIdHeader, id);
|
||||
} else if (Array.isArray(options.headers)) {
|
||||
options.headers.push([requestIdHeader, id]);
|
||||
} else if (typeof options.headers === 'object') {
|
||||
options.headers[requestIdHeader] = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return oldFetch.call(this, input, options);
|
||||
} catch(e) {
|
||||
console.error("Fetch intercept error:", e);
|
||||
return oldFetch.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// --- 3. Traditional Form Submit Interception ---
|
||||
document.addEventListener('submit', function(e) {
|
||||
try {
|
||||
var form = e.target;
|
||||
if (!form || !form.tagName || form.tagName.toLowerCase() !== 'form') return;
|
||||
if (!form.method || form.method.toLowerCase() !== 'post') return;
|
||||
|
||||
if (form.querySelector && form.querySelector('input[type="file"]')) return;
|
||||
|
||||
var id = 'form_' + Date.now() + '_' + Math.random().toString(36).substr(2);
|
||||
var formData = new FormData(form);
|
||||
|
||||
var submitter = e.submitter || document.activeElement;
|
||||
if (submitter && submitter.form === form && submitter.name) {
|
||||
formData.append(submitter.name, submitter.value);
|
||||
}
|
||||
|
||||
if (window.URLSearchParams) {
|
||||
var params = new URLSearchParams(formData);
|
||||
register(id, params.toString(), 'application/x-www-form-urlencoded');
|
||||
|
||||
var action = form.getAttribute('action') || window.location.href;
|
||||
var separator = action.indexOf('?') !== -1 ? '&' : '?';
|
||||
form.setAttribute('action', action + separator + requestIdParam + '=' + id);
|
||||
}
|
||||
} catch(err) {
|
||||
console.error("Form submit intercept error:", err);
|
||||
}
|
||||
}, true);
|
||||
|
||||
console.log('Unified X-Requested-With interceptor active');
|
||||
})();
|
||||
""".trimIndent()
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.schoolselection.web
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Bitmap
|
||||
import android.net.http.SslError
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.SslErrorHandler
|
||||
import android.webkit.WebChromeClient
|
||||
import android.webkit.WebResourceError
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebResourceResponse
|
||||
import android.webkit.WebSettings
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
|
||||
/**
|
||||
* WebView 代理配置与客户端包装类
|
||||
*/
|
||||
class WebCompatDelegate(private val webView: WebView) {
|
||||
|
||||
private val defaultUserAgent: String = webView.settings.userAgentString
|
||||
private val requestInterceptor = WebViewRequestInterceptor()
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
fun enhanceSettings(isDesktopMode: Boolean): WebCompatDelegate {
|
||||
webView.settings.apply {
|
||||
javaScriptEnabled = true
|
||||
domStorageEnabled = true
|
||||
databaseEnabled = true
|
||||
@Suppress("DEPRECATION")
|
||||
allowUniversalAccessFromFileURLs = true
|
||||
@Suppress("DEPRECATION")
|
||||
allowFileAccessFromFileURLs = true
|
||||
allowFileAccess = true
|
||||
allowContentAccess = true
|
||||
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
|
||||
useWideViewPort = true
|
||||
loadWithOverviewMode = true
|
||||
|
||||
if (isDesktopMode) {
|
||||
userAgentString = DESKTOP_USER_AGENT
|
||||
layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
||||
} else {
|
||||
userAgentString = defaultUserAgent
|
||||
layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL
|
||||
}
|
||||
|
||||
setSupportZoom(true)
|
||||
builtInZoomControls = true
|
||||
displayZoomControls = false
|
||||
}
|
||||
|
||||
val cookieManager = CookieManager.getInstance()
|
||||
cookieManager.setAcceptCookie(true)
|
||||
cookieManager.setAcceptThirdPartyCookies(webView, true)
|
||||
return this
|
||||
}
|
||||
|
||||
fun wrapWebViewClient(original: WebViewClient, isDesktopModeProvider: () -> Boolean): WebViewClient {
|
||||
return object : WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
|
||||
return original.shouldOverrideUrlLoading(view, request)
|
||||
}
|
||||
|
||||
override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest?): WebResourceResponse? {
|
||||
if (request != null) {
|
||||
val currentDesktopMode = isDesktopModeProvider()
|
||||
val interceptedResponse = requestInterceptor.intercept(request, currentDesktopMode)
|
||||
if (interceptedResponse != null) {
|
||||
return interceptedResponse
|
||||
}
|
||||
}
|
||||
return original.shouldInterceptRequest(view, request)
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||
original.onPageStarted(view, url, favicon)
|
||||
view?.let { wv ->
|
||||
// 早期注入 JS_INTERCEPT_POST 拦截网络请求
|
||||
wv.evaluateJavascript(JS_INTERCEPT_POST, null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
original.onPageFinished(view, url)
|
||||
|
||||
view?.let { wv ->
|
||||
wv.evaluateJavascript(JS_INTERCEPT_POST, null)
|
||||
|
||||
if (isDesktopModeProvider()) {
|
||||
injectDesktopViewportFix(wv)
|
||||
}
|
||||
wv.injectAllJavaScript()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReceivedSslError(v: WebView?, h: SslErrorHandler?, e: SslError?) {
|
||||
original.onReceivedSslError(v, h, e)
|
||||
}
|
||||
|
||||
override fun onReceivedError(v: WebView, q: WebResourceRequest, e: WebResourceError) =
|
||||
original.onReceivedError(v, q, e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅在桌面模式下补全 Viewport Meta 标签与触发 resize,避免 PC 网页排版挤压
|
||||
*/
|
||||
private fun injectDesktopViewportFix(view: WebView) {
|
||||
val desktopWidth = 1280
|
||||
view.evaluateJavascript("""
|
||||
(function() {
|
||||
try {
|
||||
var metas = document.getElementsByTagName('meta');
|
||||
for (var i = metas.length - 1; i >= 0; i--) {
|
||||
if (metas[i].getAttribute('name') === 'viewport') {
|
||||
metas[i].parentNode.removeChild(metas[i]);
|
||||
}
|
||||
}
|
||||
var meta = document.createElement('meta');
|
||||
meta.name = "viewport";
|
||||
meta.content = "width=$desktopWidth, initial-scale=1.0, minimum-scale=0.1, maximum-scale=5.0, user-scalable=yes";
|
||||
document.head.appendChild(meta);
|
||||
|
||||
// 触发 resize 事件促使根据 window 宽高度重绘的 JS 组件重新计算高度
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
} catch(e) {
|
||||
console.error("injectDesktopViewportFix Error: ", e);
|
||||
}
|
||||
})();
|
||||
""".trimIndent(), null)
|
||||
}
|
||||
|
||||
fun wrapWebChromeClient(original: WebChromeClient, onProgress: (Int) -> Unit): WebChromeClient {
|
||||
return object : WebChromeClient() {
|
||||
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
||||
onProgress(newProgress)
|
||||
original.onProgressChanged(view, newProgress)
|
||||
}
|
||||
override fun onReceivedTitle(v: WebView?, t: String?) = original.onReceivedTitle(v, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 统一注入 Bridge 初始化与 POST 拦截 JS */
|
||||
internal fun WebView.injectAllJavaScript() {
|
||||
evaluateJavascript(JS_BRIDGE_INIT, null)
|
||||
evaluateJavascript(JS_INTERCEPT_POST, null)
|
||||
}
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.schoolselection.web
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Bitmap
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebChromeClient
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
|
||||
actual val isDesktopPlatform: Boolean = false
|
||||
|
||||
@Composable
|
||||
actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) {
|
||||
BackHandler(enabled = enabled, onBack = onBack)
|
||||
}
|
||||
|
||||
/**
|
||||
* Android 端的 WebViewController 实现
|
||||
*/
|
||||
class AndroidWebViewController : WebViewController {
|
||||
var webViewInstance: WebView? = null
|
||||
|
||||
override val currentUrl: String
|
||||
get() = webViewInstance?.url ?: ""
|
||||
|
||||
override fun reload() {
|
||||
webViewInstance?.reload()
|
||||
}
|
||||
|
||||
override fun goBack(): Boolean {
|
||||
return if (webViewInstance?.canGoBack() == true) {
|
||||
webViewInstance?.goBack()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun canGoBack(): Boolean {
|
||||
return webViewInstance?.canGoBack() == true
|
||||
}
|
||||
|
||||
override fun setDevToolsEnabled(enabled: Boolean) {
|
||||
WebView.setWebContentsDebuggingEnabled(enabled)
|
||||
}
|
||||
|
||||
override fun executeScript(jsCode: String) {
|
||||
evaluateJavascript(jsCode, null)
|
||||
}
|
||||
|
||||
override fun evaluateJavascript(script: String, callback: ((String?) -> Unit)?) {
|
||||
webViewInstance?.post {
|
||||
val finalScript = if (script.contains("_shiguangBridgeInjected")) {
|
||||
script
|
||||
} else {
|
||||
"""
|
||||
$JS_BRIDGE_INIT
|
||||
$script
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
webViewInstance?.evaluateJavascript(finalScript) { res ->
|
||||
callback?.invoke(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun rememberWebViewController(): WebViewController {
|
||||
return remember { AndroidWebViewController() }
|
||||
}
|
||||
|
||||
class NativeBridge(private val handler: WebBridgeHandler) {
|
||||
@JavascriptInterface
|
||||
fun postMessage(jsonMessage: String) {
|
||||
handler.onMessageReceived(jsonMessage)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface", "SetJavaScriptEnabled")
|
||||
@Composable
|
||||
actual fun PlatformWebView(
|
||||
modifier: Modifier,
|
||||
url: String,
|
||||
isDesktopMode: Boolean,
|
||||
isDevToolsEnabled: Boolean,
|
||||
controller: WebViewController,
|
||||
bridgeHandler: WebBridgeHandler,
|
||||
onProgressChange: (Float) -> Unit,
|
||||
onTitleChange: (String) -> Unit,
|
||||
onNavigateToSchedule: () -> Unit
|
||||
) {
|
||||
val androidController = controller as? AndroidWebViewController
|
||||
|
||||
val currentOnProgressChange by rememberUpdatedState(onProgressChange)
|
||||
val currentOnTitleChange by rememberUpdatedState(onTitleChange)
|
||||
|
||||
val currentIsDesktopMode by rememberUpdatedState(isDesktopMode)
|
||||
|
||||
var loadedBaseUrl by remember { mutableStateOf("") }
|
||||
|
||||
var isFirstLaunch by remember { mutableStateOf(true) }
|
||||
|
||||
// 监听外部强制 URL 变更
|
||||
LaunchedEffect(url) {
|
||||
if (url.isNotBlank() && url != "about:blank" && url != loadedBaseUrl) {
|
||||
loadedBaseUrl = url
|
||||
androidController?.webViewInstance?.let { wv ->
|
||||
if (wv.url != url) {
|
||||
wv.loadUrl(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 监听 桌面/移动 模式动态切换
|
||||
LaunchedEffect(isDesktopMode) {
|
||||
if (isFirstLaunch) {
|
||||
isFirstLaunch = false
|
||||
return@LaunchedEffect
|
||||
}
|
||||
|
||||
androidController?.webViewInstance?.let { wv ->
|
||||
val delegate = WebCompatDelegate(wv)
|
||||
delegate.enhanceSettings(isDesktopMode)
|
||||
|
||||
val currentRealUrl = wv.url?.takeIf { it.isNotBlank() && it != "about:blank" } ?: url
|
||||
if (currentRealUrl.isNotBlank() && currentRealUrl != "about:blank") {
|
||||
wv.loadUrl(currentRealUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 监听 开发者工具 开关
|
||||
LaunchedEffect(isDevToolsEnabled) {
|
||||
WebView.setWebContentsDebuggingEnabled(isDevToolsEnabled)
|
||||
}
|
||||
|
||||
Box(modifier = modifier) {
|
||||
AndroidView(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
factory = { context ->
|
||||
WebView(context).apply {
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
settings.apply {
|
||||
javaScriptEnabled = true
|
||||
domStorageEnabled = true
|
||||
useWideViewPort = true
|
||||
loadWithOverviewMode = true
|
||||
setSupportZoom(true)
|
||||
builtInZoomControls = true
|
||||
displayZoomControls = false
|
||||
}
|
||||
|
||||
androidController?.webViewInstance = this
|
||||
|
||||
val delegate = WebCompatDelegate(this)
|
||||
delegate.enhanceSettings(isDesktopMode)
|
||||
|
||||
addJavascriptInterface(WebPostBridge(), "WebPostService")
|
||||
addJavascriptInterface(NativeBridge(bridgeHandler), "_shiguangNativeBridge")
|
||||
|
||||
val baseChromeClient = object : WebChromeClient() {
|
||||
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
||||
currentOnProgressChange(newProgress / 100f)
|
||||
}
|
||||
|
||||
override fun onReceivedTitle(view: WebView?, title: String?) {
|
||||
if (!title.isNullOrBlank() && !title.startsWith("http")) {
|
||||
currentOnTitleChange(title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val baseViewClient = object : WebViewClient() {
|
||||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||
currentOnProgressChange(0.1f)
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
currentOnProgressChange(1.0f)
|
||||
view?.evaluateJavascript("document.title") { value ->
|
||||
val unquoted = value?.trim('"')?.replace("\\\"", "\"")?.trim() ?: ""
|
||||
if (unquoted.isNotBlank() && unquoted != "null") {
|
||||
currentOnTitleChange(unquoted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
webChromeClient = delegate.wrapWebChromeClient(baseChromeClient) { progressInt ->
|
||||
currentOnProgressChange(progressInt.toFloat())
|
||||
}
|
||||
|
||||
webViewClient = delegate.wrapWebViewClient(baseViewClient) { currentIsDesktopMode }
|
||||
|
||||
if (url.isNotBlank() && url != "about:blank") {
|
||||
loadedBaseUrl = url
|
||||
loadUrl(url)
|
||||
}
|
||||
}
|
||||
},
|
||||
update = { webView ->
|
||||
androidController?.webViewInstance = webView
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
androidController?.webViewInstance?.let { wv ->
|
||||
wv.stopLoading()
|
||||
wv.webChromeClient = null
|
||||
wv.webViewClient = WebViewClient()
|
||||
(wv.parent as? ViewGroup)?.removeView(wv)
|
||||
|
||||
wv.clearHistory()
|
||||
wv.clearCache(true)
|
||||
wv.clearFormData()
|
||||
wv.clearSslPreferences()
|
||||
wv.destroy()
|
||||
}
|
||||
|
||||
val cookieManager = android.webkit.CookieManager.getInstance()
|
||||
cookieManager.removeAllCookies(null)
|
||||
cookieManager.flush()
|
||||
|
||||
androidController?.webViewInstance = null
|
||||
}
|
||||
}
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.schoolselection.web
|
||||
|
||||
import android.util.Log
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebResourceResponse
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.client.plugins.HttpTimeout
|
||||
import io.ktor.client.request.headers
|
||||
import io.ktor.client.request.request
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.bodyAsChannel
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.content.ByteArrayContent
|
||||
import io.ktor.http.parsing.ParseException
|
||||
import io.ktor.http.parseHeaderValue
|
||||
import io.ktor.http.takeFrom
|
||||
import io.ktor.utils.io.jvm.javaio.toInputStream
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.net.URI
|
||||
import java.util.Collections
|
||||
|
||||
/**
|
||||
* WebView 请求拦截器(电脑模式专用)
|
||||
* 用于过滤特定指纹 Header 并接管 XHR/Fetch POST 数据流
|
||||
*/
|
||||
class WebViewRequestInterceptor {
|
||||
companion object {
|
||||
private val ktorClientNoRedirects = HttpClient(CIO) {
|
||||
followRedirects = false
|
||||
install(HttpTimeout) {
|
||||
connectTimeoutMillis = 30_000
|
||||
requestTimeoutMillis = 60_000
|
||||
socketTimeoutMillis = 60_000
|
||||
}
|
||||
}
|
||||
|
||||
private val ktorClientWithRedirects = HttpClient(CIO) {
|
||||
followRedirects = true
|
||||
install(HttpTimeout) {
|
||||
connectTimeoutMillis = 30_000
|
||||
requestTimeoutMillis = 60_000
|
||||
socketTimeoutMillis = 60_000
|
||||
}
|
||||
}
|
||||
|
||||
private val postBodyRegistry = Collections.synchronizedMap(mutableMapOf<String, RegisteredPostData>())
|
||||
|
||||
fun registerPostData(id: String, body: String, contentType: String) {
|
||||
postBodyRegistry[id] = RegisteredPostData(body, contentType)
|
||||
}
|
||||
|
||||
private data class RegisteredPostData(val body: String, val contentType: String)
|
||||
}
|
||||
|
||||
private val cookieManager = CookieManager.getInstance()
|
||||
|
||||
fun intercept(request: WebResourceRequest, isDesktopMode: Boolean): WebResourceResponse? {
|
||||
val rawUrl = request.url.toString()
|
||||
|
||||
// 1. 基础校验:只在 Desktop 模式且 http/https 请求下工作
|
||||
if (!rawUrl.startsWith("http") || !isDesktopMode) return null
|
||||
|
||||
val requestIdHeader = request.requestHeaders["X-WebView-Post-Id"]
|
||||
val requestIdParam = request.url.getQueryParameter("_webview_post_id")
|
||||
val requestId = requestIdHeader ?: requestIdParam
|
||||
|
||||
// 2. 关键过滤逻辑:
|
||||
// 如果既不是 MainFrame (主网页导航),也没有带 POST ID 标,
|
||||
// 说明这只是网页内部的普通 GET/AJAX/图片/JS 资源请求,直接放行给 WebView 原生网络栈!
|
||||
if (!request.isForMainFrame && requestId == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
// 剥离内部凭据 Query 参数,恢复真实的目标请求 URL
|
||||
val url = if (requestIdParam != null) {
|
||||
val uriBuilder = request.url.buildUpon().clearQuery()
|
||||
request.url.queryParameterNames.forEach { name ->
|
||||
if (name != "_webview_post_id") {
|
||||
request.url.getQueryParameters(name).forEach { value ->
|
||||
uriBuilder.appendQueryParameter(name, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
uriBuilder.build().toString()
|
||||
} else {
|
||||
rawUrl
|
||||
}
|
||||
|
||||
val registeredData = requestId?.let { postBodyRegistry.remove(it) }
|
||||
|
||||
// 如果不是 GET 且没有获取到 Body 数据,放回原生处理
|
||||
if (request.method.uppercase() != "GET" && registeredData == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val client = if (request.isForMainFrame) ktorClientNoRedirects else ktorClientWithRedirects
|
||||
|
||||
try {
|
||||
return runBlocking {
|
||||
val response = client.request {
|
||||
this.url.takeFrom(url)
|
||||
this.method = HttpMethod.parse(request.method)
|
||||
|
||||
if (registeredData != null) {
|
||||
val rawContentType = registeredData.contentType.ifBlank { "application/x-www-form-urlencoded" }
|
||||
val parsedContentType = try {
|
||||
ContentType.parse(rawContentType)
|
||||
} catch (e: Exception) {
|
||||
ContentType.Application.FormUrlEncoded
|
||||
}
|
||||
setBody(ByteArrayContent(registeredData.body.toByteArray(Charsets.UTF_8), parsedContentType))
|
||||
}
|
||||
|
||||
headers {
|
||||
request.requestHeaders.forEach { (key, value) ->
|
||||
// 过滤容易被服务端反爬系统标记为移动端 WebView 的 Header
|
||||
if (!key.equals("X-Requested-With", ignoreCase = true) &&
|
||||
!key.equals("X-WebView-Post-Id", ignoreCase = true)) {
|
||||
append(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
val cookies = cookieManager.getCookie(url)
|
||||
if (!cookies.isNullOrEmpty()) {
|
||||
append(HttpHeaders.Cookie, cookies)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 同步 Set-Cookie 到 WebView 容器
|
||||
response.headers.getAll(HttpHeaders.SetCookie)?.forEach { cookieStr ->
|
||||
cookieManager.setCookie(url, cookieStr)
|
||||
}
|
||||
cookieManager.flush()
|
||||
|
||||
val statusCode = response.status.value
|
||||
|
||||
// WebView 无法原生解析 3xx 响应,主框架需通过 JS 跳转替代
|
||||
if (statusCode in 300..399) {
|
||||
if (request.isForMainFrame) {
|
||||
val location = response.headers[HttpHeaders.Location]
|
||||
if (location != null) {
|
||||
val absoluteLocation = resolveAbsoluteUrl(url, location)
|
||||
val html = "<html><script>window.location.replace('$absoluteLocation');</script></html>"
|
||||
return@runBlocking WebResourceResponse(
|
||||
"text/html",
|
||||
"UTF-8",
|
||||
200,
|
||||
"OK",
|
||||
mapOf("Cache-Control" to "no-cache"),
|
||||
html.byteInputStream()
|
||||
)
|
||||
}
|
||||
}
|
||||
return@runBlocking null
|
||||
}
|
||||
|
||||
val contentTypeHeader = response.headers[HttpHeaders.ContentType]
|
||||
var mimeType = "text/html"
|
||||
var encoding = "UTF-8"
|
||||
|
||||
if (!contentTypeHeader.isNullOrBlank()) {
|
||||
try {
|
||||
val parsedHeader = parseHeaderValue(contentTypeHeader)
|
||||
if (parsedHeader.isNotEmpty()) {
|
||||
mimeType = parsedHeader[0].value.substringBefore(";")
|
||||
val charsetParam = parsedHeader[0].params.find { it.name.equals("charset", ignoreCase = true) }
|
||||
if (charsetParam != null) {
|
||||
encoding = charsetParam.value
|
||||
}
|
||||
}
|
||||
} catch (e: ParseException) {
|
||||
mimeType = contentTypeHeader.substringBefore(";")
|
||||
if (contentTypeHeader.contains("charset=")) {
|
||||
encoding = contentTypeHeader.substringAfter("charset=").substringBefore(";")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val responseHeadersMap = mutableMapOf<String, String>()
|
||||
response.headers.forEach { name, values ->
|
||||
// 剔除 Content-Encoding,防止底层自动解压后 WebView 重复解压导致乱码
|
||||
if (!name.equals("Content-Encoding", ignoreCase = true)) {
|
||||
responseHeadersMap[name] = values.joinToString(", ")
|
||||
}
|
||||
}
|
||||
|
||||
val inputStream = response.bodyAsChannel().toInputStream()
|
||||
|
||||
WebResourceResponse(
|
||||
mimeType,
|
||||
encoding,
|
||||
statusCode,
|
||||
response.status.description.ifBlank { "OK" },
|
||||
responseHeadersMap,
|
||||
inputStream
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("WebViewInterceptor", "Error intercepting request: $url", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveAbsoluteUrl(baseUrl: String, location: String): String {
|
||||
return try {
|
||||
URI(baseUrl).resolve(location).toString()
|
||||
} catch (e: Exception) {
|
||||
location
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSBridge 注入桥接,供 JS 侧暂存 POST Body 数据
|
||||
*/
|
||||
class WebPostBridge {
|
||||
@JavascriptInterface
|
||||
fun register(id: String, body: String, type: String) {
|
||||
WebViewRequestInterceptor.registerPostData(id, body, type)
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.settings.notification
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import shiguangschedule.shared.generated.resources.Res
|
||||
import shiguangschedule.shared.generated.resources.desc_compat_wearable_sync
|
||||
import shiguangschedule.shared.generated.resources.item_auto_mode
|
||||
import shiguangschedule.shared.generated.resources.item_background_and_autostart
|
||||
import shiguangschedule.shared.generated.resources.item_compat_wearable_sync
|
||||
import shiguangschedule.shared.generated.resources.item_course_reminder
|
||||
import shiguangschedule.shared.generated.resources.item_dnd_permission
|
||||
import shiguangschedule.shared.generated.resources.item_exact_alarm_permission
|
||||
import shiguangschedule.shared.generated.resources.item_ignore_battery_optimization
|
||||
import shiguangschedule.shared.generated.resources.item_remind_time_before
|
||||
import shiguangschedule.shared.generated.resources.remind_time_minutes_format
|
||||
import shiguangschedule.shared.generated.resources.section_title_general
|
||||
import shiguangschedule.shared.generated.resources.status_authorized
|
||||
import shiguangschedule.shared.generated.resources.status_disabled
|
||||
import shiguangschedule.shared.generated.resources.status_enabled
|
||||
import shiguangschedule.shared.generated.resources.status_unauthorized
|
||||
import shiguangschedule.shared.generated.resources.text_auto_mode_dependency
|
||||
import shiguangschedule.shared.generated.resources.text_permission_importance_detail
|
||||
import shiguangschedule.shared.generated.resources.text_permission_importance_title
|
||||
|
||||
/**
|
||||
* 常规设置卡片 UI 组件 (Android 专属)
|
||||
*/
|
||||
@Composable
|
||||
fun GeneralSettingsCard(
|
||||
uiState: NotificationSettingsUiState,
|
||||
currentModeText: String?,
|
||||
onReminderToggle: (Boolean) -> Unit,
|
||||
onCompatWearableToggle: (Boolean) -> Unit,
|
||||
onAutoModeClick: () -> Unit,
|
||||
onRemindTimeClick: () -> Unit,
|
||||
onAppSettingsClick: () -> Unit,
|
||||
onBatteryOptimizationClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
// 仅在开启提醒开关但无权限时弹窗引导
|
||||
var showExactAlarmDialog by remember { mutableStateOf(false) }
|
||||
|
||||
Column(modifier = modifier) {
|
||||
Text(
|
||||
text = stringResource(Res.string.section_title_general),
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||
contentColor = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
// 权限说明头部
|
||||
Text(
|
||||
text = stringResource(Res.string.text_permission_importance_title),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = stringResource(Res.string.text_permission_importance_detail),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
HorizontalDivider(modifier = Modifier.padding(vertical = 16.dp))
|
||||
|
||||
// 1. 上课提醒主开关
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(Res.string.item_course_reminder),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
Switch(
|
||||
checked = uiState.reminderEnabled,
|
||||
onCheckedChange = { targetState ->
|
||||
if (targetState) {
|
||||
if (hasExactAlarmPermission(context)) {
|
||||
onReminderToggle(true)
|
||||
} else {
|
||||
showExactAlarmDialog = true
|
||||
}
|
||||
} else {
|
||||
onReminderToggle(false)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))
|
||||
|
||||
// 2. 兼容穿戴设备同步通知开关
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(Res.string.item_compat_wearable_sync),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
Switch(
|
||||
checked = uiState.compatWearableSync,
|
||||
onCheckedChange = onCompatWearableToggle
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(Res.string.desc_compat_wearable_sync),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(top = 4.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
// 3. 上课自动模式
|
||||
SettingItemRow(
|
||||
title = stringResource(Res.string.item_auto_mode),
|
||||
currentValue = currentModeText,
|
||||
onClick = onAutoModeClick
|
||||
)
|
||||
if (!uiState.reminderEnabled) {
|
||||
Text(
|
||||
text = stringResource(Res.string.text_auto_mode_dependency),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f),
|
||||
modifier = Modifier.padding(start = 16.dp, top = 4.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
// 4. 提前提醒时间
|
||||
SettingItemRow(
|
||||
title = stringResource(Res.string.item_remind_time_before),
|
||||
currentValue = stringResource(Res.string.remind_time_minutes_format, uiState.remindBeforeMinutes),
|
||||
onClick = onRemindTimeClick
|
||||
)
|
||||
|
||||
// 5. 精确闹钟权限 (Android 12+):直接跳转页面
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
HorizontalDivider()
|
||||
val statusText = if (uiState.exactAlarmStatus)
|
||||
stringResource(Res.string.status_enabled)
|
||||
else
|
||||
stringResource(Res.string.status_disabled)
|
||||
|
||||
SettingItemRow(
|
||||
title = stringResource(Res.string.item_exact_alarm_permission),
|
||||
currentValue = statusText,
|
||||
onClick = { openExactAlarmSettings(context) }
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
// 6. 勿扰模式权限:直接跳转页面
|
||||
val dndStatusText = if (uiState.dndPermissionStatus)
|
||||
stringResource(Res.string.status_authorized)
|
||||
else
|
||||
stringResource(Res.string.status_unauthorized)
|
||||
|
||||
SettingItemRow(
|
||||
title = stringResource(Res.string.item_dnd_permission),
|
||||
currentValue = dndStatusText,
|
||||
onClick = { openDndSettings(context) }
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
// 7. 后台与自启动
|
||||
SettingItemRow(
|
||||
title = stringResource(Res.string.item_background_and_autostart),
|
||||
onClick = onAppSettingsClick
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
// 8. 忽略电池优化
|
||||
SettingItemRow(
|
||||
title = stringResource(Res.string.item_ignore_battery_optimization),
|
||||
onClick = onBatteryOptimizationClick
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 点击开启上课提醒无权限时显示的弹窗
|
||||
if (showExactAlarmDialog) {
|
||||
ExactAlarmPermissionGuideDialog(
|
||||
onDismiss = { showExactAlarmDialog = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
+340
@@ -0,0 +1,340 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.settings.notification
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.AutoControlMode
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.components.ToastManager
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import shiguangschedule.shared.generated.resources.Res
|
||||
import shiguangschedule.shared.generated.resources.action_cancel
|
||||
import shiguangschedule.shared.generated.resources.action_close
|
||||
import shiguangschedule.shared.generated.resources.action_confirm
|
||||
import shiguangschedule.shared.generated.resources.action_go_to_settings
|
||||
import shiguangschedule.shared.generated.resources.auto_mode_dnd
|
||||
import shiguangschedule.shared.generated.resources.auto_mode_dnd_permission_warning
|
||||
import shiguangschedule.shared.generated.resources.auto_mode_off
|
||||
import shiguangschedule.shared.generated.resources.auto_mode_silent
|
||||
import shiguangschedule.shared.generated.resources.dialog_text_clear_confirmation
|
||||
import shiguangschedule.shared.generated.resources.dialog_text_dnd_permission
|
||||
import shiguangschedule.shared.generated.resources.dialog_text_exact_alarm_permission
|
||||
import shiguangschedule.shared.generated.resources.dialog_title_auto_mode_selection
|
||||
import shiguangschedule.shared.generated.resources.dialog_title_clear_confirmation
|
||||
import shiguangschedule.shared.generated.resources.dialog_title_dnd_permission
|
||||
import shiguangschedule.shared.generated.resources.dialog_title_exact_alarm_permission
|
||||
import shiguangschedule.shared.generated.resources.dialog_title_set_remind_time
|
||||
import shiguangschedule.shared.generated.resources.dialog_title_view_skipped_dates
|
||||
import shiguangschedule.shared.generated.resources.label_minutes_input
|
||||
import shiguangschedule.shared.generated.resources.skipped_dates_none
|
||||
import shiguangschedule.shared.generated.resources.toast_clear_failed
|
||||
import shiguangschedule.shared.generated.resources.toast_clear_success
|
||||
|
||||
/**
|
||||
* Android 专属的弹窗派发器
|
||||
* 移除多余的 Worker 触发回调,由后台的 SyncManager 统一通过 Flow 响应式调度
|
||||
*/
|
||||
@Composable
|
||||
fun NotificationDialogDispatcher(
|
||||
uiState: NotificationSettingsUiState,
|
||||
viewModel: NotificationSettingsViewModel
|
||||
) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
var showDndGuideDialog by remember { mutableStateOf(false) }
|
||||
|
||||
when (uiState.activeDialog) {
|
||||
is NotificationDialogType.EditRemindMinutes -> {
|
||||
var tempInput by remember(uiState.remindBeforeMinutes) {
|
||||
mutableStateOf(uiState.remindBeforeMinutes.toString())
|
||||
}
|
||||
EditRemindMinutesDialog(
|
||||
currentMinutes = tempInput,
|
||||
onMinutesChange = { tempInput = it.filter { c -> c.isDigit() } },
|
||||
onConfirm = {
|
||||
val mins = tempInput.toIntOrNull() ?: 15
|
||||
viewModel.updateRemindBeforeMinutes(mins)
|
||||
viewModel.dismissDialog()
|
||||
},
|
||||
onDismiss = { viewModel.dismissDialog() }
|
||||
)
|
||||
}
|
||||
|
||||
is NotificationDialogType.AutoModeSelection -> {
|
||||
AutoModeSelectionDialog(
|
||||
currentAutoModeEnabled = uiState.autoModeEnabled,
|
||||
currentAutoControlMode = uiState.autoControlMode,
|
||||
hasDndPermission = uiState.dndPermissionStatus,
|
||||
onModeSelected = { selectedKey ->
|
||||
if (selectedKey == "OFF") {
|
||||
viewModel.updateAutoMode(false, uiState.autoControlMode)
|
||||
} else if (selectedKey is AutoControlMode) {
|
||||
viewModel.updateAutoMode(true, selectedKey)
|
||||
}
|
||||
viewModel.dismissDialog()
|
||||
},
|
||||
onRequireDndPermission = {
|
||||
showDndGuideDialog = true
|
||||
},
|
||||
onDismiss = { viewModel.dismissDialog() }
|
||||
)
|
||||
}
|
||||
|
||||
is NotificationDialogType.ClearConfirmation -> {
|
||||
val successMsg = stringResource(Res.string.toast_clear_success)
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { viewModel.dismissDialog() },
|
||||
title = { Text(stringResource(Res.string.dialog_title_clear_confirmation)) },
|
||||
text = { Text(stringResource(Res.string.dialog_text_clear_confirmation)) },
|
||||
confirmButton = {
|
||||
Button(onClick = {
|
||||
viewModel.clearSkippedDates { result ->
|
||||
result.fold(
|
||||
onSuccess = { ToastManager.show(successMsg) },
|
||||
onFailure = { e ->
|
||||
coroutineScope.launch {
|
||||
val errorMsg = getString(Res.string.toast_clear_failed, e.message ?: "")
|
||||
ToastManager.show(errorMsg)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
viewModel.dismissDialog()
|
||||
}) { Text(stringResource(Res.string.action_confirm)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { viewModel.dismissDialog() }) { Text(stringResource(Res.string.action_cancel)) }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
is NotificationDialogType.ViewSkippedDates -> {
|
||||
ViewSkippedDatesDialog(
|
||||
dates = uiState.skippedDates,
|
||||
onDismiss = { viewModel.dismissDialog() }
|
||||
)
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
|
||||
// 选中自动模式无权限时,弹出勿扰权限引导弹窗
|
||||
if (showDndGuideDialog) {
|
||||
DndPermissionGuideDialog(
|
||||
onDismiss = { showDndGuideDialog = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Android 专属的权限引导弹窗组
|
||||
* 由 Android 侧组件按照本地 UI State 显隐控制并调用
|
||||
*/
|
||||
@Composable
|
||||
fun ExactAlarmPermissionGuideDialog(
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
PermissionGuideDialog(
|
||||
title = stringResource(Res.string.dialog_title_exact_alarm_permission),
|
||||
text = stringResource(Res.string.dialog_text_exact_alarm_permission),
|
||||
onConfirm = { openExactAlarmSettings(context) },
|
||||
onDismiss = onDismiss
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DndPermissionGuideDialog(
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
PermissionGuideDialog(
|
||||
title = stringResource(Res.string.dialog_title_dnd_permission),
|
||||
text = stringResource(Res.string.dialog_text_dnd_permission),
|
||||
onConfirm = { openDndSettings(context) },
|
||||
onDismiss = onDismiss
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AutoModeSelectionDialog(
|
||||
currentAutoModeEnabled: Boolean,
|
||||
currentAutoControlMode: AutoControlMode,
|
||||
hasDndPermission: Boolean,
|
||||
onModeSelected: (Any) -> Unit,
|
||||
onRequireDndPermission: () -> Unit,
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
var selectedKey by remember { mutableStateOf<Any>(if (currentAutoModeEnabled) currentAutoControlMode else "OFF") }
|
||||
|
||||
val modeOptions = listOf(
|
||||
"OFF" to stringResource(Res.string.auto_mode_off),
|
||||
AutoControlMode.DND to stringResource(Res.string.auto_mode_dnd),
|
||||
AutoControlMode.SILENT to stringResource(Res.string.auto_mode_silent)
|
||||
)
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(Res.string.dialog_title_auto_mode_selection)) },
|
||||
text = {
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
if (!hasDndPermission) {
|
||||
Text(
|
||||
text = stringResource(Res.string.auto_mode_dnd_permission_warning),
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
modifier = Modifier.padding(bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
modeOptions.forEach { (optionKey, label) ->
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { selectedKey = optionKey }
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
RadioButton(selected = (selectedKey == optionKey), onClick = { selectedKey = optionKey })
|
||||
Text(label, modifier = Modifier.padding(start = 8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
Button(onClick = {
|
||||
if (selectedKey != "OFF" && !hasDndPermission) {
|
||||
onDismiss()
|
||||
onRequireDndPermission()
|
||||
} else {
|
||||
onModeSelected(selectedKey)
|
||||
}
|
||||
}) {
|
||||
Text(stringResource(Res.string.action_confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(Res.string.action_cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EditRemindMinutesDialog(
|
||||
currentMinutes: String,
|
||||
onMinutesChange: (String) -> Unit,
|
||||
onConfirm: () -> Unit,
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(Res.string.dialog_title_set_remind_time)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = currentMinutes,
|
||||
onValueChange = onMinutesChange,
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
||||
label = { Text(stringResource(Res.string.label_minutes_input)) },
|
||||
singleLine = true,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
Button(onClick = onConfirm) { Text(stringResource(Res.string.action_confirm)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(Res.string.action_cancel)) }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ViewSkippedDatesDialog(dates: Set<String>, onDismiss: () -> Unit) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(Res.string.dialog_title_view_skipped_dates)) },
|
||||
text = {
|
||||
if (dates.isEmpty()) {
|
||||
Text(stringResource(Res.string.skipped_dates_none))
|
||||
} else {
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(100.dp),
|
||||
modifier = Modifier.heightIn(max = 300.dp)
|
||||
) {
|
||||
items(dates.toList().sorted()) { date ->
|
||||
Surface(
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
color = MaterialTheme.colorScheme.secondaryContainer,
|
||||
modifier = Modifier.padding(4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = date,
|
||||
modifier = Modifier.padding(8.dp),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSecondaryContainer
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
Button(onClick = onDismiss) { Text(stringResource(Res.string.action_close)) }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用权限引导弹窗基础 UI Component
|
||||
*/
|
||||
@Composable
|
||||
fun PermissionGuideDialog(
|
||||
title: String,
|
||||
text: String,
|
||||
onConfirm: () -> Unit,
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = { Text(text) },
|
||||
confirmButton = {
|
||||
Button(onClick = {
|
||||
onConfirm()
|
||||
onDismiss()
|
||||
}) { Text(stringResource(Res.string.action_go_to_settings)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(Res.string.action_cancel)) }
|
||||
}
|
||||
)
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.settings.notification
|
||||
|
||||
import android.Manifest
|
||||
import android.app.AlarmManager
|
||||
import android.app.NotificationManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.net.toUri
|
||||
|
||||
// --- 权限检查逻辑 ---
|
||||
|
||||
/**
|
||||
* 检查是否拥有精确闹钟调度权限
|
||||
*/
|
||||
fun hasExactAlarmPermission(context: Context): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = context.getSystemService<AlarmManager>()
|
||||
alarmManager?.canScheduleExactAlarms() ?: false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否拥有发送通知权限 (Android 13+)
|
||||
*/
|
||||
fun hasNotificationPermission(context: Context): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
ContextCompat.checkSelfPermission(
|
||||
context, Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否拥有勿扰模式 (DND) 控制权限
|
||||
*/
|
||||
fun hasDndPermission(context: Context): Boolean {
|
||||
val notificationManager = context.getSystemService<NotificationManager>()
|
||||
return notificationManager?.isNotificationPolicyAccessGranted ?: false
|
||||
}
|
||||
|
||||
// --- 系统设置页面跳转 ---
|
||||
|
||||
/**
|
||||
* 打开精确闹钟权限设置页
|
||||
*/
|
||||
fun openExactAlarmSettings(context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
safelyStartActivity(context, intent) { openAppSettings(context) }
|
||||
} else {
|
||||
openAppSettings(context)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开勿扰权限设置页
|
||||
*/
|
||||
fun openDndSettings(context: Context) {
|
||||
val intent = Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
safelyStartActivity(context, intent) { openAppSettings(context) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开当前应用的系统设置详情页
|
||||
*/
|
||||
fun openAppSettings(context: Context) {
|
||||
val intent = Intent(
|
||||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
"package:${context.packageName}".toUri()
|
||||
).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
safelyStartActivity(context, intent)
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开忽略电池优化设置页
|
||||
*/
|
||||
fun openIgnoreBatteryOptimizationSettings(context: Context) {
|
||||
val intent = Intent(
|
||||
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
"package:${context.packageName}".toUri()
|
||||
).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
safelyStartActivity(context, intent) { openAppSettings(context) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全启动 Activity,防止由于系统裁剪导致 ActivityNotFoundException
|
||||
*/
|
||||
private inline fun safelyStartActivity(
|
||||
context: Context,
|
||||
intent: Intent,
|
||||
onFallback: () -> Unit = {}
|
||||
) {
|
||||
try {
|
||||
context.startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
onFallback()
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.settings.notification
|
||||
|
||||
import android.Manifest
|
||||
import android.os.Build
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.AutoControlMode
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.components.ToastManager
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import shiguangschedule.shared.generated.resources.Res
|
||||
import shiguangschedule.shared.generated.resources.auto_mode_dnd
|
||||
import shiguangschedule.shared.generated.resources.auto_mode_off
|
||||
import shiguangschedule.shared.generated.resources.auto_mode_silent
|
||||
import shiguangschedule.shared.generated.resources.toast_enable_reminder_first
|
||||
import shiguangschedule.shared.generated.resources.toast_notification_permission_denied
|
||||
|
||||
/**
|
||||
* 平台通用的常规设置区块实现(Android 端)
|
||||
*/
|
||||
@Composable
|
||||
actual fun PlatformGeneralSettingsSection(
|
||||
uiState: NotificationSettingsUiState,
|
||||
viewModel: NotificationSettingsViewModel
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val lifecycleOwner = LocalLifecycleOwner.current
|
||||
|
||||
// 注册通知权限请求器,若用户拒绝授权则通过 ToastManager 弹出提示
|
||||
val permissionDeniedMessage = stringResource(Res.string.toast_notification_permission_denied)
|
||||
val notificationLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.RequestPermission()
|
||||
) { isGranted ->
|
||||
if (!isGranted) {
|
||||
ToastManager.show(permissionDeniedMessage)
|
||||
}
|
||||
}
|
||||
|
||||
// 监听生命周期:每次页面重新回到前台
|
||||
DisposableEffect(lifecycleOwner) {
|
||||
val observer = LifecycleEventObserver { _, event ->
|
||||
if (event == Lifecycle.Event.ON_RESUME) {
|
||||
viewModel.updateExactAlarmStatus(hasExactAlarmPermission(context))
|
||||
viewModel.updateDndPermissionStatus(hasDndPermission(context))
|
||||
}
|
||||
}
|
||||
lifecycleOwner.lifecycle.addObserver(observer)
|
||||
|
||||
onDispose {
|
||||
lifecycleOwner.lifecycle.removeObserver(observer)
|
||||
}
|
||||
}
|
||||
|
||||
// 页面首次挂载时在 Android 13+ 平台上按需发起通知权限申请
|
||||
LaunchedEffect(Unit) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && !hasNotificationPermission(context)) {
|
||||
notificationLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
}
|
||||
|
||||
val currentModeText = if (!uiState.autoModeEnabled) {
|
||||
stringResource(Res.string.auto_mode_off)
|
||||
} else {
|
||||
when (uiState.autoControlMode) {
|
||||
AutoControlMode.DND -> stringResource(Res.string.auto_mode_dnd)
|
||||
AutoControlMode.SILENT -> stringResource(Res.string.auto_mode_silent)
|
||||
}
|
||||
}
|
||||
|
||||
val enableReminderToast = stringResource(Res.string.toast_enable_reminder_first)
|
||||
|
||||
GeneralSettingsCard(
|
||||
uiState = uiState,
|
||||
currentModeText = currentModeText,
|
||||
onReminderToggle = { isEnabled ->
|
||||
viewModel.updateReminderEnabled(isEnabled)
|
||||
},
|
||||
onCompatWearableToggle = { isEnabled ->
|
||||
viewModel.updateCompatWearableSync(isEnabled)
|
||||
},
|
||||
onAutoModeClick = {
|
||||
if (uiState.reminderEnabled) {
|
||||
viewModel.showDialog(NotificationDialogType.AutoModeSelection)
|
||||
} else {
|
||||
ToastManager.show(enableReminderToast)
|
||||
}
|
||||
},
|
||||
onRemindTimeClick = { viewModel.showDialog(NotificationDialogType.EditRemindMinutes) },
|
||||
onAppSettingsClick = { openAppSettings(context) },
|
||||
onBatteryOptimizationClick = { openIgnoreBatteryOptimizationSettings(context) }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台通用的通知设置弹窗分发器实现(Android 端)
|
||||
*/
|
||||
@Composable
|
||||
actual fun PlatformNotificationDialogDispatcher(
|
||||
uiState: NotificationSettingsUiState,
|
||||
viewModel: NotificationSettingsViewModel
|
||||
) {
|
||||
NotificationDialogDispatcher(
|
||||
uiState = uiState,
|
||||
viewModel = viewModel
|
||||
)
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.ui.theme
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Build
|
||||
import androidx.annotation.ChecksSdkIntAtLeast
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.AppThemeMode
|
||||
|
||||
@Composable
|
||||
actual fun rememberColorScheme(
|
||||
darkTheme: Boolean,
|
||||
dynamicColor: Boolean,
|
||||
customLightPrimary: Color,
|
||||
customDarkPrimary: Color
|
||||
): ColorScheme {
|
||||
val context = LocalContext.current
|
||||
return when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
else -> {
|
||||
val seedColor = if (darkTheme) customDarkPrimary else customLightPrimary
|
||||
rememberMaterialKolorScheme(
|
||||
darkTheme = darkTheme,
|
||||
seedColor = seedColor
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun SetupPlatformThemeEffects(
|
||||
colorScheme: ColorScheme,
|
||||
darkTheme: Boolean,
|
||||
themeMode: AppThemeMode
|
||||
) {
|
||||
val view = LocalView.current
|
||||
if (!view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
|
||||
val backgroundColor = colorScheme.background.toArgb()
|
||||
window.setBackgroundDrawable(backgroundColor.toDrawable())
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
window.statusBarColor = Color.Transparent.toArgb()
|
||||
@Suppress("DEPRECATION")
|
||||
window.navigationBarColor = Color.Transparent.toArgb()
|
||||
|
||||
val insetsController = WindowCompat.getInsetsController(window, view)
|
||||
insetsController.isAppearanceLightStatusBars = !darkTheme
|
||||
insetsController.isAppearanceLightNavigationBars = !darkTheme
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@get:ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
|
||||
actual val supportsDynamicColor: Boolean
|
||||
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M234,684Q285,645 348,622.5Q411,600 480,600Q549,600 612,622.5Q675,645 726,684Q761,643 780.5,591Q800,539 800,480Q800,347 706.5,253.5Q613,160 480,160Q347,160 253.5,253.5Q160,347 160,480Q160,539 179.5,591Q199,643 234,684ZM380.5,479.5Q340,439 340,380Q340,321 380.5,280.5Q421,240 480,240Q539,240 579.5,280.5Q620,321 620,380Q620,439 579.5,479.5Q539,520 480,520Q421,520 380.5,479.5ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM580,784.5Q627,769 666,740Q627,711 580,695.5Q533,680 480,680Q427,680 380,695.5Q333,711 294,740Q333,769 380,784.5Q427,800 480,800Q533,800 580,784.5ZM523,423Q540,406 540,380Q540,354 523,337Q506,320 480,320Q454,320 437,337Q420,354 420,380Q420,406 437,423Q454,440 480,440Q506,440 523,423ZM480,380Q480,380 480,380Q480,380 480,380Q480,380 480,380Q480,380 480,380Q480,380 480,380Q480,380 480,380Q480,380 480,380Q480,380 480,380ZM480,740Q480,740 480,740Q480,740 480,740Q480,740 480,740Q480,740 480,740Q480,740 480,740Q480,740 480,740Q480,740 480,740Q480,740 480,740Z"/>
|
||||
</vector>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M234,684Q285,645 348,622.5Q411,600 480,600Q549,600 612,622.5Q675,645 726,684Q761,643 780.5,591Q800,539 800,480Q800,347 706.5,253.5Q613,160 480,160Q347,160 253.5,253.5Q160,347 160,480Q160,539 179.5,591Q199,643 234,684ZM380.5,479.5Q340,439 340,380Q340,321 380.5,280.5Q421,240 480,240Q539,240 579.5,280.5Q620,321 620,380Q620,439 579.5,479.5Q539,520 480,520Q421,520 380.5,479.5ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M440,520L200,520L200,440L440,440L440,200L520,200L520,440L760,440L760,520L520,520L520,760L440,760L440,520Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M480,720L640,560L584,504L520,568L520,400L440,400L440,568L376,504L320,560L480,720ZM200,320L200,760Q200,760 200,760Q200,760 200,760L760,760Q760,760 760,760Q760,760 760,760L760,320L200,320ZM200,840Q167,840 143.5,816.5Q120,793 120,760L120,261Q120,247 124.5,234Q129,221 138,210L188,149Q199,135 215.5,127.5Q232,120 250,120L710,120Q728,120 744.5,127.5Q761,135 772,149L822,210Q831,221 835.5,234Q840,247 840,261L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM216,240L744,240L710,200Q710,200 710,200Q710,200 710,200L250,200Q250,200 250,200Q250,200 250,200L216,240ZM480,540L480,540L480,540Q480,540 480,540Q480,540 480,540L480,540Q480,540 480,540Q480,540 480,540Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M313,520L537,744L480,800L160,480L480,160L537,216L313,440L800,440L800,520L313,520Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M440,160L440,647L216,423L160,480L480,800L800,480L744,423L520,647L520,160L440,160Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M480,600L280,400L680,400L480,600Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M647,520L160,520L160,440L647,440L423,216L480,160L800,480L480,800L423,744L647,520Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M200,880Q167,880 143.5,856.5Q120,833 120,800L120,240Q120,207 143.5,183.5Q167,160 200,160L240,160L240,80L320,80L320,160L640,160L640,80L720,80L720,160L760,160Q793,160 816.5,183.5Q840,207 840,240L840,800Q840,833 816.5,856.5Q793,880 760,880L200,880ZM200,800L760,800Q760,800 760,800Q760,800 760,800L760,400L200,400L200,800Q200,800 200,800Q200,800 200,800ZM200,320L760,320L760,240Q760,240 760,240Q760,240 760,240L200,240Q200,240 200,240Q200,240 200,240L200,320ZM200,320L200,240Q200,240 200,240Q200,240 200,240L200,240Q200,240 200,240Q200,240 200,240L200,320Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M382,720L154,492L211,435L382,606L749,239L806,296L382,720Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M424,664L706,382L650,326L424,552L310,438L254,494L424,664ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,346 707,253Q614,160 480,160Q346,160 253,253Q160,346 160,480Q160,614 253,707Q346,800 480,800ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M504,480L320,296L376,240L616,480L376,720L320,664L504,480Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M240,880Q207,880 183.5,856.5Q160,833 160,800L160,160Q160,127 183.5,103.5Q207,80 240,80L720,80Q753,80 776.5,103.5Q800,127 800,160L800,800Q800,833 776.5,856.5Q753,880 720,880L240,880ZM240,800L720,800Q720,800 720,800Q720,800 720,800L720,160Q720,160 720,160Q720,160 720,160L640,160L640,440L540,380L440,440L440,160L240,160Q240,160 240,160Q240,160 240,160L240,800Q240,800 240,800Q240,800 240,800ZM240,800Q240,800 240,800Q240,800 240,800L240,160Q240,160 240,160Q240,160 240,160L240,160Q240,160 240,160Q240,160 240,160L240,800Q240,800 240,800Q240,800 240,800ZM440,440L540,380L640,440L640,440L540,380L440,440Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M256,760L200,704L424,480L200,256L256,200L480,424L704,200L760,256L536,480L760,704L704,760L480,536L256,760Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M260,800Q169,800 104.5,737Q40,674 40,583Q40,505 87,444Q134,383 210,366Q235,274 310,217Q385,160 480,160Q597,160 678.5,241.5Q760,323 760,440L760,440L760,440Q829,448 874.5,499.5Q920,551 920,620Q920,695 867.5,747.5Q815,800 740,800L260,800ZM260,720L740,720Q782,720 811,691Q840,662 840,620Q840,578 811,549Q782,520 740,520L680,520L680,440Q680,357 621.5,298.5Q563,240 480,240Q397,240 338.5,298.5Q280,357 280,440L280,440L260,440Q202,440 161,481Q120,522 120,580Q120,638 161,679Q202,720 260,720ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480L480,480L480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480L480,480L480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M280,840Q247,840 223.5,816.5Q200,793 200,760L200,240L160,240L160,160L360,160L360,120L600,120L600,160L800,160L800,240L760,240L760,760Q760,793 736.5,816.5Q713,840 680,840L280,840ZM680,240L280,240L280,760Q280,760 280,760Q280,760 280,760L680,760Q680,760 680,760Q680,760 680,760L680,240ZM360,680L440,680L440,320L360,320L360,680ZM520,680L600,680L600,320L520,320L520,680ZM280,240L280,240L280,760Q280,760 280,760Q280,760 280,760L280,760Q280,760 280,760Q280,760 280,760L280,240Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M320,840L320,760L400,760L400,680L160,680Q127,680 103.5,656.5Q80,633 80,600L80,200Q80,167 103.5,143.5Q127,120 160,120L800,120Q833,120 856.5,143.5Q880,167 880,200L880,600Q880,633 856.5,656.5Q833,680 800,680L560,680L560,760L640,760L640,840L320,840ZM160,600L800,600Q800,600 800,600Q800,600 800,600L800,200Q800,200 800,200Q800,200 800,200L160,200Q160,200 160,200Q160,200 160,200L160,600Q160,600 160,600Q160,600 160,600ZM160,600Q160,600 160,600Q160,600 160,600L160,200Q160,200 160,200Q160,200 160,200L160,200Q160,200 160,200Q160,200 160,200L160,600Q160,600 160,600Q160,600 160,600Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M242,760L442,480L242,200L340,200L540,480L340,760L242,760ZM480,760L680,480L480,200L578,200L778,480L578,760L480,760Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M480,640L280,440L336,382L440,486L440,160L520,160L520,486L624,382L680,440L480,640ZM240,800Q207,800 183.5,776.5Q160,753 160,720L160,600L240,600L240,720Q240,720 240,720Q240,720 240,720L720,720Q720,720 720,720Q720,720 720,720L720,600L800,600L800,720Q800,753 776.5,776.5Q753,800 720,800L240,800Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M200,760L257,760L648,369L591,312L200,703L200,760ZM120,840L120,670L648,143Q660,132 674.5,126Q689,120 705,120Q721,120 736,126Q751,132 762,144L817,200Q829,211 834.5,226Q840,241 840,256Q840,272 834.5,286.5Q829,301 817,313L290,840L120,840ZM760,256L760,256L704,200L704,200L760,256ZM619,341L591,312L591,312L648,369L648,369L619,341Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M400,720L400,640L560,640L560,720L400,720ZM240,520L240,440L720,440L720,520L240,520ZM120,320L120,240L840,240L840,320L120,320Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M240,760L360,760L360,520L600,520L600,760L720,760L720,400L480,220L240,400L240,760ZM160,840L160,360L480,120L800,360L800,840L520,840L520,600L440,600L440,840L160,840ZM480,490L480,490L480,490L480,490L480,490L480,490L480,490L480,490L480,490Z"/>
|
||||
</vector>
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM200,760L760,760Q760,760 760,760Q760,760 760,760L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760ZM240,680L720,680L570,480L450,640L360,520L240,680ZM200,760Q200,760 200,760Q200,760 200,760L200,200Q200,200 200,200Q200,200 200,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M440,680L280,680Q197,680 138.5,621.5Q80,563 80,480Q80,397 138.5,338.5Q197,280 280,280L440,280L440,360L280,360Q230,360 195,395Q160,430 160,480Q160,530 195,565Q230,600 280,600L440,600L440,680ZM320,520L320,440L640,440L640,520L320,520ZM520,680L520,600L680,600Q730,600 765,565Q800,530 800,480Q800,430 765,395Q730,360 680,360L520,360L520,280L680,280Q763,280 821.5,338.5Q880,397 880,480Q880,563 821.5,621.5Q763,680 680,680L520,680Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M536.5,456.5Q560,433 560,400Q560,367 536.5,343.5Q513,320 480,320Q447,320 423.5,343.5Q400,367 400,400Q400,433 423.5,456.5Q447,480 480,480Q513,480 536.5,456.5ZM480,774Q602,662 661,570.5Q720,479 720,408Q720,299 650.5,229.5Q581,160 480,160Q379,160 309.5,229.5Q240,299 240,408Q240,479 299,570.5Q358,662 480,774ZM480,880Q319,743 239.5,625.5Q160,508 160,408Q160,258 256.5,169Q353,80 480,80Q607,80 703.5,169Q800,258 800,408Q800,508 720.5,625.5Q641,743 480,880ZM480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M120,720L120,640L640,640L640,720L120,720ZM784,680L584,480L784,280L840,336L696,480L840,624L784,680ZM120,520L120,440L520,440L520,520L120,520ZM120,320L120,240L640,240L640,320L120,320Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M240,560Q207,560 183.5,536.5Q160,513 160,480Q160,447 183.5,423.5Q207,400 240,400Q273,400 296.5,423.5Q320,447 320,480Q320,513 296.5,536.5Q273,560 240,560ZM480,560Q447,560 423.5,536.5Q400,513 400,480Q400,447 423.5,423.5Q447,400 480,400Q513,400 536.5,423.5Q560,447 560,480Q560,513 536.5,536.5Q513,560 480,560ZM720,560Q687,560 663.5,536.5Q640,513 640,480Q640,447 663.5,423.5Q687,400 720,400Q753,400 776.5,423.5Q800,447 800,480Q800,513 776.5,536.5Q753,560 720,560Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M480,800Q447,800 423.5,776.5Q400,753 400,720Q400,687 423.5,663.5Q447,640 480,640Q513,640 536.5,663.5Q560,687 560,720Q560,753 536.5,776.5Q513,800 480,800ZM480,560Q447,560 423.5,536.5Q400,513 400,480Q400,447 423.5,423.5Q447,400 480,400Q513,400 536.5,423.5Q560,447 560,480Q560,513 536.5,536.5Q513,560 480,560ZM480,320Q447,320 423.5,296.5Q400,273 400,240Q400,207 423.5,183.5Q447,160 480,160Q513,160 536.5,183.5Q560,207 560,240Q560,273 536.5,296.5Q513,320 480,320Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M480,880Q398,880 325,848.5Q252,817 197.5,762.5Q143,708 111.5,635Q80,562 80,480Q80,397 112.5,324Q145,251 200.5,197Q256,143 330,111.5Q404,80 488,80Q568,80 639,107.5Q710,135 763.5,183.5Q817,232 848.5,298.5Q880,365 880,442Q880,557 810,618.5Q740,680 640,680L566,680Q557,680 553.5,685Q550,690 550,696Q550,708 565,730.5Q580,753 580,782Q580,832 552.5,856Q525,880 480,880ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480ZM303,503Q320,486 320,460Q320,434 303,417Q286,400 260,400Q234,400 217,417Q200,434 200,460Q200,486 217,503Q234,520 260,520Q286,520 303,503ZM423,343Q440,326 440,300Q440,274 423,257Q406,240 380,240Q354,240 337,257Q320,274 320,300Q320,326 337,343Q354,360 380,360Q406,360 423,343ZM623,343Q640,326 640,300Q640,274 623,257Q606,240 580,240Q554,240 537,257Q520,274 520,300Q520,326 537,343Q554,360 580,360Q606,360 623,343ZM743,503Q760,486 760,460Q760,434 743,417Q726,400 700,400Q674,400 657,417Q640,434 640,460Q640,486 657,503Q674,520 700,520Q726,520 743,503ZM480,800Q489,800 494.5,795Q500,790 500,782Q500,768 485,749Q470,730 470,692Q470,650 499,625Q528,600 570,600L640,600Q706,600 753,561.5Q800,523 800,442Q800,321 707.5,240.5Q615,160 488,160Q352,160 256,253Q160,346 160,480Q160,613 253.5,706.5Q347,800 480,800Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M367,433Q320,386 320,320Q320,254 367,207Q414,160 480,160Q546,160 593,207Q640,254 640,320Q640,386 593,433Q546,480 480,480Q414,480 367,433ZM160,800L160,688Q160,654 177.5,625.5Q195,597 224,582Q286,551 350,535.5Q414,520 480,520Q546,520 610,535.5Q674,551 736,582Q765,597 782.5,625.5Q800,654 800,688L800,800L160,800ZM240,720L720,720L720,688Q720,677 714.5,668Q709,659 700,654Q646,627 591,613.5Q536,600 480,600Q424,600 369,613.5Q314,627 260,654Q251,659 245.5,668Q240,677 240,688L240,720ZM536.5,376.5Q560,353 560,320Q560,287 536.5,263.5Q513,240 480,240Q447,240 423.5,263.5Q400,287 400,320Q400,353 423.5,376.5Q447,400 480,400Q513,400 536.5,376.5ZM480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320ZM480,720L480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720L480,720Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M280,920Q247,920 223.5,896.5Q200,873 200,840L200,120Q200,87 223.5,63.5Q247,40 280,40L680,40Q713,40 736.5,63.5Q760,87 760,120L760,244Q778,251 789,266Q800,281 800,300L800,380Q800,399 789,414Q778,429 760,436L760,840Q760,873 736.5,896.5Q713,920 680,920L280,920ZM280,840L680,840Q680,840 680,840Q680,840 680,840L680,120Q680,120 680,120Q680,120 680,120L280,120Q280,120 280,120Q280,120 280,120L280,840Q280,840 280,840Q280,840 280,840ZM280,840Q280,840 280,840Q280,840 280,840L280,120Q280,120 280,120Q280,120 280,120L280,120Q280,120 280,120Q280,120 280,120L280,840Q280,840 280,840Q280,840 280,840ZM508.5,788.5Q520,777 520,760Q520,743 508.5,731.5Q497,720 480,720Q463,720 451.5,731.5Q440,743 440,760Q440,777 451.5,788.5Q463,800 480,800Q497,800 508.5,788.5Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M480,800Q346,800 253,707Q160,614 160,480Q160,346 253,253Q346,160 480,160Q549,160 612,188.5Q675,217 720,270L720,160L800,160L800,440L520,440L520,360L688,360Q656,304 600.5,272Q545,240 480,240Q380,240 310,310Q240,380 240,480Q240,580 310,650Q380,720 480,720Q557,720 619,676Q681,632 706,560L790,560Q762,666 676,733Q590,800 480,800Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M840,280L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L680,120L840,280ZM760,314L646,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760L760,760Q760,760 760,760Q760,760 760,760L760,314ZM565,685Q600,650 600,600Q600,550 565,515Q530,480 480,480Q430,480 395,515Q360,550 360,600Q360,650 395,685Q430,720 480,720Q530,720 565,685ZM240,400L600,400L600,240L240,240L240,400ZM200,314L200,760Q200,760 200,760Q200,760 200,760L200,760Q200,760 200,760Q200,760 200,760L200,200Q200,200 200,200Q200,200 200,200L200,200L200,314Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M612,668L668,612L520,464L520,280L440,280L440,496L612,668ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480ZM480,800Q613,800 706.5,706.5Q800,613 800,480Q800,347 706.5,253.5Q613,160 480,160Q347,160 253.5,253.5Q160,347 160,480Q160,613 253.5,706.5Q347,800 480,800Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M200,760L560,760L560,560L760,560L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760ZM200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,600L600,840L200,840ZM280,560L280,480L480,480L480,560L280,560ZM280,400L280,320L680,320L680,400L280,400ZM200,760L200,760L200,560L200,200Q200,200 200,200Q200,200 200,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M280,800L80,600L280,400L336,457L233,560L520,560L520,640L233,640L336,743L280,800ZM680,560L624,503L727,400L440,400L440,320L727,320L624,217L680,160L880,360L680,560Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M280,840L80,640L280,440L337,496L233,600L840,600L840,680L233,680L337,784L280,840ZM680,520L623,464L727,360L120,360L120,280L727,280L623,176L680,120L880,320L680,520Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M440,840L440,600L520,600L520,680L840,680L840,760L520,760L520,840L440,840ZM120,760L120,680L360,680L360,760L120,760ZM280,600L280,520L120,520L120,440L280,440L280,360L360,360L360,600L280,600ZM440,520L440,440L840,440L840,520L440,520ZM600,360L600,120L680,120L680,200L840,200L840,280L680,280L680,360L600,360ZM120,280L120,200L520,200L520,280L120,280Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M440,640L440,314L336,418L280,360L480,160L680,360L624,418L520,314L520,640L440,640ZM240,800Q207,800 183.5,776.5Q160,753 160,720L160,600L240,600L240,720Q240,720 240,720Q240,720 240,720L720,720Q720,720 720,720Q720,720 720,720L720,600L800,600L800,720Q800,753 776.5,776.5Q753,800 720,800L240,800Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M200,440Q167,440 143.5,416.5Q120,393 120,360L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,360Q840,393 816.5,416.5Q793,440 760,440L200,440ZM200,360L760,360Q760,360 760,360Q760,360 760,360L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,360Q200,360 200,360Q200,360 200,360ZM200,840Q167,840 143.5,816.5Q120,793 120,760L120,600Q120,567 143.5,543.5Q167,520 200,520L760,520Q793,520 816.5,543.5Q840,567 840,600L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM200,760L760,760Q760,760 760,760Q760,760 760,760L760,600Q760,600 760,600Q760,600 760,600L200,600Q200,600 200,600Q200,600 200,600L200,760Q200,760 200,760Q200,760 200,760ZM200,200L200,200Q200,200 200,200Q200,200 200,200L200,360Q200,360 200,360Q200,360 200,360L200,360Q200,360 200,360Q200,360 200,360L200,200Q200,200 200,200Q200,200 200,200ZM200,600L200,600Q200,600 200,600Q200,600 200,600L200,760Q200,760 200,760Q200,760 200,760L200,760Q200,760 200,760Q200,760 200,760L200,600Q200,600 200,600Q200,600 200,600Z"/>
|
||||
</vector>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M200,440Q167,440 143.5,416.5Q120,393 120,360L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,360Q840,393 816.5,416.5Q793,440 760,440L200,440ZM200,840Q167,840 143.5,816.5Q120,793 120,760L120,600Q120,567 143.5,543.5Q167,520 200,520L760,520Q793,520 816.5,543.5Q840,567 840,600L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M160,720L320,720Q320,720 320,720Q320,720 320,720L320,240Q320,240 320,240Q320,240 320,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720ZM400,720L560,720Q560,720 560,720Q560,720 560,720L560,240Q560,240 560,240Q560,240 560,240L400,240Q400,240 400,240Q400,240 400,240L400,720Q400,720 400,720Q400,720 400,720ZM640,720L800,720Q800,720 800,720Q800,720 800,720L800,240Q800,240 800,240Q800,240 800,240L640,240Q640,240 640,240Q640,240 640,240L640,720Q640,720 640,720Q640,720 640,720ZM160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L800,160Q833,160 856.5,183.5Q880,207 880,240L880,720Q880,753 856.5,776.5Q833,800 800,800L160,800Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L213,160Q246,160 269.5,183.5Q293,207 293,240L293,720Q293,753 269.5,776.5Q246,800 213,800L160,800ZM454,800Q421,800 397.5,776.5Q374,753 374,720L374,240Q374,207 397.5,183.5Q421,160 454,160L507,160Q540,160 563.5,183.5Q587,207 587,240L587,720Q587,753 563.5,776.5Q540,800 507,800L454,800ZM747,800Q714,800 690.5,776.5Q667,753 667,720L667,240Q667,207 690.5,183.5Q714,160 747,160L800,160Q833,160 856.5,183.5Q880,207 880,240L880,720Q880,753 856.5,776.5Q833,800 800,800L747,800Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,261 @@
|
||||
// 基于 HTML 页面抓取的拾光课表正方适配脚本
|
||||
|
||||
/**
|
||||
* 解析表格
|
||||
*/
|
||||
function parserTbale() {
|
||||
const regexName = /[●★○]/g;
|
||||
const courseInfoList = [];
|
||||
const $ = window.jQuery;
|
||||
if (!$) return courseInfoList;
|
||||
|
||||
$('#kbgrid_table_0 td').each((i, td) => {
|
||||
if ($(td).hasClass('td_wrap') && $(td).text().trim() !== '') {
|
||||
const day = parseInt($(td).attr('id').split('-')[0]);
|
||||
|
||||
$(td).find('.timetable_con.text-left').each((i, course) => {
|
||||
const name = $(course).find('.title font').text().replace(regexName, '').trim();
|
||||
|
||||
const infoStr = $(course).find('p').eq(0).find('font').eq(1).text().trim();
|
||||
|
||||
const position = $(course).find('p').eq(1).find('font').text().trim();
|
||||
const teacher = $(course).find('p').eq(2).find('font').text().trim();
|
||||
|
||||
if (infoStr && infoStr.match(/\((\d+-\d+节)\)/) && infoStr.split('节)')[1]) {
|
||||
const [sections, weeks] = parserInfo(infoStr);
|
||||
|
||||
if (name && position && teacher && sections.length && weeks.length) {
|
||||
const startSection = sections[0];
|
||||
const endSection = sections[sections.length - 1];
|
||||
|
||||
const finalPosition = position.split(/\s+/).pop();
|
||||
|
||||
const data = { name, day, weeks, teacher, position: finalPosition, startSection, endSection };
|
||||
courseInfoList.push(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return courseInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析列表
|
||||
*/
|
||||
function parserList() {
|
||||
const regexName = /[●★○]/g;
|
||||
const regexWeekNum = /周数:|周/g;
|
||||
const regexPosition = /上课地点:/g;
|
||||
const regexTeacher = /教师 :/g;
|
||||
|
||||
const $ = window.jQuery;
|
||||
if (!$) return [];
|
||||
|
||||
let courseInfoList = [];
|
||||
$('#kblist_table tbody').each((day, tbody) => {
|
||||
if (day > 0 && day < 8) {
|
||||
let sections;
|
||||
$(tbody).find('tr:not(:first-child)').each((trIndex, tr) => {
|
||||
let name, font;
|
||||
|
||||
if ($(tr).find('td').length > 1) {
|
||||
sections = parserSections($(tr).find('td:first-child').text());
|
||||
name = $(tr).find('td:nth-child(2)').find('.title').text().replace(regexName, '').trim();
|
||||
font = $(tr).find('td:nth-child(2)').find('p font');
|
||||
} else {
|
||||
name = $(tr).find('td').find('.title').text().replace(regexName, '').trim();
|
||||
font = $(tr).find('td').find('p font');
|
||||
}
|
||||
|
||||
const weekStr = $(font[0]).text().replace(regexWeekNum, '').trim();
|
||||
const weeks = parserWeeks(weekStr);
|
||||
|
||||
const positionRaw = $(font[1]).text().replace(regexPosition, '').trim();
|
||||
const finalPosition = positionRaw.split(/\s+/).pop();
|
||||
|
||||
const teacher = $(font[2]).text().replace(regexTeacher, '').trim();
|
||||
|
||||
if (name && sections && weeks.length && teacher && finalPosition) {
|
||||
const startSection = sections[0];
|
||||
const endSection = sections[sections.length - 1];
|
||||
|
||||
const data = {
|
||||
name,
|
||||
day,
|
||||
weeks,
|
||||
teacher,
|
||||
position: finalPosition,
|
||||
startSection,
|
||||
endSection
|
||||
};
|
||||
courseInfoList.push(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return courseInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析课程信息
|
||||
*/
|
||||
function parserInfo(str) {
|
||||
const sections = parserSections(str.match(/\((\d+-\d+节)\)/)[1].replace(/节/g, ''));
|
||||
const weekStrWithMarker = str.split('节)')[1];
|
||||
const weeks = parserWeeks(weekStrWithMarker.replace(/周/g, '').trim());
|
||||
return [sections, weeks];
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析节次
|
||||
*/
|
||||
function parserSections(str) {
|
||||
const [start, end] = str.split('-').map(Number);
|
||||
if (isNaN(start) || isNaN(end) || start > end) return [];
|
||||
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析周次
|
||||
*/
|
||||
function parserWeeks(str) {
|
||||
const segments = str.split(',');
|
||||
let weeks = [];
|
||||
const segmentRegex = /(\d+)(?:-(\d+))?\s*(\([单双]\))?/g;
|
||||
|
||||
for (const segment of segments) {
|
||||
// 清理段落中的周字和多余空格
|
||||
const cleanSegment = segment.replace(/周/g, '').trim();
|
||||
|
||||
// 重置正则的 lastIndex
|
||||
segmentRegex.lastIndex = 0;
|
||||
|
||||
let match;
|
||||
// 循环匹配一个段落内可能存在的所有周次定义(虽然通常只有一个)
|
||||
while ((match = segmentRegex.exec(cleanSegment)) !== null) {
|
||||
const start = parseInt(match[1]);
|
||||
const end = match[2] ? parseInt(match[2]) : start;
|
||||
const flagStr = match[3] || ''; // (单) 或 (双) 或 ""
|
||||
|
||||
let flag = 0;
|
||||
if (flagStr.includes('单')) {
|
||||
flag = 1;
|
||||
} else if (flagStr.includes('双')) {
|
||||
flag = 2;
|
||||
}
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
// 过滤单双周
|
||||
if (flag === 1 && i % 2 !== 1) continue; // 仅保留单周
|
||||
if (flag === 2 && i % 2 !== 0) continue; // 仅保留双周
|
||||
|
||||
// 防止重复添加
|
||||
if (!weeks.includes(i)) {
|
||||
weeks.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 排序并返回唯一的周次列表
|
||||
return weeks.sort((a, b) => a - b);
|
||||
}
|
||||
|
||||
async function scrapeAndParseCourses() {
|
||||
window.shiguangBridge.showToast("正在检查页面并抓取课程数据...");
|
||||
const ts = `1.登陆教务系统\n2.导航到学生课表查询页面\n3.等待课表信息加载,选择对应学年、学期,确认无误后点击【查询】\n4.确保页面上显示了课程表\n5.点击下方【一键导入】`
|
||||
try {
|
||||
const response = await fetch(window.location.href);
|
||||
const text = await response.text();
|
||||
if (!text.includes("课表查询")) {
|
||||
console.log("页面内容检查失败!");
|
||||
await window.shiguangBridgePromise.showAlert("导入失败", "当前页面似乎不是学生课表查询页面。请检查:\n" + ts, "确定");
|
||||
return null;
|
||||
}
|
||||
const typeElement = document.querySelector('#shcPDF');
|
||||
if (!typeElement) {
|
||||
console.log("未能找到视图类型元素 (#shcPDF)");
|
||||
await window.shiguangBridgePromise.showAlert("导入失败", "未能识别课表视图类型,请确认您已点击查询且课表已加载完毕。", "确定");
|
||||
return null;
|
||||
}
|
||||
const type = typeElement.dataset['type'];
|
||||
const tableElement = document.querySelector(type === 'list' ? '#kblist_table' : '#kbgrid_table_0');
|
||||
if (!tableElement) {
|
||||
console.log("未能找到课表主体 HTML");
|
||||
await window.shiguangBridgePromise.showAlert("导入失败", `未能找到课表主体 (${type} 视图),请确认您已点击查询且课表已加载完毕。`, "确定");
|
||||
return null;
|
||||
}
|
||||
let result = [];
|
||||
if (type === 'list') {
|
||||
result = parserList();
|
||||
} else {
|
||||
result = parserTbale();
|
||||
}
|
||||
if (result.length === 0) {
|
||||
window.shiguangBridge.showToast("未找到任何课程数据,请检查所选学年学期是否正确或本学期无课。");
|
||||
return null;
|
||||
}
|
||||
console.log(`JS: 课程数据解析成功,共找到 ${result.length} 门课程。`);
|
||||
return { courses: result };
|
||||
} catch (error) {
|
||||
window.shiguangBridge.showToast(`抓取或解析失败: ${error.message}`);
|
||||
console.error('JS: Scrape/Parse Error:', error);
|
||||
await window.shiguangBridgePromise.showAlert("抓取或解析失败", `发生错误:${error.message}。请重试或联系开发者。`, "确定");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveCourses(parsedCourses) {
|
||||
window.shiguangBridge.showToast(`正在保存 ${parsedCourses.length} 门课程...`);
|
||||
console.log(`JS: 尝试保存 ${parsedCourses.length} 门课程...`);
|
||||
try {
|
||||
await window.shiguangBridgePromise.saveImportedCourses(JSON.stringify(parsedCourses, null, 2));
|
||||
console.log("JS: 课程保存成功!");
|
||||
return true;
|
||||
} catch (error) {
|
||||
window.shiguangBridge.showToast(`课程保存失败: ${error.message}`);
|
||||
console.error('JS: Save Courses Error:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function runImportFlow() {
|
||||
const alertConfirmed = await window.shiguangBridgePromise.showAlert(
|
||||
"教务系统课表导入",
|
||||
"导入前请确保您已在浏览器中成功登录教务系统,并处于课表查询页面且已点击查询。",
|
||||
"好的,开始导入"
|
||||
);
|
||||
if (!alertConfirmed) {
|
||||
window.shiguangBridge.showToast("用户取消了导入。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof window.jQuery === 'undefined' && typeof $ === 'undefined') {
|
||||
const errorMsg = "当前教务系统页面似乎没有加载 jQuery 库。本脚本依赖 jQuery 进行 DOM 解析。";
|
||||
window.shiguangBridge.showToast(errorMsg);
|
||||
await window.shiguangBridgePromise.showAlert("导入失败", errorMsg + "\n请尝试刷新页面或使用其他导入方式。", "确定");
|
||||
console.error("JS: 缺少 jQuery 依赖,流程终止。");
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await scrapeAndParseCourses();
|
||||
if (result === null) {
|
||||
console.log("JS: 课程获取或解析失败,流程终止。");
|
||||
return;
|
||||
}
|
||||
const { courses } = result;
|
||||
|
||||
const saveResult = await saveCourses(courses);
|
||||
if (!saveResult) {
|
||||
console.log("JS: 课程保存失败,流程终止。");
|
||||
return;
|
||||
}
|
||||
|
||||
window.shiguangBridge.showToast(`课程导入成功,共导入 ${courses.length} 门课程!`);
|
||||
console.log("JS: 整个导入流程执行完毕并成功。");
|
||||
window.shiguangBridge.notifyTaskCompletion();
|
||||
}
|
||||
|
||||
runImportFlow();
|
||||
@@ -0,0 +1,462 @@
|
||||
<resources>
|
||||
<!-- 应用基础信息 -->
|
||||
<string name="app_name">星课表</string>
|
||||
|
||||
<!-- 通用按钮和提示信息 -->
|
||||
<string name="action_confirm">确定</string>
|
||||
<string name="action_cancel">取消</string>
|
||||
<string name="a11y_save">保存</string>
|
||||
<string name="a11y_delete">删除</string>
|
||||
<string name="a11y_edit">编辑</string>
|
||||
<string name="a11y_back">返回</string>
|
||||
<string name="action_add">添加</string>
|
||||
<string name="action_next_step">下一步</string>
|
||||
<string name="title_loading">加载中...</string>
|
||||
<string name="text_error">错误</string>
|
||||
<string name="label_none">无</string>
|
||||
<string name="action_select_all">全选</string>
|
||||
<string name="action_deselect_all">取消全选</string>
|
||||
<string name="a11y_state_selected">已选中</string>
|
||||
<string name="a11y_state_not_selected">未选中</string>
|
||||
<string name="confirm_delete">确认删除</string>
|
||||
<string name="common_dialog_title_abandon_changes">放弃更改?</string>
|
||||
<string name="common_dialog_msg_unsaved_changes">当前内容已修改,退出将丢失未保存的数据。</string>
|
||||
<string name="common_action_exit_without_save">退出</string>
|
||||
<string name="common_action_continue_editing">继续编辑</string>
|
||||
<string name="action_reset">重置</string>
|
||||
<string name="floating_course_hint">已挂起,左右滑周点击空白处放下</string>
|
||||
|
||||
<!-- 主界面及今日课表 -->
|
||||
<string name="nav_today_schedule">今日课表</string>
|
||||
<string name="nav_course_schedule">课表</string>
|
||||
<string name="nav_settings">我的</string>
|
||||
<string name="title_today_schedule">今日课表</string>
|
||||
<string name="text_no_courses_today">今天没有课程</string>
|
||||
<string name="title_vacation_until_start">假期中(距离开学还有%1$s天)</string>
|
||||
<string name="title_semester_not_set">请设置开学日期</string>
|
||||
<string name="date_format_year_month_day">%1$s年%2$s月%3$s日</string>
|
||||
|
||||
<!-- 添加课程 -->
|
||||
<string name="toast_save_success">保存成功</string>
|
||||
<string name="toast_delete_success">删除成功</string>
|
||||
<string name="title_edit_course">编辑课程</string>
|
||||
<string name="title_add_course">添加课程</string>
|
||||
<string name="label_course_name">课程名称*</string>
|
||||
<string name="toast_name_empty">课程名称不能为空</string>
|
||||
<string name="label_teacher">教师</string>
|
||||
<string name="label_position">地点</string>
|
||||
<string name="label_day_of_week">星期</string>
|
||||
<string name="label_start_section">开始节次</string>
|
||||
<string name="label_end_section">结束节次</string>
|
||||
<string name="toast_time_invalid">开始节次不能大于结束节次</string>
|
||||
<string name="label_course_weeks">上课周次</string>
|
||||
<string name="action_single_week">单周</string>
|
||||
<string name="action_double_week">双周</string>
|
||||
<string name="snackbar_add_course_within_semester">请在教学周期间添加或调整课程</string>
|
||||
<string name="label_section_range_suffix">节</string>
|
||||
<string name="title_select_time">选择上课时间</string>
|
||||
<string name="text_weeks_selected">已选: %1$s</string>
|
||||
<string name="title_select_weeks">选择上课周次</string>
|
||||
<string name="title_select_color">选择课程颜色</string>
|
||||
<string name="label_custom_time">自定义时间</string>
|
||||
<string name="label_start_time">开始时间</string>
|
||||
<string name="label_end_time">结束时间</string>
|
||||
<string name="label_remark">备注</string>
|
||||
|
||||
<!-- 课程相关 -->
|
||||
<string name="course_position_prefix">地点: %1$s</string>
|
||||
<string name="course_teacher_prefix">老师: %1$s</string>
|
||||
<string name="title_select_week">选择周次</string>
|
||||
<string name="title_current_week">第 %1$s 周</string>
|
||||
<string name="title_vacation">假期中</string>
|
||||
<string name="status_semester_ended">学期已结束 %1$d 天</string>
|
||||
|
||||
<!-- 时间与星期格式 -->
|
||||
<string-array name="week_days_short_names">
|
||||
<item>一</item>
|
||||
<item>二</item>
|
||||
<item>三</item>
|
||||
<item>四</item>
|
||||
<item>五</item>
|
||||
<item>六</item>
|
||||
<item>日</item>
|
||||
</string-array>
|
||||
<string-array name="week_days_full_names">
|
||||
<item>周一</item>
|
||||
<item>周二</item>
|
||||
<item>周三</item>
|
||||
<item>周四</item>
|
||||
<item>周五</item>
|
||||
<item>周六</item>
|
||||
<item>周日</item>
|
||||
</string-array>
|
||||
<string name="format_week_display">%1$d周</string>
|
||||
|
||||
<!-- 通知与闹钟 -->
|
||||
<string name="notification_title_course_alert">上课提醒</string>
|
||||
<string name="item_auto_mode">上课自动模式</string>
|
||||
<string name="text_auto_mode_dependency">依赖于「课程提醒」的开启</string>
|
||||
<string name="toast_enable_reminder_first">请先开启「课程提醒」</string>
|
||||
<string name="alarm_option_none">不提醒</string>
|
||||
<string name="alarm_option_on_time">准时提醒</string>
|
||||
<string name="notification_live_status_preparing">准备上课</string>
|
||||
<string name="notification_unknown_course">未知课程</string>
|
||||
<string name="notification_unknown_position">地点未知</string>
|
||||
|
||||
<!-- 小组件相关 -->
|
||||
<string name="widget_name_tiny">超小课程2x1</string>
|
||||
<string name="widget_name_compact">紧凑课程2x2</string>
|
||||
<string name="widget_name_double_days">近日课程4x2</string>
|
||||
<string name="widget_name_list_vertical">垂直列表课表4xN</string>
|
||||
<string name="widget_tomorrow_course_preview">明日预告</string>
|
||||
<string name="widget_today_courses_finished">今日课程已结束</string>
|
||||
<string name="widget_vacation_expecting">期待新学期</string>
|
||||
<string name="widget_remaining_courses_format_today">今日还有 %1$d 节课</string>
|
||||
<string name="widget_remaining_courses_format_tomorrow">明天有 %1$d 节课</string>
|
||||
<string name="widget_title_today">今天</string>
|
||||
<string name="widget_title_tomorrow">明天</string>
|
||||
<string name="widget_course_remaining_count">剩余 %1$d 节</string>
|
||||
<string name="widget_course_total_count">共有 %1$d 节</string>
|
||||
|
||||
<!-- 通知设置 -->
|
||||
<string name="title_course_notification_settings">课程提醒设置</string>
|
||||
<string name="section_title_general">常规</string>
|
||||
<string name="section_title_advanced">高级</string>
|
||||
<string name="text_permission_importance_title">权限设置对于 Android 提醒非常重要</string>
|
||||
<string name="text_permission_importance_detail">为了确保提醒按时送达,你需要:\n1. 授予精确闹钟权限 (Android 12及以上)\n2. 开启应用的自启动权限\n3. 关闭应用的电池优化功能\n4. 授予勿扰模式权限(用于自动模式切换)\n\n请在下方的设置项中手动开启这些权限。</string>
|
||||
<string name="item_course_reminder">课程提醒</string>
|
||||
<string name="item_remind_time_before">提前提醒时间</string>
|
||||
<string name="remind_time_minutes_format">%1$s 分钟</string>
|
||||
<string name="item_exact_alarm_permission">精确闹钟权限</string>
|
||||
<string name="item_dnd_permission">勿扰模式权限</string>
|
||||
<string name="status_enabled">已开启</string>
|
||||
<string name="status_disabled">已关闭</string>
|
||||
<string name="status_authorized">已授权</string>
|
||||
<string name="status_unauthorized">未授权</string>
|
||||
<string name="item_background_and_autostart">后台运行和自启</string>
|
||||
<string name="item_ignore_battery_optimization">忽略电池优化</string>
|
||||
<string name="section_title_skip_dates">跳过日期功能</string>
|
||||
<string name="text_skip_dates_experimental">实验性的功能,不保证一定有用</string>
|
||||
<string name="item_update_holiday_info">更新节假日信息</string>
|
||||
<string name="update_holiday_info_hint">可能不稳定(一般情况下只有年末才公布下一年的节假日信息)</string>
|
||||
<string name="item_clear_skipped_dates">清空跳过日期</string>
|
||||
<string name="item_view_skipped_dates">查看跳过的日期</string>
|
||||
<string name="skipped_dates_count_format">%1$d 个日期</string>
|
||||
<string name="skipped_dates_none">无</string>
|
||||
<string name="toast_clear_success">已清空所有跳过日期!</string>
|
||||
<string name="toast_clear_failed">清空失败:%1$s</string>
|
||||
<string name="dialog_title_auto_mode_selection">上课自动模式选择</string>
|
||||
<string name="auto_mode_dnd_permission_warning">(缺少勿扰权限,启用勿扰/静音可能无效)</string>
|
||||
<string name="dialog_title_set_remind_time">设置提前提醒时间</string>
|
||||
<string name="label_minutes_input">分钟数</string>
|
||||
<string name="dialog_title_exact_alarm_permission">需要精确闹钟权限</string>
|
||||
<string name="dialog_text_exact_alarm_permission">为了确保提醒能在准确时间送达,请授予精确闹钟权限。</string>
|
||||
<string name="action_go_to_settings">去设置</string>
|
||||
<string name="dialog_title_clear_confirmation">确认清空</string>
|
||||
<string name="dialog_text_clear_confirmation">这会永久清除所有跳过的日期,无法恢复。确定要继续吗?</string>
|
||||
<string name="dialog_title_dnd_permission">需要勿扰模式权限</string>
|
||||
<string name="dialog_text_dnd_permission">为了启用上课自动模式,请授予应用访问勿扰模式设置的权限。</string>
|
||||
<string name="auto_mode_off">关闭</string>
|
||||
<string name="auto_mode_dnd">勿扰模式 (DND)</string>
|
||||
<string name="auto_mode_silent">静音模式 (SILENT)</string>
|
||||
<string name="dialog_title_view_skipped_dates">跳过的提醒日期</string>
|
||||
<string name="action_close">关闭</string>
|
||||
<string name="toast_notification_permission_denied">通知权限被拒绝,无法接收课程提醒。</string>
|
||||
<string name="item_compat_wearable_sync">兼容穿戴设备同步通知</string>
|
||||
<string name="desc_compat_wearable_sync">因 Android 16 实时通知属性与部分穿戴设备通知同步软件存在兼容性冲突,开启此项将优化同步兼容性,但会停用实时更新效果</string>
|
||||
|
||||
<!-- 设置选项 -->
|
||||
<string name="title_schedule_settings">课程表设置</string>
|
||||
<string name="section_title_general_settings">通用设置</string>
|
||||
<string name="item_show_non_current_week">显示非本周课程</string>
|
||||
<string name="desc_show_non_current_week">在课表中展示当前周次以外的课程</string>
|
||||
<string name="item_show_weekends">是否显示周末</string>
|
||||
<string name="desc_show_weekends">开启后,课程表中将显示周末的课程安排</string>
|
||||
<string name="item_set_start_date">设置开学日期</string>
|
||||
<string name="desc_set_start_date">选择学期第一周(教务系统参考的第一周)的周一</string>
|
||||
<string name="status_not_set">未设置</string>
|
||||
<string name="item_total_weeks">本学期总周数</string>
|
||||
<string name="desc_total_weeks">设置学期总共持续多少周</string>
|
||||
<string name="status_total_weeks_format">%1$d 周</string>
|
||||
<string name="item_current_week">当前周数</string>
|
||||
<string name="desc_current_week_manual">手动调整当前周数</string>
|
||||
<string name="status_set_start_date_first">请设置开始日期</string>
|
||||
<string name="status_current_week_format">第 %1$d 周</string>
|
||||
<string name="item_first_day_of_week">设置每周起始日</string>
|
||||
<string name="desc_first_day_of_week">设置一周从哪天开始计算和显示</string>
|
||||
<string name="day_of_week_monday">周一</string>
|
||||
<string name="day_of_week_sunday">周日</string>
|
||||
<string name="item_schedule_tweak">课程调动</string>
|
||||
<string name="desc_schedule_tweak">一键将指定日期的所有课程调整到新日期</string>
|
||||
<string name="section_title_advanced_features">高级功能</string>
|
||||
<string name="item_course_conversion">课表导入/导出</string>
|
||||
<string name="desc_course_conversion">支持文件导入导出与正方教务导入</string>
|
||||
<string name="desc_notification_settings">管理您的课程提醒通知</string>
|
||||
<string name="desc_manage_course_tables">管理多份课程表,可切换、删除</string>
|
||||
<string name="item_time_slot_customization">自定义时间段</string>
|
||||
<string name="desc_time_slot_customization">编辑您的课程时间段设置</string>
|
||||
<string name="item_more_options">更多</string>
|
||||
<string name="desc_more_options">提供我们的更多信息</string>
|
||||
<string name="a11y_more_options">更多选项</string>
|
||||
<string name="dialog_title_select_total_weeks">选择总周数</string>
|
||||
<string name="dialog_title_manual_set_week">手动设置当前周数</string>
|
||||
<string name="dialog_title_set_first_day_of_week">设置每周起始日</string>
|
||||
<string name="text_no_course_tables">暂无课表可选择</string>
|
||||
<string name="course_table_id_prefix">ID: %1$s</string>
|
||||
<string name="course_table_created_at_prefix">创建于: %1$s</string>
|
||||
<string name="label_current">当前</string>
|
||||
|
||||
<!-- 管理课表 -->
|
||||
<string name="title_manage_course_tables">管理课表</string>
|
||||
<string name="dialog_title_add_table">添加新课表</string>
|
||||
<string name="a11y_add_new_table">添加新课表</string>
|
||||
<string name="label_table_name">课表名称</string>
|
||||
<string name="text_no_tables_hint">暂无课表,点击右下角按钮添加。</string>
|
||||
<string name="toast_switch_table_success">已切换到课表: %1$s</string>
|
||||
<string name="toast_add_table_success">课表 \'%1$s\' 已添加</string>
|
||||
<string name="dialog_title_edit_table">编辑课表名称</string>
|
||||
<string name="toast_edit_table_success">课表名称已更新</string>
|
||||
<string name="dialog_text_confirm_delete">您确定要删除课表 \'%1$s\' 吗?此操作无法撤销。</string>
|
||||
<string name="toast_delete_table_success">%1$s 已删除</string>
|
||||
<string name="toast_delete_last_table_failed">不能删除最后一个课表</string>
|
||||
<string name="a11y_current_table">当前课表</string>
|
||||
<string name="item_course_management">课程管理</string>
|
||||
<string name="desc_course_management">按名称查看和编辑所有课程</string>
|
||||
|
||||
<!-- 管理课程 -->
|
||||
<string name="title_selected_items_count">已选择 %1$d 项</string>
|
||||
<string name="text_no_unique_courses_hint">当前课表暂无课程数据</string>
|
||||
<string name="a11y_cancel_selection">取消多选</string>
|
||||
<string name="a11y_exit_selection_mode">退出选择模式</string>
|
||||
<string name="a11y_enter_selection_mode">进入选择模式</string>
|
||||
<string name="label_weeks_format">周次: %1$s</string>
|
||||
|
||||
<!-- 时间段管理 -->
|
||||
<string name="title_time_slot_management">时间段管理</string>
|
||||
<string name="a11y_add_time_slot">添加时间段</string>
|
||||
<string name="a11y_save_all_settings">保存所有设置</string>
|
||||
<string name="toast_settings_saved">所有设置已保存到数据库</string>
|
||||
<string name="title_default_duration_settings">默认时长设置</string>
|
||||
<string name="label_class_duration_minutes">一节课时长 (分钟)</string>
|
||||
<string name="toast_class_duration_positive">课程时长必须大于0分钟</string>
|
||||
<string name="label_break_duration_minutes">课间休息 (分钟)</string>
|
||||
<string name="toast_break_duration_non_negative">休息时长不能为负</string>
|
||||
<string name="text_no_time_slots_hint">当前没有时间段。点击右上角 \'+\' 添加。</string>
|
||||
<string name="toast_slot_removed_unsaved">时间段已从列表移除,请点击保存以更新数据库</string>
|
||||
<string name="time_slot_section_number">第 %1$s 节</string>
|
||||
<string name="a11y_delete_time_slot">删除时间段</string>
|
||||
<string name="dialog_title_edit_time_slot">编辑时间段</string>
|
||||
<string name="dialog_title_add_time_slot">添加新时间段</string>
|
||||
<string name="label_time_picker_start">开始</string>
|
||||
<string name="label_time_picker_end">结束</string>
|
||||
<string name="label_time_picker_hour">小时</string>
|
||||
<string name="label_time_picker_minute">分钟</string>
|
||||
<string name="action_save_changes">保存更改</string>
|
||||
<string name="toast_end_time_must_be_later">结束时间必须晚于开始时间</string>
|
||||
<string name="toast_slot_modified_unsaved">时间段已修改,请点击保存以更新数据库</string>
|
||||
<string name="toast_slot_added_unsaved">时间段已添加至列表,请点击保存以更新数据库</string>
|
||||
<string name="label_time_slot_alias">别名(可选)</string>
|
||||
<string name="toast_time_conflict">选择的时间超出了前后课时限制范围</string>
|
||||
|
||||
<!-- 课表导入/导出 -->
|
||||
<string name="title_conversion">课表导入/导出</string>
|
||||
<string name="section_file_conversion">文件导入/导出</string>
|
||||
<string name="item_import_course_file">课程文件导入</string>
|
||||
<string name="desc_import_json">导入json文件</string>
|
||||
<string name="item_export_course_file">课程文件导出</string>
|
||||
<string name="desc_export_json_with_config">导出携带时间段配置的json课程文件</string>
|
||||
<string name="item_export_ics_file">日历文件导出</string>
|
||||
<string name="desc_export_ics_with_alarm">导出ics文件,点击生成指定提醒时间参数的文件</string>
|
||||
<string name="section_school_import">教务导入</string>
|
||||
<string name="item_school_system_import">正方教务导入</string>
|
||||
<string name="desc_school_import_quick">登录正方教务系统,进入课表查询页面后导入课程</string>
|
||||
<string name="dialog_title_select_import_table">选择要导入的目标课表</string>
|
||||
<string name="dialog_title_select_export_table">选择要导出的课表</string>
|
||||
<string name="dialog_title_ics_export_settings">日历导出设置</string>
|
||||
<string name="label_select_alarm_time">选择提醒时间:</string>
|
||||
<string name="a11y_details">详情</string>
|
||||
<string name="snackbar_file_selection_canceled">文件选择已取消。</string>
|
||||
<string name="snackbar_file_save_canceled">文件保存已取消。</string>
|
||||
<string name="dialog_title_file_saved">文件已保存</string>
|
||||
<string name="dialog_text_file_saved_share_prompt">文件已成功导出到您的下载目录,您想分享它吗?</string>
|
||||
<string name="action_share">分享</string>
|
||||
<string name="toast_import_success">课表导入成功!</string>
|
||||
<string name="error_export_table_not_found">导出失败:找不到课表</string>
|
||||
<string name="error_export_failed">导出失败:%1$s</string>
|
||||
<string name="error_import_failed">导入失败:%1$s</string>
|
||||
<string name="error_ics_export_data_failed">日历文件导出失败:获取数据失败</string>
|
||||
<string name="section_sync">同步</string>
|
||||
|
||||
<!-- 更多设置 -->
|
||||
<string name="title_more_options">更多</string>
|
||||
<string name="a11y_app_icon">应用图标</string>
|
||||
<string name="label_version_prefix">版本: %1$s</string>
|
||||
<string name="item_start_screen_settings">启动页面设置</string>
|
||||
<string name="dialog_select_start_screen">选择启动时显示的页面</string>
|
||||
|
||||
<!-- 课程调动 -->
|
||||
<string name="title_tweak_schedule">调课</string>
|
||||
<string name="a11y_save_tweak">保存调课更改</string>
|
||||
<string name="label_select_tweak_table">选择要调整的课表</string>
|
||||
<string name="action_select_table">选择课表</string>
|
||||
<string name="label_tweak_from_date">被调整日期</string>
|
||||
<string name="label_tweak_to_date">调整到日期</string>
|
||||
<string name="text_tweak_hint">请确认以下两个日期的课程信息,点击右上角保存即可完成调课。</string>
|
||||
<string name="title_tweak_from_course">被调整的课程</string>
|
||||
<string name="a11y_arrow">箭头</string>
|
||||
<string name="title_tweak_to_course">调整到日期的课程</string>
|
||||
<string name="text_no_course">无课程</string>
|
||||
<string name="error_tweak_no_table_or_semester">请先选择课表并设置学期开始日期</string>
|
||||
<string name="error_tweak_same_day">被调整日期和调整到日期不能是同一天</string>
|
||||
<string name="toast_tweak_success">调课成功!</string>
|
||||
<string name="error_tweak_failed">调课失败:%1$s</string>
|
||||
<string name="course_time_day_section_details_tweak">%1$s | 节次 %2$s-%3$s</string>
|
||||
<string name="course_time_day_time_details_tweak">%1$s | 时间 %2$s-%3$s</string>
|
||||
<string name="tweak_mode_merge">合并 (A + B)</string>
|
||||
<string name="tweak_mode_overwrite">覆盖 (A → B)</string>
|
||||
<string name="tweak_mode_exchange">交换 (A ↔ B)</string>
|
||||
<string name="date_format_month_day">%1$d月%2$d日</string>
|
||||
|
||||
<!-- 教务导入 -->
|
||||
<string name="title_enter_url">输入网址</string>
|
||||
<string name="a11y_cancel_editing">取消编辑</string>
|
||||
<string name="placeholder_enter_url_full">输入网址 (https://...)</string>
|
||||
<string name="a11y_load">加载</string>
|
||||
<string name="a11y_enter_url">输入网址</string>
|
||||
<string name="action_refresh">刷新</string>
|
||||
<string name="a11y_refresh">刷新</string>
|
||||
<string name="action_switch_to_phone_mode">切换到手机模式</string>
|
||||
<string name="action_switch_to_desktop_mode">切换到电脑模式</string>
|
||||
<string name="toast_switched_to_desktop">已切换到电脑模式</string>
|
||||
<string name="toast_switched_to_phone">已切换到手机模式</string>
|
||||
<string name="text_import_guide">请登录教务系统后切换到有课表显示的页面再点击导入课程,点击右上角的更多查看其他选项</string>
|
||||
<string name="action_execute_import">执行导入</string>
|
||||
<string name="dialog_title_select_table_for_import">选择一个课表以导入课程</string>
|
||||
<string name="toast_executing_import_script">正在执行导入脚本...</string>
|
||||
<string name="toast_load_import_script_failed">加载导入脚本失败: %1$s</string>
|
||||
|
||||
<!-- 色彩编辑器 -->
|
||||
<string name="color_picker_title_edit">颜色调节</string>
|
||||
<string name="color_picker_title_precise">精准数值</string>
|
||||
<string name="color_picker_mode_visual">滑块模式</string>
|
||||
<string name="color_picker_mode_input">数字模式</string>
|
||||
<string name="color_picker_label_hue">色相</string>
|
||||
<string name="color_picker_label_saturation">饱和度</string>
|
||||
<string name="color_picker_label_value">亮度</string>
|
||||
<string name="color_picker_label_alpha">透明度</string>
|
||||
<string name="a11y_switch_color_mode">切换输入方式</string>
|
||||
|
||||
<!-- 个性化配置 -->
|
||||
<string name="item_personalization">个性化配置</string>
|
||||
<string name="desc_personalization">调整课表格子高度、圆角、间距及透明度</string>
|
||||
<string name="style_category_interface">界面显示</string>
|
||||
<string name="style_category_grid_size">网格尺寸</string>
|
||||
<string name="style_category_course_block">课程块配置</string>
|
||||
<string name="style_category_color_scheme">颜色方案 (点击圆形编辑)</string>
|
||||
<string name="label_wallpaper">课表背景壁纸</string>
|
||||
<string name="desc_wallpaper_set">已设置 (长按可清除)</string>
|
||||
<string name="desc_wallpaper_unset">未设置 (点击选择图片)</string>
|
||||
<string name="label_hide_section_time">隐藏节次具体时间</string>
|
||||
<string name="label_hide_date_under_day">隐藏日期 (周几下方)</string>
|
||||
<string name="label_hide_grid_lines">隐藏网格线</string>
|
||||
<string name="label_show_start_time">显示课程格开始时间</string>
|
||||
<string name="label_section_height">格子高度</string>
|
||||
<string name="label_time_column_width">侧边栏宽度</string>
|
||||
<string name="label_day_header_height">顶部表头高度</string>
|
||||
<string name="label_hide_location">隐藏上课地点</string>
|
||||
<string name="label_hide_teacher">隐藏授课老师</string>
|
||||
<string name="label_remove_location_at">移除地点前的 @ 符号</string>
|
||||
<string name="label_font_scale">文字缩放比例</string>
|
||||
<string name="label_corner_radius">圆角半径</string>
|
||||
<string name="label_inner_padding">内部填充</string>
|
||||
<string name="label_outer_padding">外部间距</string>
|
||||
<string name="label_opacity">不透明度</string>
|
||||
<string name="title_light_color_pool">浅色模式颜色池</string>
|
||||
<string name="title_dark_color_pool">深色模式颜色池</string>
|
||||
<string name="preview_light_mode">浅色模式预览\n固定深色文字</string>
|
||||
<string name="preview_dark_mode">深色模式预览\n固定浅色文字</string>
|
||||
<string name="action_reset_style">恢复默认样式设置</string>
|
||||
<string name="dialog_reset_title">重置样式</string>
|
||||
<string name="dialog_reset_message">确定要将所有样式设置恢复为默认值吗?此操作不可撤销。</string>
|
||||
<string name="action_confirm_crop">确定裁剪</string>
|
||||
<string name="label_text_align_center_h">文字水平居中</string>
|
||||
<string name="label_text_align_center_v">文字垂直居中</string>
|
||||
<string name="label_border_type">边框样式</string>
|
||||
<string name="border_type_solid">实线</string>
|
||||
<string name="border_type_dashed">虚线</string>
|
||||
<string name="label_range">范围</string>
|
||||
<string name="placeholder_input_value">请输入数值</string>
|
||||
<string name="label_page_text_color">课表页面文字颜色</string>
|
||||
<string name="label_course_text_color">课程块文字颜色</string>
|
||||
<string name="label_schedule_mode_24h">24小时时间轴模式</string>
|
||||
|
||||
<!-- 快捷操作 -->
|
||||
<string name="item_quick_actions">快捷操作</string>
|
||||
<string name="desc_quick_actions">包含调课、课程临时变动等功能</string>
|
||||
<string name="label_quick_action_category_schedule">课表调整</string>
|
||||
<string name="item_quick_delete">快速删除课程</string>
|
||||
<string name="quick_delete_subtitle">按周次、星期或特定日期批量清理课表</string>
|
||||
|
||||
<!-- 快速删除课程 -->
|
||||
<string name="label_dimension_weeks_days">维度一:按周次和星期</string>
|
||||
<string name="label_dimension_dates">维度二:按特定日期</string>
|
||||
<string name="hint_no_selection">请选择周次、星期或日期</string>
|
||||
<string name="hint_affected_count">预计从课表中移除 %1$d 节课程记录</string>
|
||||
<string name="dialog_delete_confirm_msg">此操作不可撤销。受影响的课程记录将从选定的时间点中抹除,但课程的基础信息仍会保留。</string>
|
||||
<string name="quick_delete_filter_weeks_days_hint">设置重复周次与星期 (可选)</string>
|
||||
<string name="quick_delete_filter_date_range_hint">设置特定日期范围 (可选)</string>
|
||||
<string name="quick_delete_label_days_prefix">星期: %1$s</string>
|
||||
<string name="quick_delete_dialog_select_date_title">选择日期范围</string>
|
||||
<string name="quick_delete_success">课表清理成功</string>
|
||||
<string name="error_load_failed">初始化失败,请重试</string>
|
||||
<string name="error_op_failed">操作失败: %1$s</string>
|
||||
|
||||
<!-- 主题设置 -->
|
||||
<string name="theme_follow_system">跟随系统</string>
|
||||
<string name="theme_light">浅色模式</string>
|
||||
<string name="theme_dark">深色模式</string>
|
||||
<string name="theme_settings_title">主题设置</string>
|
||||
<string name="theme_mode_label">主题模式切换</string>
|
||||
<string name="dynamic_color_title">动态取色 (Material You)</string>
|
||||
<string name="dynamic_color_desc">基于系统壁纸自动生成配色方案(仅支持 Android 12+)</string>
|
||||
<string name="custom_color_title">自定义主色调</string>
|
||||
<string name="light_primary_color">浅色模式主色</string>
|
||||
<string name="dark_primary_color">深色模式主色</string>
|
||||
<string name="theme_color_hint">说明:改变此颜色后,系统将作为种子色重新计算全应用配色方案。</string>
|
||||
|
||||
<!-- 备份和还原 -->
|
||||
<string name="backup_err_empty">备份文件为空,无法恢复</string>
|
||||
<string name="backup_err_corrupted">文件解析失败,数据可能已损坏</string>
|
||||
<string name="backup_err_version_too_new">该备份数据版本过新,请升级 App 后再试</string>
|
||||
<string name="item_backup_restore">备份与恢复</string>
|
||||
<string name="desc_backup_restore">支持云盘与本地文件多渠道备份,保障课表数据安全</string>
|
||||
<string name="section_data_maintenance">数据维护</string>
|
||||
<string name="item_backup_data">备份数据</string>
|
||||
<string name="desc_backup_data">将当前的课表及配置打包保存</string>
|
||||
<string name="item_restore_data">恢复数据</string>
|
||||
<string name="desc_restore_data">下载并覆盖本地课表配置数据</string>
|
||||
<string name="section_service_config">服务配置</string>
|
||||
<string name="item_webdav_config">WebDAV 参数配置</string>
|
||||
<string name="desc_webdav_unconfigured">未配置网盘连接</string>
|
||||
<string name="desc_webdav_connected">已连接: %1$s</string>
|
||||
<string name="dialog_title_backup_target">选择备份目标渠道</string>
|
||||
<string name="dialog_title_restore_source">选择恢复数据来源</string>
|
||||
<string name="dialog_title_config_webdav">配置 WebDAV</string>
|
||||
<string name="label_webdav_url">服务器地址 (URL)</string>
|
||||
<string name="label_webdav_account">账号</string>
|
||||
<string name="label_webdav_pwd_saved">密码已保存 (留空不修改)</string>
|
||||
<string name="label_webdav_pwd_empty">应用独立密码</string>
|
||||
<string name="label_webdav_path">云端备份位置</string>
|
||||
<string name="desc_webdav_path_hint">实际数据将隔离保存在该目录下的 /Backup 文件夹中</string>
|
||||
<string name="toast_operation_success">操作成功完成</string>
|
||||
<string name="toast_operation_failed">操作失败: %1$s</string>
|
||||
<string name="error_webdav_unconfigured">请先配置 WebDAV 服务</string>
|
||||
<string name="error_stream_open_failed">无法打开数据流</string>
|
||||
<string name="backup_err_connect_failed">连接失败,请检查配置或网络</string>
|
||||
<string name="backup_err_upload_failed">文件上传失败</string>
|
||||
<string name="backup_err_local_export_failed">本地导出失败</string>
|
||||
<string name="backup_err_restore_failed_prefix">还原失败: %1$s</string>
|
||||
<string name="backup_target_webdav">WebDAV 云同步</string>
|
||||
<string name="backup_target_local_zip">本地 ZIP 文件</string>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.xingheyuzhuan.shiguangschedule
|
||||
|
||||
import androidx.compose.animation.EnterTransition
|
||||
import androidx.compose.animation.ExitTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInHorizontally
|
||||
import androidx.compose.animation.slideOutHorizontally
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
|
||||
import androidx.navigation3.runtime.NavEntry
|
||||
import androidx.navigation3.runtime.get
|
||||
import androidx.navigation3.runtime.metadata
|
||||
import androidx.navigation3.runtime.rememberNavBackStack
|
||||
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
|
||||
import androidx.navigation3.ui.NavDisplay
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.StartScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.schedule.WeeklyScheduleScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.schoolselection.web.WebViewScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.SettingsScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.SettingsViewModel
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.additional.MoreOptionsScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.backup.BackupScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.conversion.CourseTableConversionScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.course.AddEditCourseScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.coursemanagement.CourseInstanceListScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.coursemanagement.CourseNameListScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.coursetables.ManageCourseTablesScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.notification.NotificationSettingsScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.quickactions.QuickActionsScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.quickactions.delete.QuickDeleteScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.quickactions.tweaks.TweakScheduleScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.style.StyleSettingsScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.themesettings.ThemeSettingsScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.settings.time.TimeSlotManagementScreen
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.theme.ShiguangScheduleTheme
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.today.TodayScheduleScreen
|
||||
import org.koin.compose.viewmodel.koinViewModel
|
||||
|
||||
@Composable
|
||||
fun App() {
|
||||
val viewModel: SettingsViewModel = koinViewModel()
|
||||
val state by viewModel.uiState.collectAsState()
|
||||
|
||||
if (state.isReady) {
|
||||
ShiguangScheduleTheme(settings = state.appSettings) {
|
||||
val startDest = remember(state.appSettings.startScreen) {
|
||||
when (state.appSettings.startScreen) {
|
||||
StartScreen.COURSE_SCHEDULE -> Destination.CourseSchedule
|
||||
StartScreen.TODAY_SCHEDULE -> Destination.TodaySchedule
|
||||
}
|
||||
}
|
||||
AppNavigation(startDestination = startDest)
|
||||
}
|
||||
} else {
|
||||
Surface(modifier = Modifier.fillMaxSize()) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AppNavigation(startDestination: Destination) {
|
||||
val backStack = rememberNavBackStack(
|
||||
configuration = navSavedStateConfig,
|
||||
startDestination
|
||||
)
|
||||
|
||||
val onNavigate: (Destination) -> Unit = remember(backStack) {
|
||||
{ dest ->
|
||||
if (dest.isMainScreen) {
|
||||
if (backStack.lastOrNull() != dest) {
|
||||
backStack.clear()
|
||||
backStack.add(dest)
|
||||
}
|
||||
} else {
|
||||
if (backStack.lastOrNull() != dest) {
|
||||
backStack.add(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onBack: () -> Unit = remember(backStack) {
|
||||
{
|
||||
if (backStack.size > 1) {
|
||||
backStack.removeAt(backStack.lastIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val animSpec = tween<IntOffset>(300)
|
||||
|
||||
NavDisplay(
|
||||
backStack = backStack,
|
||||
onBack = onBack,
|
||||
transitionSpec = {
|
||||
val fromMain = initialState.metadata[ShiguangNavMetadata.IsMainScreenKey] ?: false
|
||||
val toMain = targetState.metadata[ShiguangNavMetadata.IsMainScreenKey] ?: false
|
||||
|
||||
if (fromMain && toMain) {
|
||||
EnterTransition.None togetherWith ExitTransition.None
|
||||
} else {
|
||||
slideInHorizontally(initialOffsetX = { it }, animationSpec = animSpec) togetherWith
|
||||
slideOutHorizontally(targetOffsetX = { -it / 3 }, animationSpec = animSpec) + fadeOut()
|
||||
}
|
||||
},
|
||||
popTransitionSpec = {
|
||||
val fromMain = initialState.metadata[ShiguangNavMetadata.IsMainScreenKey] ?: false
|
||||
val toMain = targetState.metadata[ShiguangNavMetadata.IsMainScreenKey] ?: false
|
||||
|
||||
if (fromMain && toMain) {
|
||||
EnterTransition.None togetherWith ExitTransition.None
|
||||
} else {
|
||||
slideInHorizontally(initialOffsetX = { -it / 3 }, animationSpec = animSpec) + fadeIn() togetherWith
|
||||
slideOutHorizontally(targetOffsetX = { it }, animationSpec = animSpec)
|
||||
}
|
||||
},
|
||||
predictivePopTransitionSpec = {
|
||||
slideInHorizontally(initialOffsetX = { -it / 3 }, animationSpec = animSpec) + fadeIn() togetherWith
|
||||
slideOutHorizontally(targetOffsetX = { it }, animationSpec = animSpec)
|
||||
},
|
||||
entryDecorators = listOf(
|
||||
rememberSaveableStateHolderNavEntryDecorator(),
|
||||
rememberViewModelStoreNavEntryDecorator()
|
||||
)
|
||||
) { key ->
|
||||
val destination = key as Destination
|
||||
|
||||
NavEntry(
|
||||
key = key,
|
||||
metadata = metadata {
|
||||
put(ShiguangNavMetadata.IsMainScreenKey, destination.isMainScreen)
|
||||
}
|
||||
) {
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
ScreenContent(
|
||||
targetDest = destination,
|
||||
onNavigate = onNavigate,
|
||||
onBack = onBack
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ScreenContent(
|
||||
targetDest: Destination,
|
||||
onNavigate: (Destination) -> Unit,
|
||||
onBack: () -> Unit
|
||||
) {
|
||||
when (targetDest) {
|
||||
Destination.CourseSchedule -> WeeklyScheduleScreen(onNavigate, onBack)
|
||||
Destination.Settings -> SettingsScreen(onNavigate, onBack)
|
||||
Destination.TodaySchedule -> TodayScheduleScreen(onNavigate, onBack)
|
||||
Destination.TimeSlotSettings -> TimeSlotManagementScreen(onBack)
|
||||
Destination.ManageCourseTables -> ManageCourseTablesScreen(onBack)
|
||||
Destination.CourseTableConversion -> CourseTableConversionScreen(onNavigate, onBack)
|
||||
Destination.NotificationSettings -> NotificationSettingsScreen(onBack)
|
||||
Destination.MoreOptions -> MoreOptionsScreen(onNavigate, onBack)
|
||||
Destination.QuickActions -> QuickActionsScreen(onNavigate, onBack)
|
||||
Destination.TweakSchedule -> TweakScheduleScreen(onBack)
|
||||
Destination.CourseManagementList -> CourseNameListScreen(onNavigate, onBack)
|
||||
Destination.StyleSettings -> StyleSettingsScreen(onBack)
|
||||
Destination.QuickDelete -> QuickDeleteScreen(onBack)
|
||||
Destination.ThemeSettings -> ThemeSettingsScreen(onBack)
|
||||
Destination.BackupAndRestore -> BackupScreen(onBack)
|
||||
|
||||
is Destination.WebView -> WebViewScreen(
|
||||
onNavigate, onBack, targetDest.initialUrl
|
||||
)
|
||||
is Destination.AddEditCourse -> AddEditCourseScreen(
|
||||
onBack, targetDest.courseId
|
||||
)
|
||||
is Destination.CourseManagementDetail -> CourseInstanceListScreen(
|
||||
targetDest.courseName, onBack, onNavigate
|
||||
)
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.xingheyuzhuan.shiguangschedule
|
||||
|
||||
import androidx.navigation3.runtime.NavKey
|
||||
import androidx.navigation3.runtime.NavMetadataKey
|
||||
import androidx.savedstate.serialization.SavedStateConfiguration
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
import kotlinx.serialization.modules.polymorphic
|
||||
import kotlinx.serialization.modules.subclass
|
||||
|
||||
/**
|
||||
* 导航元数据 Key 定义
|
||||
*/
|
||||
object ShiguangNavMetadata {
|
||||
object IsMainScreenKey : NavMetadataKey<Boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用所有目的地(页面)的定义
|
||||
*/
|
||||
@Serializable
|
||||
sealed interface Destination : NavKey {
|
||||
|
||||
/** 标记一级主界面的子接口 */
|
||||
sealed interface MainDestination : Destination
|
||||
|
||||
@Serializable data object CourseSchedule : MainDestination
|
||||
@Serializable data object Settings : MainDestination
|
||||
@Serializable data object TodaySchedule : MainDestination
|
||||
|
||||
@Serializable data object TimeSlotSettings : Destination
|
||||
@Serializable data object ManageCourseTables : Destination
|
||||
@Serializable data object CourseTableConversion : Destination
|
||||
@Serializable data object NotificationSettings : Destination
|
||||
@Serializable data object MoreOptions : Destination
|
||||
@Serializable data object QuickActions : Destination
|
||||
@Serializable data object TweakSchedule : Destination
|
||||
@Serializable data object QuickDelete : Destination
|
||||
@Serializable data object CourseManagementList : Destination
|
||||
@Serializable data object StyleSettings : Destination
|
||||
@Serializable data object ThemeSettings : Destination
|
||||
@Serializable data object BackupAndRestore : Destination
|
||||
|
||||
@Serializable
|
||||
data class WebView(
|
||||
val initialUrl: String? = "about:blank"
|
||||
) : Destination
|
||||
|
||||
@Serializable
|
||||
data class AddEditCourse(
|
||||
val courseId: String? = null
|
||||
) : Destination
|
||||
|
||||
@Serializable
|
||||
data class CourseManagementDetail(
|
||||
val courseName: String
|
||||
) : Destination
|
||||
}
|
||||
|
||||
val Destination.isMainScreen: Boolean
|
||||
get() = this is Destination.MainDestination
|
||||
|
||||
val navSerializersModule = SerializersModule {
|
||||
polymorphic(NavKey::class) {
|
||||
subclass(Destination.CourseSchedule::class)
|
||||
subclass(Destination.Settings::class)
|
||||
subclass(Destination.TodaySchedule::class)
|
||||
subclass(Destination.TimeSlotSettings::class)
|
||||
subclass(Destination.ManageCourseTables::class)
|
||||
subclass(Destination.CourseTableConversion::class)
|
||||
subclass(Destination.NotificationSettings::class)
|
||||
subclass(Destination.MoreOptions::class)
|
||||
subclass(Destination.QuickActions::class)
|
||||
subclass(Destination.TweakSchedule::class)
|
||||
subclass(Destination.QuickDelete::class)
|
||||
subclass(Destination.CourseManagementList::class)
|
||||
subclass(Destination.StyleSettings::class)
|
||||
subclass(Destination.ThemeSettings::class)
|
||||
subclass(Destination.BackupAndRestore::class)
|
||||
subclass(Destination.WebView::class)
|
||||
subclass(Destination.AddEditCourse::class)
|
||||
subclass(Destination.CourseManagementDetail::class)
|
||||
}
|
||||
}
|
||||
|
||||
val navSavedStateConfig = SavedStateConfiguration {
|
||||
serializersModule = navSerializersModule
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.api.date
|
||||
|
||||
import com.xingheyuzhuan.shiguangschedule.data.repository.AppSettingsRepository
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.plugins.contentnegotiation.*
|
||||
import io.ktor.client.plugins.logging.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@Serializable
|
||||
data class ApiResponse(
|
||||
@SerialName("holiday")
|
||||
val holidays: Map<String, HolidayInfo>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class HolidayInfo(
|
||||
@SerialName("date")
|
||||
val date: String,
|
||||
@SerialName("holiday")
|
||||
val isHoliday: Boolean
|
||||
)
|
||||
|
||||
/**
|
||||
* API 导入对象,基于 Ktor 3.0 实现。
|
||||
*/
|
||||
object ApiDateImporter {
|
||||
private const val BASE_URL = "https://timor.tech/api/holiday/year"
|
||||
|
||||
private val client = HttpClient {
|
||||
install(Logging) {
|
||||
level = LogLevel.INFO
|
||||
logger = Logger.DEFAULT
|
||||
}
|
||||
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
ignoreUnknownKeys = true
|
||||
coerceInputValues = true
|
||||
})
|
||||
}
|
||||
|
||||
defaultRequest {
|
||||
url(BASE_URL)
|
||||
header("User-Agent", "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36")
|
||||
}
|
||||
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = 15000
|
||||
connectTimeoutMillis = 15000
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 API 获取跳过的日期(假期),并保存到 AppSettingsRepository 中。
|
||||
*/
|
||||
suspend fun importAndSaveSkippedDates(appSettingsRepository: AppSettingsRepository) {
|
||||
try {
|
||||
val response: ApiResponse = client.get("").body()
|
||||
|
||||
val skippedDates = response.holidays.values
|
||||
.filter { it.isHoliday }
|
||||
.map { it.date }
|
||||
.toSet()
|
||||
|
||||
val currentSettings = appSettingsRepository.getAppSettings().first()
|
||||
val updatedSettings = currentSettings.copy(skippedDates = skippedDates)
|
||||
appSettingsRepository.insertOrUpdateAppSettings(updatedSettings)
|
||||
|
||||
println("成功导入并保存了 ${skippedDates.size} 个跳过的日期。")
|
||||
} catch (e: Exception) {
|
||||
println("数据导入失败: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun close() = client.close()
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.api.webdav
|
||||
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.plugins.auth.Auth
|
||||
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
|
||||
import io.ktor.client.plugins.auth.providers.basic
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.utils.io.readAvailable
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import okio.SYSTEM
|
||||
|
||||
/**
|
||||
* WebDAV 协议通信客户端
|
||||
* 职责:处理物理文件与目录的传输,支持多级目录级联创建。
|
||||
*/
|
||||
class WebDavClient(
|
||||
private val config: WebDavConfig
|
||||
) {
|
||||
|
||||
private val client by lazy {
|
||||
HttpClient {
|
||||
install(Auth) {
|
||||
basic {
|
||||
credentials {
|
||||
BasicAuthCredentials(username = config.username, password = config.password)
|
||||
}
|
||||
sendWithoutRequest { true }
|
||||
}
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = 30000
|
||||
connectTimeoutMillis = 15000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val normalizedBaseUrl: String
|
||||
get() = if (config.baseUrl.endsWith("/")) config.baseUrl else "${config.baseUrl}/"
|
||||
|
||||
private fun buildFullUrl(relativePath: String): String {
|
||||
val root = config.getCleanRootPath()
|
||||
val relative = relativePath.trim('/')
|
||||
return "$normalizedBaseUrl$root$relative"
|
||||
}
|
||||
|
||||
suspend fun ensureRootDirectoryExists(): Boolean {
|
||||
val rootDir = config.getCleanRootPath().trim('/')
|
||||
return ensureRemoteDirChainExists(rootDir)
|
||||
}
|
||||
|
||||
private suspend fun ensureRemoteDirChainExists(relativeDirChain: String): Boolean {
|
||||
if (relativeDirChain.isEmpty()) return true
|
||||
|
||||
val pathSegments = relativeDirChain.split('/').filter { it.isNotEmpty() }
|
||||
var currentPath = ""
|
||||
|
||||
try {
|
||||
for (segment in pathSegments) {
|
||||
currentPath = if (currentPath.isEmpty()) segment else "$currentPath/$segment"
|
||||
val fullUrl = "$normalizedBaseUrl$currentPath/"
|
||||
|
||||
val response = client.request(fullUrl) {
|
||||
method = HttpMethod("MKCOL")
|
||||
}
|
||||
|
||||
val isSuccess = response.status == HttpStatusCode.Created ||
|
||||
response.status == HttpStatusCode.MethodNotAllowed
|
||||
|
||||
if (!isSuccess) return false
|
||||
}
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传本地文件 (PUT)
|
||||
*/
|
||||
suspend fun uploadFile(localPath: Path, remoteFileName: String): Boolean {
|
||||
if (!FileSystem.SYSTEM.exists(localPath)) return false
|
||||
|
||||
val rootPrefix = config.getCleanRootPath()
|
||||
val fileRelativeDir = remoteFileName.substringBeforeLast('/', "")
|
||||
|
||||
val fullRelativeDirChain = if (fileRelativeDir.isEmpty()) {
|
||||
rootPrefix.trim('/')
|
||||
} else {
|
||||
"${rootPrefix.trim('/')}/${fileRelativeDir.trim('/')}"
|
||||
}
|
||||
|
||||
if (!ensureRemoteDirChainExists(fullRelativeDirChain)) return false
|
||||
|
||||
return try {
|
||||
val bytes = FileSystem.SYSTEM.read(localPath) { readByteArray() }
|
||||
val fullUrl = buildFullUrl(remoteFileName)
|
||||
val response = client.put(fullUrl) {
|
||||
setBody(bytes)
|
||||
}
|
||||
response.status.isSuccess()
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载远端文件 (GET)
|
||||
*/
|
||||
suspend fun downloadFile(remoteFileName: String, targetLocalPath: Path): Boolean {
|
||||
return try {
|
||||
val fullUrl = buildFullUrl(remoteFileName)
|
||||
val response = client.get(fullUrl)
|
||||
|
||||
if (response.status.isSuccess()) {
|
||||
val byteChannel = response.bodyAsChannel()
|
||||
val buffer = ByteArray(8192)
|
||||
FileSystem.SYSTEM.write(targetLocalPath) {
|
||||
while (!byteChannel.isClosedForRead) {
|
||||
val read = byteChannel.readAvailable(buffer)
|
||||
if (read <= 0) break
|
||||
write(buffer, 0, read)
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun close() = client.close()
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.api.webdav
|
||||
|
||||
/**
|
||||
* WebDAV 基础认证及路径配置
|
||||
* @param baseUrl 服务器基准地址
|
||||
* @param username 账号
|
||||
* @param password 应用独立密码
|
||||
* @param rootPath 备份的根路径设置
|
||||
*/
|
||||
data class WebDavConfig(
|
||||
val baseUrl: String,
|
||||
val username: String,
|
||||
val password: SenderPassword,
|
||||
val rootPath: String = "ShiguangSchedule"
|
||||
) {
|
||||
/**
|
||||
* 自动化处理根路径的斜杠,确保返回的形式
|
||||
* 避免业务层拼接时出现 "//" 或漏掉 "/" 导致 URL 解析失败
|
||||
*/
|
||||
fun getCleanRootPath(): String {
|
||||
val trimmed = rootPath.trim().trim('/')
|
||||
return if (trimmed.isEmpty()) "" else "$trimmed/"
|
||||
}
|
||||
}
|
||||
|
||||
typealias SenderPassword = String
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.ForeignKey
|
||||
import androidx.room3.Index
|
||||
import androidx.room3.PrimaryKey
|
||||
|
||||
/**
|
||||
* Room 实体类,代表“课程”数据表。
|
||||
* 它存储每门课程的详细信息,并与 `CourseTable` 关联。
|
||||
* 支持标准节次时间和自定义周重复时间两种模式。
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "courses",
|
||||
foreignKeys = [ForeignKey(
|
||||
entity = CourseTable::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["courseTableId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)],
|
||||
indices = [Index(value = ["courseTableId"])]
|
||||
)
|
||||
data class Course(
|
||||
@PrimaryKey
|
||||
val id: String, // 课程的唯一标识符 UUID
|
||||
val courseTableId: String, // 课程所属的课表 ID
|
||||
val name: String, // 课程名称,例如 "大学物理"
|
||||
val teacher: String, // 授课老师姓名
|
||||
val position: String, // 上课地点,例如 "主楼A101"
|
||||
val day: Int, // 上课的星期几,例如 1=周一, 7=周日
|
||||
|
||||
// 设为可空:当使用自定义时间时,这些字段将被忽略
|
||||
val startSection: Int?, // 课程开始的节次
|
||||
val endSection: Int?, // 课程结束的节次
|
||||
val isCustomTime: Boolean = false, // 是否使用自定义时间 (true: 使用 HH:MM 字符串)
|
||||
val customStartTime: String?, // 自定义起始时间,格式为 "HH:MM"
|
||||
val customEndTime: String?, // 自定义结束时间,格式为 "HH:MM"
|
||||
val colorInt: Int, // 课程卡片的颜色索引
|
||||
val remark: String? = null, // 课程备注信息,限 300 字以内
|
||||
)
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Delete
|
||||
import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy
|
||||
import androidx.room3.Query
|
||||
import androidx.room3.RoomWarnings
|
||||
import androidx.room3.Transaction
|
||||
import androidx.room3.Update
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Room 数据访问对象 (DAO),用于操作课程 (Course) 数据表。
|
||||
* 已更新以支持标准节次和自定义时间字段的混合排序,并增加了精准更新支持。
|
||||
*/
|
||||
@Dao
|
||||
interface CourseDao {
|
||||
/**
|
||||
* 获取指定课表ID的所有课程。
|
||||
* 排序逻辑已调整,支持按节次和自定义时间字符串混合排序。
|
||||
*/
|
||||
@Query(
|
||||
"""
|
||||
SELECT * FROM courses
|
||||
WHERE courseTableId = :courseTableId
|
||||
ORDER BY
|
||||
day ASC,
|
||||
-- 如果是标准课,按 startSection 排序;否则给定一个大值 99
|
||||
CASE WHEN isCustomTime = 0 THEN startSection ELSE 99 END ASC,
|
||||
-- 如果是自定义课,按 customStartTime 字符串排序;否则给定一个大值 '99:99'
|
||||
CASE WHEN isCustomTime = 1 THEN customStartTime ELSE '99:99' END ASC
|
||||
"""
|
||||
)
|
||||
fun getCoursesByTableId(courseTableId: String): Flow<List<Course>>
|
||||
|
||||
/**
|
||||
* 获取指定课表ID的所有课程,并包含其对应的周数。
|
||||
* 排序逻辑与上面保持一致,确保关联查询结果的顺序正确字段。
|
||||
*/
|
||||
@Transaction
|
||||
@Query(
|
||||
"""
|
||||
SELECT * FROM courses
|
||||
WHERE courseTableId = :courseTableId
|
||||
ORDER BY
|
||||
day ASC,
|
||||
CASE WHEN isCustomTime = 0 THEN startSection ELSE 99 END ASC,
|
||||
CASE WHEN isCustomTime = 1 THEN customStartTime ELSE '99:99' END ASC
|
||||
"""
|
||||
)
|
||||
@Suppress(RoomWarnings.QUERY_MISMATCH)
|
||||
fun getCoursesWithWeeksByTableId(courseTableId: String): Flow<List<CourseWithWeeks>>
|
||||
|
||||
/**
|
||||
* 检查指定 ID 的课程是否存在。
|
||||
* 用于 Repository 判断是执行插入(Insert)还是精准更新(Update)。
|
||||
*/
|
||||
@Query("SELECT EXISTS(SELECT 1 FROM courses WHERE id = :courseId)")
|
||||
suspend fun exists(courseId: String): Boolean
|
||||
|
||||
/**
|
||||
* 更新现有的课程信息。
|
||||
* 相比 REPLACE,使用 @Update 仅修改字段而不删除行,因此不会触发级联删除。
|
||||
* 适用于调课、修改颜色或名称等不希望触动其他周次数据的场景。
|
||||
*/
|
||||
@Update
|
||||
suspend fun update(course: Course)
|
||||
|
||||
/**
|
||||
* 插入一个或多个课程。
|
||||
* 策略调整为 ABORT,配合 Repository 的 exists 检查使用。
|
||||
* 确保只有在新课程时才执行插入,避免意外覆盖导致的级联数据丢失。
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.ABORT)
|
||||
suspend fun insertAll(courses: List<Course>)
|
||||
|
||||
/**
|
||||
* 删除一个或多个课程。
|
||||
*/
|
||||
@Delete
|
||||
suspend fun delete(course: Course)
|
||||
|
||||
/**
|
||||
* 根据课程ID删除单个课程。
|
||||
*/
|
||||
@Query("DELETE FROM courses WHERE id = :courseId")
|
||||
suspend fun deleteById(courseId: String)
|
||||
|
||||
/**
|
||||
* 批量删除指定的课程ID列表。
|
||||
* 依赖 ForeignKey.CASCADE,此操作会同时删除关联的 course_weeks 记录。
|
||||
*/
|
||||
@Query("DELETE FROM courses WHERE id IN (:courseIds)")
|
||||
suspend fun deleteCoursesByIds(courseIds: List<String>)
|
||||
|
||||
/**
|
||||
* 删除指定课表ID下的所有课程。
|
||||
* 这是支持覆盖导入功能的关键方法。
|
||||
*/
|
||||
@Query("DELETE FROM courses WHERE courseTableId = :courseTableId")
|
||||
suspend fun deleteCoursesByTableId(courseTableId: String)
|
||||
|
||||
/**
|
||||
* 获取指定课表ID下,在特定星期和周次的所有课程及其周数。
|
||||
* 排序逻辑已调整,以正确处理同一天内的自定义时间日程。
|
||||
*
|
||||
* @param courseTableId 课表ID。
|
||||
* @param day 星期几。
|
||||
* @param weekNumber 周次。
|
||||
*/
|
||||
@Transaction
|
||||
@Query(
|
||||
"""
|
||||
SELECT * FROM courses AS c
|
||||
INNER JOIN course_weeks AS cw ON c.id = cw.courseId
|
||||
WHERE c.courseTableId = :courseTableId
|
||||
AND c.day = :day
|
||||
AND cw.weekNumber = :weekNumber
|
||||
ORDER BY
|
||||
CASE WHEN c.isCustomTime = 0 THEN c.startSection ELSE 99 END ASC,
|
||||
CASE WHEN c.isCustomTime = 1 THEN c.customStartTime ELSE '99:99' END ASC
|
||||
"""
|
||||
)
|
||||
@Suppress(RoomWarnings.QUERY_MISMATCH)
|
||||
fun getCoursesWithWeeksByDayAndWeek(
|
||||
courseTableId: String,
|
||||
day: Int,
|
||||
weekNumber: Int
|
||||
): Flow<List<CourseWithWeeks>>
|
||||
|
||||
/**
|
||||
* 专门用于根据课程 ID 更新 colorInt 字段。
|
||||
* 用于将旧的 ARGB 值迁移到新的索引值。
|
||||
*/
|
||||
@Query("UPDATE courses SET colorInt = :newColorInt WHERE id = :courseId")
|
||||
suspend fun updateCourseColorById(courseId: String, newColorInt: Int)
|
||||
|
||||
/**
|
||||
* 批量删除指定课表下、指定名称的所有课程记录。
|
||||
* 启用级联删除后,此操作会自动删除关联的 course_weeks 记录。
|
||||
*/
|
||||
@Query("DELETE FROM courses WHERE courseTableId = :tableId AND name IN (:courseNames)")
|
||||
suspend fun deleteCoursesByNames(tableId: String, courseNames: List<String>)
|
||||
|
||||
/**
|
||||
* 获取指定课表在特定周次下的所有课程及其周数(整周数据)。
|
||||
* 用于主课表 Pager 页面的一次性数据加载。
|
||||
*
|
||||
* @param courseTableId 课表ID
|
||||
* @param weekNumber 目标周次
|
||||
*/
|
||||
@Transaction
|
||||
@Query(
|
||||
"""
|
||||
SELECT DISTINCT c.* FROM courses AS c
|
||||
INNER JOIN course_weeks AS cw ON c.id = cw.courseId
|
||||
WHERE c.courseTableId = :courseTableId
|
||||
AND cw.weekNumber = :weekNumber
|
||||
ORDER BY
|
||||
c.day ASC,
|
||||
CASE WHEN c.isCustomTime = 0 THEN c.startSection ELSE 99 END ASC,
|
||||
CASE WHEN c.isCustomTime = 1 THEN c.customStartTime ELSE '99:99' END ASC
|
||||
"""
|
||||
)
|
||||
@Suppress(RoomWarnings.QUERY_MISMATCH)
|
||||
fun getCoursesWithWeeksByTableAndWeek(
|
||||
courseTableId: String,
|
||||
weekNumber: Int
|
||||
): Flow<List<CourseWithWeeks>>
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.PrimaryKey
|
||||
|
||||
/**
|
||||
* Room 实体类,代表“课表元数据”数据表。
|
||||
* 存储每个课表的唯一信息,例如名称和 ID。
|
||||
*/
|
||||
@Entity(tableName = "course_tables")
|
||||
data class CourseTable(
|
||||
@PrimaryKey
|
||||
val id: String, // 使用 String 作为主键,与现有逻辑兼容
|
||||
val name: String, // 课表名称
|
||||
val createdAt: Long // 创建时间戳,有助于排序
|
||||
)
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.ForeignKey
|
||||
import androidx.room3.Index
|
||||
import androidx.room3.PrimaryKey
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
import kotlinx.datetime.isoDayNumber
|
||||
|
||||
/**
|
||||
* Room 实体类,代表“课表配置”数据表。
|
||||
* 与 CourseTable 形成一对一关系,存储课表专属的设置。
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "course_table_config",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = CourseTable::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["courseTableId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
],
|
||||
indices = [
|
||||
Index(value = ["courseTableId"], unique = true)
|
||||
]
|
||||
)
|
||||
data class CourseTableConfig(
|
||||
@PrimaryKey
|
||||
val courseTableId: String, // 【主键/外键】关联的课表 ID,确保一个课表只有一条配置记录
|
||||
|
||||
val showWeekends: Boolean = false, // 是否在课表视图中显示周末(周六、周日)
|
||||
val semesterStartDate: String? = null, // 学期开始日期(格式为 "yyyy-MM-dd"),用于计算当前周数
|
||||
val semesterTotalWeeks: Int = 20, // 本学期的总周数,用于定义学期范围
|
||||
|
||||
val defaultClassDuration: Int = 45, // 创建该课表内时间段时,默认的上课时长,单位:分钟
|
||||
val defaultBreakDuration: Int = 10, // 创建该课表内时间段时,默认的下课休息时长,单位:分钟
|
||||
|
||||
val firstDayOfWeek: Int = DayOfWeek.MONDAY.isoDayNumber // 该课表计算周数时,一周的起始日(1=周一,7=周日)
|
||||
)
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy
|
||||
import androidx.room3.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface CourseTableConfigDao {
|
||||
|
||||
/**
|
||||
* 插入或更新课表配置。
|
||||
* 当配置已存在时,进行替换(更新)。
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertOrUpdate(config: CourseTableConfig)
|
||||
|
||||
/**
|
||||
* 根据课表ID获取配置,以 Flow 形式返回,用于监听变化。
|
||||
*/
|
||||
@Query("SELECT * FROM course_table_config WHERE courseTableId = :courseTableId")
|
||||
fun getConfigById(courseTableId: String): Flow<CourseTableConfig?>
|
||||
|
||||
/**
|
||||
* 一次性获取配置,用于计算或不需要监听的场景。
|
||||
*/
|
||||
@Query("SELECT * FROM course_table_config WHERE courseTableId = :courseTableId LIMIT 1")
|
||||
suspend fun getConfigOnce(courseTableId: String): CourseTableConfig?
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy
|
||||
import androidx.room3.Query
|
||||
import androidx.room3.Update
|
||||
import androidx.room3.Delete
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Room 数据访问对象 (DAO),用于操作课表 (CourseTable) 数据表。
|
||||
*/
|
||||
@Dao
|
||||
interface CourseTableDao {
|
||||
/**
|
||||
* 获取所有课表,并按创建时间倒序排列。
|
||||
*/
|
||||
@Query("SELECT * FROM course_tables ORDER BY createdAt DESC")
|
||||
fun getAllCourseTables(): Flow<List<CourseTable>>
|
||||
|
||||
/**
|
||||
* 根据 ID 获取单个课表。
|
||||
*/
|
||||
@Query("SELECT * FROM course_tables WHERE id = :tableId LIMIT 1")
|
||||
suspend fun getCourseTableById(tableId: String): CourseTable?
|
||||
|
||||
/**
|
||||
* 插入一个新的课表。如果发生主键冲突,则替换旧数据。
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insert(courseTable: CourseTable)
|
||||
|
||||
/**
|
||||
* 更新一个现有课表。
|
||||
*/
|
||||
@Update
|
||||
suspend fun update(courseTable: CourseTable)
|
||||
|
||||
/**
|
||||
* 删除一个或多个课表。
|
||||
* 由于外键设置为 `onDelete = ForeignKey.CASCADE`,
|
||||
* 删除课表时,其下的所有课程也会被自动删除。
|
||||
*/
|
||||
@Delete
|
||||
suspend fun delete(courseTable: CourseTable)
|
||||
|
||||
/**
|
||||
* 根据课表ID删除单个课表。
|
||||
*/
|
||||
@Query("DELETE FROM course_tables WHERE id = :tableId")
|
||||
suspend fun deleteById(tableId: String)
|
||||
|
||||
|
||||
/**
|
||||
* 获取最早创建的一张课表。
|
||||
* 用于在 DataStore 迁移或初始化时,确定默认显示的课表 ID。
|
||||
*/
|
||||
@Query("SELECT * FROM course_tables ORDER BY createdAt ASC LIMIT 1")
|
||||
suspend fun getFirstTableOnce(): CourseTable?
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.ForeignKey
|
||||
import androidx.room3.Index
|
||||
|
||||
/**
|
||||
* Room 实体类,代表课程和周数的关联数据表。
|
||||
* 它解决了课程和周数之间的多对多关系。
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "course_weeks",
|
||||
// 联合主键,确保每对关联是唯一的
|
||||
primaryKeys = ["courseId", "weekNumber"],
|
||||
// 外键,当课程被删除时,其对应的周数关联也一并删除
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Course::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["courseId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
],
|
||||
// 索引,以提高查询性能
|
||||
indices = [Index(value = ["courseId"]), Index(value = ["weekNumber"])]
|
||||
)
|
||||
data class CourseWeek(
|
||||
val courseId: String, // 课程的唯一标识符
|
||||
val weekNumber: Int // 课程所在的周数
|
||||
)
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy
|
||||
import androidx.room3.Query
|
||||
import androidx.room3.Transaction
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Room 数据访问对象 (DAO),用于操作课程周数 (CourseWeek) 关联数据表。
|
||||
*/
|
||||
@Dao
|
||||
interface CourseWeekDao {
|
||||
/**
|
||||
* 获取指定课程的所有周数。
|
||||
*/
|
||||
@Query("SELECT * FROM course_weeks WHERE courseId = :courseId ORDER BY weekNumber ASC")
|
||||
fun getWeeksByCourseId(courseId: String): Flow<List<CourseWeek>>
|
||||
|
||||
/**
|
||||
* 批量插入课程周数。
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
suspend fun insertAll(courseWeeks: List<CourseWeek>)
|
||||
|
||||
/**
|
||||
* 更新指定课程的周数列表。
|
||||
* 这个方法在一个事务中执行,确保原子操作。
|
||||
* 核心逻辑:先删除该课程所有的旧周数,然后插入新的周数。
|
||||
*/
|
||||
@Transaction
|
||||
suspend fun updateCourseWeeks(courseId: String, courseWeeks: List<CourseWeek>) {
|
||||
// 先清理旧的关系
|
||||
deleteByCourseId(courseId)
|
||||
// 插入新的关系
|
||||
insertAll(courseWeeks)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据课程ID删除其所有的周数记录。
|
||||
*/
|
||||
@Query("DELETE FROM course_weeks WHERE courseId = :courseId")
|
||||
suspend fun deleteByCourseId(courseId: String)
|
||||
|
||||
/**
|
||||
* 根据课程ID列表和周次,批量删除周次记录。
|
||||
* 这是调课(TweakMode)场景下的核心方法:只切断特定周次的联系。
|
||||
*/
|
||||
@Query("DELETE FROM course_weeks WHERE courseId IN (:courseIds) AND weekNumber = :weekNumber")
|
||||
suspend fun deleteCourseWeeksForCourseAndWeek(courseIds: List<String>, weekNumber: Int)
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Embedded
|
||||
import androidx.room3.Relation
|
||||
|
||||
/**
|
||||
* 一个用于关联查询的数据类。
|
||||
* 它将一个 Course 实体和一个 CourseWeek 列表组合在一起。
|
||||
*
|
||||
* 这解决了 Room 中一个课程对应多个周数的复杂查询问题。
|
||||
*/
|
||||
data class CourseWithWeeks(
|
||||
@Embedded
|
||||
val course: Course,
|
||||
@Relation(
|
||||
parentColumns = ["id"],
|
||||
entityColumns = ["courseId"]
|
||||
)
|
||||
val weeks: List<CourseWeek>
|
||||
)
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.migration.Migration
|
||||
import androidx.sqlite.SQLiteConnection
|
||||
import androidx.sqlite.execSQL
|
||||
|
||||
/**
|
||||
* 数据库版本 1 迁移到 版本 2 的迁移代码。
|
||||
* 核心任务:
|
||||
* 1. 创建 course_table_config 表。
|
||||
* 2. 将老版本 app_settings 中的全局设置数据迁移到新表中。
|
||||
* 3. 删除 app_settings 表中已迁移的字段。
|
||||
*/
|
||||
val MIGRATION_1_2 = object : Migration(1, 2) {
|
||||
override suspend fun migrate(connection: SQLiteConnection) {
|
||||
// --- 步骤 1: 创建新的 course_table_config 表 ---
|
||||
connection.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `course_table_config` (
|
||||
`courseTableId` TEXT NOT NULL,
|
||||
`showWeekends` INTEGER NOT NULL DEFAULT 0,
|
||||
`semesterStartDate` TEXT,
|
||||
`semesterTotalWeeks` INTEGER NOT NULL DEFAULT 20,
|
||||
`defaultClassDuration` INTEGER NOT NULL DEFAULT 45,
|
||||
`defaultBreakDuration` INTEGER NOT NULL DEFAULT 10,
|
||||
`firstDayOfWeek` INTEGER NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY(`courseTableId`),
|
||||
FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
)
|
||||
// 添加索引
|
||||
connection.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_course_table_config_courseTableId` ON `course_table_config` (`courseTableId`)")
|
||||
|
||||
// --- 步骤 2 & 3: 读取老数据并插入新表 ---
|
||||
|
||||
var currentCourseTableId: String? = null
|
||||
var showWeekends = 0
|
||||
var semesterStartDate: String? = null
|
||||
var semesterTotalWeeks = 20
|
||||
var defaultClassDuration = 45
|
||||
var defaultBreakDuration = 10
|
||||
|
||||
// 1. 读取旧数据
|
||||
connection.prepare(
|
||||
"SELECT currentCourseTableId, showWeekends, semesterStartDate, semesterTotalWeeks, defaultClassDuration, defaultBreakDuration FROM app_settings WHERE id = 1 LIMIT 1"
|
||||
).use { stmt ->
|
||||
if (stmt.step()) {
|
||||
currentCourseTableId = if (!stmt.isNull(0)) stmt.getText(0) else null
|
||||
showWeekends = stmt.getLong(1).toInt()
|
||||
semesterStartDate = if (!stmt.isNull(2)) stmt.getText(2) else null
|
||||
semesterTotalWeeks = stmt.getLong(3).toInt()
|
||||
defaultClassDuration = stmt.getLong(4).toInt()
|
||||
defaultBreakDuration = stmt.getLong(5).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 将数据插入新表
|
||||
if (currentCourseTableId != null) {
|
||||
connection.prepare(
|
||||
"""
|
||||
INSERT INTO `course_table_config` (courseTableId, showWeekends, semesterStartDate, semesterTotalWeeks, defaultClassDuration, defaultBreakDuration, firstDayOfWeek)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
).use { stmt ->
|
||||
stmt.bindText(1, currentCourseTableId)
|
||||
stmt.bindLong(2, showWeekends.toLong())
|
||||
if (semesterStartDate != null) {
|
||||
stmt.bindText(3, semesterStartDate)
|
||||
} else {
|
||||
stmt.bindNull(3)
|
||||
}
|
||||
stmt.bindLong(4, semesterTotalWeeks.toLong())
|
||||
stmt.bindLong(5, defaultClassDuration.toLong())
|
||||
stmt.bindLong(6, defaultBreakDuration.toLong())
|
||||
stmt.bindLong(7, 1L)
|
||||
stmt.step()
|
||||
}
|
||||
}
|
||||
|
||||
// --- 步骤 4: 更新 app_settings 表结构 (删除字段) ---
|
||||
// 1. 重命名旧表
|
||||
connection.execSQL("ALTER TABLE app_settings RENAME TO app_settings_old")
|
||||
|
||||
// 2. 创建新的 app_settings 表
|
||||
connection.execSQL(
|
||||
"""
|
||||
CREATE TABLE `app_settings` (
|
||||
`id` INTEGER NOT NULL,
|
||||
`currentCourseTableId` TEXT,
|
||||
`reminderEnabled` INTEGER NOT NULL DEFAULT 0,
|
||||
`remindBeforeMinutes` INTEGER NOT NULL DEFAULT 15,
|
||||
`skippedDates` TEXT,
|
||||
`autoModeEnabled` INTEGER NOT NULL DEFAULT 0,
|
||||
`autoControlMode` TEXT NOT NULL DEFAULT 'DND',
|
||||
PRIMARY KEY(`id`)
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
// 3. 将旧表中保留的字段数据复制到新表
|
||||
connection.execSQL(
|
||||
"""
|
||||
INSERT INTO app_settings (id, currentCourseTableId, reminderEnabled, remindBeforeMinutes, skippedDates, autoModeEnabled, autoControlMode)
|
||||
SELECT id, currentCourseTableId, reminderEnabled, remindBeforeMinutes, skippedDates, 0, 'DND' FROM app_settings_old
|
||||
"""
|
||||
)
|
||||
|
||||
// 4. 删除旧表
|
||||
connection.execSQL("DROP TABLE app_settings_old")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库版本 2 迁移到 版本 3 的迁移代码。
|
||||
* 修改 courses 表,添加自定义时间字段。
|
||||
*/
|
||||
val MIGRATION_2_3 = object : Migration(2, 3) {
|
||||
override suspend fun migrate(connection: SQLiteConnection) {
|
||||
|
||||
// 创建具有新结构和约束的临时表 `courses_new`
|
||||
connection.execSQL(
|
||||
"""
|
||||
CREATE TABLE `courses_new` (
|
||||
`id` TEXT NOT NULL,
|
||||
`courseTableId` TEXT NOT NULL,
|
||||
`name` TEXT NOT NULL,
|
||||
`teacher` TEXT NOT NULL,
|
||||
`position` TEXT NOT NULL,
|
||||
`day` INTEGER NOT NULL,
|
||||
`startSection` INTEGER, -- 变为可空 (Int?)
|
||||
`endSection` INTEGER, -- 变为可空 (Int?)
|
||||
`isCustomTime` INTEGER NOT NULL DEFAULT 0, -- 新增字段,默认 FALSE
|
||||
`customStartTime` TEXT, -- 新增字段
|
||||
`customEndTime` TEXT, -- 新增字段
|
||||
`colorInt` INTEGER NOT NULL,
|
||||
PRIMARY KEY(`id`),
|
||||
FOREIGN KEY(`courseTableId`) REFERENCES `course_tables`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
// 将原表数据复制到新表
|
||||
connection.execSQL(
|
||||
"""
|
||||
INSERT INTO courses_new (id, courseTableId, name, teacher, position, day, startSection, endSection, colorInt, isCustomTime, customStartTime, customEndTime)
|
||||
SELECT id, courseTableId, name, teacher, position, day, startSection, endSection, colorInt, 0, NULL, NULL
|
||||
FROM courses
|
||||
"""
|
||||
)
|
||||
|
||||
// 移除原表并重命名新表
|
||||
connection.execSQL("DROP TABLE courses")
|
||||
connection.execSQL("ALTER TABLE courses_new RENAME TO courses")
|
||||
|
||||
// 重新创建必要的索引和外键索引
|
||||
connection.execSQL("CREATE INDEX IF NOT EXISTS `index_courses_courseTableId` ON `courses` (`courseTableId`)")
|
||||
}
|
||||
}
|
||||
|
||||
// 【集中管理所有迁移对象】
|
||||
val ALL_MIGRATIONS = arrayOf(
|
||||
MIGRATION_1_2,
|
||||
MIGRATION_2_3,
|
||||
)
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.AutoMigration
|
||||
import androidx.room3.ConstructedBy
|
||||
import androidx.room3.Database
|
||||
import androidx.room3.RoomDatabase
|
||||
import androidx.room3.RoomDatabaseConstructor
|
||||
import androidx.room3.migration.AutoMigrationSpec
|
||||
import com.xingheyuzhuan.shiguangschedule.data.di.AppStorage
|
||||
|
||||
@Database(
|
||||
entities = [
|
||||
CourseTable::class,
|
||||
Course::class,
|
||||
CourseWeek::class,
|
||||
TimeSlot::class,
|
||||
CourseTableConfig::class
|
||||
],
|
||||
version = 5,
|
||||
autoMigrations = [
|
||||
AutoMigration(from = 3, to = 4),
|
||||
AutoMigration(from = 4, to = 5, spec = MainAppDatabase.RemoveAppSettingsSpec::class)
|
||||
],
|
||||
exportSchema = true
|
||||
)
|
||||
@ConstructedBy(MainAppDatabaseConstructor::class)
|
||||
abstract class MainAppDatabase : RoomDatabase() {
|
||||
|
||||
@androidx.room3.DeleteTable(tableName = "app_settings")
|
||||
class RemoveAppSettingsSpec : AutoMigrationSpec
|
||||
|
||||
abstract fun courseTableDao(): CourseTableDao
|
||||
abstract fun courseDao(): CourseDao
|
||||
abstract fun courseWeekDao(): CourseWeekDao
|
||||
abstract fun timeSlotDao(): TimeSlotDao
|
||||
abstract fun courseTableConfigDao(): CourseTableConfigDao
|
||||
|
||||
companion object {
|
||||
fun getDatabase(appStorage: AppStorage): MainAppDatabase {
|
||||
return createMainDatabase(appStorage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect fun createMainDatabase(appStorage: AppStorage): MainAppDatabase
|
||||
|
||||
@Suppress("NO_ACTUAL_FOR_EXPECT")
|
||||
expect object MainAppDatabaseConstructor : RoomDatabaseConstructor<MainAppDatabase>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.ForeignKey
|
||||
import androidx.room3.Index
|
||||
|
||||
/**
|
||||
* Room 实体类,代表“时间段”数据表。
|
||||
* 存储每节课的节次编号和对应的开始/结束时间。
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "time_slots",
|
||||
// 外键约束,关联 CourseTable
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = CourseTable::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["courseTableId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
],
|
||||
indices = [Index(value = ["courseTableId"])],
|
||||
// 联合主键,以确保同一个课表中节次编号是唯一的
|
||||
primaryKeys = ["number", "courseTableId"]
|
||||
)
|
||||
data class TimeSlot(
|
||||
val number: Int, // 节次编号作为主键的一部分
|
||||
val startTime: String, // 开始时间,例如 "08:00"
|
||||
val endTime: String, // 结束时间,例如 "08:45"
|
||||
val courseTableId: String, //对应的课表id
|
||||
val alias: String? = null // 时间段别名(可选),如果为 null,则 UI 层面通常直接显示数字编号
|
||||
)
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.main
|
||||
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Delete
|
||||
import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy
|
||||
import androidx.room3.Query
|
||||
import androidx.room3.Update
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Room 数据访问对象 (DAO),用于操作时间段 (TimeSlot) 数据表。
|
||||
*/
|
||||
@Dao
|
||||
interface TimeSlotDao {
|
||||
/**
|
||||
* 获取指定课表的所有时间段,并按节次编号升序排列。
|
||||
*/
|
||||
@Query("SELECT * FROM time_slots WHERE courseTableId = :courseTableId ORDER BY number ASC")
|
||||
fun getTimeSlotsByCourseTableId(courseTableId: String): Flow<List<TimeSlot>>
|
||||
|
||||
/**
|
||||
* 根据节次编号和课表ID获取单个时间段。
|
||||
*/
|
||||
@Query("SELECT * FROM time_slots WHERE number = :number AND courseTableId = :courseTableId LIMIT 1")
|
||||
suspend fun getTimeSlot(number: Int, courseTableId: String): TimeSlot?
|
||||
|
||||
/**
|
||||
* 插入一个或多个时间段。如果发生主键冲突,则替换旧数据。
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAll(timeSlots: List<TimeSlot>)
|
||||
|
||||
/**
|
||||
* 更新一个现有时间段。
|
||||
*/
|
||||
@Update
|
||||
suspend fun update(timeSlot: TimeSlot)
|
||||
|
||||
/**
|
||||
* 删除一个或多个时间段。
|
||||
*/
|
||||
@Delete
|
||||
suspend fun delete(timeSlot: TimeSlot)
|
||||
|
||||
/**
|
||||
* 根据课表ID删除所有时间段。
|
||||
*/
|
||||
@Query("DELETE FROM time_slots WHERE courseTableId = :courseTableId")
|
||||
suspend fun deleteAllTimeSlotsByCourseTableId(courseTableId: String)
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.widget
|
||||
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.PrimaryKey
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
import kotlinx.datetime.isoDayNumber
|
||||
|
||||
@Entity(tableName = "widget_semester_start_date")
|
||||
data class WidgetAppSettings(
|
||||
@PrimaryKey
|
||||
val id: Int = 1,
|
||||
val semesterStartDate: String? = null, //第一周的时间
|
||||
val semesterTotalWeeks: Int = 20, // 最大周数
|
||||
val firstDayOfWeek: Int = DayOfWeek.MONDAY.isoDayNumber // 一周的起始日,1=周一,7=周日
|
||||
)
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.widget
|
||||
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy
|
||||
import androidx.room3.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface WidgetAppSettingsDao {
|
||||
/**
|
||||
* 获取小组件设置,返回一个可以为空的数据流。
|
||||
* 当表中没有数据时,它会发出一个 null 值。
|
||||
*/
|
||||
@Query("SELECT * FROM widget_semester_start_date WHERE id = 1")
|
||||
fun getAppSettings(): Flow<WidgetAppSettings?>
|
||||
|
||||
/**
|
||||
* 插入或更新小组件设置。
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertOrUpdate(settings: WidgetAppSettings)
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.widget
|
||||
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.PrimaryKey
|
||||
|
||||
/**
|
||||
* Room 实体类,专为桌面 Widget 设计的课程数据表。
|
||||
* 此表只包含 Widget 显示所需的最精简信息,数据由主数据库同步器预处理。
|
||||
*/
|
||||
@Entity(tableName = "widget_courses")
|
||||
data class WidgetCourse(
|
||||
@PrimaryKey
|
||||
val id: String, // 课程的唯一标识符
|
||||
val name: String, // 课程名称
|
||||
val teacher: String, // 老师姓名
|
||||
val position: String, // 上课地点
|
||||
val startTime: String, // 课程开始时间,例如 "08:00"
|
||||
val endTime: String, // 课程结束时间,例如 "08:45"
|
||||
val isSkipped: Boolean = false, // 是否跳过该课程
|
||||
val date: String, // 课程的真实上课日期,例如 "2025-09-15"
|
||||
val colorInt: Int // 新增字段:课程卡片的颜色索引
|
||||
)
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.widget
|
||||
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy
|
||||
import androidx.room3.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Room 数据访问对象 (DAO),用于操作 WidgetCourse 数据表。
|
||||
*/
|
||||
@Dao
|
||||
interface WidgetCourseDao {
|
||||
/**
|
||||
* 获取所有课程,返回一个数据流。
|
||||
* 它可以用来监听数据的变化,以便 Widget 自动更新。
|
||||
*/
|
||||
@Query("SELECT * FROM widget_courses ORDER BY date ASC, startTime ASC")
|
||||
fun getAllWidgetCourses(): Flow<List<WidgetCourse>>
|
||||
|
||||
/**
|
||||
* 根据指定的日期范围获取课程。
|
||||
*/
|
||||
@Query("SELECT * FROM widget_courses WHERE date BETWEEN :startDate AND :endDate ORDER BY date ASC, startTime ASC")
|
||||
fun getWidgetCoursesByDateRange(startDate: String, endDate: String): Flow<List<WidgetCourse>>
|
||||
|
||||
/**
|
||||
* 插入一个或多个课程。
|
||||
* 由于同步器会处理所有数据,我们使用 REPLACE 策略,在冲突时替换旧数据。
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.Companion.REPLACE)
|
||||
suspend fun insertAll(courses: List<WidgetCourse>)
|
||||
|
||||
/**
|
||||
* 删除所有课程。
|
||||
* 在同步前,我们可以清空旧数据。
|
||||
*/
|
||||
@Query("DELETE FROM widget_courses")
|
||||
suspend fun deleteAll()
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.db.widget
|
||||
|
||||
import androidx.room3.ConstructedBy
|
||||
import androidx.room3.Database
|
||||
import androidx.room3.RoomDatabase
|
||||
import androidx.room3.RoomDatabaseConstructor
|
||||
import com.xingheyuzhuan.shiguangschedule.data.di.AppStorage
|
||||
|
||||
@Database(
|
||||
entities = [WidgetCourse::class, WidgetAppSettings::class],
|
||||
version = 3,
|
||||
exportSchema = false
|
||||
)
|
||||
@ConstructedBy(WidgetDatabaseConstructor::class)
|
||||
abstract class WidgetDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun widgetCourseDao(): WidgetCourseDao
|
||||
abstract fun widgetAppSettingsDao(): WidgetAppSettingsDao
|
||||
|
||||
companion object {
|
||||
fun getDatabase(appStorage: AppStorage): WidgetDatabase {
|
||||
return createWidgetDatabase(appStorage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect fun createWidgetDatabase(appStorage: AppStorage): WidgetDatabase
|
||||
|
||||
@Suppress("NO_ACTUAL_FOR_EXPECT")
|
||||
expect object WidgetDatabaseConstructor : RoomDatabaseConstructor<WidgetDatabase>
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.di
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.core.DataStoreFactory
|
||||
import androidx.datastore.core.okio.OkioStorage
|
||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.schedule_style.ScheduleGridStyleProto
|
||||
import com.xingheyuzhuan.shiguangschedule.data.repository.SCHEDULE_STYLE_DATASTORE_FILE_NAME
|
||||
import com.xingheyuzhuan.shiguangschedule.data.repository.ScheduleStyleSerializer
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Named
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Module
|
||||
@Suppress("unused")
|
||||
class DataStoreModule {
|
||||
|
||||
@Single
|
||||
fun provideScheduleStyleDataStore(
|
||||
fileSystem: FileSystem,
|
||||
@Named("FilesDir") filesDir: Path
|
||||
): DataStore<ScheduleGridStyleProto> {
|
||||
return DataStoreFactory.create(
|
||||
storage = OkioStorage(
|
||||
fileSystem = fileSystem,
|
||||
serializer = ScheduleStyleSerializer,
|
||||
producePath = { filesDir / SCHEDULE_STYLE_DATASTORE_FILE_NAME }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Single
|
||||
@Named("AppSettings")
|
||||
fun provideAppSettingsDataStore(
|
||||
@Named("FilesDir") filesDir: Path
|
||||
): DataStore<Preferences> {
|
||||
return PreferenceDataStoreFactory.createWithPath(
|
||||
produceFile = { filesDir / "datastore" / "app_settings.preferences_pb" }
|
||||
)
|
||||
}
|
||||
|
||||
@Single
|
||||
@Named("ApiConfig")
|
||||
fun provideApiConfigDataStore(
|
||||
@Named("FilesDir") filesDir: Path
|
||||
): DataStore<Preferences> {
|
||||
return PreferenceDataStoreFactory.createWithPath(
|
||||
produceFile = { filesDir / "datastore" / "api_config.preferences_pb" }
|
||||
)
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.di
|
||||
|
||||
import com.xingheyuzhuan.shiguangschedule.data.db.main.*
|
||||
import com.xingheyuzhuan.shiguangschedule.data.db.widget.*
|
||||
import org.koin.core.annotation.Factory
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Module
|
||||
@Suppress("unused")
|
||||
class DatabaseModule {
|
||||
|
||||
@Single
|
||||
fun provideMainDatabase(appStorage: AppStorage): MainAppDatabase {
|
||||
return MainAppDatabase.getDatabase(appStorage)
|
||||
}
|
||||
|
||||
@Single
|
||||
fun provideWidgetDatabase(appStorage: AppStorage): WidgetDatabase {
|
||||
return WidgetDatabase.getDatabase(appStorage)
|
||||
}
|
||||
|
||||
@Factory
|
||||
fun provideCourseTableConfigDao(db: MainAppDatabase): CourseTableConfigDao = db.courseTableConfigDao()
|
||||
|
||||
@Factory
|
||||
fun provideTimeSlotDao(db: MainAppDatabase): TimeSlotDao = db.timeSlotDao()
|
||||
|
||||
@Factory
|
||||
fun provideCourseDao(db: MainAppDatabase): CourseDao = db.courseDao()
|
||||
|
||||
@Factory
|
||||
fun provideCourseTableDao(db: MainAppDatabase): CourseTableDao = db.courseTableDao()
|
||||
|
||||
@Factory
|
||||
fun provideCourseWeekDao(db: MainAppDatabase): CourseWeekDao = db.courseWeekDao()
|
||||
|
||||
@Factory
|
||||
fun provideWidgetCourseDao(db: WidgetDatabase): WidgetCourseDao = db.widgetCourseDao()
|
||||
|
||||
@Factory
|
||||
fun provideWidgetAppSettingsDao(db: WidgetDatabase): WidgetAppSettingsDao = db.widgetAppSettingsDao()
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.di
|
||||
|
||||
import okio.Path
|
||||
|
||||
/**
|
||||
* 跨平台文件存储路径抽象
|
||||
*/
|
||||
interface AppStorage {
|
||||
val filesDir: Path
|
||||
val cacheDir: Path
|
||||
fun getDatabasePath(dbName: String): String
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.di
|
||||
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import okio.SYSTEM
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Named
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Module(includes = [
|
||||
DatabaseModule::class,
|
||||
DataStoreModule::class
|
||||
])
|
||||
@ComponentScan("com.xingheyuzhuan.shiguangschedule")
|
||||
class SharedModule {
|
||||
|
||||
@Single
|
||||
fun provideFileSystem(): FileSystem = FileSystem.SYSTEM
|
||||
|
||||
@Single
|
||||
@Named("FilesDir")
|
||||
fun provideFilesDir(appStorage: AppStorage): Path {
|
||||
return appStorage.filesDir
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供全局应用缓存目录路径
|
||||
*/
|
||||
@Single
|
||||
@Named("CacheDir")
|
||||
fun provideCacheDir(appStorage: AppStorage): Path {
|
||||
return appStorage.cacheDir
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.model
|
||||
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||
import androidx.datastore.preferences.core.intPreferencesKey
|
||||
import androidx.datastore.preferences.core.longPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringSetPreferencesKey
|
||||
import org.jetbrains.compose.resources.StringResource
|
||||
import shiguangschedule.shared.generated.resources.*
|
||||
import com.xingheyuzhuan.shiguangschedule.ui.theme.DefaultThemeColor
|
||||
|
||||
/**
|
||||
* 上课时的自动化控制模式枚举
|
||||
*/
|
||||
enum class AutoControlMode(val value: String) {
|
||||
/** 请勿打扰模式 */
|
||||
DND("DND"),
|
||||
|
||||
/** 静音模式 */
|
||||
SILENT("SILENT");
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* 根据字符串获取对应的枚举值,如果匹配失败则返回默认的 DND 模式
|
||||
*/
|
||||
fun fromString(value: String?): AutoControlMode {
|
||||
return entries.find { it.value == value } ?: DND
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可选的启动页面枚举
|
||||
*/
|
||||
enum class StartScreen(val value: String, val labelRes: StringResource) {
|
||||
/** 周课表 */
|
||||
COURSE_SCHEDULE("COURSE_SCHEDULE", Res.string.nav_course_schedule),
|
||||
|
||||
/** 今日课表 */
|
||||
TODAY_SCHEDULE("TODAY_SCHEDULE", Res.string.nav_today_schedule);
|
||||
|
||||
companion object {
|
||||
fun fromString(value: String?): StartScreen {
|
||||
return entries.find { it.value == value } ?: COURSE_SCHEDULE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用主题模式枚举
|
||||
*/
|
||||
enum class AppThemeMode(val value: String, val labelRes: StringResource) {
|
||||
/** 跟随系统 */
|
||||
FOLLOW_SYSTEM("FOLLOW_SYSTEM", Res.string.theme_follow_system),
|
||||
|
||||
/** 浅色模式 */
|
||||
LIGHT("LIGHT", Res.string.theme_light),
|
||||
|
||||
/** 深色模式 */
|
||||
DARK("DARK", Res.string.theme_dark);
|
||||
|
||||
companion object {
|
||||
fun fromString(value: String?): AppThemeMode? {
|
||||
return entries.find { it.value == value }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用全局设置业务模型(DataStore 专用)
|
||||
* 集中管理业务字段、存储键 (Keys) 以及默认值。
|
||||
*/
|
||||
data class AppSettingsModel(
|
||||
/** 当前正在使用的课表 ID */
|
||||
val currentCourseTableId: String = "",
|
||||
|
||||
/** 是否开启上课前提醒 */
|
||||
val reminderEnabled: Boolean = false,
|
||||
|
||||
/** 提前提醒的时间(分钟) */
|
||||
val remindBeforeMinutes: Int = 15,
|
||||
|
||||
/** 需要跳过的日期集合 (例如: "2024-03-15") */
|
||||
val skippedDates: Set<String> = emptySet(),
|
||||
|
||||
/** 自动化模式的总开关 */
|
||||
val autoModeEnabled: Boolean = false,
|
||||
|
||||
/** 自动化控制的具体模式,限定为 [AutoControlMode] */
|
||||
val autoControlMode: AutoControlMode = AutoControlMode.DND,
|
||||
|
||||
/**
|
||||
* 兼容穿戴设备同步通知的开关
|
||||
* true: 开启兼容模式(关闭 Ongoing,方便手环抓取)
|
||||
* false: 关闭兼容模式(默认,使用 Android 16 实时更新特性)
|
||||
*/
|
||||
val compatWearableSync: Boolean = false,
|
||||
|
||||
/** 是否显示非本周课程 */
|
||||
val showNonCurrentWeekCourses: Boolean = false,
|
||||
|
||||
/** 应用启动时显示的页面 */
|
||||
val startScreen: StartScreen = StartScreen.COURSE_SCHEDULE,
|
||||
|
||||
/** 应用主题模式 */
|
||||
val themeMode: AppThemeMode = AppThemeMode.FOLLOW_SYSTEM,
|
||||
|
||||
/** 是否开启动态取色 (Material You) */
|
||||
val useDynamicColor: Boolean = true,
|
||||
|
||||
/** 自定义浅色主题主色 */
|
||||
val customLightPrimary: Long = DefaultThemeColor.toArgb().toLong(),
|
||||
|
||||
/** 自定义深色主题主色 */
|
||||
val customDarkPrimary: Long = DefaultThemeColor.toArgb().toLong(),
|
||||
) {
|
||||
/**
|
||||
* 将 DataStore 的 Key 定义在伴生对象中。
|
||||
* 这样在 Repository 中可以直接通过 AppSettingsModel.KEY_xxx 访问,
|
||||
* 避免了修改一处逻辑需要动多个文件的问题。
|
||||
*/
|
||||
companion object {
|
||||
val KEY_CURRENT_COURSE_TABLE_ID = stringPreferencesKey("current_course_table_id")
|
||||
val KEY_REMINDER_ENABLED = booleanPreferencesKey("reminder_enabled")
|
||||
val KEY_REMIND_BEFORE_MINUTES = intPreferencesKey("remind_before_minutes")
|
||||
val KEY_SKIPPED_DATES = stringSetPreferencesKey("skipped_dates")
|
||||
val KEY_AUTO_MODE_ENABLED = booleanPreferencesKey("auto_mode_enabled")
|
||||
val KEY_AUTO_CONTROL_MODE = stringPreferencesKey("auto_control_mode")
|
||||
val KEY_COMPAT_WEARABLE_SYNC = booleanPreferencesKey("compat_wearable_sync")
|
||||
val KEY_SHOW_NON_CURRENT_WEEK_COURSES = booleanPreferencesKey("show_non_current_week_courses")
|
||||
val KEY_START_SCREEN = stringPreferencesKey("start_screen")
|
||||
val KEY_THEME_MODE = stringPreferencesKey("theme_mode")
|
||||
val KEY_USE_DYNAMIC_COLOR = booleanPreferencesKey("use_dynamic_color")
|
||||
val KEY_CUSTOM_LIGHT_PRIMARY = longPreferencesKey("custom_light_primary")
|
||||
val KEY_CUSTOM_DARK_PRIMARY = longPreferencesKey("custom_dark_primary")
|
||||
|
||||
/**
|
||||
* 从 Preferences 中解析出 AppSettingsModel
|
||||
*/
|
||||
fun fromPreferences(prefs: Preferences, fallbackTableId: String): AppSettingsModel {
|
||||
val d = AppSettingsModel() // 默认值模板
|
||||
return AppSettingsModel(
|
||||
currentCourseTableId = prefs[KEY_CURRENT_COURSE_TABLE_ID] ?: fallbackTableId.ifEmpty { d.currentCourseTableId },
|
||||
reminderEnabled = prefs[KEY_REMINDER_ENABLED] ?: d.reminderEnabled,
|
||||
remindBeforeMinutes = prefs[KEY_REMIND_BEFORE_MINUTES] ?: d.remindBeforeMinutes,
|
||||
skippedDates = prefs[KEY_SKIPPED_DATES] ?: d.skippedDates,
|
||||
autoModeEnabled = prefs[KEY_AUTO_MODE_ENABLED] ?: d.autoModeEnabled,
|
||||
autoControlMode = AutoControlMode.fromString(prefs[KEY_AUTO_CONTROL_MODE]),
|
||||
compatWearableSync = prefs[KEY_COMPAT_WEARABLE_SYNC] ?: d.compatWearableSync,
|
||||
showNonCurrentWeekCourses = prefs[KEY_SHOW_NON_CURRENT_WEEK_COURSES] ?: d.showNonCurrentWeekCourses,
|
||||
startScreen = prefs[KEY_START_SCREEN]?.let { StartScreen.fromString(it) } ?: d.startScreen,
|
||||
themeMode = prefs[KEY_THEME_MODE]?.let { AppThemeMode.fromString(it) } ?: d.themeMode,
|
||||
useDynamicColor = prefs[KEY_USE_DYNAMIC_COLOR] ?: d.useDynamicColor,
|
||||
customLightPrimary = prefs[KEY_CUSTOM_LIGHT_PRIMARY] ?: d.customLightPrimary,
|
||||
customDarkPrimary = prefs[KEY_CUSTOM_DARK_PRIMARY] ?: d.customDarkPrimary,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.model
|
||||
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.cbor.Cbor
|
||||
|
||||
object CourseImportExport {
|
||||
|
||||
/**
|
||||
* 核心数据规范版本号
|
||||
* 确立基础全量多课表 CBOR 备份协议规范
|
||||
* 未来如果重构了底层数据架构(如颠覆了基础字段或关联关系),可手动升级为 2,借此编写迁移清洗流
|
||||
*/
|
||||
const val COURSE_SCHEMA_VERSION = 1
|
||||
|
||||
/**
|
||||
* 自定义 Json 解析器
|
||||
* ignoreUnknownKeys = true: 确保旧版 App 遇到新加的字段(如 remark)时能跳过而不崩溃
|
||||
* encodeDefaults = true: 导出时即使字段是默认值也会包含在 JSON 中
|
||||
*/
|
||||
val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
encodeDefaults = true
|
||||
coerceInputValues = true
|
||||
}
|
||||
|
||||
/**
|
||||
* CBOR 解析器(用于全盘多表备份、WebDAV 高密二进制流场景)
|
||||
*/
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
val cbor = Cbor {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 全盘备份文件的最外层“集装箱”
|
||||
*/
|
||||
@Serializable
|
||||
data class TotalAppBackupEnvelope(
|
||||
val backupTimestamp: Long, // 备份生成的时间戳
|
||||
val appVersionCode: Int, // 实际承载 CURRENT_SCHEMA_VERSION,代表数据协议版本
|
||||
val currentCourseTableId: String, // 备份前用户当前激活/选中的课表 ID
|
||||
val allTables: List<SingleTablePack> // 系统中所有课表的总集合列表
|
||||
)
|
||||
|
||||
/**
|
||||
* 单个课表资产的隔离包裹
|
||||
*/
|
||||
@Serializable
|
||||
data class SingleTablePack(
|
||||
val tableId: String, // 课表在数据库中的物理 UUID 主键
|
||||
val tableName: String, // 课表名称
|
||||
val createdAt: Long, // 课表本身的创建时间戳,用于恢复后列表排序
|
||||
val tableData: CourseTableExportModel // 直接复用单表导出模型
|
||||
)
|
||||
|
||||
|
||||
|
||||
// 用于 JSON 导入和导出的配置模型
|
||||
@Serializable
|
||||
data class CourseConfigJsonModel(
|
||||
val semesterStartDate: String? = null,
|
||||
val semesterTotalWeeks: Int = 20,
|
||||
val defaultClassDuration: Int = 45,
|
||||
val defaultBreakDuration: Int = 10,
|
||||
val firstDayOfWeek: Int = 1
|
||||
)
|
||||
|
||||
// 导入时使用的 JSON 模型
|
||||
@Serializable
|
||||
data class CourseTableImportModel(
|
||||
val courses: List<ImportCourseJsonModel>,
|
||||
val timeSlots: List<TimeSlotJsonModel>? = emptyList(),
|
||||
val config: CourseConfigJsonModel? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ImportCourseJsonModel(
|
||||
val id: String? = null,
|
||||
val name: String,
|
||||
val teacher: String,
|
||||
val position: String,
|
||||
val day: Int,
|
||||
val startSection: Int? = null,
|
||||
val endSection: Int? = null,
|
||||
val weeks: List<Int>,
|
||||
val isCustomTime: Boolean = false,
|
||||
val customStartTime: String? = null,
|
||||
val customEndTime: String? = null,
|
||||
val color: Int? = null,
|
||||
val remark: String? = null
|
||||
)
|
||||
|
||||
// 导出时使用的 JSON 模型
|
||||
@Serializable
|
||||
data class CourseTableExportModel(
|
||||
val courses: List<ExportCourseJsonModel>,
|
||||
val timeSlots: List<TimeSlotJsonModel>,
|
||||
val config: CourseConfigJsonModel
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ExportCourseJsonModel(
|
||||
val id: String, // 导出时id必须
|
||||
val name: String,
|
||||
val teacher: String,
|
||||
val position: String,
|
||||
val day: Int,
|
||||
val startSection: Int? = null,
|
||||
val endSection: Int? = null,
|
||||
val color: Int, // 导出时颜色必须
|
||||
val weeks: List<Int>,
|
||||
val isCustomTime: Boolean = false,
|
||||
val customStartTime: String? = null,
|
||||
val customEndTime: String? = null,
|
||||
val remark: String?
|
||||
)
|
||||
|
||||
// 导入和导出都通用的时间段模型
|
||||
@Serializable
|
||||
data class TimeSlotJsonModel(
|
||||
val number: Int,
|
||||
val startTime: String,
|
||||
val endTime: String,
|
||||
val alias: String? = null
|
||||
)
|
||||
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.model
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.schedule_style.BorderTypeProto
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.schedule_style.DualColorProto
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.schedule_style.ScheduleGridStyleProto
|
||||
import com.xingheyuzhuan.shiguangschedule.data.model.schedule_style.ScheduleModeProto
|
||||
|
||||
// 1. Compose 业务模型
|
||||
|
||||
/**
|
||||
* 浅色和深色模式下的颜色对。
|
||||
*/
|
||||
data class DualColor(val light: Color, val dark: Color)
|
||||
|
||||
/**
|
||||
* 课表网格样式配置的业务模型
|
||||
* 所有尺寸(Dp)属性使用 Float,颜色(Color)属性使用 Long。
|
||||
*/
|
||||
data class ScheduleGridStyle(
|
||||
// Grid 尺寸 (单位: Float/Dp)
|
||||
val timeColumnWidthDp: Float = DEFAULT_TIME_COLUMN_WIDTH,
|
||||
val dayHeaderHeightDp: Float = DEFAULT_DAY_HEADER_HEIGHT,
|
||||
val sectionHeightDp: Float = DEFAULT_SECTION_HEIGHT,
|
||||
|
||||
// CourseBlock 外观 (单位: Float/Dp & Float)
|
||||
val courseBlockCornerRadiusDp: Float = DEFAULT_BLOCK_CORNER_RADIUS,
|
||||
val courseBlockOuterPaddingDp: Float = DEFAULT_BLOCK_OUTER_PADDING,
|
||||
val courseBlockInnerPaddingDp: Float = DEFAULT_BLOCK_INNER_PADDING,
|
||||
val courseBlockAlphaFloat: Float = DEFAULT_BLOCK_ALPHA,
|
||||
|
||||
// 颜色列表
|
||||
val courseColorMaps: List<DualColor> = DEFAULT_COLOR_MAPS,
|
||||
|
||||
val courseBlockFontScale: Float = DEFAULT_FONT_SCALE,
|
||||
|
||||
// 界面开关与布局控制
|
||||
val hideGridLines: Boolean = false,
|
||||
val hideSectionTime: Boolean = false,
|
||||
val hideDateUnderDay: Boolean = false,
|
||||
val showStartTime: Boolean = false,
|
||||
val hideLocation: Boolean = false,
|
||||
val hideTeacher: Boolean = false,
|
||||
val removeLocationAt: Boolean = false,
|
||||
val textAlignCenterHorizontal: Boolean = false,
|
||||
val textAlignCenterVertical: Boolean = false,
|
||||
val borderType: BorderTypeProto = BorderTypeProto.BORDER_TYPE_NONE,
|
||||
val scheduleMode: ScheduleModeProto = ScheduleModeProto.SECTION_MODE,
|
||||
val pageTextColorLong: Long? = null,
|
||||
val courseTextColorLong: Long? = null,
|
||||
|
||||
// 背景壁纸路径 (存储在私有目录下的绝对路径)
|
||||
val backgroundImagePath: String? = null
|
||||
) {
|
||||
|
||||
fun generateRandomColorIndex(): Int {
|
||||
if (courseColorMaps.isEmpty()) return 0
|
||||
return kotlin.random.Random.nextInt(courseColorMaps.size)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// --- 默认常量
|
||||
val DEFAULT_TIME_COLUMN_WIDTH = 40f
|
||||
val DEFAULT_DAY_HEADER_HEIGHT = 45f
|
||||
val DEFAULT_SECTION_HEIGHT = 70f
|
||||
val DEFAULT_BLOCK_CORNER_RADIUS = 4f
|
||||
val DEFAULT_BLOCK_OUTER_PADDING = 1f
|
||||
val DEFAULT_BLOCK_INNER_PADDING = 4f
|
||||
val DEFAULT_BLOCK_ALPHA = 1f
|
||||
val DEFAULT_FONT_SCALE = 1f
|
||||
|
||||
val DEFAULT_COLOR_MAPS = listOf(
|
||||
DualColor(light = Color(0xFFFFCC99), dark = Color(0xFF663300)),
|
||||
DualColor(light = Color(0xFFFFE699), dark = Color(0xFF664D00)),
|
||||
DualColor(light = Color(0xFFE6FF99), dark = Color(0xFF4D6600)),
|
||||
DualColor(light = Color(0xFFCCFF99), dark = Color(0xFF336600)),
|
||||
DualColor(light = Color(0xFF99FFB3), dark = Color(0xFF00661A)),
|
||||
DualColor(light = Color(0xFF99FFE6), dark = Color(0xFF00664D)),
|
||||
DualColor(light = Color(0xFF99FFFF), dark = Color(0xFF006666)),
|
||||
DualColor(light = Color(0xFF99E6FF), dark = Color(0xFF004D66)),
|
||||
DualColor(light = Color(0xFFB399FF), dark = Color(0xFF1A0066)),
|
||||
DualColor(light = Color(0xFFFF99E6), dark = Color(0xFF66004D)),
|
||||
DualColor(light = Color(0xFFFF99CC), dark = Color(0xFF660033)),
|
||||
DualColor(light = Color(0xFFFF99B3), dark = Color(0xFF66001A)),
|
||||
)
|
||||
|
||||
/**
|
||||
* 默认样式对象,用于首次启动或重置样式。
|
||||
*/
|
||||
val DEFAULT = ScheduleGridStyle(
|
||||
timeColumnWidthDp = DEFAULT_TIME_COLUMN_WIDTH,
|
||||
dayHeaderHeightDp = DEFAULT_DAY_HEADER_HEIGHT,
|
||||
sectionHeightDp = DEFAULT_SECTION_HEIGHT,
|
||||
courseBlockCornerRadiusDp = DEFAULT_BLOCK_CORNER_RADIUS,
|
||||
courseBlockOuterPaddingDp = DEFAULT_BLOCK_OUTER_PADDING,
|
||||
courseBlockInnerPaddingDp = DEFAULT_BLOCK_INNER_PADDING,
|
||||
courseBlockAlphaFloat = DEFAULT_BLOCK_ALPHA,
|
||||
courseColorMaps = DEFAULT_COLOR_MAPS,
|
||||
courseBlockFontScale = DEFAULT_FONT_SCALE,
|
||||
hideGridLines = false,
|
||||
hideSectionTime = false,
|
||||
hideDateUnderDay = false,
|
||||
showStartTime = false,
|
||||
hideLocation = false,
|
||||
hideTeacher = false,
|
||||
removeLocationAt = false,
|
||||
textAlignCenterHorizontal = false,
|
||||
textAlignCenterVertical = false,
|
||||
borderType = BorderTypeProto.BORDER_TYPE_NONE,
|
||||
scheduleMode = ScheduleModeProto.SECTION_MODE,
|
||||
pageTextColorLong = null,
|
||||
courseTextColorLong = null,
|
||||
backgroundImagePath = null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 2. Proto ⇔ Compose 转换扩展函数
|
||||
|
||||
fun DualColorProto.toCompose(): DualColor {
|
||||
// Wire 中属性是直接访问的,long 类型不需要 toInt (除非颜色存储逻辑需要)
|
||||
return DualColor(
|
||||
light = Color(this.light_color), // Wire 属性名是下划线风格
|
||||
dark = Color(this.dark_color)
|
||||
)
|
||||
}
|
||||
|
||||
fun DualColor.toProto(): DualColorProto {
|
||||
// Wire 不使用 Builder,而是直接构造类或使用 copy()
|
||||
return DualColorProto(
|
||||
light_color = this.light.toArgb().toLong(),
|
||||
dark_color = this.dark.toArgb().toLong()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Protobuf -> ScheduleGridStyle 转换 function
|
||||
*/
|
||||
fun ScheduleGridStyleProto.toCompose(): ScheduleGridStyle {
|
||||
val d = ScheduleGridStyle.DEFAULT
|
||||
|
||||
return ScheduleGridStyle(
|
||||
// Wire 中不使用 hasXXX() 判定,而是直接判定是否为 null 或默认值 (Proto3)
|
||||
// 1. 基础布局尺寸 (Wire 生成的是可空或带默认值的属性)
|
||||
timeColumnWidthDp = this.time_column_width_dp ?: d.timeColumnWidthDp,
|
||||
dayHeaderHeightDp = this.day_header_height_dp ?: d.dayHeaderHeightDp,
|
||||
sectionHeightDp = this.section_height_dp ?: d.sectionHeightDp,
|
||||
|
||||
// 2. 课程块外观
|
||||
courseBlockCornerRadiusDp = this.course_block_corner_radius_dp ?: d.courseBlockCornerRadiusDp,
|
||||
courseBlockOuterPaddingDp = this.course_block_outer_padding_dp ?: d.courseBlockOuterPaddingDp,
|
||||
courseBlockInnerPaddingDp = this.course_block_inner_padding_dp ?: d.courseBlockInnerPaddingDp,
|
||||
|
||||
// 3. 透明度与缩放
|
||||
courseBlockAlphaFloat = this.course_block_alpha_float ?: d.courseBlockAlphaFloat,
|
||||
courseBlockFontScale = this.course_block_font_scale ?: d.courseBlockFontScale,
|
||||
|
||||
// 5. 列表转换 (Wire 中 List 不会是 null,为空则是 EmptyList)
|
||||
courseColorMaps = if (this.course_color_maps.isEmpty()) d.courseColorMaps else this.course_color_maps.map { it.toCompose() },
|
||||
|
||||
// 6. 开关映射
|
||||
hideGridLines = this.hide_grid_lines ?: d.hideGridLines,
|
||||
hideSectionTime = this.hide_section_time ?: d.hideSectionTime,
|
||||
hideDateUnderDay = this.hide_date_under_day ?: d.hideDateUnderDay,
|
||||
showStartTime = this.show_start_time ?: d.showStartTime,
|
||||
hideLocation = this.hide_location ?: d.hideLocation,
|
||||
hideTeacher = this.hide_teacher ?: d.hideTeacher,
|
||||
removeLocationAt = this.remove_location_at ?: d.removeLocationAt,
|
||||
pageTextColorLong = this.page_text_color_long,
|
||||
courseTextColorLong = this.course_text_color_long,
|
||||
|
||||
// 7. 对齐与边框
|
||||
textAlignCenterHorizontal = this.text_align_center_horizontal ?: d.textAlignCenterHorizontal,
|
||||
textAlignCenterVertical = this.text_align_center_vertical ?: d.textAlignCenterVertical,
|
||||
borderType = this.border_type ?: d.borderType,
|
||||
scheduleMode = this.schedule_mode ?: d.scheduleMode,
|
||||
|
||||
// 8. 背景图路径映射
|
||||
backgroundImagePath = if (!this.background_image_path.isNullOrEmpty()) this.background_image_path else null
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* ScheduleGridStyle -> Protobuf 转换 (用于写入)
|
||||
*/
|
||||
fun ScheduleGridStyle.toProto(): ScheduleGridStyleProto {
|
||||
return ScheduleGridStyleProto(
|
||||
time_column_width_dp = this.timeColumnWidthDp,
|
||||
day_header_height_dp = this.dayHeaderHeightDp,
|
||||
section_height_dp = this.sectionHeightDp,
|
||||
course_block_corner_radius_dp = this.courseBlockCornerRadiusDp,
|
||||
course_block_outer_padding_dp = this.courseBlockOuterPaddingDp,
|
||||
course_block_inner_padding_dp = this.courseBlockInnerPaddingDp,
|
||||
course_block_alpha_float = this.courseBlockAlphaFloat,
|
||||
course_block_font_scale = this.courseBlockFontScale,
|
||||
course_color_maps = this.courseColorMaps.map { it.toProto() },
|
||||
hide_grid_lines = this.hideGridLines,
|
||||
hide_section_time = this.hideSectionTime,
|
||||
hide_date_under_day = this.hideDateUnderDay,
|
||||
show_start_time = this.showStartTime,
|
||||
hide_location = this.hideLocation,
|
||||
hide_teacher = this.hideTeacher,
|
||||
remove_location_at = this.removeLocationAt,
|
||||
text_align_center_horizontal = this.textAlignCenterHorizontal,
|
||||
text_align_center_vertical = this.textAlignCenterVertical,
|
||||
border_type = this.borderType,
|
||||
schedule_mode = this.scheduleMode,
|
||||
|
||||
page_text_color_long = this.pageTextColorLong,
|
||||
course_text_color_long = this.courseTextColorLong,
|
||||
background_image_path = this.backgroundImagePath ?: ""
|
||||
)
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package com.xingheyuzhuan.shiguangschedule.data.repository
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import com.xingheyuzhuan.shiguangschedule.data.api.webdav.WebDavClient
|
||||
import com.xingheyuzhuan.shiguangschedule.data.api.webdav.WebDavConfig
|
||||
import com.xingheyuzhuan.shiguangschedule.tool.SecureCrypto
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.koin.core.annotation.Named
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
/**
|
||||
* 全局 API 配置持久化中心仓库(KMP 共享层)
|
||||
*/
|
||||
@Single
|
||||
class ApiConfigRepository(
|
||||
@Named("ApiConfig") private val dataStore: DataStore<Preferences>,
|
||||
private val secureCrypto: SecureCrypto
|
||||
) {
|
||||
|
||||
/**
|
||||
* 所有的 API 存储 Key 划分严格的边界线
|
||||
*/
|
||||
object ApiKeys {
|
||||
|
||||
/** WebDAV 备份 business line 命名空间 */
|
||||
object WebDav {
|
||||
private const val PREFIX = "webdav_"
|
||||
val BASE_URL = stringPreferencesKey("${PREFIX}base_url")
|
||||
val USERNAME = stringPreferencesKey("${PREFIX}username")
|
||||
val ROOT_PATH = stringPreferencesKey("${PREFIX}root_path")
|
||||
val ENCRYPTED_PASSWORD = stringPreferencesKey("${PREFIX}encrypted_pwd")
|
||||
val CRYPTO_IV = stringPreferencesKey("${PREFIX}crypto_iv")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应式流:实时观察 WebDAV 的完整配置状态
|
||||
*/
|
||||
val webDavConfigFlow: Flow<WebDavConfig?> = dataStore.data.map { preferences ->
|
||||
val baseUrl = preferences[ApiKeys.WebDav.BASE_URL]
|
||||
val username = preferences[ApiKeys.WebDav.USERNAME]
|
||||
val rootPath = preferences[ApiKeys.WebDav.ROOT_PATH] ?: "ShiguangSchedule"
|
||||
val encryptedPassword = preferences[ApiKeys.WebDav.ENCRYPTED_PASSWORD]
|
||||
val ivString = preferences[ApiKeys.WebDav.CRYPTO_IV]
|
||||
|
||||
if (!baseUrl.isNullOrBlank() && !username.isNullOrBlank() &&
|
||||
!encryptedPassword.isNullOrBlank() && !ivString.isNullOrBlank()
|
||||
) {
|
||||
val decryptedPassword = secureCrypto.decrypt(encryptedPassword, ivString)
|
||||
|
||||
if (decryptedPassword != null) {
|
||||
WebDavConfig(
|
||||
baseUrl = baseUrl,
|
||||
username = username,
|
||||
password = decryptedPassword,
|
||||
rootPath = rootPath
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存或更新 WebDAV 配置
|
||||
*/
|
||||
suspend fun saveWebDavConfig(config: WebDavConfig) {
|
||||
val cryptoResult = secureCrypto.encrypt(config.password) ?: return
|
||||
|
||||
dataStore.edit { preferences ->
|
||||
preferences[ApiKeys.WebDav.BASE_URL] = config.baseUrl.trim()
|
||||
preferences[ApiKeys.WebDav.USERNAME] = config.username.trim()
|
||||
preferences[ApiKeys.WebDav.ROOT_PATH] = config.rootPath.trim()
|
||||
preferences[ApiKeys.WebDav.ENCRYPTED_PASSWORD] = cryptoResult.encryptedData
|
||||
preferences[ApiKeys.WebDav.CRYPTO_IV] = cryptoResult.iv
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除 WebDAV 配置
|
||||
*/
|
||||
suspend fun clearWebDavConfig() {
|
||||
dataStore.edit { preferences ->
|
||||
preferences.remove(ApiKeys.WebDav.BASE_URL)
|
||||
preferences.remove(ApiKeys.WebDav.USERNAME)
|
||||
preferences.remove(ApiKeys.WebDav.ROOT_PATH)
|
||||
preferences.remove(ApiKeys.WebDav.ENCRYPTED_PASSWORD)
|
||||
preferences.remove(ApiKeys.WebDav.CRYPTO_IV)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 传输引擎工厂:动态创建一套可用的 WebDavClient
|
||||
*/
|
||||
suspend fun createWebDavClient(explicitConfig: WebDavConfig? = null): WebDavClient? {
|
||||
val finalConfig = explicitConfig ?: webDavConfigFlow.firstOrNull()
|
||||
return finalConfig?.let {
|
||||
WebDavClient(config = it)
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user