Skip to content

Commit

Permalink
feat: recheck switches after requesting a permission
Browse files Browse the repository at this point in the history
  • Loading branch information
ViscousPot committed Oct 14, 2024
1 parent e2b4d2b commit 0fffe0a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/com/viscouspot/gitsync/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class MainActivity : AppCompatActivity() {
private var requestLegacyStoragePermission: ActivityResultLauncher<Array<String>>? = null
private var requestStoragePermission: ActivityResultLauncher<Intent>? = null

private var requestedPermission = false

companion object {
const val REFRESH = "REFRESH"
}
Expand Down Expand Up @@ -182,6 +184,16 @@ class MainActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()

if (requestedPermission) {
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
settingsManager.setSyncMessageEnabled(true)
}
if (checkAccessibilityPermission()) {
settingsManager.setApplicationObserverEnabled(true)
}
requestedPermission = false
}

refreshAll()
}

Expand Down Expand Up @@ -643,6 +655,7 @@ class MainActivity : AppCompatActivity() {
val openSettings = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
openSettings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_HISTORY)
startActivity(openSettings)
requestedPermission = true
Toast.makeText(this, getString(R.string.enable_accessibility_service), Toast.LENGTH_SHORT).show()
}

Expand All @@ -655,6 +668,7 @@ class MainActivity : AppCompatActivity() {
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)

requestedPermission = true
requestNotificationPermission.launch(intent)
}
}

0 comments on commit 0fffe0a

Please sign in to comment.