Allow to resend a failed message

Add an option to the context menu of the message to resend it if it has
failed.
This commit is contained in:
Ruben Pollan 2013-10-13 12:53:41 +02:00
parent 1c8f8666ba
commit 04eafd5fab
6 changed files with 50 additions and 5 deletions

View File

@ -11,4 +11,8 @@
<item android:title="@string/conversation_context__menu_forward_message"
android:id="@+id/menu_context_forward" />
<item android:title="@string/conversation_context__menu_resend_message"
android:id="@+id/menu_context_resend"
android:visible="false" />
</menu>

View File

@ -496,6 +496,7 @@
<string name="conversation_context__menu_copy_text">Copy text</string>
<string name="conversation_context__menu_delete_message">Delete message</string>
<string name="conversation_context__menu_forward_message">Forward message</string>
<string name="conversation_context__menu_resend_message">Resend message</string>
<!-- conversation_insecure -->
<string name="conversation_insecure__menu_start_secure_session">Start Secure Session</string>

View File

@ -12,6 +12,7 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.text.ClipboardManager;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -24,6 +25,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.loaders.ConversationLoader;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.MessageSender;
import java.sql.Date;
import java.text.SimpleDateFormat;
@ -58,19 +60,23 @@ public class ConversationFragment extends SherlockListFragment
menu.clear();
inflater.inflate(R.menu.conversation_context, menu);
MessageRecord messageRecord = getMessageRecord();
if (messageRecord.isFailed()) {
MenuItem resend = menu.findItem(R.id.menu_context_resend);
resend.setVisible(true);
}
}
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
Cursor cursor = ((CursorAdapter)getListAdapter()).getCursor();
ConversationItem conversationItem = (ConversationItem)(((ConversationAdapter)getListAdapter()).newView(getActivity(), cursor, null));
MessageRecord messageRecord = conversationItem.getMessageRecord();
MessageRecord messageRecord = getMessageRecord();
switch(item.getItemId()) {
case R.id.menu_context_copy: handleCopyMessage(messageRecord); return true;
case R.id.menu_context_delete_message: handleDeleteMessage(messageRecord); return true;
case R.id.menu_context_details: handleDisplayDetails(messageRecord); return true;
case R.id.menu_context_forward: handleForwardMessage(messageRecord); return true;
case R.id.menu_context_resend: handleResendMessage(messageRecord); return true;
}
return false;
@ -82,6 +88,12 @@ public class ConversationFragment extends SherlockListFragment
this.listener = (ConversationFragmentListener)activity;
}
private MessageRecord getMessageRecord() {
Cursor cursor = ((CursorAdapter)getListAdapter()).getCursor();
ConversationItem conversationItem = (ConversationItem)(((ConversationAdapter)getListAdapter()).newView(getActivity(), cursor, null));
return conversationItem.getMessageRecord();
}
public void reload(Recipients recipients, long threadId) {
this.recipients = recipients;
this.threadId = threadId;
@ -158,6 +170,12 @@ public class ConversationFragment extends SherlockListFragment
startActivity(composeIntent);
}
private void handleResendMessage(MessageRecord message) {
long messageId = message.getId();
final Activity activity = getActivity();
MessageSender.resend(activity, messageId, message.isMms());
}
private void initializeResources() {
this.masterSecret = (MasterSecret)this.getActivity().getIntent()
.getParcelableExtra("master_secret");

View File

@ -230,6 +230,11 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
" WHERE " + ID + " = ?", new String[] {id + ""});
}
public void markAsSending(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENDING_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));
}
public void markAsSentFailed(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_FAILED_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));

View File

@ -78,7 +78,7 @@ public class MmsSender extends MmscProcessor {
Log.w("MmsSender", me);
if (messageId != -1)
database.markAsSentFailed(messageId);
}
}
} else if (intent.getAction().equals(SendReceiveService.SEND_MMS_CONNECTIVITY_ACTION)) {
handleConnectivityChange();
}

View File

@ -95,6 +95,23 @@ public class MessageSender {
return threadId;
}
public static void resend(Context context, long messageId, boolean isMms)
{
Intent intent;
if (isMms) {
DatabaseFactory.getMmsDatabase(context).markAsSending(messageId);
intent = new Intent(SendReceiveService.SEND_MMS_ACTION, null,
context, SendReceiveService.class);
} else {
DatabaseFactory.getSmsDatabase(context).markAsSending(messageId);
intent = new Intent(SendReceiveService.SEND_SMS_ACTION, null,
context, SendReceiveService.class);
}
intent.putExtra("message_id", messageId);
context.startService(intent);
}
private static void sendMms(Context context, Recipients recipients, MasterSecret masterSecret,
SendReq sendRequest, long threadId, int distributionType, boolean secure)
throws MmsException