|
|
@ -4,6 +4,7 @@ import android.app.Application |
|
|
|
import android.app.NotificationChannel |
|
|
|
import android.app.NotificationChannel |
|
|
|
import android.app.NotificationManager |
|
|
|
import android.app.NotificationManager |
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import android.content.pm.PackageManager |
|
|
|
import android.os.Build |
|
|
|
import android.os.Build |
|
|
|
import androidx.annotation.RequiresApi |
|
|
|
import androidx.annotation.RequiresApi |
|
|
|
import androidx.appcompat.app.AppCompatDelegate |
|
|
|
import androidx.appcompat.app.AppCompatDelegate |
|
|
@ -28,12 +29,24 @@ class App : Application() { |
|
|
|
private set |
|
|
|
private set |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var versionCode = 0 |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate() { |
|
|
|
override fun onCreate() { |
|
|
|
super.onCreate() |
|
|
|
super.onCreate() |
|
|
|
INSTANCE = this |
|
|
|
INSTANCE = this |
|
|
|
db = AppDatabase.createDatabase(INSTANCE) |
|
|
|
db = AppDatabase.createDatabase(INSTANCE) |
|
|
|
|
|
|
|
versionCode = try { |
|
|
|
|
|
|
|
packageManager.getPackageInfo(packageName, 0).versionCode |
|
|
|
|
|
|
|
} catch (e: PackageManager.NameNotFoundException) { |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
} |
|
|
|
initNightTheme() |
|
|
|
initNightTheme() |
|
|
|
upThemeStore() |
|
|
|
if (!ThemeStore.isConfigured(this, versionCode)) { |
|
|
|
|
|
|
|
upThemeStore() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
|
|
|
|
|
|
createChannelId() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun initNightTheme() { |
|
|
|
fun initNightTheme() { |
|
|
@ -44,6 +57,9 @@ class App : Application() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 更新主题 |
|
|
|
|
|
|
|
*/ |
|
|
|
fun upThemeStore() { |
|
|
|
fun upThemeStore() { |
|
|
|
if (getPrefBoolean("isNightTheme", false)) { |
|
|
|
if (getPrefBoolean("isNightTheme", false)) { |
|
|
|
ThemeStore.editTheme(this) |
|
|
|
ThemeStore.editTheme(this) |
|
|
@ -63,6 +79,7 @@ class App : Application() { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 创建通知ID |
|
|
|
* 创建通知ID |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.O) |
|
|
|
@RequiresApi(Build.VERSION_CODES.O) |
|
|
|
private fun createChannelId() { |
|
|
|
private fun createChannelId() { |
|
|
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager |
|
|
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager |
|
|
|