@Override public void run() { if (neighbourAdapter == null) return; neighbourAdapter.advanceTime(); NetpowerctrlApplication.getMainThreadHandler().postDelayed(this, 5000); }
public void pairResult(final NeighbourAdapter.AdapterItem item, boolean accepted) { if (accepted) { Toast.makeText(getActivity(), R.string.neighbour_pairing_accepted, Toast.LENGTH_SHORT).show(); neighbourAdapter.setPaired(item, true); } else { Toast.makeText(getActivity(), R.string.neighbour_pairing_denied, Toast.LENGTH_SHORT).show(); } }
@Override public void dataReceived(long uniqueID) { NeighbourAdapter.AdapterItem item = neighbourAdapter.getItemByID(uniqueID); if (item == null) return; Toast.makeText( getActivity(), getString(R.string.neighbour_data_received, item.getName()), Toast.LENGTH_SHORT) .show(); }
@Override public boolean onMenuItemClick(MenuItem menuItem) { final NeighbourAdapter.AdapterItem item = neighbourAdapter.getItem(clickedPosition); switch (menuItem.getItemId()) { case R.id.menu_neighbour_remove: { NeighbourDataSync.sendData(getActivity(), item.address, item.uniqueID, this, true); return true; } case R.id.menu_neighbour_push: { NeighbourDataSync.sendData(getActivity(), item.address, item.uniqueID, this, false); return true; } } return false; }
@Override public void pairingRemoved(long uniqueID) { neighbourAdapter.removePairing(uniqueID); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_neighbours, container, false); neighbourAdapter.setInflater(inflater); //noinspection ConstantConditions ListView list = (ListView) view.findViewById(R.id.list); networkIDText = (TextView) view.findViewById(R.id.hintText); updateNetworkIDText(); list.setEmptyView(view.findViewById(android.R.id.empty)); list.setAdapter(neighbourAdapter); list.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { final NeighbourAdapter.AdapterItem item = neighbourAdapter.getNeighbour(position); if (item.isPaired) { clickedPosition = position; PopupMenu popup = new PopupMenu(getActivity(), view); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.neighbour_entry, popup.getMenu()); popup .getMenu() .findItem(R.id.menu_neighbour_push) .setEnabled(item.isOnline && item.isSameVersion); popup.getMenu().findItem(R.id.menu_neighbour_remove).setEnabled(item.isOnline); popup.setOnMenuItemClickListener(NeighbourFragment.this); popup.show(); return; } if (!item.isSameVersion) { //noinspection ConstantConditions new AlertDialog.Builder(getActivity()) .setTitle(R.string.error_neighbour_wrong_version_title) .setMessage(R.string.error_neighbour_wrong_version) .setIcon(android.R.drawable.ic_menu_help) .setPositiveButton( android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { sendPairingRequest(item); } }) .setNegativeButton( android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }) .show(); //noinspection ConstantConditions Toast.makeText(getActivity(), R.string.neighbour_not_same_version, Toast.LENGTH_SHORT) .show(); return; } sendPairingRequest(item); } }); return view; }