mirror of https://github.com/M66B/FairEmail.git
parent
cebd727209
commit
86822f4e79
|
@ -1816,7 +1816,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
|
||||
tvMessage.setText(context.getText(R.string.title_ask_show_image));
|
||||
|
||||
new DialogBuilderLifecycle(context, owner)
|
||||
final Dialog dialog = new AlertDialog.Builder(context)
|
||||
.setView(dview)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -1827,7 +1827,19 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
.create();
|
||||
|
||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
||||
public void onCreate() {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroyed() {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onShowImagesConfirmed(final TupleMessageEx message) {
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
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;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
public class DialogBuilderLifecycle extends AlertDialog.Builder implements LifecycleObserver {
|
||||
private LifecycleOwner owner;
|
||||
private AlertDialog dialog;
|
||||
private CharSequence title = null;
|
||||
private CharSequence message = null;
|
||||
|
||||
public DialogBuilderLifecycle(Context context, LifecycleOwner owner) {
|
||||
super(context);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public DialogBuilderLifecycle(Context context, int themeResId, LifecycleOwner owner) {
|
||||
super(context, themeResId);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog.Builder setTitle(int titleId) {
|
||||
return setTitle(getContext().getString(titleId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog.Builder setTitle(@Nullable CharSequence title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog.Builder setMessage(int messageId) {
|
||||
return setMessage(getContext().getString(messageId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog.Builder setMessage(@Nullable CharSequence message) {
|
||||
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;
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroy() {
|
||||
dialog.dismiss();
|
||||
owner = null;
|
||||
dialog = null;
|
||||
title = null;
|
||||
message = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue