refactor(android): Batch A - Delegate checkStatus() to NotificationStatusChecker
Refactored checkStatus() to delegate to NotificationStatusChecker service. Changes: - Added statusChecker service instance to plugin - Initialize statusChecker in load() method - Replaced 53 lines of status checking logic with 3-line delegation - checkStatus() now calls NotificationStatusChecker.getComprehensiveStatus() This is the first method in Batch A (pure delegation, read-only). Verification: - Service method exists and returns JSObject ✅ - Error handling preserved ✅ - No behavior change (delegation only) ✅ Reduction: ~50 lines removed from plugin class
This commit is contained in:
@@ -88,6 +88,9 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
|
||||
private val PERMISSION_REQUEST_CODE = 1001
|
||||
|
||||
// Service instances for delegation
|
||||
private var statusChecker: NotificationStatusChecker? = null
|
||||
|
||||
override fun load() {
|
||||
super.load()
|
||||
try {
|
||||
@@ -96,7 +99,8 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
return
|
||||
}
|
||||
db = DailyNotificationDatabase.getDatabase(context)
|
||||
Log.i(TAG, "Daily Notification Plugin loaded successfully")
|
||||
statusChecker = NotificationStatusChecker(context)
|
||||
Log.i(TAG, "Daily Notification Plugin loaded successfully")
|
||||
|
||||
// Phase 1: Perform app launch recovery (cold start only)
|
||||
// Runs asynchronously, non-blocking, with timeout
|
||||
@@ -1113,53 +1117,17 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
|
||||
@PluginMethod
|
||||
fun checkStatus(call: PluginCall) {
|
||||
// Comprehensive status check
|
||||
// Comprehensive status check - delegate to NotificationStatusChecker
|
||||
try {
|
||||
if (context == null) {
|
||||
return call.reject("Context not available")
|
||||
}
|
||||
|
||||
var postNotificationsGranted = false
|
||||
var channelEnabled = false
|
||||
var exactAlarmsGranted = false
|
||||
var channelImportance = 0
|
||||
val channelId = "daily_notification_channel"
|
||||
|
||||
// Check POST_NOTIFICATIONS permission
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
postNotificationsGranted = context.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
postNotificationsGranted = NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||
}
|
||||
|
||||
// Check exact alarms permission
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
exactAlarmsGranted = alarmManager.canScheduleExactAlarms()
|
||||
} else {
|
||||
exactAlarmsGranted = true // Always available on older Android versions
|
||||
}
|
||||
|
||||
// Check channel status
|
||||
channelEnabled = NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as android.app.NotificationManager?
|
||||
val channel = notificationManager?.getNotificationChannel(channelId)
|
||||
channelImportance = channel?.importance ?: android.app.NotificationManager.IMPORTANCE_DEFAULT
|
||||
channelEnabled = channel?.importance != android.app.NotificationManager.IMPORTANCE_NONE
|
||||
}
|
||||
|
||||
val canScheduleNow = postNotificationsGranted && channelEnabled && exactAlarmsGranted
|
||||
|
||||
val result = JSObject().apply {
|
||||
put("canScheduleNow", canScheduleNow)
|
||||
put("postNotificationsGranted", postNotificationsGranted)
|
||||
put("channelEnabled", channelEnabled)
|
||||
put("exactAlarmsGranted", exactAlarmsGranted)
|
||||
put("channelImportance", channelImportance)
|
||||
put("channelId", channelId)
|
||||
if (statusChecker == null) {
|
||||
statusChecker = NotificationStatusChecker(context)
|
||||
}
|
||||
|
||||
val result = statusChecker!!.getComprehensiveStatus()
|
||||
call.resolve(result)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to check status", e)
|
||||
|
||||
Reference in New Issue
Block a user