Skip to content

Commit

Permalink
add an option to disable history? #294
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkempire78 committed Jul 28, 2023
1 parent 4cfd40b commit ff2e24d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/src/main/java/com/darkempire78/opencalculator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<!-- Reply Preference -->
<string-array name="history_size_entries">
<item>0</item>
<item>10</item>
<item>20</item>
<item>50</item>
Expand All @@ -12,6 +13,7 @@
</string-array>

<string-array name="history_size_values">
<item>0</item>
<item>10</item>
<item>20</item>
<item>50</item>
Expand Down

0 comments on commit ff2e24d

Please sign in to comment.