From c66fc0136b1504cf1f15dd9963fad3a10fcd52e9 Mon Sep 17 00:00:00 2001 From: YuutaW <17158086+Trumeet@users.noreply.github.com> Date: Fri, 1 Mar 2019 20:02:53 -0800 Subject: refactor(app): make a static instance for Storage Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com> --- .../main/java/moe/yuuta/workmode/MainActivity.kt | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'app/src/main/java/moe/yuuta/workmode/MainActivity.kt') 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> { override fun run(): List? { 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") } } -- cgit v1.2.3