Add feedback service, reminder diagnostics and smooth week transitions
This commit is contained in:
@@ -7,6 +7,7 @@ import io.flutter.embedding.engine.FlutterEngine
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
private var calendar: CalendarBridge? = null
|
||||
private var reminders: ReminderSystemBridge? = null
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
@@ -18,6 +19,7 @@ class MainActivity : FlutterActivity() {
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
calendar = CalendarBridge(this, flutterEngine.dartExecutor.binaryMessenger)
|
||||
reminders = ReminderSystemBridge(this, flutterEngine.dartExecutor.binaryMessenger)
|
||||
}
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
@@ -25,6 +27,7 @@ class MainActivity : FlutterActivity() {
|
||||
}
|
||||
override fun onDestroy() {
|
||||
calendar?.close()
|
||||
reminders?.close()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.tpschedule.app
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.ActivityManager
|
||||
import android.app.NotificationManager
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import io.flutter.plugin.common.BinaryMessenger
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class ReminderSystemBridge(private val activity: Activity, messenger: BinaryMessenger) {
|
||||
private val channel = MethodChannel(messenger, "com.tpschedule.app/reminders")
|
||||
|
||||
init {
|
||||
channel.setMethodCallHandler { call, result ->
|
||||
try {
|
||||
when (call.method) {
|
||||
"getStatus" -> result.success(status())
|
||||
"openNotificationSettings" -> {
|
||||
openNotificationSettings()
|
||||
result.success(null)
|
||||
}
|
||||
"openBackgroundSettings" -> {
|
||||
openBackgroundSettings()
|
||||
result.success(null)
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
result.error("reminder_system_unavailable", "系统提醒设置暂时不可用", null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun status(): Map<String, Any?> {
|
||||
val activityManager = activity.getSystemService(Activity.ACTIVITY_SERVICE) as ActivityManager
|
||||
val powerManager = activity.getSystemService(Activity.POWER_SERVICE) as PowerManager
|
||||
val notificationManager = activity.getSystemService(Activity.NOTIFICATION_SERVICE) as NotificationManager
|
||||
return mapOf(
|
||||
"manufacturer" to Build.MANUFACTURER,
|
||||
"model" to Build.MODEL,
|
||||
"androidVersion" to Build.VERSION.RELEASE,
|
||||
"sdk" to Build.VERSION.SDK_INT,
|
||||
"backgroundRestricted" to if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
activityManager.isBackgroundRestricted
|
||||
} else null,
|
||||
"batteryOptimizationsIgnored" to powerManager.isIgnoringBatteryOptimizations(activity.packageName),
|
||||
"powerSaveMode" to powerManager.isPowerSaveMode,
|
||||
"interruptionFilter" to notificationManager.currentInterruptionFilter,
|
||||
)
|
||||
}
|
||||
|
||||
private fun applicationDetails() = Intent(
|
||||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
Uri.parse("package:${activity.packageName}"),
|
||||
)
|
||||
|
||||
private fun openNotificationSettings() {
|
||||
val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||
.putExtra(Settings.EXTRA_APP_PACKAGE, activity.packageName)
|
||||
} else applicationDetails()
|
||||
openWithFallback(intent)
|
||||
}
|
||||
|
||||
private fun openBackgroundSettings() {
|
||||
// Show settings for the user to review; never request automatic exemption.
|
||||
openWithFallback(Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS))
|
||||
}
|
||||
|
||||
private fun openWithFallback(intent: Intent) {
|
||||
try {
|
||||
activity.startActivity(intent)
|
||||
} catch (_: Exception) {
|
||||
activity.startActivity(applicationDetails())
|
||||
}
|
||||
}
|
||||
|
||||
fun close() {
|
||||
channel.setMethodCallHandler(null)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user