.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package com.ssb.simplitend.apputils;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.ssb.simplitend.patientprofile.PatientProfileAPIService;
|
||||
import com.ssb.simplitend.welcome.welcomecg.WelcomeApiService;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class PatientDataCache {
|
||||
|
||||
private static PatientData patientData;
|
||||
|
||||
public synchronized static void setPatientData(PatientData data){
|
||||
patientData = data;
|
||||
}
|
||||
|
||||
public synchronized static void getPatientData(Context context,
|
||||
@NonNull PatientDataCache.GetPatientCallBack callBack,
|
||||
boolean show_progress){
|
||||
if (patientData != null){
|
||||
callBack.patientData(patientData);
|
||||
return;
|
||||
}
|
||||
|
||||
updatePatientData(context, callBack, show_progress);
|
||||
}
|
||||
|
||||
private static void updatePatientData(Context context, GetPatientCallBack callBack, boolean show_progress) {
|
||||
PatientProfileAPIService apiService = RetrofitHelper.getRetrofit().create(PatientProfileAPIService.class);
|
||||
|
||||
ProgressDialog progressDialog = new ProgressDialog(context);
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we fetch details for you...");
|
||||
progressDialog.setCancelable(false);
|
||||
if (show_progress) {
|
||||
progressDialog.show();
|
||||
}
|
||||
|
||||
apiService.getUsrProfileProgress("Bearer " + AppUtil.getPatientToken(context))
|
||||
.enqueue(new Callback<CallResponse<PatientData>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<PatientData>> call, Response<CallResponse<PatientData>> response) {
|
||||
progressDialog.dismiss();
|
||||
if (response.body() != null) {
|
||||
if (response.body().status != 200 || response.body().result == null) {
|
||||
if (callBack != null) callBack.patientData(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (callBack != null){
|
||||
setPatientData(response.body().result);
|
||||
callBack.patientData(response.body().result);
|
||||
}
|
||||
} else {
|
||||
if (callBack != null) callBack.patientData(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<PatientData>> call, Throwable t) {
|
||||
progressDialog.dismiss();
|
||||
if (callBack != null) callBack.patientData(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GetPatientCallBack{
|
||||
void patientData(PatientData patientData);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.articles.ArticlesActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.CaregiverChatsFragment;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.DashBoardFragment;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.CgDashBoardFragment;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.MyPatientFragment;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.ssb.simplitend.cg_subscription.CgSubscriptionActivity;
|
||||
@@ -77,7 +77,7 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
binding.bottomNav.setItemSelectListener(this);
|
||||
|
||||
// initializing dashboard fragment
|
||||
replaceFragment(new DashBoardFragment());
|
||||
replaceFragment(new CgDashBoardFragment());
|
||||
|
||||
setLayoutDetails();
|
||||
|
||||
@@ -173,7 +173,7 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
@Override
|
||||
public void onBottomNavItemSelected(MenuItem selectedItem) {
|
||||
if (selectedItem == MenuItem.DASHBOARD){
|
||||
replaceFragment(new DashBoardFragment());
|
||||
replaceFragment(new CgDashBoardFragment());
|
||||
|
||||
// setting up toolbar accordingly
|
||||
binding.toolbar.setNavigationIcon(AppCompatResources.getDrawable(this, R.drawable.ic_menu));
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.databinding.ActivityPersonalInfoBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
@@ -56,9 +57,27 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
private ArrayList<String> countryList;
|
||||
private HashMap<String, ArrayList<String>> country_N_states_map;
|
||||
|
||||
public static final String IS_CAREGIVER = "is_caregiver";
|
||||
/*
|
||||
There are total three ways to enter this activity
|
||||
|
||||
private boolean isCaregiver;
|
||||
1. From the caregiver side to edit patient profile
|
||||
where, IS_CAREGIVER value is not passed.
|
||||
thus, default value of isCaregiver is false
|
||||
|
||||
2. From the caregiver side to update Caregivers profile
|
||||
where, IS_CAREGIVER value is passed as true.
|
||||
thus, to update the caregiver data
|
||||
|
||||
In both above cases use the bearer token from the caregiver side
|
||||
|
||||
3. From patient side to update Patients profile
|
||||
where, IS_FROM_PATIENT value is passed as true
|
||||
*/
|
||||
|
||||
public static final String IS_CAREGIVER = "is_caregiver";
|
||||
public static final String IS_FROM_PATIENT = "from_patient";
|
||||
|
||||
private boolean isCaregiver, isFromPatient;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -69,6 +88,7 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
Intent intent = getIntent();
|
||||
if (intent != null){
|
||||
isCaregiver = intent.getBooleanExtra(IS_CAREGIVER, false);
|
||||
isFromPatient = intent.getBooleanExtra(IS_FROM_PATIENT, false);
|
||||
}
|
||||
|
||||
if (isCaregiver){
|
||||
@@ -80,12 +100,26 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
|
||||
clickEvents();
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData -> {
|
||||
this.patientData = careGiverData.patientDetails;
|
||||
this.careGiverData = careGiverData;
|
||||
if (isFromPatient){
|
||||
// intent from patient side
|
||||
// thus, fetching the patient cache
|
||||
PatientDataCache.getPatientData(this, (patientData1 -> {
|
||||
this.patientData = patientData1;
|
||||
|
||||
setDetails();
|
||||
}), true);
|
||||
setDetails();
|
||||
}), true);
|
||||
}else{
|
||||
// other possible intent is from caregiver side
|
||||
// thus, fetching caregiver cache
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData -> {
|
||||
if (careGiverData == null) return;
|
||||
|
||||
this.patientData = careGiverData.patientDetails;
|
||||
this.careGiverData = careGiverData;
|
||||
|
||||
setDetails();
|
||||
}), true);
|
||||
}
|
||||
|
||||
binding.name.requestFocus();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class DashBoardFragment extends Fragment implements
|
||||
public class CgDashBoardFragment extends Fragment implements
|
||||
OnMapReadyCallback, ArticleContracts.GetArticleCallback {
|
||||
|
||||
// view binding
|
||||
@@ -53,7 +53,7 @@ public class DashBoardFragment extends Fragment implements
|
||||
|
||||
private PatientData patientData;
|
||||
|
||||
public DashBoardFragment(){
|
||||
public CgDashBoardFragment(){
|
||||
// required empty
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.ssb.simplitend.patient_dashboard;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
|
||||
public class DashBoardActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.ssb.simplitend.patient_dashboard.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -13,14 +17,45 @@ import androidx.navigation.Navigation;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.databinding.PatientDashboardFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.activities.WelcomeActivity;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
public class PatientDashboardFragment extends Fragment {
|
||||
|
||||
// view binding
|
||||
protected PatientDashboardFragmentBinding binding;
|
||||
|
||||
private PatientData patientData;
|
||||
|
||||
// date suffixes
|
||||
String[] suffixes =
|
||||
// 0 1 2 3 4 5 6 7 8 9
|
||||
{ "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th",
|
||||
// 10 11 12 13 14 15 16 17 18 19
|
||||
"th", "th", "th", "th", "th", "th", "th", "th", "th", "th",
|
||||
// 20 21 22 23 24 25 26 27 28 29
|
||||
"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th",
|
||||
// 30 31
|
||||
"th", "st" };
|
||||
|
||||
// ticker broadcast receiver that is called every one minute passes the system clock
|
||||
private final BroadcastReceiver timeTickReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent == null) return;
|
||||
|
||||
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
|
||||
updateTime();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public PatientDashboardFragment() {
|
||||
// required
|
||||
}
|
||||
@@ -30,11 +65,39 @@ public class PatientDashboardFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = PatientDashboardFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
PatientDataCache.getPatientData(requireContext(), (patientData -> {
|
||||
this.patientData = patientData;
|
||||
}), true);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateTime();
|
||||
Activity activity = getActivity();
|
||||
if (activity != null){
|
||||
activity.registerReceiver(timeTickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Activity activity = getActivity();
|
||||
if (activity != null){
|
||||
activity.unregisterReceiver(timeTickReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
binding.chats.setOnClickListener(v ->
|
||||
Navigation.findNavController(v).navigate(R.id.action_CPDashboardFragment_to_chatListFragment)
|
||||
@@ -51,5 +114,72 @@ public class PatientDashboardFragment extends Fragment {
|
||||
startActivity(intent);
|
||||
requireActivity().finish();
|
||||
});
|
||||
|
||||
binding.closeReminder.setOnClickListener(v -> removeReminder());
|
||||
|
||||
binding.calls.setOnClickListener(v -> {
|
||||
addReminder();
|
||||
});
|
||||
|
||||
binding.profile.setOnClickListener(v -> {
|
||||
Navigation.findNavController(v).navigate(R.id.action_CPDashboardFragment_to_patientProfileInfoFragment);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateTime() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
String currentTime = sdf.format(calendar.getTime());
|
||||
binding.currentTime.setText(currentTime.toUpperCase());
|
||||
|
||||
binding.dayOfWeek.setText(getDayOfWeek(calendar.get(Calendar.DAY_OF_WEEK)));
|
||||
|
||||
SimpleDateFormat date_sdf = new SimpleDateFormat("MMMM dd, yyyy", Locale.getDefault());
|
||||
String date_str = date_sdf.format(calendar.getTime());
|
||||
|
||||
binding.date.setText(date_str);
|
||||
|
||||
}
|
||||
|
||||
public String getDayOfWeek(int position){
|
||||
switch (position){
|
||||
case 1:
|
||||
return "Sunday";
|
||||
case 2:
|
||||
return "Monday";
|
||||
case 3:
|
||||
return "Tuesday";
|
||||
case 4:
|
||||
return "Wednesday";
|
||||
case 5:
|
||||
return "Thursday";
|
||||
case 6:
|
||||
return "Friday";
|
||||
case 7:
|
||||
return "Saturday";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private void removeReminder() {
|
||||
binding.homeReminder.setVisibility(View.GONE);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = binding.bgImg.getLayoutParams();
|
||||
|
||||
layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._140sdp);
|
||||
|
||||
binding.bgImg.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
private void addReminder(){
|
||||
binding.homeReminder.setVisibility(View.VISIBLE);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = binding.bgImg.getLayoutParams();
|
||||
|
||||
layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._200sdp);;
|
||||
|
||||
binding.bgImg.setLayoutParams(layoutParams);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.ssb.simplitend.patient_dashboard.fragments;
|
||||
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.EditProfileInfoActivity.IS_FROM_PATIENT;
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.ACTIVITY_F;
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.CONTACTS_F;
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.MED_INFO_F;
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.MED_REMINDER_F;
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.WHICH_FRAGMENT;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.EditProfileInfoActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity;
|
||||
import com.ssb.simplitend.cg_geofencing.CgGeoFencingActivity;
|
||||
import com.ssb.simplitend.databinding.ActivityPatProfileInfoBinding;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
public class PatientProfileInfoFragment extends Fragment {
|
||||
|
||||
private ActivityPatProfileInfoBinding binding;
|
||||
|
||||
private PatientData patientData;
|
||||
|
||||
public PatientProfileInfoFragment(){
|
||||
// required
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = ActivityPatProfileInfoBinding.inflate(inflater, container, false);
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
PatientDataCache.getPatientData(requireContext(), (patientData -> {
|
||||
this.patientData = patientData;
|
||||
|
||||
setPatientDetails();
|
||||
}), true);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void setPatientDetails() {
|
||||
if (patientData == null) {
|
||||
Toast.makeText(requireContext(), "Couldn't load patient data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
};
|
||||
|
||||
// if (patientData.p != null) {
|
||||
// // image
|
||||
// Glide.with(this)
|
||||
// .load(AppUtil.IMAGE_BASE_URL + careGiverData.profile_photo)
|
||||
// .placeholder(android.R.color.darker_gray)
|
||||
// .error(R.drawable.ic_contact)
|
||||
// .into(binding.image);
|
||||
// }
|
||||
|
||||
binding.name.setText(patientData.first_name);
|
||||
binding.phoneNumber.setText(patientData.phone_number);
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
|
||||
binding.medication.setOnClickListener(v -> {
|
||||
gotoProfileShower(MED_REMINDER_F);
|
||||
});
|
||||
|
||||
binding.contacts.setOnClickListener(v -> {
|
||||
gotoProfileShower(CONTACTS_F);
|
||||
});
|
||||
|
||||
binding.medRecords.setOnClickListener(v -> {
|
||||
gotoProfileShower(MED_INFO_F);
|
||||
});
|
||||
|
||||
binding.patActivities.setOnClickListener(v -> {
|
||||
gotoProfileShower(ACTIVITY_F);
|
||||
});
|
||||
|
||||
binding.editBtn.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(requireActivity(), EditProfileInfoActivity.class);
|
||||
intent.putExtra(IS_FROM_PATIENT, true);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
}
|
||||
|
||||
private void gotoProfileShower(String which_f) {
|
||||
Intent intent = new Intent(requireActivity(), PatientProfileShowerActivity.class);
|
||||
intent.putExtra(WHICH_FRAGMENT, which_f);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.EditTextErrorRemover;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
||||
import com.ssb.simplitend.databinding.SignInFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeContracts;
|
||||
@@ -152,6 +153,7 @@ public class SignInFragment extends Fragment implements WelcomeContracts.Registe
|
||||
@Override
|
||||
public void onResponse(PatientData patientResult, String token) {
|
||||
// caching user data
|
||||
PatientDataCache.setPatientData(patientResult);
|
||||
|
||||
progressDialog.dismiss();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.navigation.Navigation;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.databinding.CreatePinFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeContracts;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeViewModel;
|
||||
@@ -154,8 +155,7 @@ public class CreatePinFragment extends Fragment implements WelcomeContracts.Regi
|
||||
|
||||
@Override
|
||||
public void onResponse(PatientData patientResult, String token) {
|
||||
Log.d(TAG, "onResponse: " + patientResult);
|
||||
Log.d(TAG, "onResponse: Token " + token);
|
||||
PatientDataCache.setPatientData(patientResult);
|
||||
|
||||
progressDialog.setMessage("Almost there...");
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.location.Location;
|
||||
@@ -26,6 +27,7 @@ import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
@@ -100,7 +102,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
// viewmodel
|
||||
private WelcomeViewModel viewModel;
|
||||
|
||||
public LocationFragment(){
|
||||
public LocationFragment() {
|
||||
// required empty const.
|
||||
}
|
||||
|
||||
@@ -170,8 +172,8 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
SupportMapFragment mapFragment = SupportMapFragment.newInstance(gmo);
|
||||
|
||||
getParentFragmentManager().beginTransaction()
|
||||
.add(R.id.map_frag_cont, mapFragment)
|
||||
.commit();
|
||||
.add(R.id.map_frag_cont, mapFragment)
|
||||
.commit();
|
||||
|
||||
mapFragment.getMapAsync(this);
|
||||
|
||||
@@ -199,7 +201,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (editable.toString().length() == 6){
|
||||
if (editable.toString().length() == 6) {
|
||||
binding.zipCode.clearFocus();
|
||||
AppUtil.closeKeyboard(requireActivity());
|
||||
}
|
||||
@@ -212,33 +214,30 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
private void loadPatientAddressSavedState() throws Exception {
|
||||
PatientData patientData = viewModel.getPatientData();
|
||||
|
||||
if (patientData.country != null){
|
||||
if (patientData.country != null) {
|
||||
binding.countrySpinner.selectItemByIndex(countryList.indexOf(patientData.country));
|
||||
|
||||
if (patientData.state != null){
|
||||
if (patientData.state != null) {
|
||||
binding.stateSpinner.selectItemByIndex(country_N_states_map.get(patientData.country).indexOf(patientData.state));
|
||||
}
|
||||
}
|
||||
|
||||
if (patientData.lat != null && patientData.lng != null){
|
||||
if (patientData.lat != null && patientData.lng != null) {
|
||||
double lat = Double.parseDouble(patientData.lat);
|
||||
double lng = Double.parseDouble(patientData.lng);
|
||||
|
||||
currentLocation = new LatLng(lat, lng);
|
||||
}else{
|
||||
// default current location // washington DC
|
||||
currentLocation = new LatLng(40.75796541422796, -73.98557368665934);
|
||||
}
|
||||
|
||||
if (patientData.address_line1 != null){
|
||||
if (patientData.address_line1 != null) {
|
||||
binding.street.setText(patientData.address_line1);
|
||||
}
|
||||
|
||||
if (patientData.city != null){
|
||||
if (patientData.city != null) {
|
||||
binding.town.setText(patientData.city);
|
||||
}
|
||||
|
||||
if (patientData.post_code != null){
|
||||
if (patientData.post_code != null) {
|
||||
binding.zipCode.setText(patientData.post_code);
|
||||
}
|
||||
}
|
||||
@@ -264,8 +263,8 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
// animating camera to selected location
|
||||
CameraPosition camPos = new CameraPosition.Builder()
|
||||
.target(place.getLatLng())
|
||||
.zoom(15)
|
||||
.build();
|
||||
.zoom(15)
|
||||
.build();
|
||||
|
||||
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(camPos));
|
||||
|
||||
@@ -285,30 +284,30 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
private void clickEvents() {
|
||||
|
||||
binding.backBtn.setOnClickListener(v -> {
|
||||
if (getActivity() != null){
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
});
|
||||
|
||||
binding.submit.setOnClickListener(v ->
|
||||
{
|
||||
if (allOkay()){
|
||||
{
|
||||
if (allOkay()) {
|
||||
|
||||
PatientData patientData = viewModel.getPatientData();
|
||||
PatientData patientData = viewModel.getPatientData();
|
||||
|
||||
patientData.address_line1 = binding.street.getText().toString();
|
||||
patientData.city = binding.town.getText().toString();
|
||||
patientData.post_code = binding.zipCode.getText().toString();
|
||||
patientData.address_line1 = binding.street.getText().toString();
|
||||
patientData.city = binding.town.getText().toString();
|
||||
patientData.post_code = binding.zipCode.getText().toString();
|
||||
|
||||
patientData.country = countryList.get(binding.countrySpinner.getSelectedIndex());
|
||||
patientData.state = country_N_states_map.get(patientData.country).get(binding.stateSpinner.getSelectedIndex());
|
||||
patientData.country = countryList.get(binding.countrySpinner.getSelectedIndex());
|
||||
patientData.state = country_N_states_map.get(patientData.country).get(binding.stateSpinner.getSelectedIndex());
|
||||
|
||||
patientData.lat = String.valueOf(currentLocation.latitude);
|
||||
patientData.lng = String.valueOf(currentLocation.longitude);
|
||||
patientData.lat = String.valueOf(currentLocation.latitude);
|
||||
patientData.lng = String.valueOf(currentLocation.longitude);
|
||||
|
||||
Navigation.findNavController(v).navigate(R.id.action_locationFragment_to_createPinFragment);
|
||||
}
|
||||
}
|
||||
Navigation.findNavController(v).navigate(R.id.action_locationFragment_to_createPinFragment);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
binding.search.setOnClickListener(v -> {
|
||||
@@ -326,32 +325,32 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
private boolean allOkay() {
|
||||
boolean allOkay = true;
|
||||
|
||||
if (binding.street.getText().toString().trim().isEmpty()){
|
||||
if (binding.street.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.street.setError("Required");
|
||||
}
|
||||
|
||||
if (binding.town.getText().toString().trim().isEmpty()){
|
||||
if (binding.town.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.town.setError("Required");
|
||||
}
|
||||
|
||||
if (binding.zipCode.getText().toString().trim().isEmpty()){
|
||||
if (binding.zipCode.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.zipCode.setError("Required");
|
||||
}
|
||||
|
||||
if (binding.countrySpinner.getSelectedIndex() == -1){
|
||||
if (binding.countrySpinner.getSelectedIndex() == -1) {
|
||||
allOkay = false;
|
||||
binding.countrySpinner.setError("Required");
|
||||
}
|
||||
|
||||
if (binding.stateSpinner.getSelectedIndex() == -1){
|
||||
if (binding.stateSpinner.getSelectedIndex() == -1) {
|
||||
allOkay = false;
|
||||
binding.stateSpinner.setError("Required");
|
||||
}
|
||||
|
||||
if (currentLocation == null && allOkay){
|
||||
|
||||
if (currentLocation == null && allOkay) {
|
||||
allOkay = false;
|
||||
Toast.makeText(requireContext(), "Please click on map to select a location.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@@ -366,26 +365,32 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
|
||||
Boolean fineLocationGranted;
|
||||
|
||||
if (result.containsKey(Manifest.permission.ACCESS_FINE_LOCATION)){
|
||||
if (result.containsKey(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
fineLocationGranted = result.get(Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
}else{
|
||||
} else {
|
||||
fineLocationGranted = false;
|
||||
}
|
||||
|
||||
Boolean coarseLocationGranted;
|
||||
|
||||
if (result.containsKey(Manifest.permission.ACCESS_COARSE_LOCATION)){
|
||||
if (result.containsKey(Manifest.permission.ACCESS_COARSE_LOCATION)) {
|
||||
coarseLocationGranted = result.get(Manifest.permission.ACCESS_COARSE_LOCATION);
|
||||
}else{
|
||||
} else {
|
||||
coarseLocationGranted = false;
|
||||
}
|
||||
|
||||
if ((fineLocationGranted != null && fineLocationGranted) || (coarseLocationGranted != null && coarseLocationGranted)) {
|
||||
// one of the location access granted.
|
||||
Toast.makeText(requireContext(), "Fetching your current location", Toast.LENGTH_SHORT).show();
|
||||
if (googleMap != null) {
|
||||
if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
googleMap.setMyLocationEnabled(true);
|
||||
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
|
||||
}
|
||||
requestLocations();
|
||||
}
|
||||
|
||||
}
|
||||
).launch(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION});
|
||||
}
|
||||
@@ -411,16 +416,17 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
@Override
|
||||
public void onMapReady(@NonNull GoogleMap googleMap) {
|
||||
this.googleMap = googleMap;
|
||||
CameraPosition default_map_pos = new CameraPosition.Builder()
|
||||
.target(currentLocation)
|
||||
.zoom(15)
|
||||
.build();
|
||||
|
||||
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(default_map_pos));
|
||||
if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||
googleMap.setMyLocationEnabled(true);
|
||||
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
|
||||
}
|
||||
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.75796541422796, -73.98557368665934), 14));
|
||||
|
||||
googleMap.setOnMapClickListener(this);
|
||||
|
||||
if (currentLocation != null){
|
||||
if (currentLocation != null) {
|
||||
addMarker(currentLocation, "Selected location");
|
||||
}
|
||||
}
|
||||
@@ -430,7 +436,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
addMarker(latLng, "Selected location");
|
||||
}
|
||||
|
||||
private void addMarker(LatLng latLng, String title){
|
||||
private void addMarker(LatLng latLng, String title) {
|
||||
// updating current location
|
||||
this.currentLocation = latLng;
|
||||
if (marker != null && marker.isVisible()) marker.remove();
|
||||
@@ -444,25 +450,31 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
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){
|
||||
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.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){
|
||||
if (address.getSubLocality() != null) {
|
||||
binding.town.setText(address.getSubLocality());
|
||||
}else{
|
||||
} else {
|
||||
binding.town.setText(address.getLocality());
|
||||
}
|
||||
|
||||
if (countryList == null) return;
|
||||
|
||||
if (countryList.contains(address.getCountryName())){
|
||||
if (countryList.contains(address.getCountryName())) {
|
||||
int index = countryList.indexOf(address.getCountryName());
|
||||
|
||||
if (index >= 0 && index < countryList.size()){
|
||||
if (index >= 0 && index < countryList.size()) {
|
||||
binding.countrySpinner.selectItemByIndex(index);
|
||||
|
||||
ArrayList<String> stateList = country_N_states_map.get(address.getCountryName());
|
||||
@@ -471,24 +483,24 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
|
||||
int state_index = stateList.indexOf(address.getAdminArea());
|
||||
|
||||
if (state_index >= 0 && state_index < stateList.size()){
|
||||
if (state_index >= 0 && state_index < stateList.size()) {
|
||||
binding.stateSpinner.selectItemByIndex(state_index);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
binding.countrySpinner.clearSelectedItem();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// do nothing as we couldn't load the location from the lat lng
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void requestLocations(){
|
||||
if (!isLocationProviderEnabled(requireContext())){
|
||||
private void requestLocations() {
|
||||
if (!isLocationProviderEnabled(requireContext())) {
|
||||
AppUtil.showAlert(requireContext(),
|
||||
getString(R.string.GPS_ENABLE_REQUIRED),
|
||||
getString(R.string.GPS_ENABLE_MESSAGE),
|
||||
@@ -512,7 +524,6 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
|
||||
public boolean isLocationProviderEnabled(Context context) {
|
||||
LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
|
||||
|
||||
return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
}
|
||||
|
||||
@@ -559,17 +570,6 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
|
||||
binding.countrySpinner.setItems(countryList);
|
||||
|
||||
|
||||
// selecting United States country as by default
|
||||
// if (countryList.contains(UNITED_STATES)){
|
||||
// binding.countrySpinner.selectItemByIndex(countryList.indexOf(UNITED_STATES));
|
||||
//
|
||||
// if (country_N_states_map.containsKey(UNITED_STATES))
|
||||
// {
|
||||
// binding.stateSpinner.setItems(country_N_states_map.get(UNITED_STATES));
|
||||
// }
|
||||
// }
|
||||
|
||||
binding.stateSpinner.setDismissWhenNotifiedItemSelected(true);
|
||||
binding.countrySpinner.setDismissWhenNotifiedItemSelected(true);
|
||||
|
||||
@@ -577,14 +577,14 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
binding.countrySpinner.setIsFocusable(true);
|
||||
|
||||
binding.countrySpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
|
||||
|
||||
|
||||
binding.countrySpinner.setError(null);
|
||||
|
||||
ArrayList<String> stateList;
|
||||
|
||||
if (country_N_states_map.containsKey(t1) && country_N_states_map.get(t1) != null){
|
||||
if (country_N_states_map.containsKey(t1) && country_N_states_map.get(t1) != null) {
|
||||
stateList = country_N_states_map.get(t1);
|
||||
}else{
|
||||
} else {
|
||||
stateList = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
binding.stateSpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
|
||||
binding.stateSpinner.setError(null);
|
||||
binding.zipCode.requestFocus();
|
||||
|
||||
@@ -17,6 +17,7 @@ import androidx.navigation.Navigation;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.apputils.RetrofitHelper;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.CaregiverDashActivity;
|
||||
@@ -216,6 +217,7 @@ public class SplashFragment extends Fragment
|
||||
@Override
|
||||
public void onProfileProgressFetched(PatientData patientData) {
|
||||
// caching data
|
||||
PatientDataCache.setPatientData(patientData);
|
||||
|
||||
binding.retry.setVisibility(View.GONE);
|
||||
binding.loadAnim.setVisibility(View.GONE);
|
||||
|
||||
Reference in New Issue
Block a user