Checkpoint, remaking ContactsListFragment SelectionMode/Searchmode
This commit is contained in:
parent
52cdc51847
commit
590c56a573
3 changed files with 381 additions and 343 deletions
|
@ -119,7 +119,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ListView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/contactsList"
|
android:id="@+id/contactsList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
316
src/android/org/linphone/contacts/ContactsListAdapter.java
Normal file
316
src/android/org/linphone/contacts/ContactsListAdapter.java
Normal file
|
@ -0,0 +1,316 @@
|
||||||
|
package org.linphone.contacts;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.SectionIndexer;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.linphone.LinphoneUtils;
|
||||||
|
import org.linphone.R;
|
||||||
|
import org.linphone.activities.LinphoneActivity;
|
||||||
|
import org.linphone.ui.SelectableAdapter;
|
||||||
|
import org.linphone.ui.SelectableHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.ViewHolder> implements SectionIndexer {
|
||||||
|
//public class ContactsListAdapter extends RecyclerView.Adapter<ContactsListAdapter.ViewHolder> implements SectionIndexer {
|
||||||
|
// class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
|
||||||
|
public CheckBox delete;
|
||||||
|
public ImageView linphoneFriend;
|
||||||
|
public TextView name;
|
||||||
|
public LinearLayout separator;
|
||||||
|
public TextView separatorText;
|
||||||
|
public ImageView contactPicture;
|
||||||
|
public TextView organization;
|
||||||
|
//public ImageView friendStatus;
|
||||||
|
private ClickListener listener;
|
||||||
|
|
||||||
|
private ViewHolder(View view, ClickListener listener) {
|
||||||
|
super(view);
|
||||||
|
|
||||||
|
delete = (CheckBox) view.findViewById(R.id.delete);
|
||||||
|
linphoneFriend = (ImageView) view.findViewById(R.id.friendLinphone);
|
||||||
|
name = (TextView) view.findViewById(R.id.name);
|
||||||
|
separator = (LinearLayout) view.findViewById(R.id.separator);
|
||||||
|
separatorText = (TextView) view.findViewById(R.id.separator_text);
|
||||||
|
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
||||||
|
organization = (TextView) view.findViewById(R.id.contactOrganization);
|
||||||
|
//friendStatus = (ImageView) view.findViewById(R.id.friendStatus);
|
||||||
|
this.listener= listener;
|
||||||
|
view.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onItemClicked(getAdapterPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ClickListener {
|
||||||
|
void onItemClicked(int position);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LinphoneContact> contacts;
|
||||||
|
String[] sections;
|
||||||
|
ArrayList<String> sectionsList;
|
||||||
|
Map<String, Integer> map = new LinkedHashMap<String, Integer>();
|
||||||
|
private ViewHolder.ClickListener clickListener;
|
||||||
|
private Context mContext;
|
||||||
|
private boolean isSearchMode;
|
||||||
|
|
||||||
|
ContactsListAdapter(Context context, List<LinphoneContact> contactsList, ViewHolder.ClickListener clickListener, SelectableHelper helper) {
|
||||||
|
super(helper);
|
||||||
|
this.mContext=context;
|
||||||
|
updateDataSet(contactsList);
|
||||||
|
this.clickListener = clickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.contact_cell, parent, false);
|
||||||
|
return new ViewHolder(v, clickListener);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
|
||||||
|
LinphoneContact contact = (LinphoneContact) getItem(position);
|
||||||
|
|
||||||
|
holder.name.setText(contact.getFullName());
|
||||||
|
|
||||||
|
if (!isSearchMode) {
|
||||||
|
if (getPositionForSection(getSectionForPosition(position)) != position) {
|
||||||
|
holder.separator.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
holder.separator.setVisibility(View.VISIBLE);
|
||||||
|
String fullName = contact.getFullName();
|
||||||
|
if (fullName != null && !fullName.isEmpty()) {
|
||||||
|
holder.separatorText.setText(String.valueOf(fullName.charAt(0)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
holder.separator.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contact.isInFriendList()) {
|
||||||
|
holder.linphoneFriend.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.linphoneFriend.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||||
|
if (contact.hasPhoto()) {
|
||||||
|
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isOrgVisible = getResources().getBoolean(R.bool.display_contact_organization);
|
||||||
|
String org = contact.getOrganization();
|
||||||
|
if (org != null && !org.isEmpty() && isOrgVisible) {
|
||||||
|
holder.organization.setText(org);
|
||||||
|
holder.organization.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.organization.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.delete.setVisibility(this.isEditionEnabled() ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
holder.delete.setChecked(isSelected(position));
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return contacts.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public int getCount() {
|
||||||
|
// return contacts.size();
|
||||||
|
// }
|
||||||
|
|
||||||
|
public Object getItem(int position) {
|
||||||
|
if (position >= getItemCount()) return null;
|
||||||
|
return contacts.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void updateDataSet(List<LinphoneContact> contactsList) {
|
||||||
|
contacts = contactsList;
|
||||||
|
|
||||||
|
map = new LinkedHashMap<String, Integer>();
|
||||||
|
String prevLetter = null;
|
||||||
|
for (int i = 0; i < contacts.size(); i++) {
|
||||||
|
LinphoneContact contact = contacts.get(i);
|
||||||
|
String fullName = contact.getFullName();
|
||||||
|
if (fullName == null || fullName.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String firstLetter = fullName.substring(0, 1).toUpperCase(Locale.getDefault());
|
||||||
|
if (!firstLetter.equals(prevLetter)) {
|
||||||
|
prevLetter = firstLetter;
|
||||||
|
map.put(firstLetter, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sectionsList = new ArrayList<String>(map.keySet());
|
||||||
|
sections = new String[sectionsList.size()];
|
||||||
|
sectionsList.toArray(sections);
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
|
// View view = null;
|
||||||
|
// LinphoneContact contact = (LinphoneContact) getItem(position);
|
||||||
|
// if (contact == null) return null;
|
||||||
|
//
|
||||||
|
// ViewHolder holder = null;
|
||||||
|
// if (convertView != null) {
|
||||||
|
// view = convertView;
|
||||||
|
// holder = (ViewHolder) view.getTag();
|
||||||
|
// } else {
|
||||||
|
// view = mInflater.inflate(R.layout.contact_cell, parent, false);
|
||||||
|
// holder = new ViewHolder(view);
|
||||||
|
// view.setTag(holder);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// holder.name.setText(contact.getFullName());
|
||||||
|
//
|
||||||
|
// if (!isSearchMode) {
|
||||||
|
// if (getPositionForSection(getSectionForPosition(position)) != position) {
|
||||||
|
// holder.separator.setVisibility(View.GONE);
|
||||||
|
// } else {
|
||||||
|
// holder.separator.setVisibility(View.VISIBLE);
|
||||||
|
// String fullName = contact.getFullName();
|
||||||
|
// if (fullName != null && !fullName.isEmpty()) {
|
||||||
|
// holder.separatorText.setText(String.valueOf(fullName.charAt(0)));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// holder.separator.setVisibility(View.GONE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (contact.isInFriendList()) {
|
||||||
|
// holder.linphoneFriend.setVisibility(View.VISIBLE);
|
||||||
|
// } else {
|
||||||
|
// holder.linphoneFriend.setVisibility(View.GONE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||||
|
// if (contact.hasPhoto()) {
|
||||||
|
// LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// boolean isOrgVisible = getResources().getBoolean(R.bool.display_contact_organization);
|
||||||
|
// String org = contact.getOrganization();
|
||||||
|
// if (org != null && !org.isEmpty() && isOrgVisible) {
|
||||||
|
// holder.organization.setText(org);
|
||||||
|
// holder.organization.setVisibility(View.VISIBLE);
|
||||||
|
// } else {
|
||||||
|
// holder.organization.setVisibility(View.GONE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (isEditMode) {
|
||||||
|
// holder.delete.setVisibility(View.VISIBLE);
|
||||||
|
// holder.delete.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||||
|
// contactsList.setItemChecked(position, b);
|
||||||
|
// if(getNbItemsChecked() == getCount()){
|
||||||
|
// deselectAll.setVisibility(View.VISIBLE);
|
||||||
|
// selectAll.setVisibility(View.GONE);
|
||||||
|
// enabledDeleteButton(true);
|
||||||
|
// } else {
|
||||||
|
// if(getNbItemsChecked() == 0){
|
||||||
|
// deselectAll.setVisibility(View.GONE);
|
||||||
|
// selectAll.setVisibility(View.VISIBLE);
|
||||||
|
// enabledDeleteButton(false);
|
||||||
|
// } else {
|
||||||
|
// deselectAll.setVisibility(View.GONE);
|
||||||
|
// selectAll.setVisibility(View.VISIBLE);
|
||||||
|
// enabledDeleteButton(true);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// if (contactsList.isItemChecked(position)) {
|
||||||
|
// holder.delete.setChecked(true);
|
||||||
|
// } else {
|
||||||
|
// holder.delete.setChecked(false);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// holder.delete.setVisibility(View.INVISIBLE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /*Friend[] friends = LinphoneManager.getLc().getFriendsLists();
|
||||||
|
// if (!ContactsManager.getInstance().isContactPresenceDisabled() && friends != null) {
|
||||||
|
// holder.friendStatus.setVisibility(View.VISIBLE);
|
||||||
|
// PresenceActivityType presenceActivity = friends[0].getPresenceModel().getActivity().getType();
|
||||||
|
// if (presenceActivity == PresenceActivityType.Online) {
|
||||||
|
// holder.friendStatus.setImageResource(R.drawable.led_connected);
|
||||||
|
// } else if (presenceActivity == PresenceActivityType.Busy) {
|
||||||
|
// holder.friendStatus.setImageResource(R.drawable.led_error);
|
||||||
|
// } else if (presenceActivity == PresenceActivityType.Away) {
|
||||||
|
// holder.friendStatus.setImageResource(R.drawable.led_inprogress);
|
||||||
|
// } else if (presenceActivity == PresenceActivityType.Offline) {
|
||||||
|
// holder.friendStatus.setImageResource(R.drawable.led_disconnected);
|
||||||
|
// } else {
|
||||||
|
// holder.friendStatus.setImageResource(R.drawable.call_quality_indicator_0);
|
||||||
|
// }
|
||||||
|
// }*/
|
||||||
|
//
|
||||||
|
// return view;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] getSections() {
|
||||||
|
return sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPositionForSection(int sectionIndex) {
|
||||||
|
if (sectionIndex >= sections.length || sectionIndex < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return map.get(sections[sectionIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSectionForPosition(int position) {
|
||||||
|
if (position >= contacts.size() || position < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LinphoneContact contact = contacts.get(position);
|
||||||
|
String fullName = contact.getFullName();
|
||||||
|
if (fullName == null || fullName.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
String letter = fullName.substring(0, 1).toUpperCase(Locale.getDefault());
|
||||||
|
return sectionsList.indexOf(letter);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -49,6 +53,7 @@ import org.linphone.LinphoneManager;
|
||||||
import org.linphone.LinphoneUtils;
|
import org.linphone.LinphoneUtils;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.activities.LinphoneActivity;
|
import org.linphone.activities.LinphoneActivity;
|
||||||
|
import org.linphone.ui.SelectableHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -56,12 +61,14 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ContactsListFragment extends Fragment implements OnClickListener, OnItemClickListener, ContactsUpdatedListener {
|
public class ContactsListFragment extends Fragment implements OnItemClickListener, ContactsUpdatedListener, ContactsListAdapter.ViewHolder.ClickListener ,SelectableHelper.DeleteListener {
|
||||||
|
//public class ContactsListFragment extends Fragment implements OnClickListener, OnItemClickListener, ContactsUpdatedListener {
|
||||||
|
//public class ContactsListFragment extends Fragment implements OnClickListener, OnItemClickListener, ContactsUpdatedListener {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private ListView contactsList;
|
private RecyclerView contactsList;
|
||||||
private TextView noSipContact, noContact;
|
private TextView noSipContact, noContact;
|
||||||
private ImageView allContacts, linphoneContacts, newContact, edit, selectAll, deselectAll, delete, cancel;
|
private ImageView allContacts, linphoneContacts, newContact, edit, selectAll, deselectAll, delete, cancel;
|
||||||
private boolean onlyDisplayLinphoneContacts, isEditMode, isSearchMode;
|
private boolean onlyDisplayLinphoneContacts;
|
||||||
private View allContactsSelected, linphoneContactsSelected;
|
private View allContactsSelected, linphoneContactsSelected;
|
||||||
private LinearLayout editList, topbar;
|
private LinearLayout editList, topbar;
|
||||||
private int lastKnownPosition;
|
private int lastKnownPosition;
|
||||||
|
@ -70,12 +77,17 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
private ImageView clearSearchField;
|
private ImageView clearSearchField;
|
||||||
private EditText searchField;
|
private EditText searchField;
|
||||||
private ProgressBar contactsFetchInProgress;
|
private ProgressBar contactsFetchInProgress;
|
||||||
|
private LinearLayoutManager layoutManager;
|
||||||
|
private Context mContext;
|
||||||
|
private SelectableHelper mSelectionHelper;
|
||||||
|
private ContactsListAdapter mContactAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
mInflater = inflater;
|
mInflater = inflater;
|
||||||
View view = inflater.inflate(R.layout.contacts_list, container, false);
|
View view = inflater.inflate(R.layout.contacts_list, container, false);
|
||||||
|
mContext = getActivity().getApplicationContext();
|
||||||
|
mSelectionHelper = new SelectableHelper(view, this);
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
editOnClick = getArguments().getBoolean("EditOnClick");
|
editOnClick = getArguments().getBoolean("EditOnClick");
|
||||||
sipAddressToAdd = getArguments().getString("SipAddress");
|
sipAddressToAdd = getArguments().getString("SipAddress");
|
||||||
|
@ -87,7 +99,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
noSipContact = (TextView) view.findViewById(R.id.noSipContact);
|
noSipContact = (TextView) view.findViewById(R.id.noSipContact);
|
||||||
noContact = (TextView) view.findViewById(R.id.noContact);
|
noContact = (TextView) view.findViewById(R.id.noContact);
|
||||||
|
|
||||||
contactsList = (ListView) view.findViewById(R.id.contactsList);
|
contactsList = view.findViewById(R.id.contactsList);
|
||||||
contactsList.setOnItemClickListener(this);
|
contactsList.setOnItemClickListener(this);
|
||||||
|
|
||||||
allContacts = (ImageView) view.findViewById(R.id.all_contacts);
|
allContacts = (ImageView) view.findViewById(R.id.all_contacts);
|
||||||
|
@ -148,13 +160,21 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
|
|
||||||
contactsFetchInProgress = (ProgressBar) view.findViewById(R.id.contactsFetchInProgress);
|
contactsFetchInProgress = (ProgressBar) view.findViewById(R.id.contactsFetchInProgress);
|
||||||
contactsFetchInProgress.setVisibility(View.VISIBLE);
|
contactsFetchInProgress.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
layoutManager = new LinearLayoutManager(mContext);
|
||||||
|
contactsList.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ContactsManager.getInstance().fetchContactsAsync();
|
ContactsManager.getInstance().fetchContactsAsync();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNbItemsChecked(){
|
public int getNbItemsChecked(){
|
||||||
int size = contactsList.getAdapter().getCount();
|
int size = contactsList.getAdapter().getItemCount();
|
||||||
int nb = 0;
|
int nb = 0;
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
if(contactsList.isItemChecked(i)) {
|
if(contactsList.isItemChecked(i)) {
|
||||||
|
@ -174,127 +194,6 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
int id = v.getId();
|
|
||||||
|
|
||||||
if (id == R.id.select_all) {
|
|
||||||
deselectAll.setVisibility(View.VISIBLE);
|
|
||||||
selectAll.setVisibility(View.GONE);
|
|
||||||
enabledDeleteButton(true);
|
|
||||||
selectAllList(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (id == R.id.deselect_all) {
|
|
||||||
deselectAll.setVisibility(View.GONE);
|
|
||||||
selectAll.setVisibility(View.VISIBLE);
|
|
||||||
enabledDeleteButton(false);
|
|
||||||
selectAllList(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id == R.id.cancel) {
|
|
||||||
quitEditMode();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id == R.id.delete) {
|
|
||||||
final Dialog dialog = LinphoneActivity.instance().displayDialog(getString(R.string.delete_text));
|
|
||||||
Button delete = (Button) dialog.findViewById(R.id.delete_button);
|
|
||||||
Button cancel = (Button) dialog.findViewById(R.id.cancel);
|
|
||||||
|
|
||||||
delete.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
removeContacts();
|
|
||||||
dialog.dismiss();
|
|
||||||
quitEditMode();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cancel.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
dialog.dismiss();
|
|
||||||
quitEditMode();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dialog.show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id == R.id.edit) {
|
|
||||||
editList.setVisibility(View.VISIBLE);
|
|
||||||
topbar.setVisibility(View.GONE);
|
|
||||||
enabledDeleteButton(false);
|
|
||||||
isEditMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id == R.id.all_contacts) {
|
|
||||||
onlyDisplayLinphoneContacts = false;
|
|
||||||
allContactsSelected.setVisibility(View.VISIBLE);
|
|
||||||
allContacts.setEnabled(false);
|
|
||||||
linphoneContacts.setEnabled(true);
|
|
||||||
linphoneContactsSelected.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
else if (id == R.id.linphone_contacts) {
|
|
||||||
allContactsSelected.setVisibility(View.INVISIBLE);
|
|
||||||
linphoneContactsSelected.setVisibility(View.VISIBLE);
|
|
||||||
linphoneContacts.setEnabled(false);
|
|
||||||
allContacts.setEnabled(true);
|
|
||||||
onlyDisplayLinphoneContacts = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isEditMode){
|
|
||||||
deselectAll.setVisibility(View.GONE);
|
|
||||||
selectAll.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchField.getText().toString().length() > 0) {
|
|
||||||
searchContacts();
|
|
||||||
} else {
|
|
||||||
changeContactsAdapter();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id == R.id.newContact) {
|
|
||||||
editConsumed = true;
|
|
||||||
if(displayName != null)
|
|
||||||
LinphoneActivity.instance().addContact(displayName, sipAddressToAdd);
|
|
||||||
else
|
|
||||||
LinphoneActivity.instance().addContact(null, sipAddressToAdd);
|
|
||||||
}
|
|
||||||
else if (id == R.id.clearSearchField) {
|
|
||||||
searchField.setText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectAllList(boolean isSelectAll){
|
|
||||||
int size = contactsList.getAdapter().getCount();
|
|
||||||
for(int i=0; i<size; i++) {
|
|
||||||
contactsList.setItemChecked(i,isSelectAll);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeContacts() {
|
|
||||||
ArrayList<String> ids = new ArrayList<String>();
|
|
||||||
int size = contactsList.getAdapter().getCount();
|
|
||||||
|
|
||||||
for (int i = size - 1; i >= 0; i--) {
|
|
||||||
if (contactsList.isItemChecked(i)) {
|
|
||||||
LinphoneContact contact = (LinphoneContact) contactsList.getAdapter().getItem(i);
|
|
||||||
if (contact.isAndroidContact()) {
|
|
||||||
contact.deleteFriend();
|
|
||||||
ids.add(contact.getAndroidId());
|
|
||||||
} else {
|
|
||||||
contact.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ContactsManager.getInstance().deleteMultipleContactsAtOnce(ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void quitEditMode(){
|
public void quitEditMode(){
|
||||||
isEditMode = false;
|
isEditMode = false;
|
||||||
editList.setVisibility(View.GONE);
|
editList.setVisibility(View.GONE);
|
||||||
|
@ -306,8 +205,9 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayFirstContact(){
|
public void displayFirstContact(){
|
||||||
if (contactsList != null && contactsList.getAdapter() != null && contactsList.getAdapter().getCount() > 0) {
|
if (contactsList != null && contactsList.getAdapter() != null && contactsList.getAdapter().getItemCount() > 0) {
|
||||||
LinphoneActivity.instance().displayContact((LinphoneContact) contactsList.getAdapter().getItem(0), false);
|
ContactsListAdapter mAdapt = (ContactsListAdapter)contactsList.getAdapter();
|
||||||
|
LinphoneActivity.instance().displayContact((LinphoneContact) mAdapt.getItem(0), false);
|
||||||
} else {
|
} else {
|
||||||
LinphoneActivity.instance().displayEmptyFragment();
|
LinphoneActivity.instance().displayEmptyFragment();
|
||||||
}
|
}
|
||||||
|
@ -323,21 +223,27 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
changeContactsToggle();
|
changeContactsToggle();
|
||||||
|
List<LinphoneContact> listContact;
|
||||||
isSearchMode = true;
|
isSearchMode = true;
|
||||||
|
|
||||||
if (onlyDisplayLinphoneContacts) {
|
if (onlyDisplayLinphoneContacts) {
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
listContact = ContactsManager.getInstance().getSIPContacts(search);
|
||||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(search)));
|
|
||||||
} else {
|
} else {
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
listContact = ContactsManager.getInstance().getContacts(search);
|
||||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getContacts(search)));
|
|
||||||
}
|
}
|
||||||
|
mContactAdapter = new ContactsListAdapter(mContext, listContact, this, mSelectionHelper);
|
||||||
|
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||||
|
contactsList.setAdapter(mContactAdapter);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeContactsAdapter() {
|
private void changeContactsAdapter() {
|
||||||
changeContactsToggle();
|
changeContactsToggle();
|
||||||
|
List<LinphoneContact> listContact;
|
||||||
isSearchMode = false;
|
isSearchMode = false;
|
||||||
noSipContact.setVisibility(View.GONE);
|
noSipContact.setVisibility(View.GONE);
|
||||||
noContact.setVisibility(View.GONE);
|
noContact.setVisibility(View.GONE);
|
||||||
|
@ -345,22 +251,26 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
|
|
||||||
ContactsListAdapter adapter;
|
ContactsListAdapter adapter;
|
||||||
contactsList.setFastScrollEnabled(false);
|
contactsList.setFastScrollEnabled(false);
|
||||||
|
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||||
|
|
||||||
|
|
||||||
if (onlyDisplayLinphoneContacts) {
|
if (onlyDisplayLinphoneContacts) {
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
listContact = ContactsManager.getInstance().getSIPContacts();
|
||||||
adapter = new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts());
|
|
||||||
contactsList.setAdapter(adapter);
|
|
||||||
edit.setEnabled(true);
|
|
||||||
} else {
|
} else {
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
listContact = ContactsManager.getInstance().getContacts();
|
||||||
adapter = new ContactsListAdapter(ContactsManager.getInstance().getContacts());
|
|
||||||
contactsList.setAdapter(adapter);
|
|
||||||
edit.setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
mContactAdapter = new ContactsListAdapter(mContext, listContact, this, mSelectionHelper);
|
||||||
|
contactsList.setAdapter(mContactAdapter);
|
||||||
|
edit.setEnabled(true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
contactsList.setFastScrollEnabled(true);
|
contactsList.setFastScrollEnabled(true);
|
||||||
adapter.notifyDataSetInvalidated();
|
adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
|
||||||
if (adapter.getCount() > 0) {
|
if (adapter.getItemCount() > 0) {
|
||||||
contactsFetchInProgress.setVisibility(View.GONE);
|
contactsFetchInProgress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
|
ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
|
||||||
|
@ -387,7 +297,8 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
editConsumed = true;
|
editConsumed = true;
|
||||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
||||||
} else {
|
} else {
|
||||||
lastKnownPosition = contactsList.getFirstVisiblePosition();
|
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
||||||
|
// lastKnownPosition = contactsList.getFirstVisiblePosition();
|
||||||
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,206 +355,17 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
} else {
|
} else {
|
||||||
changeContactsAdapter();
|
changeContactsAdapter();
|
||||||
}
|
}
|
||||||
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
contactsList.scrollToPosition(lastKnownPosition);
|
||||||
|
// contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
@Override
|
||||||
private class ViewHolder {
|
public void onDeleteSelection(Object[] objectsToDelete) {
|
||||||
public CheckBox delete;
|
|
||||||
public ImageView linphoneFriend;
|
|
||||||
public TextView name;
|
|
||||||
public LinearLayout separator;
|
|
||||||
public TextView separatorText;
|
|
||||||
public ImageView contactPicture;
|
|
||||||
public TextView organization;
|
|
||||||
//public ImageView friendStatus;
|
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
}
|
||||||
delete = (CheckBox) view.findViewById(R.id.delete);
|
|
||||||
linphoneFriend = (ImageView) view.findViewById(R.id.friendLinphone);
|
|
||||||
name = (TextView) view.findViewById(R.id.name);
|
|
||||||
separator = (LinearLayout) view.findViewById(R.id.separator);
|
|
||||||
separatorText = (TextView) view.findViewById(R.id.separator_text);
|
|
||||||
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
|
||||||
organization = (TextView) view.findViewById(R.id.contactOrganization);
|
|
||||||
//friendStatus = (ImageView) view.findViewById(R.id.friendStatus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<LinphoneContact> contacts;
|
@Override
|
||||||
String[] sections;
|
public void onItemClicked(int position) {
|
||||||
ArrayList<String> sectionsList;
|
|
||||||
Map<String, Integer>map = new LinkedHashMap<String, Integer>();
|
|
||||||
|
|
||||||
ContactsListAdapter(List<LinphoneContact> contactsList) {
|
|
||||||
updateDataSet(contactsList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateDataSet(List<LinphoneContact> contactsList) {
|
|
||||||
contacts = contactsList;
|
|
||||||
|
|
||||||
map = new LinkedHashMap<String, Integer>();
|
|
||||||
String prevLetter = null;
|
|
||||||
for (int i = 0; i < contacts.size(); i++) {
|
|
||||||
LinphoneContact contact = contacts.get(i);
|
|
||||||
String fullName = contact.getFullName();
|
|
||||||
if (fullName == null || fullName.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String firstLetter = fullName.substring(0, 1).toUpperCase(Locale.getDefault());
|
|
||||||
if (!firstLetter.equals(prevLetter)) {
|
|
||||||
prevLetter = firstLetter;
|
|
||||||
map.put(firstLetter, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sectionsList = new ArrayList<String>(map.keySet());
|
|
||||||
sections = new String[sectionsList.size()];
|
|
||||||
sectionsList.toArray(sections);
|
|
||||||
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return contacts.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getItem(int position) {
|
|
||||||
if (position >= getCount()) return null;
|
|
||||||
return contacts.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getItemId(int position) {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
||||||
View view = null;
|
|
||||||
LinphoneContact contact = (LinphoneContact) getItem(position);
|
|
||||||
if (contact == null) return null;
|
|
||||||
|
|
||||||
ViewHolder holder = null;
|
|
||||||
if (convertView != null) {
|
|
||||||
view = convertView;
|
|
||||||
holder = (ViewHolder) view.getTag();
|
|
||||||
} else {
|
|
||||||
view = mInflater.inflate(R.layout.contact_cell, parent, false);
|
|
||||||
holder = new ViewHolder(view);
|
|
||||||
view.setTag(holder);
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.name.setText(contact.getFullName());
|
|
||||||
|
|
||||||
if (!isSearchMode) {
|
|
||||||
if (getPositionForSection(getSectionForPosition(position)) != position) {
|
|
||||||
holder.separator.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
holder.separator.setVisibility(View.VISIBLE);
|
|
||||||
String fullName = contact.getFullName();
|
|
||||||
if (fullName != null && !fullName.isEmpty()) {
|
|
||||||
holder.separatorText.setText(String.valueOf(fullName.charAt(0)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
holder.separator.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contact.isInFriendList()) {
|
|
||||||
holder.linphoneFriend.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
holder.linphoneFriend.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
|
||||||
if (contact.hasPhoto()) {
|
|
||||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isOrgVisible = getResources().getBoolean(R.bool.display_contact_organization);
|
|
||||||
String org = contact.getOrganization();
|
|
||||||
if (org != null && !org.isEmpty() && isOrgVisible) {
|
|
||||||
holder.organization.setText(org);
|
|
||||||
holder.organization.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
holder.organization.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEditMode) {
|
|
||||||
holder.delete.setVisibility(View.VISIBLE);
|
|
||||||
holder.delete.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
|
||||||
contactsList.setItemChecked(position, b);
|
|
||||||
if(getNbItemsChecked() == getCount()){
|
|
||||||
deselectAll.setVisibility(View.VISIBLE);
|
|
||||||
selectAll.setVisibility(View.GONE);
|
|
||||||
enabledDeleteButton(true);
|
|
||||||
} else {
|
|
||||||
if(getNbItemsChecked() == 0){
|
|
||||||
deselectAll.setVisibility(View.GONE);
|
|
||||||
selectAll.setVisibility(View.VISIBLE);
|
|
||||||
enabledDeleteButton(false);
|
|
||||||
} else {
|
|
||||||
deselectAll.setVisibility(View.GONE);
|
|
||||||
selectAll.setVisibility(View.VISIBLE);
|
|
||||||
enabledDeleteButton(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (contactsList.isItemChecked(position)) {
|
|
||||||
holder.delete.setChecked(true);
|
|
||||||
} else {
|
|
||||||
holder.delete.setChecked(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
holder.delete.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Friend[] friends = LinphoneManager.getLc().getFriendsLists();
|
|
||||||
if (!ContactsManager.getInstance().isContactPresenceDisabled() && friends != null) {
|
|
||||||
holder.friendStatus.setVisibility(View.VISIBLE);
|
|
||||||
PresenceActivityType presenceActivity = friends[0].getPresenceModel().getActivity().getType();
|
|
||||||
if (presenceActivity == PresenceActivityType.Online) {
|
|
||||||
holder.friendStatus.setImageResource(R.drawable.led_connected);
|
|
||||||
} else if (presenceActivity == PresenceActivityType.Busy) {
|
|
||||||
holder.friendStatus.setImageResource(R.drawable.led_error);
|
|
||||||
} else if (presenceActivity == PresenceActivityType.Away) {
|
|
||||||
holder.friendStatus.setImageResource(R.drawable.led_inprogress);
|
|
||||||
} else if (presenceActivity == PresenceActivityType.Offline) {
|
|
||||||
holder.friendStatus.setImageResource(R.drawable.led_disconnected);
|
|
||||||
} else {
|
|
||||||
holder.friendStatus.setImageResource(R.drawable.call_quality_indicator_0);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object[] getSections() {
|
|
||||||
return sections;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPositionForSection(int sectionIndex) {
|
|
||||||
if (sectionIndex >= sections.length || sectionIndex < 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return map.get(sections[sectionIndex]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSectionForPosition(int position) {
|
|
||||||
if (position >= contacts.size() || position < 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
LinphoneContact contact = contacts.get(position);
|
|
||||||
String fullName = contact.getFullName();
|
|
||||||
if (fullName == null || fullName.isEmpty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
String letter = fullName.substring(0, 1).toUpperCase(Locale.getDefault());
|
|
||||||
return sectionsList.indexOf(letter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue