mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
1st wired up version of multi-select + delete button (still rough on the edges)
This commit is contained in:
parent
69e7243480
commit
3525337075
48
res/layout/message_list.xml
Normal file
48
res/layout/message_list.xml
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent" >
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/message_list"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
/>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/batch_button_area"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:padding="2sp"
|
||||||
|
android:background="#CCCCCC"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/batch_read_button"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Read"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/batch_delete_button"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Delete"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/batch_flag_button"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Flag"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
</RelativeLayout>
|
@ -25,12 +25,12 @@
|
|||||||
<!-- http://stackoverflow.com/questions/1121192/android-custom-listview-unable-to-click-on-items
|
<!-- http://stackoverflow.com/questions/1121192/android-custom-listview-unable-to-click-on-items
|
||||||
we want something a bit bigger than it is right now -->
|
we want something a bit bigger than it is right now -->
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/selected_checkbox"
|
android:id="@+id/selected_checkbox"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:button="@drawable/checkbox"
|
android:button="@drawable/checkbox"
|
||||||
android:text=""
|
android:background="@drawable/checkbox_background"
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -562,5 +562,6 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
|||||||
<string name="background_ops_never">Never</string>
|
<string name="background_ops_never">Never</string>
|
||||||
<string name="background_ops_always">Always</string>
|
<string name="background_ops_always">Always</string>
|
||||||
<string name="background_ops_enabled">When \'Background data\' is checked</string>
|
<string name="background_ops_enabled">When \'Background data\' is checked</string>
|
||||||
|
|
||||||
|
<string name="no_message_seletected_toast">No message selected</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -3240,16 +3240,27 @@ public class MessagingController implements Runnable
|
|||||||
throw new RuntimeException("Error moving message", me);
|
throw new RuntimeException("Error moving message", me);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteMessageList(final Account account, final String folder, final List<Message> messageList,
|
||||||
public void deleteMessages(final Account account, final String folder, final Message[] messages,
|
final MessagingListener listener)
|
||||||
final MessagingListener listener)
|
|
||||||
{
|
{
|
||||||
for (Message message : messages)
|
for (Message message : messageList)
|
||||||
{
|
{
|
||||||
deleteMessage(account, folder, message, listener);
|
suppressMessage(account, folder, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
put("deleteMessageList", null, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for (Message message : messageList)
|
||||||
|
{
|
||||||
|
deleteMessageSynchronous(account, folder, message, listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteMessage(final Account account, final String folder, final Message message,
|
public void deleteMessage(final Account account, final String folder, final Message message,
|
||||||
final MessagingListener listener)
|
final MessagingListener listener)
|
||||||
{
|
{
|
||||||
|
@ -25,30 +25,26 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnKeyListener;
|
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.View.OnFocusChangeListener;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
|
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import com.android.email.K9ListActivity;
|
|
||||||
import com.android.email.Account;
|
import com.android.email.Account;
|
||||||
import com.android.email.Email;
|
import com.android.email.Email;
|
||||||
|
import com.android.email.K9Activity;
|
||||||
import com.android.email.MessagingController;
|
import com.android.email.MessagingController;
|
||||||
import com.android.email.MessagingListener;
|
import com.android.email.MessagingListener;
|
||||||
import com.android.email.R;
|
import com.android.email.R;
|
||||||
@ -76,7 +72,9 @@ import com.android.email.mail.store.LocalStore.LocalMessage;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MessageList extends K9ListActivity
|
public class MessageList
|
||||||
|
extends K9Activity
|
||||||
|
implements OnClickListener, AdapterView.OnItemClickListener
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final int DIALOG_MARK_ALL_AS_READ = 1;
|
private static final int DIALOG_MARK_ALL_AS_READ = 1;
|
||||||
@ -87,13 +85,12 @@ public class MessageList extends K9ListActivity
|
|||||||
|
|
||||||
private static final String EXTRA_ACCOUNT = "account";
|
private static final String EXTRA_ACCOUNT = "account";
|
||||||
private static final String EXTRA_STARTUP = "startup";
|
private static final String EXTRA_STARTUP = "startup";
|
||||||
|
private static final String EXTRA_FOLDER = "folder";
|
||||||
private static final String EXTRA_FOLDER = "folder";
|
|
||||||
private static final String STATE_KEY_LIST = "com.android.email.activity.messagelist_state";
|
private static final String STATE_KEY_LIST = "com.android.email.activity.messagelist_state";
|
||||||
|
|
||||||
private static final String STATE_CURRENT_FOLDER = "com.android.email.activity.messagelist_folder";
|
private static final String STATE_CURRENT_FOLDER = "com.android.email.activity.messagelist_folder";
|
||||||
private static final String STATE_KEY_SELECTION = "com.android.email.activity.messagelist_selection";
|
private static final String STATE_KEY_SELECTION = "com.android.email.activity.messagelist_selection";
|
||||||
|
private static final String STATE_KEY_SELECTED_COUNT = "com.android.email.activity.messagelist_selected_count";
|
||||||
|
|
||||||
private static final int WIDGET_NONE = 1;
|
private static final int WIDGET_NONE = 1;
|
||||||
private static final int WIDGET_FLAG = 2;
|
private static final int WIDGET_FLAG = 2;
|
||||||
@ -159,6 +156,13 @@ public class MessageList extends K9ListActivity
|
|||||||
|
|
||||||
private boolean mStartup = false;
|
private boolean mStartup = false;
|
||||||
|
|
||||||
|
private int mSelectedCount = 0;
|
||||||
|
|
||||||
|
private View mBatchButtonArea;
|
||||||
|
private Button mBatchReadButton;
|
||||||
|
private Button mBatchDeleteButton;
|
||||||
|
private Button mBatchFlagButton;
|
||||||
|
|
||||||
private DateFormat getDateFormat()
|
private DateFormat getDateFormat()
|
||||||
{
|
{
|
||||||
if (dateFormat == null)
|
if (dateFormat == null)
|
||||||
@ -386,7 +390,8 @@ public class MessageList extends K9ListActivity
|
|||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onListItemClick(ListView parent, View v, int position, long id)
|
@Override
|
||||||
|
public void onItemClick(AdapterView parent, View v, int position, long id)
|
||||||
{
|
{
|
||||||
if ((position+1) == (mAdapter.getCount()))
|
if ((position+1) == (mAdapter.getCount()))
|
||||||
{
|
{
|
||||||
@ -411,12 +416,15 @@ public class MessageList extends K9ListActivity
|
|||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||||
|
|
||||||
mListView = getListView();
|
setContentView(R.layout.message_list);
|
||||||
|
|
||||||
|
mListView = (ListView) findViewById(R.id.message_list);
|
||||||
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
|
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
|
||||||
mListView.setLongClickable(true);
|
mListView.setLongClickable(true);
|
||||||
mListView.setFastScrollEnabled(true);
|
mListView.setFastScrollEnabled(true);
|
||||||
mListView.setScrollingCacheEnabled(true);
|
mListView.setScrollingCacheEnabled(true);
|
||||||
|
mListView.setOnItemClickListener(this);
|
||||||
|
|
||||||
registerForContextMenu(mListView);
|
registerForContextMenu(mListView);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -427,6 +435,14 @@ public class MessageList extends K9ListActivity
|
|||||||
|
|
||||||
mInflater = getLayoutInflater();
|
mInflater = getLayoutInflater();
|
||||||
|
|
||||||
|
mBatchButtonArea = findViewById(R.id.batch_button_area);
|
||||||
|
mBatchReadButton = (Button) findViewById(R.id.batch_read_button);
|
||||||
|
mBatchReadButton.setOnClickListener(this);
|
||||||
|
mBatchDeleteButton = (Button) findViewById(R.id.batch_delete_button);
|
||||||
|
mBatchDeleteButton.setOnClickListener(this);
|
||||||
|
mBatchFlagButton = (Button) findViewById(R.id.batch_flag_button);
|
||||||
|
mBatchFlagButton.setOnClickListener(this);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
|
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
|
||||||
mStartup = (boolean)intent.getBooleanExtra(EXTRA_STARTUP, false);
|
mStartup = (boolean)intent.getBooleanExtra(EXTRA_STARTUP, false);
|
||||||
@ -446,11 +462,9 @@ public class MessageList extends K9ListActivity
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
mFolderName = savedInstanceState.getString(STATE_CURRENT_FOLDER);
|
mFolderName = savedInstanceState.getString(STATE_CURRENT_FOLDER);
|
||||||
|
mSelectedCount = savedInstanceState.getInt(STATE_KEY_SELECTED_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since the color chip is always the same color for a given account we just
|
* Since the color chip is always the same color for a given account we just
|
||||||
* cache the id of the chip right here.
|
* cache the id of the chip right here.
|
||||||
@ -469,7 +483,7 @@ public class MessageList extends K9ListActivity
|
|||||||
|
|
||||||
mCurrentFolder = mAdapter.getFolder(mFolderName);
|
mCurrentFolder = mAdapter.getFolder(mFolderName);
|
||||||
|
|
||||||
setListAdapter(mAdapter);
|
mListView.setAdapter(mAdapter);
|
||||||
|
|
||||||
if (savedInstanceState != null)
|
if (savedInstanceState != null)
|
||||||
{
|
{
|
||||||
@ -541,6 +555,7 @@ public class MessageList extends K9ListActivity
|
|||||||
outState.putParcelable(STATE_KEY_LIST, mListView.onSaveInstanceState());
|
outState.putParcelable(STATE_KEY_LIST, mListView.onSaveInstanceState());
|
||||||
outState.putInt(STATE_KEY_SELECTION, mListView .getSelectedItemPosition());
|
outState.putInt(STATE_KEY_SELECTION, mListView .getSelectedItemPosition());
|
||||||
outState.putString(STATE_CURRENT_FOLDER, mCurrentFolder.name);
|
outState.putString(STATE_CURRENT_FOLDER, mCurrentFolder.name);
|
||||||
|
outState.putInt(STATE_KEY_SELECTED_COUNT, mSelectedCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1833,9 +1848,11 @@ public class MessageList extends K9ListActivity
|
|||||||
|
|
||||||
|
|
||||||
holder.flagged.setChecked(message.flagged);
|
holder.flagged.setChecked(message.flagged);
|
||||||
|
//So that the mSelectedCount is only incremented/decremented
|
||||||
|
//when a user checks the checkbox (vs code)
|
||||||
|
holder.position = -1;
|
||||||
holder.selected.setChecked(message.selected);
|
holder.selected.setChecked(message.selected);
|
||||||
|
|
||||||
|
|
||||||
if (message.downloaded)
|
if (message.downloaded)
|
||||||
{
|
{
|
||||||
holder.chip.getBackground().setAlpha(message.read ? 0 : 127);
|
holder.chip.getBackground().setAlpha(message.read ? 0 : 127);
|
||||||
@ -1868,6 +1885,7 @@ public class MessageList extends K9ListActivity
|
|||||||
holder.from.setTypeface(null, Typeface.NORMAL);
|
holder.from.setTypeface(null, Typeface.NORMAL);
|
||||||
holder.date.setText("No date");
|
holder.date.setText("No date");
|
||||||
holder.from.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
holder.from.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||||||
|
//WARNING: Order of the next 2 lines matter
|
||||||
holder.position = -1;
|
holder.position = -1;
|
||||||
holder.selected.setChecked(false);
|
holder.selected.setChecked(false);
|
||||||
holder.flagged.setChecked(false);
|
holder.flagged.setChecked(false);
|
||||||
@ -2147,7 +2165,28 @@ public class MessageList extends K9ListActivity
|
|||||||
if (position!=-1)
|
if (position!=-1)
|
||||||
{
|
{
|
||||||
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
|
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
|
||||||
message.selected = isChecked;
|
if (message.selected!=isChecked)
|
||||||
|
{
|
||||||
|
if (isChecked)
|
||||||
|
{
|
||||||
|
mSelectedCount++;
|
||||||
|
if (mSelectedCount==1)
|
||||||
|
{
|
||||||
|
//TODO: Fade in animation
|
||||||
|
mBatchButtonArea.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSelectedCount--;
|
||||||
|
if (mSelectedCount==0)
|
||||||
|
{
|
||||||
|
//TODO: Fade out animation
|
||||||
|
mBatchButtonArea.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message.selected = isChecked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2268,4 +2307,44 @@ public class MessageList extends K9ListActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
if (v==mBatchDeleteButton)
|
||||||
|
{
|
||||||
|
List<Message> messageList = new ArrayList<Message>();
|
||||||
|
//TODO: Optimize i.e. batch all these operations
|
||||||
|
for (MessageInfoHolder holder : mAdapter.messages)
|
||||||
|
{
|
||||||
|
if (holder.selected)
|
||||||
|
{
|
||||||
|
if (holder.read == false && holder.folder.unreadMessageCount > 0)
|
||||||
|
{
|
||||||
|
holder.folder.unreadMessageCount--;
|
||||||
|
}
|
||||||
|
mAdapter.removeMessage(holder);
|
||||||
|
messageList.add(holder.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!messageList.isEmpty())
|
||||||
|
{
|
||||||
|
//We assume that all messages are in the same folder
|
||||||
|
String folderName = messageList.get(0).getFolder().getName();
|
||||||
|
MessagingController.getInstance(getApplication()).deleteMessageList(mAccount, folderName, messageList, null);
|
||||||
|
mSelectedCount = 0;
|
||||||
|
//TODO: Fade out animation
|
||||||
|
mBatchButtonArea.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Should not happen
|
||||||
|
Toast.makeText(this, R.string.no_message_seletected_toast, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Toast.makeText(this, "Not yet implemented", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user