UI opgesplitst: hoofdscherm (status+acties) en apart instellingenscherm (SettingsActivity)

This commit is contained in:
eddy 2026-10-14 20:16:32 +02:00
commit 29691e1425
5 changed files with 107 additions and 75 deletions

View file

@ -37,6 +37,10 @@
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:exported="false" />
<!-- Afgaande wekker: toont bovenop het vergrendelscherm, zonder in de recente apps -->
<activity
android:name=".AlarmActivity"

View file

@ -1,12 +1,10 @@
package nl.eddydevink.buschauffeurswekker
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
@ -21,6 +19,7 @@ import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
/** Hoofdscherm: status + acties. Instellingen staan in [SettingsActivity]. */
class MainActivity : AppCompatActivity() {
private lateinit var prefs: Prefs
@ -35,14 +34,16 @@ class MainActivity : AppCompatActivity() {
findViewById<MaterialButton>(R.id.btn_check).setOnClickListener { runCheck() }
findViewById<MaterialButton>(R.id.btn_test).setOnClickListener {
AlarmScheduler.scheduleTest(this)
Toast.makeText(this, "Testwekker gaat over 10 seconden af", Toast.LENGTH_SHORT).show()
toast("Testwekker gaat over 10 seconden af")
}
findViewById<MaterialButton>(R.id.btn_settings).setOnClickListener {
startActivity(Intent(this, SettingsActivity::class.java))
}
findViewById<MaterialButton>(R.id.btn_save).setOnClickListener { saveSettings() }
// Staat altijd zichtbaar in de status-edit: pionnen van de volgende controle alvast zetten.
AlarmScheduler.scheduleNoonCheck(this)
// Config via launch-intent (installatie/hulp): adb shell am start ... --es url "..." --es user "..." --es pass "..."
// Config via launch-intent (installatiehulp):
// adb shell am start ... --es url "..." --es user "..." --es pass "..."
handleSetupIntent(intent)
}
@ -61,7 +62,6 @@ class MainActivity : AppCompatActivity() {
if (!url.isNullOrBlank()) prefs.calendarUrl = url.trim()
if (!user.isNullOrBlank()) prefs.username = user.trim()
if (pass != null) prefs.password = pass
renderSettings()
lifecycleScope.launch {
val r = ShiftCheck.run(this@MainActivity)
renderStatus()
@ -72,7 +72,6 @@ class MainActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
renderStatus()
renderSettings()
}
private fun renderStatus() {
@ -94,21 +93,7 @@ class MainActivity : AppCompatActivity() {
}
}
private fun renderSettings() {
findViewById<EditText>(R.id.et_url).setText(prefs.calendarUrl.orEmpty())
findViewById<EditText>(R.id.et_user).setText(prefs.username.orEmpty())
findViewById<EditText>(R.id.et_pass).setText(prefs.password.orEmpty())
}
private fun saveSettings() {
prefs.calendarUrl = findViewById<EditText>(R.id.et_url).text.toString().trim()
prefs.username = findViewById<EditText>(R.id.et_user).text.toString().trim()
prefs.password = findViewById<EditText>(R.id.et_pass).text.toString()
toast("Instellingen opgeslagen")
}
private fun runCheck() {
saveSettings()
val btn = findViewById<MaterialButton>(R.id.btn_check)
btn.isEnabled = false
btn.text = "Bezig…"

View file

@ -0,0 +1,30 @@
package nl.eddydevink.buschauffeurswekker
import android.os.Bundle
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.button.MaterialButton
import nl.eddydevink.buschauffeurswekker.core.Prefs
/** Apart instellingenscherm: CalDAV-gegevens (URL, gebruiker, app-wachtwoord). */
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
val prefs = Prefs(this)
findViewById<EditText>(R.id.et_url).setText(prefs.calendarUrl.orEmpty())
findViewById<EditText>(R.id.et_user).setText(prefs.username.orEmpty())
findViewById<EditText>(R.id.et_pass).setText(prefs.password.orEmpty())
findViewById<MaterialButton>(R.id.btn_save).setOnClickListener {
prefs.calendarUrl = findViewById<EditText>(R.id.et_url).text.toString().trim()
prefs.username = findViewById<EditText>(R.id.et_user).text.toString().trim()
prefs.password = findViewById<EditText>(R.id.et_pass).text.toString()
Toast.makeText(this, "Instellingen opgeslagen", Toast.LENGTH_SHORT).show()
finish()
}
}
}

View file

@ -31,64 +31,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Testwekker (over 10 seconden)" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="8dp"
android:background="?android:attr/listDivider" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Instellingen (CalDAV)"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<EditText
android:id="@+id/et_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="Agenda-URL (bv. https://nextcloud.eddydevink.nl/remote.php/dav/calendars/eddy/ebs_diensten-1/)"
android:inputType="textUri" />
<EditText
android:id="@+id/et_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gebruikersnaam (Nextcloud)"
android:inputType="text" />
<EditText
android:id="@+id/et_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="App-wachtwoord (Nextcloud → Beveiliging → App-wachtwoorden)"
android:inputType="textPassword" />
android:text="Wekker testen (over 10 seconden)" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_save"
android:id="@+id/btn_settings"
style="@style/Widget.Material3.Button.TonalButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Opslaan" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="8dp"
android:background="?android:attr/listDivider" />
<TextView
android:id="@+id/tv_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="Elke dag om 12:00 leest de app de agenda van morgen (EBS-Diensten via CalDAV). De dienstbegintijd wordt naar beneden afgerond op een heel kwartier (05:00–05:14 → 05:00, 05:15–05:29 → 05:15, 05:30–05:44 → 05:30, 05:45–05:59 → 05:45) en er worden drie wekkers gezet: Opstaan 2 uur, Wally 1,5 uur en Vertrek 0,5 uur vóór aanvang. Geen dienst → geen wekkers. Meldingen vraagt het systeem bij de eerste start." />
android:text="Instellingen" />
</LinearLayout>
</ScrollView>

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Instellingen (CalDAV)"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<EditText
android:id="@+id/et_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="Agenda-URL (bv. https://nextcloud.eddydevink.nl/remote.php/dav/calendars/eddy/ebs_diensten-1/)"
android:inputType="textUri" />
<EditText
android:id="@+id/et_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gebruikersnaam (Nextcloud)"
android:inputType="text" />
<EditText
android:id="@+id/et_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="App-wachtwoord (Nextcloud → Beveiliging → App-wachtwoorden)"
android:inputType="textPassword" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_save"
style="@style/Widget.Material3.Button.TonalButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Opslaan" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="8dp"
android:background="?android:attr/listDivider" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="Elke dag om 12:00 leest de app de agenda van morgen. De dienstbegintijd wordt naar beneden afgerond op een heel kwartier (05:00–05:14 → 05:00, 05:15–05:29 → 05:15, 05:30–05:44 → 05:30, 05:45–05:59 → 05:45) en er worden drie wekkers gezet: Opstaan 2 uur, Wally 1,5 uur en Vertrek 0,5 uur vóór aanvang. Geen dienst → geen wekkers. Meldingen vraagt het systeem bij de eerste start." />
</LinearLayout>
</ScrollView>