@Override public void drop(int from, int to) { if (from != to) { try { MyUnit item = mAdapter.getItem(from); mAdapter.remove(item); mAdapter.insert(item, to); mAdapter.notifyDataSetChanged(); Utils.saveUnitOrderStorage(getActivity(), mAdapter.getAll()); } catch (Exception e) { e.printStackTrace(); } } }
private void checkUnitAndRefresh() { Debug.e("", "Refreshing..."); String selectedUnit = converter.getSelectedUnit(); ArrayList<String> unitList = converter.getFavUnitName(); if (!unitList.contains(selectedUnit)) { Utils.setPref(getActivity(), Constant.SELECTED_UNIT_STORAGE, MyStorageUnitConverter.BYTE); tvUnitSelVal.setText(MyStorageUnitConverter.BYTE); } mAdapter.addAll(converter.getFavUnit()); }
private void init() { converter = new MyStorageUnitConverter(getActivity()); TextView tvTitleText = (TextView) findViewById(R.id.tvTitleText); tvTitleText.setTypeface(Utils.getBold(getActivity())); tvTitleText.setText(R.string.title_unit); Button btnMenu = (Button) findViewById(R.id.btnMenu); btnMenu.setOnClickListener(menuClickListener); TextView tvUnitSelKey = (TextView) findViewById(R.id.tvUnitSelKey); tvUnitSelKey.setTypeface(Utils.getBold(getActivity())); tvUnitSelVal = (TextView) findViewById(R.id.tvUnitSelVal); tvUnitSelVal.setTypeface(Utils.getBold(getActivity())); tvUnitSelVal.setText(converter.getSelectedUnit()); tvUnitSelVal.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { showUnitSpinner(converter.getUnitList().toArray(new String[0])); } }); TextView tvUnitValueKey = (TextView) findViewById(R.id.tvUnitValueKey); tvUnitValueKey.setTypeface(Utils.getBold(getActivity())); tvUnitValueVal = (TextView) findViewById(R.id.tvUnitValueVal); tvUnitValueVal.setTypeface(Utils.getBold(getActivity())); tvUnitValueVal.setText("" + converter.getSelectedValue()); tvUnitValueVal.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { CalcFragment calc = new CalcFragment(); calc.show(getSupportFragmentManager(), ""); } }); mAdapter = new ConverterStorageAdapter(getActivity(), R.layout.unit_converter_item); lvUnitConverter = (DragSortListView) findViewById(R.id.lvUnitConverter); lvUnitConverter.setDropListener(onDrop); lvUnitConverter.setAdapter(mAdapter); mAdapter.addAll(converter.getFavUnit()); ImageView imgFavUnit = (ImageView) findViewById(R.id.imgFavUnit); imgFavUnit.setOnClickListener(favClickListener); }
@Override public void onValueSet(String value) { converter.setSelectedValue(Double.valueOf(value)); tvUnitValueVal.setText("" + converter.getSelectedValue()); mAdapter.addAll(converter.getFavUnit()); }