Files
SimpliTend/app/src/main/java/com/ssb/simplitend/patientprofile/ProfileProgressFragment.java
2023-08-08 21:08:29 +05:30

167 lines
5.7 KiB
Java

package com.ssb.simplitend.patientprofile;
import static com.ssb.simplitend.patientprofile.RegisterCompleteFragment.PROFILE_PROGRESS;
import android.app.ProgressDialog;
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 androidx.navigation.Navigation;
import com.ssb.simplitend.R;
import com.ssb.simplitend.apputils.AppUtil;
import com.ssb.simplitend.apputils.RetrofitHelper;
import com.ssb.simplitend.databinding.ProfileProgressFragmentBinding;
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 ProfileProgressFragment extends Fragment implements ProfileContracts.ProfileProgressCallback {
// view binding
protected ProfileProgressFragmentBinding binding;
private ProgressDialog progressDialog;
int profile_progress;
public ProfileProgressFragment() {
// required empty const.
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = ProfileProgressFragmentBinding.inflate(inflater, container, false);
initProgress();
clickEvents();
return binding.getRoot();
}
private void initProgress() {
progressDialog = new ProgressDialog(requireContext());
progressDialog.setTitle("Please wait...");
progressDialog.setMessage("while we load the profile progress.");
progressDialog.setCancelable(false);
progressDialog.show();
PatientProfileAPIService apiService = RetrofitHelper.getRetrofit().create(PatientProfileAPIService.class);
String token = "Bearer " + AppUtil.getUserToken(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 clickEvents() {
binding.addContact.setOnClickListener(v ->
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_addContactFragment)
);
binding.medicReminder.setOnClickListener(v ->
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_reminderFragment)
);
binding.medicInfo.setOnClickListener(v ->
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_medicalInfoFragment)
);
binding.setUpRoutine.setOnClickListener(v ->
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_routineFragment)
);
binding.proceed.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putInt(PROFILE_PROGRESS, profile_progress);
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_registerCompleteFragment, bundle);
});
}
@Override
public void onProfileProgressFetched(@NonNull PatientData patientData) {
profile_progress = 0;
if (patientData.isCareGiverLink == 1) {
// TODO: 25-07-2023 look into this
profile_progress++;
}
if (patientData.isPatientReminderData == 1) {
profile_progress++;
binding.medReminderImg.setImageResource(0);
binding.medReminderImg.setBackgroundResource(R.drawable.ic_done);
binding.medReminderImg.setPaddingRelative(15, 15, 15, 15);
}
if (patientData.isPatientMedicalData == 1) {
profile_progress++;
binding.medInfoImg.setImageResource(0);
binding.medInfoImg.setBackgroundResource(R.drawable.ic_done);
binding.medInfoImg.setPadding(15, 15, 15, 15);
}
if (patientData.isPatientRoutineData == 1) {
profile_progress++;
binding.setupRoutineImg.setImageResource(0);
binding.setupRoutineImg.setBackgroundResource(R.drawable.ic_done);
binding.setupRoutineImg.setPadding(15, 15, 15, 15);
}
String btn_text;
if (profile_progress == 4){
btn_text = "Proceed";
}else{
btn_text = "Skip";
}
binding.proceed.setText(btn_text);
progressDialog.dismiss();
}
@Override
public void onProfileProgressFetchFailed(Throwable t, String message) {
progressDialog.dismiss();
Toast.makeText(requireContext(), "Couldn't load profile progress.", Toast.LENGTH_SHORT).show();
}
}