Skip to content

Commit

Permalink
Add setting for Scoop's system notification settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TacoTheDank committed Jun 23, 2021
1 parent 86a3c7c commit 835a6b5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/taco/scoop/ui/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import taco.scoop.R
import taco.scoop.databinding.ActivitySettingsBinding
import taco.scoop.util.openSystemNotificationSettings
import taco.scoop.util.readLogsPermissionGranted

class SettingsActivity : AppCompatActivity() {
Expand Down Expand Up @@ -38,6 +39,12 @@ class SettingsActivity : AppCompatActivity() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences)

val notifSettingsPref = findPreference<Preference>("pref_notif_sys_settings")
notifSettingsPref?.setOnPreferenceClickListener {
requireContext().openSystemNotificationSettings()
true
}

val blacklistedAppsPref = findPreference<Preference>("pref_blacklisted_apps")
blacklistedAppsPref?.setActivityIntent(BlacklistAppsActivity::class.java)

Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/taco/scoop/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import android.Manifest
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Build
import android.provider.Settings
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -99,3 +102,21 @@ fun runReadLogsGrantShell() {
"pm grant ${BuildConfig.APPLICATION_ID} $readLogsPermission"
).exec()
}

fun Context.openSystemNotificationSettings() {
try {
Intent().apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
action = "android.settings.APP_NOTIFICATION_SETTINGS"
putExtra("app_package", packageName)
putExtra("app_uid", applicationInfo.uid)
}
}.also(this::startActivity)
} catch (e: Exception) {
e.printStackTrace()
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<string name="settings_misc">Verschiedenes</string>

<!-- Settings (notifications) -->
<string name="settings_system_notifications">Notification settings</string>
<string name="settings_system_notifications_summary">Manage app notifications on the system level</string>
<string name="settings_show_notif">Benachrichtigung bei Crash zeigen</string>
<string name="settings_action_buttons">Schnellaktionen zeigen</string>
<string name="settings_action_buttons_summary">Fügt Buttons zum Kopieren und Teilen des Crashes zur Benachrichtigung hinzu</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<string name="settings_misc">Variado</string>

<!-- Settings (notifications) -->
<string name="settings_system_notifications">Notification settings</string>
<string name="settings_system_notifications_summary">Manage app notifications on the system level</string>
<string name="settings_show_notif">Mostrar notificação ao travar</string>
<string name="settings_action_buttons">Mostrar botões de ações</string>
<string name="settings_action_buttons_summary">Adicionar botões para copiar e compartilhar o travamento na notificação</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<string name="settings_misc">Miscellaneous</string>

<!-- Settings (notifications) -->
<string name="settings_system_notifications">Notification settings</string>
<string name="settings_system_notifications_summary">Manage app notifications on the system level</string>
<string name="settings_show_notif">Show notification on crash</string>
<string name="settings_action_buttons">Show action buttons</string>
<string name="settings_action_buttons_summary">Add buttons to copy and share the crash to the notification</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
android:title="@string/settings_notif"
app:iconSpaceReserved="false">

<Preference
android:key="pref_notif_sys_settings"
android:summary="@string/settings_system_notifications_summary"
android:title="@string/settings_system_notifications"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="true"
android:key="show_notification"
Expand Down

0 comments on commit 835a6b5

Please sign in to comment.