fixed rotation in choose contact activity
This commit is contained in:
parent
acf0b995ab
commit
03e88500b9
|
@ -9,6 +9,7 @@ import android.support.annotation.StringRes;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
@ -19,6 +20,7 @@ import android.widget.AbsListView.MultiChoiceModeListener;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -40,7 +42,7 @@ import rocks.xmpp.addr.Jid;
|
||||||
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
|
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
|
||||||
private List<String> mActivatedAccounts = new ArrayList<>();
|
private List<String> mActivatedAccounts = new ArrayList<>();
|
||||||
private Set<Contact> selected;
|
private Set<String> selected = new HashSet<>();
|
||||||
private Set<String> filterContacts;
|
private Set<String> filterContacts;
|
||||||
|
|
||||||
private PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
|
private PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
|
||||||
|
@ -70,6 +72,14 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
filterContacts = new HashSet<>();
|
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");
|
String[] contacts = getIntent().getStringArrayExtra("filter_contacts");
|
||||||
if (contacts != null) {
|
if (contacts != null) {
|
||||||
Collections.addAll(filterContacts, contacts);
|
Collections.addAll(filterContacts, contacts);
|
||||||
|
@ -86,16 +96,24 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
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);
|
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
if (view != null && imm != null) {
|
||||||
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
|
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||||
|
}
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.select_multiple, menu);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
|
binding.fab.setVisibility(View.VISIBLE);
|
||||||
|
selected.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -122,9 +140,9 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
||||||
Contact item = (Contact) getListItems().get(position);
|
Contact item = (Contact) getListItems().get(position);
|
||||||
if (checked) {
|
if (checked) {
|
||||||
selected.add(item);
|
selected.add(item.getJid().toString());
|
||||||
} else {
|
} else {
|
||||||
selected.remove(item);
|
selected.remove(item.getJid().toString());
|
||||||
}
|
}
|
||||||
int numSelected = selected.size();
|
int numSelected = selected.size();
|
||||||
MenuItem selectButton = mode.getMenu().findItem(R.id.selection_submit);
|
MenuItem selectButton = mode.getMenu().findItem(R.id.selection_submit);
|
||||||
|
@ -187,6 +205,12 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
|
savedInstanceState.putStringArray("selected_contacts",getSelectedContactJids());
|
||||||
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
protected void filterContacts(final String needle) {
|
protected void filterContacts(final String needle) {
|
||||||
getListItems().clear();
|
getListItems().clear();
|
||||||
if (xmppConnectionService == null) {
|
if (xmppConnectionService == null) {
|
||||||
|
@ -209,11 +233,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getSelectedContactJids() {
|
private String[] getSelectedContactJids() {
|
||||||
List<String> result = new ArrayList<>();
|
return selected.toArray(new String[selected.size()]);
|
||||||
for (Contact contact : selected) {
|
|
||||||
result.add(contact.getJid().toString());
|
|
||||||
}
|
|
||||||
return result.toArray(new String[result.size()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshUiReal() {
|
public void refreshUiReal() {
|
||||||
|
|
|
@ -2181,6 +2181,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean showLoadMoreMessages(final Conversation c) {
|
private boolean showLoadMoreMessages(final Conversation c) {
|
||||||
|
if (activity == null || activity.xmppConnectionService == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
final boolean mam = hasMamSupport(c) && !c.getContact().isBlocked();
|
final boolean mam = hasMamSupport(c) && !c.getContact().isBlocked();
|
||||||
final MessageArchiveService service = activity.xmppConnectionService.getMessageArchiveService();
|
final MessageArchiveService service = activity.xmppConnectionService.getMessageArchiveService();
|
||||||
return mam && (c.getLastClearHistory().getTimestamp() != 0 || (c.countMessages() == 0 && c.messagesLoaded.get() && c.hasMessagesLeftOnServer() && !service.queryInProgress(c)));
|
return mam && (c.getLastClearHistory().getTimestamp() != 0 || (c.countMessages() == 0 && c.messagesLoaded.get() && c.hasMessagesLeftOnServer() && !service.queryInProgress(c)));
|
||||||
|
|
Loading…
Reference in a new issue