.
This commit is contained in:
@@ -3,13 +3,16 @@ package com.ssb.simplitend.caregiverdashboard.activities;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.articles.ArticlesActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.CgDashBoardFragment;
|
||||
@@ -44,18 +47,23 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
binding = CaregiverDashboardActivityBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData) -> {
|
||||
this.careGiverData = careGiverData;
|
||||
|
||||
watchSubscription();
|
||||
}, true);
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData) -> {
|
||||
this.careGiverData = careGiverData;
|
||||
|
||||
watchSubscription();
|
||||
setLayoutDetails();
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Fragment fragment = getSupportFragmentManager().findFragmentByTag("chat");
|
||||
@@ -93,8 +101,6 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
|
||||
// initializing dashboard fragment
|
||||
replaceFragment(new CgDashBoardFragment(), "dashboard");
|
||||
|
||||
setLayoutDetails();
|
||||
|
||||
}
|
||||
|
||||
@@ -159,7 +165,14 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
menuBinding.name.setText(careGiverData.patientDetails.first_name);
|
||||
menuBinding.name.setText(careGiverData.first_name);
|
||||
if (careGiverData.profile_photo != null){
|
||||
Glide.with(this)
|
||||
.load(AppUtil.IMAGE_BASE_URL + careGiverData.profile_photo)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(R.drawable.caregiver_img)
|
||||
.into(menuBinding.cgImage);
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceFragment(Fragment fragment, String tag){
|
||||
|
||||
@@ -31,15 +31,19 @@ public class CaregiverProfileActivity extends AppCompatActivity implements Compo
|
||||
binding = ActivityCaregiverProfileBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> {
|
||||
this.careGiverData = careGiverData1;
|
||||
|
||||
setCareGiverDetails();
|
||||
}), true);
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
}
|
||||
|
||||
private void setCareGiverDetails() {
|
||||
@@ -53,7 +57,7 @@ public class CaregiverProfileActivity extends AppCompatActivity implements Compo
|
||||
Glide.with(this)
|
||||
.load(AppUtil.IMAGE_BASE_URL + careGiverData.profile_photo)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(R.drawable.ic_contact)
|
||||
.error(R.drawable.caregiver_img)
|
||||
.into(binding.image);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.activities;
|
||||
|
||||
import static com.ssb.simplitend.apputils.RetrofitHelper.UPDATE_CONTACT;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.github.dhaval2404.imagepicker.ImagePicker;
|
||||
import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
@@ -21,6 +34,8 @@ 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.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
|
||||
import com.ssb.simplitend.databinding.ActivityPersonalInfoBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
@@ -29,6 +44,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -38,24 +54,28 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class EditProfileInfoActivity extends AppCompatActivity implements
|
||||
CgHomeContracts.UpdateCaregiverDataCallback, CgHomeContracts.UpdatePatientDataCallback {
|
||||
|
||||
private static final String TAG = "PatientProfileInfoActiv";
|
||||
|
||||
// view binding
|
||||
protected ActivityPersonalInfoBinding binding;
|
||||
|
||||
private CaregiverMainViewModel viewModel;
|
||||
private ProgressDialog progressDialog;
|
||||
private DatePickerDialog datePickerDialog;
|
||||
|
||||
private ArrayList<String> countryCodeList;
|
||||
|
||||
private PatientData patientData;
|
||||
|
||||
private CareGiverData careGiverData;
|
||||
|
||||
private ArrayList<String> countryList;
|
||||
private HashMap<String, ArrayList<String>> country_N_states_map;
|
||||
private Uri selectedImageUri;
|
||||
private ActivityResultLauncher<Intent> imageSelector;
|
||||
|
||||
/*
|
||||
There are total three ways to enter this activity
|
||||
@@ -85,6 +105,9 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
binding = ActivityPersonalInfoBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(CaregiverMainViewModel.class);
|
||||
progressDialog = new ProgressDialog(this);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null){
|
||||
isCaregiver = intent.getBooleanExtra(IS_CAREGIVER, false);
|
||||
@@ -120,8 +143,6 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
setDetails();
|
||||
}), true);
|
||||
}
|
||||
|
||||
binding.name.requestFocus();
|
||||
}
|
||||
|
||||
private void setDetails() {
|
||||
@@ -136,6 +157,15 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
binding.dob.setText(formatDateToMMddYYYY("yyyy-MM-dd", careGiverData.date_of_birth));
|
||||
binding.contactNumber.setText(careGiverData.phone_number);
|
||||
binding.email.setText(careGiverData.email);
|
||||
binding.email.setEnabled(false);
|
||||
|
||||
if (careGiverData.profile_photo != null){
|
||||
Glide.with(this)
|
||||
.load(AppUtil.IMAGE_BASE_URL + careGiverData.profile_photo)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(R.drawable.caregiver_img)
|
||||
.into(binding.image);
|
||||
}
|
||||
}else{
|
||||
if (patientData == null) {
|
||||
Toast.makeText(this, "Couldn't load patient data.", Toast.LENGTH_SHORT).show();
|
||||
@@ -143,6 +173,14 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
// load patient data
|
||||
if (careGiverData.profile_photo != null){
|
||||
Glide.with(this)
|
||||
.load(AppUtil.IMAGE_BASE_URL + patientData.profile_photo)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(R.drawable.caregiver_img)
|
||||
.into(binding.image);
|
||||
}
|
||||
|
||||
binding.name.setText(patientData.first_name);
|
||||
binding.dob.setText(formatDateToMMddYYYY("yyyy-MM-dd", patientData.date_of_birth));
|
||||
binding.contactNumber.setText(patientData.phone_number);
|
||||
@@ -209,11 +247,38 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
|
||||
inputFieldFocusManage();
|
||||
|
||||
imageSelector = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> {
|
||||
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
|
||||
//Image Uri will not be null for RESULT_OK
|
||||
selectedImageUri = result.getData().getData();
|
||||
|
||||
binding.image.setImageURI(null);
|
||||
binding.image.setImageURI(selectedImageUri);
|
||||
|
||||
} else if (result.getResultCode() == ImagePicker.RESULT_ERROR) {
|
||||
Toast.makeText(this, ImagePicker.getError(result.getData()), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "Task Cancelled", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
binding.save.setOnClickListener(v -> {
|
||||
onBackPressed();
|
||||
if (allCgOkay()) {
|
||||
AppUtil.closeKeyboard(this);
|
||||
AppUtil.showSOSDecision(this,
|
||||
getString(R.string.make_changes),
|
||||
getString(R.string.yes),
|
||||
getString(R.string.no),
|
||||
yes -> {
|
||||
updateCareGiverData();
|
||||
}, no -> {
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
binding.dob.setOnClickListener(v -> {
|
||||
@@ -223,6 +288,125 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
binding.backBtn.setOnClickListener(v -> {
|
||||
onBackPressed();
|
||||
});
|
||||
|
||||
binding.image.setOnClickListener(v -> {
|
||||
|
||||
ImagePicker.with(this)
|
||||
.cropSquare()
|
||||
.maxResultSize(500, 500)
|
||||
.galleryOnly()
|
||||
.createIntent(intent -> {
|
||||
imageSelector.launch(intent);
|
||||
return null;
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private boolean allCgOkay() {
|
||||
|
||||
binding.name.setError(null);
|
||||
binding.dob.setError(null);
|
||||
binding.contactNumber.setError(null);
|
||||
binding.email.setError(null);
|
||||
|
||||
boolean allOkay = true;
|
||||
|
||||
if (binding.name.getText().toString().trim().isEmpty()) {
|
||||
binding.name.setError("Required");
|
||||
allOkay = false;
|
||||
}
|
||||
|
||||
if (binding.dob.getText().toString().trim().isEmpty()) {
|
||||
binding.dob.setError("Required");
|
||||
allOkay = false;
|
||||
}
|
||||
|
||||
if (binding.contactNumber.getText().toString().trim().isEmpty() ||
|
||||
binding.contactNumber.getText().toString().trim().length() < 10) {
|
||||
binding.contactNumber.setError("Invalid");
|
||||
allOkay = false;
|
||||
} else if (binding.countryCodes.getSelectedIndex() == -1 ||
|
||||
binding.countryCodes.getSelectedIndex() >= countryCodeList.size()) {
|
||||
allOkay = false;
|
||||
Toast.makeText(this, "Select a country code.", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
// validating phone number
|
||||
try {
|
||||
Phonenumber.PhoneNumber phone_number = PhoneNumberUtil.getInstance().parse(countryCodeList.get(binding.countryCodes.getSelectedIndex()) +
|
||||
binding.contactNumber.getText().toString(), "US");
|
||||
|
||||
if (!PhoneNumberUtil.getInstance().isValidNumber(phone_number)) {
|
||||
binding.contactNumber.setError("Invalid phone number");
|
||||
allOkay = false;
|
||||
}
|
||||
} catch (NumberParseException e) {
|
||||
// do nothing as we couldn't validate phone number
|
||||
}
|
||||
}
|
||||
|
||||
if (binding.email.getText().toString().trim().isEmpty()) {
|
||||
binding.email.setError("Required");
|
||||
allOkay = false;
|
||||
} else if (!Patterns.EMAIL_ADDRESS.matcher(binding.email.getText().toString()).matches()) {
|
||||
binding.email.setError("Invalid email");
|
||||
allOkay = false;
|
||||
}
|
||||
|
||||
return allOkay;
|
||||
}
|
||||
|
||||
private void updateCareGiverData() {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) return;
|
||||
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we update your data.");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
Map<String, RequestBody> body = new HashMap<>();
|
||||
|
||||
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 country_code;
|
||||
if (binding.countryCodes.getSelectedIndex() == -1 ||
|
||||
binding.countryCodes.getSelectedIndex() >= countryCodeList.size()){
|
||||
country_code = "+1";
|
||||
}else{
|
||||
country_code = countryCodeList.get(binding.countryCodes.getSelectedIndex());
|
||||
}
|
||||
RequestBody contact_number_part = RequestBody.create(country_code+binding.contactNumber.getText().toString(), MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("contact_number", contact_number_part);
|
||||
|
||||
RequestBody email_part = RequestBody.create(binding.email.getText().toString(), MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("email", email_part);
|
||||
|
||||
RequestBody dob_part = RequestBody.create(binding.dob.getText().toString(), MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("date_of_birth", dob_part);
|
||||
|
||||
MultipartBody.Part filePart = null;
|
||||
|
||||
if (selectedImageUri != null) {
|
||||
RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpeg"), new File(selectedImageUri.getPath()));
|
||||
filePart = MultipartBody.Part.createFormData("photo",
|
||||
"img_" + System.currentTimeMillis()
|
||||
, requestFile);
|
||||
}
|
||||
|
||||
if (isCaregiver){
|
||||
viewModel.updateCaregiverData(careGiverData.caregiver_xid,
|
||||
body, filePart, "Bearer " + AppUtil.getCgToken(this),
|
||||
this);
|
||||
}else{
|
||||
RequestBody street_part = RequestBody.create(binding.street.getText().toString().trim(), MediaType.parse("text/plain;charset=utf-8"));
|
||||
body.put("street", street_part);
|
||||
|
||||
viewModel.updatePatientData(careGiverData.patientId,
|
||||
body, filePart, "Bearer " + AppUtil.getCgToken(this),
|
||||
this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setDOB(int year, int month, int dayOfMonth) {
|
||||
@@ -295,14 +479,6 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
pickDate();
|
||||
return true;
|
||||
});
|
||||
|
||||
binding.email.setOnEditorActionListener(((textView, i, keyEvent) -> {
|
||||
AppUtil.closeKeyboard(this);
|
||||
binding.email.clearFocus();
|
||||
|
||||
binding.countrySpinner.show();
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
private void pickDate() {
|
||||
@@ -441,19 +617,11 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
binding.stateSpinner.setItems(stateList);
|
||||
binding.stateSpinner.clearSelectedItem();
|
||||
}
|
||||
|
||||
binding.street.requestFocus();
|
||||
|
||||
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();
|
||||
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@@ -484,4 +652,48 @@ public class EditProfileInfoActivity extends AppCompatActivity {
|
||||
|
||||
return returnString.toString();
|
||||
}
|
||||
|
||||
// update caregiver data callback
|
||||
@Override
|
||||
public void onCaregiverDataUpdated(@NonNull CareGiverData careGiverData) {
|
||||
binding.image.requestFocus();
|
||||
progressDialog.dismiss();
|
||||
|
||||
AppUtil.showAnimateDBS(this,
|
||||
getString(R.string.changes_successful), R.raw.done_anim_primary,
|
||||
3600, v3 -> {
|
||||
// here v3 is null
|
||||
CaregiverDataCache.setCareGiverData(careGiverData);
|
||||
Toast.makeText(this, "Data updated.", Toast.LENGTH_SHORT).show();
|
||||
onBackPressed();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaregiverDateUpdateFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// update patient details callback
|
||||
@Override
|
||||
public void onPatientDataUpdated(@NonNull PatientData patient) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
AppUtil.showAnimateDBS(this,
|
||||
getString(R.string.changes_successful), R.raw.done_anim_primary,
|
||||
3600, v3 -> {
|
||||
// here v3 is null
|
||||
this.careGiverData.patientDetails = patient;
|
||||
CaregiverDataCache.setCareGiverData(careGiverData);
|
||||
Toast.makeText(this, "Data updated.", Toast.LENGTH_SHORT).show();
|
||||
onBackPressed();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPatientDataUpdateFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package com.ssb.simplitend.caregiverdashboard.fragments;
|
||||
|
||||
import static com.ssb.simplitend.articles.ArticleShowerActivity.ARTICLE_TITLE;
|
||||
import static com.ssb.simplitend.articles.ArticleShowerActivity.ARTICLE_URL_KEY;
|
||||
import static com.ssb.simplitend.cg_geofencing.CgGeoFencingActivity.GEOFENCE_DETAILS_KEY;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -30,6 +32,8 @@ import com.ssb.simplitend.articles.ArticleResult;
|
||||
import com.ssb.simplitend.articles.ArticleShowerActivity;
|
||||
import com.ssb.simplitend.articles.ArticlesActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.ssb.simplitend.cg_geofencing.CgGeoFencingActivity;
|
||||
import com.ssb.simplitend.databinding.CaregiverDashFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
@@ -42,7 +46,7 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class CgDashBoardFragment extends Fragment implements
|
||||
OnMapReadyCallback, ArticleContracts.GetArticleCallback {
|
||||
OnMapReadyCallback, ArticleContracts.GetArticleCallback, CgHomeContracts.GetGeoFenceCallback {
|
||||
|
||||
// view binding
|
||||
protected CaregiverDashFragmentBinding binding;
|
||||
@@ -53,6 +57,10 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
|
||||
private PatientData patientData;
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
private GoogleMap mGoogleMap;
|
||||
|
||||
public CgDashBoardFragment(){
|
||||
// required empty
|
||||
}
|
||||
@@ -62,22 +70,29 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = CaregiverDashFragmentBinding.inflate(inflater, container, false);
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(CaregiverMainViewModel.class);
|
||||
|
||||
CaregiverDataCache.getCaregiverData(requireActivity(), (careGiverData1 -> {
|
||||
this.careGiverData = careGiverData1;
|
||||
|
||||
setDetails();
|
||||
}), true);
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
setUpMap();
|
||||
|
||||
loadArticles();
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
CaregiverDataCache.getCaregiverData(requireActivity(), (careGiverData1 -> {
|
||||
this.careGiverData = careGiverData1;
|
||||
|
||||
setDetails();
|
||||
}), true);
|
||||
}
|
||||
|
||||
private void loadArticles() {
|
||||
viewModel.getArticles(this);
|
||||
}
|
||||
@@ -92,7 +107,7 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
|
||||
binding.patientName.setText(patientData.first_name);
|
||||
|
||||
setUpMap();
|
||||
loadPatientData();
|
||||
}
|
||||
|
||||
private void setUpMap() {
|
||||
@@ -202,6 +217,28 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull GoogleMap googleMap) {
|
||||
this.mGoogleMap = googleMap;
|
||||
|
||||
loadPatientData();
|
||||
|
||||
googleMap.setOnMapClickListener(latLng1 -> {
|
||||
if (careGiverData != null) {
|
||||
progressDialog.setTitle("please wait...");
|
||||
progressDialog.setMessage("while we load GeoFence.");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
viewModel.getGeoFenceDetails(careGiverData.caregiver_xid,
|
||||
"Bearer " + AppUtil.getCgToken(requireContext()),
|
||||
this);
|
||||
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadPatientData() {
|
||||
LatLng latLng;
|
||||
|
||||
// loading patient's location
|
||||
@@ -217,18 +254,29 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
latLng = new LatLng(18.93294274664527, 72.82806102186441);
|
||||
}
|
||||
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));
|
||||
if (mGoogleMap == null) return;
|
||||
|
||||
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.position(latLng)
|
||||
.title(patientData.first_name + "");
|
||||
|
||||
googleMap.addMarker(markerOptions);
|
||||
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));;
|
||||
mGoogleMap.addMarker(markerOptions);
|
||||
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));;
|
||||
}
|
||||
|
||||
googleMap.setOnMapClickListener(latLng1 -> {
|
||||
Intent intent = new Intent(requireActivity(), CgGeoFencingActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
@Override
|
||||
public void onGeofenceDetailsFetched(GeoFenceDetails geoFenceDetails) {
|
||||
progressDialog.dismiss();
|
||||
Intent intent = new Intent(requireActivity(), CgGeoFencingActivity.class);
|
||||
intent.putExtra(GEOFENCE_DETAILS_KEY, geoFenceDetails);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeofenceDetailsFetchFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.fragments;
|
||||
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.*;
|
||||
import static com.ssb.simplitend.cg_geofencing.CgGeoFencingActivity.GEOFENCE_DETAILS_KEY;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
@@ -13,23 +15,33 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.EditProfileInfoActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.ssb.simplitend.cg_geofencing.CgGeoFencingActivity;
|
||||
import com.ssb.simplitend.databinding.MyPatientFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
|
||||
public class MyPatientFragment extends Fragment {
|
||||
public class MyPatientFragment extends Fragment implements CgHomeContracts.GetGeoFenceCallback {
|
||||
|
||||
// view binding
|
||||
protected MyPatientFragmentBinding binding;
|
||||
|
||||
private CareGiverData careGiverData;
|
||||
|
||||
public MyPatientFragment(){
|
||||
private CaregiverMainViewModel viewModel;
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
public MyPatientFragment() {
|
||||
// required empty
|
||||
}
|
||||
|
||||
@@ -38,6 +50,9 @@ public class MyPatientFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = MyPatientFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(CaregiverMainViewModel.class);
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
|
||||
adjustLayout();
|
||||
|
||||
initViews();
|
||||
@@ -47,6 +62,30 @@ public class MyPatientFragment extends Fragment {
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
CaregiverDataCache.getCaregiverData(requireContext(), (careGiverData1 -> {
|
||||
this.careGiverData = careGiverData1;
|
||||
if (careGiverData1 == null || careGiverData1.patientDetails == null) {
|
||||
Toast.makeText(requireContext(), "Couldn't load patient details.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
binding.name.setText(careGiverData1.patientDetails.first_name);
|
||||
binding.phoneNumber.setText(careGiverData1.patientDetails.phone_number);
|
||||
|
||||
if (careGiverData1.patientDetails.profile_photo != null){
|
||||
Glide.with(requireContext())
|
||||
.load(AppUtil.IMAGE_BASE_URL + careGiverData1.patientDetails.profile_photo)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(R.drawable.caregiver_img)
|
||||
.into(binding.profileImg);
|
||||
}
|
||||
|
||||
}), true);
|
||||
}
|
||||
|
||||
// adjusts the guideline percentage w.r.t the aspect ratio of the screen
|
||||
private void adjustLayout() {
|
||||
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||
@@ -56,23 +95,13 @@ public class MyPatientFragment extends Fragment {
|
||||
// Calculate aspect ratio
|
||||
float aspectRatio = (float) screenHeight / (float) screenWidth;
|
||||
|
||||
if (aspectRatio < 2.03f){
|
||||
if (aspectRatio < 2.03f) {
|
||||
binding.guideline.setGuidelinePercent(0.55f);
|
||||
}
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
CaregiverDataCache.getCaregiverData(requireContext(), (careGiverData1 -> {
|
||||
this.careGiverData = careGiverData1;
|
||||
if (careGiverData1 == null || careGiverData1.patientDetails == null){
|
||||
Toast.makeText(requireContext(), "Couldn't load patient details.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
binding.name.setText(careGiverData1.patientDetails.first_name);
|
||||
binding.phoneNumber.setText(careGiverData1.patientDetails.phone_number);
|
||||
|
||||
}), true);
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
@@ -83,8 +112,19 @@ public class MyPatientFragment extends Fragment {
|
||||
});
|
||||
|
||||
binding.geofence.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(requireActivity(), CgGeoFencingActivity.class);
|
||||
startActivity(intent);
|
||||
if (careGiverData != null) {
|
||||
progressDialog.setTitle("please wait...");
|
||||
progressDialog.setMessage("while we load GeoFence.");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
viewModel.getGeoFenceDetails(careGiverData.caregiver_xid,
|
||||
"Bearer " + AppUtil.getCgToken(requireContext()),
|
||||
this);
|
||||
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
binding.medication.setOnClickListener(v -> {
|
||||
@@ -104,7 +144,7 @@ public class MyPatientFragment extends Fragment {
|
||||
});
|
||||
|
||||
binding.phoneNumber.setOnClickListener(v -> {
|
||||
if (careGiverData != null && careGiverData.patientDetails != null){
|
||||
if (careGiverData != null && careGiverData.patientDetails != null) {
|
||||
AppUtil.dialPhone(requireActivity(), careGiverData.patientDetails.phone_number);
|
||||
}
|
||||
});
|
||||
@@ -116,4 +156,18 @@ public class MyPatientFragment extends Fragment {
|
||||
intent.putExtra(WHICH_FRAGMENT, which_f);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeofenceDetailsFetched(@NonNull GeoFenceDetails geoFenceDetails) {
|
||||
progressDialog.dismiss();
|
||||
Intent intent = new Intent(requireActivity(), CgGeoFencingActivity.class);
|
||||
intent.putExtra(GEOFENCE_DETAILS_KEY, geoFenceDetails);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeofenceDetailsFetchFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,23 +3,27 @@ package com.ssb.simplitend.caregiverdashboard.mvvm;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.google.android.material.appbar.MaterialToolbar;
|
||||
import com.ssb.simplitend.articles.ArticleContracts;
|
||||
import com.ssb.simplitend.articles.ArticleResult;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.yarolegovich.slidingrootnav.SlidingRootNav;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class CaregiverMainViewModel extends ViewModel {
|
||||
|
||||
public SlidingRootNav slidingRootNav;
|
||||
|
||||
private final HomeRepository homeRepository;
|
||||
private final CgHomeRepository cgHomeRepository;
|
||||
|
||||
private ArrayList<ArticleResult> articleResults;
|
||||
|
||||
public CaregiverMainViewModel(){
|
||||
this.homeRepository = HomeRepository.getHomeRepository();
|
||||
this.cgHomeRepository = CgHomeRepository.getHomeRepository();
|
||||
}
|
||||
|
||||
public void setArticleResults(ArrayList<ArticleResult> articleResults) {
|
||||
@@ -28,11 +32,46 @@ public class CaregiverMainViewModel extends ViewModel {
|
||||
|
||||
public void getArticles(@NonNull ArticleContracts.GetArticleCallback articleCallback){
|
||||
if (articleResults == null){
|
||||
homeRepository.getArticles(articleCallback);
|
||||
cgHomeRepository.getArticles(articleCallback);
|
||||
}else{
|
||||
articleCallback.onArticlesFetched(articleResults);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveGeoFenceDetails(@NonNull GeoFenceDetails geoFenceDetails,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.SaveGeoFenceCallback geoFenceCallback){
|
||||
cgHomeRepository.saveGeoFenceDetails(geoFenceDetails, token, geoFenceCallback);
|
||||
}
|
||||
|
||||
public void getGeoFenceDetails(int cg_xid,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.GetGeoFenceCallback getGeoFenceCallback){
|
||||
cgHomeRepository.getGeoFenceDetails(cg_xid, token, getGeoFenceCallback);
|
||||
}
|
||||
|
||||
public void updateCaregiverData(int cg_xid,
|
||||
Map<String, RequestBody> body,
|
||||
MultipartBody.Part photo,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.UpdateCaregiverDataCallback updateCaregiverDataCallback){
|
||||
cgHomeRepository.updateCaregiverData(cg_xid, body, photo, token, updateCaregiverDataCallback);
|
||||
}
|
||||
|
||||
public void updatePatientData(int patient_xid,
|
||||
Map<String, RequestBody> body,
|
||||
MultipartBody.Part photo,
|
||||
String token,
|
||||
@NonNull CgHomeContracts.UpdatePatientDataCallback patientDataCallback){
|
||||
cgHomeRepository.updatePatientData(patient_xid, body, photo, token, patientDataCallback);
|
||||
}
|
||||
|
||||
public void updatePatientAddress(int pat_id,
|
||||
Map<String, String> body,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.UpdatePatientAddressCallback patientAddressCallback){
|
||||
cgHomeRepository.updatePatientAddress(pat_id, body, token, patientAddressCallback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.mvvm;
|
||||
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
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 java.util.Map;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.PartMap;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface CgDashboardApiService {
|
||||
|
||||
@GET("api/get-caregiver-patient-location-link/{id}")
|
||||
Call<CallResponse<GeoFenceDetails>> getGeofenceDetails(@Path("id") int id,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@POST("api/caregiver-patient-location-link")
|
||||
Call<CallResponse<GeoFenceDetails>> saveGeoFenceDetails(@Body GeoFenceDetails geoFenceDetails,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@Multipart
|
||||
@POST("api/caregiver-profile-update/{id}")
|
||||
Call<CallResponse<CareGiverData>> updateCaregiverData(@Path("id") int cg_xid,
|
||||
@PartMap Map<String, RequestBody> body,
|
||||
@Part MultipartBody.Part photo,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@Multipart
|
||||
@POST("api/patient-profile-update/{id}")
|
||||
Call<CallResponse<PatientData>> updatePatientData(@Path("id") int pat_xid,
|
||||
@PartMap Map<String, RequestBody> body,
|
||||
@Part MultipartBody.Part photo,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@POST("api/update-patient-address/{id}")
|
||||
Call<CallResponse<PatientData>> updatePatientAddress(@Path("id") int pat_xid,
|
||||
@Body Map<String, String> body,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.mvvm;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
public interface CgHomeContracts {
|
||||
|
||||
interface GetGeoFenceCallback {
|
||||
|
||||
void onGeofenceDetailsFetched(GeoFenceDetails geoFenceDetails);
|
||||
|
||||
void onGeofenceDetailsFetchFailed(Throwable throwable, String message);
|
||||
|
||||
}
|
||||
|
||||
interface SaveGeoFenceCallback {
|
||||
|
||||
void onGeofenceDetailsSaved(GeoFenceDetails geoFenceDetails);
|
||||
|
||||
void onGeofenceDetailsSaveFailed(Throwable throwable, String message);
|
||||
|
||||
}
|
||||
|
||||
interface UpdateCaregiverDataCallback {
|
||||
void onCaregiverDataUpdated(@NonNull CareGiverData careGiverData);
|
||||
|
||||
void onCaregiverDateUpdateFailed(Throwable throwable, String message);
|
||||
}
|
||||
|
||||
interface UpdatePatientDataCallback {
|
||||
void onPatientDataUpdated(@NonNull PatientData patientData);
|
||||
|
||||
void onPatientDataUpdateFailed(Throwable throwable, String message);
|
||||
}
|
||||
|
||||
interface UpdatePatientAddressCallback {
|
||||
void onPatientAddressUpdated(@NonNull PatientData patientData);
|
||||
|
||||
void onPatientAddressUpdateFailed(Throwable throwable, String message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.mvvm;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.ssb.simplitend.apputils.RetrofitHelper;
|
||||
import com.ssb.simplitend.articles.ArticleContracts;
|
||||
import com.ssb.simplitend.articles.ArticlePresenter;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
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 java.util.Map;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.PartMap;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public class CgHomeRepository {
|
||||
|
||||
private static CgHomeRepository cgHomeRepository;
|
||||
|
||||
private final CgDashboardApiService dash_apiService;
|
||||
|
||||
private CgHomeRepository(){
|
||||
dash_apiService = RetrofitHelper.getRetrofit().create(CgDashboardApiService.class);
|
||||
}
|
||||
|
||||
public static synchronized CgHomeRepository getHomeRepository(){
|
||||
if (cgHomeRepository == null){
|
||||
cgHomeRepository = new CgHomeRepository();
|
||||
}
|
||||
|
||||
return cgHomeRepository;
|
||||
}
|
||||
|
||||
public void getArticles(@NonNull ArticleContracts.GetArticleCallback getArticleCallback){
|
||||
ArticlePresenter articlePresenter = ArticlePresenter.getArticlePresenter();
|
||||
|
||||
articlePresenter.getArticles(getArticleCallback);
|
||||
}
|
||||
|
||||
public void getGeoFenceDetails(int cg_xid,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.GetGeoFenceCallback getGeoFenceCallback){
|
||||
|
||||
dash_apiService.getGeofenceDetails(cg_xid, token)
|
||||
.enqueue(new Callback<CallResponse<GeoFenceDetails>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<GeoFenceDetails>> call, Response<CallResponse<GeoFenceDetails>> response) {
|
||||
if (response.body() != null){
|
||||
if (response.body().status != 200){
|
||||
getGeoFenceCallback.onGeofenceDetailsFetchFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.body().result == null){
|
||||
getGeoFenceCallback.onGeofenceDetailsFetched(new GeoFenceDetails());
|
||||
}else{
|
||||
getGeoFenceCallback.onGeofenceDetailsFetched(response.body().result);
|
||||
}
|
||||
}else{
|
||||
getGeoFenceCallback.onGeofenceDetailsFetchFailed(new Exception(), "Couldn't load GeoFence.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<GeoFenceDetails>> call, Throwable t) {
|
||||
getGeoFenceCallback.onGeofenceDetailsFetchFailed(new Exception(), "Couldn't load GeoFence.");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void saveGeoFenceDetails(@NonNull GeoFenceDetails geoFenceDetails,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.SaveGeoFenceCallback geoFenceCallback){
|
||||
|
||||
dash_apiService.saveGeoFenceDetails(geoFenceDetails, token)
|
||||
.enqueue(new Callback<CallResponse<GeoFenceDetails>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<GeoFenceDetails>> call, Response<CallResponse<GeoFenceDetails>> response) {
|
||||
if (response.body() != null){
|
||||
if (response.body().status != 200 || response.body().result == null){
|
||||
geoFenceCallback.onGeofenceDetailsSaveFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
geoFenceCallback.onGeofenceDetailsSaved(response.body().result);
|
||||
}else{
|
||||
geoFenceCallback.onGeofenceDetailsSaveFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<GeoFenceDetails>> call, Throwable t) {
|
||||
geoFenceCallback.onGeofenceDetailsSaveFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void updateCaregiverData(int cg_xid,
|
||||
Map<String, RequestBody> body,
|
||||
MultipartBody.Part photo,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.UpdateCaregiverDataCallback updateCaregiverDataCallback){
|
||||
dash_apiService.updateCaregiverData(cg_xid, body, photo, token)
|
||||
.enqueue(new Callback<CallResponse<CareGiverData>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<CareGiverData>> call, Response<CallResponse<CareGiverData>> response) {
|
||||
if (response.body() != null){
|
||||
if (response.body().status != 200 || response.body().result == null){
|
||||
updateCaregiverDataCallback.onCaregiverDateUpdateFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
updateCaregiverDataCallback.onCaregiverDataUpdated(response.body().result);
|
||||
}else{
|
||||
updateCaregiverDataCallback.onCaregiverDateUpdateFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<CareGiverData>> call, Throwable t) {
|
||||
updateCaregiverDataCallback.onCaregiverDateUpdateFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updatePatientData(int patient_xid,
|
||||
Map<String, RequestBody> body,
|
||||
MultipartBody.Part photo,
|
||||
String token,
|
||||
@NonNull CgHomeContracts.UpdatePatientDataCallback patientDataCallback){
|
||||
dash_apiService.updatePatientData(patient_xid, body, photo, token)
|
||||
.enqueue(new Callback<CallResponse<PatientData>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<PatientData>> call, Response<CallResponse<PatientData>> response) {
|
||||
if (response.body() != null){
|
||||
if (response.body().status != 200 || response.body().result == null){
|
||||
patientDataCallback.onPatientDataUpdateFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
patientDataCallback.onPatientDataUpdated(response.body().result);
|
||||
}else{
|
||||
patientDataCallback.onPatientDataUpdateFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<PatientData>> call, Throwable t) {
|
||||
patientDataCallback.onPatientDataUpdateFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updatePatientAddress(int pat_id,
|
||||
Map<String, String> body,
|
||||
@NonNull String token,
|
||||
@NonNull CgHomeContracts.UpdatePatientAddressCallback patientAddressCallback){
|
||||
dash_apiService.updatePatientAddress(pat_id, body, token)
|
||||
.enqueue(new Callback<CallResponse<PatientData>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<PatientData>> call, Response<CallResponse<PatientData>> response) {
|
||||
if (response.body() != null){
|
||||
if (response.body().status != 200 || response.body().result == null){
|
||||
patientAddressCallback.onPatientAddressUpdateFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
patientAddressCallback.onPatientAddressUpdated(response.body().result);
|
||||
}else{
|
||||
patientAddressCallback.onPatientAddressUpdateFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<PatientData>> call, Throwable t) {
|
||||
patientAddressCallback.onPatientAddressUpdateFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.mvvm;
|
||||
|
||||
public interface DashboardApiService {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.mvvm;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.ssb.simplitend.articles.ArticleContracts;
|
||||
import com.ssb.simplitend.articles.ArticlePresenter;
|
||||
|
||||
public class HomeRepository {
|
||||
|
||||
private static HomeRepository homeRepository;
|
||||
|
||||
private HomeRepository(){}
|
||||
|
||||
public static synchronized HomeRepository getHomeRepository(){
|
||||
if (homeRepository == null){
|
||||
homeRepository = new HomeRepository();
|
||||
}
|
||||
|
||||
return homeRepository;
|
||||
}
|
||||
|
||||
public void getArticles(@NonNull ArticleContracts.GetArticleCallback getArticleCallback){
|
||||
ArticlePresenter articlePresenter = ArticlePresenter.getArticlePresenter();
|
||||
|
||||
articlePresenter.getArticles(getArticleCallback);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.mvvm.models;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class GeoFenceDetails implements Serializable {
|
||||
public int id;
|
||||
public String caregiver_xid;
|
||||
public String patient_xid;
|
||||
public String location_name;
|
||||
public String radius;
|
||||
public String type;
|
||||
public String message;
|
||||
public String created_at;
|
||||
public String updated_at;
|
||||
|
||||
public GeoFenceDetails(){}
|
||||
}
|
||||
@@ -1,22 +1,26 @@
|
||||
package com.ssb.simplitend.cg_geofencing;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.CameraPosition;
|
||||
import com.google.android.gms.maps.model.CircleOptions;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
@@ -26,25 +30,44 @@ import com.google.android.libraries.places.widget.Autocomplete;
|
||||
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.ssb.simplitend.databinding.ActivityCgGeofencingBinding;
|
||||
import com.ssb.simplitend.databinding.GeofenceBottomSheetBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class CgGeoFencingActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
public class CgGeoFencingActivity extends AppCompatActivity implements OnMapReadyCallback,
|
||||
CgHomeContracts.SaveGeoFenceCallback, CgHomeContracts.UpdatePatientAddressCallback {
|
||||
|
||||
private static final String TAG = "CgGeoFencingActivity";
|
||||
|
||||
// view binding
|
||||
protected ActivityCgGeofencingBinding binding;
|
||||
|
||||
private CaregiverMainViewModel viewModel;
|
||||
|
||||
public static final String GEOFENCE_DETAILS_KEY = "geofence_details";
|
||||
private GeoFenceDetails geoFenceDetails;
|
||||
|
||||
private static final String MILES = "miles";
|
||||
private static final String KMS = "kms";
|
||||
|
||||
// bottom sheet binding
|
||||
private BottomSheetDialog bottomSheetDialog;
|
||||
|
||||
private GeofenceBottomSheetBinding geofence_bs_binding;
|
||||
|
||||
private CareGiverData careGiverData;
|
||||
private PatientData patientData;
|
||||
|
||||
private GoogleMap mMap;
|
||||
@@ -53,91 +76,109 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
private ActivityResultLauncher<Intent> startAutocompleteMapSearch;
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityCgGeofencingBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
Intent intent = getIntent();
|
||||
|
||||
if (intent != null && intent.hasExtra(GEOFENCE_DETAILS_KEY)) {
|
||||
try {
|
||||
geoFenceDetails = (GeoFenceDetails) intent.getSerializableExtra(GEOFENCE_DETAILS_KEY);
|
||||
if (geoFenceDetails == null) throw new Exception();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "Couldn't load Geofence.", Toast.LENGTH_SHORT).show();
|
||||
geoFenceDetails = new GeoFenceDetails();
|
||||
onBackPressed();
|
||||
}
|
||||
} else {
|
||||
onBackPressed();
|
||||
}
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(CaregiverMainViewModel.class);
|
||||
progressDialog = new ProgressDialog(this);
|
||||
|
||||
geofence_bs_binding = GeofenceBottomSheetBinding.inflate(getLayoutInflater());
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData -> {
|
||||
if (careGiverData == null) return;;
|
||||
if (careGiverData == null) return;
|
||||
|
||||
this.careGiverData = careGiverData;
|
||||
this.patientData = careGiverData.patientDetails;
|
||||
}), true);
|
||||
|
||||
initViews();
|
||||
|
||||
initBottomSheet();
|
||||
|
||||
clickEvents();
|
||||
|
||||
}
|
||||
|
||||
private void initBottomSheet() {
|
||||
|
||||
bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
|
||||
bottomSheetDialog.setContentView(geofence_bs_binding.getRoot());
|
||||
bottomSheetDialog.setCancelable(true);
|
||||
|
||||
if (geoFenceDetails == null) return;
|
||||
|
||||
float radius = 0.0f;
|
||||
if (geoFenceDetails.radius != null){
|
||||
try {
|
||||
radius = Float.parseFloat(geoFenceDetails.radius);
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (MILES.equals(geoFenceDetails.type)){
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(1);
|
||||
radius = radius / 1609.34f;
|
||||
}else{
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(0);
|
||||
radius = radius / 1000f;
|
||||
}
|
||||
|
||||
geofence_bs_binding.unitSpinner.setLifecycleOwner(this);
|
||||
geofence_bs_binding.unitSpinner.setIsFocusable(true);
|
||||
|
||||
geofence_bs_binding.radius.setText("" + radius);
|
||||
geofence_bs_binding.message.setText(geoFenceDetails.message);
|
||||
geofence_bs_binding.location.setText(geoFenceDetails.location_name);
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
||||
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.geofence_map);
|
||||
if (mapFragment != null) {
|
||||
mapFragment.getMapAsync(this);
|
||||
}else{
|
||||
} else {
|
||||
Toast.makeText(this, "Couldn't load map. Please try again.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
|
||||
bottomSheetDialog.setContentView(geofence_bs_binding.getRoot());
|
||||
bottomSheetDialog.setCancelable(true);
|
||||
|
||||
try {
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(0);
|
||||
}catch (Exception e){
|
||||
ArrayList<String> arrayList = new ArrayList<>();
|
||||
arrayList.add("Kms");
|
||||
arrayList.add("Miles");
|
||||
geofence_bs_binding.unitSpinner.setItems(arrayList);
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(0);
|
||||
}
|
||||
|
||||
geofence_bs_binding.unitSpinner.setLifecycleOwner(this);
|
||||
geofence_bs_binding.unitSpinner.setIsFocusable(true);
|
||||
|
||||
registerMapSearchResultLauncher();
|
||||
|
||||
}
|
||||
|
||||
private void clickEvents(){
|
||||
private void clickEvents() {
|
||||
binding.backBtn.setOnClickListener(v -> onBackPressed());
|
||||
|
||||
binding.setGf.setOnClickListener(v -> {
|
||||
if (bottomSheetDialog != null){
|
||||
if (bottomSheetDialog != null) {
|
||||
bottomSheetDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
geofence_bs_binding.save.setOnClickListener(v -> {
|
||||
Float radius = getRadius();
|
||||
|
||||
if (radius == null){
|
||||
Toast.makeText(this, "Invalid radius", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
if (allOkay()){
|
||||
saveGeoFence();
|
||||
}
|
||||
|
||||
// convert to meters
|
||||
if (geofence_bs_binding.unitSpinner.getSelectedIndex() == 1){
|
||||
// it is miles
|
||||
radius = radius * 1609.34f; // to meters
|
||||
}else{
|
||||
// it is kms
|
||||
radius = radius * 1000; // to meters
|
||||
}
|
||||
|
||||
if (radius < 100){
|
||||
Toast.makeText(this, "Radius should be minimum 100 meters.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
addMarker(mLatLng);
|
||||
addCircle(radius);
|
||||
});
|
||||
|
||||
binding.search.setOnClickListener(v -> {
|
||||
@@ -149,6 +190,114 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
startAutocompleteMapSearch.launch(intent);
|
||||
});
|
||||
|
||||
binding.resetBtn.setOnClickListener(v -> {
|
||||
loadPatientsLocation();
|
||||
binding.updateBtnsView.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
binding.updateBtn.setOnClickListener(v -> {
|
||||
if (careGiverData != null){
|
||||
updatePatientAddress();
|
||||
}else{
|
||||
Toast.makeText(this, "Cannot update address.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updatePatientAddress() {
|
||||
if (this.mLatLng == null) return;
|
||||
|
||||
try {
|
||||
// fetching address from the lag lng
|
||||
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
|
||||
List<Address> addresses = geocoder.getFromLocation(mLatLng.latitude, mLatLng.longitude, 1);
|
||||
|
||||
if (addresses != null && addresses.size() > 0 && addresses.get(0) != null) {
|
||||
Address address = addresses.get(0);
|
||||
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we update the patients address");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
Map<String, String> body = new HashMap<>();
|
||||
|
||||
body.put("town", (address.getSubLocality() != null?address.getSubLocality():address.getLocality()));
|
||||
body.put("street", (address.getSubThoroughfare() != null?address.getSubThoroughfare():address.getThoroughfare()));
|
||||
body.put("state", address.getAdminArea());
|
||||
body.put("country", address.getCountryName());
|
||||
body.put("zip_code",address.getPostalCode());
|
||||
body.put("lat", this.mLatLng.latitude + "");
|
||||
body.put("lng", this.mLatLng.longitude + "");
|
||||
|
||||
viewModel.updatePatientAddress(careGiverData.patientId, body,
|
||||
"Bearer " + AppUtil.getCgToken(this),
|
||||
this);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// do nothing as we couldn't load the location from the lat lng
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allOkay() {
|
||||
geofence_bs_binding.message.setError(null);
|
||||
geofence_bs_binding.location.setError(null);
|
||||
boolean allOkay = true;
|
||||
|
||||
if (geofence_bs_binding.message.getText().toString().trim().isEmpty()){
|
||||
allOkay = false;
|
||||
geofence_bs_binding.message.setError("Required");
|
||||
}
|
||||
|
||||
if (geofence_bs_binding.location.getText().toString().trim().isEmpty()){
|
||||
allOkay = false;
|
||||
geofence_bs_binding.location.setError("Required");
|
||||
}
|
||||
|
||||
return allOkay;
|
||||
}
|
||||
|
||||
private void saveGeoFence() {
|
||||
Float radius = getRadius();
|
||||
|
||||
if (radius == null) {
|
||||
Toast.makeText(this, "Invalid radius", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// convert to meters
|
||||
if (geofence_bs_binding.unitSpinner.getSelectedIndex() == 1) {
|
||||
// it is miles
|
||||
radius = radius * 1609.34f; // to meters
|
||||
} else {
|
||||
// it is kms
|
||||
radius = radius * 1000; // to meters
|
||||
}
|
||||
|
||||
if (radius < 1000) {
|
||||
Toast.makeText(this, "Radius should be minimum 1 KM.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}else if (radius > 10_000){
|
||||
Toast.makeText(this, "Radius should be maximum 10 KM.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
geoFenceDetails.message = geofence_bs_binding.message.getText().toString();
|
||||
geoFenceDetails.location_name = geofence_bs_binding.location.getText().toString();
|
||||
geoFenceDetails.radius = "" + radius;
|
||||
geoFenceDetails.type = geofence_bs_binding.unitSpinner.getSelectedIndex() == 0?KMS:MILES;
|
||||
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we set Geofence for you.");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
viewModel.saveGeoFenceDetails(geoFenceDetails,
|
||||
"Bearer " + AppUtil.getCgToken(this),
|
||||
this);
|
||||
|
||||
}
|
||||
|
||||
private void addCircle(float radius) {
|
||||
@@ -162,9 +311,6 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
mMap.addCircle(circleOptions);
|
||||
bottomSheetDialog.dismiss();
|
||||
mMap.animateCamera(CameraUpdateFactory.zoomTo(13));
|
||||
|
||||
Toast.makeText(this, "Geofence added. Radius : " + radius + " meters.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private Float getRadius() {
|
||||
@@ -172,8 +318,9 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
try {
|
||||
radius = Float.valueOf(geofence_bs_binding.radius.getText().toString());
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
Log.e(TAG, "getRadius: ", e);
|
||||
}
|
||||
|
||||
return radius;
|
||||
@@ -183,6 +330,19 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
public void onMapReady(@NonNull GoogleMap googleMap) {
|
||||
this.mMap = googleMap;
|
||||
|
||||
loadPatientsLocation();
|
||||
|
||||
mMap.setOnMapClickListener(latLng1 -> {
|
||||
this.mLatLng = latLng1;
|
||||
|
||||
binding.updateBtnsView.setVisibility(View.VISIBLE);
|
||||
|
||||
addMarker(this.mLatLng);
|
||||
addCircle();
|
||||
});
|
||||
}
|
||||
|
||||
private void loadPatientsLocation() {
|
||||
LatLng latLng;
|
||||
|
||||
// loading patient's location
|
||||
@@ -193,28 +353,40 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
double lng = Double.parseDouble(patientData.lng);
|
||||
|
||||
latLng = new LatLng(lat, lng);
|
||||
}catch (Exception e){
|
||||
addMarker(latLng);
|
||||
addCircle();
|
||||
} catch (Exception e) {
|
||||
// near marine drive
|
||||
latLng = new LatLng(18.93294274664527, 72.82806102186441);
|
||||
}
|
||||
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));
|
||||
addMarker(latLng);
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 13));
|
||||
}
|
||||
|
||||
private void addMarker(@NonNull LatLng latLng){
|
||||
if (mMap == null || patientData == null) return;
|
||||
private void addCircle() {
|
||||
try {
|
||||
if (geoFenceDetails.radius != null){
|
||||
float radius = Float.parseFloat(geoFenceDetails.radius);
|
||||
addCircle(radius);
|
||||
}
|
||||
}catch (Exception e){
|
||||
Log.e(TAG, "onMapReady: ", e);
|
||||
Toast.makeText(this, "Couldn't load geofence.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void addMarker(@NonNull LatLng latLng) {
|
||||
if (mMap == null || patientData == null) return;
|
||||
this.mLatLng = latLng;
|
||||
|
||||
mMap.clear();
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.position(latLng)
|
||||
.title(patientData.first_name + "");
|
||||
.title(patientData.first_name + "");
|
||||
|
||||
mMap.addMarker(markerOptions);
|
||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));;
|
||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 13));
|
||||
}
|
||||
|
||||
private void registerMapSearchResultLauncher() {
|
||||
@@ -234,11 +406,46 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
if (place.getLatLng() == null) return;
|
||||
|
||||
addMarker(place.getLatLng());
|
||||
this.mLatLng = place.getLatLng();
|
||||
|
||||
binding.updateBtnsView.setVisibility(View.VISIBLE);
|
||||
|
||||
addMarker(this.mLatLng);
|
||||
addCircle();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeofenceDetailsSaved(GeoFenceDetails geoFenceDetails) {
|
||||
progressDialog.dismiss();
|
||||
this.geoFenceDetails = geoFenceDetails;
|
||||
|
||||
bottomSheetDialog.dismiss();
|
||||
|
||||
addMarker(mLatLng);
|
||||
addCircle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeofenceDetailsSaveFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPatientAddressUpdated(@NonNull PatientData patientData) {
|
||||
binding.updateBtnsView.setVisibility(View.GONE);
|
||||
this.careGiverData.patientDetails = patientData;
|
||||
CaregiverDataCache.setCareGiverData(this.careGiverData);
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(this, "Patient's location updated.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPatientAddressUpdateFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(this, "Couldn't update patient's location.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ssb.simplitend.patientprofile;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
@@ -24,10 +25,17 @@ import com.daimajia.androidanimations.library.Techniques;
|
||||
import com.daimajia.androidanimations.library.YoYo;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.RetrofitHelper;
|
||||
import com.ssb.simplitend.databinding.RegisterationDoneFragmentBinding;
|
||||
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
public class RegisterCompleteFragment extends Fragment {
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class RegisterCompleteFragment extends Fragment implements ProfileContracts.ProfileProgressCallback{
|
||||
|
||||
public RegisterationDoneFragmentBinding binding;
|
||||
|
||||
@@ -36,6 +44,8 @@ public class RegisterCompleteFragment extends Fragment {
|
||||
|
||||
int profile_progress, is_connect_to_caregiver;
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
public RegisterCompleteFragment() {
|
||||
// required
|
||||
}
|
||||
@@ -44,6 +54,7 @@ public class RegisterCompleteFragment extends Fragment {
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = RegisterationDoneFragmentBinding.inflate(inflater, container, false);
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
|
||||
if (getArguments() != null) {
|
||||
profile_progress = getArguments().getInt(PROFILE_PROGRESS, 20);
|
||||
@@ -83,28 +94,75 @@ public class RegisterCompleteFragment extends Fragment {
|
||||
|
||||
binding.proceed.setOnClickListener(v -> {
|
||||
|
||||
if (is_connect_to_caregiver == 1) {
|
||||
gotoPatientDashBoard();
|
||||
} else {
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Ask Caregiver to register",
|
||||
"Kindly ask CareGiver to complete registeration.",
|
||||
"OK",
|
||||
((dialogInterface, i) -> {
|
||||
|
||||
}), null, null);
|
||||
}
|
||||
checkConnectionStatus();
|
||||
});
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void checkConnectionStatus() {
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we check the Caregiver connection status.");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
PatientProfileAPIService apiService = RetrofitHelper.getRetrofit().create(PatientProfileAPIService.class);
|
||||
|
||||
String token = "Bearer " + AppUtil.getPatientToken(requireContext());
|
||||
|
||||
apiService.getUsrProfileProgress(token)
|
||||
.enqueue(new Callback<CallResponse<PatientData>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<PatientData>> call, Response<CallResponse<PatientData>> response) {
|
||||
if (response.body() != null) {
|
||||
if (response.body().status != 200 || response.body().result == null) {
|
||||
onProfileProgressFetchFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
onProfileProgressFetched(response.body().result);
|
||||
} else {
|
||||
onProfileProgressFetchFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<PatientData>> call, Throwable t) {
|
||||
onProfileProgressFetchFailed(new Exception(), "Please try again later.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void gotoPatientDashBoard() {
|
||||
Intent intent = new Intent(requireActivity(), DashBoardActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
requireActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileProgressFetched(PatientData patientData) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
if (patientData.isCareGiverConnectedWithPatient == 1) {
|
||||
gotoPatientDashBoard();
|
||||
} else {
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Ask Caregiver to register",
|
||||
"Kindly ask CareGiver to complete registeration.",
|
||||
"OK",
|
||||
((dialogInterface, i) -> {
|
||||
|
||||
}), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileProgressFetchFailed(Throwable t, String message) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
//binding.animIv.setAnimation(R.raw.done_anim_2);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CgForgotPwdResult;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.ConnectCgResult;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -87,7 +87,6 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
|
||||
// image selected uri
|
||||
private Uri selectedImageUri;
|
||||
|
||||
private ContactData contactData;
|
||||
|
||||
// Remote contact list
|
||||
|
||||
@@ -261,7 +261,6 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
Intent intent = result.getData();
|
||||
if (intent != null) {
|
||||
Place place = Autocomplete.getPlaceFromIntent(intent);
|
||||
Log.d(TAG, "Place: selected" + place.getLatLng());
|
||||
|
||||
if (place.getLatLng() == null) return;
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ public class RegisterFragment extends Fragment implements WelcomeContracts.Verif
|
||||
} else if (binding.countryCodes.getSelectedIndex() == -1 ||
|
||||
binding.countryCodes.getSelectedIndex() >= countryCodeList.size()) {
|
||||
allOkay = false;
|
||||
Toast.makeText(requireContext(), "Select a coutnry code.", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(requireContext(), "Select a country code.", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
// validating phone number
|
||||
try {
|
||||
|
||||
@@ -24,6 +24,8 @@ public class PatientData {
|
||||
// for payload purpose
|
||||
public String pin_code, c_pin_code;
|
||||
|
||||
public String profile_photo;
|
||||
|
||||
// progress flags
|
||||
public int isCareGiverLink
|
||||
, isPatientReminderData
|
||||
|
||||
@@ -52,25 +52,21 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="@dimen/_100sdp"
|
||||
android:layout_height="@dimen/_100sdp"
|
||||
|
||||
android:src="@drawable/static_3"
|
||||
app:civ_circle_background_color="@color/white"
|
||||
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="35dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
app:cardCornerRadius="@dimen/_50sdp"
|
||||
app:strokeColor="@color/color_accent"
|
||||
app:strokeWidth="1dp"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="@dimen/_100sdp"
|
||||
android:layout_height="@dimen/_100sdp"
|
||||
android:contentDescription="@string/onboard_image"
|
||||
android:src="@drawable/ic_contact" />
|
||||
android:layout_marginHorizontal="15dp"
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
|
||||
@@ -164,6 +164,52 @@
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/update_btns_view"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_margin="15dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:weightSum="2">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/reset_btn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
||||
android:text="@string/reset"
|
||||
android:fontFamily="@font/nunito_regular"
|
||||
android:textColor="@color/black"
|
||||
android:textAllCaps="false"
|
||||
|
||||
app:backgroundTint="@color/white"
|
||||
app:cornerRadius="5dp"
|
||||
|
||||
/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/update_btn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
||||
android:layout_marginStart="15dp"
|
||||
|
||||
android:text="@string/update"
|
||||
android:fontFamily="@font/nunito_regular"
|
||||
android:textColor="@color/white"
|
||||
android:textAllCaps="false"
|
||||
|
||||
app:backgroundTint="@color/color_primary"
|
||||
app:cornerRadius="5dp"
|
||||
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -38,6 +38,20 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="@dimen/_100sdp"
|
||||
android:layout_height="@dimen/_100sdp"
|
||||
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
|
||||
app:civ_circle_background_color="@color/white"
|
||||
|
||||
android:src="@drawable/ic_add_image"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -265,7 +279,7 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/home_address"
|
||||
android:text="@string/patients_home_address"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:textColor="@color/black"
|
||||
@@ -298,6 +312,7 @@
|
||||
|
||||
<com.skydoves.powerspinner.PowerSpinnerView
|
||||
android:id="@+id/country_spinner"
|
||||
android:enabled="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -363,6 +378,7 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/town"
|
||||
android:enabled="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/edit_text_bg_2"
|
||||
@@ -409,6 +425,7 @@
|
||||
|
||||
<com.skydoves.powerspinner.PowerSpinnerView
|
||||
android:id="@+id/state_spinner"
|
||||
android:enabled="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -449,6 +466,7 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/zip_code"
|
||||
android:enabled="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/edit_text_bg_2"
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
/>
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/cg_image"
|
||||
android:layout_width="@dimen/_40sdp"
|
||||
android:layout_height="@dimen/_40sdp"
|
||||
|
||||
android:src="@drawable/static_3"
|
||||
app:civ_circle_background_color="@color/white"
|
||||
|
||||
android:layout_marginHorizontal="15dp"
|
||||
|
||||
@@ -68,7 +70,7 @@
|
||||
tools:text="@string/aditya_gaikwad"
|
||||
android:fontFamily="@font/nunito_medium"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_18ssp"
|
||||
android:textSize="@dimen/_16ssp"
|
||||
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
android:contentDescription="@string/patient_profile"
|
||||
|
||||
android:elevation="15dp"
|
||||
app:civ_circle_background_color="@color/white"
|
||||
|
||||
android:src="@drawable/static_3" />
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<item name="android:textCursorDrawable">@drawable/primary_cursor_drawable</item>
|
||||
<item name="android:windowBackground">@drawable/splash_screen</item>
|
||||
|
||||
<!-- <item name="android:datePickerStyle">@style/myDatePickerStyle</item>-->
|
||||
<!-- <item name="android:datePickerStyle">@style/myDatePickerStyle</item>-->
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
@@ -388,5 +388,8 @@
|
||||
<string name="default_notification_channel_id">ForegroundServiceChannel</string>
|
||||
<string name="all_apps">All apps</string>
|
||||
<string name="select_default_contact">(Select default contact)</string>
|
||||
<string name="reset">Reset</string>
|
||||
<string name="update">Update</string>
|
||||
<string name="patients_home_address">Patients Home Address</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user