Email deletion
This commit is contained in:
2
TODO
2
TODO
@@ -1,5 +1,5 @@
|
||||
- Email selection
|
||||
-- Deleting emails
|
||||
-- Show which have been selected (background? image?)
|
||||
-- Mark as read
|
||||
- Send button action
|
||||
- Deleting identities
|
||||
|
||||
BIN
res/drawable-hdpi/ic_content_discard.png
Normal file
BIN
res/drawable-hdpi/ic_content_discard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
res/drawable-mdpi/ic_content_discard.png
Normal file
BIN
res/drawable-mdpi/ic_content_discard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
res/drawable-xhdpi/ic_content_discard.png
Normal file
BIN
res/drawable-xhdpi/ic_content_discard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -2,7 +2,7 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/activated_background" >
|
||||
android:background="@drawable/folder_activated_background" >
|
||||
<TextView
|
||||
android:id="@+id/folder_name"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
11
res/menu/email_list_context.xml
Normal file
11
res/menu/email_list_context.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete_emails"
|
||||
android:icon="@drawable/ic_content_discard"
|
||||
android:title="@string/action_delete_emails"
|
||||
i2pandroid:showAsAction="ifRoom"/>
|
||||
|
||||
</menu>
|
||||
@@ -6,6 +6,9 @@
|
||||
<string name="action_send_email">Send email</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
|
||||
<string name="items_selected">%s selected</string>
|
||||
<string name="action_delete_emails">Delete selected emails</string>
|
||||
|
||||
<string name="drawer_open">Open nav</string>
|
||||
<string name="drawer_close">Close nav</string>
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import i2p.bote.util.BoteHelper;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -22,10 +23,12 @@ import android.widget.TextView;
|
||||
|
||||
public class EmailListAdapter extends ArrayAdapter<Email> {
|
||||
private final LayoutInflater mInflater;
|
||||
private SparseBooleanArray mSelectedEmails;
|
||||
|
||||
public EmailListAdapter(Context context) {
|
||||
super(context, android.R.layout.simple_list_item_2);
|
||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mSelectedEmails = new SparseBooleanArray();
|
||||
}
|
||||
|
||||
public void setData(List<Email> emails) {
|
||||
@@ -78,4 +81,29 @@ public class EmailListAdapter extends ArrayAdapter<Email> {
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public void toggleSelection(int position) {
|
||||
selectView(position, !mSelectedEmails.get(position));
|
||||
}
|
||||
|
||||
public void removeSelection() {
|
||||
mSelectedEmails = new SparseBooleanArray();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void selectView(int position, boolean value) {
|
||||
if (value)
|
||||
mSelectedEmails.put(position, value);
|
||||
else
|
||||
mSelectedEmails.delete(position);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public int getSelectedCount() {
|
||||
return mSelectedEmails.size();
|
||||
}
|
||||
|
||||
public SparseBooleanArray getSelectedIds() {
|
||||
return mSelectedEmails;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,16 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
@@ -44,6 +48,7 @@ public class EmailListFragment extends ListFragment implements
|
||||
|
||||
private EmailListAdapter mAdapter;
|
||||
private EmailFolder mFolder;
|
||||
private ActionMode mMode;
|
||||
|
||||
private EditText mPasswordInput;
|
||||
private TextView mPasswordError;
|
||||
@@ -90,6 +95,17 @@ public class EmailListFragment extends ListFragment implements
|
||||
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
// Set up CAB
|
||||
mMode = null;
|
||||
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
onListItemSelect(position);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (mFolder == null) {
|
||||
setEmptyText(getResources().getString(
|
||||
R.string.folder_does_not_exist));
|
||||
@@ -216,8 +232,73 @@ public class EmailListFragment extends ListFragment implements
|
||||
@Override
|
||||
public void onListItemClick(ListView parent, View view, int pos, long id) {
|
||||
super.onListItemClick(parent, view, pos, id);
|
||||
mCallback.onEmailSelected(
|
||||
mFolder.getName(), mAdapter.getItem(pos).getMessageID());
|
||||
if (mMode == null) {
|
||||
mCallback.onEmailSelected(
|
||||
mFolder.getName(), mAdapter.getItem(pos).getMessageID());
|
||||
} else
|
||||
onListItemSelect(pos);
|
||||
}
|
||||
|
||||
private void onListItemSelect(int position) {
|
||||
mAdapter.toggleSelection(position);
|
||||
boolean hasCheckedElement = mAdapter.getSelectedCount() > 0;
|
||||
|
||||
if (hasCheckedElement && mMode == null) {
|
||||
mMode = ((ActionBarActivity) getActivity()).startSupportActionMode(new ModeCallback());
|
||||
} else if (!hasCheckedElement && mMode != null) {
|
||||
mMode.finish();
|
||||
}
|
||||
|
||||
if (mMode != null)
|
||||
mMode.setTitle(getResources().getString(
|
||||
R.string.items_selected, mAdapter.getSelectedCount()));
|
||||
}
|
||||
|
||||
private final class ModeCallback implements ActionMode.Callback {
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
// Respond to clicks on the actions in the CAB
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_delete_emails:
|
||||
SparseBooleanArray selected = mAdapter.getSelectedIds();
|
||||
for (int i = (selected.size() - 1); i >= 0; i--) {
|
||||
if (selected.valueAt(i)) {
|
||||
Email email = mAdapter.getItem(selected.keyAt(i));
|
||||
// The Loader will update mAdapter
|
||||
I2PBote.getInstance().deleteEmail(mFolder, email.getMessageID());
|
||||
}
|
||||
}
|
||||
mode.finish();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
// Inflate the menu for the CAB
|
||||
MenuInflater inflater = mode.getMenuInflater();
|
||||
inflater.inflate(R.menu.email_list_context, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
// Here you can make any necessary updates to the activity when
|
||||
// the CAB is removed.
|
||||
mAdapter.removeSelection();
|
||||
|
||||
if (mode == mMode)
|
||||
mMode = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
// Here you can perform updates to the CAB due to
|
||||
// an invalidate() request
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// LoaderManager.LoaderCallbacks<List<Email>>
|
||||
|
||||
Reference in New Issue
Block a user