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.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
|
@ -88,6 +89,8 @@ public class Contact implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getNumerosOrAddresses() {
|
public List<String> getNumerosOrAddresses() {
|
||||||
|
if (numerosOrAddresses == null)
|
||||||
|
numerosOrAddresses = new ArrayList<String>();
|
||||||
return numerosOrAddresses;
|
return numerosOrAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,15 +39,22 @@ public class EditContactFragment extends Fragment {
|
||||||
private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
||||||
private ArrayList<ContentProviderOperation> ops;
|
private ArrayList<ContentProviderOperation> ops;
|
||||||
private int firstSipAddressIndex = -1;
|
private int firstSipAddressIndex = -1;
|
||||||
|
private String newSipOrNumberToAdd;
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
this.inflater = inflater;
|
this.inflater = inflater;
|
||||||
|
|
||||||
contact = null;
|
contact = null;
|
||||||
if (getArguments() != null && getArguments().getSerializable("Contact") != null) {
|
if (getArguments() != null) {
|
||||||
contact = (Contact) getArguments().getSerializable("Contact");
|
if (getArguments().getSerializable("Contact") != null) {
|
||||||
isNewContact = false;
|
contact = (Contact) getArguments().getSerializable("Contact");
|
||||||
contactID = Integer.parseInt(contact.getID());
|
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);
|
view = inflater.inflate(R.layout.edit_contact, container, false);
|
||||||
|
@ -174,53 +181,16 @@ public class EditContactFragment extends Fragment {
|
||||||
|
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
for (String numberOrAddress : contact.getNumerosOrAddresses()) {
|
for (String numberOrAddress : contact.getNumerosOrAddresses()) {
|
||||||
final boolean isSip = numberOrAddress.startsWith("sip:");
|
View view = displayNumberOrAddress(controls, numberOrAddress);
|
||||||
if (isSip) {
|
if (view != null)
|
||||||
if (firstSipAddressIndex == -1) {
|
controls.addView(view);
|
||||||
firstSipAddressIndex = controls.getChildCount();
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
final NewOrUpdatedNumberOrAddress nounoa = new NewOrUpdatedNumberOrAddress(numberOrAddress, isSip);
|
|
||||||
numbersAndAddresses.add(nounoa);
|
|
||||||
|
|
||||||
final View view = inflater.inflate(R.layout.contact_edit_row, null);
|
|
||||||
|
|
||||||
final EditText noa = (EditText) view.findViewById(R.id.numoraddr);
|
|
||||||
noa.setInputType(isSip ? InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS : InputType.TYPE_CLASS_PHONE);
|
|
||||||
noa.setText(numberOrAddress);
|
|
||||||
noa.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
nounoa.setNewNumberOrAddress(noa.getText().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ImageView delete = (ImageView) view.findViewById(R.id.delete);
|
|
||||||
delete.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
nounoa.delete();
|
|
||||||
numbersAndAddresses.remove(nounoa);
|
|
||||||
view.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
controls.addView(view);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (newSipOrNumberToAdd != null) {
|
||||||
|
View view = displayNumberOrAddress(controls, newSipOrNumberToAdd);
|
||||||
|
if (view != null)
|
||||||
|
controls.addView(view);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isNewContact) {
|
if (!isNewContact) {
|
||||||
deleteContact = inflater.inflate(R.layout.contact_delete_button, null);
|
deleteContact = inflater.inflate(R.layout.contact_delete_button, null);
|
||||||
|
@ -246,6 +216,53 @@ public class EditContactFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private View displayNumberOrAddress(final TableLayout controls, String numberOrAddress) {
|
||||||
|
final boolean isSip = numberOrAddress.startsWith("sip:");
|
||||||
|
if (isSip) {
|
||||||
|
if (firstSipAddressIndex == -1) {
|
||||||
|
firstSipAddressIndex = controls.getChildCount();
|
||||||
|
}
|
||||||
|
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)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final NewOrUpdatedNumberOrAddress nounoa = new NewOrUpdatedNumberOrAddress(numberOrAddress, isSip);
|
||||||
|
numbersAndAddresses.add(nounoa);
|
||||||
|
|
||||||
|
final View view = inflater.inflate(R.layout.contact_edit_row, null);
|
||||||
|
|
||||||
|
final EditText noa = (EditText) view.findViewById(R.id.numoraddr);
|
||||||
|
noa.setInputType(isSip ? InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS : InputType.TYPE_CLASS_PHONE);
|
||||||
|
noa.setText(numberOrAddress);
|
||||||
|
noa.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
nounoa.setNewNumberOrAddress(noa.getText().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ImageView delete = (ImageView) view.findViewById(R.id.delete);
|
||||||
|
delete.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
nounoa.delete();
|
||||||
|
numbersAndAddresses.remove(nounoa);
|
||||||
|
view.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
private void addEmptyRowToAllowNewNumberOrAddress(final TableLayout controls, final boolean isSip) {
|
private void addEmptyRowToAllowNewNumberOrAddress(final TableLayout controls, final boolean isSip) {
|
||||||
final View view = inflater.inflate(R.layout.contact_add_row, null);
|
final View view = inflater.inflate(R.layout.contact_add_row, null);
|
||||||
|
|
||||||
|
|
|
@ -1188,7 +1188,9 @@ public class LinphoneActivity extends FragmentActivity implements
|
||||||
Intent intent = Compatibility.prepareAddContactIntent(displayName, sipUri);
|
Intent intent = Compatibility.prepareAddContactIntent(displayName, sipUri);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
} 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