Add delte contact in contact list
This commit is contained in:
parent
3d3a1c4f23
commit
dde619359b
5 changed files with 125 additions and 63 deletions
|
@ -69,6 +69,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@id/avatar_layout"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@id/delete"
|
||||
android:layout_marginLeft="10dp" />
|
||||
|
||||
<ImageView
|
||||
|
|
|
@ -218,10 +218,7 @@ public class ContactFragment extends Fragment implements OnClickListener {
|
|||
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACT);
|
||||
|
||||
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
||||
LinphoneActivity.instance().hideStatusBar();
|
||||
}
|
||||
LinphoneActivity.instance().hideTabBar(false);
|
||||
}
|
||||
contact.refresh(getActivity().getContentResolver());
|
||||
if (contact.getName() == null || contact.getName().equals("")) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.linphone;
|
||||
/*
|
||||
ContactsFragment.java
|
||||
Copyright (C) 2012 Belledonne Communications, Grenoble, France
|
||||
ContactsListFragment.java
|
||||
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
@ -21,18 +21,19 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
import org.linphone.core.LinphoneCallLog;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.core.PresenceActivityType;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -59,7 +60,7 @@ import android.widget.TextView;
|
|||
* @author Sylvain Berfini
|
||||
*/
|
||||
@SuppressLint("DefaultLocale")
|
||||
public class ContactsFragment extends Fragment implements OnClickListener, OnItemClickListener {
|
||||
public class ContactsListFragment extends Fragment implements OnClickListener, OnItemClickListener {
|
||||
private LayoutInflater mInflater;
|
||||
private ListView contactsList;
|
||||
private TextView noSipContact, noContact;
|
||||
|
@ -74,13 +75,13 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
private EditText searchField;
|
||||
private Cursor searchCursor;
|
||||
|
||||
private static ContactsFragment instance;
|
||||
private static ContactsListFragment instance;
|
||||
|
||||
static final boolean isInstanciated() {
|
||||
return instance != null;
|
||||
}
|
||||
|
||||
public static final ContactsFragment instance() {
|
||||
public static final ContactsListFragment instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -165,6 +166,29 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
return view;
|
||||
}
|
||||
|
||||
public int getNbItemsChecked(){
|
||||
int size = contactsList.getAdapter().getCount();
|
||||
int nb = 0;
|
||||
for(int i=0; i<size; i++) {
|
||||
if(contactsList.isItemChecked(i)) {
|
||||
nb ++;
|
||||
}
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
public void enabledDeleteButton(Boolean enabled){
|
||||
if(enabled){
|
||||
delete.setEnabled(true);
|
||||
delete.setAlpha(1f);
|
||||
} else {
|
||||
if (getNbItemsChecked() == 0){
|
||||
delete.setEnabled(false);
|
||||
delete.setAlpha(0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
|
@ -172,12 +196,14 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
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;
|
||||
}
|
||||
|
@ -215,6 +241,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
if (id == R.id.edit) {
|
||||
editList.setVisibility(View.VISIBLE);
|
||||
topbar.setVisibility(View.GONE);
|
||||
enabledDeleteButton(false);
|
||||
isEditMode = true;
|
||||
}
|
||||
|
||||
|
@ -261,11 +288,31 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
}
|
||||
}
|
||||
|
||||
private void deleteExistingContact(Contact contact) {
|
||||
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
||||
String[] args = new String[] { contact.getID() };
|
||||
|
||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build()
|
||||
);
|
||||
|
||||
try {
|
||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||
ContactsManager.getInstance().removeAllFriends(contact);
|
||||
} catch (Exception e) {
|
||||
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
private void removeContacts(){
|
||||
int size = contactsList.getAdapter().getCount();
|
||||
for(int i=0; i<size; i++) {
|
||||
if(contactsList.isItemChecked(i)){
|
||||
//TODO remove contacts
|
||||
Contact contact = (Contact) contactsList.getAdapter().getItem(i);
|
||||
deleteExistingContact(contact);
|
||||
ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(), contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -373,11 +420,8 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACTS);
|
||||
LinphoneActivity.instance().hideTabBar(false);
|
||||
onlyDisplayLinphoneContacts = ContactsManager.getInstance().isLinphoneContactsPrefered();
|
||||
|
||||
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
||||
LinphoneActivity.instance().hideStatusBar();
|
||||
}
|
||||
}
|
||||
|
||||
invalidate();
|
||||
|
@ -473,6 +517,21 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
@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)) {
|
|
@ -91,7 +91,6 @@ public class EditContactFragment extends Fragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isNewContact) {
|
||||
if (getResources().getBoolean(R.bool.forbid_empty_new_contact_in_editor)) {
|
||||
boolean areAllFielsEmpty = true;
|
||||
for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) {
|
||||
if (nounoa.newNumberOrAddress != null && !nounoa.newNumberOrAddress.equals("")) {
|
||||
|
@ -103,7 +102,6 @@ public class EditContactFragment extends Fragment {
|
|||
getFragmentManager().popBackStackImmediate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
contactsManager.createNewContact(ops, firstName.getText().toString(), lastName.getText().toString());
|
||||
} else {
|
||||
contactsManager.updateExistingContact(ops, contact, firstName.getText().toString(), lastName.getText().toString());
|
||||
|
@ -125,7 +123,7 @@ public class EditContactFragment extends Fragment {
|
|||
getFragmentManager().popBackStackImmediate();
|
||||
|
||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.isTablet))
|
||||
ContactsFragment.instance().invalidate();
|
||||
ContactsListFragment.instance().invalidate();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -237,9 +235,7 @@ public class EditContactFragment extends Fragment {
|
|||
super.onResume();
|
||||
|
||||
if(LinphoneActivity.isInstanciated()){
|
||||
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
||||
LinphoneActivity.instance().hideStatusBar();
|
||||
}
|
||||
LinphoneActivity.instance().hideTabBar(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -236,14 +236,14 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
startActivity(new Intent(LinphoneActivity.instance(), CallOutgoingActivity.class));
|
||||
} else if (state == State.CallEnd || state == State.Error || state == State.CallReleased) {
|
||||
// Convert LinphoneCore message for internalization
|
||||
if (message != null && call.getReason() == Reason.Declined) {
|
||||
displayCustomToast(getString(R.string.error_call_declined), Toast.LENGTH_LONG);
|
||||
if (message != null && call.getErrorInfo().getReason() == Reason.Declined) {
|
||||
displayCustomToast(getString(R.string.error_call_declined), Toast.LENGTH_SHORT);
|
||||
} else if (message != null && call.getReason() == Reason.NotFound) {
|
||||
displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_LONG);
|
||||
displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_SHORT);
|
||||
} else if (message != null && call.getReason() == Reason.Media) {
|
||||
displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_LONG);
|
||||
displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_SHORT);
|
||||
} else if (message != null && state == State.Error) {
|
||||
displayCustomToast(getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_LONG);
|
||||
displayCustomToast(getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_SHORT);
|
||||
}
|
||||
resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
|
||||
}
|
||||
|
@ -371,14 +371,14 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
Fragment newFragment = null;
|
||||
|
||||
switch (newFragmentType) {
|
||||
case HISTORY:
|
||||
newFragment = new HistoryFragment();
|
||||
case HISTORY_LIST:
|
||||
newFragment = new HistoryListFragment();
|
||||
break;
|
||||
case HISTORY_DETAIL:
|
||||
newFragment = new HistoryDetailFragment();
|
||||
break;
|
||||
case CONTACTS:
|
||||
newFragment = new ContactsFragment();
|
||||
case CONTACTS_LIST:
|
||||
newFragment = new ContactsListFragment();
|
||||
friendStatusListenerFragment = newFragment;
|
||||
break;
|
||||
case CONTACT:
|
||||
|
@ -455,9 +455,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
}
|
||||
|
||||
if (newFragmentType != FragmentsAvailable.DIALER
|
||||
|| newFragmentType != FragmentsAvailable.CONTACTS
|
||||
|| newFragmentType != FragmentsAvailable.CONTACTS_LIST
|
||||
|| newFragmentType != FragmentsAvailable.CHATLIST
|
||||
|| newFragmentType != FragmentsAvailable.HISTORY) {
|
||||
|| newFragmentType != FragmentsAvailable.HISTORY_LIST) {
|
||||
transaction.addToBackStack(newFragmentType.toString());
|
||||
}
|
||||
transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
|
||||
|
@ -513,9 +513,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
currentFragment = newFragmentType;
|
||||
if (newFragmentType == FragmentsAvailable.DIALER
|
||||
|| newFragmentType == FragmentsAvailable.SETTINGS
|
||||
|| newFragmentType == FragmentsAvailable.CONTACTS
|
||||
|| newFragmentType == FragmentsAvailable.CONTACTS_LIST
|
||||
|| newFragmentType == FragmentsAvailable.CHATLIST
|
||||
|| newFragmentType == FragmentsAvailable.HISTORY) {
|
||||
|| newFragmentType == FragmentsAvailable.HISTORY_LIST) {
|
||||
try {
|
||||
getFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
} catch (java.lang.IllegalStateException e) {
|
||||
|
@ -599,7 +599,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
Bundle extras = new Bundle();
|
||||
extras.putBoolean("ChatAddressOnly", chatOnly);
|
||||
changeCurrentFragment(FragmentsAvailable.CONTACTS, extras);
|
||||
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras);
|
||||
preferLinphoneContacts = false;
|
||||
}
|
||||
|
||||
|
@ -607,7 +607,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
Bundle extras = new Bundle();
|
||||
extras.putBoolean("EditOnClick", true);
|
||||
extras.putString("SipAddress", sipAddress);
|
||||
changeCurrentFragment(FragmentsAvailable.CONTACTS, extras);
|
||||
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras);
|
||||
}
|
||||
|
||||
public void displayAbout() {
|
||||
|
@ -705,12 +705,12 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
resetSelection();
|
||||
|
||||
if (id == R.id.history) {
|
||||
changeCurrentFragment(FragmentsAvailable.HISTORY, null);
|
||||
changeCurrentFragment(FragmentsAvailable.HISTORY_LIST, null);
|
||||
history_selected.setVisibility(View.VISIBLE);
|
||||
LinphoneManager.getLc().resetMissedCallsCount();
|
||||
displayMissedCalls(0);
|
||||
} else if (id == R.id.contacts) {
|
||||
changeCurrentFragment(FragmentsAvailable.CONTACTS, null);
|
||||
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, null);
|
||||
contacts_selected.setVisibility(View.VISIBLE);
|
||||
} else if (id == R.id.dialer) {
|
||||
changeCurrentFragment(FragmentsAvailable.DIALER, null);
|
||||
|
@ -742,11 +742,11 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
resetSelection();
|
||||
|
||||
switch (menuToSelect) {
|
||||
case HISTORY:
|
||||
case HISTORY_LIST:
|
||||
case HISTORY_DETAIL:
|
||||
history_selected.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case CONTACTS:
|
||||
case CONTACTS_LIST:
|
||||
case CONTACT:
|
||||
case EDIT_CONTACT:
|
||||
contacts_selected.setVisibility(View.VISIBLE);
|
||||
|
@ -852,7 +852,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
getChatStorage().updateMessageStatus(to, id, newState);
|
||||
}
|
||||
|
||||
private void displayMissedCalls(final int missedCallsCount) {
|
||||
public void displayMissedCalls(final int missedCallsCount) {
|
||||
if (missedCallsCount > 0) {
|
||||
missedCalls.setText(missedCallsCount + "");
|
||||
missedCalls.setVisibility(View.VISIBLE);
|
||||
|
@ -865,7 +865,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
}
|
||||
}
|
||||
|
||||
private void displayMissedChats(final int missedChatCount) {;
|
||||
private void displayMissedChats(final int missedChatCount) {
|
||||
if (missedChatCount > 0) {
|
||||
missedChats.setText(missedChatCount + "");
|
||||
missedChats.setVisibility(View.VISIBLE);
|
||||
|
@ -1230,8 +1230,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (currentFragment == FragmentsAvailable.DIALER
|
||||
|| currentFragment == FragmentsAvailable.CONTACTS
|
||||
|| currentFragment == FragmentsAvailable.HISTORY
|
||||
|| currentFragment == FragmentsAvailable.CONTACTS_LIST
|
||||
|| currentFragment == FragmentsAvailable.HISTORY_LIST
|
||||
|| currentFragment == FragmentsAvailable.CHATLIST) {
|
||||
boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled();
|
||||
if (!isBackgroundModeActive) {
|
||||
|
@ -1332,16 +1332,28 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
|
||||
private void displayMainAccount(){
|
||||
defaultAccount.setVisibility(View.VISIBLE);
|
||||
defaultAccount = (RelativeLayout) findViewById(R.id.default_account);
|
||||
ImageView status = (ImageView) defaultAccount.findViewById(R.id.status_led);
|
||||
TextView address = (TextView) defaultAccount.findViewById(R.id.address);
|
||||
TextView displayName = (TextView) defaultAccount.findViewById(R.id.display_name);
|
||||
|
||||
LinphoneProxyConfig proxy = LinphoneManager.getLc().getDefaultProxyConfig();
|
||||
|
||||
LinphoneProxyConfig proxy = LinphoneManager.getLc().getDefaultProxyConfig();
|
||||
if(proxy == null) {
|
||||
displayName.setText(getString(R.string.no_account));
|
||||
status.setVisibility(View.GONE);
|
||||
|
||||
defaultAccount.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
LinphoneActivity.instance().displayAccountSettings(0);
|
||||
openOrCloseSideMenu(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
address.setText(proxy.getAddress().asStringUriOnly());
|
||||
displayName.setText(LinphoneUtils.getAddressDisplayName(proxy.getAddress()));
|
||||
status.setImageResource(getStatusIconResource(proxy.getState()));
|
||||
status.setVisibility(View.VISIBLE);
|
||||
|
||||
defaultAccount.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
|
@ -1351,6 +1363,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshAccounts(){
|
||||
if(LinphoneManager.getLc().getProxyConfigList().length > 1) {
|
||||
|
@ -1373,11 +1386,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
accountsList = (ListView) findViewById(R.id.accounts_list);
|
||||
defaultAccount = (RelativeLayout) findViewById(R.id.default_account);
|
||||
|
||||
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
|
||||
displayMainAccount();
|
||||
} else {
|
||||
defaultAccount.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
refreshAccounts();
|
||||
}
|
||||
|
@ -1424,7 +1433,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
view = getLayoutInflater().inflate(R.layout.accounts, parent, false);
|
||||
}
|
||||
|
||||
ImageView status = (ImageView) view.findViewById(R.id.statusLed);
|
||||
ImageView status = (ImageView) view.findViewById(R.id.status_led);
|
||||
TextView address = (TextView) view.findViewById(R.id.address);
|
||||
String sipAddress = lpc.getAddress().asStringUriOnly();
|
||||
|
||||
|
|
Loading…
Reference in a new issue