mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-26 15:40:59 +01:00
Use custom layout for message dialogs
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user