Skip to content

Commit

Permalink
fixed first run not starting monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
robinsrk committed Dec 8, 2024
1 parent 413be19 commit ddfa03f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions app/src/main/java/dev/robin/flip_2_dnd/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
Expand Down Expand Up @@ -66,17 +67,29 @@ class MainActivity : ComponentActivity() {
}

private fun checkAndStartService() {
if (!isNotificationPolicyAccessGranted()) {
requestNotificationPolicyAccess()
return
}

if (!isBatteryOptimizationDisabled()) {
requestDisableBatteryOptimization()
return
}
val notificationPolicyGranted = isNotificationPolicyAccessGranted()
val batteryOptimizationDisabled = isBatteryOptimizationDisabled()

// Always start the service
startFlipDetectorService()

// If permissions are not granted, show a warning
if (!notificationPolicyGranted || !batteryOptimizationDisabled) {
// Optional: Add a toast or dialog to inform user about missing permissions
Toast.makeText(
this,
"Please grant all permissions for full functionality",
Toast.LENGTH_LONG
).show()

if (!notificationPolicyGranted) {
requestNotificationPolicyAccess()
}

if (!batteryOptimizationDisabled) {
requestDisableBatteryOptimization()
}
}
}

private fun isNotificationPolicyAccessGranted(): Boolean {
Expand Down

0 comments on commit ddfa03f

Please sign in to comment.