diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-22 12:04:10 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-22 12:04:10 +0200 |
| commit | 48b44a6e27b87ee8bf5340a8d7ff37afaf04b7f9 (patch) | |
| tree | 1eb779b880a78bda3af7bed4eb93a43dafd288bc /app/src/main/java/mygram/droid/SettingsActivity.java | |
| parent | a605449390de7737e718e6d10574e5581cf757e3 (diff) | |
| download | mygram-droid-48b44a6e27b87ee8bf5340a8d7ff37afaf04b7f9.tar.gz mygram-droid-48b44a6e27b87ee8bf5340a8d7ff37afaf04b7f9.zip | |
Optional app PIN, settings header, pink selection ring
- A PIN (4 to 8 digits, salted SHA-256 in prefs) set in Settings shows
a logo splash with a PIN prompt at start and whenever the app returns
after leaving the screen; Back there leaves the app.
- Settings gets the back-arrow header shared with the folder grid
(Ui.header) and scrolls, since the PIN fields overflow the screen.
- Tile and list focus rings use the icon pink.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'app/src/main/java/mygram/droid/SettingsActivity.java')
| -rw-r--r-- | app/src/main/java/mygram/droid/SettingsActivity.java | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/app/src/main/java/mygram/droid/SettingsActivity.java b/app/src/main/java/mygram/droid/SettingsActivity.java index a8839bb..3783058 100644 --- a/app/src/main/java/mygram/droid/SettingsActivity.java +++ b/app/src/main/java/mygram/droid/SettingsActivity.java @@ -18,12 +18,16 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.InputType; +import android.view.ViewGroup; import android.widget.EditText; import android.widget.LinearLayout; +import android.widget.ScrollView; import android.widget.Toast; -/** Viewer password, photo and background durations, change instance. */ +/** Viewer password, durations, app PIN, change instance. */ public final class SettingsActivity extends Activity { + private static final int PIN_INPUT = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; + @Override protected void onCreate(Bundle state) { super.onCreate(state); @@ -41,23 +45,58 @@ public final class SettingsActivity extends Activity { EditText bg = Ui.field(this, "15", InputType.TYPE_CLASS_NUMBER); bg.setText(String.valueOf(Prefs.backgroundSeconds())); box.addView(bg); + box.addView(Ui.text(this, Prefs.hasPin() ? "New app PIN, 4 to 8 digits (empty keeps it)" + : "App PIN, 4 to 8 digits (empty for none)", 14)); + EditText pin = Ui.field(this, "PIN", PIN_INPUT); + box.addView(pin); + EditText again = Ui.field(this, "Repeat PIN", PIN_INPUT); + box.addView(again); LinearLayout row = Ui.row(this); row.addView(Ui.iconButton(this, R.drawable.ic_check, "Save", v -> save(pw.getText().toString(), - photo.getText().toString(), bg.getText().toString()))); + photo.getText().toString(), bg.getText().toString(), pin.getText().toString(), + again.getText().toString()))); + if (Prefs.hasPin()) + row.addView(Ui.iconButton(this, R.drawable.ic_lock_open, "Remove PIN", v -> { + Prefs.setPin(null); + Toast.makeText(this, "PIN removed", Toast.LENGTH_SHORT).show(); + finish(); + })); row.addView(Ui.iconButton(this, R.drawable.ic_swap, "Change instance", v -> startActivity(new Intent(this, SetupActivity.class)))); box.addView(row); - setContentView(box); + + // Taller than the screen with the PIN fields; the scroll view follows focus. + ScrollView scroll = new ScrollView(this); + scroll.addView(box); + LinearLayout column = new LinearLayout(this); + column.setOrientation(LinearLayout.VERTICAL); + column.addView(Ui.header(this, "Settings")); + column.addView(scroll, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1)); + setContentView(column); row.getChildAt(0).requestFocus(); } - private void save(String password, String photo, String background) { + private void save(String password, String photo, String background, String pin, String again) { int p = seconds(photo), b = seconds(background); if (p < 1 || b < 1) { - Toast.makeText(this, "Durations must be 1 to 600 seconds", Toast.LENGTH_LONG).show(); + toast("Durations must be 1 to 600 seconds"); return; } + if (!pin.isEmpty() || !again.isEmpty()) { + if (!Prefs.validPin(pin)) { + toast("The PIN must be 4 to 8 digits"); + return; + } + if (!pin.equals(again)) { + toast("The two PINs differ"); + return; + } + } Prefs.setTimes(p, b); + if (!pin.isEmpty()) { + Prefs.setPin(pin); + App.locked = false; // just typed it; ask from the next time the app leaves the screen + } if (password.equals(Prefs.password())) { finish(); return; @@ -68,7 +107,11 @@ public final class SettingsActivity extends Activity { }, ok -> { Prefs.setPassword(password); finish(); - }, e -> Toast.makeText(this, "Login failed: " + e.getMessage(), Toast.LENGTH_LONG).show()); + }, e -> toast("Login failed: " + e.getMessage())); + } + + private void toast(String s) { + Toast.makeText(this, s, Toast.LENGTH_LONG).show(); } private static int seconds(String s) { |
