use of org.kde.kdeconnect.UserInterface.List.PluginItem in project kdeconnect-android by KDE.
the class DeviceFragment method refreshUI.
void refreshUI() {
if (device == null || rootView == null) {
return;
}
//Once in-app, there is no point in keep displaying the notification if any
device.hidePairingNotification();
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (device.isPairRequestedByPeer()) {
((TextView) rootView.findViewById(R.id.pair_message)).setText(R.string.pair_requested);
rootView.findViewById(R.id.pair_progress).setVisibility(View.GONE);
rootView.findViewById(R.id.pair_button).setVisibility(View.GONE);
rootView.findViewById(R.id.pair_request).setVisibility(View.VISIBLE);
} else {
boolean paired = device.isPaired();
boolean reachable = device.isReachable();
boolean onData = NetworkHelper.isOnMobileNetwork(getContext());
rootView.findViewById(R.id.pairing_buttons).setVisibility(paired ? View.GONE : View.VISIBLE);
rootView.findViewById(R.id.not_reachable_message).setVisibility((paired && !reachable && !onData) ? View.VISIBLE : View.GONE);
rootView.findViewById(R.id.on_data_message).setVisibility((paired && !reachable && onData) ? View.VISIBLE : View.GONE);
try {
ArrayList<ListAdapter.Item> items = new ArrayList<>();
//Plugins button list
final Collection<Plugin> plugins = device.getLoadedPlugins().values();
for (final Plugin p : plugins) {
if (!p.hasMainActivity())
continue;
if (p.displayInContextMenu())
continue;
items.add(new PluginItem(p, new View.OnClickListener() {
@Override
public void onClick(View v) {
p.startMainActivity(mActivity);
}
}));
}
//Failed plugins List
final ConcurrentHashMap<String, Plugin> failed = device.getFailedPlugins();
if (!failed.isEmpty()) {
if (errorHeader == null) {
errorHeader = new TextView(mActivity);
errorHeader.setPadding(0, ((int) (28 * getResources().getDisplayMetrics().density)), 0, ((int) (8 * getResources().getDisplayMetrics().density)));
errorHeader.setOnClickListener(null);
errorHeader.setOnLongClickListener(null);
errorHeader.setText(getResources().getString(R.string.plugins_failed_to_load));
}
items.add(new CustomItem(errorHeader));
for (Map.Entry<String, Plugin> entry : failed.entrySet()) {
String pluginKey = entry.getKey();
final Plugin plugin = entry.getValue();
if (plugin == null) {
items.add(new SmallEntryItem(pluginKey));
} else {
items.add(new SmallEntryItem(plugin.getDisplayName(), new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.getErrorDialog(mActivity).show();
}
}));
}
}
}
//Plugins without permissions List
final ConcurrentHashMap<String, Plugin> permissionsNeeded = device.getPluginsWithoutPermissions();
if (!permissionsNeeded.isEmpty()) {
if (noPermissionsHeader == null) {
noPermissionsHeader = new TextView(mActivity);
noPermissionsHeader.setPadding(0, ((int) (28 * getResources().getDisplayMetrics().density)), 0, ((int) (8 * getResources().getDisplayMetrics().density)));
noPermissionsHeader.setOnClickListener(null);
noPermissionsHeader.setOnLongClickListener(null);
noPermissionsHeader.setText(getResources().getString(R.string.plugins_need_permission));
}
items.add(new CustomItem(noPermissionsHeader));
for (Map.Entry<String, Plugin> entry : permissionsNeeded.entrySet()) {
String pluginKey = entry.getKey();
final Plugin plugin = entry.getValue();
if (plugin == null) {
items.add(new SmallEntryItem(pluginKey));
} else {
items.add(new SmallEntryItem(plugin.getDisplayName(), new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.getPermissionExplanationDialog(mActivity).show();
}
}));
}
}
}
ListView buttonsList = (ListView) rootView.findViewById(R.id.buttons_list);
ListAdapter adapter = new ListAdapter(mActivity, items);
buttonsList.setAdapter(adapter);
mActivity.invalidateOptionsMenu();
} catch (IllegalStateException e) {
e.printStackTrace();
//Ignore: The activity was closed while we were trying to update it
} catch (ConcurrentModificationException e) {
Log.e("DeviceActivity", "ConcurrentModificationException");
//Try again
this.run();
}
}
}
});
}
Aggregations