Add 'up' button to message composition screen

This commit is contained in:
Sergei Novikov 2017-02-28 17:33:31 +03:00 committed by cketti
parent 05df114eb1
commit b811bd6048

View file

@ -9,6 +9,7 @@ import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.app.Dialog; import android.app.Dialog;
@ -92,6 +93,7 @@ import com.fsck.k9.message.PgpMessageBuilder;
import com.fsck.k9.message.QuotedTextMode; import com.fsck.k9.message.QuotedTextMode;
import com.fsck.k9.message.SimpleMessageBuilder; import com.fsck.k9.message.SimpleMessageBuilder;
import com.fsck.k9.message.SimpleMessageFormat; import com.fsck.k9.message.SimpleMessageFormat;
import com.fsck.k9.search.LocalSearch;
import com.fsck.k9.ui.EolConvertingEditText; import com.fsck.k9.ui.EolConvertingEditText;
import com.fsck.k9.ui.compose.QuotedMessageMvpView; import com.fsck.k9.ui.compose.QuotedMessageMvpView;
import com.fsck.k9.ui.compose.QuotedMessagePresenter; import com.fsck.k9.ui.compose.QuotedMessagePresenter;
@ -207,6 +209,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private boolean isInSubActivity = false; private boolean isInSubActivity = false;
private boolean navigateUp;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -232,6 +236,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
setContentView(R.layout.message_compose); setContentView(R.layout.message_compose);
} }
initializeActionBar();
// on api level 15, setContentView() shows the progress bar for some reason... // on api level 15, setContentView() shows the progress bar for some reason...
setProgressBarIndeterminateVisibility(false); setProgressBarIndeterminateVisibility(false);
@ -734,7 +740,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
} }
internalMessageHandler.sendEmptyMessage(MSG_DISCARDED_DRAFT); internalMessageHandler.sendEmptyMessage(MSG_DISCARDED_DRAFT);
changesMadeSinceLastSave = false; changesMadeSinceLastSave = false;
finish(); if (navigateUp) {
openAutoExpandFolder();
} else {
finish();
}
} }
private void onReadReceipt() { private void onReadReceipt() {
@ -920,6 +930,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home:
prepareToFinish(true);
break;
case R.id.send: case R.id.send:
checkToSendMessage(); checkToSendMessage();
break; break;
@ -987,6 +1000,12 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override @Override
public void onBackPressed() { public void onBackPressed() {
prepareToFinish(false);
}
private void prepareToFinish(boolean shouldNavigateUp) {
navigateUp = shouldNavigateUp;
if (changesMadeSinceLastSave && draftIsNotEmpty()) { if (changesMadeSinceLastSave && draftIsNotEmpty()) {
if (!account.hasDraftsFolder()) { if (!account.hasDraftsFolder()) {
showDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); showDialog(DIALOG_CONFIRM_DISCARD_ON_BACK);
@ -998,11 +1017,24 @@ public class MessageCompose extends K9Activity implements OnClickListener,
if (draftId == INVALID_DRAFT_ID) { if (draftId == INVALID_DRAFT_ID) {
onDiscard(); onDiscard();
} else { } else {
super.onBackPressed(); if (navigateUp) {
openAutoExpandFolder();
} else {
super.onBackPressed();
}
} }
} }
} }
private void openAutoExpandFolder() {
String folder = account.getAutoExpandFolderName();
LocalSearch search = new LocalSearch(folder);
search.addAccountUuid(account.getUuid());
search.addAllowedFolder(folder);
MessageList.actionDisplaySearch(this, search, false, true);
finish();
}
private boolean draftIsNotEmpty() { private boolean draftIsNotEmpty() {
if (messageContentView.getText().length() != 0) { if (messageContentView.getText().length() != 0) {
return true; return true;
@ -1578,6 +1610,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
} }
}; };
private void initializeActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
// TODO We miss callbacks for this listener if they happens while we are paused! // TODO We miss callbacks for this listener if they happens while we are paused!
public MessagingListener messagingListener = new SimpleMessagingListener() { public MessagingListener messagingListener = new SimpleMessagingListener() {