diff --git a/app/build.gradle b/app/build.gradle index b5682fd9..7b97167c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,8 +35,8 @@ android { } defaultConfig { applicationId = "org.openimis.imispolicies" - minSdkVersion = 21 - targetSdkVersion = 33 + minSdkVersion 21 + targetSdkVersion 33 versionCode = gitVersionCode versionName = gitVersionName testInstrumentationRunner = 'androidx.test.runner.AndroidJUnitRunner' @@ -247,7 +247,7 @@ dependencies { implementation 'com.embarkmobile:zxing-android-minimal:1.2.1@aar' implementation 'androidx.annotation:annotation:1.7.0' implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.10.0' + implementation 'com.google.android.material:material:1.13.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //noinspection GradleDependency implementation 'com.squareup.picasso:picasso:2.8' @@ -256,6 +256,8 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.3.2' implementation 'org.apache.commons:commons-lang3:3.12.0' implementation 'cz.msebera.android:httpclient:4.5.8' + implementation 'androidx.activity:activity:1.8.0' + implementation "androidx.viewpager2:viewpager2:1.0.0" implementation 'androidx.test:core:1.7.0' androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { diff --git a/app/src/localeBepha/res/values/strings.xml b/app/src/localeBepha/res/values/strings.xml index 4ae7a116..f1dbe495 100644 --- a/app/src/localeBepha/res/values/strings.xml +++ b/app/src/localeBepha/res/values/strings.xml @@ -205,10 +205,10 @@ Version Name Release Date - Total Households - Total Adherents - Total Policies - Total Contributions + Total Households: + Total Adherents: + Total Policies: + Total Contributions: Upload Enrolments Create Enrolments XML Upload Renewals @@ -259,9 +259,9 @@ Search Modify household Downloading household - Edited Households - Edited Adherents - Edited Policies + Edited Households: + Edited Adherents: + Edited Policies: Edited Contributions Adherent number not found Adherent number required diff --git a/app/src/localeMv/res/values-fr/strings.xml b/app/src/localeMv/res/values-fr/strings.xml index 7e509662..9506faf6 100644 --- a/app/src/localeMv/res/values-fr/strings.xml +++ b/app/src/localeMv/res/values-fr/strings.xml @@ -90,7 +90,7 @@ Sél. Mois Date d\'adhésion Paquet de bénéfice - Date d\'entrée en vigueur + Date d\'entrée en vigueur: Date de début Date d\'expiration Agent @@ -120,7 +120,7 @@ Suspendu Le numéro de reçu doit être unique. Le contrat a une contribution. Veuillez d\'abord supprimer les contributions - Contrat avec succès + Contrat supprimé avec succès Contribution supprimée avec succès Assuré supprimé avec succès Vous ne pouvez pas supprimer le chef de famille. @@ -482,5 +482,9 @@ Cash Téléphone portable Virement banquaire + Cliquez pour changer la photo + Choisir votre date de naissance + Êtes-vous sûre de vouloir supprimer cet assuré ? + Êtes-vous sûre de vouloir supprimer cette police ? Fermer diff --git a/app/src/localeMv/res/values/strings.xml b/app/src/localeMv/res/values/strings.xml index b7aa11d7..da3384fd 100644 --- a/app/src/localeMv/res/values/strings.xml +++ b/app/src/localeMv/res/values/strings.xml @@ -477,5 +477,7 @@ Current resource language: %1$s Current system language is not supported. The app will use the default language. Supported languages:\n%1$s + Are you sure you want to delete this insuree? + Are you sure you want to delete this policy? Close diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ad266e97..ceb2ecbe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,9 +13,7 @@ - - - + @@ -28,7 +26,8 @@ - + + + + + + + + + + @@ -63,7 +90,9 @@ android:resource="@xml/paths" /> - + + @@ -134,9 +164,7 @@ - - - + - - + \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/AboutActivity.java b/app/src/main/java/org/openimis/imispolicies/AboutActivity.java new file mode 100644 index 00000000..026e63f4 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/AboutActivity.java @@ -0,0 +1,41 @@ +package org.openimis.imispolicies; + +import android.os.Bundle; +import android.view.MenuItem; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class AboutActivity extends AppCompatActivity { + + TextView appVersion, releaseDate; + ClientAndroidInterface ca; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_about); + setTitle(R.string.About); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + ca = new ClientAndroidInterface(this); + appVersion = findViewById(R.id.VersionValue); + releaseDate = findViewById(R.id.ReleaseDateValue); + appVersion.setText(ca.getVersion()); + releaseDate.setText(getResources().getString(R.string.ReleaseDateValue)); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java index b9c35d71..995f9346 100644 --- a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java +++ b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java @@ -680,17 +680,12 @@ public String getHF(int DistrictId, String HFLevel) { protected HashMap jsonToTable(String jsonString) { HashMap data = new HashMap<>(); try { - JSONArray array = new JSONArray(jsonString); - for (int i = 0; i < array.length(); i++) { - JSONObject object = array.getJSONObject(i); - String ControlName = object.getString("id"); - String ControlValue; - if (!"null".equals(object.getString("value"))) { - ControlValue = object.getString("value"); - } else { - ControlValue = null; - } - data.put(ControlName, ControlValue); + JSONObject object = new JSONObject(jsonString); + Iterator keys = object.keys(); + while (keys.hasNext()) { + String key = keys.next(); + String value = object.getString(key); + data.put(key, value); } } catch (JSONException e) { e.printStackTrace(); @@ -941,6 +936,7 @@ public int SaveInsuree(String InsureeData, int FamilyId, int isHead, int ExceedT String PhotoPath = data.get("hfImagePath"); String newPhotoPath = data.get("hfNewPhotoPath"); + Log.d("new photopath", newPhotoPath); if (!"".equals(newPhotoPath)) { PhotoPath = copyImageFromGalleryToApplication(newPhotoPath, data.get("txtInsuranceNumber")); @@ -1078,7 +1074,7 @@ protected String copyImageFromGalleryToApplication(String selectedPath, String I FileOutputStream outputStream = new FileOutputStream(outputFile); Target imageTarget = new OutputStreamImageTarget(outputStream, global.getIntKey("image_jpeg_quality", 40), deleteOldFiles); try { - activity.runOnUiThread(() -> picassoInstance.load(selectedPath) + activity.runOnUiThread(() -> picassoInstance.load(tempPhotoUri) .resize(global.getIntKey("image_width_limit", 400), global.getIntKey("image_height_limit", 400)) .centerInside() @@ -1347,6 +1343,10 @@ else if (dateWithGracePeriod4 != null && (dEnrollDate.compareTo(dateWithGracePer return period.toString(); } + public void setTempPhotoUri(Uri uri){ + tempPhotoUri = uri; + } + @JavascriptInterface @SuppressWarnings("unused") public void selectPicture() { @@ -1693,6 +1693,7 @@ public int SavePolicy(String PolicyData, int FamilyId, int PolicyId) throws Exce if (IsBulkCNUsed()) { sqlHandler.assignCnToPolicy(rtPolicyId, controlNumber); } + Log.e("familyId", String.valueOf(FamilyId)); InsertRecordedPolicies("new", String.valueOf(FamilyId), data.get("ddlProduct"), data.get("hfPolicyValue"), MaxPolicyId); } else { int Online = 2; @@ -4981,7 +4982,7 @@ public int getCountPremiums(String id) { return TotalPremiums; } - @RequiresApi(api = Build.VERSION_CODES.N) + //@RequiresApi(api = Build.VERSION_CODES.N) @JavascriptInterface @SuppressWarnings("unused") public String getSumPremium() { diff --git a/app/src/main/java/org/openimis/imispolicies/Enrolment.java b/app/src/main/java/org/openimis/imispolicies/Enrolment.java new file mode 100644 index 00000000..88b6d1d4 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/Enrolment.java @@ -0,0 +1,75 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import org.json.JSONArray; +import org.json.JSONException; + +public class Enrolment extends AppCompatActivity { + + RecyclerView recyclerView; + FloatingActionButton btnAdd; + ClientAndroidInterface ca; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_enrolment); + setTitle(getApplicationContext().getString(R.string.Families)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + } + ca = new ClientAndroidInterface(this); + + recyclerView = findViewById(R.id.recyclerFamilies); + btnAdd = findViewById(R.id.btnAddNew); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + loadFamilies(); + btnAdd.setOnClickListener(v -> { + + Intent intent = new Intent(this, FamilyActivity.class); + intent.putExtra("familyId",0); + startActivity(intent); + }); + } + + @Override + protected void onResume() { + super.onResume(); + loadFamilies(); + } + + private void loadFamilies() { + String families = ca.getAllFamilies(); + try { + JSONArray familyArray = new JSONArray(families); + FamilyAdapter adapter = new FamilyAdapter(this,familyArray); + recyclerView.setAdapter(adapter); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + // Option 2: Fermer l'activité directement + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java b/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java new file mode 100644 index 00000000..f50a56bd --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java @@ -0,0 +1,350 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import com.google.android.material.textfield.MaterialAutoCompleteTextView; +import com.google.android.material.textfield.TextInputLayout; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.openimis.imispolicies.util.JsonDropdownHelper; + +public class FamilyActivity extends AppCompatActivity { + private static final int REQUEST_CODE_CLOSE = 14; + + private MaterialAutoCompleteTextView spRegion, spDistrict, spWard, spVillage, spPovertyStatus, spFamilyType, + spConfirmationType, spApprovalSMS, spLanguageSMS; + private TextInputLayout layoutRegion, layoutDistrict, layoutWard, layoutVillage; + Button btnNext; + + int familyId = 0; + JSONObject familyObj; + ClientAndroidInterface ca; + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_CODE_CLOSE && resultCode == RESULT_OK) { + finish(); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_family); + setTitle(getApplicationContext().getString(R.string.AddNewFamily)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + } + ca = new ClientAndroidInterface(this); + familyObj = new JSONObject(); + + spRegion = findViewById(R.id.spRegion); + spDistrict = findViewById(R.id.spDistrict); + spWard = findViewById(R.id.spWard); + spVillage = findViewById(R.id.spVillage); + spPovertyStatus = findViewById(R.id.spPovertyStatus); + spFamilyType = findViewById(R.id.spFamilyType); + spConfirmationType = findViewById(R.id.spConfirmationType); + spApprovalSMS = findViewById(R.id.spApprovalSMS); + spLanguageSMS = findViewById(R.id.spLanguageSMS); + btnNext = findViewById(R.id.btnNext); + layoutRegion = findViewById(R.id.layoutRegion); + layoutDistrict = findViewById(R.id.layoutDistrict); + layoutWard = findViewById(R.id.layoutWard); + layoutVillage = findViewById(R.id.layoutVillage); + + Intent intent = getIntent(); + if (intent != null && intent.hasExtra("familyId")){ + familyId = intent.getIntExtra("familyId", 0); + } + + try { + defineRequiredField(); + fillRegions(); + getPovertyStatus(); + getConfirmationTypes(); + getFamilyTypes(); + getApprovalOfSMS(); + getLanguageOfSMS(); + setupListeners(); + } catch (JSONException e) { + throw new RuntimeException(e); + } + canSave(); + } + + private void defineRequiredField(){ + layoutRegion.setError(" "); + layoutDistrict.setError(" "); + layoutWard.setError(" "); + layoutVillage.setError(" "); + } + + private void fillRegions() throws JSONException { + String regions = ca.getRegions(); + JSONArray regionsArray = new JSONArray(regions); + JsonDropdownHelper.bindDropdown( + this, + spRegion, + regionsArray, + "LocationName", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + String regionId = selectedItem.getString("LocationId"); + fillDistricts(regionId); + spDistrict.setText(""); + spWard.setText(""); + spVillage.setText(""); + spWard.setAdapter(null); + spVillage.setAdapter(null); + canSave(); + familyObj.put("ddlRegion", regionId); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + ); + } + + private void fillDistricts(String regionId) throws JSONException { + String districts = ca.getDistricts(Integer.parseInt(regionId)); + JSONArray districtArray = new JSONArray(districts); + JsonDropdownHelper.bindDropdown( + this, + spDistrict, + districtArray, + "LocationName", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + String districtId = selectedItem.getString("LocationId"); + fillWards(Integer.parseInt(districtId)); + spWard.setText(""); + spVillage.setText(""); + spVillage.setAdapter(null); + canSave(); + familyObj.put("ddlDistrict", districtId); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + ); + } + + private void fillWards(int districtId) throws JSONException { + String wards = ca.getWards(districtId); + JSONArray wardsArray = new JSONArray(wards); + JsonDropdownHelper.bindDropdown( + this, + spWard, + wardsArray, + "LocationName", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + String wardId = selectedItem.getString("LocationId"); + spVillage.setText(""); + fillVillages(Integer.parseInt(wardId)); + canSave(); + familyObj.put("ddlWard", wardId); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + ); + } + + private void fillVillages(int wardId) throws JSONException { + String villages = ca.getVillages(wardId); + JSONArray villagesArray = new JSONArray(villages); + JsonDropdownHelper.bindDropdown( + this, + spVillage, + villagesArray, + "LocationName", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + familyObj.put("ddlVillage", selectedItem.getString("LocationId")); + canSave(); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + ); + } + + private void saveFamily() { + try { + familyObj.put("hfFamilyId", String.valueOf(familyId)); + Intent intent = new Intent(this, InsureeActivity.class); + intent.putExtra("FamilyData", familyObj.toString()); + intent.putExtra("FamilyId", familyId); + startActivityForResult(intent, REQUEST_CODE_CLOSE); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void canSave() { + if(spVillage.getText().toString().isEmpty()){ + btnNext.setEnabled(false); + } else { + btnNext.setEnabled(true); + } + } + + private void getPovertyStatus() throws JSONException { + String yesNoString = ca.getYesNo(); + JSONArray yesNoArray = new JSONArray(yesNoString); + JsonDropdownHelper.bindDropdown( + this, + spPovertyStatus, + yesNoArray, + "key", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + familyObj.put("ddlPovertyStatus", selectedItem.getString("key")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + ); + } + + private void getConfirmationTypes() throws JSONException { + String textLanguage = "ConfirmationType"; + String confirmationString = ca.getConfirmationTypes(); + JSONArray confirmationArray = new JSONArray(confirmationString); + JsonDropdownHelper.bindDropdown( + this, + spConfirmationType, + confirmationArray, + textLanguage, + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try{ + familyObj.put("ddlConfirmationType", selectedItem.getString("ConfirmationTypeCode")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + ); + } + + private void getFamilyTypes() throws JSONException { + String textLanguage = "FamilyType"; + String familyTypesString = ca.getGroupTypes(); + JSONArray familyTypesArray = new JSONArray(familyTypesString); + JsonDropdownHelper.bindDropdown( + this, + spFamilyType, + familyTypesArray, + textLanguage, + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + familyObj.put("ddlGroupType", selectedItem.getString("FamilyTypeCode")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + ); + } + + private void getApprovalOfSMS() throws JSONException { + String approvalString = ca.getApprovalOfSMS(); + JSONArray approvalArray = new JSONArray(approvalString); + JsonDropdownHelper.bindDropdown( + this, + spApprovalSMS, + approvalArray, + "key", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + familyObj.put("ddlApprovalOfSMS", selectedItem.getString("value")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + ); + } + + private void getLanguageOfSMS() throws JSONException { + String textLanguage = "LanguageName"; + String languagesString = ca.getLanguagesOfSMS(); + JSONArray languagesArray = new JSONArray(languagesString); + JsonDropdownHelper.bindDropdown( + this, + spLanguageSMS, + languagesArray, + textLanguage, + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + familyObj.put("ddlLanguageOfSMS", selectedItem.getString("LanguageCode")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + ); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + public void setupListeners(){ + + btnNext.setOnClickListener(v -> saveFamily()); + + } + +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/FamilyAdapter.java b/app/src/main/java/org/openimis/imispolicies/FamilyAdapter.java new file mode 100644 index 00000000..5fee30e4 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/FamilyAdapter.java @@ -0,0 +1,157 @@ +package org.openimis.imispolicies; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.PopupMenu; +import android.widget.TextView; + +import androidx.recyclerview.widget.RecyclerView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class FamilyAdapter extends RecyclerView.Adapter { + + private Context context; + private JSONArray families; + private ProgressDialog progressDialog; + + public FamilyAdapter(Context context, JSONArray families) { + this.context = context; + this.families = families; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + + View view = LayoutInflater.from(context) + .inflate(R.layout.item_family, parent, false); + + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + + try { + JSONObject family = families.getJSONObject(position); + holder.name.setText(family.getString("InsureeName")); + holder.chfid.setText(family.getString("CHFID")); + holder.region.setText(family.getString("RegionName")); + holder.district.setText(family.getString("DistrictName")); + holder.village.setText(family.getString("VillageName")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + + holder.btnContextMenu.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showContextMenu(view, position); + } + }); + } + + @Override + public int getItemCount() { + return families.length(); + } + + public class ViewHolder extends RecyclerView.ViewHolder{ + + TextView name,chfid,region, district, village; + ImageView btnContextMenu; + + public ViewHolder(View itemView) { + super(itemView); + + name = itemView.findViewById(R.id.txtFamilyInsureeName); + chfid = itemView.findViewById(R.id.txtFamilyInsuranceNumber); + region = itemView.findViewById(R.id.txtRegion); + district = itemView.findViewById(R.id.txtDistrict); + village = itemView.findViewById(R.id.txtVillage); + btnContextMenu = itemView.findViewById(R.id.btnContextMenuFamily); + } + } + + private void showContextMenu(View anchorView, int position) { + PopupMenu popup = new PopupMenu(context, anchorView); + popup.getMenuInflater().inflate(R.menu.family_menu, popup.getMenu()); + + popup.setOnMenuItemClickListener(item -> { + try { + JSONObject family = families.getJSONObject(position); + int familyId = family.getInt("FamilyId"); + int isOffline = family.getInt("isOffline"); + if(item.getItemId() == R.id.family_menu_edit){ + Intent intent = new Intent(context, FamilyInsurees.class); + intent.putExtra("FamilyId", familyId); + context.startActivity(intent); + } else if(item.getItemId() == R.id.family_menu_delete){ + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.Confirm) + .setMessage(R.string.DeleteFamily) + .setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + showLoadingDialog(); + ClientAndroidInterface ca = new ClientAndroidInterface((Activity) context); + if(isOffline == 0 || isOffline == 2){ + int result = ca.DeleteOnlineDataF(familyId); + if (result == 1) { + ca.ShowDialog(context.getResources().getString(R.string.FamilyDeleted)); + dialogInterface.dismiss(); + } + } else { + int deleteSuccess = ca.DeleteFamily(familyId); + if (deleteSuccess == 1) { + ca.ShowDialog(context.getResources().getString(R.string.FamilyDeleted)); + dialogInterface.dismiss(); + Intent intent = new Intent(context, Enrolment.class); + context.startActivity(intent); + ((Activity) context).finish(); + } else if(deleteSuccess == -1){ + ca.ShowDialog(context.getResources().getString(R.string.LoginToDeleteOnlineData)); + } else if(deleteSuccess == 3){ + int result = ca.DeleteOnlineDataF(familyId); + if (result == 1) { + ca.ShowDialog(context.getResources().getString(R.string.FamilyDeleted)); + dialogInterface.dismiss(); + } + } + } + if (progressDialog != null && progressDialog.isShowing()) { + progressDialog.dismiss(); + } + } + }) + .setNegativeButton(R.string.No, null) + .show(); + } + + } catch (JSONException e) { + throw new RuntimeException(e); + } + return false; + }); + + popup.show(); + } + + private void showLoadingDialog() { + progressDialog = new ProgressDialog(context); + progressDialog.setMessage(context.getResources().getString(R.string.Pleasewait)); + progressDialog.setTitle(context.getResources().getString(R.string.Delete)); + progressDialog.setCancelable(false); + progressDialog.show(); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/FamilyInsurees.java b/app/src/main/java/org/openimis/imispolicies/FamilyInsurees.java new file mode 100644 index 00000000..cc970de0 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/FamilyInsurees.java @@ -0,0 +1,109 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; +import android.widget.Button; +import android.widget.ListView; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager2.widget.ViewPager2; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.openimis.imispolicies.tools.Log; + +import java.util.HashMap; + +public class FamilyInsurees extends AppCompatActivity { + + public static int familyId; + TextView regionName, districtName, wardName, villageName; + ClientAndroidInterface ca; + private ViewPager2 viewPager; + private TabLayout tabLayout; + public static int regionId; + public static int districtId; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_family_insurees); + setTitle(getResources().getString(R.string.FamilyAndInsurees)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + viewPager = findViewById(R.id.viewPager); + tabLayout = findViewById(R.id.tabLayout); + ca = new ClientAndroidInterface(this); + familyId = getIntent().getIntExtra("FamilyId", 0); + initViews(); + if(familyId != 0){ + LoadFamilyHeader(familyId); + } + + PagerAdapter adapter = new PagerAdapter(this); + viewPager.setAdapter(adapter); + viewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL); + new TabLayoutMediator(tabLayout, viewPager, + (tab, position) -> tab.setText(adapter.getTitle(position)) + ).attach(); + } + + @Override + protected void onResume() { + super.onResume(); + } + + private void LoadFamilyHeader(int familyId){ + String FamilyHeader = ca.getFamilyHeader(familyId); + bindDataFromDatafield(FamilyHeader); + } + + private void bindDataFromDatafield(String data){ + try { + JSONArray array = new JSONArray(data); + JSONObject object = array.getJSONObject(0); + regionId = object.getInt("RegionId"); + districtId = object.getInt("DistrictId"); + regionName.setText(object.getString("RegionName")); + districtName.setText(object.getString("DistrictName")); + wardName.setText(object.getString("WardName")); + villageName.setText(object.getString("VillageName")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void initViews() { + regionName = findViewById(R.id.RegionName); + districtName = findViewById(R.id.DistrictName); + wardName = findViewById(R.id.WardName); + villageName = findViewById(R.id.VillageName); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/InsureeActivity.java b/app/src/main/java/org/openimis/imispolicies/InsureeActivity.java new file mode 100644 index 00000000..40532815 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/InsureeActivity.java @@ -0,0 +1,1245 @@ +package org.openimis.imispolicies; + +import android.content.ContentResolver; +import android.content.Intent; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Bundle; +import android.provider.MediaStore; +import android.view.MenuItem; +import android.view.View; +import android.widget.ImageView; +import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; + +import com.google.android.material.button.MaterialButton; +import com.google.android.material.card.MaterialCardView; +import com.google.android.material.datepicker.MaterialDatePicker; +import com.google.android.material.textfield.MaterialAutoCompleteTextView; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; +import com.google.zxing.client.android.Intents; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.openimis.imispolicies.tools.Log; +import org.openimis.imispolicies.util.JsonDropdownHelper; +import org.openimis.imispolicies.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; + +public class InsureeActivity extends AppCompatActivity { + + JSONObject familyObject; + private JSONObject insureeObject; + + private ImageView imgInsuree; + private MaterialCardView cardImage; + private TextInputEditText txtLastName, txtOtherNames, txtInsuranceNumber, txtBirthDate, txtCurrentAddress, txtPhoneNumber, + txtEmail, txtIdentificationNumber; + private TextInputLayout layoutChfId, layoutOtherNames, layoutLastName, layoutBirthDate, layoutGender, layoutRelationships; + private MaterialButton btnSave, btnScan; + private MaterialAutoCompleteTextView ddlMaritalStatus, ddlBeneficiaryCard, ddlGenders, ddlRelationships, ddlCurrentRegion, + ddlCurrenDistricts, ddlCurrentMunicipality, ddlCurrentVillage, ddlFSPRegion, ddlFSPDistrict, ddlFSPCategory, ddlFSP, + ddlProfession, ddlEducation, ddlIdentificationType, ddlVulnerability; + + private int insureeId = 0; + private String isOffline = "."; + private int isHead = -1; + private String photoPath = ""; + private String hfImagePath; + private String hfNewPhotoPath; + private int familyId; + public Uri tempPhotoUri = null; + + public static String filePath = null; + + public static int RESULT_LOAD_IMG = 1; + public static int RESULT_SCAN = 100; + + // Date picker + private MaterialDatePicker datePicker; + + ClientAndroidInterface ca; + + private String FSPDistrictId, HFLevel; + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == ClientAndroidInterface.RESULT_LOAD_IMG && resultCode == RESULT_OK) { + Uri selectedImage; + if (data == null || data.getData() == null || + (data.getData() != null + && data.getAction() != null + && data.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE))) { + Log.d("Main", "RESULT_LOAD_IMG got a camera result, in the predefined location"); + selectedImage = ClientAndroidInterface.tempPhotoUri; + captureImageCallback(selectedImage); + } else { + // File selection + selectedImage = data.getData(); + ca.setTempPhotoUri(selectedImage); + selectImageCallback(selectedImage); + } + } else if (requestCode == ClientAndroidInterface.RESULT_SCAN && resultCode == RESULT_OK && data != null) { + String insureeNumber = data.getStringExtra(Intents.Scan.RESULT); + if (!StringUtils.isEmpty(insureeNumber)) { + scanQrCallback(insureeNumber); + } + } + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_insuree); + setTitle(getResources().getString(R.string.AddEditInsuree)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + insureeObject = new JSONObject(); + ca = new ClientAndroidInterface(this); + insureeId = getIntent().getIntExtra("InsureeId", 0); + familyId = getIntent().getIntExtra("FamilyId", 0); + initViews(); + layoutRelationships.setVisibility(View.GONE); + + String jsonString = getIntent().getStringExtra("FamilyData"); + if (jsonString != null) { + // creation d'une famille + try { + familyObject = new JSONObject(jsonString); + isHead = 1; + } catch (JSONException e) { + e.printStackTrace(); + } + } else { + if(insureeId != 0){ + // modification d'un assuré + loadInitialData(); + } else { + // création d'un membre + isHead = 0; + layoutRelationships.setVisibility(View.VISIBLE); + layoutRelationships.setError(" "); + } + } + setupPickers(); + setupDatePicker(); + setupListeners(); + defineRequiredField(); + canSave(); + } + + private void initViews() { + ddlRelationships = findViewById(R.id.ddlRelationships); + txtInsuranceNumber = findViewById(R.id.txtInsuranceNumber); + txtOtherNames = findViewById(R.id.txtOtherNames); + txtLastName = findViewById(R.id.txtLastName); + imgInsuree = findViewById(R.id.imgInsuree); + txtBirthDate = findViewById(R.id.txtBirthDate); + ddlGenders = findViewById(R.id.ddlGenders); + cardImage = findViewById(R.id.cardImage); + btnSave = findViewById(R.id.btnSave); + ddlMaritalStatus = findViewById(R.id.ddlMaritalStatus); + ddlBeneficiaryCard = findViewById(R.id.ddlBeneficiaryCard); + ddlCurrentRegion = findViewById(R.id.ddlCurrentRegion); + ddlCurrenDistricts = findViewById(R.id.ddlCurrentDistrict); + ddlCurrentMunicipality = findViewById(R.id.ddlCurrentMunicipality); + ddlCurrentVillage = findViewById(R.id.ddlCurrentVillage); + ddlFSPRegion = findViewById(R.id.ddlFSPRegion); + ddlFSPDistrict = findViewById(R.id.ddlFSPDistrict); + ddlFSPCategory = findViewById(R.id.ddlFSPCategory); + ddlFSP = findViewById(R.id.ddlFSP); + ddlProfession = findViewById(R.id.ddlProfession); + ddlEducation = findViewById(R.id.ddlEducation); + ddlIdentificationType = findViewById(R.id.ddlIdentificationType); + ddlVulnerability = findViewById(R.id.ddlVulnerability); + btnScan = findViewById(R.id.btnScan); + layoutChfId = findViewById(R.id.layoutChfID); + layoutOtherNames = findViewById(R.id.layoutOtherNames); + layoutLastName = findViewById(R.id.layoutLastName); + layoutBirthDate = findViewById(R.id.layoutBirthDate); + layoutGender = findViewById(R.id.layoutGenders); + txtPhoneNumber = findViewById(R.id.txtPhoneNumber); + txtEmail = findViewById(R.id.txtEmail); + txtCurrentAddress = findViewById(R.id.txtCurrentAddress); + txtIdentificationNumber = findViewById(R.id.txtIdentificationNumber); + layoutRelationships = findViewById(R.id.layoutRelationships); + } + + private void defineRequiredField(){ + layoutChfId.setError(" "); + layoutLastName.setError(" "); + layoutBirthDate.setError(" "); + layoutOtherNames.setError(" "); + layoutGender.setError(" "); + } + + private void setupPickers() { + fillRelationships(); + fillGenders(); + fillMaritalStatus(); + fillBeneficiaryCard(); + fillCurrentRegions(); + fillFSPRegions(); + fillEducations(); + fillProfession(); + fillIdentificationTypes(); + fillVulnerability(); + } + + private void canSave(){ + if(txtInsuranceNumber.getText().toString().isEmpty() || + txtBirthDate.getText().toString().isEmpty() || + txtLastName.getText().toString().isEmpty() || + txtOtherNames.getText().toString().isEmpty() || + ddlGenders.getText().toString().isEmpty() + ){ + btnSave.setEnabled(false); + } else if (isHead != 1 && ddlRelationships.getText().toString().isEmpty()) { + btnSave.setEnabled(false); + } else { + btnSave.setEnabled(true); + } + } + + private void fillRelationships (){ + try { + String textLanguage = "Relation"; +// if (ca.getSelectedLanguage() != "en") { +// textLanguage = "AltLanguage"; +// } + // Setup Relationship Spinner + String relationships = ca.getRelationships(); + JSONArray relationshipsArray = new JSONArray(relationships); + JsonDropdownHelper.bindDropdown( + this, + ddlRelationships, + relationshipsArray, + textLanguage, + "", + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if (selectedItem != null) { + try { + String relationId = selectedItem.getString("RelationId"); + insureeObject.put("ddlRelationship", relationId); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("Relationship") && !insureeObject.getString("Relationship").isEmpty()){ + String savedValue = insureeObject.getString("Relationship"); + insureeObject.put("ddlRelationship", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlRelationships, + relationshipsArray, + textLanguage, + "RelationId", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillCurrentRegions (){ + try{ + String data = ca.getRegionsWO(); + JSONArray regionsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlCurrentRegion, + regionsArray, + "LocationName", + "", + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + String regionId = selectedItem.getString("LocationId"); + insureeObject.put("ddlCurrentRegion", regionId); + fillCurrentDistricts(regionId); + ddlCurrentMunicipality.setAdapter(null); + ddlCurrentVillage.setAdapter(null); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("CurRegion") && !insureeObject.getString("CurRegion").isEmpty()){ + String savedValue = insureeObject.getString("CurRegion"); + insureeObject.put("ddlCurrentRegion", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlCurrentRegion, + regionsArray, + "LocationName", + "LocationId", + savedValue + ); + } + } catch (JSONException e){ + throw new RuntimeException(e); + } + } + + private void fillFSPRegions (){ + try{ + String data = ca.getRegionsWO(); + JSONArray regionsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlFSPRegion, + regionsArray, + "LocationName", + "", + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + String regionId = selectedItem.getString("LocationId"); + insureeObject.put("ddlFSPRegion", regionId); + ddlFSPDistrict.setText(""); + ddlFSP.setText(""); + ddlFSPCategory.setText(""); + fillFSPDistricts(regionId); + fillFSP(null, null); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("FSPRegion") && !insureeObject.getString("FSPRegion").isEmpty()){ + String savedValue = insureeObject.getString("FSPRegion"); + insureeObject.put("ddlFSPRegion", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlFSPRegion, + regionsArray, + "LocationName", + "LocationId", + savedValue + ); + } + } catch (JSONException e){ + throw new RuntimeException(e); + } + } + + private void fillCurrentDistricts(String regionId){ + try{ + if(regionId != null && !regionId.isEmpty()){ + String data = ca.getDistrictsWO(Integer.parseInt(regionId)); + JSONArray districtsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlCurrenDistricts, + districtsArray, + "LocationName", + "", + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + String districtId = selectedItem.getString("LocationId"); + insureeObject.put("ddlCurrentDistrict", districtId); + ddlCurrentMunicipality.setText(""); + ddlCurrentVillage.setText(""); + fillCurrentWard(districtId); + fillCurrentVillage(null); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("CurDistrict") && !insureeObject.getString("CurDistrict").isEmpty()){ + String savedValue = insureeObject.getString("CurDistrict"); + insureeObject.put("ddlCurrentDistrict", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlCurrenDistricts, + districtsArray, + "LocationName", + "LocationId", + savedValue + ); + } + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillFSPDistricts(String regionId){ + try{ + if(regionId != null && !regionId.isEmpty()){ + String data = ca.getDistrictsWO(Integer.parseInt(regionId)); + JSONArray districtsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlFSPDistrict, + districtsArray, + "LocationName", + "", + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + if(!selectedItem.getString("LocationId").isEmpty()){ + FSPDistrictId = selectedItem.getString("LocationId"); + insureeObject.put("ddlFSPDistrict", FSPDistrictId); + ddlFSPCategory.setText(""); + ddlFSP.setText(""); + fillFSPCategory(); + fillFSP(FSPDistrictId, HFLevel); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("FSPDistrict") && + !insureeObject.getString("FSPDistrict").isEmpty()){ + String savedValue = insureeObject.getString("FSPDistrict"); + insureeObject.put("ddlFSPDistrict", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlFSPDistrict, + districtsArray, + "LocationName", + "LocationId", + savedValue + ); + } + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillCurrentWard(String districtId){ + try { + if (districtId != null && !districtId.isEmpty()) { + String data = ca.getWards(Integer.parseInt(districtId)); + JSONArray wardsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlCurrentMunicipality, + wardsArray, + "LocationName", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + String wardId = selectedItem.getString("LocationId"); + insureeObject.put("ddlCurrentMunicipality", wardId); + ddlCurrentVillage.setText(""); + fillCurrentVillage(wardId); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("CurWard") && + !insureeObject.getString("CurWard").isEmpty()){ + String savedValue = insureeObject.getString("CurWard"); + insureeObject.put("ddlCurrentMunicipality", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlCurrentMunicipality, + wardsArray, + "LocationName", + "LocationId", + savedValue + ); + } + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillFSPCategory(){ + try { + String data = ca.getHFLevels(); + JSONArray wardsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlFSPCategory, + wardsArray, + "HFLevel", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + HFLevel = selectedItem.getString("Code"); + insureeObject.put("ddlFSPCategory", HFLevel); + ddlFSP.setText(""); + fillFSP(FSPDistrictId, HFLevel); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("FSPCategory") && + !insureeObject.getString("FSPCategory").isEmpty()){ + String savedValue = insureeObject.getString("FSPCategory"); + insureeObject.put("ddlFSPCategory", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlFSPCategory, + wardsArray, + "HFLevel", + "Code", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillCurrentVillage(String wardId){ + if(wardId != null && !wardId.isEmpty()) { + String data = ca.getVillages(Integer.parseInt(wardId)); + try { + JSONArray villagesArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlCurrentVillage, + villagesArray, + "LocationName", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + String villageId = selectedItem.getString("LocationId"); + insureeObject.put("ddlCurrentVillage", villageId); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + }); + + if(insureeObject != null && insureeObject.has("CurVillage") && + !insureeObject.getString("CurVillage").isEmpty()){ + String savedValue = insureeObject.getString("CurVillage"); + insureeObject.put("ddlCurrentVillage", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlCurrentVillage, + villagesArray, + "LocationName", + "LocationId", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + + private void fillFSP(String districtId, String HFLevel){ + if(districtId != null && !districtId.isEmpty() && HFLevel != null && !HFLevel.isEmpty()) { + String data = ca.getHF(Integer.parseInt(districtId), HFLevel); + try { + JSONArray villagesArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlFSP, + villagesArray, + "HF", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if(selectedItem != null){ + try { + String FSPId = selectedItem.getString("HFID"); + insureeObject.put("ddlFSP", FSPId); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + }); + + if(insureeObject != null && insureeObject.has("HFID") && + !insureeObject.getString("HFID").isEmpty()){ + String savedValue = insureeObject.getString("HFID"); + insureeObject.put("ddlFSP", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlFSP, + villagesArray, + "HF", + "HFID", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + } + + private void fillGenders() { + + try { + String textLanguage = "Gender"; +// if (ca.getSelectedLanguage() != "en") { +// textLanguage = "AltLanguage"; +// } + String genders = ca.getGender(); + JSONArray gendersArray = new JSONArray(genders); + JsonDropdownHelper.bindDropdown( + this, + ddlGenders, + gendersArray, + textLanguage, + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if (selectedItem != null) { + try { + String code = selectedItem.getString("Code"); + insureeObject.put("ddlGender", code); + canSave(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("Gender") && + !insureeObject.getString("Gender").isEmpty()){ + String savedValue = insureeObject.getString("Gender"); + insureeObject.put("ddlGender", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlGenders, + gendersArray, + textLanguage, + "Code", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillEducations(){ + String textLanguage = "Education"; +// if (ca.getSelectedLanguage() != "en") { +// textLanguage = "AltLanguage"; + String data = ca.getEducations(); + try { + JSONArray educationsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlEducation, + educationsArray, + textLanguage, + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + String educationId = selectedItem.getString("EducationId"); + insureeObject.put("ddlEducation", educationId); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + }); + + if(insureeObject != null && insureeObject.has("Education") && + !insureeObject.getString("Education").isEmpty()){ + String savedValue = insureeObject.getString("Education"); + insureeObject.put("ddlEducation", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlEducation, + educationsArray, + textLanguage, + "EducationId", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillProfession() { + String textLanguage = "Profession"; + String data = ca.getProfessions(); + try { + JSONArray professionsArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlProfession, + professionsArray, + textLanguage, + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + String professionId = selectedItem.getString("ProfessionId"); + insureeObject.put("ddlProfession", professionId); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + }); + + if(insureeObject != null && insureeObject.has("Profession") && + !insureeObject.getString("Profession").isEmpty()){ + String savedValue = insureeObject.getString("Profession"); + insureeObject.put("ddlProfession", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlProfession, + professionsArray, + textLanguage, + "ProfessionId", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillIdentificationTypes(){ + String textLanguage = "IdentificationTypes"; + String data = ca.getIdentificationTypes(); + try { + JSONArray identificationTypesArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlIdentificationType, + identificationTypesArray, + textLanguage, + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + try { + String identificationTypeId = selectedItem.getString("IdentificationCode"); + insureeObject.put("ddlIdentificationType", identificationTypeId); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + }); + + if(insureeObject != null && insureeObject.has("typeOfId") && + !insureeObject.getString("TypeOfId").isEmpty()){ + String savedValue = insureeObject.getString("TypeOfId"); + insureeObject.put("ddlIdentificationType", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlIdentificationType, + identificationTypesArray, + textLanguage, + "Code", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void fillVulnerability (){ + String data = ca.getVulnerability(); + try { + JSONArray vulnerabilityArray = new JSONArray(data); + JsonDropdownHelper.bindDropdown( + this, + ddlVulnerability, + vulnerabilityArray, + "key", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if (selectedItem != null) { + try { + String vulnerabilityId = selectedItem.getString("value"); + insureeObject.put("ddlVulnerability", vulnerabilityId); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("Vulnerability") && + !insureeObject.getString("Vulnerability").isEmpty()){ + String savedValue = insureeObject.getString("Vulnerability"); + insureeObject.put("ddlVulnerability", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlVulnerability, + vulnerabilityArray, + "key", + "value", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + + private void fillMaritalStatus() { + String maritalStatus = ca.getMaritalStatus(); + try { + JSONArray maritalStatusData = new JSONArray(maritalStatus); + JsonDropdownHelper.bindDropdown( + this, + ddlMaritalStatus, + maritalStatusData, + "Status", // displayField + null, // pas de texte par défaut + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if (selectedItem != null) { + try { + String code = selectedItem.getString("Code"); + insureeObject.put("ddlMaritalStatus", code); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("Marital") && + !insureeObject.getString("Marital").isEmpty()){ + String savedValue = insureeObject.getString("Marital"); + insureeObject.put("ddlMaritalStatus", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlMaritalStatus, + maritalStatusData, + "Status", + "Code", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + // fillBeneficiaryCard avec JSON + private void fillBeneficiaryCard() { + String yesNoData = ca.getYesNo(); + try { + JSONArray yesNoArray = new JSONArray(yesNoData); + JsonDropdownHelper.bindDropdown( + this, + ddlBeneficiaryCard, + yesNoArray, + "key", // displayField + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if (selectedItem != null) { + try { + String value = selectedItem.getString("value"); + insureeObject.put("ddlBeneficiaryCard", value); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } + ); + + if(insureeObject != null && insureeObject.has("CardIssued") && + !insureeObject.getString("CardIssued").isEmpty()){ + String savedValue = insureeObject.getString("CardIssued"); + insureeObject.put("ddlBeneficiaryCard", savedValue); + JsonDropdownHelper.selectValue( + this, + ddlBeneficiaryCard, + yesNoArray, + "key", + "value", + savedValue + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + + } + + private void setupDatePicker() { + // Create Material Date Picker + MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.datePicker(); + builder.setTitleText(getResources().getString(R.string.SelectBirthDate)); + builder.setSelection(MaterialDatePicker.todayInUtcMilliseconds()); + + datePicker = builder.build(); + + datePicker.addOnPositiveButtonClickListener(selection -> { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(selection); + SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()); + txtBirthDate.setText(format.format(calendar.getTime())); + }); + + txtBirthDate.setOnClickListener(v -> { + datePicker.show(getSupportFragmentManager(), "DATE_PICKER"); + }); + } + + private void setupListeners() { + + // Insurance number on text changed + txtInsuranceNumber.addTextChangedListener(new android.text.TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { +// String chfId = txtInsuranceNumber.getText().toString().trim(); +// boolean ans = ca.isValidInsuranceNumber(chfId); +// if(ans != true){ +// txtInsuranceNumber.setText(""); +// } + } + + @Override + public void afterTextChanged(android.text.Editable s) { + + } + }); + + // Image card click listener + cardImage.setOnClickListener(v -> ca.selectPicture()); + + // Save button + btnSave.setOnClickListener(v -> saveFormData()); + + btnScan.setOnClickListener(v -> { + ca.getScannedNumber(); + }); + + } + + public void scanQrCallback(String insureeNumber){ + if(ca.isValidInsuranceNumber(insureeNumber)){ + txtInsuranceNumber.setText(insureeNumber); + getImage(); + } else { + txtInsuranceNumber.setText(""); + txtInsuranceNumber.setFocusable(true); + } + } + + public void selectImageCallback(Uri imageUri) { + if (imageUri != null) { + try { + InputStream testStream = getContentResolver().openInputStream(imageUri); + if (testStream != null) { + testStream.close(); + } + hfNewPhotoPath = getPathFromUri(imageUri); + Log.d("DEBUG_URI", "L'URI est accessible: " + hfNewPhotoPath); + loadImage(imageUri); + } catch (Exception e) { + Log.e("DEBUG_URI", "L'URI n'est pas accessible: " + e.getMessage()); + Toast.makeText(this, "Image non accessible", Toast.LENGTH_SHORT).show(); + return; + } + } else { + Log.d("selectImageCallback", "No image selected"); + Toast.makeText(this, "No image selected", Toast.LENGTH_SHORT).show(); + } + } + + public void captureImageCallback(Uri imageUri) { + if (imageUri != null) { + try { + InputStream testStream = getContentResolver().openInputStream(imageUri); + if (testStream != null) { + testStream.close(); + } + hfNewPhotoPath = imageUri.toString(); + Log.d("DEBUG_URI", "L'URI est accessible: " + hfNewPhotoPath); + loadImage(imageUri); + } catch (Exception e) { + Log.e("DEBUG_URI", "L'URI n'est pas accessible: " + e.getMessage()); + Toast.makeText(this, "Image non accessible", Toast.LENGTH_SHORT).show(); + return; + } + } else { + Log.d("selectImageCallback", "No image selected"); + Toast.makeText(this, "No image selected", Toast.LENGTH_SHORT).show(); + } + } + + private String getPathFromUri(Uri uri) { + String path = null; + + // Pour les URI de type content:// + if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { + String[] projection = {MediaStore.Images.Media.DATA}; + Cursor cursor = getContentResolver().query(uri, projection, null, null, null); + if (cursor != null) { + int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + path = cursor.getString(columnIndex); + cursor.close(); + } + } + // Pour les URI de type file:// + else if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { + path = uri.getPath(); + } + + return path != null ? path : ""; + } + + private void getImage() { + String insuranceNumber = txtInsuranceNumber.getText().toString().trim(); + String imagePath = ca.GetListOfImagesContain(insuranceNumber); + + if (imagePath != null && !imagePath.isEmpty()) { + hfImagePath = "file://" + imagePath; + loadImage(hfImagePath); + } else { + imgInsuree.setImageResource(android.R.color.transparent); + imgInsuree.setImageDrawable(null); + hfImagePath = ""; + } + // Log pour débogage + Log.d("getImage", "Insurance Number: " + insuranceNumber + ", Image Path: " + hfImagePath); + } + + private void loadImage(String imagePath) { + File imgFile = new File(imagePath); + if (imgFile.exists()) { + Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); + imgInsuree.setImageBitmap(bitmap); + }else{ + imgInsuree.setImageResource(R.drawable.image_not_supported); + } + } + + private void loadImage(Uri imageUri){ + try { + InputStream inputStream = getContentResolver().openInputStream(imageUri); + Bitmap bitmap = BitmapFactory.decodeStream(inputStream); + imgInsuree.setImageBitmap(bitmap); + if (inputStream != null) { + inputStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + + private void loadInitialData() { + Bundle extras = getIntent().getExtras(); + try { + if (extras != null) { + String insuree = ca.getInsuree(insureeId); + JSONArray array = new JSONArray(insuree); + insureeObject = array.getJSONObject(0); + isOffline = insureeObject.getString("isOffline"); + isHead = insureeObject.getInt("isHead"); + photoPath = insureeObject.getString("PhotoPath"); + if(isHead == 1){ + layoutRelationships.setVisibility(View.GONE); + } else { + layoutRelationships.setVisibility(View.VISIBLE); + layoutRelationships.setError(" "); + } + bindInsureeData(insureeObject); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void bindInsureeData(JSONObject object) throws JSONException { + + txtInsuranceNumber.setText(object.getString("CHFID")); + txtOtherNames.setText(object.getString("OtherNames")); + txtLastName.setText(object.getString("LastName")); + txtBirthDate.setText(object.getString("DOB")); + txtIdentificationNumber.setText(object.getString("IdentificationNumber")); + txtPhoneNumber.setText(object.getString("Phone")); + txtEmail.setText(object.getString("Email")); + txtCurrentAddress.setText(object.getString("CurrentAddress")); + + if(photoPath.isEmpty()){ + getImage(); + } + + //Load image if exists + if (photoPath != null && !photoPath.isEmpty()) { + var photoFolder = ca.GetSystemImageFolder(); + if (photoPath.indexOf(photoFolder) == -1) { + photoPath = photoFolder + photoPath; + loadImage(photoPath); + } + } + } + + public void saveFormData() { + try { + getImage(); + insureeObject.put("isOffline", isOffline); + insureeObject.put("hfisHead", isHead); + insureeObject.put("hfImagePath", hfImagePath); + insureeObject.put("hfNewPhotoPath", hfNewPhotoPath); + insureeObject.put("txtInsuranceNumber", txtInsuranceNumber.getText().toString()); + insureeObject.put("txtLastName", txtLastName.getText().toString()); + insureeObject.put("txtOtherNames", txtOtherNames.getText().toString()); + insureeObject.put("txtBirthDate", txtBirthDate.getText().toString()); + insureeObject.put("txtIdentificationNumber", txtIdentificationNumber.getText().toString()); + insureeObject.put("txtPhoneNumber", txtPhoneNumber.getText().toString()); + insureeObject.put("txtEmail", txtEmail.getText().toString()); + insureeObject.put("txtCurrentAddress", txtCurrentAddress.getText().toString()); + insureeObject.put("hfInsureeId", String.valueOf(insureeId)); + + if(familyObject != null){ + familyId = ca.SaveFamily(familyObject.toString(),insureeObject.toString()); + if(familyId > 0){ + Intent intent = new Intent(this, FamilyInsurees.class); + intent.putExtra("FamilyId", familyId); + setResult(RESULT_OK); + startActivity(intent); + finish(); + } + } else if(insureeId == 0){ + // ajout d'un membre + int ans = ca.SaveInsuree(insureeObject.toString(),familyId, isHead, 0, 0); + if(ans!=0 && ans != 7){ + FragmentActivity activity = (FragmentActivity) this; + FragmentManager fm = activity.getSupportFragmentManager(); + Bundle result = new Bundle(); + result.putBoolean("refresh_insurees", true); + fm.setFragmentResult("requestKey", result); + finish(); + } + } else { + // modification d'un assuré + String FamilyPolicy = ca.getFamilyPolicy(familyId); + JSONArray policies = new JSONArray(FamilyPolicy); + JSONObject policy = policies.getJSONObject(0); + int MemberCount = Integer.parseInt(policy.getString("MemberCount")); + int Threshold = Integer.parseInt(policy.getString("Threshold")); + int TotalIns = Integer.parseInt(policy.getString("Ins")); + int PolicyId = Integer.parseInt(policy.getString("PolicyId")); + int exceedThreshold = -1; + + if (PolicyId > 0 && insureeId == 0) { + + if (TotalIns >= MemberCount) { + exceedThreshold = 0; + ca.ShowDialog(getResources().getString(R.string.ExceedMemberCount)); + } else if (TotalIns >= Threshold) { + exceedThreshold = 1; + } else { + exceedThreshold = 0; + } + } + try { + int ans = ca.SaveInsuree(insureeObject.toString(),familyId, isHead, 0, 0); + if(ans!=0 && ans != 7){ + finish(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + } catch (JSONException e) { + throw new RuntimeException(e); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/InsureeAdapter.java b/app/src/main/java/org/openimis/imispolicies/InsureeAdapter.java new file mode 100644 index 00000000..0312cffd --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/InsureeAdapter.java @@ -0,0 +1,170 @@ +package org.openimis.imispolicies; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.PopupMenu; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.card.MaterialCardView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class InsureeAdapter extends RecyclerView.Adapter { + + private Context context; + private JSONArray insurees; + private int familyId; + private ProgressDialog progressDialog; + + public InsureeAdapter(Context context, JSONArray insurees, int familyId) { + this.context = context; + this.insurees = insurees; + this.familyId = familyId; + } + + + @NonNull + @Override + public InsureeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(context) + .inflate(R.layout.list_item_insuree, parent, false); + + return new InsureeAdapter.ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull InsureeAdapter.ViewHolder holder, int position) { + try { + JSONObject insuree = insurees.getJSONObject(position); + holder.name.setText(insuree.getString("InsureeName")); + holder.chfid.setText(insuree.getString("CHFID")); + holder.dob.setText(insuree.getString("DOB")); + + if(insuree.getString("isHead").equals("1")){ + holder.insureeCard.setStrokeColor(context.getResources().getColor(R.color.colorAccent)); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + + holder.btnContextMenu.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showContextMenu(view, position); + } + }); + } + + @Override + public int getItemCount() { + return insurees.length(); + } + + public class ViewHolder extends RecyclerView.ViewHolder{ + + TextView name,chfid,dob; + ImageView btnContextMenu; + MaterialCardView insureeCard; + + public ViewHolder(View itemView) { + super(itemView); + chfid = itemView.findViewById(R.id.CHFID); + name = itemView.findViewById(R.id.InsureeName); + dob = itemView.findViewById(R.id.item_dob); + btnContextMenu = itemView.findViewById(R.id.btnContextMenuInsuree); + insureeCard = itemView.findViewById(R.id.family_insurees_card); + } + } + + private void showContextMenu(View anchorView, int position) { + PopupMenu popup = new PopupMenu(context, anchorView); + popup.getMenuInflater().inflate(R.menu.insuree_menu, popup.getMenu()); + try { + JSONObject insuree = insurees.getJSONObject(position); + int insureeId = insuree.getInt("InsureeId"); + int isOffline = insuree.getInt("isOffline"); + if(insuree.getString("isHead").equals("1")){ + popup.getMenu().findItem(R.id.insuree_menu_delete).setVisible(false); + } else { + popup.getMenu().findItem(R.id.insuree_menu_delete).setVisible(true); + } + popup.setOnMenuItemClickListener(item -> { + if(item.getItemId() == R.id.insuree_menu_edit){ + Intent intent = new Intent(context, InsureeActivity.class); + intent.putExtra("InsureeId", insureeId); + intent.putExtra("FamilyId", familyId); + context.startActivity(intent); + } else if(item.getItemId() == R.id.insuree_menu_delete){ + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.Confirm) + .setMessage(R.string.DeleteInsuree) + .setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + showLoadingDialog(); + ClientAndroidInterface ca = new ClientAndroidInterface((Activity) context); + int deleteSuccess = 0; + if(isOffline == 0 || isOffline == 2){ + showLoadingDialog(); + deleteSuccess = ca.DeleteOnlineData(insureeId, "I"); + } else { + deleteSuccess = ca.DeleteInsuree(insureeId); + } + if (deleteSuccess == 1) { + dialogInterface.dismiss(); + progressDialog.dismiss(); + FragmentActivity activity = (FragmentActivity) context; + FragmentManager fm = activity.getSupportFragmentManager(); + Bundle result = new Bundle(); + result.putBoolean("refresh_insurees", true); + fm.setFragmentResult("requestKey", result); + ca.ShowDialog(context.getResources().getString(R.string.InsureeDeleted)); + } else if(deleteSuccess == 2){ + dialogInterface.dismiss(); + progressDialog.dismiss(); + ca.ShowDialog(context.getResources().getString(R.string.IsHeadDelete)); + } else if(deleteSuccess == -1){ + dialogInterface.dismiss(); + progressDialog.dismiss(); + ca.ShowDialog(context.getResources().getString(R.string.LoginToDeleteOnlineData)); + } else { + dialogInterface.dismiss(); + ca.ShowDialog(context.getResources().getString(R.string.InsureeNotDeleted)); + } + } + }) + .setNegativeButton(R.string.No, null) + .show(); + } + return false; + }); + } catch (JSONException e) { + throw new RuntimeException(e); + } + popup.show(); + } + + private void showLoadingDialog() { + progressDialog = new ProgressDialog(context); + progressDialog.setMessage(context.getResources().getString(R.string.Pleasewait)); + progressDialog.setTitle(context.getResources().getString(R.string.Delete)); + progressDialog.setCancelable(false); + progressDialog.show(); + } +} diff --git a/app/src/main/java/org/openimis/imispolicies/InsureesFragment.java b/app/src/main/java/org/openimis/imispolicies/InsureesFragment.java new file mode 100644 index 00000000..e692bd83 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/InsureesFragment.java @@ -0,0 +1,70 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import org.json.JSONArray; +import org.json.JSONException; + +public class InsureesFragment extends Fragment { + + FloatingActionButton btnAddInsuree; + private int familyId = 0; + RecyclerView recyclerInsurees; + private ClientAndroidInterface ca; + + public InsureesFragment(){} + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.insurees_fragment, container, false); + getParentFragmentManager().setFragmentResultListener("requestKey", this, (requestKey, bundle) -> { + boolean refresh = bundle.getBoolean("refresh_insurees"); + if (refresh) { + LoadInsurees(); + } + }); + btnAddInsuree = view.findViewById(R.id.btnNewInsuree); + recyclerInsurees = view.findViewById(R.id.recyclerInsurees); + ca = new ClientAndroidInterface(getActivity()); + familyId = getActivity().getIntent().getIntExtra("FamilyId", 0); + recyclerInsurees.setLayoutManager(new LinearLayoutManager(getContext())); + LoadInsurees(); + + + btnAddInsuree.setOnClickListener(v -> { + Intent intent = new Intent(getActivity(), InsureeActivity.class); + intent.putExtra("FamilyId", familyId); + startActivity(intent); + }); + + return view; + } + + @Override + public void onResume() { + super.onResume(); + LoadInsurees(); + } + + private void LoadInsurees() { + try { + String insurees = ca.getInsureesForFamily(familyId); + JSONArray insureeArray = new JSONArray(insurees); + InsureeAdapter adapter = new InsureeAdapter(getContext(),insureeArray, familyId); + recyclerInsurees.setAdapter(adapter); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } +} diff --git a/app/src/main/java/org/openimis/imispolicies/JSONSpinnerAdapter.java b/app/src/main/java/org/openimis/imispolicies/JSONSpinnerAdapter.java new file mode 100644 index 00000000..7f2d4b6c --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/JSONSpinnerAdapter.java @@ -0,0 +1,77 @@ +package org.openimis.imispolicies; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class JSONSpinnerAdapter extends BaseAdapter { + + private Context context; + private JSONArray data; + private String text; + + public JSONSpinnerAdapter(Context context, JSONArray data, String text) { + this.context = context; + this.data = data; + this.text = text; + } + + @Override + public int getCount() { + return data.length(); + } + + @Override + public Object getItem(int position) { + try { + return data.getJSONObject(position); + } catch (JSONException e) { + return null; + } + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + TextView textView = new TextView(context); + textView.setPadding(20,20,20,20); + textView.setTextSize(16); + + try { + JSONObject obj = data.getJSONObject(position); + textView.setText(obj.getString(text)); + } catch (JSONException e) { + e.printStackTrace(); + } + + return textView; + } + + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + + TextView textView = new TextView(context); + textView.setPadding(20,20,20,20); + textView.setTextSize(16); + + try { + JSONObject obj = data.getJSONObject(position); + textView.setText(obj.getString(text)); + } catch (JSONException e) { + e.printStackTrace(); + } + + return textView; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/LoginActivity.java b/app/src/main/java/org/openimis/imispolicies/LoginActivity.java new file mode 100644 index 00000000..5647a266 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/LoginActivity.java @@ -0,0 +1,168 @@ +package org.openimis.imispolicies; + +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.Intent; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.MenuItem; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.google.android.material.button.MaterialButton; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + +import org.openimis.imispolicies.util.AndroidUtils; + +public class LoginActivity extends AppCompatActivity { + + TextInputLayout layoutLoginName, layoutPassword; + MaterialButton btnLogin; + TextInputEditText txtLoginName, txtPassword; + String officerCode; + ClientAndroidInterface ca; + int page; + private ProgressDialog progressDialog; + ProgressBar progressBar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + setTitle(getResources().getString(R.string.Login)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + ca = new ClientAndroidInterface(this); + progressDialog = new ProgressDialog(this); + officerCode = ca.getOfficerCode(); + page = getIntent().getIntExtra("Page",0); + initViews(); + canSave(); + setupListenners(); + + btnLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String username = txtLoginName.getText().toString(); + String password = txtPassword.getText().toString(); + + boolean hasInternet = ca.CheckInternetAvailable(); + if(!hasInternet){ + ca.ShowDialog(getResources().getString(R.string.NoInternet)); + } else { + progressBar.setVisibility(View.VISIBLE); + boolean loggedIn = ca.LoginJI(username, password); + if(loggedIn){ + if(page == 0){ + finish(); + } else if (page == 1) { + progressBar.setVisibility(View.GONE); + Intent intent = new Intent(LoginActivity.this, SearchActivity.class); + startActivity(intent); + finish(); + } else if (page == 2) { + progressBar.setVisibility(View.GONE); + Intent intent = new Intent(LoginActivity.this, Enrolment.class); + startActivity(intent); + finish(); + } else if (page == 4) { + progressBar.setVisibility(View.GONE); + ca.launchActivity("Reports"); + finish(); + } else if (page == 5) { + progressBar.setVisibility(View.GONE); + ca.launchActivity("Enquire"); + finish(); + } else { + progressBar.setVisibility(View.GONE); + Intent intent = new Intent(LoginActivity.this, MainActivity.class); + startActivity(intent); + finish(); + } + } else { + progressDialog.dismiss(); + ca.ShowDialog(getResources().getString(R.string.LoginFail)); + } + } + + } + }); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void initViews(){ + layoutPassword = findViewById(R.id.layoutPassword); + layoutLoginName = findViewById(R.id.layoutLoginName); + btnLogin = findViewById(R.id.btnLogin); + txtLoginName = findViewById(R.id.txtLoginName); + txtPassword = findViewById(R.id.txtPassword); + progressBar = findViewById(R.id.loginProgressBar); + + txtLoginName.setText(officerCode); + } + + private void canSave(){ + if(txtLoginName.getText().toString().isEmpty() || + txtPassword.getText().toString().isEmpty() + ){ + btnLogin.setEnabled(false); + } else { + btnLogin.setEnabled(true); + } + } + + private void setupListenners(){ + txtLoginName.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) { + canSave(); + } + + @Override + public void afterTextChanged(Editable editable) { + + } + }); + + txtPassword.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) { + canSave(); + } + + @Override + public void afterTextChanged(Editable editable) { + + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/MainActivity.java b/app/src/main/java/org/openimis/imispolicies/MainActivity.java index 861f735b..12a3f40c 100644 --- a/app/src/main/java/org/openimis/imispolicies/MainActivity.java +++ b/app/src/main/java/org/openimis/imispolicies/MainActivity.java @@ -120,9 +120,11 @@ public class MainActivity extends AppCompatActivity private String selectedLanguage; public String ImagePath; public String InsureeNumber; - TextView Login; + TextView Login, tvTotalFamily, tvTotalInsuree, tvTotalPolicies, tvTotalPremium, tvTotalFamilyOnline, tvTotalInsureeOnline, + tvSumPremium; TextView OfficerName; ClientAndroidInterface ca; + InsureeActivity insureeActivity; String aBuffer = ""; String calledFrom = "java"; public File f; @@ -135,25 +137,7 @@ public class MainActivity extends AppCompatActivity protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == ClientAndroidInterface.RESULT_LOAD_IMG && resultCode == RESULT_OK) { - Uri selectedImage; - if (data == null || data.getData() == null || - (data.getData() != null - && data.getAction() != null - && data.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE))) { - Log.d("Main", "RESULT_LOAD_IMG got a camera result, in the predefined location"); - selectedImage = ClientAndroidInterface.tempPhotoUri; - } else { - // File selection - selectedImage = data.getData(); - } - wv.evaluateJavascript(String.format("selectImageCallback(\"%s\");", selectedImage), null); - } else if (requestCode == ClientAndroidInterface.RESULT_SCAN && resultCode == RESULT_OK && data != null) { - String insureeNumber = data.getStringExtra(Intents.Scan.RESULT); - if (!StringUtils.isEmpty(insureeNumber)) { - wv.evaluateJavascript(String.format("scanQrCallback(\"%s\");", insureeNumber), null); - } - } else if (requestCode == REQUEST_PICK_MD_FILE) { + if (requestCode == REQUEST_PICK_MD_FILE) { if (resultCode == RESULT_OK && data != null) { Uri uri = data.getData(); if (uri != null) { @@ -260,10 +244,6 @@ protected void onCreate(Bundle savedInstanceState) { Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); - FloatingActionButton fab = findViewById(R.id.fab); - fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show()); - DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); @@ -272,40 +252,52 @@ protected void onCreate(Bundle savedInstanceState) { toggle.syncState(); navigationView = findViewById(R.id.nav_view); + tvTotalFamily = findViewById(R.id.TotalFamily); + tvTotalFamilyOnline = findViewById(R.id.TotalFamilyOnline); + tvTotalInsuree = findViewById(R.id.TotalInsuree); + tvTotalPremium = findViewById(R.id.TotalPremium); + tvTotalInsureeOnline = findViewById(R.id.TotalInsureeOnline); + tvTotalPolicies = findViewById(R.id.TotalPolicies); + tvSumPremium = findViewById(R.id.PremiumAmount); navigationView.setNavigationItemSelectedListener(this); - wv = findViewById(R.id.webview); - WebSettings settings = wv.getSettings(); - wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); - settings.setJavaScriptEnabled(true); - //noinspection deprecation - settings.setRenderPriority(WebSettings.RenderPriority.HIGH); - settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); - settings.setDomStorageEnabled(true); - settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); - settings.setUseWideViewPort(true); - settings.setSaveFormData(true); - settings.setAllowFileAccess(true); - //noinspection deprecation - settings.setEnableSmoothTransition(true); - settings.setLoadWithOverviewMode(true); - wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android"); +// wv = findViewById(R.id.webview); +// WebSettings settings = wv.getSettings(); +// wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); +// settings.setJavaScriptEnabled(true); +// //noinspection deprecation +// settings.setRenderPriority(WebSettings.RenderPriority.HIGH); +// settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); +// settings.setDomStorageEnabled(true); +// settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); +// settings.setUseWideViewPort(true); +// settings.setSaveFormData(true); +// settings.setAllowFileAccess(true); +// //noinspection deprecation +// settings.setEnableSmoothTransition(true); +// settings.setLoadWithOverviewMode(true); +// wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android"); //Register for context acquire_menu - registerForContextMenu(wv); - - wv.loadUrl("file:///android_asset/pages/Home.html"); - wv.setWebViewClient(new MyWebViewClient(MainActivity.this)); - - wv.setWebChromeClient(new WebChromeClient() { - @Override - public void onReceivedTitle(WebView view, String title) { - super.onReceivedTitle(view, title); - //noinspection ConstantConditions - getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE); - getSupportActionBar().setSubtitle(title); - } - }); +// registerForContextMenu(wv); + +// wv.loadUrl("file:///android_asset/pages/Home.html"); +// wv.setWebViewClient(new MyWebViewClient(MainActivity.this)); + +// wv.setWebChromeClient(new WebChromeClient() { +// @Override +// public void onReceivedTitle(WebView view, String title) { +// super.onReceivedTitle(view, title); +// //noinspection ConstantConditions +// getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE); +// getSupportActionBar().setSubtitle(title); +// } +// }); + + ca = new ClientAndroidInterface(this); + + LoadTotal(); + NavigationView navigationView = findViewById(R.id.nav_view); View headerview = navigationView.getHeaderView(0); Login = headerview.findViewById(R.id.tvLogin); @@ -316,20 +308,33 @@ public void onReceivedTitle(WebView view, String title) { drawer.closeDrawer(GravityCompat.START); SetLoggedIn(); }); - ca = new ClientAndroidInterface(this); if (ca.isMasterDataAvailable() > 0) { loadLanguages(); } - navigationView.setCheckedItem(R.id.nav_home); - if (checkRequirements()) { - onAllRequirementsMet(); - } - setVisibilityOfPaymentMenu(); } catch (Exception e) { Sentry.captureException(e); } } + private void LoadTotal(){ + int Families = ca.getTotalFamily(); + int Insuree = ca.getTotalInsuree(); + int Policy = ca.getTotalPolicy(); + int Premium = ca.getTotalPremium(); + String SumPremium = ca.getSumPremium(); + + int FamiliesOnline = ca.getTotalFamilyOnline(); + int InsureeOnline = ca.getTotalInsureeOnline(); + + tvTotalFamily.setText(String.valueOf(Families)); + tvTotalInsuree.setText(String.valueOf(Insuree)); + tvTotalPolicies.setText(String.valueOf(Policy)); + tvTotalPremium.setText(String.valueOf(Premium)); + tvSumPremium.setText(SumPremium); + tvTotalFamilyOnline.setText(String.valueOf(FamiliesOnline)); + tvTotalInsureeOnline.setText(String.valueOf(InsureeOnline)); + } + private void setVisibilityOfPaymentMenu() { navigationView = findViewById(R.id.nav_view); MenuItem navPayment = navigationView.getMenu().findItem(R.id.nav_payment); @@ -341,6 +346,7 @@ private void setVisibilityOfPaymentMenu() { protected void onResume() { super.onResume(); OfficerName.setText(global.getOfficerName()); + LoadTotal(); } public static void SetLoggedIn() { @@ -697,18 +703,25 @@ public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.nav_home) { - wv.loadUrl("file:///android_asset/pages/Home.html"); + //wv.loadUrl("file:///android_asset/pages/Home.html"); } else if (id == R.id.nav_acquire) { Intent intent = new Intent(this, Acquire.class); startActivity(intent); } else if (id == R.id.nav_enrolment) { - wv.loadUrl("file:///android_asset/pages/Enrollment.html"); + //wv.loadUrl("file:///android_asset/pages/Enrollment.html"); + Intent intent = new Intent(this, Enrolment.class); + startActivity(intent); } else if (id == R.id.nav_modify_family) { global = (Global) getApplicationContext(); if (global.isLoggedIn()) { - wv.loadUrl("file:///android_asset/pages/Search.html"); + //wv.loadUrl("file:///android_asset/pages/Search.html"); + Intent intent = new Intent(this, SearchActivity.class); + startActivity(intent); } else { - wv.loadUrl("file:///android_asset/pages/Login.html?s=1"); + //wv.loadUrl("file:///android_asset/pages/Login.html?s=1"); + Intent i = new Intent(this, LoginActivity.class); + i.putExtra("Page", 1); + startActivity(i); } } else if (id == R.id.nav_renewal) { @@ -721,15 +734,22 @@ public boolean onNavigationItemSelected(MenuItem item) { Intent i = new Intent(this, Reports.class); startActivity(i); } else { - wv.loadUrl("file:///android_asset/pages/Login.html?s=4"); + //wv.loadUrl("file:///android_asset/pages/Login.html?s=4"); + Intent i = new Intent(this, LoginActivity.class); + i.putExtra("Page", 4); + startActivity(i); } } else if (id == R.id.nav_feedback) { Intent intent = new Intent(this, FeedbackList.class); startActivity(intent); } else if (id == R.id.nav_sync) { - wv.loadUrl("file:///android_asset/pages/Sync.html"); + //wv.loadUrl("file:///android_asset/pages/Sync.html"); + Intent intent = new Intent(this, SyncActivity.class); + startActivity(intent); } else if (id == R.id.nav_about) { - wv.loadUrl("file:///android_asset/pages/About.html"); + //wv.loadUrl("file:///android_asset/pages/About.html"); + Intent intent = new Intent(this, AboutActivity.class); + startActivity(intent); } else if (id == R.id.nav_settings) { wv.loadUrl("file:///android_asset/pages/Settings.html"); } else if (id == R.id.nav_quit) { @@ -748,7 +768,10 @@ public boolean onNavigationItemSelected(MenuItem item) { Intent intent = new Intent(this, Enquire.class); startActivity(intent); } else { - wv.loadUrl("file:///android_asset/pages/Login.html?s=5"); + //wv.loadUrl("file:///android_asset/pages/Login.html?s=5"); + Intent i = new Intent(this, LoginActivity.class); + i.putExtra("Page", 5); + startActivity(i); } } else if (id == R.id.nav_payment) { ClientAndroidInterface ca = new ClientAndroidInterface(this); @@ -765,14 +788,15 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: - if (wv.canGoBack()) { - if (global.getCurrentUrl() != null) - wv.loadUrl("file:///android_asset/pages/" + global.getCurrentUrl()); - else - wv.goBack(); - } else { - finish(); - } +// if (wv.canGoBack()) { +// if (global.getCurrentUrl() != null) +// wv.loadUrl("file:///android_asset/pages/" + global.getCurrentUrl()); +// else +// wv.goBack(); +// } else { +// finish(); +// } + finish(); return true; } } diff --git a/app/src/main/java/org/openimis/imispolicies/PagerAdapter.java b/app/src/main/java/org/openimis/imispolicies/PagerAdapter.java new file mode 100644 index 00000000..2c624310 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/PagerAdapter.java @@ -0,0 +1,37 @@ +package org.openimis.imispolicies; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.viewpager2.adapter.FragmentStateAdapter; + +public class PagerAdapter extends FragmentStateAdapter { + private static final int NUM_PAGES = 2; + private String[] titles = new String[]{"Insurees", "Policies"}; + + public PagerAdapter(@NonNull FragmentActivity fragmentActivity) { + super(fragmentActivity); + } + + @NonNull + @Override + public Fragment createFragment(int position) { + switch (position) { + case 0: + return new InsureesFragment(); + case 1: + return new PoliciesFragment(); + default: + return new InsureesFragment(); + } + } + + @Override + public int getItemCount() { + return NUM_PAGES; + } + + public String getTitle(int position) { + return titles[position]; + } +} diff --git a/app/src/main/java/org/openimis/imispolicies/PoliciesFragment.java b/app/src/main/java/org/openimis/imispolicies/PoliciesFragment.java new file mode 100644 index 00000000..318fa23e --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/PoliciesFragment.java @@ -0,0 +1,76 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import org.json.JSONArray; +import org.json.JSONException; + +import java.text.ParseException; + +public class PoliciesFragment extends Fragment { + + FloatingActionButton btnAddPolicy; + private int familyId; + RecyclerView recyclerPolicies; + private ClientAndroidInterface ca; + + public PoliciesFragment() {} + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.policies_fragment, container, false); + getParentFragmentManager().setFragmentResultListener("requestKey", this, (requestKey, bundle) -> { + boolean refresh = bundle.getBoolean("refresh_policies"); + if (refresh) { + loadPolicies(); + } + }); + familyId = FamilyInsurees.familyId; + btnAddPolicy = view.findViewById(R.id.btnNewPolicy); + recyclerPolicies = view.findViewById(R.id.recyclerPolicies); + ca = new ClientAndroidInterface(getActivity()); + recyclerPolicies.setLayoutManager(new LinearLayoutManager(getContext())); + loadPolicies(); + + btnAddPolicy.setOnClickListener(v -> { + Intent intent = new Intent(getActivity(), PolicyActivity.class); + intent.putExtra("FamilyId", familyId); + intent.putExtra("RegionId", FamilyInsurees.regionId); + intent.putExtra("DistrictId", FamilyInsurees.districtId); + startActivity(intent); + }); + + return view; + + } + + @Override + public void onResume() { + super.onResume(); + loadPolicies(); + } + + private void loadPolicies(){ + try { + String policies = ca.getFamilyPolicies(familyId); + JSONArray policiesArray = new JSONArray(policies); + PolicyAdapter adapter = new PolicyAdapter(getContext(),policiesArray, familyId); + recyclerPolicies.setAdapter(adapter); + } catch (JSONException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } +} diff --git a/app/src/main/java/org/openimis/imispolicies/PolicyActivity.java b/app/src/main/java/org/openimis/imispolicies/PolicyActivity.java new file mode 100644 index 00000000..5920d094 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/PolicyActivity.java @@ -0,0 +1,328 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; + +import com.google.android.material.button.MaterialButton; +import com.google.android.material.datepicker.MaterialDatePicker; +import com.google.android.material.textfield.MaterialAutoCompleteTextView; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.openimis.imispolicies.tools.Log; +import org.openimis.imispolicies.util.JsonDropdownHelper; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +public class PolicyActivity extends AppCompatActivity { + + private TextInputLayout layoutEnrolmentDate, layoutProduct, layoutEffectiveDate, layoutStartDate, layoutExpiryDate, layoutControlNumber; + private TextView txtPolicyStatus, spPolicyValue, spContribution, spBalance; + private MaterialButton btnSave; + private MaterialAutoCompleteTextView ddlProduct; + private TextInputEditText txtEnrolmentDate, txtEffectiveDate, txtStartDate, txtExpiryDate, AssignedControlNumber; + private JSONObject policyObject; + private int policyId = 0; + private int familyId; + ClientAndroidInterface ca; + boolean hasCycle; + private int officerId, regionId, districtId, productId; + private MaterialDatePicker datePicker; + private int isOffline = 1; + private String policyStatus = "1"; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_policy); + setTitle(getResources().getString(R.string.AddEditPolicy)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + initViews(); + setupListeners(); + setupDatePicker(); + defineRequiredField(); + + policyObject = new JSONObject(); + ca = new ClientAndroidInterface(this); + policyId = getIntent().getIntExtra("PolicyId", 0); + familyId = getIntent().getIntExtra("FamilyId", 0); + regionId = getIntent().getIntExtra("RegionId", 0); + districtId = getIntent().getIntExtra("DistrictId", 0); + + if(!ca.IsBulkCNUsed()){ + layoutControlNumber.setVisibility(View.GONE); + } + layoutEffectiveDate.setEnabled(false); + txtExpiryDate.setEnabled(false); + officerId = ca.getOfficerId(); + + if(policyId != 0){ + loadInitialData(); + } + loadProducts(regionId, districtId, null); + canSave(); + } + + private void initViews(){ + layoutEnrolmentDate = findViewById(R.id.layoutEnrolmentDate); + layoutProduct = findViewById(R.id.layoutProduct); + layoutEffectiveDate = findViewById(R.id.layoutEffectiveDate); + layoutStartDate = findViewById(R.id.layoutStartDate); + layoutExpiryDate = findViewById(R.id.layoutExpiryDate); + layoutControlNumber = findViewById(R.id.layoutControlNumber); + txtPolicyStatus = findViewById(R.id.txtPolicyStatus); + spPolicyValue = findViewById(R.id.spPolicyValue); + spContribution = findViewById(R.id.spContribution); + spBalance = findViewById(R.id.spBalance); + btnSave = findViewById(R.id.btnSavePolicy); + ddlProduct = findViewById(R.id.ddlProduct); + txtEnrolmentDate = findViewById(R.id.txtEnrolmentDate); + txtEffectiveDate = findViewById(R.id.txtEffectiveDate); + txtStartDate = findViewById(R.id.txtStartDate); + txtExpiryDate = findViewById(R.id.txtExpiryDate); + AssignedControlNumber = findViewById(R.id.AssignedControlNumber); + } + + private void setupListeners(){ + txtEnrolmentDate.setOnClickListener(v -> { + datePicker.show(getSupportFragmentManager(), "DATE_PICKER"); + }); + + btnSave.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + savePolicy(); + } + }); + } + + private void defineRequiredField(){ + layoutEnrolmentDate.setError(" "); + layoutProduct.setError(" "); + layoutStartDate.setError(" "); + layoutExpiryDate.setError(" "); + } + + private void canSave(){ + if(txtEnrolmentDate.getText().toString().isEmpty() || + txtStartDate.getText().toString().isEmpty() || + txtExpiryDate.getText().toString().isEmpty() || + ddlProduct.getText().toString().isEmpty() + ){ + btnSave.setEnabled(false); + } else { + btnSave.setEnabled(true); + } + } + + private void loadProducts(int regionId, int districtId, String enrolmentDate){ + try { + String products = ca.getProducts(regionId, districtId, enrolmentDate); + JSONArray productsArray = new JSONArray(products); + JsonDropdownHelper.bindDropdown( + this, + ddlProduct, + productsArray, + "ProductNameCombined", + null, + new JsonDropdownHelper.OnJsonItemSelectedListener() { + @Override + public void onItemSelected(JSONObject selectedItem, int position) { + if (selectedItem != null) { + try { + productId = selectedItem.getInt("ProdId"); + String enrolDate = txtEnrolmentDate.getText().toString().trim(); + policyObject.put("ddlProduct", productId); + getPolicyPeriod(enrolDate, productId, familyId, policyId); + canSave(); + + if(ca.IsBulkCNUsed()) { + if(productId == 0) { + AssignedControlNumber.setText(""); + } + String controlNumber = ca.GetNextBulkCn(String.valueOf(productId)); + if(controlNumber.equals("undefined")) { + ca.ShowDialog(getResources().getString(R.string.noBulkCNAvailable)); + AssignedControlNumber.setText(""); + } else { + AssignedControlNumber.setText(""); + } + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } + ); + + if(policyObject != null && policyObject.has("ProdId") && policyObject.getInt("ProdId") != 0){ + productId = policyObject.getInt("ProdId"); + policyObject.put("ddlProduct", productId); + JsonDropdownHelper.selectValue( + this, + ddlProduct, + productsArray, + "ProductNameCombined", + "ProdId", + String.valueOf(productId) + ); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void setupDatePicker() { + // Create Material Date Picker + MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.datePicker(); + builder.setTitleText(getResources().getString(R.string.EnrolmentDate)); + builder.setSelection(MaterialDatePicker.todayInUtcMilliseconds()); + + datePicker = builder.build(); + + datePicker.addOnPositiveButtonClickListener(selection -> { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(selection); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); + txtEnrolmentDate.setText(format.format(calendar.getTime())); + String enrolDate = txtEnrolmentDate.getText().toString().trim(); + loadProducts(regionId, districtId, enrolDate); + if(productId != 0){ + getPolicyPeriod(format.format(calendar.getTime()), productId, familyId, policyId); + } + canSave(); + }); + + txtEnrolmentDate.setOnClickListener(v -> { + datePicker.show(getSupportFragmentManager(), "DATE_PICKER"); + }); + } + + private void getPolicyPeriod(String EnrolmentDate, int ProdId, int FamilyId, int policyId){ + if(EnrolmentDate.length() == 0 || ProdId == 0){ + return; + } + try { + String period = ca.getPolicyPeriod(ProdId, EnrolmentDate); + JSONArray periodArray = new JSONArray(period); + String startDate = periodArray.getJSONObject(0).getString("StartDate"); + String expiryDate = periodArray.getJSONObject(0).getString("ExpiryDate"); + hasCycle = periodArray.getJSONObject(0).getBoolean("HasCycle"); + + txtStartDate.setText(startDate); + txtExpiryDate.setText(expiryDate); + + txtStartDate.setEnabled(hasCycle); + + double PolicyValue = ca.getPolicyValue(EnrolmentDate, ProdId, FamilyId, startDate, hasCycle, 0, "N", isOffline); + spPolicyValue.setText(String.valueOf(PolicyValue)); + } catch (ParseException e) { + throw new RuntimeException(e); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void savePolicy(){ + try { + policyObject.put("ddlOfficer",officerId); + policyObject.put("AssignedControlNumber", AssignedControlNumber.getText()); + policyObject.put("hfPolicyValue", spPolicyValue.getText()); + policyObject.put("hfPolicyStatus", txtPolicyStatus.getText()); + policyObject.put("txtExpiryDate", txtExpiryDate.getText()); + policyObject.put("txtEnrolmentDate", txtEnrolmentDate.getText()); + policyObject.put("txtStartDate", txtStartDate.getText()); + policyObject.put("txtEffectiveDate", txtEffectiveDate.getText()); + policyObject.put("hfPolicyStatus", policyStatus); + + policyId = ca.SavePolicy(policyObject.toString(), familyId, policyId); + if(policyId > 0){ + FragmentActivity activity = (FragmentActivity) this; + FragmentManager fm = activity.getSupportFragmentManager(); + Bundle result = new Bundle(); + result.putBoolean("refresh_policies", true); + fm.setFragmentResult("requestKey", result); + finish(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void loadInitialData(){ + try { + String policy = ca.getPolicy(policyId); + JSONArray array = new JSONArray(policy); + policyObject = array.getJSONObject(0); + productId = policyObject.getInt("ProdId"); + officerId = policyObject.getInt("OfficerId"); + txtStartDate.setText(policyObject.getString("StartDate")); + txtEnrolmentDate.setText(policyObject.getString("EnrollDate")); + txtExpiryDate.setText(policyObject.getString("ExpiryDate")); + isOffline = policyObject.getInt("isOffline"); + txtPolicyStatus.setText(policyObject.getString("PolicyStatus")); + spBalance.setText(policyObject.getString("Balance")); + spContribution.setText(policyObject.getString("Contribution")); + policyStatus = policyObject.getString("PolicyStatusValue"); + double currentPolicyValue = policyObject.getDouble("PolicyValue"); + spPolicyValue.setText(String.valueOf(currentPolicyValue)); + String policyStage = policyObject.getString("PolicyStage"); + Log.d("policy object", policyObject.toString()); + if(ca.IsBulkCNUsed()){ + if(!policyObject.getString("ControlNumber").isEmpty()){ + AssignedControlNumber.setText(policyObject.getString("ControlNumber")); + } else { + AssignedControlNumber.setText(""); + } + } + + double NewPolicyValue = ca.getPolicyValue(txtEnrolmentDate.getText().toString(), productId, familyId, txtStartDate.getText().toString(), hasCycle, policyId, policyStage, isOffline); + if (NewPolicyValue != currentPolicyValue) { + Date Vdate = new Date(txtEnrolmentDate.getText().toString()); //or your date here + var NewDate = ((Vdate.getMonth() + 1) + '/' + Vdate.getDate() + '/' + Vdate.getYear()); + ca.ShowDialog(ca.getString("PolicyValueChange") + NewDate + ' ' + ca.getString("Changed")); + } + + if (policyStatus.equals("1")) { + layoutExpiryDate.setEnabled(true); + } else { + layoutExpiryDate.setEnabled(false); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/PolicyAdapter.java b/app/src/main/java/org/openimis/imispolicies/PolicyAdapter.java new file mode 100644 index 00000000..f4c0f78c --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/PolicyAdapter.java @@ -0,0 +1,165 @@ +package org.openimis.imispolicies; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.PopupMenu; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.card.MaterialCardView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class PolicyAdapter extends RecyclerView.Adapter { + + private Context context; + private JSONArray policies; + private int familyId; + private ProgressDialog progressDialog; + + public PolicyAdapter(Context context, JSONArray policies, int familyId) { + this.context = context; + this.policies = policies; + this.familyId = familyId; + } + + @NonNull + @Override + public PolicyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(context) + .inflate(R.layout.list_item_policy, parent, false); + + return new PolicyAdapter.ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull PolicyAdapter.ViewHolder holder, int position) { + try { + JSONObject policy = policies.getJSONObject(position); + holder.productCode.setText(policy.getString("ProductCode")); + holder.productName.setText(policy.getString("ProductName")); + holder.startDate.setText(policy.getString("StartDate")); + holder.expiryDate.setText(policy.getString("ExpiryDate")); + holder.value.setText(policy.getString("PolicyValue")); + holder.policyStatus.setText(policy.getString("PolicyStatus")); + holder.effectiveDate.setText(policy.getString("EffectiveDate")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + + holder.btnContextMenu.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showContextMenu(view, position); + } + }); + } + + @Override + public int getItemCount() { + return policies.length(); + } + + public class ViewHolder extends RecyclerView.ViewHolder{ + TextView productCode,productName,policyStatus, expiryDate, startDate, value, effectiveDate; + ImageView btnContextMenu; + + public ViewHolder(View itemView) { + super(itemView); + productCode = itemView.findViewById(R.id.policyProductCode); + productName = itemView.findViewById(R.id.policyProductName); + policyStatus = itemView.findViewById(R.id.policyStatus); + expiryDate = itemView.findViewById(R.id.policyExpiryDate); + effectiveDate = itemView.findViewById(R.id.policyEffectiveDate); + startDate = itemView.findViewById(R.id.policyStartDate); + value = itemView.findViewById(R.id.policyValue); + btnContextMenu = itemView.findViewById(R.id.btnContextMenuPolicy); + } + } + + private void showContextMenu(View anchorView, int position) { + PopupMenu popup = new PopupMenu(context, anchorView); + popup.getMenuInflater().inflate(R.menu.policy_menu, popup.getMenu()); + try { + JSONObject policy = policies.getJSONObject(position); + int policyId = policy.getInt("PolicyId"); + int isOffline = policy.getInt("isOffline"); + popup.setOnMenuItemClickListener(item -> { + if(item.getItemId() == R.id.policy_menu_edit){ + Intent intent = new Intent(context, PolicyActivity.class); + intent.putExtra("PolicyId", policyId); + intent.putExtra("FamilyId", familyId); + intent.putExtra("RegionId", FamilyInsurees.regionId); + intent.putExtra("DistrictId", FamilyInsurees.districtId); + context.startActivity(intent); + } else if(item.getItemId() == R.id.policy_menu_payment){ +// Intent intent = new Intent(context, PolicyPremiumActivity.class); +// intent.putExtra("PolicyId", policyId); +// intent.putExtra("FamilyId", familyId); +// context.startActivity(intent); + } else if(item.getItemId() == R.id.policy_menu_delete){ + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.Confirm) + .setMessage(R.string.DeletePolicyPremium) + .setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + showLoadingDialog(); + ClientAndroidInterface ca = new ClientAndroidInterface((Activity) context); + int deleteSuccess = -1; + if(isOffline == 0 || isOffline == 2){ + showLoadingDialog(); + deleteSuccess = ca.DeleteOnlineData(policyId, "PO"); + } else { + deleteSuccess = ca.DeletePolicy(policyId); + } + if (deleteSuccess == 1) { + FragmentActivity activity = (FragmentActivity) context; + FragmentManager fm = activity.getSupportFragmentManager(); + dialogInterface.dismiss(); + progressDialog.dismiss(); + Bundle result = new Bundle(); + result.putBoolean("refresh_policies", true); + fm.setFragmentResult("requestKey", result); + ca.ShowDialog(context.getResources().getString(R.string.PolicyDeleted)); + } else if(deleteSuccess == -1){ + dialogInterface.dismiss(); + progressDialog.dismiss(); + ca.ShowDialog(context.getResources().getString(R.string.LoginToDeleteOnlineData)); + } + } + }) + .setNegativeButton(R.string.No, null) + .show(); + } + return false; + }); + } catch (JSONException e) { + throw new RuntimeException(e); + } + popup.show(); + } + + private void showLoadingDialog() { + progressDialog = new ProgressDialog(context); + progressDialog.setMessage(context.getResources().getString(R.string.Pleasewait)); + progressDialog.setTitle(context.getResources().getString(R.string.Delete)); + progressDialog.setCancelable(false); + progressDialog.show(); + } +} diff --git a/app/src/main/java/org/openimis/imispolicies/SearchActivity.java b/app/src/main/java/org/openimis/imispolicies/SearchActivity.java new file mode 100644 index 00000000..2761f52b --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/SearchActivity.java @@ -0,0 +1,97 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.MenuItem; +import android.view.View; +import android.widget.ProgressBar; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.google.android.material.button.MaterialButton; +import com.google.android.material.textfield.TextInputEditText; + +public class SearchActivity extends AppCompatActivity { + + private TextInputEditText txtSearchInsuranceNumber; + MaterialButton btnSearch; + ClientAndroidInterface ca; + ProgressBar progressBar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_search); + setTitle(R.string.Search); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + ca = new ClientAndroidInterface(this); + initViews(); + canSearch(); + txtSearchInsuranceNumber.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) { + canSearch(); + } + + @Override + public void afterTextChanged(Editable editable) { + + } + }); + + btnSearch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + progressBar.setVisibility(View.VISIBLE); + String InsuranceNumber = txtSearchInsuranceNumber.getText().toString(); + if (ca.ModifyFamily(InsuranceNumber) == 1) { + progressBar.setVisibility(View.GONE); + Intent intent = new Intent(SearchActivity.this, Enrolment.class); + startActivity(intent); + finish(); + } else { + progressBar.setVisibility(View.GONE); + } + } + }); + + + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void initViews(){ + btnSearch = findViewById(R.id.btnSearch); + txtSearchInsuranceNumber = findViewById(R.id.txtSearchInsuranceNumber); + progressBar = findViewById(R.id.loadingProgressBar); + } + + private void canSearch (){ + if(txtSearchInsuranceNumber.getText().toString().isEmpty()){ + btnSearch.setEnabled(false); + } else { + btnSearch.setEnabled(true); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/SyncActivity.java b/app/src/main/java/org/openimis/imispolicies/SyncActivity.java new file mode 100644 index 00000000..6368fb7e --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/SyncActivity.java @@ -0,0 +1,103 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.google.android.material.button.MaterialButton; + +public class SyncActivity extends AppCompatActivity { + + ClientAndroidInterface ca; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sync); + setTitle(getResources().getString(R.string.Sync)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + ca = new ClientAndroidInterface(this); + + initButton(R.id.btnUploadEnrolment); + initButton(R.id.btnUploadRenewals); + initButton(R.id.btnUploadFeedBack); + initButton(R.id.btnEnrollmentXML); + initButton(R.id.btnCreateRenewalXML); + initButton(R.id.btnCreateFeedbackXML); + initButton(R.id.btnDownloadMaster); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void initButton(int id) { + MaterialButton btn = findViewById(id); + if (btn != null) { + btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int id = view.getId(); + + if (id == R.id.btnUploadEnrolment) { + if(!ca.isLoggedIn()){ + Intent intent = new Intent(SyncActivity.this, LoginActivity.class); + intent.putExtra("Page", 0); + startActivity(intent); + } else { + try { + ca.uploadEnrolment(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } else if (id == R.id.btnUploadRenewals) { + if (!ca.isLoggedIn()) { + Intent intent = new Intent(SyncActivity.this, LoginActivity.class); + intent.putExtra("Page", 0); + startActivity(intent); + } else { + ca.uploadRenewals(); + } + } else if (id == R.id.btnUploadFeedBack) { + if (!ca.isLoggedIn()) { + Intent intent = new Intent(SyncActivity.this, LoginActivity.class); + intent.putExtra("Page", 0); + startActivity(intent); + } else { + ca.uploadFeedbacks(); + } + } else if (id == R.id.btnEnrollmentXML) { + ca.CreateEnrolmentXML(); + } else if (id == R.id.btnCreateRenewalXML) { + ca.CreateRenewalExport(); + } else if (id == R.id.btnCreateFeedbackXML) { + ca.CreateFeedbackExport(); + } else if (id == R.id.btnDownloadMaster) { + String res = ca.checkNet(); + if (res.equals("false")) { + ca.getLocalData(); + } else { + ca.downloadMasterData(); + } + } + } + }); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/util/ActivityManager.java b/app/src/main/java/org/openimis/imispolicies/util/ActivityManager.java new file mode 100644 index 00000000..0f7833d9 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/util/ActivityManager.java @@ -0,0 +1,26 @@ +package org.openimis.imispolicies.util; + +import android.app.Activity; + +import java.util.Stack; + +public class ActivityManager { + + private static Stack activityStack = new Stack<>(); + + public static void addActivity(Activity activity) { + activityStack.push(activity); + } + + public static void finishCurrentAndPrevious() { + if (!activityStack.isEmpty()) { + Activity current = activityStack.pop(); + current.finish(); + } + + if (!activityStack.isEmpty()) { + Activity previous = activityStack.pop(); + previous.finish(); + } + } +} diff --git a/app/src/main/java/org/openimis/imispolicies/util/AndroidUtils.java b/app/src/main/java/org/openimis/imispolicies/util/AndroidUtils.java index 5b6df771..d60a941e 100644 --- a/app/src/main/java/org/openimis/imispolicies/util/AndroidUtils.java +++ b/app/src/main/java/org/openimis/imispolicies/util/AndroidUtils.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.DialogInterface; import android.os.Looper; +import android.widget.ProgressBar; import android.widget.Toast; import androidx.annotation.NonNull; diff --git a/app/src/main/java/org/openimis/imispolicies/util/JsonDropdownHelper.java b/app/src/main/java/org/openimis/imispolicies/util/JsonDropdownHelper.java new file mode 100644 index 00000000..93672105 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/util/JsonDropdownHelper.java @@ -0,0 +1,121 @@ +package org.openimis.imispolicies.util; + +import android.content.Context; +import android.util.SparseArray; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; + +import com.google.android.material.textfield.MaterialAutoCompleteTextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class JsonDropdownHelper { + + public interface OnJsonItemSelectedListener { + void onItemSelected(JSONObject selectedItem, int position); + } + + public static void bindDropdown(Context context, + MaterialAutoCompleteTextView dropdown, + JSONArray jsonArray, + String displayField, + String defaultText, + OnJsonItemSelectedListener listener) { + + List displayList = new ArrayList<>(); + SparseArray itemMap = new SparseArray<>(); + + try { + // Ajouter le texte par défaut + int startPosition = 0; + if (defaultText != null && !defaultText.isEmpty()) { + displayList.add(defaultText); + itemMap.put(0, null); + startPosition = 1; + } + + // Ajouter les données JSON + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject item = jsonArray.getJSONObject(i); + String displayValue = item.getString(displayField); + displayList.add(displayValue); + itemMap.put(startPosition + i, item); + } + } catch (JSONException e) { + e.printStackTrace(); + } + + ArrayAdapter adapter = new ArrayAdapter<>( + context, + android.R.layout.simple_dropdown_item_1line, + displayList + ); + dropdown.setAdapter(adapter); + + dropdown.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (listener != null) { + JSONObject selectedItem = itemMap.get(position); + listener.onItemSelected(selectedItem, position); + } + } + }); + } + + /** + * Méthode utilitaire pour pré-sélectionner une valeur après le bind + */ + public static void selectValue(Context context, + MaterialAutoCompleteTextView dropdown, + JSONArray jsonArray, + String displayField, + String valueField, + String savedValue) { + try { + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject item = jsonArray.getJSONObject(i); + String itemValue = item.getString(valueField); + + if (itemValue.equals(savedValue)) { + String displayValue = item.getString(displayField); + dropdown.setText(displayValue, false); + break; + } + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + + public static void selectValueFromObject(MaterialAutoCompleteTextView dropdown, + JSONArray jsonArray, + String displayField, + String valueField, + JSONObject selectedObject) { + + if (selectedObject == null) return; + + try { + String selectedValue = selectedObject.getString(valueField); + + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject item = jsonArray.getJSONObject(i); + + if (item.getString(valueField).equals(selectedValue)) { + dropdown.setText(item.getString(displayField), false); + break; + } + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/res/drawable/arrow_forward.xml b/app/src/main/res/drawable/arrow_forward.xml new file mode 100644 index 00000000..29e11bc6 --- /dev/null +++ b/app/src/main/res/drawable/arrow_forward.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/button_background.xml b/app/src/main/res/drawable/button_background.xml new file mode 100644 index 00000000..77b60250 --- /dev/null +++ b/app/src/main/res/drawable/button_background.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_disable.xml b/app/src/main/res/drawable/button_disable.xml new file mode 100644 index 00000000..c54341f2 --- /dev/null +++ b/app/src/main/res/drawable/button_disable.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/context_menu.xml b/app/src/main/res/drawable/context_menu.xml new file mode 100644 index 00000000..c3809a28 --- /dev/null +++ b/app/src/main/res/drawable/context_menu.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/corner.xml b/app/src/main/res/drawable/corner.xml index aa8efe61..6e896a98 100644 --- a/app/src/main/res/drawable/corner.xml +++ b/app/src/main/res/drawable/corner.xml @@ -3,7 +3,7 @@ android:thickness="0dp" android:shape="rectangle"> - + android:color="@color/grey2"/> + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_add_24.xml b/app/src/main/res/drawable/ic_add_24.xml new file mode 100644 index 00000000..2ae27b84 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_calendar_24.xml b/app/src/main/res/drawable/ic_calendar_24.xml new file mode 100644 index 00000000..2a703af6 --- /dev/null +++ b/app/src/main/res/drawable/ic_calendar_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/image_not_supported.xml b/app/src/main/res/drawable/image_not_supported.xml new file mode 100644 index 00000000..54507b03 --- /dev/null +++ b/app/src/main/res/drawable/image_not_supported.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/list_item_selector.xml b/app/src/main/res/drawable/list_item_selector.xml new file mode 100644 index 00000000..adde64e2 --- /dev/null +++ b/app/src/main/res/drawable/list_item_selector.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/qr_code_scanner.xml b/app/src/main/res/drawable/qr_code_scanner.xml new file mode 100644 index 00000000..45f715ad --- /dev/null +++ b/app/src/main/res/drawable/qr_code_scanner.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/recycler_divider.xml b/app/src/main/res/drawable/recycler_divider.xml new file mode 100644 index 00000000..7f305467 --- /dev/null +++ b/app/src/main/res/drawable/recycler_divider.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/spinner_background.xml b/app/src/main/res/drawable/spinner_background.xml new file mode 100644 index 00000000..9749e6f6 --- /dev/null +++ b/app/src/main/res/drawable/spinner_background.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/spinner_required.xml b/app/src/main/res/drawable/spinner_required.xml new file mode 100644 index 00000000..9b74d8b3 --- /dev/null +++ b/app/src/main/res/drawable/spinner_required.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml new file mode 100644 index 00000000..543f3dab --- /dev/null +++ b/app/src/main/res/layout/activity_about.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_enrolment.xml b/app/src/main/res/layout/activity_enrolment.xml new file mode 100644 index 00000000..04418894 --- /dev/null +++ b/app/src/main/res/layout/activity_enrolment.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/app/src/main/res/layout/activity_family.xml b/app/src/main/res/layout/activity_family.xml new file mode 100644 index 00000000..b768e756 --- /dev/null +++ b/app/src/main/res/layout/activity_family.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_family_insurees.xml b/app/src/main/res/layout/activity_family_insurees.xml new file mode 100644 index 00000000..0408dd35 --- /dev/null +++ b/app/src/main/res/layout/activity_family_insurees.xml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_insuree.xml b/app/src/main/res/layout/activity_insuree.xml new file mode 100644 index 00000000..c75d9f49 --- /dev/null +++ b/app/src/main/res/layout/activity_insuree.xml @@ -0,0 +1,573 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 00000000..185863ad --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_policy.xml b/app/src/main/res/layout/activity_policy.xml new file mode 100644 index 00000000..8fc0bc0d --- /dev/null +++ b/app/src/main/res/layout/activity_policy.xml @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml new file mode 100644 index 00000000..519fddf8 --- /dev/null +++ b/app/src/main/res/layout/activity_search.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_sync.xml b/app/src/main/res/layout/activity_sync.xml new file mode 100644 index 00000000..0fdce3d7 --- /dev/null +++ b/app/src/main/res/layout/activity_sync.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 129a857d..c877dcf5 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -22,16 +22,6 @@ - - - + diff --git a/app/src/main/res/layout/dialog.xml b/app/src/main/res/layout/dialog.xml index 0a732105..79b3495b 100644 --- a/app/src/main/res/layout/dialog.xml +++ b/app/src/main/res/layout/dialog.xml @@ -2,7 +2,7 @@ @@ -16,7 +16,10 @@ diff --git a/app/src/main/res/layout/dialog_delete_family.xml b/app/src/main/res/layout/dialog_delete_family.xml new file mode 100644 index 00000000..24dc4dfb --- /dev/null +++ b/app/src/main/res/layout/dialog_delete_family.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_progress.xml b/app/src/main/res/layout/dialog_progress.xml new file mode 100644 index 00000000..e4c6b181 --- /dev/null +++ b/app/src/main/res/layout/dialog_progress.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/home_content.xml b/app/src/main/res/layout/home_content.xml new file mode 100644 index 00000000..5c58ffff --- /dev/null +++ b/app/src/main/res/layout/home_content.xml @@ -0,0 +1,274 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/insurees_fragment.xml b/app/src/main/res/layout/insurees_fragment.xml new file mode 100644 index 00000000..6a294a01 --- /dev/null +++ b/app/src/main/res/layout/insurees_fragment.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_family.xml b/app/src/main/res/layout/item_family.xml new file mode 100644 index 00000000..81cee374 --- /dev/null +++ b/app/src/main/res/layout/item_family.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_item_insuree.xml b/app/src/main/res/layout/list_item_insuree.xml new file mode 100644 index 00000000..42c8d48f --- /dev/null +++ b/app/src/main/res/layout/list_item_insuree.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_item_policy.xml b/app/src/main/res/layout/list_item_policy.xml new file mode 100644 index 00000000..e829743d --- /dev/null +++ b/app/src/main/res/layout/list_item_policy.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/policies_fragment.xml b/app/src/main/res/layout/policies_fragment.xml new file mode 100644 index 00000000..760c6704 --- /dev/null +++ b/app/src/main/res/layout/policies_fragment.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/family_menu.xml b/app/src/main/res/menu/family_menu.xml new file mode 100644 index 00000000..5ed2c589 --- /dev/null +++ b/app/src/main/res/menu/family_menu.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/insuree_menu.xml b/app/src/main/res/menu/insuree_menu.xml new file mode 100644 index 00000000..2741cef4 --- /dev/null +++ b/app/src/main/res/menu/insuree_menu.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/policy_menu.xml b/app/src/main/res/menu/policy_menu.xml new file mode 100644 index 00000000..8d502145 --- /dev/null +++ b/app/src/main/res/menu/policy_menu.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cc3476f1..fa35ad00 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -8,7 +8,7 @@ #FF0000 - #999 + #B4B4B4 #800000 #008080 #09578e @@ -20,6 +20,7 @@ #b66200 #dcdcdc #737373 + #B1B1B1 #f4f4f4 #0032d6 #ff000d @@ -27,4 +28,5 @@ #00000000 #ff808080 #ffcccccc + #FF0000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee5e65a1..2db32050 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,9 +90,9 @@ Select Month Enrolment date Product - Effective Date + Effective Date: Start Date - Expire Date + Expire Date: Enrolment Officer Policy Status : Policy Value : @@ -483,4 +483,7 @@ Cash Mobile Phone Bank Transfer + Empty + Tap to change photo + Select birth date diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9dcb2b92..59dd732a 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,13 +1,14 @@ -