This commit is contained in:
Daniel Gultsch 2014-04-20 20:48:16 +02:00
parent 8003e53013
commit d140ef6390
3 changed files with 32 additions and 14 deletions

View File

@ -288,6 +288,12 @@ public class DatabaseBackend extends SQLiteOpenHelper {
String[] args = { message.getUuid() }; String[] args = { message.getUuid() };
db.delete(Message.TABLENAME, Message.UUID + "=?", args); db.delete(Message.TABLENAME, Message.UUID + "=?", args);
} }
public void deleteMessagesInConversation(Conversation conversation) {
SQLiteDatabase db = this.getWritableDatabase();
String[] args = { conversation.getUuid() };
db.delete(Message.TABLENAME, Message.CONVERSATION + "=?", args);
}
public void deleteContact(Contact contact) { public void deleteContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();

View File

@ -1035,7 +1035,12 @@ public class XmppConnectionService extends Service {
} }
public void clearConversationHistory(Conversation conversation) { public void clearConversationHistory(Conversation conversation) {
this.databaseBackend.deleteMessagesInConversation(conversation);
this.fileBackend.removeFiles(conversation);
conversation.getMessages().clear();
if (this.convChangedListener != null) {
this.convChangedListener.onConversationListChanged();
}
} }
public int getConversationCount() { public int getConversationCount() {

View File

@ -34,6 +34,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ListView; import android.widget.ListView;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.PopupMenu.OnMenuItemClickListener;
@ -297,16 +298,7 @@ public class ConversationActivity extends XmppActivity {
startActivity(new Intent(this, ContactsActivity.class)); startActivity(new Intent(this, ContactsActivity.class));
break; break;
case R.id.action_archive: case R.id.action_archive:
Conversation conv = getSelectedConversation(); this.endConversation(getSelectedConversation());
conv.setStatus(Conversation.STATUS_ARCHIVED);
paneShouldBeOpen = true;
spl.openPane();
xmppConnectionService.archiveConversation(conv);
if (conversationList.size() > 0) {
selectedConversation = conversationList.get(0);
} else {
selectedConversation = null;
}
break; break;
case R.id.action_contact_details: case R.id.action_contact_details:
Contact contact = this.getSelectedConversation().getContact(); Contact contact = this.getSelectedConversation().getContact();
@ -400,18 +392,33 @@ public class ConversationActivity extends XmppActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
protected void clearHistoryDialog(Conversation conversation) { private void endConversation(Conversation conversation) {
conversation.setStatus(Conversation.STATUS_ARCHIVED);
paneShouldBeOpen = true;
spl.openPane();
xmppConnectionService.archiveConversation(conversation);
if (conversationList.size() > 0) {
selectedConversation = conversationList.get(0);
} else {
selectedConversation = null;
}
}
protected void clearHistoryDialog(final Conversation conversation) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.clear_conversation_history)); builder.setTitle(getString(R.string.clear_conversation_history));
View dialogView = getLayoutInflater().inflate(R.layout.dialog_clear_history, null); View dialogView = getLayoutInflater().inflate(R.layout.dialog_clear_history, null);
final CheckBox endConversationCheckBox = (CheckBox) dialogView.findViewById(R.id.end_conversation_checkbox);
builder.setView(dialogView); builder.setView(dialogView);
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.delete_messages), new OnClickListener() { builder.setPositiveButton(getString(R.string.delete_messages), new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub activity.xmppConnectionService.clearConversationHistory(conversation);
if (endConversationCheckBox.isChecked()) {
endConversation(conversation);
}
} }
}); });
builder.create().show(); builder.create().show();