mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 07:23:03 +00:00
Refactoring
This commit is contained in:
parent
1b5156dfc5
commit
683e95b75b
1 changed files with 19 additions and 12 deletions
|
@ -34,7 +34,8 @@ import androidx.lifecycle.OnLifecycleEvent;
|
|||
public class DialogBuilderLifecycle extends AlertDialog.Builder implements LifecycleObserver {
|
||||
private LifecycleOwner owner;
|
||||
private AlertDialog dialog;
|
||||
private boolean hasMessage = false;
|
||||
private CharSequence title = null;
|
||||
private CharSequence message = null;
|
||||
|
||||
public DialogBuilderLifecycle(Context context, LifecycleOwner owner) {
|
||||
super(context);
|
||||
|
@ -48,16 +49,13 @@ public class DialogBuilderLifecycle extends AlertDialog.Builder implements Lifec
|
|||
|
||||
@Override
|
||||
public AlertDialog.Builder setTitle(int titleId) {
|
||||
if (hasMessage)
|
||||
throw new IllegalArgumentException("Custom message set");
|
||||
return super.setTitle(titleId);
|
||||
return setTitle(getContext().getString(titleId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog.Builder setTitle(@Nullable CharSequence title) {
|
||||
if (hasMessage)
|
||||
throw new IllegalArgumentException("Custom message set");
|
||||
return super.setTitle(title);
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,16 +65,23 @@ public class DialogBuilderLifecycle extends AlertDialog.Builder implements Lifec
|
|||
|
||||
@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);
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog create() {
|
||||
if (title == null && message != null) {
|
||||
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_message, null);
|
||||
TextView tvMessage = dview.findViewById(R.id.tvMessage);
|
||||
tvMessage.setText(message);
|
||||
setView(dview);
|
||||
} else {
|
||||
if (title != null)
|
||||
super.setTitle(title);
|
||||
if (message != null)
|
||||
super.setMessage(message);
|
||||
}
|
||||
dialog = super.create();
|
||||
owner.getLifecycle().addObserver(this);
|
||||
return dialog;
|
||||
|
@ -87,5 +92,7 @@ public class DialogBuilderLifecycle extends AlertDialog.Builder implements Lifec
|
|||
dialog.dismiss();
|
||||
owner = null;
|
||||
dialog = null;
|
||||
title = null;
|
||||
message = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue