use of com.amaze.filemanager.utils.ComputerParcelable in project AmazeFileManager by TeamAmaze.
the class SmbSearchDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
builder.title(R.string.searchingdevices);
builder.negativeColor(accentColor);
builder.negativeText(R.string.cancel);
builder.onNegative((dialog, which) -> {
if (subnetScanner != null)
subnetScanner.interrupt();
dismiss();
});
builder.onPositive((dialog, which) -> {
if (subnetScanner != null)
subnetScanner.interrupt();
if (getActivity() != null && getActivity() instanceof MainActivity) {
dismiss();
MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.showSMBDialog("", "", false);
}
});
builder.positiveText(R.string.use_custom_ip);
builder.positiveColor(accentColor);
computers.add(new ComputerParcelable("-1", "-1"));
listViewAdapter = new ListViewAdapter(getActivity(), computers);
subnetScanner = new SubnetScanner(getActivity());
subnetScanner.setObserver(new SubnetScanner.ScanObserver() {
@Override
public void computerFound(final ComputerParcelable computer) {
if (getActivity() != null)
getActivity().runOnUiThread(() -> {
if (!computers.contains(computer))
computers.add(computer);
listViewAdapter.notifyDataSetChanged();
});
}
@Override
public void searchFinished() {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> {
if (computers.size() == 1) {
dismiss();
Toast.makeText(getActivity(), getResources().getString(R.string.nodevicefound), Toast.LENGTH_SHORT).show();
MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.showSMBDialog("", "", false);
return;
}
computers.remove(computers.size() - 1);
listViewAdapter.notifyDataSetChanged();
});
}
}
});
subnetScanner.start();
builder.adapter(listViewAdapter, null);
return builder.build();
}
Aggregations