/* * mygram-droid: Android TV client for Foldergram. * Copyright (C) 2026 Danilo M. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package mygram.droid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.InputType; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Toast; /** Viewer password, photo and background durations, change instance. */ public final class SettingsActivity extends Activity { @Override protected void onCreate(Bundle state) { super.onCreate(state); LinearLayout box = Ui.column(this); box.addView(Ui.text(this, Prefs.server(), 18)); box.addView(Ui.text(this, "Viewer password", 14)); EditText pw = Ui.field(this, "Password", Ui.password()); pw.setText(Prefs.password()); box.addView(pw); box.addView(Ui.text(this, "Photo duration, seconds", 14)); EditText photo = Ui.field(this, "8", InputType.TYPE_CLASS_NUMBER); photo.setText(String.valueOf(Prefs.photoSeconds())); box.addView(photo); box.addView(Ui.text(this, "Background change, seconds", 14)); EditText bg = Ui.field(this, "15", InputType.TYPE_CLASS_NUMBER); bg.setText(String.valueOf(Prefs.backgroundSeconds())); box.addView(bg); 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()))); row.addView(Ui.iconButton(this, R.drawable.ic_swap, "Change instance", v -> startActivity(new Intent(this, SetupActivity.class)))); box.addView(row); setContentView(box); row.getChildAt(0).requestFocus(); } private void save(String password, String photo, String background) { 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(); return; } Prefs.setTimes(p, b); if (password.equals(Prefs.password())) { finish(); return; } Api.async(() -> { Api.login(Prefs.server(), password); return true; }, ok -> { Prefs.setPassword(password); finish(); }, e -> Toast.makeText(this, "Login failed: " + e.getMessage(), Toast.LENGTH_LONG).show()); } private static int seconds(String s) { try { int v = Integer.parseInt(s.trim()); return v <= 600 ? v : -1; } catch (NumberFormatException e) { return -1; } } }