Verified Commit 4d5c92f4 authored by Francisco Cunha's avatar Francisco Cunha Committed by Hussein

P4A-930 - Make MessageLoaderHelper call callbacks on the main thread

K9 cherry pick 721c97fe39a923f7c0cbf28b261d2a76b41792fe
parent 5a272587
......@@ -5,6 +5,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
......@@ -89,6 +91,7 @@ public class MessageLoaderHelper {
private OpenPgpDecryptionResult cachedDecryptionResult;
private MessageCryptoHelper messageCryptoHelper;
private Handler handler = new Handler(Looper.getMainLooper());
public MessageLoaderHelper(Context context, LoaderManager loaderManager, FragmentManager fragmentManager,
......@@ -441,20 +444,21 @@ public class MessageLoaderHelper {
MessagingListener downloadMessageListener = new SimpleMessagingListener() {
@Override
public void loadMessageRemoteFinished(Account account, String folder, String uid) {
if (!messageReference.equals(account.getUuid(), folder, uid)) {
return;
}
onMessageDownloadFinished();
public void loadMessageRemoteFinished(final Account account, final String folder, final String uid) {
handler.post(() -> {
if (!messageReference.equals(account.getUuid(), folder, uid)) {
return;
}
onMessageDownloadFinished();
});
}
@Override
public void loadMessageRemoteFailed(Account account, String folder, String uid, final Throwable t) {
onDownloadMessageFailed(t);
handler.post(() -> onDownloadMessageFailed(t));
}
};
// callback interface
public interface MessageLoaderCallbacks {
......
......@@ -895,14 +895,20 @@ public class MessageViewFragment extends PEpFragment implements ConfirmationDial
@Override
public void onDownloadErrorMessageNotFound() {
mMessageView.enableDownloadButton();
getActivity().runOnUiThread(() -> FeedbackTools.showLongFeedback(getView(), getString(R.string.status_invalid_id_error)));
runOnMainThread(() -> {
mMessageView.enableDownloadButton();
FeedbackTools.showLongFeedback(getView(), getString(R.string.status_invalid_id_error));
}
);
}
@Override
public void onDownloadErrorNetworkError() {
mMessageView.enableDownloadButton();
getActivity().runOnUiThread(() -> FeedbackTools.showLongFeedback(getView(), getString(R.string.status_network_error)));
runOnMainThread(() -> {
mMessageView.enableDownloadButton();
FeedbackTools.showLongFeedback(getView(), getString(R.string.status_network_error));
}
);
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment