/** * Constructor for unit search dialog builder used to build a dialog for * a single unit type. Note that this will show all units, including those * that are already buttons on the main screen * @param unitType contains units for the search dialog */ public UnitSearchDialogBuilder(UnitType unitType) { ArrayList<UnitSearchItem> items = new ArrayList<>(); // note that we're using a blank unit type key, this will be fine // since we only have one unit type to distinguish from UnitListBuilder(items, unitType, ""); mOriginalList = items; }
/** * Helper function to build a list dialog box that has a search function * Dialog lists has a cancel button. * * @param hint hint that displays in the EditText search box * @param itemClickListener OnClickListener for when the user selects one * of the units in the dialog list */ private void createSearchDialog(CharSequence hint, AdapterView.OnItemClickListener itemClickListener) { Context context = getActivity(); mSearchDialogBuilder = new UnitSearchDialogBuilder(mUnitType); CalcActivity ca = (CalcActivity) getActivity(); //TODO not sure if the idleResource should be accessed this way... mSearchDialogBuilder.buildDialog(context, hint, ca.getIdlingResource(), itemClickListener); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mSearchDialogBuilder.cancelDialog(); UnitSearchItem item = mSearchDialogBuilder.getItem(position); selectUnitAtUnitArrayPos(item.getUnitPosition(), item.getUnitTypeKey()); } });
mSearchDialogBuilder = new UnitSearchDialogBuilder(mCalc.getUnitTypeList()); mSearchDialogBuilder.buildDialog(mAppContext, getString(R.string.find_unit), mIdlingResource,
/** * Constructor for unit search dialog builder used to build a dialog for * a list of Unit Types * @param unitTypeList is the collection of Unit Types and units to search * over. */ public UnitSearchDialogBuilder(UnitTypeList unitTypeList){ ArrayList<UnitSearchItem> items = new ArrayList<>(); for (Map.Entry<String, UnitType> entry : unitTypeList.getUnitTypeArray().entrySet()) { String unitTypeKey = entry.getKey(); UnitType unitType = entry.getValue(); UnitListBuilder(items, unitType, unitTypeKey); } mOriginalList = items; }