2023-07-31 20:36:26 +05:30
|
|
|
package com.ssb.simplitend.patientprofile;
|
|
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
2023-08-31 21:00:09 +05:30
|
|
|
import android.app.ProgressDialog;
|
2023-08-10 21:00:59 +05:30
|
|
|
import android.content.Intent;
|
2023-08-16 21:05:21 +05:30
|
|
|
import android.graphics.drawable.Drawable;
|
2023-07-31 20:36:26 +05:30
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
2023-08-16 21:05:21 +05:30
|
|
|
import android.widget.Toast;
|
2023-07-31 20:36:26 +05:30
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
2023-08-16 21:05:21 +05:30
|
|
|
import androidx.vectordrawable.graphics.drawable.Animatable2Compat;
|
2023-07-31 20:36:26 +05:30
|
|
|
|
2023-08-11 21:14:23 +05:30
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
import com.bumptech.glide.load.DataSource;
|
|
|
|
|
import com.bumptech.glide.load.engine.GlideException;
|
|
|
|
|
import com.bumptech.glide.load.resource.gif.GifDrawable;
|
|
|
|
|
import com.bumptech.glide.request.RequestListener;
|
|
|
|
|
import com.bumptech.glide.request.target.Target;
|
2023-07-31 20:36:26 +05:30
|
|
|
import com.daimajia.androidanimations.library.Techniques;
|
|
|
|
|
import com.daimajia.androidanimations.library.YoYo;
|
|
|
|
|
import com.ssb.simplitend.R;
|
|
|
|
|
import com.ssb.simplitend.apputils.AppUtil;
|
2023-08-31 21:00:09 +05:30
|
|
|
import com.ssb.simplitend.apputils.RetrofitHelper;
|
2023-07-31 20:36:26 +05:30
|
|
|
import com.ssb.simplitend.databinding.RegisterationDoneFragmentBinding;
|
2023-08-10 21:00:59 +05:30
|
|
|
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
2023-08-31 21:00:09 +05:30
|
|
|
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
|
|
|
|
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
2023-07-31 20:36:26 +05:30
|
|
|
|
2023-08-31 21:00:09 +05:30
|
|
|
import retrofit2.Call;
|
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
|
|
|
|
|
public class RegisterCompleteFragment extends Fragment implements ProfileContracts.ProfileProgressCallback{
|
2023-07-31 20:36:26 +05:30
|
|
|
|
|
|
|
|
public RegisterationDoneFragmentBinding binding;
|
|
|
|
|
|
2023-08-03 21:23:47 +05:30
|
|
|
public static final String PROFILE_PROGRESS = "profile_progress";
|
2023-08-10 21:00:59 +05:30
|
|
|
public static final String IS_CONNECTED_TO_CG = "is_connect_to_cg";
|
2023-08-03 21:23:47 +05:30
|
|
|
|
2023-08-10 21:00:59 +05:30
|
|
|
int profile_progress, is_connect_to_caregiver;
|
2023-08-03 21:23:47 +05:30
|
|
|
|
2023-08-31 21:00:09 +05:30
|
|
|
private ProgressDialog progressDialog;
|
|
|
|
|
|
2023-08-11 21:14:23 +05:30
|
|
|
public RegisterCompleteFragment() {
|
2023-07-31 20:36:26 +05:30
|
|
|
// required
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
|
@Override
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
binding = RegisterationDoneFragmentBinding.inflate(inflater, container, false);
|
2023-08-31 21:00:09 +05:30
|
|
|
progressDialog = new ProgressDialog(requireContext());
|
2023-07-31 20:36:26 +05:30
|
|
|
|
2023-08-11 21:14:23 +05:30
|
|
|
if (getArguments() != null) {
|
2023-08-03 21:23:47 +05:30
|
|
|
profile_progress = getArguments().getInt(PROFILE_PROGRESS, 20);
|
2023-08-10 21:00:59 +05:30
|
|
|
is_connect_to_caregiver = getArguments().getInt(IS_CONNECTED_TO_CG, 0);
|
2023-08-03 21:23:47 +05:30
|
|
|
}
|
|
|
|
|
|
2023-08-11 21:14:23 +05:30
|
|
|
Glide.with(requireContext())
|
|
|
|
|
.asGif()
|
|
|
|
|
.load(R.raw.filling_anim)
|
|
|
|
|
.listener(new RequestListener<GifDrawable>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
|
2023-08-16 21:05:21 +05:30
|
|
|
if (resource == null) return false;
|
|
|
|
|
|
2023-08-11 21:14:23 +05:30
|
|
|
resource.setLoopCount(1);
|
2023-08-16 21:05:21 +05:30
|
|
|
resource.registerAnimationCallback(new Animatable2Compat.AnimationCallback() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Drawable drawable) {
|
|
|
|
|
super.onAnimationEnd(drawable);
|
|
|
|
|
String title = "Your profile is " + (profile_progress * 20) + "% complete!";
|
|
|
|
|
|
|
|
|
|
binding.title.setText(title);
|
|
|
|
|
YoYo.with(Techniques.FadeIn)
|
|
|
|
|
.duration(100)
|
|
|
|
|
.playOn(binding.title);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-08-11 21:14:23 +05:30
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.into(binding.animIv);
|
2023-07-31 20:36:26 +05:30
|
|
|
|
|
|
|
|
binding.proceed.setOnClickListener(v -> {
|
|
|
|
|
|
2023-08-31 21:00:09 +05:30
|
|
|
checkConnectionStatus();
|
2023-07-31 20:36:26 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return binding.getRoot();
|
|
|
|
|
}
|
2023-08-10 21:00:59 +05:30
|
|
|
|
2023-08-31 21:00:09 +05:30
|
|
|
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.");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 21:00:59 +05:30
|
|
|
private void gotoPatientDashBoard() {
|
|
|
|
|
Intent intent = new Intent(requireActivity(), DashBoardActivity.class);
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
requireActivity().finish();
|
|
|
|
|
}
|
2023-08-31 21:00:09 +05:30
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onProfileProgressFetched(PatientData patientData) {
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
|
|
|
|
|
if (patientData.isCareGiverConnectedWithPatient == 1) {
|
2023-09-04 16:13:26 +05:30
|
|
|
if (patientData.isCaregiverTakeSubscription == 1){
|
|
|
|
|
gotoPatientDashBoard();
|
|
|
|
|
}else{
|
|
|
|
|
AppUtil.showAlert(requireContext(),
|
|
|
|
|
"Ask Caregiver to Subscribe",
|
|
|
|
|
"Kindly ask CareGiver to complete SimpliTend subscription.",
|
|
|
|
|
"OK",
|
|
|
|
|
((dialogInterface, i) -> {
|
|
|
|
|
|
|
|
|
|
}), null, null);
|
|
|
|
|
}
|
2023-08-31 21:00:09 +05:30
|
|
|
} else {
|
|
|
|
|
AppUtil.showAlert(requireContext(),
|
|
|
|
|
"Ask Caregiver to register",
|
2023-09-04 16:13:26 +05:30
|
|
|
"Kindly ask CareGiver to complete registration.",
|
2023-08-31 21:00:09 +05:30
|
|
|
"OK",
|
|
|
|
|
((dialogInterface, i) -> {
|
|
|
|
|
|
|
|
|
|
}), null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onProfileProgressFetchFailed(Throwable t, String message) {
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
2023-07-31 20:36:26 +05:30
|
|
|
}
|
2023-08-11 21:14:23 +05:30
|
|
|
|
|
|
|
|
//binding.animIv.setAnimation(R.raw.done_anim_2);
|
|
|
|
|
// binding.animIv.playAnimation();
|
|
|
|
|
//
|
|
|
|
|
// binding.animIv.addAnimatorListener(new Animator.AnimatorListener() {
|
|
|
|
|
//@Override
|
|
|
|
|
//public void onAnimationStart(@NonNull Animator animator) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//@Override
|
|
|
|
|
//public void onAnimationEnd(@NonNull Animator animator) {
|
|
|
|
|
//
|
|
|
|
|
// String title = "Your profile is " + (profile_progress * 20) + "% complete!";
|
|
|
|
|
//
|
|
|
|
|
// binding.title.setText(title);
|
|
|
|
|
// YoYo.with(Techniques.FadeIn)
|
|
|
|
|
// .duration(100)
|
|
|
|
|
// .playOn(binding.title);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//@Override
|
|
|
|
|
//public void onAnimationCancel(@NonNull Animator animator) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//@Override
|
|
|
|
|
//public void onAnimationRepeat(@NonNull Animator animator) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// });
|