.
This commit is contained in:
@@ -28,8 +28,10 @@ public abstract class AppUtil {
|
||||
|
||||
// fields
|
||||
public static final String USER_DETAILS = "user_details";
|
||||
public static final String CAREGIVER_DETAILS = "user_details";
|
||||
|
||||
public static final String USER_TOKEN = "user_token";
|
||||
public static final String CAREGIVER_TOKEN = "user_token";
|
||||
public static final String PATIENT_UID = "patient_uid";
|
||||
|
||||
// util functions
|
||||
@@ -136,9 +138,6 @@ public abstract class AppUtil {
|
||||
|
||||
Log.d(TAG, "saveToken: user token saved successful");
|
||||
|
||||
// TODO: 17-07-2023 remove below line afterwards
|
||||
Log.d(TAG, "saveUserCache: " + token);
|
||||
|
||||
}
|
||||
|
||||
public static String getUserToken(Context context){
|
||||
@@ -151,4 +150,16 @@ public abstract class AppUtil {
|
||||
return sp.getInt(PATIENT_UID, -1);
|
||||
}
|
||||
|
||||
public static void saveCgData(String token, Context context){
|
||||
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
editor.putString(CAREGIVER_TOKEN, token);
|
||||
|
||||
editor.apply();
|
||||
|
||||
Log.d(TAG, "saveToken: caregiver token saved successful");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,4 +50,4 @@ public abstract class RetrofitHelper {
|
||||
return retrofit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ssb.simplitend.patient_dashboard.fragments;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -11,7 +12,10 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.databinding.PatientDashboardFragmentBinding;
|
||||
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
||||
import com.ssb.simplitend.welcome.activities.WelcomeActivity;
|
||||
|
||||
public class PatientDashboardFragment extends Fragment {
|
||||
|
||||
@@ -36,5 +40,17 @@ public class PatientDashboardFragment extends Fragment {
|
||||
binding.chats.setOnClickListener(v ->
|
||||
Navigation.findNavController(v).navigate(R.id.action_CPDashboardFragment_to_chatListFragment)
|
||||
);
|
||||
|
||||
binding.sosBtn.setOnClickListener(v -> {
|
||||
// fake sign out
|
||||
// TODO: 08-08-2023 remove this
|
||||
|
||||
AppUtil.saveUserCache(null, -1, requireContext());
|
||||
|
||||
Intent intent = new Intent(requireActivity(), WelcomeActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(intent);
|
||||
requireActivity().finish();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,15 @@ public class ProfileProgressFragment extends Fragment implements ProfileContract
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.ssb.simplitend.welcome.activities;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.ssb.simplitend.databinding.ActivityWelcomeBinding;
|
||||
|
||||
public class WelcomeActivity extends AppCompatActivity {
|
||||
@@ -11,12 +11,16 @@ public class WelcomeActivity extends AppCompatActivity {
|
||||
// View binding
|
||||
protected ActivityWelcomeBinding binding;
|
||||
|
||||
private static final String TAG = "aditya";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// setting screen layout
|
||||
binding = ActivityWelcomeBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package com.ssb.simplitend.welcome.welcomecg.fragments;
|
||||
|
||||
import static android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_WEAK;
|
||||
import static android.hardware.biometrics.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
||||
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.biometric.BiometricManager;
|
||||
import androidx.biometric.BiometricPrompt;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.daimajia.androidanimations.library.Techniques;
|
||||
import com.daimajia.androidanimations.library.YoYo;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.caregiverdashboard.CaregiverDashActivity;
|
||||
import com.ssb.simplitend.databinding.CgAuthFragmentBinding;
|
||||
|
||||
public class CgAuthActivity extends AppCompatActivity {
|
||||
|
||||
protected CgAuthFragmentBinding binding;
|
||||
|
||||
private BiometricManager biometricManager;
|
||||
private BiometricPrompt biometricPrompt;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = CgAuthFragmentBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
binding.fingerprintView.setOnClickListener(v -> {
|
||||
|
||||
authenticateBiometrics();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
||||
biometricManager = BiometricManager.from(this);
|
||||
|
||||
biometricPrompt = new BiometricPrompt(this, ContextCompat.getMainExecutor(this),
|
||||
new BiometricPrompt.AuthenticationCallback() {
|
||||
@Override
|
||||
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
|
||||
super.onAuthenticationError(errorCode, errString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
||||
super.onAuthenticationSucceeded(result);
|
||||
gotoCgDash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
super.onAuthenticationFailed();
|
||||
}
|
||||
});
|
||||
|
||||
configureBiometrics();
|
||||
|
||||
// four digit pin catch
|
||||
binding.pin.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (editable.length() == 4) {
|
||||
AppUtil.closeKeyboard(CgAuthActivity.this);
|
||||
|
||||
if (editable.toString().equals("0000")) {
|
||||
gotoCgDash();
|
||||
} else {
|
||||
YoYo.with(Techniques.Wobble)
|
||||
.playOn(binding.pin);
|
||||
|
||||
binding.pin.setError("Invalid pin.");
|
||||
binding.pin.setText(null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void authenticateBiometrics() {
|
||||
if (biometricManager == null) return;
|
||||
|
||||
int biometric_status = biometricManager.canAuthenticate(BIOMETRIC_STRONG | BiometricManager.Authenticators.BIOMETRIC_WEAK);
|
||||
|
||||
if (biometric_status == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
// go ahead and do it.
|
||||
biometricPrompt.authenticate(new BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle("Unlock Simplitend")
|
||||
.setConfirmationRequired(false)
|
||||
.setNegativeButtonText("Cancel")
|
||||
.build());
|
||||
} else if (biometric_status == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED){
|
||||
// no fingerprints enrolled
|
||||
|
||||
AppUtil.showAlert(this,
|
||||
"No biometrics added.",
|
||||
"No fingerprints are registered on your device.\nKindly add biometrics to authenticate.",
|
||||
"Go to settings",
|
||||
((dialogInterface, i) -> {
|
||||
|
||||
final Intent enrollIntent;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
||||
enrollIntent = new Intent(Settings.ACTION_BIOMETRIC_ENROLL);
|
||||
enrollIntent.putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, BIOMETRIC_STRONG);
|
||||
}else{
|
||||
enrollIntent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
|
||||
}
|
||||
|
||||
startActivity(enrollIntent);
|
||||
|
||||
}),
|
||||
"No thanks",
|
||||
((dialogInterface, i) -> {
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void configureBiometrics() {
|
||||
|
||||
if (biometricManager == null) return;
|
||||
|
||||
switch (biometricManager.canAuthenticate(BIOMETRIC_STRONG)) {
|
||||
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
|
||||
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
|
||||
binding.fingerprintOr.setVisibility(View.GONE);
|
||||
binding.fingerprintView.setVisibility(View.GONE);
|
||||
break;
|
||||
case BiometricManager.BIOMETRIC_SUCCESS:
|
||||
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
|
||||
binding.fingerprintOr.setVisibility(View.VISIBLE);
|
||||
binding.fingerprintView.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void gotoCgDash() {
|
||||
Intent intent = new Intent(CgAuthActivity.this, CaregiverDashActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
|
||||
startActivity(intent);
|
||||
CgAuthActivity.this.finish();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.ssb.simplitend.welcome.welcomecg.fragments;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -9,21 +12,32 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.databinding.ConnectCaregiverFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.WelcomeContracts;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CgWelcomeViewModel;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.ConnectCgResult;
|
||||
|
||||
public class CgConnectFragment extends Fragment {
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CgConnectFragment extends Fragment implements WelcomeContracts.ConnectCgCallback{
|
||||
|
||||
protected ConnectCaregiverFragmentBinding binding;
|
||||
|
||||
public static final String CAREGIVER_EMAIL = "cg_email";
|
||||
public static final String CAREGIVER_PASSWORD = "caregiver_pwd";
|
||||
|
||||
private String cg_email, cg_password;
|
||||
private String cg_email;
|
||||
|
||||
private CgWelcomeViewModel viewModel;
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
public CgConnectFragment() {
|
||||
// required
|
||||
@@ -34,13 +48,49 @@ public class CgConnectFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = ConnectCaregiverFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(CgWelcomeViewModel.class);
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
binding.connectBtn.setOnClickListener(v -> {
|
||||
if (binding.code.getText().toString().length() != 4){
|
||||
binding.code.setError("Invalid code.");
|
||||
return;
|
||||
}
|
||||
|
||||
connectCG();
|
||||
});
|
||||
}
|
||||
|
||||
private void connectCG() {
|
||||
if (cg_email == null){
|
||||
Toast.makeText(requireContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
};
|
||||
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we verify your code.");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
Map<String, String> body = new HashMap<>();
|
||||
|
||||
body.put("email", cg_email);
|
||||
body.put("code", binding.code.getText().toString());
|
||||
|
||||
viewModel.connectCg(body, this);
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
|
||||
// showing gif
|
||||
Glide.with(binding.image)
|
||||
.asGif()
|
||||
@@ -48,6 +98,25 @@ public class CgConnectFragment extends Fragment {
|
||||
.placeholder(R.drawable.forgot_pin_email_img)
|
||||
.into(binding.image);
|
||||
|
||||
binding.code.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (editable.length() == 4){
|
||||
AppUtil.closeKeyboard(requireActivity());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,20 +126,29 @@ public class CgConnectFragment extends Fragment {
|
||||
Bundle bundle = getArguments();
|
||||
|
||||
if (bundle == null ||
|
||||
bundle.getString(CAREGIVER_EMAIL, null) == null ||
|
||||
bundle.getString(CAREGIVER_PASSWORD, null) == null) {
|
||||
bundle.getString(CAREGIVER_EMAIL, null) == null) {
|
||||
// no data received
|
||||
// Thus, asking cg_user to sign in again
|
||||
Navigation.findNavController(binding.getRoot())
|
||||
.popBackStack(R.id.cgSignInFragment, false);
|
||||
|
||||
return;
|
||||
}else{
|
||||
cg_email = bundle.getString(CAREGIVER_EMAIL);
|
||||
cg_password = bundle.getString(CAREGIVER_PASSWORD);
|
||||
|
||||
binding.emailAddress.setText(cg_email);
|
||||
Toast.makeText(requireContext(), "" + cg_password, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCgConnected(ConnectCgResult result) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
Toast.makeText(requireContext(), "Caregiver connected.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCgConnectFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
Toast.makeText(requireContext(), "" + message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CgHowToSetUpFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = CgHowToSetUpFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
binding.nextBtn.setOnClickListener(v -> Navigation.findNavController(v).navigate(R.id.action_cgHowToSetUpFragment_to_cgSignInFragment));
|
||||
binding.nextBtn.setOnClickListener(v -> Navigation.findNavController(v).navigate(R.id.action_cgHowToSetUpFragment_to_cgRegisterFragment));
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@@ -48,11 +48,11 @@ public class CgOnBoardFragment extends Fragment {
|
||||
});
|
||||
|
||||
binding.getsStarted.setOnClickListener(v -> {
|
||||
Navigation.findNavController(v).navigate(R.id.action_cgOnBoardFragment_to_cgHowToSetUpFragment);
|
||||
Navigation.findNavController(v).navigate(R.id.action_cgOnBoardFragment_to_cgSignInFragment);
|
||||
});
|
||||
|
||||
binding.skip.setOnClickListener(v -> {
|
||||
Navigation.findNavController(v).navigate(R.id.action_cgOnBoardFragment_to_cgHowToSetUpFragment);
|
||||
Navigation.findNavController(v).navigate(R.id.action_cgOnBoardFragment_to_cgSignInFragment);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -427,7 +427,6 @@ public class CgRegisterFragment extends Fragment implements WelcomeContracts.Reg
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(CAREGIVER_EMAIL, careGiverData.email);
|
||||
bundle.putString(CAREGIVER_PASSWORD, mPassword);
|
||||
|
||||
progressDialog.dismiss();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ssb.simplitend.welcome.welcomecg.fragments;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -85,7 +86,7 @@ public class CgSignInFragment extends Fragment implements WelcomeContracts.CgLog
|
||||
});
|
||||
|
||||
binding.registerBtn.setOnClickListener(v -> {
|
||||
Navigation.findNavController(v).navigate(R.id.action_cgSignInFragment_to_cgRegisterFragment);
|
||||
Navigation.findNavController(v).navigate(R.id.action_cgSignInFragment_to_cgHowToSetUpFragment);
|
||||
});
|
||||
|
||||
binding.forgotPassword.setOnClickListener(v -> {
|
||||
@@ -114,6 +115,14 @@ public class CgSignInFragment extends Fragment implements WelcomeContracts.CgLog
|
||||
public void onLoginSuccess(CareGiverData careGiverData, String token) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(requireContext(), "Log in success.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
AppUtil.saveCgData(token, requireContext());
|
||||
|
||||
Intent intent = new Intent(requireActivity(), CgAuthActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
|
||||
requireActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,7 +68,12 @@ public class ContactListFragment extends Fragment {
|
||||
|
||||
private void clickEvents() {
|
||||
|
||||
binding.backBtn.setOnClickListener(v -> Navigation.findNavController(v).popBackStack());
|
||||
binding.backBtn.setOnClickListener(v -> {
|
||||
if (Navigation.findNavController(v).getPreviousBackStackEntry() != null){
|
||||
Navigation.findNavController(v).popBackStack();
|
||||
Toast.makeText(requireContext(), "Back done", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
binding.createContact.setOnClickListener(v ->
|
||||
{
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.ssb.simplitend.welcome.welcomepatient.fragments.register;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -13,9 +15,20 @@ import androidx.navigation.NavOptions;
|
||||
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.SplashFragmentBinding;
|
||||
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
||||
import com.ssb.simplitend.patientprofile.PatientProfileAPIService;
|
||||
import com.ssb.simplitend.patientprofile.ProfileContracts;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
public class SplashFragment extends Fragment {
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SplashFragment extends Fragment implements ProfileContracts.ProfileProgressCallback{
|
||||
|
||||
// view binding
|
||||
protected SplashFragmentBinding binding;
|
||||
@@ -25,6 +38,59 @@ public class SplashFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = SplashFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
checkIfAhyUser();
|
||||
}
|
||||
|
||||
private void checkIfAhyUser() {
|
||||
String token = AppUtil.getUserToken(requireContext());
|
||||
if (token != null && !token.isEmpty()){
|
||||
// user is already logged in as PATIENT
|
||||
// thus, checking if the logged in PATIENT has already added CAREGIVER
|
||||
|
||||
PatientProfileAPIService apiService = RetrofitHelper.getRetrofit().create(PatientProfileAPIService.class);
|
||||
|
||||
apiService.getUsrProfileProgress("Bearer " + 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.");
|
||||
}
|
||||
});
|
||||
|
||||
}else{
|
||||
// no user has logged in
|
||||
gotoWelcomeFragment();
|
||||
}
|
||||
}
|
||||
|
||||
private void gotoDashBoard(){
|
||||
Intent intent = new Intent(requireActivity(), DashBoardActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(intent);
|
||||
requireActivity().finish();
|
||||
}
|
||||
|
||||
public void gotoWelcomeFragment(){
|
||||
new Handler().postDelayed(() -> {
|
||||
|
||||
NavOptions navOptions = new NavOptions.Builder()
|
||||
@@ -35,7 +101,28 @@ public class SplashFragment extends Fragment {
|
||||
.navigate(R.id.action_splashFragment_to_welcomeFragment, null, navOptions);
|
||||
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
return binding.getRoot();
|
||||
@Override
|
||||
public void onProfileProgressFetched(PatientData patientData) {
|
||||
if (patientData.isCareGiverLink == 1){
|
||||
// user has already added caregiver as a contact
|
||||
// thus, sending it to dashboard
|
||||
gotoDashBoard();
|
||||
}else{
|
||||
// user has not added caregiver contact.
|
||||
// thus, sending it to contact list to add caregiver contact.
|
||||
NavOptions navOptions = new NavOptions.Builder()
|
||||
.setPopUpTo(R.id.splashFragment, true)
|
||||
.build();
|
||||
|
||||
Navigation.findNavController(binding.mainIcon)
|
||||
.navigate(R.id.action_splashFragment_to_contactListFragment, null, navOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileProgressFetchFailed(Throwable t, String message) {
|
||||
Toast.makeText(requireContext(), "Couldn't connect.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user