.
This commit is contained in:
@@ -1,23 +1,48 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.deactivateacc.AccountPresenter;
|
||||
import com.ssb.simplitend.databinding.ActivityContactAdminBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactData;
|
||||
|
||||
public class ContactAdminActivity extends AppCompatActivity {
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class ContactAdminActivity extends AppCompatActivity implements AccountPresenter.ContactAdminCallback {
|
||||
|
||||
private ActivityContactAdminBinding binding;
|
||||
|
||||
private AccountPresenter presenter;
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
private CareGiverData careGiverData;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityContactAdminBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, careGiverData -> {
|
||||
this.careGiverData = careGiverData;
|
||||
}, true);
|
||||
|
||||
presenter = AccountPresenter.getAccountPresenter();
|
||||
progressDialog = new ProgressDialog(this);
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
@@ -49,5 +74,76 @@ public class ContactAdminActivity extends AppCompatActivity {
|
||||
|
||||
private void clickEvents() {
|
||||
binding.backBtn.setOnClickListener(v -> onBackPressed());
|
||||
|
||||
binding.submit.setOnClickListener(v -> {
|
||||
if (careGiverData == null){
|
||||
Toast.makeText(this, "Could not connect.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (allOkay()){
|
||||
submitResponse();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void submitResponse() {
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we submit your query");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
Map<String, RequestBody> body = new HashMap<>();
|
||||
|
||||
RequestBody topic_body = RequestBody.create(binding.topic.getText().toString(), MediaType.parse("text/plain"));
|
||||
body.put("title", topic_body);
|
||||
|
||||
RequestBody description_body = RequestBody.create(binding.description.getText().toString(), MediaType.parse("text/plain"));
|
||||
body.put("description", description_body);
|
||||
|
||||
RequestBody query_body = RequestBody.create("None", MediaType.parse("text/plain"));
|
||||
body.put("query", query_body);
|
||||
|
||||
RequestBody patient_xid_body = RequestBody.create(careGiverData.patientId + "", MediaType.parse("text/plain"));
|
||||
body.put("patient_xid", patient_xid_body);
|
||||
|
||||
RequestBody caregiver_xid_body = RequestBody.create(careGiverData.caregiver_xid + "", MediaType.parse("text/plain"));
|
||||
body.put("caregiver_xid", caregiver_xid_body);
|
||||
|
||||
presenter.contactAdmin(body,
|
||||
"Bearer " + AppUtil.getCgToken(this),
|
||||
this);
|
||||
|
||||
}
|
||||
|
||||
private boolean allOkay() {
|
||||
boolean allOkay = true;
|
||||
|
||||
if (binding.topic.getText().toString().trim().isEmpty()){
|
||||
binding.topic.setError("Required");
|
||||
allOkay = false;
|
||||
}
|
||||
|
||||
if (binding.description.getText().toString().trim().isEmpty()){
|
||||
binding.description.setError("Required");
|
||||
allOkay = false;
|
||||
}
|
||||
|
||||
return allOkay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
progressDialog.dismiss();
|
||||
|
||||
Toast.makeText(this, "Query sent successfully.", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(String message) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
Toast.makeText(this, message + "", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.activities.deactivateacc;
|
||||
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PartMap;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface AccountApiService {
|
||||
|
||||
@POST("api/deactivate-reactivate-account/{id}")
|
||||
Call<CallResponse<Object>> de_re_ActivateAccount(@Body Map<String, Integer> body,
|
||||
@Path("id") int caregiver_xid,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@Multipart
|
||||
@POST("api/caregiver-contact-admin")
|
||||
Call<CallResponse<Object>> contactAdmin(@PartMap Map<String, RequestBody> body,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.activities.deactivateacc;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.ssb.simplitend.apputils.RetrofitHelper;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class AccountPresenter {
|
||||
|
||||
public static final int ACC_ACTIVE = 1;
|
||||
public static final String ACC_ACTIVE_STR = "1";
|
||||
public static final int ACC_DEACTIVATE_BY_USER = 2;
|
||||
public static final int ACC_DEACTIVATE_BY_ADMIN = 3;
|
||||
|
||||
private static AccountPresenter accountPresenter;
|
||||
|
||||
private AccountApiService apiService;
|
||||
|
||||
private AccountPresenter(){
|
||||
apiService = RetrofitHelper.getRetrofit().create(AccountApiService.class);
|
||||
}
|
||||
|
||||
public synchronized static AccountPresenter getAccountPresenter(){
|
||||
if (accountPresenter == null){
|
||||
accountPresenter = new AccountPresenter();
|
||||
}
|
||||
|
||||
return accountPresenter;
|
||||
}
|
||||
|
||||
public void accountReDeActivate(int active_status,
|
||||
int caregiver_xid,
|
||||
@NonNull String token,
|
||||
@NonNull AccountReDeActivateCallback callback){
|
||||
|
||||
Map<String, Integer> body = new HashMap<>();
|
||||
|
||||
body.put("status", active_status);
|
||||
|
||||
apiService.de_re_ActivateAccount(body, caregiver_xid, token)
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {
|
||||
if (response.body() != null){
|
||||
if (response.body().status != 200 || response.body().error_code != 0){
|
||||
callback.onAccountDeReActivateFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
callback.onAccountDeReActivate();
|
||||
}else{
|
||||
callback.onAccountDeReActivateFailed(new Exception(), "Couldn't complete that action.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<Object>> call, Throwable t) {
|
||||
callback.onAccountDeReActivateFailed(new Exception(), "Couldn't complete that action.");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void contactAdmin(Map<String, RequestBody> body,
|
||||
@NonNull String token, @NonNull ContactAdminCallback contactAdminCallback){
|
||||
|
||||
apiService.contactAdmin(body, token)
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {
|
||||
if (response.body() != null){
|
||||
if (response.body().status != 200 || response.body().error_code != 0){
|
||||
contactAdminCallback.onFailed(response.body().message);
|
||||
return;
|
||||
}
|
||||
|
||||
contactAdminCallback.onSuccess();
|
||||
}else{
|
||||
contactAdminCallback.onFailed("Couldn't connect. Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<Object>> call, Throwable t) {
|
||||
contactAdminCallback.onFailed("Couldn't connect. Please try again later.");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public interface AccountReDeActivateCallback{
|
||||
void onAccountDeReActivate();
|
||||
|
||||
void onAccountDeReActivateFailed(Throwable throwable, String message);
|
||||
}
|
||||
|
||||
public interface ContactAdminCallback{
|
||||
void onSuccess();
|
||||
|
||||
void onFailed(String message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -3,22 +3,41 @@ package com.ssb.simplitend.caregiverdashboard.activities.deactivateacc;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.databinding.ActivityDeactivateAccBinding;
|
||||
import com.ssb.simplitend.welcome.activities.WelcomeActivity;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
|
||||
public class DeActivateAccountActivity extends AppCompatActivity {
|
||||
public class DeActivateAccountActivity extends AppCompatActivity implements AccountPresenter.AccountReDeActivateCallback {
|
||||
|
||||
protected ActivityDeactivateAccBinding binding;
|
||||
|
||||
private AccountPresenter accountPresenter;
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
private CareGiverData careGiverData;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityDeactivateAccBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> {
|
||||
this.careGiverData = careGiverData1;
|
||||
}), true);
|
||||
|
||||
accountPresenter = AccountPresenter.getAccountPresenter();
|
||||
progressDialog = new ProgressDialog(this);
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
@@ -42,6 +61,24 @@ public class DeActivateAccountActivity extends AppCompatActivity {
|
||||
binding.firstView.setVisibility(View.GONE);
|
||||
binding.secondView.setVisibility(View.VISIBLE);
|
||||
});
|
||||
|
||||
binding.confirmDeactivate.setOnClickListener(v -> {
|
||||
if (careGiverData == null){
|
||||
Toast.makeText(this, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
progressDialog.setTitle("Please wait....");
|
||||
progressDialog.setMessage("while we de-activate your account");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
accountPresenter.accountReDeActivate(AccountPresenter.ACC_DEACTIVATE_BY_USER,
|
||||
careGiverData.caregiver_xid,
|
||||
"Bearer " + AppUtil.getCgToken(this),
|
||||
this);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@@ -60,4 +97,24 @@ public class DeActivateAccountActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountDeReActivate() {
|
||||
Toast.makeText(this, "Account Deactivated", Toast.LENGTH_SHORT).show();
|
||||
progressDialog.dismiss();
|
||||
|
||||
AppUtil.cgSignOut(this);
|
||||
|
||||
Intent intent = new Intent(this, WelcomeActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountDeReActivateFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.ssb.simplitend.welcome.welcomecg.fragments;
|
||||
|
||||
import static com.ssb.simplitend.welcome.welcomecg.fragments.CgConnectFragment.CAREGIVER_EMAIL;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_STATUS_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_XID_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.IS_CAREGIVER_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.TOKEN_KEY;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
@@ -21,6 +25,7 @@ import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.CaregiverDashActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.deactivateacc.AccountPresenter;
|
||||
import com.ssb.simplitend.databinding.CgSignInFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.welcomecg.WelcomeContracts;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
@@ -147,15 +152,39 @@ public class CgSignInFragment extends Fragment implements WelcomeContracts.CgLog
|
||||
.navigate(R.id.action_cgSignInFragment_to_cgConnectFragment, bundle, navOptions);
|
||||
}
|
||||
|
||||
private void gotoReActivateScreen(String cg_status, String token, int cg_xid){
|
||||
NavOptions navOptions = new NavOptions.Builder()
|
||||
.setPopUpTo(R.id.welcomeFragment, true)
|
||||
.build();
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
bundle.putString(CG_STATUS_KEY, cg_status);
|
||||
bundle.putBoolean(IS_CAREGIVER_KEY, true);
|
||||
bundle.putInt(CG_XID_KEY, cg_xid);
|
||||
bundle.putString(TOKEN_KEY, token);
|
||||
|
||||
Navigation.findNavController(binding.getRoot())
|
||||
.navigate(R.id.action_cgSignInFragment_to_reActivateFragment, bundle, navOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginSuccess(CareGiverData careGiverData, String token) {
|
||||
// caching user data
|
||||
CaregiverDataCache.setCareGiverData(careGiverData);
|
||||
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(requireContext(), "Log in success.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
AppUtil.saveCgData(token, careGiverData.patientId, requireContext());
|
||||
progressDialog.dismiss();
|
||||
|
||||
if (!careGiverData.caregiver_status.equals(AccountPresenter.ACC_ACTIVE_STR)){
|
||||
// account is not active
|
||||
|
||||
gotoReActivateScreen(careGiverData.caregiver_status, AppUtil.getCgToken(requireContext()),
|
||||
careGiverData.caregiver_xid);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(requireContext(), "Log in success.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
if (careGiverData.isPatientAndCareGiverConnected == 1){
|
||||
gotoDashboard();
|
||||
|
||||
@@ -39,5 +39,7 @@ public class CareGiverData{
|
||||
public String is_admin;
|
||||
public int patientId;
|
||||
|
||||
public String caregiver_status;
|
||||
|
||||
public PatientData patientDetails;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.ssb.simplitend.welcome.welcomepatient.fragments;
|
||||
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_STATUS_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_XID_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.IS_CAREGIVER_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.TOKEN_KEY;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -21,8 +26,8 @@ import androidx.navigation.Navigation;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.EditTextErrorRemover;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.deactivateacc.AccountPresenter;
|
||||
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
||||
import com.ssb.simplitend.databinding.SignInFragmentBinding;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeContracts;
|
||||
@@ -150,16 +155,40 @@ public class SignInFragment extends Fragment implements WelcomeContracts.Registe
|
||||
return allOkay;
|
||||
}
|
||||
|
||||
private void gotoReActivateScreen(String cg_status, String token, int cg_xid){
|
||||
NavOptions navOptions = new NavOptions.Builder()
|
||||
.setPopUpTo(R.id.welcomeFragment, true)
|
||||
.build();
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
bundle.putString(CG_STATUS_KEY, cg_status);
|
||||
bundle.putBoolean(IS_CAREGIVER_KEY, false);
|
||||
bundle.putInt(CG_XID_KEY, cg_xid);
|
||||
bundle.putString(TOKEN_KEY, token);
|
||||
|
||||
Navigation.findNavController(binding.getRoot())
|
||||
.navigate(R.id.action_signInFragment_to_reActivateFragment, bundle, navOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(PatientData patientResult, String token) {
|
||||
// caching user data
|
||||
PatientDataCache.setPatientData(patientResult);
|
||||
AppUtil.savePatientData(token, patientResult.patientId, requireContext(), true);
|
||||
|
||||
progressDialog.dismiss();
|
||||
|
||||
progressDialog.setMessage("Almost there...");
|
||||
if (!patientResult.caregiver_status.equals(AccountPresenter.ACC_ACTIVE_STR)){
|
||||
// account is not active
|
||||
|
||||
AppUtil.savePatientData(token, patientResult.patientId, requireContext(), true);
|
||||
gotoReActivateScreen(patientResult.caregiver_status,
|
||||
AppUtil.getPatientToken(requireContext()), -1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
progressDialog.setMessage("Almost there...");
|
||||
|
||||
progressDialog.dismiss();
|
||||
|
||||
|
||||
@@ -2,15 +2,12 @@ package com.ssb.simplitend.welcome.welcomepatient.fragments.contacts;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.ssb.simplitend.databinding.ContactViewHolderBinding;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.Contact;
|
||||
|
||||
@@ -39,7 +36,7 @@ public class ContactListAdapter extends ListAdapter<ArrayList<Contact>, ContactL
|
||||
@NonNull
|
||||
@Override
|
||||
public ContactViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ContactViewHolderBinding binding = ContactViewHolderBinding.inflate(LayoutInflater.from(parent.getContext()));
|
||||
ContactViewHolderBinding binding = ContactViewHolderBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||
return new ContactViewHolder(binding);
|
||||
}
|
||||
|
||||
@@ -49,7 +46,7 @@ public class ContactListAdapter extends ListAdapter<ArrayList<Contact>, ContactL
|
||||
|
||||
ArrayList<Contact> contacts = getItem(position);
|
||||
|
||||
holder.binding.name.setOnClickListener(v -> {
|
||||
holder.binding.card.setOnClickListener(v -> {
|
||||
if (contactClickListener != null && contacts != null){
|
||||
Contact contact = new Contact(contacts);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Contact implements Serializable {
|
||||
|
||||
@@ -70,4 +71,17 @@ public class Contact implements Serializable {
|
||||
", email_address='" + email_address + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Contact contact = (Contact) o;
|
||||
return phone_number.equals(contact.phone_number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(phone_number);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
@@ -59,15 +60,15 @@ public class ContactViewModel extends AndroidViewModel {
|
||||
public ArrayList<ArrayList<Contact>> getContactList(Context context) {
|
||||
ArrayList<ArrayList<Contact>> contactLIst = new ArrayList<>();
|
||||
|
||||
HashMap<String, ArrayList<Contact>> contactMap = this.contactRepository.getContactList(context);
|
||||
HashMap<String, Set<Contact>> contactMap = this.contactRepository.getContactList(context);
|
||||
|
||||
for (ArrayList<Contact> contacts: contactMap.values()){
|
||||
for (Set<Contact> contacts: contactMap.values()){
|
||||
if (contacts != null && contacts.size() > 0){
|
||||
contactLIst.add(contacts);
|
||||
contactLIst.add(new ArrayList<>(contacts));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(contactLIst, (contacts, t1) -> contacts.get(0).first_name.compareTo(t1.get(0).first_name));
|
||||
Collections.sort(contactLIst, (contacts, t1) -> contacts.get(0).first_name.toLowerCase().compareTo(t1.get(0).first_name.toLowerCase()));
|
||||
|
||||
return contactLIst;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import com.ssb.simplitend.apputils.RetrofitHelper;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactListResponse;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.WelcomeApiService;
|
||||
@@ -17,8 +19,10 @@ import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
@@ -160,13 +164,13 @@ public class UserContactRepository {
|
||||
});
|
||||
}
|
||||
|
||||
public HashMap<String, ArrayList<Contact>> getContactList(Context context) {
|
||||
public HashMap<String, Set<Contact>> getContactList(Context context) {
|
||||
|
||||
/*
|
||||
key -> name
|
||||
values -> different contacts with same name
|
||||
*/
|
||||
HashMap<String, ArrayList<Contact>> contactMap = new HashMap<>();
|
||||
HashMap<String, Set<Contact>> contactMap = new HashMap<>();
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
|
||||
@@ -190,25 +194,35 @@ public class UserContactRepository {
|
||||
|
||||
if (number == null) continue;
|
||||
if (name == null || name.isEmpty()) name = "No name";
|
||||
|
||||
|
||||
try {
|
||||
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
|
||||
Phonenumber.PhoneNumber formatted_number = phoneNumberUtil.parse(number, "US");
|
||||
number = "+" + formatted_number.getCountryCode() + formatted_number.getNationalNumber();
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
Contact contact = new Contact(name, number);
|
||||
|
||||
if (name.equals("DONNA Saatchi")){
|
||||
Log.d(TAG, "getContactList: ");
|
||||
}
|
||||
|
||||
ArrayList<Contact> contactList;
|
||||
Set<Contact> contactList;
|
||||
|
||||
if (contactMap.containsKey(c_id)) {
|
||||
// there is already number associate with this name
|
||||
// thus, adding to the existing contact list against the name
|
||||
contactList = contactMap.get(c_id);
|
||||
} else {
|
||||
contactList = new ArrayList<>();
|
||||
contactList = new HashSet<>();
|
||||
}
|
||||
|
||||
if (contactList == null) contactList = new ArrayList<>();
|
||||
if (contactList == null) contactList = new HashSet<>();
|
||||
|
||||
if (contactList.contains(contact)){
|
||||
// duplicate number for same contact
|
||||
// this, duplication is due to different accounts on device like Google, Whatsapp, etc
|
||||
continue;
|
||||
}
|
||||
|
||||
contactList.add(contact);
|
||||
contactMap.put(c_id, contactList);
|
||||
}
|
||||
@@ -224,7 +238,7 @@ public class UserContactRepository {
|
||||
return contactMap;
|
||||
}
|
||||
|
||||
private void getEmailForContact(Context context, HashMap<String, ArrayList<Contact>> contactMap) {
|
||||
private void getEmailForContact(Context context, HashMap<String, Set<Contact>> contactMap) {
|
||||
Uri emailUri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
|
||||
String[] emailProjection = {
|
||||
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
||||
@@ -244,7 +258,7 @@ public class UserContactRepository {
|
||||
String c_id = emailCursor.getString(c_id_index);
|
||||
|
||||
if (contactMap.containsKey(c_id)){
|
||||
ArrayList<Contact> contacts = contactMap.get(c_id);
|
||||
Set<Contact> contacts = contactMap.get(c_id);
|
||||
if (contacts != null){
|
||||
for (Contact contact: contacts){
|
||||
if (contact != null){
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.ssb.simplitend.welcome.welcomepatient.fragments.register;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
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.NavOptions;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
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.activities.deactivateacc.AccountPresenter;
|
||||
import com.ssb.simplitend.databinding.FragmentAccReActivBinding;
|
||||
import com.ssb.simplitend.databinding.SplashFragmentBinding;
|
||||
|
||||
public class ReActivateFragment extends Fragment implements AccountPresenter.AccountReDeActivateCallback {
|
||||
|
||||
// view binding
|
||||
protected FragmentAccReActivBinding binding;
|
||||
|
||||
public static final String CG_STATUS_KEY = "cg_status_key";
|
||||
public static final String IS_CAREGIVER_KEY = "is_caregiver_key";
|
||||
public static final String TOKEN_KEY = "token_key";
|
||||
public static final String CG_XID_KEY = "cg_xid_key";
|
||||
public static final String CG_TOKEN_KEY = "cg_xid_key";
|
||||
|
||||
private int caregiver_status;
|
||||
private boolean is_caregiver;
|
||||
private int caregiver_xid;
|
||||
private String token;
|
||||
|
||||
private AccountPresenter accountPresenter;
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentAccReActivBinding.inflate(inflater, container, false);
|
||||
|
||||
accountPresenter = AccountPresenter.getAccountPresenter();
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
|
||||
Bundle bundle = getArguments();
|
||||
if (bundle != null){
|
||||
try {
|
||||
caregiver_status = Integer.parseInt(bundle.getString(CG_STATUS_KEY, "3"));
|
||||
}catch (Exception e){
|
||||
caregiver_status = 3; // default
|
||||
}
|
||||
is_caregiver = bundle.getBoolean(IS_CAREGIVER_KEY, false);
|
||||
caregiver_xid = bundle.getInt(CG_XID_KEY, -1);
|
||||
token = bundle.getString(TOKEN_KEY, null);
|
||||
}
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
||||
// setting message
|
||||
String message;
|
||||
if (AccountPresenter.ACC_DEACTIVATE_BY_USER == caregiver_status){
|
||||
// deactivated by cg
|
||||
if (is_caregiver){
|
||||
message = getString(R.string.re_activate_msg_cg_by_cg);
|
||||
|
||||
binding.reActivateBtn.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
message = getString(R.string.re_activate_msg_patient_by_cg);
|
||||
|
||||
binding.reActivateBtn.setVisibility(View.GONE);
|
||||
}
|
||||
}else{
|
||||
binding.reActivateBtn.setVisibility(View.GONE);
|
||||
|
||||
// deactivated by admin
|
||||
if (is_caregiver){
|
||||
message = getString(R.string.re_activate_msg_cg_by_admin);
|
||||
}else {
|
||||
message = getString(R.string.re_activate_msg_patient_by_admin);
|
||||
}
|
||||
}
|
||||
|
||||
binding.message.setText(message);
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
binding.call.setOnClickListener(v -> {
|
||||
callNumber(getString(R.string.support_contact));
|
||||
});
|
||||
|
||||
binding.email.setOnClickListener(v -> {
|
||||
contactMail();
|
||||
});
|
||||
|
||||
binding.logInAnotherAcc.setOnClickListener(v -> {
|
||||
AppUtil.cgSignOut(requireContext());
|
||||
AppUtil.patientSignOut(requireContext());
|
||||
CaregiverDataCache.setCareGiverData(null);
|
||||
PatientDataCache.setPatientData(null);
|
||||
|
||||
Navigation.findNavController(v).navigate(R.id.action_reActivateFragment_to_splashFragment);
|
||||
});
|
||||
|
||||
binding.reActivateBtn.setOnClickListener(v -> {
|
||||
if (caregiver_xid == -1 || token == null){
|
||||
Toast.makeText(requireContext(), "Cannot re-activate your account", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
progressDialog.setTitle("Please wait....");
|
||||
progressDialog.setMessage("while we gather you information and re-activate your account.");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
accountPresenter.accountReDeActivate(AccountPresenter.ACC_ACTIVE,
|
||||
caregiver_xid, "Bearer " + token, this);
|
||||
});
|
||||
}
|
||||
|
||||
private void callNumber(String phone_number){
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel",
|
||||
phone_number,
|
||||
null));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void messageNumber(String phone_number){
|
||||
Uri uri = Uri.parse("smsto:" + phone_number);
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
|
||||
// intent.putExtra("sms_body", "The SMS text");
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void contactMail() {
|
||||
String contact_email = getString(R.string.contact_email);
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
||||
intent.setData(Uri.fromParts("mailto", contact_email, null));
|
||||
|
||||
if (intent.resolveActivity(requireActivity().getPackageManager()) != null) {
|
||||
startActivity(intent);
|
||||
}else{
|
||||
Toast.makeText(requireContext(), "No email app found.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountDeReActivate() {
|
||||
progressDialog.dismiss();
|
||||
|
||||
Toast.makeText(requireContext(), "Account re-activated.", Toast.LENGTH_SHORT).show();
|
||||
NavOptions navOptions = new NavOptions.Builder()
|
||||
.setPopUpTo(R.id.splashFragment, true)
|
||||
.build();
|
||||
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_reActivateFragment_to_splashFragment, null, navOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountDeReActivateFailed(Throwable throwable, String message) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
Toast.makeText(requireContext(), "Couldn't re-activate your account.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.ssb.simplitend.welcome.welcomepatient.fragments.register;
|
||||
|
||||
import static com.ssb.simplitend.welcome.welcomecg.fragments.CgConnectFragment.CAREGIVER_EMAIL;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_STATUS_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_XID_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.IS_CAREGIVER_KEY;
|
||||
import static com.ssb.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.TOKEN_KEY;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
@@ -24,6 +28,7 @@ import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.apputils.RetrofitHelper;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.CaregiverDashActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.deactivateacc.AccountPresenter;
|
||||
import com.ssb.simplitend.databinding.SplashFragmentBinding;
|
||||
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
||||
import com.ssb.simplitend.patientprofile.PatientProfileAPIService;
|
||||
@@ -149,6 +154,22 @@ public class SplashFragment extends Fragment
|
||||
.show();
|
||||
}
|
||||
|
||||
private void gotoReActivateScreen(String cg_status, String token, int cg_xid, boolean is_caregiver){
|
||||
NavOptions navOptions = new NavOptions.Builder()
|
||||
.setPopUpTo(R.id.splashFragment, true)
|
||||
.build();
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
bundle.putString(CG_STATUS_KEY, cg_status);
|
||||
bundle.putBoolean(IS_CAREGIVER_KEY, is_caregiver);
|
||||
bundle.putInt(CG_XID_KEY, cg_xid);
|
||||
bundle.putString(TOKEN_KEY, token);
|
||||
|
||||
Navigation.findNavController(binding.getRoot())
|
||||
.navigate(R.id.action_splashFragment_to_reActivateFragment, bundle, navOptions);
|
||||
}
|
||||
|
||||
private void gotoPatientProfileProgress(){
|
||||
NavOptions navOptions = new NavOptions.Builder()
|
||||
.setPopUpTo(R.id.splashFragment, true)
|
||||
@@ -194,6 +215,15 @@ public class SplashFragment extends Fragment
|
||||
// caching data
|
||||
CaregiverDataCache.setCareGiverData(careGiverData);
|
||||
|
||||
if (!careGiverData.caregiver_status.equals(AccountPresenter.ACC_ACTIVE_STR)){
|
||||
// account is not active
|
||||
|
||||
gotoReActivateScreen(careGiverData.caregiver_status, AppUtil.getCgToken(requireContext()),
|
||||
careGiverData.caregiver_xid, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
binding.retry.setVisibility(View.GONE);
|
||||
binding.loadAnim.setVisibility(View.GONE);
|
||||
|
||||
@@ -239,6 +269,15 @@ public class SplashFragment extends Fragment
|
||||
// caching data
|
||||
PatientDataCache.setPatientData(patientData);
|
||||
|
||||
if (!patientData.caregiver_status.equals(AccountPresenter.ACC_ACTIVE_STR)){
|
||||
// account is not active
|
||||
|
||||
gotoReActivateScreen(patientData.caregiver_status,
|
||||
AppUtil.getPatientToken(requireContext()),
|
||||
-1, false);
|
||||
return;
|
||||
}
|
||||
|
||||
binding.retry.setVisibility(View.GONE);
|
||||
binding.loadAnim.setVisibility(View.GONE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user