-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
714 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
android/app/src/main/kotlin/com/github/jing332/alistflutter/constant/LogLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.jing332.alistflutter.constant | ||
|
||
import androidx.annotation.IntDef | ||
|
||
@IntDef( | ||
LogLevel.PANIC, | ||
LogLevel.FATAL, | ||
LogLevel.ERROR, | ||
LogLevel.WARN, | ||
LogLevel.INFO, | ||
LogLevel.DEBUG, | ||
LogLevel.TRACE | ||
) | ||
annotation class LogLevel { | ||
companion object { | ||
const val PANIC = 0 | ||
const val FATAL = 1 | ||
const val ERROR = 2 | ||
const val WARN = 3 | ||
const val INFO = 4 | ||
const val DEBUG = 5 | ||
const val TRACE = 6 | ||
|
||
fun Int.toLevelString(): String { | ||
return when (this) { | ||
PANIC -> "PANIC" | ||
FATAL -> "FATAL" | ||
ERROR -> "ERROR" | ||
WARN -> "WARN" | ||
INFO -> "INFO" | ||
DEBUG -> "DEBUG" | ||
TRACE -> "TRACE" | ||
else -> "UNKNOWN" | ||
} | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
android/app/src/main/kotlin/com/github/jing332/alistflutter/data/AppDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
package com.github.jing332.alistflutter.data | ||
import androidx.room.AutoMigration | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import com.github.jing332.alistandroid.data.dao.ServerLogDao | ||
import com.github.jing332.alistflutter.data.entities.ServerLog | ||
import com.github.jing332.alistflutter.App.Companion.app | ||
val appDb by lazy { AppDatabase.create() } | ||
@Database( | ||
version = 2, | ||
entities = [ServerLog::class], | ||
autoMigrations = [ | ||
AutoMigration(from = 1, to = 2) | ||
] | ||
) | ||
abstract class AppDatabase : RoomDatabase() { | ||
abstract val serverLogDao: ServerLogDao | ||
companion object { | ||
fun create() = Room.databaseBuilder( | ||
app, | ||
AppDatabase::class.java, | ||
"alistandroid.db" | ||
) | ||
.allowMainThreadQueries() | ||
.build() | ||
} | ||
}*/ |
31 changes: 31 additions & 0 deletions
31
android/app/src/main/kotlin/com/github/jing332/alistflutter/data/entities/ServerLog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.jing332.alistflutter.data.entities | ||
|
||
import com.github.jing332.alistflutter.constant.LogLevel | ||
|
||
data class ServerLog( | ||
|
||
@LogLevel val level: Int, | ||
val message: String, | ||
val time: String, | ||
) { | ||
companion object { | ||
|
||
@Suppress("RegExpRedundantEscape") | ||
fun String.evalLog(): ServerLog? { | ||
val logPattern = """(\w+)\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\] (.+)""".toRegex() | ||
val result = logPattern.find(this) | ||
if (result != null) { | ||
val (level, time, msg) = result.destructured | ||
val l = when (level[0].toString()) { | ||
"D" -> LogLevel.DEBUG | ||
"I" -> LogLevel.INFO | ||
"W" -> LogLevel.WARN | ||
"E" -> LogLevel.ERROR | ||
else -> LogLevel.INFO | ||
} | ||
return ServerLog(level = l, message = msg, time = time) | ||
} | ||
return null | ||
} | ||
} | ||
} |
Oops, something went wrong.