aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java38
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java3
2 files changed, 31 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
index a212ef78a..e79be5c4a 100644
--- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
@@ -19,6 +19,7 @@ import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.ListView;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -40,7 +41,7 @@ import rocks.xmpp.addr.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
private List<String> mActivatedAccounts = new ArrayList<>();
- private Set<Contact> selected;
+ private Set<String> selected = new HashSet<>();
private Set<String> filterContacts;
private PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
@@ -70,6 +71,13 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
filterContacts = new HashSet<>();
+ if (savedInstanceState != null) {
+ String[] selectedContacts = savedInstanceState.getStringArray("selected_contacts");
+ if (selectedContacts != null) {
+ selected.clear();
+ selected.addAll(Arrays.asList(selectedContacts));
+ }
+ }
String[] contacts = getIntent().getStringArrayExtra("filter_contacts");
if (contacts != null) {
Collections.addAll(filterContacts, contacts);
@@ -86,16 +94,24 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+ binding.fab.setVisibility(View.GONE);
+ final View view = getSearchEditText();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
+ if (view != null && imm != null) {
+ imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
+ }
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.select_multiple, menu);
- selected = new HashSet<>();
+ MenuItem selectButton = menu.findItem(R.id.selection_submit);
+ String buttonText = getResources().getQuantityString(R.plurals.select_contact, selected.size(), selected.size());
+ selectButton.setTitle(buttonText);
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
+ binding.fab.setVisibility(View.VISIBLE);
+ selected.clear();
}
@Override
@@ -122,9 +138,9 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
Contact item = (Contact) getListItems().get(position);
if (checked) {
- selected.add(item);
+ selected.add(item.getJid().toString());
} else {
- selected.remove(item);
+ selected.remove(item.getJid().toString());
}
int numSelected = selected.size();
MenuItem selectButton = mode.getMenu().findItem(R.id.selection_submit);
@@ -188,6 +204,12 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
return true;
}
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ savedInstanceState.putStringArray("selected_contacts", getSelectedContactJids());
+ super.onSaveInstanceState(savedInstanceState);
+ }
+
protected void filterContacts(final String needle) {
getListItems().clear();
if (xmppConnectionService == null) {
@@ -210,11 +232,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
private String[] getSelectedContactJids() {
- List<String> result = new ArrayList<>();
- for (Contact contact : selected) {
- result.add(contact.getJid().toString());
- }
- return result.toArray(new String[result.size()]);
+ return selected.toArray(new String[selected.size()]);
}
public void refreshUiReal() {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 1a4095b0e..01452d3db 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -2501,6 +2501,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
private boolean showLoadMoreMessages(final Conversation c) {
+ if (activity == null || activity.xmppConnectionService == null) {
+ return false;
+ }
final boolean mam = hasMamSupport(c) && !c.getContact().isBlocked();
final MessageArchiveService service = activity.xmppConnectionService.getMessageArchiveService();
return mam && (c.getLastClearHistory().getTimestamp() != 0 || (c.countMessages() == 0 && c.messagesLoaded.get() && c.hasMessagesLeftOnServer() && !service.queryInProgress(c)));