.
This commit is contained in:
@@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -54,5 +55,19 @@ public class SignInSignUpFragment extends Fragment {
|
||||
onBoardPagerAdapter = new OnBoardPagerAdapter(getChildFragmentManager(), getLifecycle());
|
||||
binding.viewPager.setAdapter(onBoardPagerAdapter);
|
||||
binding.circleIndicator.setViewPager(binding.viewPager);
|
||||
|
||||
// margin top to indicator depending upon screen density so that... image in onboard looks non-stretched vertically
|
||||
float dynamic_size = getResources().getDisplayMetrics().ydpi;
|
||||
|
||||
if (dynamic_size >= 420){
|
||||
|
||||
dynamic_size = dynamic_size * 0.4f;
|
||||
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) binding.circleIndicator.getLayoutParams();
|
||||
layoutParams.setMargins(0, (int) dynamic_size, 0, 0);
|
||||
|
||||
binding.circleIndicator.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
package com.ssb.simplitend.welcome.welcomepatient.fragments.contacts;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
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.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.ssb.simplitend.databinding.ContactViewHolderBinding;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.Contact;
|
||||
|
||||
public class ContactListAdapter extends ListAdapter<Contact, ContactListAdapter.ContactViewHolder> {
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ContactListAdapter extends ListAdapter<ArrayList<Contact>, ContactListAdapter.ContactViewHolder> {
|
||||
|
||||
private OnContactClickListener contactClickListener;
|
||||
|
||||
private static final DiffUtil.ItemCallback<Contact> DIFF_UTIL = new DiffUtil.ItemCallback<Contact>() {
|
||||
private static final DiffUtil.ItemCallback<ArrayList<Contact>> DIFF_UTIL = new DiffUtil.ItemCallback<ArrayList<Contact>>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull Contact oldItem, @NonNull Contact newItem) {
|
||||
public boolean areItemsTheSame(@NonNull ArrayList<Contact> oldItem, @NonNull ArrayList<Contact> newItem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull Contact oldItem, @NonNull Contact newItem) {
|
||||
public boolean areContentsTheSame(@NonNull ArrayList<Contact> oldItem, @NonNull ArrayList<Contact> newItem) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -43,9 +47,56 @@ public class ContactListAdapter extends ListAdapter<Contact, ContactListAdapter.
|
||||
public void onBindViewHolder(@NonNull ContactViewHolder holder, int position) {
|
||||
holder.setData(getItem(position));
|
||||
|
||||
holder.binding.getRoot().setOnClickListener(v -> {
|
||||
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){
|
||||
contactClickListener.onClick(getItem(position));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -63,19 +114,17 @@ public class ContactListAdapter extends ListAdapter<Contact, ContactListAdapter.
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
public void setData(Contact contact){
|
||||
if (contact.first_name == null){
|
||||
binding.name.setText("No name");
|
||||
return;
|
||||
public void setData(ArrayList<Contact> contacts){
|
||||
if (contacts == null || contacts.isEmpty()) return;
|
||||
|
||||
Contact contact = contacts.get(0);
|
||||
|
||||
if (contact.first_name == null || contact.first_name.isEmpty()){
|
||||
contact.first_name = "No name";
|
||||
}
|
||||
|
||||
binding.name.setText(contact.first_name);
|
||||
|
||||
// static
|
||||
if (contact.first_name.length() >= 1)
|
||||
{
|
||||
binding.initial.setText(contact.first_name.substring(0, 1).toUpperCase());
|
||||
}
|
||||
binding.initial.setText(contact.first_name.toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import android.os.Looper;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -32,6 +31,7 @@ import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.Contact
|
||||
import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ContactListFragment extends Fragment {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ContactListFragment extends Fragment {
|
||||
|
||||
protected ActivityResultLauncher<Intent> insertContactLauncher;
|
||||
|
||||
private ArrayList<Contact> contactList;
|
||||
private ArrayList<ArrayList<Contact>> contactList;
|
||||
|
||||
public ContactListFragment() {
|
||||
// required empty const.
|
||||
@@ -118,18 +118,15 @@ public class ContactListFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Contact> filteredList = new ArrayList<>();
|
||||
ArrayList<ArrayList<Contact>> filteredList = new ArrayList<>();
|
||||
|
||||
for (Contact contact : contactList) {
|
||||
if (contact.first_name != null && contact.first_name.trim().toLowerCase().contains(searchInput)) {
|
||||
filteredList.add(contact);
|
||||
} else if (contact.phone_number != null && contact.phone_number.trim().contains(searchInput)) {
|
||||
filteredList.add(contact);
|
||||
} else if (contact.email_address != null && contact.email_address.trim().toLowerCase().contains(searchInput)) {
|
||||
filteredList.add(contact);
|
||||
} else if (contact.relationship != null && contact.relationship.trim().toLowerCase().contains(searchInput)) {
|
||||
filteredList.add(contact);
|
||||
for (ArrayList<Contact> contacts: contactList){
|
||||
if (contacts == null || contacts.isEmpty() || contacts.get(0).first_name == null) continue;
|
||||
|
||||
if (contacts.get(0).first_name.trim().toLowerCase().contains(searchInput.trim().toLowerCase())){
|
||||
filteredList.add(contacts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (filteredList.isEmpty()) {
|
||||
@@ -138,7 +135,7 @@ public class ContactListFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
contactListAdapter.submitList(filteredList);
|
||||
if (contactListAdapter != null) contactListAdapter.submitList(filteredList);
|
||||
|
||||
binding.contactRv.smoothScrollToPosition(0);
|
||||
|
||||
@@ -192,6 +189,5 @@ public class ContactListFragment extends Fragment {
|
||||
else
|
||||
filterContactList(binding.search.getText().toString().trim().toLowerCase());
|
||||
|
||||
binding.contactRv.smoothScrollToPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -23,7 +23,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
@@ -43,8 +45,18 @@ public class ContactViewModel extends AndroidViewModel {
|
||||
this.contactRepository = UserContactRepository.getContactRepository();
|
||||
}
|
||||
|
||||
public ArrayList<Contact> getContactList(Context context) {
|
||||
return this.contactRepository.getContactList(context.getApplicationContext());
|
||||
public ArrayList<ArrayList<Contact>> getContactList(Context context) {
|
||||
ArrayList<ArrayList<Contact>> contactLIst = new ArrayList<>();
|
||||
|
||||
TreeMap<String, ArrayList<Contact>> contactMap = this.contactRepository.getContactList(context);
|
||||
|
||||
for (ArrayList<Contact> contacts: contactMap.values()){
|
||||
if (contacts != null && contacts.size() > 0){
|
||||
contactLIst.add(contacts);
|
||||
}
|
||||
}
|
||||
|
||||
return contactLIst;
|
||||
}
|
||||
|
||||
public UserContactRepository getContactRepository() {
|
||||
|
||||
@@ -18,10 +18,12 @@ import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeContracts;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
@@ -166,8 +168,13 @@ public class UserContactRepository {
|
||||
});
|
||||
}
|
||||
|
||||
public ArrayList<Contact> getContactList(Context context) {
|
||||
final ArrayList<Contact> contactList = new ArrayList<>();
|
||||
public TreeMap<String, ArrayList<Contact>> getContactList(Context context) {
|
||||
|
||||
/*
|
||||
key -> name
|
||||
values -> different contacts with same name
|
||||
*/
|
||||
TreeMap<String, ArrayList<Contact>> contactMap = new TreeMap<>();
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
|
||||
@@ -179,33 +186,43 @@ public class UserContactRepository {
|
||||
|
||||
if (cursor != null) {
|
||||
|
||||
// To avoid duplicate phone numbers
|
||||
HashSet<String> mobileNoSet = new HashSet<>();
|
||||
|
||||
try {
|
||||
final int nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
|
||||
final int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
||||
|
||||
String name, number;
|
||||
while (cursor.moveToNext()) {
|
||||
name = cursor.getString(nameIndex);
|
||||
number = cursor.getString(numberIndex);
|
||||
String name = cursor.getString(nameIndex);
|
||||
String number = cursor.getString(numberIndex);
|
||||
|
||||
if (number == null) continue;
|
||||
if (name == null || name.isEmpty()) name = "No name";
|
||||
|
||||
if (!mobileNoSet.contains(number)) {
|
||||
Contact contact = new Contact(name, number);
|
||||
Contact contact = new Contact(name, number);
|
||||
|
||||
contactList.add(contact);
|
||||
mobileNoSet.add(number);
|
||||
ArrayList<Contact> contactList;
|
||||
|
||||
if (contactMap.containsKey(name)){
|
||||
// there is already number associate with this name
|
||||
// thus, adding to the existing contact list against the name
|
||||
contactList = contactMap.get(name);
|
||||
}else{
|
||||
contactList = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (contactList == null) contactList = new ArrayList<>();
|
||||
|
||||
contactList.add(contact);
|
||||
contactMap.put(name, contactList);
|
||||
}
|
||||
} finally {
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return contactList;
|
||||
return contactMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,15 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.databinding.OnboardOneFragmentBinding;
|
||||
|
||||
public class OnBoardOne extends Fragment {
|
||||
@@ -25,6 +29,18 @@ public class OnBoardOne extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = OnboardOneFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
float dynamic_size = getResources().getDisplayMetrics().ydpi * 0.3f;
|
||||
|
||||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) binding.image.getLayoutParams();
|
||||
layoutParams.setMargins(10, 0, 10, (int) dynamic_size);
|
||||
|
||||
binding.image.setLayoutParams(layoutParams);
|
||||
|
||||
LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) binding.title.getLayoutParams();
|
||||
layoutParams.setMargins(10, 0,10, (int) dynamic_size);
|
||||
|
||||
binding.title.setLayoutParams(layoutParams3);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -26,6 +28,18 @@ public class OnBoardThree extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = OnboardThreeFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
float dynamic_size = getResources().getDisplayMetrics().ydpi * 0.3f;
|
||||
|
||||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) binding.image.getLayoutParams();
|
||||
layoutParams.setMargins(10, 0, 10, (int) dynamic_size);
|
||||
|
||||
binding.image.setLayoutParams(layoutParams);
|
||||
|
||||
LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) binding.title.getLayoutParams();
|
||||
layoutParams.setMargins(10, 0,10, (int) dynamic_size);
|
||||
|
||||
binding.title.setLayoutParams(layoutParams3);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -26,6 +28,18 @@ public class OnBoardTwo extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = OnboardTwoFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
float dynamic_size = getResources().getDisplayMetrics().ydpi * 0.3f;
|
||||
|
||||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) binding.image.getLayoutParams();
|
||||
layoutParams.setMargins(10, 0, 10, (int) dynamic_size);
|
||||
|
||||
binding.image.setLayoutParams(layoutParams);
|
||||
|
||||
LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) binding.title.getLayoutParams();
|
||||
layoutParams.setMargins(10, 0,10, (int) dynamic_size);
|
||||
|
||||
binding.title.setLayoutParams(layoutParams3);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
@@ -63,6 +65,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
GoogleMap.OnMapClickListener, LocationListener {
|
||||
@@ -431,6 +434,51 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
marker = googleMap.addMarker(new MarkerOptions()
|
||||
.position(latLng).draggable(false)
|
||||
.title(title));
|
||||
|
||||
try {
|
||||
// fetching address from the lag lng
|
||||
Geocoder geocoder = new Geocoder(requireContext(), Locale.getDefault());
|
||||
List<Address> addresses = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1);
|
||||
|
||||
if (addresses != null && addresses.size() > 0 && addresses.get(0) != null){
|
||||
Address address = addresses.get(0);
|
||||
|
||||
binding.zipCode.setText(address.getPostalCode());
|
||||
|
||||
binding.street.setText(address.getThoroughfare());
|
||||
|
||||
if (address.getSubLocality() != null){
|
||||
binding.town.setText(address.getSubLocality());
|
||||
}else{
|
||||
binding.town.setText(address.getLocality());
|
||||
}
|
||||
|
||||
if (countryList == null) return;
|
||||
|
||||
if (countryList.contains(address.getCountryName())){
|
||||
int index = countryList.indexOf(address.getCountryName());
|
||||
|
||||
if (index >= 0 && index < countryList.size()){
|
||||
binding.countrySpinner.selectItemByIndex(index);
|
||||
|
||||
ArrayList<String> stateList = country_N_states_map.get(address.getCountryName());
|
||||
|
||||
if (stateList == null || stateList.isEmpty()) return;
|
||||
|
||||
int state_index = stateList.indexOf(address.getAdminArea());
|
||||
|
||||
if (state_index >= 0 && state_index < stateList.size()){
|
||||
binding.stateSpinner.selectItemByIndex(state_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
// do nothing as we couldn't load the location from the lat lng
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void requestLocations(){
|
||||
|
||||
Reference in New Issue
Block a user