From ee86c0c6e7b2eeeb5e0bf983c0648010b6001ef4 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 28 Aug 2018 10:19:05 +0200 Subject: [PATCH] Improved background and foreground connections --- .../ui/fragments/ConversationFragment.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java index 1b98d7b..5e897e1 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java @@ -1,7 +1,6 @@ package org.communiquons.android.comunic.client.ui.fragments; import android.app.AlertDialog; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; @@ -396,8 +395,7 @@ public class ConversationFragment extends Fragment public void onDestroy() { super.onDestroy(); - if(mDeleteMessageAsyncTask != null) - mDeleteMessageAsyncTask.setOnPostExecuteListener(null); + unsetPendingDeleteTasksCallback(); } @Override @@ -433,6 +431,10 @@ public class ConversationFragment extends Fragment @Override public void onLoadError() { + + if(getActivity() == null) + return; + //Display a toast Toast.makeText(getActivity(), R.string.fragment_conversation_err_load_message, Toast.LENGTH_SHORT).show(); @@ -814,6 +816,8 @@ public class ConversationFragment extends Fragment * @param pos The position of the message to delete */ private void deleteConversationMessage(final int pos){ + unsetPendingDeleteTasksCallback(); + mDeleteMessageAsyncTask = new DeleteConversationMessageTask(getActivity()); mDeleteMessageAsyncTask.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener() { @Override @@ -827,6 +831,14 @@ public class ConversationFragment extends Fragment messagesList.get(pos).getId()); } + /** + * Unset any conversation message delete pending tasks + */ + private void unsetPendingDeleteTasksCallback(){ + if(mDeleteMessageAsyncTask != null) + mDeleteMessageAsyncTask.setOnPostExecuteListener(null); + } + /** * Delete conversation message callback *