Files
SimpliTend/app/src/main/java/com/ssb/simplitend/patientprofile/ProfileProgressFragment.java

141 lines
5.2 KiB
Java
Raw Normal View History

2023-07-20 22:02:26 +05:30
package com.ssb.simplitend.patientprofile;
2023-06-29 17:54:41 +05:30
2023-07-25 16:55:09 +05:30
import android.app.ProgressDialog;
2023-06-29 17:54:41 +05:30
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2023-07-25 16:55:09 +05:30
import android.widget.Toast;
2023-06-29 17:54:41 +05:30
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
2023-07-07 21:07:04 +05:30
import androidx.navigation.Navigation;
2023-06-29 17:54:41 +05:30
2023-07-07 21:07:04 +05:30
import com.ssb.simplitend.R;
2023-07-25 16:55:09 +05:30
import com.ssb.simplitend.apputils.AppUtil;
import com.ssb.simplitend.apputils.RetrofitHelper;
2023-06-29 17:54:41 +05:30
import com.ssb.simplitend.databinding.ProfileProgressFragmentBinding;
2023-08-01 21:20:23 +05:30
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
2023-06-29 17:54:41 +05:30
2023-07-25 16:55:09 +05:30
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class ProfileProgressFragment extends Fragment implements ProfileContracts.ProfileProgressCallback {
2023-06-29 17:54:41 +05:30
// view binding
protected ProfileProgressFragmentBinding binding;
2023-07-25 16:55:09 +05:30
private ProgressDialog progressDialog;
public ProfileProgressFragment() {
2023-06-29 17:54:41 +05:30
// required empty const.
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = ProfileProgressFragmentBinding.inflate(inflater, container, false);
2023-07-07 21:07:04 +05:30
initProgress();
clickEvents();
2023-06-29 17:54:41 +05:30
return binding.getRoot();
}
2023-07-07 21:07:04 +05:30
private void initProgress() {
2023-07-25 16:55:09 +05:30
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.");
}
});
2023-07-07 21:07:04 +05:30
}
private void clickEvents() {
2023-07-25 16:55:09 +05:30
binding.addContact.setOnClickListener(v ->
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_addContactFragment)
);
2023-07-07 21:07:04 +05:30
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)
);
2023-07-11 19:01:00 +05:30
binding.setUpRoutine.setOnClickListener(v ->
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_routineFragment)
);
2023-07-31 20:36:26 +05:30
binding.proceed.setOnClickListener(v -> {
Navigation.findNavController(v).navigate(R.id.action_profileProgressFragment_to_registerCompleteFragment);
2023-07-11 19:01:00 +05:30
});
2023-07-07 21:07:04 +05:30
}
2023-07-25 16:55:09 +05:30
@Override
public void onProfileProgressFetched(@NonNull PatientData patientData) {
if (patientData.isCareGiverLink == 1) {
// TODO: 25-07-2023 look into this
}
if (patientData.isPatientReminderData == 1) {
binding.medReminderImg.setImageResource(0);
binding.medReminderImg.setBackgroundResource(R.drawable.ic_done);
2023-07-29 14:09:21 +05:30
binding.medReminderImg.setPaddingRelative(15, 15, 15, 15);
2023-07-25 16:55:09 +05:30
}
if (patientData.isPatientMedicalData == 1) {
binding.medInfoImg.setImageResource(0);
binding.medInfoImg.setBackgroundResource(R.drawable.ic_done);
2023-07-29 14:09:21 +05:30
binding.medInfoImg.setPadding(15, 15, 15, 15);
2023-07-25 16:55:09 +05:30
}
if (patientData.isPatientRoutineData == 1) {
binding.setupRoutineImg.setImageResource(0);
binding.setupRoutineImg.setBackgroundResource(R.drawable.ic_done);
2023-07-29 14:09:21 +05:30
binding.setupRoutineImg.setPadding(15, 15, 15, 15);
2023-07-25 16:55:09 +05:30
}
progressDialog.dismiss();
}
@Override
public void onProfileProgressFetchFailed(Throwable t, String message) {
progressDialog.dismiss();
Toast.makeText(requireContext(), "Couldn't load profile progress.", Toast.LENGTH_SHORT).show();
}
2023-06-29 17:54:41 +05:30
}