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) {
|
||||
contact = (Contact) getArguments().getSerializable("Contact");
|
||||
isNewContact = false;
|
||||
contactID = Integer.parseInt(contact.getID());
|
||||
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,53 +181,16 @@ public class EditContactFragment extends Fragment {
|
|||
|
||||
if (contact != null) {
|
||||
for (String numberOrAddress : contact.getNumerosOrAddresses()) {
|
||||
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)) {
|
||||
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);
|
||||
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);
|
||||
|
@ -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) {
|
||||
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);
|
||||
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