Pre-fill add/edit contact form with number to add
This commit is contained in:
parent
b3b97ad8e0
commit
ed19f7305c
3 changed files with 72 additions and 50 deletions
|
@ -18,6 +18,7 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
|
@ -88,6 +89,8 @@ public class Contact implements Serializable {
|
|||
}
|
||||
|
||||
public List<String> getNumerosOrAddresses() {
|
||||
if (numerosOrAddresses == null)
|
||||
numerosOrAddresses = new ArrayList<String>();
|
||||
return numerosOrAddresses;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,15 +39,22 @@ public class EditContactFragment extends Fragment {
|
|||
private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
||||
private ArrayList<ContentProviderOperation> ops;
|
||||
private int firstSipAddressIndex = -1;
|
||||
private String newSipOrNumberToAdd;
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
this.inflater = inflater;
|
||||
|
||||
contact = null;
|
||||
if (getArguments() != null && getArguments().getSerializable("Contact") != null) {
|
||||
if (getArguments() != null) {
|
||||
if (getArguments().getSerializable("Contact") != null) {
|
||||
contact = (Contact) getArguments().getSerializable("Contact");
|
||||
isNewContact = false;
|
||||
contactID = Integer.parseInt(contact.getID());
|
||||
contact.refresh(getActivity().getContentResolver());
|
||||
}
|
||||
if (getArguments().getString("NewSipAdress") != null) {
|
||||
newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
|
||||
}
|
||||
}
|
||||
|
||||
view = inflater.inflate(R.layout.edit_contact, container, false);
|
||||
|
@ -174,6 +181,42 @@ public class EditContactFragment extends Fragment {
|
|||
|
||||
if (contact != null) {
|
||||
for (String numberOrAddress : contact.getNumerosOrAddresses()) {
|
||||
View view = displayNumberOrAddress(controls, numberOrAddress);
|
||||
if (view != null)
|
||||
controls.addView(view);
|
||||
}
|
||||
}
|
||||
if (newSipOrNumberToAdd != null) {
|
||||
View view = displayNumberOrAddress(controls, newSipOrNumberToAdd);
|
||||
if (view != null)
|
||||
controls.addView(view);
|
||||
}
|
||||
|
||||
if (!isNewContact) {
|
||||
deleteContact = inflater.inflate(R.layout.contact_delete_button, null);
|
||||
deleteContact.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
deleteExistingContact();
|
||||
LinphoneActivity.instance().removeContactFromLists(contact);
|
||||
LinphoneActivity.instance().displayContacts(false);
|
||||
}
|
||||
});
|
||||
controls.addView(deleteContact, controls.getChildCount());
|
||||
}
|
||||
|
||||
// Add one for phone numbers, one for SIP address
|
||||
if (!getResources().getBoolean(R.bool.hide_phone_numbers_in_editor)) {
|
||||
addEmptyRowToAllowNewNumberOrAddress(controls, false);
|
||||
}
|
||||
|
||||
if (!getResources().getBoolean(R.bool.hide_sip_addresses_in_editor)) {
|
||||
firstSipAddressIndex = controls.getChildCount() - 2; // Update the value to always display phone numbers before SIP accounts
|
||||
addEmptyRowToAllowNewNumberOrAddress(controls, true);
|
||||
}
|
||||
}
|
||||
|
||||
private View displayNumberOrAddress(final TableLayout controls, String numberOrAddress) {
|
||||
final boolean isSip = numberOrAddress.startsWith("sip:");
|
||||
if (isSip) {
|
||||
if (firstSipAddressIndex == -1) {
|
||||
|
@ -182,7 +225,7 @@ public class EditContactFragment extends Fragment {
|
|||
numberOrAddress = numberOrAddress.replace("sip:", "");
|
||||
}
|
||||
if ((getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) && !isSip) || (getResources().getBoolean(R.bool.hide_sip_addresses_in_editor) && isSip)) {
|
||||
continue;
|
||||
return null;
|
||||
}
|
||||
|
||||
final NewOrUpdatedNumberOrAddress nounoa = new NewOrUpdatedNumberOrAddress(numberOrAddress, isSip);
|
||||
|
@ -217,33 +260,7 @@ public class EditContactFragment extends Fragment {
|
|||
view.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
controls.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNewContact) {
|
||||
deleteContact = inflater.inflate(R.layout.contact_delete_button, null);
|
||||
deleteContact.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
deleteExistingContact();
|
||||
LinphoneActivity.instance().removeContactFromLists(contact);
|
||||
LinphoneActivity.instance().displayContacts(false);
|
||||
}
|
||||
});
|
||||
controls.addView(deleteContact, controls.getChildCount());
|
||||
}
|
||||
|
||||
// Add one for phone numbers, one for SIP address
|
||||
if (!getResources().getBoolean(R.bool.hide_phone_numbers_in_editor)) {
|
||||
addEmptyRowToAllowNewNumberOrAddress(controls, false);
|
||||
}
|
||||
|
||||
if (!getResources().getBoolean(R.bool.hide_sip_addresses_in_editor)) {
|
||||
firstSipAddressIndex = controls.getChildCount() - 2; // Update the value to always display phone numbers before SIP accounts
|
||||
addEmptyRowToAllowNewNumberOrAddress(controls, true);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private void addEmptyRowToAllowNewNumberOrAddress(final TableLayout controls, final boolean isSip) {
|
||||
|
|
|
@ -1188,7 +1188,9 @@ public class LinphoneActivity extends FragmentActivity implements
|
|||
Intent intent = Compatibility.prepareAddContactIntent(displayName, sipUri);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
changeCurrentFragment(FragmentsAvailable.EDIT_CONTACT, null);
|
||||
Bundle extras = new Bundle();
|
||||
extras.putSerializable("NewSipAdress", sipUri);
|
||||
changeCurrentFragment(FragmentsAvailable.EDIT_CONTACT, extras);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue