diff options
author | YuutaW <17158086+Trumeet@users.noreply.github.com> | 2019-03-01 20:02:53 -0800 |
---|---|---|
committer | YuutaW <17158086+Trumeet@users.noreply.github.com> | 2019-03-01 20:02:53 -0800 |
commit | c66fc0136b1504cf1f15dd9963fad3a10fcd52e9 (patch) | |
tree | a3da820059b4d0d6f79572e146b512f8e5eb73ca /app/src/main/java/moe/yuuta/workmode/MainActivity.kt | |
parent | e6cc81e32a44dde2a73f045bd27e72bcb911fbdd (diff) | |
download | WorkMode-c66fc0136b1504cf1f15dd9963fad3a10fcd52e9.tar WorkMode-c66fc0136b1504cf1f15dd9963fad3a10fcd52e9.tar.gz WorkMode-c66fc0136b1504cf1f15dd9963fad3a10fcd52e9.tar.bz2 WorkMode-c66fc0136b1504cf1f15dd9963fad3a10fcd52e9.zip |
refactor(app): make a static instance for Storage
Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com>
Diffstat (limited to 'app/src/main/java/moe/yuuta/workmode/MainActivity.kt')
-rw-r--r-- | app/src/main/java/moe/yuuta/workmode/MainActivity.kt | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/app/src/main/java/moe/yuuta/workmode/MainActivity.kt b/app/src/main/java/moe/yuuta/workmode/MainActivity.kt index 544a6fb..72f1050 100644 --- a/app/src/main/java/moe/yuuta/workmode/MainActivity.kt +++ b/app/src/main/java/moe/yuuta/workmode/MainActivity.kt @@ -81,7 +81,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View } override fun onSwitchChanged(switchView: Switch?, isChecked: Boolean) { - SuspendedStorage(this).setStatus(if (isChecked) Status.ON else Status.OFF) + SuspendedStorage.get(this).setStatus(if (isChecked) Status.ON else Status.OFF) scheduleApply() } @@ -113,7 +113,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View if (resultCode == Activity.RESULT_OK && data != null && data.hasExtra(ApplicationPickerActivity.EXTRA_SELECTED_PACKAGE_NAME)) { val newSet = data.getStringArrayExtra(ApplicationPickerActivity.EXTRA_SELECTED_PACKAGE_NAME).toSet() logger.d("AR() $newSet") - SuspendedStorage(this).setList(newSet) + SuspendedStorage.get(this).setList(newSet) scheduleApply() } } @@ -139,11 +139,11 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View */ private fun displayUI() { switchBar.removeOnSwitchChangeListener(this) - switchBar.isChecked = SuspendedStorage(this).getStatus() == Status.ON + switchBar.isChecked = SuspendedStorage.get(this).getStatus() == Status.ON switchBar.addOnSwitchChangeListener(this) tabLayout.removeOnTabSelectedListener(mSwitchListModeListener) tabLayout.getTabAt( - when (SuspendedStorage(this).getListMode()) { + when (SuspendedStorage.get(this).getListMode()) { ListMode.BLACKLIST -> 0 ListMode.WHITELIST -> 1 } @@ -157,7 +157,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View mSortDisplayStoppable = Async.beginTask(object : Runnable<List<String>> { override fun run(): List<String>? { val sCollator = java.text.Collator.getInstance() - return SuspendedStorage(this@MainActivity).getList() + return SuspendedStorage.get(this@MainActivity).getList() .stream() .sorted { o1, o2 -> return@sorted sCollator.compare(packageManager.getApplicationLabel(packageManager.getApplicationInfo(o1, 0)).toString() @@ -184,7 +184,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View mAdapter.data = result diff.dispatchUpdatesTo(mAdapter) if (result.isEmpty()) { - welcomeTip.setText(when (SuspendedStorage(this@MainActivity).getListMode()) { + welcomeTip.setText(when (SuspendedStorage.get(this@MainActivity).getListMode()) { ListMode.BLACKLIST -> R.string.blacklist_welcome ListMode.WHITELIST -> R.string.whitelist_welcome }) @@ -232,7 +232,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View tabLayout.addOnTabSelectedListener(this) } .setPositiveButton(android.R.string.ok) { _, _ -> - SuspendedStorage(this@MainActivity).setListMode(ListMode.BLACKLIST) + SuspendedStorage.get(this@MainActivity).setListMode(ListMode.BLACKLIST) scheduleApply() } .show() @@ -248,7 +248,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View tabLayout.addOnTabSelectedListener(this) } .setPositiveButton(android.R.string.ok) { _, _ -> - SuspendedStorage(this@MainActivity).setListMode(ListMode.WHITELIST) + SuspendedStorage.get(this@MainActivity).setListMode(ListMode.WHITELIST) scheduleApply() } .show() @@ -303,7 +303,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View R.id.fab_add -> { startActivityForResult(Intent(this, ApplicationPickerActivity::class.java) .putExtra(ApplicationPickerActivity.EXTRA_SELECTED_PACKAGE_NAME, - SuspendedStorage(this).getList().toTypedArray()), RC_PICK) + SuspendedStorage.get(this).getList().toTypedArray()), RC_PICK) } } } @@ -314,7 +314,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View override fun applicationError(errorCode: Int) { logger.e("StatusException: $errorCode") - SuspendedStorage(this).reportCrack("a_e", "co: $errorCode") + SuspendedStorage.get(this).reportCrack("a_e", "co: $errorCode") } private fun proceedLicensing(reason: Int) { @@ -327,9 +327,9 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View } }") when (reason) { - Policy.LICENSED -> SuspendedStorage(this).removeCrack("g_p_l") - Policy.NOT_LICENSED -> SuspendedStorage(this).reportCrack("g_p_l", "n_p") - Policy.RETRY -> SuspendedStorage(this).reportCrack("g_p_l", "rt") + Policy.LICENSED -> SuspendedStorage.get(this).removeCrack("g_p_l") + Policy.NOT_LICENSED -> SuspendedStorage.get(this).reportCrack("g_p_l", "n_p") + Policy.RETRY -> SuspendedStorage.get(this).reportCrack("g_p_l", "rt") } } |