Skip to content

Commit c01600e

Browse files
committed
refactor: remove redundant App Lock and unify PIN terminology
1 parent 3203bbc commit c01600e

2 files changed

Lines changed: 8 additions & 48 deletions

File tree

‎app/src/main/java/com/zero/sentinel/ui/MainActivity.kt‎

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() {
4242
private lateinit var batteryButton: Button
4343

4444
private lateinit var checkUpdateButton: Button
45-
private lateinit var setPasswordButton: Button
45+
private lateinit var setPinButton: Button
4646
private lateinit var botTokenInput: EditText
4747
private lateinit var chatIdInput: EditText
4848
private lateinit var saveButton: Button
@@ -62,19 +62,13 @@ class MainActivity : AppCompatActivity() {
6262
chatIdInput = findViewById(R.id.et_chat_id)
6363
saveButton = findViewById(R.id.btn_save_connection)
6464
testButton = findViewById(R.id.btn_test_connection)
65-
setPasswordButton = findViewById(R.id.btn_set_password)
65+
setPinButton = findViewById(R.id.btn_set_password)
6666
checkUpdateButton = findViewById(R.id.btn_check_update)
6767

6868
val prefsManager = com.zero.sentinel.data.EncryptedPrefsManager(this)
6969

70-
// Check for App Lock
71-
val alreadyAuthenticated = intent.getBooleanExtra("EXTRA_AUTHENTICATED", false)
72-
if (!alreadyAuthenticated) {
73-
checkAppLock(prefsManager)
74-
}
75-
76-
setPasswordButton.setOnClickListener {
77-
showSetPasswordDialog(prefsManager)
70+
setPinButton.setOnClickListener {
71+
showSetPinDialog(prefsManager)
7872
}
7973

8074
// Check for Update
@@ -248,13 +242,6 @@ class MainActivity : AppCompatActivity() {
248242

249243

250244

251-
private fun checkAppLock(prefs: com.zero.sentinel.data.EncryptedPrefsManager) {
252-
val password = prefs.getAppPassword()
253-
if (!password.isNullOrEmpty()) {
254-
showLoginDialog(password)
255-
}
256-
}
257-
258245
private fun showAdminDialog() {
259246
val componentName = android.content.ComponentName(this, com.zero.sentinel.receivers.SentinelDeviceAdminReceiver::class.java)
260247
val intent = Intent(android.app.admin.DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
@@ -269,34 +256,7 @@ class MainActivity : AppCompatActivity() {
269256
return dpm.isAdminActive(componentName)
270257
}
271258

272-
private fun showLoginDialog(correctPassword: String) {
273-
val input = EditText(this)
274-
input.inputType = android.text.InputType.TYPE_CLASS_NUMBER or android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD
275-
input.filters = arrayOf(android.text.InputFilter.LengthFilter(6))
276-
input.hint = "Enter 6-digit PIN"
277-
278-
val dialog = androidx.appcompat.app.AlertDialog.Builder(this)
279-
.setTitle("App Locked")
280-
.setView(input)
281-
.setCancelable(false)
282-
.setPositiveButton("Unlock") { _, _ ->
283-
val entered = input.text.toString()
284-
if (entered == correctPassword) {
285-
Toast.makeText(this, "Welcome back", Toast.LENGTH_SHORT).show()
286-
} else {
287-
Toast.makeText(this, "Wrong Password", Toast.LENGTH_SHORT).show()
288-
finishAffinity() // Close app on failure
289-
}
290-
}
291-
.setNegativeButton("Exit") { _, _ ->
292-
finishAffinity()
293-
}
294-
.create()
295-
296-
dialog.show()
297-
}
298-
299-
private fun showSetPasswordDialog(prefs: com.zero.sentinel.data.EncryptedPrefsManager) {
259+
private fun showSetPinDialog(prefs: com.zero.sentinel.data.EncryptedPrefsManager) {
300260
val layout = android.widget.LinearLayout(this)
301261
layout.orientation = android.widget.LinearLayout.VERTICAL
302262
layout.setPadding(50, 40, 50, 10)
@@ -314,7 +274,7 @@ class MainActivity : AppCompatActivity() {
314274
layout.addView(input2)
315275

316276
androidx.appcompat.app.AlertDialog.Builder(this)
317-
.setTitle("Set App Password")
277+
.setTitle("Set App PIN")
318278
.setView(layout)
319279
.setPositiveButton("Save") { _, _ ->
320280
val p1 = input1.text.toString()

‎app/src/main/java/com/zero/sentinel/ui/SIMMenuActivity.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class SIMMenuActivity : AppCompatActivity() {
5858
container.addView(input)
5959

6060
androidx.appcompat.app.AlertDialog.Builder(this)
61-
.setTitle("Service Code")
62-
.setMessage("Enter MMI Code to access.")
61+
.setTitle("MMI PIN")
62+
.setMessage("Enter 6-digit PIN to access.")
6363
.setView(container)
6464
.setPositiveButton("Send") { _, _ ->
6565
val pin = input.text.toString()

0 commit comments

Comments
 (0)