diff --git a/opensrp-bidan/src/main/AndroidManifest.xml b/opensrp-bidan/src/main/AndroidManifest.xml index 332ebdd..3c3c998 100644 --- a/opensrp-bidan/src/main/AndroidManifest.xml +++ b/opensrp-bidan/src/main/AndroidManifest.xml @@ -120,10 +120,32 @@ android:screenOrientation="landscape" android:theme="@style/AppTheme" /> - + android:theme="@style/AppThemeNoActionBarAndTitle" + android:windowSoftInputMode="adjustResize" /> + + + + + \ No newline at end of file diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/BidanHomeActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/BidanHomeActivity.java index 0f557fe..5d81aa7 100644 --- a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/BidanHomeActivity.java +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/BidanHomeActivity.java @@ -1,384 +1,167 @@ package org.smartregister.bidan.activity; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.ActivityInfo; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AlertDialog; -import android.util.Log; -import android.view.inputmethod.InputMethodManager; -import android.widget.LinearLayout; - -import org.apache.commons.lang3.StringUtils; -import org.json.JSONObject; -import org.smartregister.adapter.SmartRegisterPaginatedAdapter; -//import org.smartregister.bidan.adapter.PathRegisterActivityPagerAdapter; -//import org.smartregister.bidan.fragment.AdvancedSearchFragment; -//import org.smartregister.bidan.fragment.ChildSmartRegisterFragment; -import org.smartregister.bidan.adapter.BidanRegisterActivityPagerAdapter; -import org.smartregister.bidan.fragment.BidanHomeFragment; -import org.smartregister.domain.FetchStatus; -import org.smartregister.domain.form.FormSubmission; -import org.smartregister.event.Event; -import org.smartregister.event.Listener; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; +import android.view.View; +import android.widget.TextView; + import org.smartregister.bidan.R; -import org.smartregister.bidan.fragment.BaseSmartRegisterFragment; -import org.smartregister.bidan.view.LocationPickerView; -import org.smartregister.provider.SmartRegisterClientsProvider; -import org.smartregister.repository.AllSharedPreferences; -import org.smartregister.service.FormSubmissionService; -import org.smartregister.service.ZiggyService; -import org.smartregister.util.FormUtils; -import org.smartregister.view.dialog.DialogOptionModel; +import org.smartregister.bidan.application.BidanApplication; +import org.smartregister.bidan.controller.NavigationControllerINA; +import org.smartregister.view.controller.ANMController; +import org.smartregister.view.controller.NavigationController; import org.smartregister.view.viewpager.OpenSRPViewPager; -import butterknife.Bind; -import butterknife.ButterKnife; -import util.JsonFormUtils; -import util.barcode.Barcode; -import util.barcode.BarcodeIntentIntegrator; -import util.barcode.BarcodeIntentResult; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; -import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS; +import butterknife.Bind; /** - * Created by Ahmed on 13-Oct-15. + * Created by sid-tech on 11/7/17. */ -public class BidanHomeActivity extends BaseRegisterActivity { - private static final String TAG = ChildSmartRegisterActivity.class.getCanonicalName(); + +public class BidanHomeActivity extends AppCompatActivity { @Bind(R.id.view_pager) protected OpenSRPViewPager mPager; - private FragmentPagerAdapter mPagerAdapter; - private static final int REQUEST_CODE_GET_JSON = 3432; - private int currentPage; - public static final int ADVANCED_SEARCH_POSITION = 1; - private ProgressDialog progressDialog; - - private android.support.v4.app.Fragment mBaseFragment = null; - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - ButterKnife.bind(this); - - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - - mBaseFragment = new BidanHomeFragment(); -// Fragment[] otherFragments = {new AdvancedSearchFragment()}; - Fragment[] otherFragments = {}; - - // Instantiate a ViewPager and a PagerAdapter. - mPagerAdapter = new BidanRegisterActivityPagerAdapter(getSupportFragmentManager(), mBaseFragment, otherFragments); - mPager.setOffscreenPageLimit(otherFragments.length); - mPager.setAdapter(mPagerAdapter); - mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { - @Override - public void onPageSelected(int position) { - currentPage = position; - } - }); - - Event.ON_DATA_FETCHED.addListener(onDataFetchedListener); - initializeProgressDialog(); - } - @Override - protected void onDestroy() { - super.onDestroy(); - Event.ON_DATA_FETCHED.removeListener(onDataFetchedListener); - } - - @Override - protected SmartRegisterPaginatedAdapter adapter() { - return new SmartRegisterPaginatedAdapter(clientsProvider()); - } - - @Override - protected DefaultOptionsProvider getDefaultOptionsProvider() { - return null; - } + private MenuItem updateMenuItem; + private MenuItem remainingFormsToSyncMenuItem; + private TextView ecRegisterClientCountView; + private TextView kartuIbuANCRegisterClientCountView; + private TextView kartuIbuPNCRegisterClientCountView; + private TextView anakRegisterClientCountView; + private TextView kohortKbCountView; + protected NavigationController navigationController; + protected ANMController anmController; - @Override - protected void setupViews() { - } + SimpleDateFormat timer = new SimpleDateFormat("hh:mm:ss"); - @Override - protected void onResumption() { - final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - LinearLayout childregister = (LinearLayout) drawer.findViewById(R.id.child_register); - childregister.setBackgroundColor(getResources().getColor(R.color.tintcolor)); - } @Override - protected NavBarOptionsProvider getNavBarOptionsProvider() { - return null; - } + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - @Override - protected SmartRegisterClientsProvider clientsProvider() { - return null; - } + setContentView(R.layout.bidan_landing); + navigationController = new NavigationControllerINA(this, anmController, BidanApplication.getInstance().context()); - @Override - protected void onInitialization() { - } + String HomeStart = timer.format(new Date()); + Map Home = new HashMap(); + Home.put("start", HomeStart); +// FlurryAgent.logEvent("home_dashboard", Home, true); - @Override - public void startRegistration() { - } + setupViews(); - @Override - public void showFragmentDialog(DialogOptionModel dialogOptionModel, Object tag) { - try { - LoginActivity.setLanguage(); - } catch (Exception e) { - Log.e(getClass().getCanonicalName(), e.getMessage()); - } - super.showFragmentDialog(dialogOptionModel, tag); } - @Override - public void startFormActivity(String formName, String entityId, String metaData) { - try { -// if (mBaseFragment instanceof ChildSmartRegisterFragment) { -// LocationPickerView locationPickerView = ((ChildSmartRegisterFragment) mBaseFragment).getLocationPickerView(); -// String locationId = JsonFormUtils.getOpenMrsLocationId(context(), locationPickerView.getSelectedItem()); -// JsonFormUtils.startForm(this, context(), REQUEST_CODE_GET_JSON, formName, entityId, -// metaData, locationId); -// } - } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); - } + private void setupViews() { + findViewById(R.id.btn_kartu_ibu_register).setOnClickListener(onRegisterStartListener); + findViewById(R.id.btn_kartu_ibu_anc_register).setOnClickListener(onRegisterStartListener); + findViewById(R.id.btn_kartu_ibu_pnc_register).setOnClickListener(onRegisterStartListener); + findViewById(R.id.btn_anak_register).setOnClickListener(onRegisterStartListener); + findViewById(R.id.btn_kohort_kb_register).setOnClickListener(onRegisterStartListener); - } - public void startAdvancedSearch() { - try { - mPager.setCurrentItem(ADVANCED_SEARCH_POSITION, false); - } catch (Exception e) { - e.printStackTrace(); - } + findViewById(R.id.btn_reporting).setOnClickListener(onButtonsClickListener); +// findViewById(R.id.btn_videos).setOnClickListener(onButtonsClickListener); + ecRegisterClientCountView = (TextView) findViewById(R.id.txt_kartu_ibu_register_client_count); + kartuIbuANCRegisterClientCountView = (TextView) findViewById(R.id.txt_kartu_ibu_anc_register_client_count); + kartuIbuPNCRegisterClientCountView = (TextView) findViewById(R.id.txt_kartu_ibu_pnc_register_client_count); + anakRegisterClientCountView = (TextView) findViewById(R.id.txt_anak_client_count); + kohortKbCountView = (TextView) findViewById(R.id.txt_kohort_kb_register_count); } - public void updateAdvancedSearchFilterCount(int count) { -// AdvancedSearchFragment advancedSearchFragment = (AdvancedSearchFragment) findFragmentByPosition(ADVANCED_SEARCH_POSITION); -// if (advancedSearchFragment != null) { -// advancedSearchFragment.updateFilterCount(count); -// } - } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == REQUEST_CODE_GET_JSON) { - if (resultCode == RESULT_OK) { + // BaseActivity +// @Override +// protected int getContentView() { +// return R.layout.bidan_landing; +// } - String jsonString = data.getStringExtra("json"); - Log.d("JSONResult", jsonString); +// @Override +// protected int getDrawerLayoutId() { +// return R.id.drawer_layout; +// } +// +// @Override +// protected int getToolbarId() { +// return LocationSwitcherToolbar.TOOLBAR_ID; +// } - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - AllSharedPreferences allSharedPreferences = new AllSharedPreferences(preferences); - - JsonFormUtils.saveForm(this, context(), jsonString, allSharedPreferences.fetchRegisteredANM()); - } - } else if (requestCode == BarcodeIntentIntegrator.REQUEST_CODE && resultCode == RESULT_OK) { - BarcodeIntentResult res = BarcodeIntentIntegrator.parseActivityResult(requestCode, resultCode, data); - if (StringUtils.isNotBlank(res.getContents())) { - onQRCodeSucessfullyScanned(res.getContents()); - } else Log.i("", "NO RESULT FOR QR CODE"); - } - } +// @Override +// protected Class onBackActivity() { +// return null; +// } +// @Override - public void saveFormSubmission(String formSubmission, String id, String formName, JSONObject fieldOverrides) { - // save the form - try { - FormUtils formUtils = FormUtils.getInstance(getApplicationContext()); - FormSubmission submission = formUtils.generateFormSubmisionFromXMLString(id, formSubmission, formName, fieldOverrides); - - org.smartregister.Context context = context(); - ZiggyService ziggyService = context.ziggyService(); - ziggyService.saveForm(getParams(submission), submission.instance()); - - FormSubmissionService formSubmissionService = context.formSubmissionService(); - formSubmissionService.updateFTSsearch(submission); - - Log.v("we are here", "hhregister"); - //switch to forms list fragmentstregi - switchToBaseFragment(formSubmission); // Unnecessary!! passing on data - - } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); - } - } - - public void switchToBaseFragment(final String data) { - Log.v("we are here", "switchtobasegragment"); - final int prevPageIndex = currentPage; - runOnUiThread(new Runnable() { - @Override - public void run() { - mPager.setCurrentItem(0, false); - refreshList(data); - } - }); - } + protected void onPause() { + super.onPause(); +} @Override - public void onBackPressed() { - BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(currentPage); - if (registerFragment.onBackPressed()) { - return; - } - if (currentPage != 0) { - new AlertDialog.Builder(this, R.style.PathAlertDialog) - .setMessage(org.smartregister.bidan.R.string.form_back_confirm_dialog_message) - .setTitle(org.smartregister.bidan.R.string.form_back_confirm_dialog_title) - .setCancelable(false) - .setPositiveButton(org.smartregister.bidan.R.string.no_button_label, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - - } - }) - .setNegativeButton(org.smartregister.bidan.R.string.yes_button_label, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - switchToBaseFragment(null); - } - }) - .show(); - } else if (currentPage == 0) { - super.onBackPressed(); // allow back key only if we are - } - } - - public android.support.v4.app.Fragment findFragmentByPosition(int position) { - FragmentPagerAdapter fragmentPagerAdapter = mPagerAdapter; - return getSupportFragmentManager().findFragmentByTag("android:switcher:" + mPager.getId() + ":" + fragmentPagerAdapter.getItemId(position)); - } - - private boolean currentActivityIsShowingForm() { - return currentPage != 0; + protected void onResume() { + super.onResume(); } @Override - protected void onPause() { - super.onPause(); - } - - public void startQrCodeScanner() { - BarcodeIntentIntegrator integ = new BarcodeIntentIntegrator(this); - integ.addExtra(Barcode.SCAN_MODE, Barcode.QR_MODE); - integ.initiateScan(); - } - - public void filterSelection() { - if (currentPage != 0) { - switchToBaseFragment(null); - BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); -// if (registerFragment != null && registerFragment instanceof ChildSmartRegisterFragment) { -// ((ChildSmartRegisterFragment) registerFragment).triggerFilterSelection(); -// } - } + protected void onDestroy() { + super.onDestroy(); } - private void onQRCodeSucessfullyScanned(String qrCode) { - Log.i(getClass().getName(), "QR code: " + qrCode); - if (StringUtils.isNotBlank(qrCode)) { - filterList(qrCode.replace("-", "")); - } - } + private View.OnClickListener onRegisterStartListener = new View.OnClickListener() { - private final Listener onDataFetchedListener = new Listener() { @Override - public void onEvent(FetchStatus fetchStatus) { - refreshList(fetchStatus); - } - }; - - public void refreshList(final FetchStatus fetchStatus) { - if (Looper.myLooper() == Looper.getMainLooper()) { - BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); - if (registerFragment != null && fetchStatus.equals(FetchStatus.fetched)) { - registerFragment.refreshListView(); + public void onClick(View view) { + switch (view.getId()) { + case R.id.btn_kartu_ibu_register: + navigationController.startECSmartRegistry(); + break; + + case R.id.btn_kohort_kb_register: + navigationController.startFPSmartRegistry(); + break; + + case R.id.btn_kartu_ibu_anc_register: + navigationController.startANCSmartRegistry(); + break; + + case R.id.btn_anak_register: + navigationController.startChildSmartRegistry(); + break; + + case R.id.btn_kartu_ibu_pnc_register: + navigationController.startPNCSmartRegistry(); + break; } - } else { - Handler handler = new android.os.Handler(Looper.getMainLooper()); - handler.post(new Runnable() { - @Override - public void run() { - BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); - if (registerFragment != null && fetchStatus.equals(FetchStatus.fetched)) { - registerFragment.refreshListView(); - } - } - }); + String HomeEnd = timer.format(new Date()); + Map Home = new HashMap(); + Home.put("end", HomeEnd); +// FlurryAgent.logEvent("home_dashboard",Home, true); } + }; - } - - private void refreshList(String data) { - BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); - if (registerFragment != null && data != null) { - registerFragment.refreshListView(); - } - - } - - private void filterList(String filterString) { - BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); - if (registerFragment != null) { - registerFragment.openVaccineCard(filterString); - } - } - - public void hideKeyboard() { - InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); - inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), HIDE_NOT_ALWAYS); - } - - private void initializeProgressDialog() { - progressDialog = new ProgressDialog(this); - progressDialog.setCancelable(false); - progressDialog.setTitle(getString(R.string.saving_dialog_title)); - progressDialog.setMessage(getString(R.string.please_wait_message)); - } - - public void showProgressDialog(String title, String message) { - if (progressDialog != null) { - if (StringUtils.isNotBlank(title)) { - progressDialog.setTitle(title); - } + private View.OnClickListener onButtonsClickListener = new View.OnClickListener() { - if (StringUtils.isNotBlank(message)) { - progressDialog.setMessage(message); + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.btn_reporting: + navigationController.startReports(); + break; + +// case R.id.btn_videos: +// navigationController.startVideos(); +// break; } - - progressDialog.show(); } - } - - public void showProgressDialog() { - showProgressDialog(getString(R.string.saving_dialog_title), getString(R.string.please_wait_message)); - } + }; - public void hideProgressDialog() { - if (progressDialog != null) { - progressDialog.dismiss(); - } - } } diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/BidanLandingActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/BidanLandingActivity.java deleted file mode 100644 index 891effb..0000000 --- a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/BidanLandingActivity.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.smartregister.bidan.activity; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.view.MenuItem; -import android.widget.TextView; - -import org.smartregister.bidan.R; -import org.smartregister.bidan.toolbar.LocationSwitcherToolbar; -import org.smartregister.view.customcontrols.CustomFontTextView; - -/** - * Created by sid-tech on 11/7/17. - */ - -public class BidanLandingActivity extends AppCompatActivity { - - private MenuItem updateMenuItem; - private MenuItem remainingFormsToSyncMenuItem; - private TextView ecRegisterClientCountView; - private TextView kartuIbuANCRegisterClientCountView; - private TextView kartuIbuPNCRegisterClientCountView; - private TextView anakRegisterClientCountView; - private TextView kohortKbCountView; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.bidan_landing); - - ecRegisterClientCountView = (TextView) findViewById(R.id.txt_kartu_ibu_register_client_count); - kartuIbuANCRegisterClientCountView = (TextView) findViewById(R.id.txt_kartu_ibu_anc_register_client_count); - kartuIbuPNCRegisterClientCountView = (TextView) findViewById(R.id.txt_kartu_ibu_pnc_register_client_count); - anakRegisterClientCountView = (TextView) findViewById(R.id.txt_anak_client_count); - kohortKbCountView = (TextView) findViewById(R.id.txt_kohort_kb_register_count); - } - - @Override - protected void onPause() { - super.onPause(); - } - - // BaseActivity -// @Override -// protected int getContentView() { -// return R.layout.bidan_landing; -// } - -// @Override -// protected int getDrawerLayoutId() { -// return R.id.drawer_layout; -// } -// -// @Override -// protected int getToolbarId() { -// return LocationSwitcherToolbar.TOOLBAR_ID; -// } - -// @Override -// protected Class onBackActivity() { -// return null; -// } -// - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } - -} diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/LoginActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/LoginActivity.java index a86d630..53816c5 100644 --- a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/LoginActivity.java +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/LoginActivity.java @@ -45,7 +45,6 @@ import org.smartregister.domain.TimeStatus; import org.smartregister.event.Listener; //import org.smartregister.growthmonitoring.service.intent.ZScoreRefreshIntentService; -import org.smartregister.immunization.util.IMDatabaseUtils; import org.smartregister.bidan.R; import org.smartregister.bidan.service.intent.PullUniqueIdsIntentService; import org.smartregister.repository.AllSharedPreferences; @@ -55,7 +54,6 @@ import org.smartregister.view.BackgroundAction; import org.smartregister.view.LockingBackgroundTask; import org.smartregister.view.ProgressIndicator; -import org.smartregister.view.activity.SmartRegisterActivity; import java.io.IOException; import java.text.SimpleDateFormat; @@ -419,7 +417,7 @@ private void goToHome(boolean remote) { BidanApplication.setCrashlyticsUser(getOpenSRPContext()); // Intent intent = new Intent(this, ChildSmartRegisterActivity.class); // Intent intent = new Intent(this, BidanHomeActivity.class); - Intent intent = new Intent(this, BidanLandingActivity.class); + Intent intent = new Intent(this, BidanHomeActivity.class); intent.putExtra(BaseRegisterActivity.IS_REMOTE_LOGIN, remote); startActivity(intent); diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKBSmartRegisterActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKBSmartRegisterActivity.java new file mode 100644 index 0000000..6281779 --- /dev/null +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKBSmartRegisterActivity.java @@ -0,0 +1,35 @@ +package org.smartregister.bidan.activity; + +import org.smartregister.provider.SmartRegisterClientsProvider; + +/** + * Created by sid-tech on 11/7/17. + */ + +public class NativeKBSmartRegisterActivity extends BaseRegisterActivity { + + @Override + protected DefaultOptionsProvider getDefaultOptionsProvider() { + return null; + } + + @Override + protected NavBarOptionsProvider getNavBarOptionsProvider() { + return null; + } + + @Override + protected SmartRegisterClientsProvider clientsProvider() { + return null; + } + + @Override + protected void onInitialization() { + + } + + @Override + public void startRegistration() { + + } +} diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIANCSmartRegisterActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIANCSmartRegisterActivity.java new file mode 100644 index 0000000..fb5b0b1 --- /dev/null +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIANCSmartRegisterActivity.java @@ -0,0 +1,35 @@ +package org.smartregister.bidan.activity; + +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity; + +/** + * Created by sid-tech on 11/7/17. + */ + +public class NativeKIANCSmartRegisterActivity extends BaseRegisterActivity { + @Override + protected DefaultOptionsProvider getDefaultOptionsProvider() { + return null; + } + + @Override + protected NavBarOptionsProvider getNavBarOptionsProvider() { + return null; + } + + @Override + protected SmartRegisterClientsProvider clientsProvider() { + return null; + } + + @Override + protected void onInitialization() { + + } + + @Override + public void startRegistration() { + + } +} diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIAnakSmartRegisterActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIAnakSmartRegisterActivity.java new file mode 100644 index 0000000..3b3bb5b --- /dev/null +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIAnakSmartRegisterActivity.java @@ -0,0 +1,35 @@ +package org.smartregister.bidan.activity; + +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity; + +/** + * Created by sid-tech on 11/7/17. + */ + +public class NativeKIAnakSmartRegisterActivity extends BaseRegisterActivity { + @Override + protected DefaultOptionsProvider getDefaultOptionsProvider() { + return null; + } + + @Override + protected NavBarOptionsProvider getNavBarOptionsProvider() { + return null; + } + + @Override + protected SmartRegisterClientsProvider clientsProvider() { + return null; + } + + @Override + protected void onInitialization() { + + } + + @Override + public void startRegistration() { + + } +} diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIPNCSmartRegisterActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIPNCSmartRegisterActivity.java new file mode 100644 index 0000000..79d6996 --- /dev/null +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKIPNCSmartRegisterActivity.java @@ -0,0 +1,35 @@ +package org.smartregister.bidan.activity; + +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity; + +/** + * Created by sid-tech on 11/7/17. + */ + +public class NativeKIPNCSmartRegisterActivity extends BaseRegisterActivity{ + @Override + protected DefaultOptionsProvider getDefaultOptionsProvider() { + return null; + } + + @Override + protected NavBarOptionsProvider getNavBarOptionsProvider() { + return null; + } + + @Override + protected SmartRegisterClientsProvider clientsProvider() { + return null; + } + + @Override + protected void onInitialization() { + + } + + @Override + public void startRegistration() { + + } +} diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKISmartRegisterActivity.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKISmartRegisterActivity.java new file mode 100644 index 0000000..ddaec9d --- /dev/null +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/activity/NativeKISmartRegisterActivity.java @@ -0,0 +1,162 @@ +package org.smartregister.bidan.activity; + +import android.app.ProgressDialog; +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; + +import org.smartregister.bidan.R; +import org.smartregister.bidan.adapter.BidanRegisterActivityPagerAdapter; +import org.smartregister.bidan.adapter.PathRegisterActivityPagerAdapter; +import org.smartregister.bidan.fragment.AdvancedSearchFragment; +import org.smartregister.bidan.fragment.BaseSmartRegisterFragment; +import org.smartregister.bidan.fragment.ChildSmartRegisterFragment; +import org.smartregister.bidan.fragment.KISmartRegisterFragment; +import org.smartregister.domain.FetchStatus; +import org.smartregister.event.Event; +import org.smartregister.event.Listener; +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.view.viewpager.OpenSRPViewPager; + +import butterknife.Bind; +import butterknife.ButterKnife; + +/** + * Created by sid-tech on 11/7/17. + */ + +public class NativeKISmartRegisterActivity extends BaseRegisterActivity { + + @Bind(R.id.view_pager) + protected OpenSRPViewPager mPager; + private FragmentPagerAdapter mPagerAdapter; + private static final int REQUEST_CODE_GET_JSON = 3432; + private int currentPage; + public static final int ADVANCED_SEARCH_POSITION = 1; + private ProgressDialog progressDialog; + + private android.support.v4.app.Fragment mBaseFragment = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ButterKnife.bind(this); + + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + + mBaseFragment = new KISmartRegisterFragment(); +// Fragment[] otherFragments = {new AdvancedSearchFragment()}; + Fragment[] otherFragments = {}; + + // Instantiate a ViewPager and a PagerAdapter. + mPagerAdapter = new BidanRegisterActivityPagerAdapter(getSupportFragmentManager(), mBaseFragment, otherFragments); + mPager.setOffscreenPageLimit(otherFragments.length); + mPager.setAdapter(mPagerAdapter); + mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + currentPage = position; + } + }); + + Event.ON_DATA_FETCHED.addListener(onDataFetchedListener); + initializeProgressDialog(); + } + + @Override + protected DefaultOptionsProvider getDefaultOptionsProvider() { + return null; + } + + @Override + protected NavBarOptionsProvider getNavBarOptionsProvider() { + return null; + } + + @Override + protected SmartRegisterClientsProvider clientsProvider() { + return null; + } + + @Override + protected void onInitialization() { + + } + + @Override + public void startRegistration() { + + } + + + + private final Listener onDataFetchedListener = new Listener() { + @Override + public void onEvent(FetchStatus fetchStatus) { + refreshList(fetchStatus); + } + }; + + public android.support.v4.app.Fragment findFragmentByPosition(int position) { + FragmentPagerAdapter fragmentPagerAdapter = mPagerAdapter; + return getSupportFragmentManager().findFragmentByTag("android:switcher:" + mPager.getId() + ":" + fragmentPagerAdapter.getItemId(position)); + } + + + + public void refreshList(final FetchStatus fetchStatus) { + if (Looper.myLooper() == Looper.getMainLooper()) { + BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); + if (registerFragment != null && fetchStatus.equals(FetchStatus.fetched)) { + registerFragment.refreshListView(); + } + } else { + Handler handler = new android.os.Handler(Looper.getMainLooper()); + handler.post(new Runnable() { + @Override + public void run() { + BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); + if (registerFragment != null && fetchStatus.equals(FetchStatus.fetched)) { + registerFragment.refreshListView(); + } + } + }); + } + + } + + private void refreshList(String data) { + BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); + if (registerFragment != null && data != null) { + registerFragment.refreshListView(); + } + + } + + private void filterList(String filterString) { + BaseSmartRegisterFragment registerFragment = (BaseSmartRegisterFragment) findFragmentByPosition(0); + if (registerFragment != null) { + registerFragment.openVaccineCard(filterString); + } + } + + private void initializeProgressDialog() { + progressDialog = new ProgressDialog(this); + progressDialog.setCancelable(false); + progressDialog.setTitle(getString(R.string.saving_dialog_title)); + progressDialog.setMessage(getString(R.string.please_wait_message)); + } + + public void updateAdvancedSearchFilterCount(int count) { +// AdvancedSearchFragment advancedSearchFragment = (AdvancedSearchFragment) findFragmentByPosition(ADVANCED_SEARCH_POSITION); +// if (advancedSearchFragment != null) { +// advancedSearchFragment.updateFilterCount(count); +// } + } + + +} diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/application/BidanApplication.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/application/BidanApplication.java index 0687265..1d4fc3c 100644 --- a/opensrp-bidan/src/main/java/org/smartregister/bidan/application/BidanApplication.java +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/application/BidanApplication.java @@ -314,7 +314,7 @@ public void setLastModified(boolean lastModified) { public void onTimeChanged() { Toast.makeText(this, R.string.device_time_changed, Toast.LENGTH_LONG).show(); context.userService().forceRemoteLogin(); - logoutCurrentUser(); +// logoutCurrentUser(); } @Override diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/controller/NavigationControllerINA.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/controller/NavigationControllerINA.java new file mode 100644 index 0000000..cf67ac1 --- /dev/null +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/controller/NavigationControllerINA.java @@ -0,0 +1,80 @@ +package org.smartregister.bidan.controller; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; + +import org.json.JSONObject; +import org.smartregister.Context; +import org.smartregister.bidan.activity.NativeKBSmartRegisterActivity; +import org.smartregister.bidan.activity.NativeKIANCSmartRegisterActivity; +import org.smartregister.bidan.activity.NativeKIAnakSmartRegisterActivity; +import org.smartregister.bidan.activity.NativeKIPNCSmartRegisterActivity; +import org.smartregister.bidan.activity.NativeKISmartRegisterActivity; +import org.smartregister.view.controller.ANMController; +import org.smartregister.view.controller.NavigationController; + +import static android.preference.PreferenceManager.getDefaultSharedPreferences; + +/** + * Created by sid-tech on 11/7/17. + */ + +public class NavigationControllerINA extends NavigationController { + private Activity activity; + private ANMController anmController; + private Context context; + + public NavigationControllerINA(Activity activity, ANMController anmController,Context context) { + super(activity,anmController); + this.activity = activity; + this.anmController = anmController; + this.context = context; + } + + @Override + public void startECSmartRegistry() { + activity.startActivity(new Intent(activity, NativeKISmartRegisterActivity.class)); + SharedPreferences sharedPreferences = getDefaultSharedPreferences(this.activity); + + if(sharedPreferences.getBoolean("firstlauch",true)) { + sharedPreferences.edit().putBoolean("firstlauch",false).commit(); + } + } + + @Override + public void startFPSmartRegistry() { + activity.startActivity(new Intent(activity, NativeKBSmartRegisterActivity.class)); + } + + @Override + public void startANCSmartRegistry() { + activity.startActivity(new Intent(activity, NativeKIANCSmartRegisterActivity.class)); + } + + @Override + public void startPNCSmartRegistry() { + activity.startActivity(new Intent(activity, NativeKIPNCSmartRegisterActivity.class)); + } + + @Override + public void startChildSmartRegistry() { + activity.startActivity(new Intent(activity, NativeKIAnakSmartRegisterActivity.class)); + } + + @Override + public void startReports() { + String id, pass; + try{ + id = new JSONObject(anmController.get()).get("anmName").toString(); + pass = context.allSettings().fetchANMPassword(); + }catch(org.json.JSONException ex){ + id="noname"; + pass="null"; + } + String uri = "http://"+id+":"+pass+"@kia-report.sid-indonesia.org/login/auth"; + activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri))); + } + +} \ No newline at end of file diff --git a/opensrp-bidan/src/main/java/org/smartregister/bidan/fragment/KISmartRegisterFragment.java b/opensrp-bidan/src/main/java/org/smartregister/bidan/fragment/KISmartRegisterFragment.java new file mode 100644 index 0000000..899f262 --- /dev/null +++ b/opensrp-bidan/src/main/java/org/smartregister/bidan/fragment/KISmartRegisterFragment.java @@ -0,0 +1,559 @@ +package org.smartregister.bidan.fragment; + +import android.content.pm.ActivityInfo; +import android.database.Cursor; +import android.os.Bundle; +import android.os.Handler; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.github.ybq.android.spinkit.style.Circle; + +import org.smartregister.bidan.R; +import org.smartregister.bidan.activity.NativeKISmartRegisterActivity; +import org.smartregister.bidan.activity.LoginActivity; +import org.smartregister.bidan.application.BidanApplication; +import org.smartregister.bidan.domain.RegisterClickables; +import org.smartregister.bidan.option.BasicSearchOption; +import org.smartregister.bidan.option.DateSort; +import org.smartregister.bidan.option.StatusSort; +//import org.smartregister.bidan.provider.ChildSmartClientsProvider; +import org.smartregister.bidan.receiver.SyncStatusBroadcastReceiver; +//import org.smartregister.bidan.servicemode.VaccinationServiceModeOption; +import org.smartregister.bidan.view.LocationPickerView; +import org.smartregister.commonregistry.CommonPersonObjectClient; +import org.smartregister.commonregistry.CommonRepository; +import org.smartregister.cursoradapter.CursorCommonObjectFilterOption; +import org.smartregister.cursoradapter.CursorCommonObjectSort; +import org.smartregister.cursoradapter.CursorSortOption; +import org.smartregister.cursoradapter.SmartRegisterPaginatedCursorAdapter; +import org.smartregister.cursoradapter.SmartRegisterQueryBuilder; +import org.smartregister.domain.FetchStatus; +//import org.smartregister.immunization.db.VaccineRepo; +//import org.smartregister.immunization.util.VaccinateActionUtils; +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.repository.AllSharedPreferences; +import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity; +import org.smartregister.view.dialog.DialogOption; +import org.smartregister.view.dialog.FilterOption; +import org.smartregister.view.dialog.ServiceModeOption; +import org.smartregister.view.dialog.SortOption; + +import java.util.ArrayList; +import java.util.List; + +import util.PathConstants; + +public class KISmartRegisterFragment extends BaseSmartRegisterFragment implements SyncStatusBroadcastReceiver.SyncStatusListener { + private final ClientActionHandler clientActionHandler = new ClientActionHandler(); + private LocationPickerView clinicSelection; + private static final long NO_RESULT_SHOW_DIALOG_DELAY = 1000l; + private Handler showNoResultDialogHandler; + private NotInCatchmentDialogFragment notInCatchmentDialogFragment; + private TextView filterCount; + private View filterSection; + private ImageView backButton; + private TextView nameInitials; + private LinearLayout btnBackToHome; + private ProgressBar syncProgressBar; + private int dueOverdueCount = 0; + + @Override + protected SecuredNativeSmartRegisterActivity.DefaultOptionsProvider getDefaultOptionsProvider() { + return new SecuredNativeSmartRegisterActivity.DefaultOptionsProvider() { + // FIXME path_conflict + //@Override + public FilterOption searchFilterOption() { + return new BasicSearchOption(""); + } + + @Override + public ServiceModeOption serviceMode() { +// return new VaccinationServiceModeOption(null, "Linda Clinic", new int[]{ +// R.string.child_profile, R.string.birthdate_age, R.string.epi_number, R.string.child_contact_number, +// R.string.child_next_vaccine +// }, new int[]{5, 2, 2, 3, 3}); + return null; + } + + @Override + public FilterOption villageFilter() { + return new CursorCommonObjectFilterOption("no village filter", ""); + } + + @Override + public SortOption sortOption() { + return new CursorCommonObjectSort(getResources().getString(R.string.woman_alphabetical_sort), "last_interacted_with desc"); + } + + @Override + public String nameInShortFormForTitle() { + return context().getStringResource(R.string.zeir); + } + }; + } + + @Override + protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { + return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { + + @Override + public DialogOption[] filterOptions() { + return new DialogOption[]{}; + } + + @Override + public DialogOption[] serviceModeOptions() { + return new DialogOption[]{ + }; + } + + @Override + public DialogOption[] sortingOptions() { + return new DialogOption[]{ + new CursorCommonObjectSort(getResources().getString(R.string.woman_alphabetical_sort), "first_name"), + new DateSort("Age", "dob"), + new StatusSort("Due Status"), + new CursorCommonObjectSort(getResources().getString(R.string.id_sort), "zeir_id") + }; + } + + @Override + public String searchHint() { + return context().getStringResource(R.string.str_search_hint); + } + }; + } + + + @Override + protected SmartRegisterClientsProvider clientsProvider() { + return null; + } + + @Override + protected void onInitialization() { + } + + @Override + protected void startRegistration() { + ((NativeKISmartRegisterActivity) getActivity()).startFormActivity("child_enrollment", null, null); + } + + @Override + protected void onCreation() { + } + + @Override + protected void onResumption() { + super.onResumption(); + getDefaultOptionsProvider(); + if (isPausedOrRefreshList()) { + initializeQueries(); + } + updateSearchView(); + try { + LoginActivity.setLanguage(); + } catch (Exception e) { + Log.e(getClass().getCanonicalName(), e.getMessage()); + } + + updateLocationText(); + if (filterMode()) { + toggleFilterSelection(); + } + SyncStatusBroadcastReceiver.getInstance().addSyncStatusListener(this); + refreshSyncStatusViews(); + } + + @Override + public void onPause() { + super.onPause(); + SyncStatusBroadcastReceiver.getInstance().removeSyncStatusListener(this); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Inflate the layout for this fragment + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + this.getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + + View view = inflater.inflate(R.layout.smart_register_activity_customized, container, false); + mView = view; + onInitialization(); + setupViews(view); + onResumption(); + return view; + } + + @Override + public void setupViews(View view) { + super.setupViews(view); + view.findViewById(R.id.btn_report_month).setVisibility(View.INVISIBLE); + view.findViewById(R.id.service_mode_selection).setVisibility(View.INVISIBLE); + + filterSection = view.findViewById(R.id.filter_selection); + filterSection.setOnClickListener(clientActionHandler); + + filterCount = (TextView) view.findViewById(R.id.filter_count); + filterCount.setVisibility(View.GONE); + filterCount.setClickable(false); + filterCount.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (view.isClickable()) { + filterSection.performClick(); + } + } + }); + + clientsView.setVisibility(View.VISIBLE); + clientsProgressView.setVisibility(View.INVISIBLE); + setServiceModeViewDrawableRight(null); + initializeQueries(); + updateSearchView(); + populateClientListHeaderView(view); + + View qrCode = view.findViewById(R.id.scan_qr_code); + qrCode.setOnClickListener(clientActionHandler); + + backButton = (ImageView) view.findViewById(R.id.back_button); + nameInitials = (TextView) view.findViewById(R.id.name_inits); + btnBackToHome = (LinearLayout) view.findViewById(R.id.btn_back_to_home); + syncProgressBar = (ProgressBar) view.findViewById(R.id.sync_progress_bar); + Circle circle = new Circle(); + syncProgressBar.setIndeterminateDrawable(circle); + + AllSharedPreferences allSharedPreferences = context().allSharedPreferences(); + String preferredName = allSharedPreferences.getANMPreferredName(allSharedPreferences.fetchRegisteredANM()); + if (!preferredName.isEmpty()) { + String[] preferredNameArray = preferredName.split(" "); + String initials = ""; + if (preferredNameArray.length > 1) { + initials = String.valueOf(preferredNameArray[0].charAt(0)) + String.valueOf(preferredNameArray[1].charAt(0)); + } else if (preferredNameArray.length == 1) { + initials = String.valueOf(preferredNameArray[0].charAt(0)); + } + nameInitials.setText(initials); + } + + View globalSearchButton = mView.findViewById(R.id.global_search); + globalSearchButton.setOnClickListener(clientActionHandler); + } + + @Override + protected void goBack() { + if (filterMode()) { + toggleFilterSelection(); + } else { + DrawerLayout drawer = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout); + if (!drawer.isDrawerOpen(GravityCompat.START)) { + drawer.openDrawer(GravityCompat.START); + } + } + } + + @Override + public boolean onBackPressed() { + if (filterMode()) { + toggleFilterSelection(); + return true; + } + return false; + } + + public LocationPickerView getLocationPickerView() { + return getClinicSelection(); + } + + private void initializeQueries() { + String tableName = PathConstants.CHILD_TABLE_NAME; + String parentTableName = PathConstants.MOTHER_TABLE_NAME; + +// ChildSmartClientsProvider hhscp = new ChildSmartClientsProvider(getActivity(), +// clientActionHandler, context().alertService(), VaccinatorApplication.getInstance().vaccineRepository(), VaccinatorApplication.getInstance().weightRepository(), context().commonrepository(tableName)); +// clientAdapter = new SmartRegisterPaginatedCursorAdapter(getActivity(), null, hhscp, context().commonrepository(tableName)); + clientAdapter = new SmartRegisterPaginatedCursorAdapter(getActivity(), null, null, context().commonrepository(tableName)); + clientsView.setAdapter(clientAdapter); + + setTablename(tableName); + SmartRegisterQueryBuilder countqueryBUilder = new SmartRegisterQueryBuilder(); + countqueryBUilder.SelectInitiateMainTableCounts(tableName); + mainCondition = " dod is NULL OR dod = '' "; + countSelect = countqueryBUilder.mainCondition(mainCondition); + super.CountExecute(); + countOverDue(); + countDueOverDue(); + + SmartRegisterQueryBuilder queryBUilder = new SmartRegisterQueryBuilder(); + queryBUilder.SelectInitiateMainTable(tableName, new String[]{ + tableName + ".relationalid", + tableName + ".details", + tableName + ".zeir_id", + tableName + ".relational_id", + tableName + ".first_name", + tableName + ".last_name", + tableName + ".gender", + parentTableName + ".first_name as mother_first_name", + parentTableName + ".last_name as mother_last_name", + parentTableName + ".dob as mother_dob", + parentTableName + ".nrc_number as mother_nrc_number", + tableName + ".father_name", + tableName + ".dob", + tableName + ".epi_card_number", + tableName + ".contact_phone_number", + tableName + ".pmtct_status", + tableName + ".provider_uc", + tableName + ".provider_town", + tableName + ".provider_id", + tableName + ".provider_location_id", + tableName + ".client_reg_date", + tableName + ".last_interacted_with", + tableName + ".inactive", + tableName + ".lost_to_follow_up" + }); + queryBUilder.customJoin("LEFT JOIN " + parentTableName + " ON " + tableName + ".relational_id = " + parentTableName + ".id"); + mainSelect = queryBUilder.mainCondition(mainCondition); + Sortqueries = ((CursorSortOption) getDefaultOptionsProvider().sortOption()).sort(); + + currentlimit = 20; + currentoffset = 0; + + super.filterandSortInInitializeQueries(); + + updateSearchView(); + refresh(); + } + + private void refreshSyncStatusViews() { + if (SyncStatusBroadcastReceiver.getInstance().isSyncing()) { + syncProgressBar.setVisibility(View.VISIBLE); + btnBackToHome.setVisibility(View.GONE); + } else { + syncProgressBar.setVisibility(View.GONE); + btnBackToHome.setVisibility(View.VISIBLE); + } + } + + @Override + public void onSyncStart() { + refreshSyncStatusViews(); + } + + @Override + public void onSyncComplete(FetchStatus fetchStatus) { + refreshSyncStatusViews(); + } + + + private void updateSearchView() { + getSearchView().removeTextChangedListener(textWatcher); + getSearchView().addTextChangedListener(textWatcher); + } + + public void triggerFilterSelection() { + if (filterSection != null && !filterMode()) { + filterSection.performClick(); + } + } + + private void populateClientListHeaderView(View view) { + LinearLayout clientsHeaderLayout = (LinearLayout) view.findViewById(org.smartregister.R.id.clients_header_layout); + clientsHeaderLayout.setVisibility(View.GONE); + + LinearLayout headerLayout = (LinearLayout) getLayoutInflater(null).inflate(R.layout.smart_register_child_header, null); + clientsView.addHeaderView(headerLayout); + clientsView.setEmptyView(getActivity().findViewById(R.id.empty_view)); + + } + + private String filterSelectionCondition(boolean urgentOnly) { + String mainCondition = " (inactive != 'true' and lost_to_follow_up != 'true') AND ( "; +// ArrayList vaccines = VaccineRepo.getVaccines("child"); + +// if (vaccines.contains(VaccineRepo.Vaccine.bcg2)) { +// vaccines.remove(VaccineRepo.Vaccine.bcg2); +// } +// if (vaccines.contains(VaccineRepo.Vaccine.ipv)) { +// vaccines.remove(VaccineRepo.Vaccine.ipv); +// } +// for (int i = 0; i < vaccines.size(); i++) { +// VaccineRepo.Vaccine vaccine = vaccines.get(i); +// if (i == vaccines.size() - 1) { +// mainCondition += " " + VaccinateActionUtils.addHyphen(vaccine.display()) + " = 'urgent' "; +// } else { +// mainCondition += " " + VaccinateActionUtils.addHyphen(vaccine.display()) + " = 'urgent' or "; +// } +// } + + if (urgentOnly) { + return mainCondition + " ) "; + } + + mainCondition += " or "; +// for (int i = 0; i < vaccines.size(); i++) { +// VaccineRepo.Vaccine vaccine = vaccines.get(i); +// if (i == vaccines.size() - 1) { +// mainCondition += " " + VaccinateActionUtils.addHyphen(vaccine.display()) + " = 'normal' "; +// } else { +// mainCondition += " " + VaccinateActionUtils.addHyphen(vaccine.display()) + " = 'normal' or "; +// } +// } + + return mainCondition + " ) "; + } + + + private void countOverDue() { + String mainCondition = filterSelectionCondition(true); + int count = count(mainCondition); + + if (filterCount != null) { + if (count > 0) { + filterCount.setText(String.valueOf(count)); + filterCount.setVisibility(View.VISIBLE); + filterCount.setClickable(true); + } else { + filterCount.setVisibility(View.GONE); + filterCount.setClickable(false); + } + } + + ((NativeKISmartRegisterActivity) getActivity()).updateAdvancedSearchFilterCount(count); + } + + private void countDueOverDue() { + String mainCondition = filterSelectionCondition(false); + dueOverdueCount = count(mainCondition); + } + + private int count(String mainConditionString) { + + int count = 0; + + Cursor c = null; + + try { + SmartRegisterQueryBuilder sqb = new SmartRegisterQueryBuilder(countSelect); + String query = ""; + if (isValidFilterForFts(commonRepository())) { + String sql = sqb.countQueryFts(tablename, "", mainConditionString, ""); + List ids = commonRepository().findSearchIds(sql); + query = sqb.toStringFts(ids, tablename + "." + CommonRepository.ID_COLUMN); + query = sqb.Endquery(query); + } else { + sqb.addCondition(filters); + query = sqb.orderbyCondition(Sortqueries); + query = sqb.Endquery(query); + } + + Log.i(getClass().getName(), query); + c = commonRepository().rawCustomQueryForAdapter(query); + c.moveToFirst(); + count = c.getInt(0); + + } catch (Exception e) { + Log.e(getClass().getName(), e.toString(), e); + } finally { + if (c != null) { + c.close(); + } + } + + return count; + + } + + private void switchViews(boolean filterSelected) { + if (filterSelected) { + if (titleLabelView != null) { + titleLabelView.setText(String.format(getString(R.string.overdue_due), String.valueOf(dueOverdueCount))); + } + nameInitials.setVisibility(View.GONE); + backButton.setVisibility(View.VISIBLE); + } else { + if (titleLabelView != null) { + titleLabelView.setText(getString(R.string.zeir)); + } + nameInitials.setVisibility(View.VISIBLE); + backButton.setVisibility(View.GONE); + } + } + + private void toggleFilterSelection() { + if (filterSection != null) { + String tagString = "PRESSED"; + if (filterSection.getTag() == null) { + filter("", "", filterSelectionCondition(false)); + filterSection.setTag(tagString); + filterSection.setBackgroundResource(R.drawable.transparent_clicked_background); + switchViews(true); + } else if (filterSection.getTag().toString().equals(tagString)) { + filter("", "", ""); + filterSection.setTag(null); + filterSection.setBackgroundResource(R.drawable.transparent_gray_background); + switchViews(false); + } + } + } + + private boolean filterMode() { + return filterSection != null && filterSection.getTag() != null; + } + + + //////////////////////////////////////////////////////////////// + // Inner classes + //////////////////////////////////////////////////////////////// + + private class ClientActionHandler implements View.OnClickListener { + @Override + public void onClick(View view) { + CommonPersonObjectClient client = null; + if (view.getTag() != null && view.getTag() instanceof CommonPersonObjectClient) { + client = (CommonPersonObjectClient) view.getTag(); + } + RegisterClickables registerClickables = new RegisterClickables(); + + switch (view.getId()) { + case R.id.child_profile_info_layout: + +// KIMasterActivity.launchActivity(getActivity(), client, null); + break; + case R.id.record_weight: + registerClickables.setRecordWeight(true); +// KIMasterActivity.launchActivity(getActivity(), client, registerClickables); + break; + + case R.id.record_vaccination: + registerClickables.setRecordAll(true); +// KIMasterActivity.launchActivity(getActivity(), client, registerClickables); + break; + case R.id.filter_selection: + toggleFilterSelection(); + break; + + case R.id.global_search: +// ((NativeKISmartRegisterActivity) getActivity()).startAdvancedSearch(); + break; + + case R.id.scan_qr_code: +// ((NativeKISmartRegisterActivity) getActivity()).startQrCodeScanner(); + break; + default: + break; + } + } + } + + +}