From 4c092d65b45caa7175d259c60a63d68c85dd9c64 Mon Sep 17 00:00:00 2001 From: vaneck237 Date: Mon, 9 Mar 2026 16:07:44 +0100 Subject: [PATCH 01/16] upgrade home and families summary activity and interfaces --- app/build.gradle | 1 + app/src/localeBepha/res/values/strings.xml | 14 +- app/src/main/AndroidManifest.xml | 22 +- .../imispolicies/ClientAndroidInterface.java | 2 +- .../org/openimis/imispolicies/Enrolment.java | 64 +++++ .../openimis/imispolicies/FamilyActivity.java | 24 ++ .../openimis/imispolicies/FamilyAdapter.java | 106 +++++++ .../openimis/imispolicies/MainActivity.java | 97 ++++--- .../main/res/layout/activity_enrolment.xml | 43 +++ app/src/main/res/layout/activity_family.xml | 10 + app/src/main/res/layout/app_bar_main.xml | 2 +- .../main/res/layout/dialog_delete_family.xml | 17 ++ app/src/main/res/layout/home_content.xml | 263 ++++++++++++++++++ app/src/main/res/layout/item_family.xml | 52 ++++ app/src/main/res/menu/family_menu.xml | 13 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 1 + 17 files changed, 680 insertions(+), 52 deletions(-) create mode 100644 app/src/main/java/org/openimis/imispolicies/Enrolment.java create mode 100644 app/src/main/java/org/openimis/imispolicies/FamilyActivity.java create mode 100644 app/src/main/java/org/openimis/imispolicies/FamilyAdapter.java create mode 100644 app/src/main/res/layout/activity_enrolment.xml create mode 100644 app/src/main/res/layout/activity_family.xml create mode 100644 app/src/main/res/layout/dialog_delete_family.xml create mode 100644 app/src/main/res/layout/home_content.xml create mode 100644 app/src/main/res/layout/item_family.xml create mode 100644 app/src/main/res/menu/family_menu.xml diff --git a/app/build.gradle b/app/build.gradle index 2135c835..65a54846 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -240,6 +240,7 @@ 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' androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' 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/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5a88ad6d..6b06e8f3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,9 +13,7 @@ - - - + @@ -28,7 +26,8 @@ - + + + @@ -71,6 +77,7 @@ android:theme="@style/AppTheme.NoActionBar"> + @@ -132,9 +139,7 @@ - - - + - - + \ 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 e06e4dfb..ad02a6d3 100644 --- a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java +++ b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java @@ -4947,7 +4947,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..4f65f997 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/Enrolment.java @@ -0,0 +1,64 @@ +package org.openimis.imispolicies; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +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; + JSONArray families = new JSONArray(); + ClientAndroidInterface ca; + TextView tvEmpty; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_enrolment); + setTitle(getApplicationContext().getString(R.string.Families)); + ca = new ClientAndroidInterface(this); + + recyclerView = findViewById(R.id.recyclerFamilies); + btnAdd = findViewById(R.id.btnAddNew); + tvEmpty = findViewById(R.id.tvEmptyFamily); + + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + try { + families = loadFamilies(); + } catch (JSONException e) { + throw new RuntimeException(e); + } + + tvEmpty.setVisibility(families.length() == 0 ? TextView.VISIBLE : TextView.GONE); + + FamilyAdapter adapter = new FamilyAdapter(this,families); + recyclerView.setAdapter(adapter); + + btnAdd.setOnClickListener(v -> { + + Intent intent = new Intent(this, FamilyActivity.class); + intent.putExtra("familyId",0); + startActivity(intent); + + }); + + } + + private JSONArray loadFamilies() throws JSONException { + String families = ca.getAllFamilies(); + return new JSONArray(families); + } +} \ 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..866e8f32 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java @@ -0,0 +1,24 @@ +package org.openimis.imispolicies; + +import android.os.Bundle; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class FamilyActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_family); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + } +} \ 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..7cc899f3 --- /dev/null +++ b/app/src/main/java/org/openimis/imispolicies/FamilyAdapter.java @@ -0,0 +1,106 @@ +package org.openimis.imispolicies; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +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; + + 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) { + + String familyId; + try { + JSONObject family = families.getJSONObject(position); + familyId = family.getString("FamilyId"); + holder.name.setText(family.getString("InsureeName")); + holder.chfid.setText(family.getString("InsuranceNumber")); + holder.region.setText(family.getString("Region")); + holder.district.setText(family.getString("District")); + holder.village.setText(family.getString("Village")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + + + holder.itemView.setOnLongClickListener(v -> { + + PopupMenu menu = new PopupMenu(context, holder.itemView); + menu.inflate(R.menu.family_menu); + + menu.setOnMenuItemClickListener(item -> { + + if(item.getItemId() == R.id.family_menu_edit){ + Intent intent = new Intent(context, FamilyActivity.class); + intent.putExtra("familyId", familyId); + context.startActivity(intent); + + } else if(item.getItemId() == R.id.family_menu_delete){ + + new AlertDialog.Builder(context) + .setTitle("Delete Family") + .setMessage("Are you sure?") + .setPositiveButton("Ok", (d,w)->{ + families.remove(position); + notifyDataSetChanged(); + }) + .setNegativeButton("Cancel", null) + .show(); + } + + return true; + }); + + menu.show(); + return true; + }); + } + + @Override + public int getItemCount() { + return families.length(); + } + + public class ViewHolder extends RecyclerView.ViewHolder{ + + TextView name,chfid,region, district, village; + + 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); + } + } +} \ 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 9298d82a..0df6a1af 100644 --- a/app/src/main/java/org/openimis/imispolicies/MainActivity.java +++ b/app/src/main/java/org/openimis/imispolicies/MainActivity.java @@ -117,7 +117,8 @@ 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; String aBuffer = ""; @@ -267,40 +268,67 @@ 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); + + 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)); + NavigationView navigationView = findViewById(R.id.nav_view); View headerview = navigationView.getHeaderView(0); Login = headerview.findViewById(R.id.tvLogin); @@ -311,7 +339,6 @@ public void onReceivedTitle(WebView view, String title) { drawer.closeDrawer(GravityCompat.START); SetLoggedIn(); }); - ca = new ClientAndroidInterface(this); if (ca.isMasterDataAvailable() > 0) { loadLanguages(); } @@ -691,12 +718,14 @@ 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()) { 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..7ccc87c4 --- /dev/null +++ b/app/src/main/res/layout/activity_enrolment.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + 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..5238d1c6 --- /dev/null +++ b/app/src/main/res/layout/activity_family.xml @@ -0,0 +1,10 @@ + + + + \ 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..0ebf4cb1 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -22,7 +22,7 @@ - + + + + + + + \ 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..e41524f2 --- /dev/null +++ b/app/src/main/res/layout/home_content.xml @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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..949b79a5 --- /dev/null +++ b/app/src/main/res/layout/item_family.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + \ 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/values/strings.xml b/app/src/main/res/values/strings.xml index ee5e65a1..39de79ad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -483,4 +483,5 @@ Cash Mobile Phone Bank Transfer + Empty diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9dcb2b92..4b192b8d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -6,6 +6,7 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent + @color/colorPrimary @color/colorPrimary From 6d17a1ff5597efb9258d2d43df23a5a276f0d99a Mon Sep 17 00:00:00 2001 From: vaneck237 Date: Tue, 10 Mar 2026 12:18:25 +0100 Subject: [PATCH 02/16] finish family form --- .../openimis/imispolicies/FamilyActivity.java | 316 +++++++++++++++++- .../imispolicies/JSONSpinnerAdapter.java | 77 +++++ .../openimis/imispolicies/MainActivity.java | 6 +- .../main/res/drawable/button_background.xml | 15 + app/src/main/res/drawable/button_disable.xml | 9 + .../main/res/drawable/spinner_background.xml | 16 + .../main/res/drawable/spinner_required.xml | 15 + app/src/main/res/layout/activity_family.xml | 153 ++++++++- app/src/main/res/layout/dialog.xml | 5 +- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/styles.xml | 2 +- 11 files changed, 596 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/org/openimis/imispolicies/JSONSpinnerAdapter.java create mode 100644 app/src/main/res/drawable/button_background.xml create mode 100644 app/src/main/res/drawable/button_disable.xml create mode 100644 app/src/main/res/drawable/spinner_background.xml create mode 100644 app/src/main/res/drawable/spinner_required.xml diff --git a/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java b/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java index 866e8f32..146d3375 100644 --- a/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java +++ b/app/src/main/java/org/openimis/imispolicies/FamilyActivity.java @@ -1,24 +1,320 @@ package org.openimis.imispolicies; +import android.content.Intent; import android.os.Bundle; - -import androidx.activity.EdgeToEdge; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.Spinner; import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.openimis.imispolicies.tools.Log; public class FamilyActivity extends AppCompatActivity { + Spinner spRegion, spDistrict, spWard, spVillage; + Spinner spPovertyStatus, spFamilyType, spConfirmationType; + Spinner spApprovalSMS, spLanguageSMS; + + Button btnNext; + + int familyId = 0; + + ClientAndroidInterface ca; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); setContentView(R.layout.activity_family); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; + setTitle(getApplicationContext().getString(R.string.AddNewFamily)); + ca = new ClientAndroidInterface(this); + + 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); + + Intent intent = getIntent(); + if (intent != null && intent.hasExtra("familyId")){ + familyId = intent.getIntExtra("familyId", 0); + } + + try { + loadRegions(); + getPovertyStatus(); + getConfirmationTypes(); + getFamilyTypes(); + getApprovalOfSMS(); + getLanguageOfSMS(); + } catch (JSONException e) { + throw new RuntimeException(e); + } + canSaveFamily(); + + spRegion.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + JSONObject selectedRegion = (JSONObject) spRegion.getSelectedItem(); + try { + String regionId = selectedRegion.getString("LocationId"); + if(regionId.isEmpty()){ + spDistrict.setAdapter(null); + spWard.setAdapter(null); + spVillage.setAdapter(null); + } else{ + loadDistricts(Integer.parseInt(regionId)); + } + canSaveFamily(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onNothingSelected(AdapterView parent) {} + }); + + spDistrict.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + JSONObject district = (JSONObject) spDistrict.getSelectedItem(); + canSaveFamily(); + try { + String districtId = district.getString("LocationId"); + if (districtId.isEmpty()){ + spWard.setAdapter(null); + spVillage.setAdapter(null); + } else { + loadWards(Integer.parseInt(districtId)); + } + canSaveFamily(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onNothingSelected(AdapterView parent) {} + }); + + spWard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + JSONObject ward = (JSONObject) spWard.getSelectedItem(); + canSaveFamily(); + try { + String wardId = ward.getString("LocationId"); + if(wardId.isEmpty()){ + spVillage.setAdapter(null); + } else { + loadVillages(Integer.parseInt(wardId)); + } + canSaveFamily(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onNothingSelected(AdapterView parent) {} + }); + + spVillage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + canSaveFamily(); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } }); + btnNext.setOnClickListener(v -> saveFamily()); + } + + private void loadRegions() throws JSONException { + String regions = ca.getRegions(); + JSONArray regionsArray = new JSONArray(regions); + JSONObject emptyItem = new JSONObject(); + emptyItem.put("LocationId", ""); + emptyItem.put("LocationName", getApplicationContext().getResources().getString(R.string.SelectRegion)); + JSONArray finalRegions = addFirst(regionsArray, emptyItem); + JSONSpinnerAdapter adapter = + new JSONSpinnerAdapter(this, finalRegions, "LocationName"); + spRegion.setAdapter(adapter); + } + + private void loadDistricts(int regionId) throws JSONException { + String districts = ca.getDistricts(regionId); + JSONArray districtArray = new JSONArray(districts); + JSONObject emptyItem = new JSONObject(); + emptyItem.put("LocationId", ""); + emptyItem.put("LocationName", getApplicationContext().getResources().getString(R.string.SelectDistrict)); + JSONArray finalDistricts = addFirst(districtArray, emptyItem); + JSONSpinnerAdapter adapter = new JSONSpinnerAdapter(this, finalDistricts, "LocationName"); + spDistrict.setAdapter(adapter); + } + + private void loadWards(int districtId) throws JSONException { + String wards = ca.getWards(districtId); + JSONArray wardsArray = new JSONArray(wards); + JSONObject emptyObject = new JSONObject(); + emptyObject.put("LocationId", ""); + emptyObject.put("LocationName", getApplicationContext().getResources().getString(R.string.SelectWard)); + JSONArray finalWards = addFirst(wardsArray, emptyObject); + JSONSpinnerAdapter adapter = new JSONSpinnerAdapter(this, finalWards, "LocationName"); + spWard.setAdapter(adapter); + } + + private void loadVillages(int wardId) throws JSONException { + String villages = ca.getVillages(wardId); + JSONArray villagesArray = new JSONArray(villages); + JSONObject emptyObject = new JSONObject(); + emptyObject.put("LocationId", ""); + emptyObject.put("LocationName", getApplicationContext().getResources().getString(R.string.SelectVillage)); + JSONArray finalVillages = addFirst(villagesArray, emptyObject); + JSONSpinnerAdapter adapter = new JSONSpinnerAdapter(this, finalVillages, "LocationName"); + spVillage.setAdapter(adapter); + } + + private void saveFamily() { + + JSONObject selectedVillage = + (JSONObject) spVillage.getSelectedItem(); + JSONObject selectedPovertyStatus = + (JSONObject) spPovertyStatus.getSelectedItem(); + JSONObject selectedConfirmationType = + (JSONObject) spConfirmationType.getSelectedItem(); + JSONObject selectedApprovalSMS = + (JSONObject) spApprovalSMS.getSelectedItem(); + JSONObject selectedGroupType = + (JSONObject) spFamilyType.getSelectedItem(); + + try { + String locationId = selectedVillage.getString("LocationId"); + String povertyStatus = selectedPovertyStatus.getString("key"); + String confirmationCode = selectedConfirmationType.getString("ConfirmationTypeCode"); + String approvalOfSMS = selectedApprovalSMS.getString("key"); + String familyTypeCode = selectedGroupType.getString("FamilyTypeCode"); + + } catch (JSONException e) { + throw new RuntimeException(e); + } + +// Toast.makeText(this, "Family Saved", Toast.LENGTH_SHORT).show(); +// +// Intent intent = new Intent(this, InsureeActivity.class); +// startActivity(intent); + } + + private void canSaveFamily() { + + try { + JSONObject selectedVillage = + (JSONObject) spVillage.getSelectedItem(); + if(spVillage.getSelectedItem() == null || selectedVillage.getString("LocationId").isEmpty()){ + btnNext.setEnabled(false); + } else { + btnNext.setEnabled(true); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private void getPovertyStatus() throws JSONException { + String yesNoString = ca.getYesNo(); + JSONArray yesNoArray = new JSONArray(yesNoString); + + JSONObject hint = new JSONObject(); + hint.put("value", getString(R.string.SelectPovertyStatus)); + hint.put("key", ""); + + JSONArray finalYesNoArray = addFirst(yesNoArray, hint); + JSONSpinnerAdapter adapter = + new JSONSpinnerAdapter(this, finalYesNoArray, "value"); + + spPovertyStatus.setAdapter(adapter); + } + + private void getConfirmationTypes() throws JSONException { + String textLanguage = "ConfirmationType"; + String confirmationString = ca.getConfirmationTypes(); + JSONArray confirmationArray = new JSONArray(confirmationString); + + JSONObject hint = new JSONObject(); + hint.put("ConfirmationTypeCode", ""); + hint.put(textLanguage, getString(R.string.SelectConfirmationType)); + + JSONArray finalConfirmationArray = addFirst(confirmationArray, hint); + + JSONSpinnerAdapter adapter = + new JSONSpinnerAdapter(this, finalConfirmationArray, "ConfirmationType"); + spConfirmationType.setAdapter(adapter); } + + private void getFamilyTypes() throws JSONException { + String textLanguage = "FamilyType"; + String familyTypesString = ca.getGroupTypes(); + JSONArray familyTypesArray = new JSONArray(familyTypesString); + + JSONObject hint = new JSONObject(); + hint.put("FamilyTypeCode", ""); + hint.put(textLanguage, getString(R.string.SelectFamilyType)); + + JSONArray finaFamilyTypeArray = addFirst(familyTypesArray, hint); + JSONSpinnerAdapter adapter = + new JSONSpinnerAdapter(this, finaFamilyTypeArray, "FamilyType"); + spFamilyType.setAdapter(adapter); + } + + private void getApprovalOfSMS() throws JSONException { + String approvalString = ca.getApprovalOfSMS(); + JSONArray approvalArray = new JSONArray(approvalString); + + JSONObject hint = new JSONObject(); + hint.put("value", ""); + hint.put("key", getString(R.string.approvalOfSMS)); + + JSONArray finalApprovalArray = addFirst(approvalArray, hint); + JSONSpinnerAdapter adapter = + new JSONSpinnerAdapter(this, finalApprovalArray, "key"); + spApprovalSMS.setAdapter(adapter); + } + + private void getLanguageOfSMS() throws JSONException { + String textLanguage = "LanguageName"; + String languagesString = ca.getLanguagesOfSMS(); + JSONArray languagesArray = new JSONArray(languagesString); + + JSONObject hint = new JSONObject(); + hint.put("LanguageCode", ""); + hint.put(textLanguage, getString(R.string.languageOfSMS)); + + JSONArray finalLanguagesArray = addFirst(languagesArray, hint); + + JSONSpinnerAdapter adapter = + new JSONSpinnerAdapter(this, finalLanguagesArray, "LanguageName"); + spLanguageSMS.setAdapter(adapter); + } + + public JSONArray addFirst(JSONArray array, JSONObject object) throws JSONException { + JSONArray newArray = new JSONArray(); + newArray.put(object); + for (int i = 0; i < array.length(); i++) { + newArray.put(array.get(i)); + } + return newArray; + } + } \ No newline at end of file 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/MainActivity.java b/app/src/main/java/org/openimis/imispolicies/MainActivity.java index 0df6a1af..0c86eae9 100644 --- a/app/src/main/java/org/openimis/imispolicies/MainActivity.java +++ b/app/src/main/java/org/openimis/imispolicies/MainActivity.java @@ -847,7 +847,7 @@ protected void onPostExecute(Throwable exception) { return; } if (exception instanceof UserNotAuthenticatedException) { - new ClientAndroidInterface(context).forceLoginDialogBox(() -> restart(context)); + new ClientAndroidInterface(context).forceLoginDialogBox(() -> startDownloading()); return; } restart(context); @@ -858,6 +858,10 @@ private void restart(@NonNull Activity activity) { activity.startActivity(refresh); activity.finish(); } + + private void startDownloading(){ + new MasterDataAsync(activity.get()).execute(); + } } public static class MasterDataLocalAsync extends AsyncTask { 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/spinner_background.xml b/app/src/main/res/drawable/spinner_background.xml new file mode 100644 index 00000000..98021e20 --- /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..edc20a6c --- /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_family.xml b/app/src/main/res/layout/activity_family.xml index 5238d1c6..5baba90f 100644 --- a/app/src/main/res/layout/activity_family.xml +++ b/app/src/main/res/layout/activity_family.xml @@ -1,10 +1,151 @@ - + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog.xml b/app/src/main/res/layout/dialog.xml index 0a732105..9da89831 100644 --- a/app/src/main/res/layout/dialog.xml +++ b/app/src/main/res/layout/dialog.xml @@ -16,7 +16,10 @@ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cc3476f1..9ebc2223 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -20,6 +20,7 @@ #b66200 #dcdcdc #737373 + #B1B1B1 #f4f4f4 #0032d6 #ff000d diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 4b192b8d..42bf4561 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ -