...
As shown above there are different parts of Main grid which can be controlled by implementing SecuredNativeSmartRegisterFragment. TBD explain each in details
- Register Label
- Sort Option
- Filter Option
- Service Mode
- Client Action Handler
- Search Filter Option
- Search Type
- Default Options
- Navigation Options
- Custom Form Handler
- New Record Button
- Adapter
- Client Provider
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public class MyRegisterFragment extends SecuredNativeSmartRegisterFragment { private final ClientActionHandler clientActionHandler = new ClientActionHandler(); public MyRegisterFragment() { super(null); } @SuppressLint("ValidFragment") public MyRegisterFragment(FormController formController) { super(formController); } // Default settings for Sort, Main Filter, Location, Service Mode, Search Filter and Search Type @Override protected SecuredNativeSmartRegisterActivity.DefaultOptionsProvider getDefaultOptionsProvider() { return new SecuredNativeSmartRegisterActivity.DefaultOptionsProvider() { @Override public SearchFilterOption searchFilterOption() { return new MySearchOption(""); } @Override public ServiceModeOption serviceMode() { return new MyServiceModeOption(null, "My Service Mode Label", new int[]{/* Resource ids for each header */ R.id.column1, R.id.column2, /*.....*/}, // Weight for each header. Should balance the weights of columns defined in client_record_layout.xml new int[]{6,2,3,2,1}); } @Override public FilterOption villageFilter() { return new CursorCommonObjectFilterOption("no village filter", ""); } @Override public SortOption sortOption() { return new CursorCommonObjectSort(getResources().getString(R.string.alphabetical_sort_text), "sort_column DESC"); } @Override public String nameInShortFormForTitle() { return Context.getInstance().getStringResource(R.string.my_register_title); } @Override public SecuredNativeSmartRegisterActivity.SearchType searchType() { return SecuredNativeSmartRegisterActivity.SearchType.PASSIVE; } }; } @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.sort_type1), "my_column1 ASC"), new CursorCommonObjectSort(getResources().getString(R.string.sort_type2), "my_column2 DESC"), new CursorCommonObjectSort(getResources().getString(R.string.sort_dob_age), "my_dob_column DESC") }; } @Override public String searchHint() { return Context.getInstance().getStringResource(R.string.text_to_display_searchbox); } }; } @Override protected void onInitialization(){ // A handler where form submission would be routed for further processing after successful save context.formSubmissionRouter().getHandlerMap().put("my_form1", new MyCustomForm1Handler(getActivity())); } @Override protected void onCreation() { // Custom tasks after fragment creation } // What app should do on click of New Record Button. It can launch QR Code activity or can also open a form directly @Override protected void startRegistration() { // Any fields in form needs to be overriden.. A usecase could be load data from DB and send to form Map<String, String> overrides = new HashMap<>(); overrides.put("my_form_field1", "abc"); startForm("my_form1", "", overrides); } @Override protected SmartRegisterPaginatedAdapter adapter() { // Setup the adapter to setup data. Here it is using CursorAdapter return new SmartRegisterPaginatedCursorAdapter(getActivity(), new SmartRegisterCursorBuilder("pkhouseholdmybindType", null, "HT", new String[]{"(SELECT count(1) FROM pkindividual WHERE household_id=H.household_id) registeredMembers"}null, (CursorSortOption) getDefaultOptionsProvider().sortOption(), "").limit(5), c clientsProvider(), SmartRegisterCursorBuilder.DB.DRISHTI); } @Override protected SmartRegisterClientsProvider clientsProvider() { return new MySmartClientsProvider(getActivity(), clientActionHandler, context.alertService()); } // Client interaction handler. A class that handles any clicks or taps on data row's different sections or layouts private class ClientActionHandler implements View.OnClickListener { @Override public void onClick(View view) { switch (view.getId()) { case R.id.column1_layout: // open details fragment ((SmartRegisterSecuredActivity)getActivity()).showDetailFragment((CommonPersonObjectClient) view.getTag(), false); break; case R.id.column2_button_followup: // do something else i.e. open another form or open a dialogue etc break; } } } } |
...