.
This commit is contained in:
@@ -40,7 +40,7 @@ public class FUAActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fua);
|
||||
|
||||
swBlock = (SwitchCompat) findViewById(R.id.swBlock);
|
||||
// swBlock = (SwitchCompat) findViewById(R.id.swBlock);
|
||||
rvApps = (RecyclerView) findViewById(R.id.rvApps);
|
||||
rvWhiteApps = (RecyclerView) findViewById(R.id.rv_white_apps);
|
||||
mySharedPref = new MySharedPref(FUAActivity.this);
|
||||
@@ -79,12 +79,12 @@ public class FUAActivity extends AppCompatActivity {
|
||||
rvWhiteApps.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
rvWhiteApps.setAdapter(whiteListAdapter);
|
||||
|
||||
swBlock.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
if (!isAccessibilityAppBlockingEnabled() && isChecked) {
|
||||
Intent accessibilityIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
startActivity(accessibilityIntent);
|
||||
}
|
||||
// swBlock.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
//
|
||||
// if (!isAccessibilityAppBlockingEnabled() && isChecked) {
|
||||
// Intent accessibilityIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
// startActivity(accessibilityIntent);
|
||||
// }
|
||||
//
|
||||
// // Intent serviceIntent = new Intent(getApplicationContext(), service.class);
|
||||
//// ContextCompat.startForegroundService(getApplicationContext(), serviceIntent);
|
||||
@@ -107,7 +107,7 @@ public class FUAActivity extends AppCompatActivity {
|
||||
// stopService(new Intent(MainActivity.this, OverlayService.class));
|
||||
// }*/
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
findViewById(R.id.done_btn).setOnClickListener(v -> {
|
||||
onBackPressed();
|
||||
@@ -162,7 +162,7 @@ public class FUAActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
swBlock.setChecked(isAccessibilityAppBlockingEnabled());
|
||||
// swBlock.setChecked(isAccessibilityAppBlockingEnabled());
|
||||
}
|
||||
|
||||
private List<AppList> getInstalledApps() {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MySharedPref {
|
||||
public void setArrayList(String key, ArrayList<String> list) {
|
||||
Set<String> set = new HashSet<>(list);
|
||||
prefsEditor.putStringSet(key, set);
|
||||
prefsEditor.commit();
|
||||
prefsEditor.apply();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,56 +49,66 @@ public class ContactListAdapter extends ListAdapter<ArrayList<Contact>, ContactL
|
||||
|
||||
ArrayList<Contact> contacts = getItem(position);
|
||||
|
||||
if (contacts == null || contacts.isEmpty()) return;
|
||||
|
||||
holder.binding.name.setLifecycleOwner(holder.binding.name.getLifecycleOwner());
|
||||
holder.binding.name.setDismissWhenNotifiedItemSelected(true);
|
||||
holder.binding.name.setIsFocusable(true);
|
||||
|
||||
if (contacts.size() > 1){
|
||||
// need to show dropdown menu
|
||||
ArrayList<String> phone_list = new ArrayList<>();
|
||||
|
||||
for (Contact contact :
|
||||
contacts) {
|
||||
if (contact.first_name == null) return;
|
||||
|
||||
phone_list.add(contact.phone_number);
|
||||
}
|
||||
|
||||
holder.binding.name.setItems(phone_list);
|
||||
|
||||
}
|
||||
|
||||
holder.binding.name.setOnClickListener(v -> {
|
||||
if (contactClickListener != null){
|
||||
|
||||
if (contacts.size() == 1){
|
||||
// only one item
|
||||
contactClickListener.onClick(contacts.get(0));
|
||||
}else{
|
||||
// more than one item
|
||||
// thus, show dropdown menu
|
||||
holder.binding.name.show();
|
||||
}
|
||||
if (contactClickListener != null && contacts != null){
|
||||
Contact contact = new Contact(contacts);
|
||||
|
||||
contactClickListener.onClick(contact);
|
||||
}
|
||||
});
|
||||
|
||||
holder.binding.name.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
|
||||
// below code is about showing a dropdown of multiple contact number menu when user clicks on one of the contact
|
||||
|
||||
if (i1 >= contacts.size()) return;
|
||||
|
||||
Contact contact = contacts.get(i1);
|
||||
|
||||
if (contact != null){
|
||||
holder.binding.name.setText(contact.first_name);
|
||||
|
||||
if (contactClickListener != null){
|
||||
contactClickListener.onClick(contact);
|
||||
}
|
||||
}
|
||||
});
|
||||
// if (contacts == null || contacts.isEmpty()) return;
|
||||
//
|
||||
// holder.binding.name.setLifecycleOwner(holder.binding.name.getLifecycleOwner());
|
||||
// holder.binding.name.setDismissWhenNotifiedItemSelected(true);
|
||||
// holder.binding.name.setIsFocusable(true);
|
||||
//
|
||||
// if (contacts.size() > 1){
|
||||
// // need to show dropdown menu
|
||||
// ArrayList<String> phone_list = new ArrayList<>();
|
||||
//
|
||||
// for (Contact contact :
|
||||
// contacts) {
|
||||
// if (contact.first_name == null) return;
|
||||
//
|
||||
// phone_list.add(contact.phone_number);
|
||||
// }
|
||||
//
|
||||
// holder.binding.name.setItems(phone_list);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// holder.binding.name.setOnClickListener(v -> {
|
||||
// if (contactClickListener != null){
|
||||
//
|
||||
// if (contacts.size() == 1){
|
||||
// // only one item
|
||||
// contactClickListener.onClick(contacts.get(0));
|
||||
// }else{
|
||||
// // more than one item
|
||||
// // thus, show dropdown menu
|
||||
// holder.binding.name.show();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// holder.binding.name.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
|
||||
//
|
||||
// if (i1 >= contacts.size()) return;
|
||||
//
|
||||
// Contact contact = contacts.get(i1);
|
||||
//
|
||||
// if (contact != null){
|
||||
// holder.binding.name.setText(contact.first_name);
|
||||
//
|
||||
// if (contactClickListener != null){
|
||||
// contactClickListener.onClick(contact);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
public void setContactClickListener(OnContactClickListener contactClickListener) {
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.ssb.simplitend.welcome.welcomepatient.fragments.contacts;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import com.ssb.simplitend.databinding.CreateContactViewHolderBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class CreateContactAdapter extends ListAdapter<String, CreateContactAdapter.CreateContactViewHolder> {
|
||||
|
||||
private static final DiffUtil.ItemCallback<String> DIFF_UTIL = new DiffUtil.ItemCallback<String>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull String oldItem, @NonNull String newItem) {
|
||||
return oldItem.equals(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull String oldItem, @NonNull String newItem) {
|
||||
return oldItem.equals(newItem);
|
||||
}
|
||||
};
|
||||
|
||||
private final ArrayList<String> countryCodeList;
|
||||
@NonNull
|
||||
private final List<String> changedContactList;
|
||||
|
||||
@NonNull
|
||||
private String default_phone_number;
|
||||
|
||||
public CreateContactAdapter(@NonNull ArrayList<String> countryCodeList, @NonNull String default_phone_number){
|
||||
super(DIFF_UTIL);
|
||||
this.countryCodeList = countryCodeList;
|
||||
this.default_phone_number = default_phone_number;
|
||||
this.changedContactList = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void setDefault_phone_number(@NonNull String default_phone_number) {
|
||||
this.default_phone_number = default_phone_number;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CreateContactViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
CreateContactViewHolderBinding binding = CreateContactViewHolderBinding.inflate(
|
||||
LayoutInflater.from(parent.getContext()),
|
||||
parent, false);
|
||||
|
||||
binding.countryCodes.setItems(countryCodeList);
|
||||
binding.countryCodes.setIsFocusable(true);
|
||||
binding.countryCodes.setDismissWhenNotifiedItemSelected(true);
|
||||
|
||||
return new CreateContactViewHolder(binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CreateContactViewHolder holder, int position) {
|
||||
holder.binding.phoneNumber.setText("");
|
||||
|
||||
if (position < 0 || position >= getItemCount()) return;
|
||||
|
||||
// input formatter for phone number
|
||||
InputFilter phoneFilter = (charSequence, i, i1, spanned, i2, i3) -> {
|
||||
String some = holder.binding.phoneNumber.getText().toString();
|
||||
String phone_number_str = charSequence.toString();
|
||||
|
||||
String country_code = null;
|
||||
|
||||
if (holder.binding.countryCodes.getSelectedIndex() != -1) {
|
||||
country_code = countryCodeList.get(holder.binding.countryCodes.getSelectedIndex());
|
||||
}
|
||||
|
||||
try {
|
||||
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
|
||||
Phonenumber.PhoneNumber phoneNumber = phoneNumberUtil.parse(charSequence, "US");
|
||||
|
||||
phone_number_str = String.valueOf(phoneNumber.getNationalNumber());
|
||||
country_code = "+" + phoneNumber.getCountryCode();
|
||||
} catch (Exception e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
if (country_code != null && !countryCodeList.contains(country_code)) {
|
||||
countryCodeList.add(country_code);
|
||||
}
|
||||
|
||||
if (country_code != null) {
|
||||
holder.binding.countryCodes.selectItemByIndex(countryCodeList.indexOf(country_code));
|
||||
}
|
||||
|
||||
if (phone_number_str.length() > 10) {
|
||||
// pasted number length is greater than 10
|
||||
return phone_number_str.substring(0, 10);
|
||||
}
|
||||
|
||||
String total_phone_number = holder.binding.phoneNumber.getText().toString() + phone_number_str;
|
||||
|
||||
if (total_phone_number.length() > 10) {
|
||||
// max length should be 10
|
||||
return "";
|
||||
} else {
|
||||
return phone_number_str;
|
||||
}
|
||||
};
|
||||
|
||||
holder.binding.phoneNumber.setFilters(new InputFilter[]{phoneFilter});
|
||||
|
||||
// Now setting the phone number and it will be automatically formatted with above filter
|
||||
holder.binding.phoneNumber.setText(getItem(position));
|
||||
|
||||
if (default_phone_number.equals(getItem(position))){
|
||||
holder.binding.defaultCheck.setSelected(true);
|
||||
}else{
|
||||
holder.binding.defaultCheck.setSelected(false);
|
||||
}
|
||||
|
||||
holder.binding.defaultCheck.setOnClickListener(v -> {
|
||||
if (!default_phone_number.equals(getItem(position))){
|
||||
default_phone_number = getItem(position);
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitList(@Nullable List<String> list) {
|
||||
super.submitList(list);
|
||||
if (list != null){
|
||||
this.changedContactList.clear();
|
||||
this.changedContactList.addAll(list);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CreateContactViewHolder extends RecyclerView.ViewHolder{
|
||||
public CreateContactViewHolderBinding binding;
|
||||
|
||||
public CreateContactViewHolder(@NonNull CreateContactViewHolderBinding binding){
|
||||
super(binding.getRoot());
|
||||
this.binding = binding;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -24,13 +23,11 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.github.dhaval2404.imagepicker.ImagePicker;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.databinding.CreateEditContactFragmentBinding;
|
||||
@@ -42,6 +39,7 @@ import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeContracts;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -87,6 +85,8 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
// Remote contact list
|
||||
protected List<ContactListResponse> contactList;
|
||||
|
||||
private CreateContactAdapter createContactAdapter;
|
||||
|
||||
public CreateContactFragment() {
|
||||
// required empty const.
|
||||
}
|
||||
@@ -113,69 +113,17 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
|
||||
// country code loading
|
||||
countryCodeList = contactViewModel.loadCountryCodeDropDown(requireContext());
|
||||
|
||||
binding.countryCodes.setLifecycleOwner(this);
|
||||
|
||||
binding.countryCodes.setItems(countryCodeList);
|
||||
|
||||
if (contactList == null) contactList = new ArrayList<>();
|
||||
if (!countryCodeList.contains("+1")) {
|
||||
countryCodeList.add("+1");
|
||||
}
|
||||
|
||||
binding.countryCodes.selectItemByIndex(countryCodeList.indexOf("+1"));
|
||||
|
||||
binding.countryCodes.setDismissWhenNotifiedItemSelected(true);
|
||||
|
||||
binding.countryCodes.setIsFocusable(true);
|
||||
createContactAdapter = new CreateContactAdapter(countryCodeList, "");
|
||||
binding.contactRv.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
binding.contactRv.setAdapter(createContactAdapter);
|
||||
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
|
||||
// phone number formatting
|
||||
// to deal with input pasting in the edit text
|
||||
InputFilter phoneFilter = (charSequence, i, i1, spanned, i2, i3) -> {
|
||||
String phone_number_str = charSequence.toString();
|
||||
|
||||
String country_code = null;
|
||||
|
||||
if (binding.countryCodes.getSelectedIndex() != -1) {
|
||||
country_code = countryCodeList.get(binding.countryCodes.getSelectedIndex());
|
||||
}
|
||||
|
||||
try {
|
||||
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
|
||||
Phonenumber.PhoneNumber phoneNumber = phoneNumberUtil.parse(charSequence, "US");
|
||||
|
||||
phone_number_str = String.valueOf(phoneNumber.getNationalNumber());
|
||||
country_code = "+" + phoneNumber.getCountryCode();
|
||||
} catch (Exception e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
if (country_code != null && !countryCodeList.contains(country_code)) {
|
||||
countryCodeList.add(country_code);
|
||||
}
|
||||
|
||||
if (country_code != null) {
|
||||
binding.countryCodes.selectItemByIndex(countryCodeList.indexOf(country_code));
|
||||
}
|
||||
|
||||
if (phone_number_str.length() > 10) {
|
||||
// pasted number length is greater than 10
|
||||
return phone_number_str.substring(0, 10);
|
||||
}
|
||||
|
||||
String total_phone_number = binding.phoneNumber.getText().toString() + phone_number_str;
|
||||
|
||||
if (total_phone_number.length() > 10) {
|
||||
// max length should be 10
|
||||
return "";
|
||||
} else {
|
||||
return phone_number_str;
|
||||
}
|
||||
};
|
||||
|
||||
binding.phoneNumber.setFilters(new InputFilter[]{phoneFilter});
|
||||
|
||||
Bundle bundle = getArguments();
|
||||
|
||||
if (bundle != null) {
|
||||
@@ -286,10 +234,7 @@ 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);
|
||||
|
||||
String contact_number = countryCodeList.get(binding.countryCodes.getSelectedIndex()) + " " +
|
||||
binding.phoneNumber.getText().toString();
|
||||
|
||||
RequestBody contact_number_part = RequestBody.create(contact_number, MediaType.parse("text/plain;charset=utf-8"));
|
||||
RequestBody contact_number_part = RequestBody.create("contact_number", MediaType.parse("text/plain;charset=utf-8"));
|
||||
|
||||
body.put("contact_number", contact_number_part);
|
||||
|
||||
@@ -333,57 +278,43 @@ 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 (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");
|
||||
}
|
||||
|
||||
if (binding.countryCodes.getSelectedIndex() == -1 && allOkay) {
|
||||
allOkay = false;
|
||||
Toast.makeText(requireContext(), "please select a country code", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
// if (binding.countryCodes.getSelectedIndex() == -1 && allOkay) {
|
||||
// allOkay = false;
|
||||
// Toast.makeText(requireContext(), "please select a country code", Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
|
||||
return allOkay;
|
||||
}
|
||||
|
||||
private boolean phoneAlreadyAdded() {
|
||||
|
||||
for (ContactListResponse contact : contactList) {
|
||||
String contact_number = countryCodeList.get(binding.countryCodes.getSelectedIndex()) + " " +
|
||||
binding.phoneNumber.getText().toString();
|
||||
|
||||
if (contact.contact_data.phone_number.equals(contact_number)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotoAddFragment(BottomSheetDialog bsd) {
|
||||
new Handler().postDelayed(() -> {
|
||||
@@ -528,6 +459,9 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
}
|
||||
|
||||
private void setDetails() {
|
||||
if (contactData == null){
|
||||
return;
|
||||
}
|
||||
|
||||
if (contactData.contact_photo != null) {
|
||||
Glide.with(requireContext())
|
||||
@@ -542,10 +476,6 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.name.setText(contactData.first_name);
|
||||
}
|
||||
|
||||
if (contactData.phone_number != null){
|
||||
binding.phoneNumber.setText(contactData.phone_number);
|
||||
}
|
||||
|
||||
if (contactData.email_address != null)
|
||||
binding.email.setText(contactData.email_address);
|
||||
|
||||
@@ -561,12 +491,6 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.email.setClickable(false);
|
||||
binding.email.setFocusable(false);
|
||||
|
||||
binding.phoneNumber.setClickable(false);
|
||||
binding.phoneNumber.setFocusable(false);
|
||||
|
||||
binding.countryCodes.setClickable(false);
|
||||
binding.countryCodes.setFocusable(false);
|
||||
|
||||
binding.caregiverCheck.setChecked(true);
|
||||
binding.caregiverCheck.setEnabled(false);
|
||||
binding.relationship.setEnabled(false);
|
||||
@@ -574,6 +498,12 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.caregiverCheckView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// adding contacts to Contact_rv
|
||||
if (contactData.extra_phone_numbers != null && !contactData.extra_phone_numbers.isEmpty()){
|
||||
String[] phone_numbers = contactData.extra_phone_numbers.split(",");
|
||||
createContactAdapter.submitList(Arrays.asList(phone_numbers));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setLayoutDetails(String title, String photo_title, String btn_txt) {
|
||||
@@ -582,4 +512,4 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.nextBtn.setText(btn_txt);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,12 @@ package com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Contact implements Serializable {
|
||||
|
||||
public String first_name, imageUri, phone_number, relationship, email_address;
|
||||
public String first_name, imageUri, phone_number, relationship, email_address
|
||||
, extra_phone_numbers;
|
||||
|
||||
public String is_sos, updated_at, created_at;
|
||||
|
||||
@@ -16,7 +17,27 @@ public class Contact implements Serializable {
|
||||
|
||||
public long id;
|
||||
|
||||
public Contact(){}
|
||||
public Contact(ArrayList<Contact> contacts){
|
||||
if (contacts != null && !contacts.isEmpty()){
|
||||
this.first_name = contacts.get(0).first_name;
|
||||
this.email_address = contacts.get(0).email_address;
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < contacts.size(); i++) {
|
||||
if (contacts.get(i) != null){
|
||||
stringBuilder.append(contacts.get(i).phone_number);
|
||||
|
||||
// adding comma only if it is not the last item
|
||||
if (i < contacts.size()-1){
|
||||
stringBuilder.append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.extra_phone_numbers = stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public Contact(String name){
|
||||
this.first_name = first_name;
|
||||
@@ -27,6 +48,8 @@ public class Contact implements Serializable {
|
||||
this.phone_number = phoneNumber;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Contact(String first_name, String phone_number, String relationship, String email_address, String is_sos, String updated_at, String created_at) {
|
||||
this.first_name = first_name;
|
||||
this.phone_number = phone_number;
|
||||
|
||||
@@ -17,6 +17,8 @@ public class ContactData implements Serializable {
|
||||
public String contact_photo;
|
||||
public CareGiverData care_giver_data;
|
||||
|
||||
public String extra_phone_numbers;
|
||||
|
||||
public int contact_id;
|
||||
|
||||
public ContactData() {
|
||||
@@ -26,6 +28,7 @@ public class ContactData implements Serializable {
|
||||
this.first_name = contact.first_name;
|
||||
this.phone_number = contact.phone_number;
|
||||
this.email_address = contact.email_address;
|
||||
this.extra_phone_numbers = contact.extra_phone_numbers;
|
||||
}
|
||||
|
||||
public ContactData(int id) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
@@ -329,29 +330,37 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
private boolean allOkay() {
|
||||
boolean allOkay = true;
|
||||
|
||||
if (binding.street.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.street.setError("Required");
|
||||
}
|
||||
// if (binding.street.getText().toString().trim().isEmpty()) {
|
||||
// allOkay = false;
|
||||
// binding.street.setError("Required");
|
||||
// }
|
||||
|
||||
if (binding.town.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.town.setError("Required");
|
||||
// allOkay = false;
|
||||
// binding.town.setError("Required");
|
||||
Toast.makeText(requireContext(), "Select a valid location.", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (binding.zipCode.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.zipCode.setError("Required");
|
||||
// allOkay = false;
|
||||
// binding.zipCode.setError("Required");
|
||||
Toast.makeText(requireContext(), "Select a valid location.", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (binding.countrySpinner.getSelectedIndex() == -1) {
|
||||
allOkay = false;
|
||||
binding.countrySpinner.setError("Required");
|
||||
// allOkay = false;
|
||||
// binding.countrySpinner.setError("Required");
|
||||
Toast.makeText(requireContext(), "Select a valid location.", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (binding.stateSpinner.getSelectedIndex() == -1) {
|
||||
allOkay = false;
|
||||
binding.stateSpinner.setError("Required");
|
||||
// allOkay = false;
|
||||
// binding.stateSpinner.setError("Required");
|
||||
Toast.makeText(requireContext(), "Select a valid location.", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentLocation == null && allOkay) {
|
||||
@@ -449,6 +458,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
.position(latLng).draggable(false)
|
||||
.title(title));
|
||||
|
||||
|
||||
try {
|
||||
// fetching address from the lag lng
|
||||
Geocoder geocoder = new Geocoder(requireContext(), Locale.getDefault());
|
||||
@@ -460,11 +470,9 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
binding.zipCode.setText(address.getPostalCode());
|
||||
|
||||
if (address.getThoroughfare() == null || address.getThoroughfare().isEmpty()) {
|
||||
binding.street.setEnabled(true);
|
||||
binding.street.setText(null);
|
||||
} else {
|
||||
binding.street.setText(address.getThoroughfare());
|
||||
binding.street.setEnabled(false);
|
||||
}
|
||||
|
||||
if (address.getSubLocality() != null) {
|
||||
@@ -495,12 +503,21 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
binding.countrySpinner.clearSelectedItem();
|
||||
}
|
||||
|
||||
}else{
|
||||
binding.countrySpinner.clearSelectedItem();
|
||||
binding.street.setText(null);
|
||||
binding.stateSpinner.clearSelectedItem();
|
||||
binding.zipCode.setText(null);
|
||||
binding.town.setText(null);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// do nothing as we couldn't load the location from the lat lng
|
||||
}
|
||||
|
||||
binding.street.clearFocus();
|
||||
binding.scrollView.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
|
||||
}
|
||||
|
||||
private void requestLocations() {
|
||||
@@ -597,23 +614,23 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
binding.stateSpinner.clearSelectedItem();
|
||||
}
|
||||
|
||||
binding.street.requestFocus();
|
||||
|
||||
if (getActivity() != null) {
|
||||
getActivity().getWindow()
|
||||
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
// binding.street.requestFocus();
|
||||
//
|
||||
// if (getActivity() != null) {
|
||||
// getActivity().getWindow()
|
||||
// .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
// }
|
||||
});
|
||||
|
||||
binding.stateSpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
|
||||
binding.stateSpinner.setError(null);
|
||||
binding.zipCode.requestFocus();
|
||||
|
||||
if (getActivity() != null) {
|
||||
getActivity().getWindow()
|
||||
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
});
|
||||
// binding.stateSpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
|
||||
// binding.stateSpinner.setError(null);
|
||||
// binding.zipCode.requestFocus();
|
||||
//
|
||||
// if (getActivity() != null) {
|
||||
// getActivity().getWindow()
|
||||
// .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user