.
This commit is contained in:
@@ -470,7 +470,27 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
if (today_date == selected_date) {
|
||||
if (reminderResult.reminder_marked != null){
|
||||
// already marked
|
||||
return;
|
||||
// now checking if it is today user has marked it done
|
||||
// if not, we shall allow them to mark it done for today
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
|
||||
try {
|
||||
Date routine_date = sdf.parse(reminderResult.reminder_marked);
|
||||
if (routine_date == null) {
|
||||
throw new Exception("Cannot parse routine marked date from Backend");
|
||||
}
|
||||
|
||||
if (today_date == routine_date.getDate()){
|
||||
// It is today when user has marked it done
|
||||
// Thus, not allowing them to mark it done again
|
||||
|
||||
Toast.makeText(requireContext(), "Cannot be undone.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
AppUtil.showAlert(requireContext(),
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.databinding.RoutineFragmentBinding;
|
||||
import com.ssb.simplitend.patientprofile.ProfileContracts;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.AddReminderFragment;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.WeekDayViewHolder;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineAdapter;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
@@ -29,6 +28,7 @@ import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineViewModel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -428,7 +428,27 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
if (today_date == selected_date) {
|
||||
if (routineDetails.routine_marked != null){
|
||||
// already marked
|
||||
return;
|
||||
// now checking if it is today user has marked it done
|
||||
// if not, we shall allow them to mark it done for today
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
|
||||
try {
|
||||
Date routine_date = sdf.parse(routineDetails.routine_marked);
|
||||
if (routine_date == null) {
|
||||
throw new Exception("Cannot parse routine marked date from Backend");
|
||||
}
|
||||
|
||||
if (today_date == routine_date.getDate()){
|
||||
// It is today when user has marked it done
|
||||
// Thus, not allowing them to mark it done again
|
||||
|
||||
Toast.makeText(requireContext(), "Cannot be undone.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
AppUtil.showAlert(requireContext(),
|
||||
|
||||
@@ -140,7 +140,6 @@ public class AddContactFragment extends Fragment implements WelcomeContracts.Con
|
||||
if (contactData.id == -1){
|
||||
// a new contact should be added
|
||||
|
||||
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Select contact",
|
||||
"Add from contacts or manually?",
|
||||
|
||||
@@ -20,6 +20,7 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.databinding.ContactInfoFragmentBinding;
|
||||
@@ -27,11 +28,22 @@ import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.Contact
|
||||
import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeContracts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ContactInfoFragment extends Fragment implements WelcomeContracts.DeleteContactInterface {
|
||||
|
||||
// view binding
|
||||
protected ContactInfoFragmentBinding binding;
|
||||
|
||||
/*
|
||||
This flag defines weather user want to connect with selected phone number
|
||||
by CALLING OR MESSAGING THEM
|
||||
0 : CALLING
|
||||
1 : MESSAGING
|
||||
*/
|
||||
private int CONTACT_BY = 0;
|
||||
|
||||
public static final String CONTACT_DATA_KEY = "contact_key";
|
||||
|
||||
private ContactData contactData;
|
||||
@@ -40,6 +52,8 @@ public class ContactInfoFragment extends Fragment implements WelcomeContracts.De
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
private ArrayList<String> contactLIst;
|
||||
|
||||
public ContactInfoFragment() {
|
||||
// required empty const.
|
||||
}
|
||||
@@ -72,17 +86,34 @@ public class ContactInfoFragment extends Fragment implements WelcomeContracts.De
|
||||
}
|
||||
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
contactLIst = new ArrayList<>();
|
||||
|
||||
binding.phoneSpinner.setIsFocusable(true);
|
||||
binding.phoneSpinner.setDismissWhenNotifiedItemSelected(true);
|
||||
binding.phoneSpinner.setLifecycleOwner(this);
|
||||
|
||||
binding.phoneSpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
|
||||
if (t1 == null) return;
|
||||
|
||||
if (CONTACT_BY == 0){
|
||||
callNumber(t1);
|
||||
}else{
|
||||
messageNumber(t1);
|
||||
}
|
||||
});
|
||||
|
||||
loadUserData();
|
||||
|
||||
}
|
||||
|
||||
private void loadUserData() {
|
||||
Glide.with(requireContext())
|
||||
.load(AppUtil.IMAGE_BASE_URL + contactData.contact_photo)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(R.drawable.ic_contact)
|
||||
.fitCenter().into(binding.image);
|
||||
if (contactData.contact_photo != null){
|
||||
Glide.with(requireContext())
|
||||
.load(AppUtil.IMAGE_BASE_URL + contactData.contact_photo)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(R.drawable.ic_contact)
|
||||
.fitCenter().into(binding.image);
|
||||
}
|
||||
|
||||
binding.name.setText(contactData.first_name);
|
||||
binding.phoneNumber.setText(contactData.phone_number);
|
||||
@@ -105,6 +136,15 @@ public class ContactInfoFragment extends Fragment implements WelcomeContracts.De
|
||||
binding.relationship.setText(contactData.relationship);
|
||||
}
|
||||
|
||||
contactLIst.add(contactData.phone_number);
|
||||
|
||||
if (contactData.extra_phone_numbers != null){
|
||||
String[] extra_numbers = contactData.extra_phone_numbers.split(",");
|
||||
contactLIst.addAll(Arrays.asList(extra_numbers));
|
||||
}
|
||||
|
||||
// configuring contact spinner
|
||||
binding.phoneSpinner.setItems(contactLIst);
|
||||
|
||||
}
|
||||
|
||||
@@ -163,21 +203,45 @@ public class ContactInfoFragment extends Fragment implements WelcomeContracts.De
|
||||
});
|
||||
|
||||
binding.callBtn.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel",
|
||||
contactData.phone_number.replace(" ", ""),
|
||||
null));
|
||||
startActivity(intent);
|
||||
CONTACT_BY = 0;
|
||||
|
||||
if (contactLIst != null){
|
||||
if (contactLIst.size() == 1){
|
||||
callNumber(contactData.phone_number);
|
||||
}else{
|
||||
binding.phoneSpinner.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
binding.messageBtn.setOnClickListener(v -> {
|
||||
Uri uri = Uri.parse("smsto:"+contactData.phone_number.replace(" ", ""));
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
|
||||
// intent.putExtra("sms_body", "The SMS text");
|
||||
startActivity(intent);
|
||||
CONTACT_BY = 1;
|
||||
|
||||
if (contactLIst != null){
|
||||
if (contactLIst.size() == 1){
|
||||
messageNumber(contactData.phone_number);
|
||||
}else{
|
||||
binding.phoneSpinner.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void callNumber(String phone_number){
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel",
|
||||
phone_number,
|
||||
null));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void messageNumber(String phone_number){
|
||||
Uri uri = Uri.parse("smsto:" + phone_number);
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
|
||||
// intent.putExtra("sms_body", "The SMS text");
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContactDelete() {
|
||||
progressDialog.dismiss();
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.ssb.simplitend.welcome.welcomepatient.fragments.contacts;
|
||||
import static com.ssb.simplitend.apputils.RetrofitHelper.CREATE_CONTACT;
|
||||
import static com.ssb.simplitend.apputils.RetrofitHelper.UPDATE_CONTACT;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@@ -12,6 +14,7 @@ import android.os.Handler;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
@@ -32,6 +35,7 @@ import com.github.dhaval2404.imagepicker.ImagePicker;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import com.skydoves.powerspinner.PowerSpinnerView;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.databinding.CreateContactViewHolderBinding;
|
||||
@@ -128,9 +132,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
to_edit = bundle.getBoolean(TO_EDIT_KEY, false);
|
||||
|
||||
if (to_edit) {
|
||||
|
||||
setLayoutDetails(getString(R.string.edit_contact), getString(R.string.change_photo), getString(R.string.save));
|
||||
|
||||
} else {
|
||||
setLayoutDetails(getString(R.string.create_contact), getString(R.string.add_photo), getString(R.string.create_contact));
|
||||
}
|
||||
@@ -138,6 +140,8 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
if (bundle.getSerializable(CONTACT_KEY) != null) {
|
||||
contactData = (ContactData) bundle.getSerializable(CONTACT_KEY);
|
||||
setDetails();
|
||||
}else{
|
||||
addContactView("", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,35 +181,40 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
private void clickEvents() {
|
||||
|
||||
binding.backBtn.setOnClickListener(v -> {
|
||||
if (getActivity() != null){
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
});
|
||||
|
||||
binding.nextBtn.setOnClickListener(v -> {
|
||||
|
||||
|
||||
String[] phone_numbers = getAllPhoneNumbers();
|
||||
|
||||
Log.d(TAG, "clickEvents: ");
|
||||
if (!phone_numbers[3].equals("0")){
|
||||
Toast.makeText(requireContext(), "Please select a default contact.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// if (allOkay()) {
|
||||
// if (to_edit) {
|
||||
// // editing existing contact
|
||||
//
|
||||
// AppUtil.showSOSDecision(requireContext(),
|
||||
// getString(R.string.make_changes),
|
||||
// getString(R.string.yes),
|
||||
// getString(R.string.no),
|
||||
// yes -> {
|
||||
// createEditContact("While we update your contact details.", true, UPDATE_CONTACT + contactData.contact_id);
|
||||
// }, no -> {
|
||||
//
|
||||
// });
|
||||
//
|
||||
// } else {
|
||||
// createEditContact("While we save the contact details.", false, CREATE_CONTACT);
|
||||
// }
|
||||
// }
|
||||
if (allOkay() && phone_numbers[2].equals("0")) {
|
||||
if (to_edit) {
|
||||
// editing existing contact
|
||||
|
||||
AppUtil.showSOSDecision(requireContext(),
|
||||
getString(R.string.make_changes),
|
||||
getString(R.string.yes),
|
||||
getString(R.string.no),
|
||||
yes -> {
|
||||
createEditContact("While we update your contact details.", true,
|
||||
UPDATE_CONTACT + contactData.contact_id, phone_numbers);
|
||||
}, no -> {
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
createEditContact("While we save the contact details.", false,
|
||||
CREATE_CONTACT, phone_numbers);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -225,7 +234,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
}
|
||||
|
||||
private void createEditContact(String progressMsg, boolean edit_contact,
|
||||
String URL) {
|
||||
String URL, String[] phoneNumbers) {
|
||||
|
||||
progressDialog.setTitle("Please wait");
|
||||
progressDialog.setMessage(progressMsg);
|
||||
@@ -236,10 +245,12 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
RequestBody user_first_name = RequestBody.create(binding.name.getText().toString().trim(), MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("full_name", user_first_name);
|
||||
|
||||
RequestBody contact_number_part = RequestBody.create("contact_number", MediaType.parse("text/plain;charset=utf-8"));
|
||||
|
||||
RequestBody contact_number_part = RequestBody.create(phoneNumbers[0], MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("contact_number", contact_number_part);
|
||||
|
||||
RequestBody extra_contact_number_part = RequestBody.create(phoneNumbers[1], MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("extra_phone_numbers", extra_contact_number_part);
|
||||
|
||||
RequestBody email_ = RequestBody.create(binding.email.getText().toString().trim(), MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("email_address", email_);
|
||||
|
||||
@@ -280,30 +291,6 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.name.setError("Required");
|
||||
}
|
||||
|
||||
// if (binding.phoneNumber.getText().toString().trim().isEmpty() ||
|
||||
// binding.phoneNumber.getText().toString().trim().length() < 10) {
|
||||
// allOkay = false;
|
||||
// binding.phoneNumber.setError("Invalid");
|
||||
// }else if (binding.countryCodes.getSelectedIndex() == -1||
|
||||
// binding.countryCodes.getSelectedIndex() >= countryCodeList.size()){
|
||||
// allOkay = false;
|
||||
// Toast.makeText(requireContext(), "Select a coutnry code.", Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
// else{
|
||||
// // validating phone number
|
||||
// try {
|
||||
// Phonenumber.PhoneNumber phone_number = PhoneNumberUtil.getInstance().parse(countryCodeList.get(binding.countryCodes.getSelectedIndex())+
|
||||
// binding.phoneNumber.getText().toString(), "US");
|
||||
//
|
||||
// if (!PhoneNumberUtil.getInstance().isValidNumber(phone_number)) {
|
||||
// binding.phoneNumber.setError("Invalid phone number");
|
||||
// allOkay = false;
|
||||
// }
|
||||
// } catch (NumberParseException e) {
|
||||
// // do nothing as we couldn't validate phone number
|
||||
// }
|
||||
// }
|
||||
|
||||
if (mustBeeCaregiver && binding.email.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.email.setError("Required");
|
||||
@@ -325,11 +312,11 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
Toast.makeText(requireActivity(), "Contact updated successFully.", Toast.LENGTH_SHORT).show();
|
||||
try {
|
||||
Navigation.findNavController(binding.getRoot()).popBackStack(R.id.addContactFragment, false);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// this fragment is not only opened by the welcome_nav_graph
|
||||
try {
|
||||
getParentFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
}catch (Exception e2){
|
||||
} catch (Exception e2) {
|
||||
// user may be out of context
|
||||
}
|
||||
}
|
||||
@@ -398,7 +385,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
progressDialog.dismiss();
|
||||
|
||||
Activity activity = getActivity();
|
||||
if (activity != null){
|
||||
if (activity != null) {
|
||||
activity.onBackPressed();
|
||||
}
|
||||
|
||||
@@ -413,7 +400,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
|
||||
try {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_createContactFragment_to_addContactFragment);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// this fragment is opened from outside of welcome_nav_graph
|
||||
try {
|
||||
getParentFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
@@ -461,7 +448,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
}
|
||||
|
||||
private void setDetails() {
|
||||
if (contactData == null){
|
||||
if (contactData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -473,8 +460,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
.fitCenter().into(binding.image);
|
||||
}
|
||||
|
||||
if (contactData.first_name != null)
|
||||
{
|
||||
if (contactData.first_name != null) {
|
||||
binding.name.setText(contactData.first_name);
|
||||
}
|
||||
|
||||
@@ -500,23 +486,27 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.caregiverCheckView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (contactData.phone_number != null){
|
||||
addContactView(contactData.phone_number, true);
|
||||
}
|
||||
|
||||
// adding contacts to Contact_rv
|
||||
if (contactData.extra_phone_numbers != null && !contactData.extra_phone_numbers.isEmpty()){
|
||||
if (contactData.extra_phone_numbers != null && !contactData.extra_phone_numbers.isEmpty()) {
|
||||
String[] phone_numbers = contactData.extra_phone_numbers.split(",");
|
||||
|
||||
for (String phone_number: phone_numbers){
|
||||
addContactView(phone_number);
|
||||
for (String phone_number : phone_numbers) {
|
||||
addContactView(phone_number, phone_numbers.length == 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addContactView(String contact_number){
|
||||
private void addContactView(String contact_number, boolean id_default) {
|
||||
CreateContactViewHolderBinding contact_binding = CreateContactViewHolderBinding.inflate(getLayoutInflater());
|
||||
|
||||
contact_binding.countryCodes.setItems(countryCodeList);
|
||||
contact_binding.countryCodes.setIsFocusable(true);
|
||||
contact_binding.countryCodes.setDismissWhenNotifiedItemSelected(true);
|
||||
contact_binding.createCountryCodes.setItems(countryCodeList);
|
||||
contact_binding.createCountryCodes.setIsFocusable(true);
|
||||
contact_binding.createCountryCodes.setDismissWhenNotifiedItemSelected(true);
|
||||
|
||||
// phone number formatting
|
||||
// to deal with input pasting in the edit text
|
||||
@@ -525,10 +515,10 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
|
||||
String country_code;
|
||||
|
||||
if (contact_binding.countryCodes.getSelectedIndex() == -1) {
|
||||
if (contact_binding.createCountryCodes.getSelectedIndex() == -1) {
|
||||
country_code = "+1";
|
||||
} else {
|
||||
country_code = countryCodeList.get(contact_binding.countryCodes.getSelectedIndex());
|
||||
country_code = countryCodeList.get(contact_binding.createCountryCodes.getSelectedIndex());
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -545,7 +535,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
countryCodeList.add(country_code);
|
||||
}
|
||||
|
||||
contact_binding.countryCodes.selectItemByIndex(countryCodeList.indexOf(country_code));
|
||||
contact_binding.createCountryCodes.selectItemByIndex(countryCodeList.indexOf(country_code));
|
||||
|
||||
if (phone_number_str.length() > 10) {
|
||||
// pasted number length is greater than 10
|
||||
@@ -565,29 +555,44 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
contact_binding.createPhoneNumber.setFilters(new InputFilter[]{phoneFilter});
|
||||
|
||||
contact_binding.createPhoneNumber.setText(contact_number);
|
||||
|
||||
|
||||
contact_binding.defaultCheck.setOnClickListener(v -> {
|
||||
if (!contact_binding.defaultCheck.isSelected()){
|
||||
if (!contact_binding.defaultCheck.isSelected()) {
|
||||
selectDefaultContact(binding.contactTable.indexOfChild(contact_binding.getRoot()));
|
||||
}
|
||||
});
|
||||
|
||||
contact_binding.delete.setOnClickListener(v -> {
|
||||
if (binding.contactTable.getChildCount() == 1){
|
||||
Toast.makeText(requireContext(), "Cannot be deleted", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
binding.contactTable.removeView(contact_binding.getRoot());
|
||||
}catch (Exception e){
|
||||
Toast.makeText(requireContext(), "Couldn't delete contact.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
contact_binding.defaultCheck.setSelected(id_default);
|
||||
|
||||
binding.contactTable.addView(contact_binding.getRoot());
|
||||
}
|
||||
|
||||
private void selectDefaultContact(int index){
|
||||
|
||||
private void selectDefaultContact(int index) {
|
||||
int count = binding.contactTable.getChildCount();
|
||||
if (index >= 0 && index < count){
|
||||
if (index >= 0 && index < count) {
|
||||
// unselecting all other editBoxes
|
||||
for (int i = 0; i < count; i++) {
|
||||
View view = binding.contactTable.getChildAt(i);
|
||||
if (view != null){
|
||||
if (view != null) {
|
||||
ImageButton default_check = view.findViewById(R.id.default_check);
|
||||
if (default_check != null){
|
||||
if (default_check != null) {
|
||||
|
||||
if (i == index){
|
||||
if (i == index) {
|
||||
default_check.setSelected(true);
|
||||
}else{
|
||||
} else {
|
||||
default_check.setSelected(false);
|
||||
}
|
||||
|
||||
@@ -601,23 +606,56 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
returns a string array of size 2
|
||||
index 0: default phone number
|
||||
index 1: extra phone number separated by ','
|
||||
index 2: error code
|
||||
index 3: if default number is selected or not 0 = default number selected and vice versa
|
||||
*/
|
||||
public String[] getAllPhoneNumbers(){
|
||||
String[] phone_numbers = {"", ""};
|
||||
public String[] getAllPhoneNumbers() {
|
||||
String[] phone_numbers = {"", "", "0", "1"};
|
||||
int count = binding.contactTable.getChildCount();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
View view = binding.contactTable.getChildAt(i);
|
||||
if (view != null){
|
||||
if (view != null) {
|
||||
ImageButton default_check = view.findViewById(R.id.default_check);
|
||||
EditText phone_input = view.findViewById(R.id.create_phone_number);
|
||||
|
||||
if (default_check != null && phone_input != null){
|
||||
// getting country code
|
||||
PowerSpinnerView countryCodeView = view.findViewById(R.id.create_country_codes);
|
||||
String countryCode = "+1";
|
||||
|
||||
if (default_check.isSelected()){
|
||||
phone_numbers[0] = phone_input.getText().toString();
|
||||
}else{
|
||||
phone_numbers[1] += (phone_input.getText().toString() + ",");
|
||||
if (countryCodeView != null) {
|
||||
int selected_cc_index = countryCodeView.getSelectedIndex();
|
||||
if (selected_cc_index > -1 && selected_cc_index < countryCodeList.size()) {
|
||||
countryCode = countryCodeList.get(selected_cc_index);
|
||||
}
|
||||
}
|
||||
|
||||
if (default_check != null && phone_input != null) {
|
||||
|
||||
phone_input.setError(null);
|
||||
|
||||
if (phone_input.getText().toString().trim().isEmpty()) {
|
||||
phone_input.setError("Cannot be empty");
|
||||
phone_numbers[2] = "1";
|
||||
}
|
||||
|
||||
if (default_check.isSelected()) {
|
||||
phone_numbers[0] = (countryCode + phone_input.getText().toString());
|
||||
phone_numbers[3] = "0";
|
||||
|
||||
// validating phone number
|
||||
try {
|
||||
Phonenumber.PhoneNumber phone_number = PhoneNumberUtil.getInstance().parse(phone_numbers[0], "US");
|
||||
if (!PhoneNumberUtil.getInstance().isValidNumber(phone_number)) {
|
||||
phone_input.setError("Invalid number");
|
||||
phone_numbers[2] = "1";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// do nothing as we couldn't validate phone number
|
||||
}
|
||||
|
||||
} else {
|
||||
phone_numbers[1] += (countryCode + phone_input.getText().toString() + ",");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -628,6 +666,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
int last_index = Math.max(phone_numbers[1].length() - 1, 0);
|
||||
phone_numbers[1] = phone_numbers[1].substring(0, last_index);
|
||||
|
||||
|
||||
return phone_numbers;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user