UI opgesplitst: hoofdscherm (status+acties) en apart instellingenscherm (SettingsActivity)
This commit is contained in:
parent
23eae6e428
commit
29691e1425
5 changed files with 107 additions and 75 deletions
|
|
@ -37,6 +37,10 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".SettingsActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<!-- Afgaande wekker: toont bovenop het vergrendelscherm, zonder in de recente apps -->
|
<!-- Afgaande wekker: toont bovenop het vergrendelscherm, zonder in de recente apps -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".AlarmActivity"
|
android:name=".AlarmActivity"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
package nl.eddydevink.buschauffeurswekker
|
package nl.eddydevink.buschauffeurswekker
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
|
@ -21,6 +19,7 @@ import java.time.Instant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
/** Hoofdscherm: status + acties. Instellingen staan in [SettingsActivity]. */
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var prefs: Prefs
|
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_check).setOnClickListener { runCheck() }
|
||||||
findViewById<MaterialButton>(R.id.btn_test).setOnClickListener {
|
findViewById<MaterialButton>(R.id.btn_test).setOnClickListener {
|
||||||
AlarmScheduler.scheduleTest(this)
|
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)
|
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)
|
handleSetupIntent(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +62,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
if (!url.isNullOrBlank()) prefs.calendarUrl = url.trim()
|
if (!url.isNullOrBlank()) prefs.calendarUrl = url.trim()
|
||||||
if (!user.isNullOrBlank()) prefs.username = user.trim()
|
if (!user.isNullOrBlank()) prefs.username = user.trim()
|
||||||
if (pass != null) prefs.password = pass
|
if (pass != null) prefs.password = pass
|
||||||
renderSettings()
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val r = ShiftCheck.run(this@MainActivity)
|
val r = ShiftCheck.run(this@MainActivity)
|
||||||
renderStatus()
|
renderStatus()
|
||||||
|
|
@ -72,7 +72,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
renderStatus()
|
renderStatus()
|
||||||
renderSettings()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderStatus() {
|
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() {
|
private fun runCheck() {
|
||||||
saveSettings()
|
|
||||||
val btn = findViewById<MaterialButton>(R.id.btn_check)
|
val btn = findViewById<MaterialButton>(R.id.btn_check)
|
||||||
btn.isEnabled = false
|
btn.isEnabled = false
|
||||||
btn.text = "Bezig…"
|
btn.text = "Bezig…"
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -31,64 +31,14 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:text="Testwekker (over 10 seconden)" />
|
android:text="Wekker testen (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" />
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btn_save"
|
android:id="@+id/btn_settings"
|
||||||
style="@style/Widget.Material3.Button.TonalButton"
|
style="@style/Widget.Material3.Button.TonalButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:text="Opslaan" />
|
android:text="Instellingen" />
|
||||||
|
|
||||||
<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." />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
63
app/src/main/res/layout/activity_settings.xml
Normal file
63
app/src/main/res/layout/activity_settings.xml
Normal 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>
|
||||||
Loading…
Reference in a new issue