Prevent crash

This commit is contained in:
M66B 2019-12-29 17:10:25 +01:00
parent 567681c08f
commit b478bebf58
3 changed files with 13 additions and 8 deletions

View File

@ -1288,7 +1288,7 @@ public class FragmentCompose extends FragmentBase {
@Override
protected void onExecuted(final Bundle args, EntityIdentity identity) {
Helper.selectKeyAlias(getActivity(), identity.sign_key_alias, new Helper.IKeyAlias() {
Helper.selectKeyAlias(getActivity(), getViewLifecycleOwner(), identity.sign_key_alias, new Helper.IKeyAlias() {
@Override
public void onSelected(String alias) {
args.putString("alias", alias);

View File

@ -4062,7 +4062,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (auto && identity == null)
return;
Helper.selectKeyAlias(getActivity(), identity == null ? null : identity.sign_key_alias, new Helper.IKeyAlias() {
String alias = (identity == null ? null : identity.sign_key_alias);
Helper.selectKeyAlias(getActivity(), getViewLifecycleOwner(), alias, new Helper.IKeyAlias() {
@Override
public void onSelected(String alias) {
args.putString("alias", alias);

View File

@ -80,6 +80,8 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;
@ -845,7 +847,7 @@ public class Helper {
prefs.edit().remove("last_authentication").apply();
}
static void selectKeyAlias(final Activity activity, final String email, final IKeyAlias intf) {
static void selectKeyAlias(final Activity activity, final LifecycleOwner owner, final String email, final IKeyAlias intf) {
final Context context = activity.getApplicationContext();
final Handler handler = new Handler();
@ -859,7 +861,8 @@ public class Helper {
handler.post(new Runnable() {
@Override
public void run() {
intf.onSelected(email);
if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
intf.onSelected(email);
}
});
return;
@ -880,10 +883,11 @@ public class Helper {
handler.post(new Runnable() {
@Override
public void run() {
if (alias == null)
intf.onNothingSelected();
else
intf.onSelected(alias);
if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
if (alias == null)
intf.onNothingSelected();
else
intf.onSelected(alias);
}
});
}