Merge pull request #4 from cyb3rko/headers-3

Adapt custom header UI to M3
This commit is contained in:
Tobias 2025-12-15 09:48:17 +01:00 committed by GitHub
commit 1b5add7126
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 88 additions and 60 deletions

View file

@ -1,6 +1,5 @@
package io.heckel.ntfy.ui
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
@ -8,7 +7,9 @@ import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputEditText
import io.heckel.ntfy.R
import io.heckel.ntfy.db.CustomHeader
@ -54,19 +55,19 @@ class CustomHeaderFragment : DialogFragment() {
val view = requireActivity().layoutInflater.inflate(R.layout.fragment_custom_header_dialog, null)
val positiveButtonTextResId = if (header == null) R.string.custom_headers_add else R.string.custom_headers_save
val titleView = view.findViewById(R.id.custom_header_dialog_title) as TextView
val descriptionView = view.findViewById(R.id.custom_header_dialog_description) as TextView
val descriptionView: TextView = view.findViewById(R.id.custom_header_dialog_description)
baseUrlView = view.findViewById(R.id.custom_header_dialog_base_url)
headerNameView = view.findViewById(R.id.custom_header_dialog_name)
headerValueView = view.findViewById(R.id.custom_header_dialog_value)
var title: String
if (header == null) {
titleView.text = getString(R.string.custom_headers_add_title)
title = getString(R.string.custom_headers_add_title)
descriptionView.text = getString(R.string.custom_header_dialog_description_add)
baseUrlView.visibility = View.VISIBLE
} else {
titleView.text = getString(R.string.custom_headers_edit_title)
title = getString(R.string.custom_headers_edit_title)
descriptionView.text = getString(R.string.custom_header_dialog_description_edit)
baseUrlView.visibility = View.GONE
baseUrlView.setText(header!!.baseUrl)
@ -75,7 +76,8 @@ class CustomHeaderFragment : DialogFragment() {
}
// Build dialog
val builder = AlertDialog.Builder(activity)
val builder = MaterialAlertDialogBuilder(requireContext())
.setTitle(title)
.setView(view)
.setPositiveButton(positiveButtonTextResId) { _, _ ->
saveClicked()
@ -140,7 +142,7 @@ class CustomHeaderFragment : DialogFragment() {
listener.onAddCustomHeader(this, newHeader)
} else {
val newHeader = CustomHeader(
if (baseUrl.isEmpty()) header!!.baseUrl else baseUrl,
baseUrl.ifEmpty { header!!.baseUrl },
headerName,
headerValue
)

View file

@ -1,55 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:visibility="visible" android:paddingBottom="10dp">
<TextView
android:text="@string/custom_header_dialog_description_add"
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="ifContentScrolls">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/custom_header_dialog_description"
style="?android:attr/textAppearanceSmall"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/custom_header_dialog_description"
android:paddingStart="4dp" android:paddingTop="3dp" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/custom_header_dialog_title"/>
<TextView
android:id="@+id/custom_header_dialog_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="3dp"
android:text="@string/custom_headers_add_title"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:paddingStart="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
android:text="@string/custom_header_dialog_description_add"
android:textColor="?android:attr/textColorSecondary"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/custom_header_dialog_base_url"
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/custom_header_dialog_base_url_hint"
android:importantForAutofill="no"
android:maxLines="1" android:inputType="text"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="6dp" app:layout_constraintTop_toBottomOf="@id/custom_header_dialog_description"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/custom_header_dialog_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/custom_headers_name_hint"
android:importantForAutofill="no"
android:maxLines="1" android:inputType="text"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="6dp" app:layout_constraintTop_toBottomOf="@id/custom_header_dialog_base_url"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/custom_header_dialog_value"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/custom_headers_value_hint"
android:importantForAutofill="no"
android:maxLines="1" android:inputType="text"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="6dp" app:layout_constraintTop_toBottomOf="@id/custom_header_dialog_name"/>
android:layout_height="wrap_content"
android:layout_marginHorizontal="?dialogPreferredPadding"
android:paddingTop="?dialogPreferredPadding"
android:hint="@string/custom_header_dialog_base_url_hint">
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/custom_header_dialog_base_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text"
android:maxLines="1"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="?dialogPreferredPadding"
android:layout_marginTop="6dp"
android:hint="@string/custom_headers_name_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/custom_header_dialog_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text"
android:maxLines="1"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="?dialogPreferredPadding"
android:layout_marginTop="6dp"
android:hint="@string/custom_headers_value_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/custom_header_dialog_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text"
android:maxLines="1"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</ScrollView>

View file

@ -371,8 +371,8 @@
<string name="custom_headers_delete">Löschen</string>
<string name="custom_headers_error_title">Ungültiger Header</string>
<string name="custom_headers_invalid_name">Ungültige Zeichen im Header-Namen</string>
<string name="custom_headers_name_hint">Header-Name (z.B. CF-Access-Client-Id)</string>
<string name="custom_headers_value_hint">Header-Wert</string>
<string name="custom_headers_name_hint">Name (z.B. CF-Access-Client-Id)</string>
<string name="custom_headers_value_hint">Wert</string>
<string name="custom_header_dialog_description_add">Einen benutzerdefinierten HTTP-Header hinzufügen, der mit jeder Anfrage an den angegebenen Server gesendet wird.</string>
<string name="custom_header_dialog_description_edit">Den Header-Namen/Wert bearbeiten oder löschen.</string>
<string name="custom_header_dialog_base_url_hint">Service-URL</string>

View file

@ -424,8 +424,8 @@
<string name="custom_headers_delete">Delete</string>
<string name="custom_headers_error_title">Invalid Header</string>
<string name="custom_headers_invalid_name">Header name contains invalid characters</string>
<string name="custom_headers_name_hint">Header name (e.g., CF-Access-Client-Id)</string>
<string name="custom_headers_value_hint">Header value</string>
<string name="custom_headers_name_hint">Name (e.g. CF-Access-Client-Id)</string>
<string name="custom_headers_value_hint">Value</string>
<string name="custom_header_dialog_description_add">Add a custom HTTP header that will be sent with every request to the specified server.</string>
<string name="custom_header_dialog_description_edit">You may edit the header name/value for the selected header, or delete it.</string>
<string name="custom_header_dialog_base_url_hint">Service URL</string>