Browse Source

Ask what to do when leaving unsent draft

Fixes #118
main
M66B 6 years ago
parent
commit
11617bc585
2 changed files with 31 additions and 13 deletions
  1. +0
    -13
      app/src/main/java/eu/faircode/email/ActivityCompose.java
  2. +31
    -0
      app/src/main/java/eu/faircode/email/FragmentCompose.java

+ 0
- 13
app/src/main/java/eu/faircode/email/ActivityCompose.java View File

@ -23,13 +23,11 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.MenuItem;
import java.util.ArrayList; import java.util.ArrayList;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
public class ActivityCompose extends ActivityBilling implements FragmentManager.OnBackStackChangedListener { public class ActivityCompose extends ActivityBilling implements FragmentManager.OnBackStackChangedListener {
static final int REQUEST_CONTACT_TO = 1; static final int REQUEST_CONTACT_TO = 1;
@ -98,17 +96,6 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager.
} }
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getSupportFragmentManager().popBackStack();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override @Override
public void onBackStackChanged() { public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0) if (getSupportFragmentManager().getBackStackEntryCount() == 0)


+ 31
- 0
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -87,6 +87,7 @@ import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.cursoradapter.widget.SimpleCursorAdapter; import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -253,6 +254,14 @@ public class FragmentCompose extends FragmentEx {
} }
}); });
((ActivityBase) getActivity()).addBackPressedListener(new ActivityBase.IBackPressedListener() {
@Override
public boolean onBackPressed() {
handleExit();
return true;
}
});
setHasOptionsMenu(true); setHasOptionsMenu(true);
// Initialize // Initialize
@ -409,6 +418,9 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home:
handleExit();
return true;
case R.id.menu_bold: case R.id.menu_bold:
case R.id.menu_italic: case R.id.menu_italic:
case R.id.menu_link: case R.id.menu_link:
@ -500,6 +512,25 @@ public class FragmentCompose extends FragmentEx {
} }
} }
private void handleExit() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new AlertDialog.Builder(getContext())
.setMessage(R.string.title_ask_delete)
.setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onAction(R.id.action_delete);
}
})
.setNegativeButton(R.string.title_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
private void handlePickContact(int requestCode, Intent data) { private void handlePickContact(int requestCode, Intent data) {
Cursor cursor = null; Cursor cursor = null;
try { try {


Loading…
Cancel
Save