From ff2e24dbabe050489dfd080b8331c91478810643 Mon Sep 17 00:00:00 2001 From: Darkempire <50015928+Darkempire78@users.noreply.github.com> Date: Fri, 28 Jul 2023 17:13:34 +0200 Subject: [PATCH] add an option to disable history? #294 --- .../opencalculator/MainActivity.kt | 27 +++++++++++++++++-- app/src/main/res/values/arrays.xml | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/darkempire78/opencalculator/MainActivity.kt b/app/src/main/java/com/darkempire78/opencalculator/MainActivity.kt index a30cbea3..fed0a8b8 100644 --- a/app/src/main/java/com/darkempire78/opencalculator/MainActivity.kt +++ b/app/src/main/java/com/darkempire78/opencalculator/MainActivity.kt @@ -111,6 +111,18 @@ class MainActivity : AppCompatActivity() { binding.historyRecylcleView.scrollToPosition(historyAdapter.itemCount - 1) } + // Disable history if setting enabled + val historySize = MyPreferences(this).historySize!!.toInt() + if (historySize == 0) { + binding.historyRecylcleView.visibility = View.GONE + binding.slidingLayoutButton.visibility = View.GONE + binding.slidingLayout.isEnabled = false + } else { + binding.historyRecylcleView.visibility = View.VISIBLE + binding.slidingLayoutButton.visibility = View.VISIBLE + binding.slidingLayout.isEnabled = true + } + binding.slidingLayout.addPanelSlideListener(object : PanelSlideListener { override fun onPanelSlide(panel: View, slideOffset: Float) { if (slideOffset == 0f) { // If the panel got collapsed @@ -865,7 +877,7 @@ class MainActivity : AppCompatActivity() { // Remove former results if > historySize preference val historySize = MyPreferences(this@MainActivity).historySize!!.toInt() - while (historySize > 0 && historyAdapter.itemCount >= historySize) { + while (historySize != -1 && historyAdapter.itemCount >= historySize && historyAdapter.itemCount > 0) { historyAdapter.removeFirstHistoryElement() } @@ -1049,7 +1061,7 @@ class MainActivity : AppCompatActivity() { // Remove former results if > historySize preference // Remove from the RecycleView val historySize = MyPreferences(this@MainActivity).historySize!!.toInt() - while (historySize > 0 && historyAdapter.itemCount >= historySize) { + while (historySize != -1 && historyAdapter.itemCount >= historySize && historyAdapter.itemCount > 0) { historyAdapter.removeFirstHistoryElement() } // Remove from the preference store data @@ -1059,6 +1071,17 @@ class MainActivity : AppCompatActivity() { } MyPreferences(this@MainActivity).saveHistory(this@MainActivity, history) + // Disable history if setting enabled + if (historySize == 0) { + binding.historyRecylcleView.visibility = View.GONE + binding.slidingLayoutButton.visibility = View.GONE + binding.slidingLayout.isEnabled = false + } else { + binding.historyRecylcleView.visibility = View.VISIBLE + binding.slidingLayoutButton.visibility = View.VISIBLE + binding.slidingLayout.isEnabled = true + } + // Disable the keyboard on display EditText binding.input.showSoftInputOnFocus = false } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 85d33adc..e8c2b47b 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1,6 +1,7 @@ + 0 10 20 50 @@ -12,6 +13,7 @@ + 0 10 20 50