use of org.kde.kdeconnect.UserInterface.List.PairingDeviceItem in project kdeconnect-android by KDE.
the class PairingFragment method updateComputerList.
private void updateComputerList() {
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
@Override
public void onServiceStart(final BackgroundService service) {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (listRefreshCalledThisFrame) {
// yet and it would always return 0.
return;
}
listRefreshCalledThisFrame = true;
headerText.setText(getString(NetworkHelper.isOnMobileNetwork(getContext()) ? R.string.on_data_message : R.string.pairing_description));
try {
Collection<Device> devices = service.getDevices().values();
final ArrayList<ListAdapter.Item> items = new ArrayList<>();
SectionItem section;
Resources res = getResources();
section = new SectionItem(res.getString(R.string.category_not_paired_devices));
section.isSectionEmpty = true;
items.add(section);
for (Device device : devices) {
if (device.isReachable() && !device.isPaired()) {
items.add(new PairingDeviceItem(device, PairingFragment.this));
section.isSectionEmpty = false;
}
}
section = new SectionItem(res.getString(R.string.category_connected_devices));
section.isSectionEmpty = true;
items.add(section);
for (Device device : devices) {
if (device.isReachable() && device.isPaired()) {
items.add(new PairingDeviceItem(device, PairingFragment.this));
section.isSectionEmpty = false;
}
}
if (section.isSectionEmpty) {
//Remove connected devices section if empty
items.remove(items.size() - 1);
}
section = new SectionItem(res.getString(R.string.category_remembered_devices));
section.isSectionEmpty = true;
items.add(section);
for (Device device : devices) {
if (!device.isReachable() && device.isPaired()) {
items.add(new PairingDeviceItem(device, PairingFragment.this));
section.isSectionEmpty = false;
}
}
if (section.isSectionEmpty) {
//Remove remembered devices section if empty
items.remove(items.size() - 1);
}
final ListView list = (ListView) rootView.findViewById(R.id.listView1);
//Store current scroll
int index = list.getFirstVisiblePosition();
View v = list.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - list.getPaddingTop());
list.setAdapter(new ListAdapter(mActivity, items));
//Restore scroll
list.setSelectionFromTop(index, top);
} catch (IllegalStateException e) {
e.printStackTrace();
//Ignore: The activity was closed while we were trying to update it
} finally {
listRefreshCalledThisFrame = false;
}
}
});
}
});
}
Aggregations