-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement configurable auto lock delay duration
- Loading branch information
1 parent
e63fa88
commit 0def953
Showing
6 changed files
with
106 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/java/alt/nainapps/aer/config/autolock/AutoLockDelayMinutesTextListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2024 nain | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
*/ | ||
|
||
package alt.nainapps.aer.config.autolock | ||
|
||
import alt.nainapps.aer.R | ||
import alt.nainapps.aer.lock.LockStore | ||
import android.content.Context | ||
import android.text.Editable | ||
import android.text.TextWatcher | ||
import android.widget.EditText | ||
|
||
fun interface AutoLockDelayMinutesTextListener : TextWatcher { | ||
|
||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { | ||
} | ||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { | ||
} | ||
override fun afterTextChanged(s: Editable) { | ||
afterTextChanged(s.toString()) | ||
} | ||
// this will be provided as lambda | ||
fun afterTextChanged(text: String) | ||
} | ||
|
||
fun buildValidatedAutoLockDelayListener(context: Context, lockstore: LockStore, input: EditText): AutoLockDelayMinutesTextListener { | ||
return AutoLockDelayMinutesTextListener { text -> | ||
// validate text isNumber | ||
try { | ||
text.toLong() | ||
} catch (error: NumberFormatException) { | ||
input.setError("NaN: Not a Number", | ||
context.getDrawable(R.drawable.ic_error)) | ||
return@AutoLockDelayMinutesTextListener | ||
} | ||
val minutes: Long = text.toLong() | ||
// validate not zero | ||
if (minutes == 0L) { | ||
input.setError("Auto lock delay can't be zero", | ||
context.getDrawable(R.drawable.ic_error)) | ||
} | ||
lockstore.autoLockDelayMinutes = minutes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters