Bug Fixes, Added Empty item message.
This commit is contained in:
@@ -2,7 +2,6 @@ package devs.org.calculator.activities
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -34,27 +33,27 @@ class MainActivity : AppCompatActivity(), DialogActionsCallback {
|
|||||||
private lateinit var baseDocumentTreeUri: Uri
|
private lateinit var baseDocumentTreeUri: Uri
|
||||||
private val dialogUtil = DialogUtil(this)
|
private val dialogUtil = DialogUtil(this)
|
||||||
private val fileManager = FileManager(this, this)
|
private val fileManager = FileManager(this, this)
|
||||||
private lateinit var sp :SharedPreferences
|
private val sp by lazy { getSharedPreferences("app", MODE_PRIVATE) }
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
sp = getSharedPreferences("app", MODE_PRIVATE)
|
|
||||||
|
|
||||||
if (!sp.contains("isFirstTime") || sp.getBoolean("isFirstTime", true)) {
|
|
||||||
binding.display.text = getString(R.string.enter_123456)
|
|
||||||
}
|
|
||||||
launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
handleActivityResult(result)
|
handleActivityResult(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sp.getBoolean("isFirst", true)){
|
||||||
|
binding.display.text = getString(R.string.enter_123456)
|
||||||
|
}
|
||||||
|
|
||||||
// Ask permission
|
// Ask permission
|
||||||
if(!Environment.isExternalStorageManager()) {
|
if(!Environment.isExternalStorageManager()) {
|
||||||
dialogUtil.showMaterialDialog(
|
dialogUtil.showMaterialDialog(
|
||||||
"Storage Permission",
|
"Storage Permission",
|
||||||
"To ensure the app works properly and allows you to easily hide or unhide your private files, please grant storage access permission.\n" +
|
"To ensure the app works properly and allows you to easily hide or un-hide your private files, please grant storage access permission.\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"For devices running Android 11 or higher, you'll need to grant the 'All Files Access' permission.",
|
"For devices running Android 11 or higher, you'll need to grant the 'All Files Access' permission.",
|
||||||
"Grant",
|
"Grant",
|
||||||
@@ -291,6 +290,7 @@ class MainActivity : AppCompatActivity(), DialogActionsCallback {
|
|||||||
private fun calculateResult() {
|
private fun calculateResult() {
|
||||||
if (currentExpression == "123456") {
|
if (currentExpression == "123456") {
|
||||||
val intent = Intent(this, SetupPasswordActivity::class.java)
|
val intent = Intent(this, SetupPasswordActivity::class.java)
|
||||||
|
sp.edit().putBoolean("isFirst", false).apply()
|
||||||
intent.putExtra("password", currentExpression)
|
intent.putExtra("password", currentExpression)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
clearDisplay()
|
clearDisplay()
|
||||||
@@ -306,10 +306,8 @@ class MainActivity : AppCompatActivity(), DialogActionsCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Replace '×' with '*' for the expression evaluator
|
|
||||||
var processedExpression = currentExpression.replace("×", "*")
|
var processedExpression = currentExpression.replace("×", "*")
|
||||||
|
|
||||||
// Process percentages in the expression
|
|
||||||
if (processedExpression.contains("%")) {
|
if (processedExpression.contains("%")) {
|
||||||
processedExpression = preprocessExpression(processedExpression)
|
processedExpression = preprocessExpression(processedExpression)
|
||||||
}
|
}
|
||||||
@@ -336,22 +334,6 @@ class MainActivity : AppCompatActivity(), DialogActionsCallback {
|
|||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
private fun updateDisplay() {
|
private fun updateDisplay() {
|
||||||
if (!sp.contains("isFirstTime") || sp.getBoolean("isFirstTime", true)) {
|
|
||||||
if (currentExpression == "123456") {
|
|
||||||
binding.total.text = getString(R.string.now_enter_button)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
else if (currentExpression != "0" && currentExpression.isNotEmpty()) {
|
|
||||||
binding.display.text = currentExpression.replace("*", "×")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
else if (currentExpression == "0") {
|
|
||||||
binding.display.text = getString(R.string.enter_123456)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
binding.display.text = currentExpression.replace("*", "×")
|
binding.display.text = currentExpression.replace("*", "×")
|
||||||
|
|
||||||
if (currentExpression == "0") {
|
if (currentExpression == "0") {
|
||||||
@@ -360,8 +342,6 @@ class MainActivity : AppCompatActivity(), DialogActionsCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Don't show preview result if the expression ends with an operator
|
|
||||||
// (but allow percentage at the end)
|
|
||||||
if (currentExpression.isEmpty() ||
|
if (currentExpression.isEmpty() ||
|
||||||
(isOperator(currentExpression.last().toString()) && currentExpression.last() != '%')) {
|
(isOperator(currentExpression.last().toString()) && currentExpression.last() != '%')) {
|
||||||
binding.total.text = ""
|
binding.total.text = ""
|
||||||
@@ -383,8 +363,9 @@ class MainActivity : AppCompatActivity(), DialogActionsCallback {
|
|||||||
} else {
|
} else {
|
||||||
String.format("%.2f", result)
|
String.format("%.2f", result)
|
||||||
}
|
}
|
||||||
|
if (sp.getBoolean("isFirst", true) && (currentExpression == "123456" || binding.display.text.toString() == "123456")){
|
||||||
binding.total.text = formattedResult
|
binding.total.text = getString(R.string.now_enter_button)
|
||||||
|
}else binding.total.text = formattedResult
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
binding.total.text = ""
|
binding.total.text = ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user