Use custom layout for message dialogs

pull/147/head
M66B 6 years ago
parent 44d7ffc54a
commit 37360c4046

@ -20,7 +20,11 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
@ -30,6 +34,7 @@ import androidx.lifecycle.OnLifecycleEvent;
public class DialogBuilderLifecycle extends AlertDialog.Builder implements LifecycleObserver {
private LifecycleOwner owner;
private AlertDialog dialog;
private boolean hasMessage = false;
public DialogBuilderLifecycle(Context context, LifecycleOwner owner) {
super(context);
@ -41,6 +46,35 @@ public class DialogBuilderLifecycle extends AlertDialog.Builder implements Lifec
this.owner = owner;
}
@Override
public AlertDialog.Builder setTitle(int titleId) {
if (hasMessage)
throw new IllegalArgumentException("Custom message set");
return super.setTitle(titleId);
}
@Override
public AlertDialog.Builder setTitle(@Nullable CharSequence title) {
if (hasMessage)
throw new IllegalArgumentException("Custom message set");
return super.setTitle(title);
}
@Override
public AlertDialog.Builder setMessage(int messageId) {
return setMessage(getContext().getString(messageId));
}
@Override
public AlertDialog.Builder setMessage(@Nullable CharSequence message) {
hasMessage = true;
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_message, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
tvMessage.setText(message);
setView(dview);
return this;
}
@Override
public AlertDialog create() {
dialog = super.create();

@ -9,7 +9,7 @@
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_open_link"
android:text="Message"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

@ -0,0 +1,16 @@
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp">
<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save