From ba58a426ac15c0051ea164fffd26fbb3a360f8ba Mon Sep 17 00:00:00 2001 From: BrianBlade Date: Fri, 3 Apr 2015 00:06:37 +0200 Subject: Enable end-conversation by swipe gesture Add EnhancedListView library de.timroes.android:EnhancedListView:0.3.4 to enable swipe-out for ListViews --- build.gradle | 1 + .../conversations/ui/ConversationActivity.java | 70 +++++++++-- .../fragment_conversations_overview.xml | 2 +- src/main/res/layout/conversation_list_row.xml | 132 +++++++++++---------- .../res/layout/fragment_conversations_overview.xml | 2 +- src/main/res/values-de/strings.xml | 1 + src/main/res/values/strings.xml | 2 + 7 files changed, 139 insertions(+), 71 deletions(-) diff --git a/build.gradle b/build.gradle index 8f7bb914..cdbb5a98 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,7 @@ dependencies { compile 'com.google.zxing:core:3.1.0' compile 'com.google.zxing:android-integration:3.1.0' compile 'de.measite.minidns:minidns:0.1.3' + compile 'de.timroes.android:EnhancedListView:0.3.4' } android { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 82afda07..364e2ce4 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -22,12 +22,12 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; -import android.widget.ListView; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.Toast; import net.java.otr4j.session.SessionStatus; +import de.timroes.android.listview.EnhancedListView; import java.util.ArrayList; import java.util.List; @@ -77,7 +77,7 @@ public class ConversationActivity extends XmppActivity private List conversationList = new ArrayList<>(); private Conversation mSelectedConversation = null; - private ListView listView; + private EnhancedListView listView; private ConversationFragment mConversationFragment; private ArrayAdapter listAdapter; @@ -156,7 +156,7 @@ public class ConversationActivity extends XmppActivity transaction.replace(R.id.selected_conversation, this.mConversationFragment, "conversation"); transaction.commit(); - listView = (ListView) findViewById(R.id.list); + listView = (EnhancedListView) findViewById(R.id.list); this.listAdapter = new ConversationAdapter(this, conversationList); listView.setAdapter(this.listAdapter); @@ -178,6 +178,49 @@ public class ConversationActivity extends XmppActivity openConversation(); } }); + + listView.setDismissCallback(new EnhancedListView.OnDismissCallback() { + + @Override + public EnhancedListView.Undoable onDismiss(EnhancedListView enhancedListView, final int position) { + final Conversation item = listAdapter.getItem(position); + listAdapter.remove(item); + listAdapter.notifyDataSetChanged(); + + if (position == 0 && listAdapter.getCount() == 0) { + endConversation(item, false, true); + return null; + } + else if (getSelectedConversation() == item) { + setSelectedConversation(listAdapter.getItem(0)); + endConversation(item, false, true); + } + + return new EnhancedListView.Undoable() { + @Override + public void undo() { + listAdapter.insert(item, position); + listAdapter.notifyDataSetChanged(); + } + + @Override + public void discard() { + endConversation(item, false, false); + } + + @Override + public String getTitle() { + return getResources().getString(R.string.title_undo_swipe_out_conversation); + } + }; + } + }); + listView.enableSwipeToDismiss(); + listView.setSwipingLayout(R.id.swipeable_item); + listView.setUndoStyle(EnhancedListView.UndoStyle.SINGLE_POPUP); + listView.setUndoHideDelay(3000); + listView.setRequireTouchBeforeDismiss(false); + mContentView = findViewById(R.id.content_view_spl); if (mContentView == null) { mContentView = findViewById(R.id.content_view_ll); @@ -485,13 +528,21 @@ public class ConversationActivity extends XmppActivity } public void endConversation(Conversation conversation) { - showConversationsOverview(); + endConversation(conversation, true, true); + } + + public void endConversation(Conversation conversation, boolean showOverview, boolean reinit) { + if (showOverview) { + showConversationsOverview(); + } xmppConnectionService.archiveConversation(conversation); - if (conversationList.size() > 0) { - setSelectedConversation(conversationList.get(0)); - this.mConversationFragment.reInit(getSelectedConversation()); - } else { - setSelectedConversation(null); + if (reinit) { + if (conversationList.size() > 0) { + setSelectedConversation(conversationList.get(0)); + this.mConversationFragment.reInit(getSelectedConversation()); + } else { + setSelectedConversation(null); + } } } @@ -744,6 +795,7 @@ public class ConversationActivity extends XmppActivity @Override public void onPause() { + listView.discardUndo(); super.onPause(); this.mActivityPaused = true; if (this.xmppConnectionServiceBound) { diff --git a/src/main/res/layout-w960dp/fragment_conversations_overview.xml b/src/main/res/layout-w960dp/fragment_conversations_overview.xml index 2744f38e..50039c03 100644 --- a/src/main/res/layout-w960dp/fragment_conversations_overview.xml +++ b/src/main/res/layout-w960dp/fragment_conversations_overview.xml @@ -12,7 +12,7 @@ android:background="@color/primarybackground" android:orientation="vertical" > - + - + - + - + - + - + - - + - - + - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/fragment_conversations_overview.xml b/src/main/res/layout/fragment_conversations_overview.xml index 69570028..24c653ae 100644 --- a/src/main/res/layout/fragment_conversations_overview.xml +++ b/src/main/res/layout/fragment_conversations_overview.xml @@ -10,7 +10,7 @@ android:background="@color/primarybackground" android:orientation="vertical" > - Keine App für die Standort-Anzeige gefunden Standort Standort empfangen + Unterhaltung beendet %d Kontakt ausgewählt %d Kontakte ausgewählt diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index af56c014..4cd7415a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -296,6 +296,7 @@ \n\nhttps://developer.android.com/tools/support-library\n(Apache License, Version 2.0) \n\nhttps://github.com/zxing/zxing\n(Apache License, Version 2.0) \n\nhttps://github.com/google/material-design-icons\n(CC BY 4.0) + \n\nhttps://github.com/timroes/EnhancedListView\n(Apache License, Version 2.0) Quiet Hours Start time @@ -454,6 +455,7 @@ No application found to display location Location Received location + Conversation closed Select %d contact Select %d contacts -- cgit v1.2.3