diff --git a/opensrp-chw-core/build.gradle b/opensrp-chw-core/build.gradle index 6ceb7ba1ec..21711e4a02 100644 --- a/opensrp-chw-core/build.gradle +++ b/opensrp-chw-core/build.gradle @@ -143,7 +143,7 @@ dependencies { exclude group: 'xpp3', module: 'xpp3' } - api('org.smartregister:opensrp-client-native-form:1.14.5.5-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-native-form:1.14.5.5.2-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'com.android.support', module: 'cardview-v7' @@ -348,4 +348,4 @@ task javadoc(type: Javadoc) { source = files([mainSrc]) classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) classpath += configurations.compile -} \ No newline at end of file +} diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java index 843c3bfe6f..0580d6f3ac 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java @@ -13,6 +13,8 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.vijay.jsonwizard.domain.Form; + import org.jeasy.rules.api.Rules; import org.joda.time.LocalDate; import org.joda.time.Months; @@ -109,9 +111,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } } + public Form getForm(){ + Form form = new Form(); + form.setActionBarBackground(R.color.family_actionbar); + form.setWizard(false); + return form; + } + public void startFormActivity(JSONObject formJson) { - startActivityForResult(CoreJsonFormUtils.getJsonIntent(this, formJson, - Utils.metadata().familyMemberFormActivity), JsonFormUtils.REQUEST_CODE_GET_JSON); + startActivityForResult( + CoreJsonFormUtils.getJsonIntent(this, formJson,Utils.metadata().familyMemberFormActivity, getForm()), + JsonFormUtils.REQUEST_CODE_GET_JSON); } // to chw diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildProfileActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildProfileActivity.java index 4c8d5b97a2..08cc5cafc8 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildProfileActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildProfileActivity.java @@ -28,6 +28,7 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.appbar.AppBarLayout; +import com.vijay.jsonwizard.domain.Form; import org.apache.commons.lang3.tuple.Triple; import org.jetbrains.annotations.NotNull; @@ -323,10 +324,18 @@ public Context getContext() { return this; } + public Form getForm(){ + Form form = new Form(); + form.setActionBarBackground(R.color.family_actionbar); + form.setWizard(false); + return form; + } + @Override public void startFormActivity(JSONObject jsonForm) { - startActivityForResult(CoreJsonFormUtils.getJsonIntent(this, jsonForm, - Utils.metadata().familyMemberFormActivity), JsonFormUtils.REQUEST_CODE_GET_JSON); + startActivityForResult( + CoreJsonFormUtils.getJsonIntent(this, jsonForm,Utils.metadata().familyMemberFormActivity, getForm()), + JsonFormUtils.REQUEST_CODE_GET_JSON); } @Override diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java index c9ec7fe2d0..480d7ab5b9 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java @@ -99,17 +99,22 @@ public void startFormActivity(String formName, String entityId, String metaData) } } - @Override - public void startFormActivity(JSONObject jsonForm) { - Intent intent = new Intent(this, Utils.metadata().familyFormActivity); - intent.putExtra(Constants.JSON_FORM_EXTRA.JSON, jsonForm.toString()); - + public Form getFormConfig(){ Form form = new Form(); form.setName(getString(R.string.add_fam)); form.setActionBarBackground(R.color.family_actionbar); form.setNavigationBackground(R.color.family_navigation); form.setHomeAsUpIndicator(R.mipmap.ic_cross_white); - intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, form); + return form; + } + + @Override + public void startFormActivity(JSONObject jsonForm) { + Intent intent = new Intent(this, Utils.metadata().familyFormActivity); + intent.putExtra(Constants.JSON_FORM_EXTRA.JSON, jsonForm.toString()); + + + intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, getFormConfig()); startActivityForResult(intent, JsonFormUtils.REQUEST_CODE_GET_JSON); } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivity.java index da00022be2..9e7a34e7d2 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivity.java @@ -213,16 +213,19 @@ protected abstract BaseProfileContract.Presenter getFamilyOtherMemberActivityPre protected abstract CoreFamilyMemberFloatingMenu getFamilyMemberFloatingMenu(); + public Form getForm(){ + Form form = new Form(); + form.setActionBarBackground(R.color.family_actionbar); + form.setWizard(false); + return form; + } + public void startFormActivity(JSONObject jsonForm) { Intent intent = new Intent(this, Utils.metadata().familyMemberFormActivity); intent.putExtra(Constants.JSON_FORM_EXTRA.JSON, jsonForm.toString()); - - Form form = new Form(); - form.setActionBarBackground(R.color.family_actionbar); - form.setWizard(false); - intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, form); + intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, getForm()); startActivityForResult(intent, JsonFormUtils.REQUEST_CODE_GET_JSON); } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivity.java index e6d2c22615..707f47e1cd 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivity.java @@ -18,6 +18,9 @@ import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; +import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.domain.Form; + import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; import org.json.JSONObject; @@ -278,6 +281,23 @@ public void updateHasPhone(boolean hasPhone) { } } + public Form getFormConfig(){ + Form form = new Form(); + form.setActionBarBackground(R.color.family_actionbar); + form.setWizard(false); + return form; + } + + @Override + public void startFormActivity(JSONObject jsonForm) { + Intent intent = new Intent(this, Utils.metadata().familyMemberFormActivity); + intent.putExtra(Constants.JSON_FORM_EXTRA.JSON, jsonForm.toString()); + + intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, getFormConfig()); + + startActivityForResult(intent, JsonFormUtils.REQUEST_CODE_GET_JSON); + } + @Override protected void initializePresenter() { familyBaseEntityId = getIntent().getStringExtra(Constants.INTENT_KEY.FAMILY_BASE_ENTITY_ID); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java index c27ac79f7f..cc93e824c9 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java @@ -7,13 +7,20 @@ import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.domain.Form; + import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; +import org.smartregister.chw.core.R; import org.smartregister.chw.core.custom_views.NavigationMenu; import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.family.activity.BaseFamilyRegisterActivity; import org.smartregister.family.model.BaseFamilyRegisterModel; import org.smartregister.family.presenter.BaseFamilyRegisterPresenter; +import org.smartregister.family.util.Constants; import org.smartregister.family.util.JsonFormUtils; +import org.smartregister.family.util.Utils; import org.smartregister.view.fragment.BaseRegisterFragment; public abstract class CoreFamilyRegisterActivity extends BaseFamilyRegisterActivity { @@ -54,6 +61,27 @@ protected void onResumption() { } } + public Form getFormConfig(){ + Form form = new Form(); + form.setName(getString(R.string.add_fam)); + form.setActionBarBackground(R.color.family_actionbar); + form.setNavigationBackground(R.color.family_navigation); + form.setHomeAsUpIndicator(R.mipmap.ic_cross_white); + form.setPreviousLabel(getResources().getString(R.string.back)); + return form; + } + + @Override + public void startFormActivity(JSONObject jsonForm) { + Intent intent = new Intent(this, Utils.metadata().familyFormActivity); + intent.putExtra(Constants.JSON_FORM_EXTRA.JSON, jsonForm.toString()); + + + intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, getFormConfig()); + + startActivityForResult(intent, JsonFormUtils.REQUEST_CODE_GET_JSON); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivity.java index 9ccb3b797b..f94f5ac3f1 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivity.java @@ -13,6 +13,8 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.vijay.jsonwizard.domain.Form; + import org.json.JSONObject; import org.smartregister.chw.anc.domain.MemberObject; import org.smartregister.chw.anc.util.NCUtils; @@ -101,10 +103,18 @@ protected static CommonPersonObjectClient getClientDetailsByBaseEntityID(@NonNul return getCommonPersonObjectClient(baseEntityId); } + public Form getForm(){ + Form form = new Form(); + form.setActionBarBackground(R.color.family_actionbar); + form.setWizard(false); + return form; + } + @Override public void startFormActivity(JSONObject formJson) { - startActivityForResult(CoreJsonFormUtils.getJsonIntent(this, formJson, - org.smartregister.family.util.Utils.metadata().familyMemberFormActivity), JsonFormUtils.REQUEST_CODE_GET_JSON); + startActivityForResult( + CoreJsonFormUtils.getJsonIntent(this, formJson,org.smartregister.family.util.Utils.metadata().familyMemberFormActivity, getForm()), + JsonFormUtils.REQUEST_CODE_GET_JSON); } protected List getChildren(MemberObject memberObject) { diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java index 4b8a4cc028..4e48f3bc2b 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java @@ -9,6 +9,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.drawerlayout.widget.DrawerLayout; import androidx.recyclerview.widget.RecyclerView; import org.smartregister.chw.core.R; @@ -27,12 +28,18 @@ public class NavigationAdapter extends RecyclerView.Adapter registeredActivities; + private DrawerLayout drawerLayout; public NavigationAdapter(List navigationOptions, Activity context, Map registeredActivities) { + this(navigationOptions, context, registeredActivities, null); + } + + public NavigationAdapter(List navigationOptions, Activity context, Map registeredActivities, DrawerLayout drawerLayout) { this.navigationOptionList = navigationOptions; this.context = context; this.onClickListener = new NavigationListener(context, this); this.registeredActivities = registeredActivities; + this.drawerLayout = drawerLayout; } public String getSelectedView() { @@ -59,17 +66,28 @@ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { NavigationOption model = navigationOptionList.get(position); holder.tvName.setText(context.getResources().getText(model.getTitleID())); - holder.tvCount.setText(String.format(Locale.getDefault(), "%d", model.getRegisterCount())); + if (model.hasRegisterCount()) { + holder.tvCount.setText(String.format(Locale.getDefault(), "%d", model.getRegisterCount())); + } else { + holder.tvCount.setText(null); + } holder.ivIcon.setImageResource(model.getResourceID()); holder.getView().setTag(model.getMenuTitle()); - if (selectedView != null && selectedView.equals(model.getMenuTitle())) { + if (selectedView != null && selectedView.equals(model.getMenuTitle()) && model.getResourceID() == model.getResourceActiveID()) { + holder.itemView.setBackgroundColor(context.getResources().getColor(R.color.navigation_item_selected)); + holder.tvCount.setTextColor(context.getResources().getColor(R.color.navigation_item_unselected)); + holder.tvName.setTextColor(context.getResources().getColor(R.color.navigation_item_unselected)); + holder.ivIcon.setImageResource(model.getResourceID()); + } else if (selectedView != null && selectedView.equals(model.getMenuTitle())) { + holder.itemView.setBackgroundColor(context.getResources().getColor(android.R.color.transparent)); holder.tvCount.setTextColor(context.getResources().getColor(R.color.navigation_item_selected)); holder.tvName.setTextColor(context.getResources().getColor(R.color.navigation_item_selected)); holder.ivIcon.setImageResource(model.getResourceActiveID()); } else { + holder.itemView.setBackgroundColor(context.getResources().getColor(android.R.color.transparent)); holder.tvCount.setTextColor(context.getResources().getColor(R.color.navigation_item_unselected)); holder.tvName.setTextColor(context.getResources().getColor(R.color.navigation_item_unselected)); holder.ivIcon.setImageResource(model.getResourceID()); @@ -98,7 +116,12 @@ private MyViewHolder(View view) { ivIcon = view.findViewById(R.id.ivIcon); if (onClickListener != null) { - view.setOnClickListener(onClickListener); + view.setOnClickListener(v -> { + if (drawerLayout != null) { + drawerLayout.closeDrawers(); + } + onClickListener.onClick(v); + }); } myView = view; diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/FamilyFloatingMenu.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/FamilyFloatingMenu.java index 1ca91f6083..57d589ade3 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/FamilyFloatingMenu.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/FamilyFloatingMenu.java @@ -81,7 +81,7 @@ public void animateFAB() { activityMain.setBackgroundResource(R.color.transparent); fab.startAnimation(rotateBack); - fab.setImageResource(R.drawable.ic_edit_white); + fab.setImageResource(R.drawable.family_floating_fab_icon); callLayout.startAnimation(fabClose); addNewMember.startAnimation(fabClose); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java index ee89067d1e..c25de0c662 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java @@ -2,8 +2,11 @@ import android.Manifest; import android.app.Activity; +import android.app.Dialog; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; +import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -245,7 +248,7 @@ private void registerServiceActivity(Activity activity) { View rlIconServiceReport = rootView.findViewById(R.id.rlServiceReport); rlIconServiceReport.setVisibility(View.VISIBLE); rlIconServiceReport.setOnClickListener(view -> { - activity.startActivity( menuFlavor.getHIA2ReportActivityIntent(activity)); + activity.startActivity(menuFlavor.getHIA2ReportActivityIntent(activity)); }); } } @@ -286,22 +289,36 @@ private void registerDrawer(Activity parentActivity) { private void registerNavigation(Activity parentActivity) { if (recyclerView != null) { + RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(parentActivity); + recyclerView.setLayoutManager(mLayoutManager); + recyclerView.setItemAnimator(new DefaultItemAnimator()); List navigationOptions = mPresenter.getOptions(); if (navigationAdapter == null) { - navigationAdapter = new NavigationAdapter(navigationOptions, parentActivity, registeredActivities); + navigationAdapter = new NavigationAdapter(navigationOptions, parentActivity, registeredActivities, drawer); + recyclerView.setAdapter(navigationAdapter); + }else { + NavigationAdapter previous = navigationAdapter; + navigationAdapter = new NavigationAdapter(navigationOptions, parentActivity, registeredActivities, drawer); + recyclerView.swapAdapter(navigationAdapter, true); + navigationAdapter.setSelectedView(previous.getSelectedView()); } - - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(parentActivity); - recyclerView.setLayoutManager(mLayoutManager); - recyclerView.setItemAnimator(new DefaultItemAnimator()); - recyclerView.setAdapter(navigationAdapter); } } private void registerLogout(final Activity parentActivity) { mPresenter.displayCurrentUser(); - tvLogout.setOnClickListener(v -> logout(parentActivity)); + AlertDialog logOutDialog = menuFlavor.doLogOutDialog(parentActivity); + tvLogout.setOnClickListener(v -> { +// drawer.closeDrawers(); + if (logOutDialog != null) { + logOutDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Log Out", (dialog, which) -> logout(parentActivity)); + logOutDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", (dialog, which) -> dialog.dismiss()); + logOutDialog.show(); + }else { + logout(parentActivity); + } + }); } private void registerSync(final Activity parentActivity) { @@ -339,7 +356,7 @@ private void registerLanguageSwitcher(final Activity context) { } x++; } - if(menuFlavor.hasMultipleLanguages()){ + if (menuFlavor.hasMultipleLanguages()) { rlIconLang.setOnClickListener(v -> { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(context.getString(R.string.choose_language)); @@ -360,8 +377,7 @@ private void registerLanguageSwitcher(final Activity context) { AlertDialog dialog = builder.create(); dialog.show(); }); - } - else { + } else { rlIconLang.setOnClickListener(null); } } @@ -485,8 +501,8 @@ public DrawerLayout getDrawer() { return drawer; } - public static String getChildNavigationCountString(){ - return menuFlavor.childNavigationMenuCountString(); + public static String getChildNavigationCountString() { + return menuFlavor.childNavigationMenuCountString(); } public interface Flavour { @@ -509,5 +525,9 @@ public interface Flavour { String childNavigationMenuCountString(); Intent getHIA2ReportActivityIntent(Activity activity); + + default AlertDialog doLogOutDialog(Activity activity){ + return null; + } } } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/listener/NavigationListener.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/listener/NavigationListener.java index 93032d8d48..68fd1a8f01 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/listener/NavigationListener.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/listener/NavigationListener.java @@ -5,10 +5,14 @@ import android.view.View; import android.widget.Toast; +import androidx.annotation.NonNull; + +import org.jetbrains.annotations.NotNull; import org.smartregister.chw.core.R; import org.smartregister.chw.core.adapter.NavigationAdapter; import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.util.Utils; +import org.smartregister.view.activity.BaseRegisterActivity; public class NavigationListener implements View.OnClickListener { @@ -66,6 +70,20 @@ public void onClick(View v) { case CoreConstants.DrawerMenu.UPDATES: startRegisterActivity(getActivity(CoreConstants.REGISTERED_ACTIVITIES.UPDATES_REGISTER_ACTIVITY)); break; + case CoreConstants.DrawerMenu.REPORTS: + startRegisterActivity(getActivity(CoreConstants.REGISTERED_ACTIVITIES.REPORTS_ACTIVITY)); + break; + case CoreConstants.DrawerMenu.ADD_NEW_FAMILY: + Class newFamilyRegisterClass = getActivity(CoreConstants.REGISTERED_ACTIVITIES.ADD_NEW_FAMILY); + if (newFamilyRegisterClass.isInstance(activity)) { + BaseRegisterActivity baseRegisterActivity = (BaseRegisterActivity) activity; + baseRegisterActivity.startRegistration(); + } else { + Intent intent = new Intent(activity, newFamilyRegisterClass); + intent.putExtra(CoreConstants.ACTIVITY_PAYLOAD.ACTION, CoreConstants.ACTION.START_REGISTRATION); + startRegisterActivity(intent, false); + } + break; default: Utils.showShortToast(activity.getApplicationContext(), "Unspecified navigation action"); break; @@ -74,11 +92,34 @@ public void onClick(View v) { } } - public void startRegisterActivity(Class registerClass) { + private boolean isClassCurrentActivity(Class klass){ + return klass.getName().equals(activity.getClass().getName()); + } + + private boolean isIntentForCurrentActivity(Intent intent) { + return intent.getComponent().getClassName().equals(activity.getClass().getName()); + } + + public void startRegisterActivity(@NotNull @NonNull Class registerClass) { + startRegisterActivity(registerClass, true); + } + + public void startRegisterActivity(@NotNull @NonNull Class registerClass, boolean finish) { if (registerClass != null) { Intent intent = new Intent(activity, registerClass); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent); + if (!isClassCurrentActivity(registerClass) && finish) { + activity.overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up); + activity.finish(); + } + } + } + + public void startRegisterActivity(@NonNull @NotNull Intent intent, boolean finish) { + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + activity.startActivity(intent); + if (!isIntentForCurrentActivity(intent) && finish) { activity.overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up); activity.finish(); } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/NavigationOption.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/NavigationOption.java index ea302701c2..add77ab3dd 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/NavigationOption.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/NavigationOption.java @@ -56,4 +56,8 @@ public void setRegisterCount(long registerCount) { RegisterCount = registerCount; } + public boolean hasRegisterCount() { + return this.RegisterCount >= 0; + } + } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/NavigationPresenter.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/NavigationPresenter.java index 918cc9865a..cbae37357e 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/NavigationPresenter.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/NavigationPresenter.java @@ -82,20 +82,25 @@ public void refreshNavigationCount(final Activity activity) { int x = 0; while (x < mModel.getNavigationItems().size()) { - final int finalX = x; - mInteractor.getRegisterCount(tableMap.get(mModel.getNavigationItems().get(x).getMenuTitle()), new NavigationContract.InteractorCallback() { - @Override - public void onResult(Integer result) { - mModel.getNavigationItems().get(finalX).setRegisterCount(result); - getNavigationView().refreshCount(); - } - - @Override - public void onError(Exception e) { - // getNavigationView().displayToast(activity, "Error retrieving count for " + tableMap.get(mModel.getNavigationItems().get(finalX).getMenuTitle())); - Timber.e("Error retrieving count for %s", tableMap.get(mModel.getNavigationItems().get(finalX).getMenuTitle())); - } - }); + final NavigationOption navigationOption = mModel.getNavigationItems().get(x); + final String navTitle = navigationOption.getMenuTitle(); + if (tableMap.containsKey(navTitle)) { + mInteractor.getRegisterCount(tableMap.get(navTitle), new NavigationContract.InteractorCallback() { + @Override + public void onResult(Integer result) { + navigationOption.setRegisterCount(result); + getNavigationView().refreshCount(); + } + + @Override + public void onError(Exception e) { + // getNavigationView().displayToast(activity, "Error retrieving count for " + tableMap.get(mModel.getNavigationItems().get(finalX).getMenuTitle())); + Timber.e("Error retrieving count for %s", tableMap.get(navTitle)); + } + }); + }else if (navigationOption.hasRegisterCount()){ + Timber.e("Error retrieving count for %s, table not defined in 'tableMap'", navTitle); + } x++; } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreConstants.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreConstants.java index f55c9167f6..72a120bd1b 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreConstants.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreConstants.java @@ -725,6 +725,8 @@ public static final class DrawerMenu { public static final String REFERRALS = "Referrals"; public static final String STOCK_USAGE_REPORT = "StockUsageItemModel usage report"; public static final String UPDATES = "Updates"; + public static final String REPORTS = "Reports"; + public static final String ADD_NEW_FAMILY = "Add New Family"; } public static final class RULE_FILE { @@ -952,6 +954,8 @@ public static final class REGISTERED_ACTIVITIES { public static final String FP_REGISTER_ACTIVITY = "FP_REGISTER_ACTIVITY"; public static final String ALL_CLIENTS_REGISTERED_ACTIVITY = "ALL_CLIENTS"; public static final String UPDATES_REGISTER_ACTIVITY = "UPDATES_REGISTER_ACTIVITY"; + public static final String REPORTS_ACTIVITY = "REPORTS_ACTIVITY"; + public static final String ADD_NEW_FAMILY = "ADD_NEW_FAMILY"; } public static final class BUSINESS_STATUS { diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java index e81bed6462..8f369b081e 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java @@ -76,12 +76,16 @@ public class CoreJsonFormUtils extends org.smartregister.family.util.JsonFormUti private static final String LOCATION_UUIDS = "location_uuids"; public static Intent getJsonIntent(Context context, JSONObject jsonForm, Class activityClass) { - Intent intent = new Intent(context, activityClass); - intent.putExtra(Constants.JSON_FORM_EXTRA.JSON, jsonForm.toString()); Form form = new Form(); form.setActionBarBackground(R.color.family_actionbar); form.setWizard(false); - intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, form); + return getJsonIntent(context, jsonForm, activityClass, form); + } + + public static Intent getJsonIntent(Context context, JSONObject jsonForm, Class activityClass, Form formConfig){ + Intent intent = new Intent(context, activityClass); + intent.putExtra(Constants.JSON_FORM_EXTRA.JSON, jsonForm.toString()); + intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, formConfig); return intent; } diff --git a/opensrp-chw-core/src/main/res/layout-w900dp/activity_base.xml b/opensrp-chw-core/src/main/res/layout-w900dp/activity_base.xml index bf68faab4d..59f3dc999e 100644 --- a/opensrp-chw-core/src/main/res/layout-w900dp/activity_base.xml +++ b/opensrp-chw-core/src/main/res/layout-w900dp/activity_base.xml @@ -8,400 +8,6 @@ android:fitsSystemWindows="true" tools:openDrawer="start"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/opensrp-chw-core/src/main/res/layout-w900dp/navigation_item.xml b/opensrp-chw-core/src/main/res/layout-w900dp/navigation_item.xml index 60a262235a..7c126ac128 100644 --- a/opensrp-chw-core/src/main/res/layout-w900dp/navigation_item.xml +++ b/opensrp-chw-core/src/main/res/layout-w900dp/navigation_item.xml @@ -11,6 +11,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" + app:tint="@color/navigation_item_icon_tint" app:srcCompat="@drawable/child_boy_infant" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/opensrp-chw-core/src/main/res/layout/activity_base.xml b/opensrp-chw-core/src/main/res/layout/activity_base.xml index 3ca25b3e62..9cc4b85ea5 100644 --- a/opensrp-chw-core/src/main/res/layout/activity_base.xml +++ b/opensrp-chw-core/src/main/res/layout/activity_base.xml @@ -1,6 +1,5 @@ + android:layout_height="match_parent"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/opensrp-chw-core/src/main/res/layout/custom_vaccine_name_check.xml b/opensrp-chw-core/src/main/res/layout/custom_vaccine_name_check.xml index 18d2bb741c..1a120474fa 100644 --- a/opensrp-chw-core/src/main/res/layout/custom_vaccine_name_check.xml +++ b/opensrp-chw-core/src/main/res/layout/custom_vaccine_name_check.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" - android:checked="true" + android:checked="@bool/initial_vaccine_checked_state" android:clickable="true" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/opensrp-chw-core/src/main/res/layout/view_family_floating_menu.xml b/opensrp-chw-core/src/main/res/layout/view_family_floating_menu.xml index 28cbb4cb8d..8bbacd16a6 100644 --- a/opensrp-chw-core/src/main/res/layout/view_family_floating_menu.xml +++ b/opensrp-chw-core/src/main/res/layout/view_family_floating_menu.xml @@ -18,7 +18,7 @@ android:tint="@android:color/white" app:backgroundTint="@color/text_black" app:fabSize="normal" - app:srcCompat="@drawable/ic_edit_white" /> + app:srcCompat="@drawable/family_floating_fab_icon" /> + + true + diff --git a/opensrp-chw-core/src/main/res/values/colors.xml b/opensrp-chw-core/src/main/res/values/colors.xml index fa246924c5..cedf0b42de 100644 --- a/opensrp-chw-core/src/main/res/values/colors.xml +++ b/opensrp-chw-core/src/main/res/values/colors.xml @@ -8,6 +8,7 @@ #575757 #FCEEF5 + @color/transparent #81D4FA #FFFFFF diff --git a/opensrp-chw-core/src/main/res/values/drawables.xml b/opensrp-chw-core/src/main/res/values/drawables.xml new file mode 100644 index 0000000000..cbed20ea9b --- /dev/null +++ b/opensrp-chw-core/src/main/res/values/drawables.xml @@ -0,0 +1,4 @@ + + + @drawable/ic_edit_white + diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreChildRegisterActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreChildRegisterActivityTest.java new file mode 100644 index 0000000000..7d118fe157 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreChildRegisterActivityTest.java @@ -0,0 +1,96 @@ +package org.smartregister.chw.core.activity; + +import android.content.Intent; + +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.powermock.reflect.Whitebox; +import org.robolectric.Robolectric; +import org.robolectric.android.controller.ActivityController; +import org.robolectric.util.ReflectionHelpers; +import org.smartregister.Context; +import org.smartregister.CoreLibrary; +import org.smartregister.chw.core.BaseUnitTest; +import org.smartregister.chw.core.R; +import org.smartregister.chw.core.custom_views.NavigationMenu; +import org.smartregister.chw.core.fragment.CoreChildRegisterFragment; +import org.smartregister.chw.core.presenter.CoreChildRegisterPresenter; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +public class CoreChildRegisterActivityTest extends BaseUnitTest { + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + private CoreChildRegisterActivity activity; + private ActivityController controller; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + Context context = Context.getInstance(); + CoreLibrary.init(context); + + //Auto login by default + String password = "pwd"; + context.session().start(context.session().lengthInMilliseconds()); + context.configuration().getDrishtiApplication().setPassword(password); + context.session().setPassword(password); + + controller = Robolectric.buildActivity(CoreChildRegisterActivity.class, new Intent()); + activity = controller.get(); + controller + .create() + .start(); + } + + @Test + public void testNavigationMenuInstanceNotNull() { + assertNotNull(ReflectionHelpers.getStaticField(NavigationMenu.class, "instance")); + } + + @Test + public void testPresenterIsInitialized() { + assertTrue(activity.presenter() instanceof CoreChildRegisterPresenter); + } + + @Test + public void testRegisterFragmentIsInitialized() { + assertTrue(Whitebox.getInternalState(activity, "mBaseFragment") instanceof CoreChildRegisterFragment); + } + + @Test + public void switchToBaseFragment() { + CoreChildRegisterActivity spyActivity = spy(activity); + doNothing().when(spyActivity).startActivity(any(Intent.class)); + doNothing().when(spyActivity).finish(); + spyActivity.switchToBaseFragment(); + verify(spyActivity).finish(); + ArgumentCaptor intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(spyActivity).startActivity(intentArgumentCaptor.capture()); + assertEquals(CoreFamilyRegisterActivity.class.getName(), intentArgumentCaptor.getValue().getComponent().getClassName()); + } + + @Test + public void openFamilyListView() { + activity.openFamilyListView(); + BottomNavigationView navigationView = Whitebox.getInternalState(activity, "bottomNavigationView"); + assertEquals(R.id.action_family, navigationView.getSelectedItemId()); + } + +} \ No newline at end of file