2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-18 13:59:32 +00:00

Added runcommandplugin widget

Summary: A simple widget to execute commands from android desktop

Test Plan:
Add the widget and execute commands from it.
By default, the selected device is the first device in the device list.
The selected device can be changed via the widget title.
If there is no commands, the widget show an empty list
If there is no connected device, show the message located in @string/unreachable_description

Reviewers: albertvaka, nicolasfella, #kde_connect

Reviewed By: albertvaka

Subscribers: kdeconnect, nicolasfella

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D12507
This commit is contained in:
Nicolas Fella
2018-07-30 18:15:00 +02:00
parent 5c4c402f23
commit e0fde16525
11 changed files with 447 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class RunCommandPlugin extends Plugin {
@@ -42,6 +43,7 @@ public class RunCommandPlugin extends Plugin {
private ArrayList<JSONObject> commandList = new ArrayList<>();
private ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>();
private final ArrayList<CommandEntry> commandItems = new ArrayList<>();
private boolean canAddCommand;
@@ -61,6 +63,10 @@ public class RunCommandPlugin extends Plugin {
return commandList;
}
public ArrayList<CommandEntry> getCommandItems() {
return commandItems;
}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_runcommand);
@@ -88,6 +94,7 @@ public class RunCommandPlugin extends Plugin {
if (np.has("commandList")) {
commandList.clear();
try {
commandItems.clear();
JSONObject obj = new JSONObject(np.getString("commandList"));
Iterator<String> keys = obj.keys();
while (keys.hasNext()) {
@@ -95,7 +102,25 @@ public class RunCommandPlugin extends Plugin {
JSONObject o = obj.getJSONObject(s);
o.put("key", s);
commandList.add(o);
try {
commandItems.add(
new CommandEntry(
o.getString("name"),
o.getString("command"),
o.getString("key")
)
);
} catch (JSONException e) {
e.printStackTrace();
}
}
Collections.sort(commandItems, (lhs, rhs) -> lhs.getName().compareTo(rhs.getName()) );
Intent updateWidget = new Intent(context, RunCommandWidget.class);
context.sendBroadcast(updateWidget);
} catch (JSONException e) {
e.printStackTrace();
}