Skip to content

Commit

Permalink
Convert preference stuff to getters
Browse files Browse the repository at this point in the history
  • Loading branch information
TacoTheDank committed Nov 24, 2021
1 parent 60343b0 commit 0c02c31
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/taco/scoop/core/receiver/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BootReceiver : BroadcastReceiver() {
if (intent?.action != Intent.ACTION_BOOT_COMPLETED)
return

if (PreferenceHelper.autostartOnBoot()) {
if (PreferenceHelper.autostartOnBoot) {
context.initScoopService()

Log.d("Scoop", "Started application on boot")
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/taco/scoop/core/receiver/CrashReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CrashReceiver : BroadcastReceiver() {
return

description = intent.getStringExtra(Intents.INTENT_DESCRIPTION)!!
if (description!!.startsWith(ThreadDeath::class.java.name) && ignoreThreadDeath())
if (description!!.startsWith(ThreadDeath::class.java.name) && ignoreThreadDeath)
return

packageName = intent.getStringExtra(Intents.INTENT_PACKAGE_NAME)
Expand All @@ -52,7 +52,7 @@ class CrashReceiver : BroadcastReceiver() {
crash = intent.getParcelableExtra("crash")
}

if (!showNotifications() or blacklistList.contains(packageName)) {
if (!showNotifications or blacklistList.contains(packageName)) {
return
}

Expand Down Expand Up @@ -80,7 +80,7 @@ class CrashReceiver : BroadcastReceiver() {
}

val notificationId = (time - bootTime).toInt()
if (showActionButtons()) {
if (showActionButtons) {
builder.addActionButtons(context, notificationId)
}

Expand All @@ -100,7 +100,7 @@ class CrashReceiver : BroadcastReceiver() {
}

private fun NotificationCompat.Builder.setNotificationStyle(): NotificationCompat.Builder {
return if (showStackTraceNotifications()) {
return if (showStackTraceNotifications) {
val style = NotificationCompat.InboxStyle()
val traces = stackTrace!!.split("\n".toRegex()).toTypedArray()
var i = 0
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/taco/scoop/ui/activity/DetailActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DetailActivity : AppCompatActivity(), SearchView.OnQueryTextListener,
TypedValue.COMPLEX_UNIT_PX, binding.detailCrashLogText.textSize
)

binding.detailScrollView.setCropHorizontally(PreferenceHelper.autoWrap())
binding.detailScrollView.setCropHorizontally(PreferenceHelper.autoWrap)
}

private fun highlightText(text: String?) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/taco/scoop/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

mCombineApps = PreferenceHelper.combineSameApps()
mCombineApps = PreferenceHelper.combineSameApps
mAdapter!!.setCombineSameApps(!mHasCrash && mCombineApps)
binding.mainCrashView.setReverseOrder(mHasCrash || !mCombineApps)

Expand Down Expand Up @@ -128,7 +128,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
super.onResume()
// Cheap way to instantly apply changes
mAdapter!!.setSearchPackageName(
this, PreferenceHelper.searchPackageName()
this, PreferenceHelper.searchPackageName
)
sVisible = true
mHandler!!.post(mUpdateCheckerRunnable)
Expand Down Expand Up @@ -157,7 +157,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
}

private fun updateLocale() {
if (PreferenceHelper.forceEnglish()) {
if (PreferenceHelper.forceEnglish) {
// TODO: Use ConfigurationCompat
val config = resources.configuration
config.locale = Locale.ENGLISH
Expand Down Expand Up @@ -198,8 +198,8 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
updateViewStates(true)
mLoader.loadData(
this,
PreferenceHelper.combineSameStackTrace(),
PreferenceHelper.combineSameApps(),
PreferenceHelper.combineSameStackTrace,
PreferenceHelper.combineSameApps,
PreferenceHelper.blacklistList
)
}
Expand Down
57 changes: 23 additions & 34 deletions app/src/main/java/taco/scoop/util/PreferenceHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,43 @@ object PreferenceHelper {
return sharedPreferences.getBoolean(getKey(key), defValue)
}

fun showNotifications(): Boolean {
return getSharedBoolean(R.string.prefKey_show_notification, true)
}
val showNotifications: Boolean
get() = getSharedBoolean(R.string.prefKey_show_notification, true)

fun showActionButtons(): Boolean {
return getSharedBoolean(R.string.prefKey_show_action_buttons, true)
}
val showActionButtons: Boolean
get() = getSharedBoolean(R.string.prefKey_show_action_buttons, true)

fun showStackTraceNotifications(): Boolean {
return getSharedBoolean(R.string.prefKey_show_stack_trace_notif, false)
}
val showStackTraceNotifications: Boolean
get() = getSharedBoolean(R.string.prefKey_show_stack_trace_notif, false)

fun combineSameApps(): Boolean {
return getSharedBoolean(R.string.prefKey_combine_same_apps, false)
}
val combineSameApps: Boolean
get() = getSharedBoolean(R.string.prefKey_combine_same_apps, false)

fun combineSameStackTrace(): Boolean {
return getSharedBoolean(R.string.prefKey_combine_same_stack_trace, true)
}
val combineSameStackTrace: Boolean
get() = getSharedBoolean(R.string.prefKey_combine_same_stack_trace, true)

fun searchPackageName(): Boolean {
return getSharedBoolean(R.string.prefKey_search_package_name, true)
}
val searchPackageName: Boolean
get() = getSharedBoolean(R.string.prefKey_search_package_name, true)

fun autoWrap(): Boolean {
return getSharedBoolean(R.string.prefKey_auto_wrap, false)
}
val autoWrap: Boolean
get() = getSharedBoolean(R.string.prefKey_auto_wrap, false)

fun autostartOnBoot(): Boolean {
return getSharedBoolean(R.string.prefKey_autostart_on_boot, false)
}
val autostartOnBoot: Boolean
get() = getSharedBoolean(R.string.prefKey_autostart_on_boot, false)

fun ignoreThreadDeath(): Boolean {
return getSharedBoolean(R.string.prefKey_ignore_threaddeath, true)
}
val ignoreThreadDeath: Boolean
get() = getSharedBoolean(R.string.prefKey_ignore_threaddeath, true)

fun forceEnglish(): Boolean {
return getSharedBoolean(R.string.prefKey_force_english, false)
}
val forceEnglish: Boolean
get() = getSharedBoolean(R.string.prefKey_force_english, false)

private fun getBlacklistedPackages(): String? {
return sharedPreferences.getString(
private val blacklistedPackages: String?
get() = sharedPreferences.getString(
getKey(R.string.key_blacklisted_packages), ""
)
}

val blacklistList: List<String>
get() = listOf(*getBlacklistedPackages()?.split(",".toRegex())!!.toTypedArray())
get() = listOf(*blacklistedPackages?.split(",".toRegex())!!.toTypedArray())

fun editBlacklistPackages(packages: ArrayList<String>) {
sharedPreferences.edit {
Expand Down

0 comments on commit 0c02c31

Please sign in to comment.