Differential D12507 Diff 38737 src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDataProvider.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDataProvider.java
1 | package org.kde.kdeconnect.Plugins.RunCommandPlugin; | ||||
---|---|---|---|---|---|
2 | | ||||
3 | import android.content.Context; | ||||
4 | import android.content.Intent; | ||||
5 | import android.os.Build; | ||||
6 | import android.support.annotation.RequiresApi; | ||||
7 | import android.view.View; | ||||
8 | import android.widget.RemoteViews; | ||||
9 | import android.widget.RemoteViewsService; | ||||
10 | | ||||
11 | import org.kde.kdeconnect_tp.R; | ||||
12 | | ||||
13 | | ||||
14 | @RequiresApi( api = Build.VERSION_CODES.ICE_CREAM_SANDWICH ) | ||||
15 | public class RunCommandWidgetDataProvider implements RemoteViewsService.RemoteViewsFactory { | ||||
16 | | ||||
17 | private final Context mContext; | ||||
18 | | ||||
19 | public RunCommandWidgetDataProvider(Context context, Intent intent) { | ||||
20 | mContext = context; | ||||
21 | } | ||||
22 | | ||||
23 | private boolean checkPlugin() { | ||||
24 | if (RunCommandWidget.getCurrentDevice() == null || !RunCommandWidget.getCurrentDevice().isReachable()) | ||||
25 | return false; | ||||
26 | | ||||
27 | return RunCommandWidget.getCurrentDevice().getPlugin(RunCommandPlugin.class) != null; | ||||
28 | } | ||||
29 | | ||||
30 | @Override | ||||
31 | public void onCreate() { | ||||
32 | } | ||||
33 | | ||||
34 | @Override | ||||
35 | public void onDataSetChanged() { | ||||
36 | | ||||
37 | } | ||||
38 | | ||||
39 | @Override | ||||
40 | public void onDestroy() { | ||||
41 | } | ||||
42 | | ||||
43 | @Override | ||||
44 | public int getCount() { | ||||
45 | return checkPlugin() ? RunCommandWidget.getCurrentDevice().getPlugin(RunCommandPlugin.class).getCommandItems().size() : 0; | ||||
46 | } | ||||
47 | | ||||
48 | @Override | ||||
49 | public RemoteViews getViewAt(int i) { | ||||
50 | | ||||
51 | RemoteViews remoteView = new RemoteViews(mContext.getPackageName(), R.layout.list_item_entry); | ||||
52 | | ||||
53 | if (checkPlugin() && RunCommandWidget.getCurrentDevice().getPlugin(RunCommandPlugin.class).getCommandItems().size() > i) { | ||||
54 | CommandEntry listItem = RunCommandWidget.getCurrentDevice().getPlugin(RunCommandPlugin.class).getCommandItems().get(i); | ||||
55 | | ||||
56 | final Intent configIntent = new Intent(mContext, RunCommandWidget.class); | ||||
57 | configIntent.setAction(RunCommandWidget.RUN_COMMAND_ACTION); | ||||
58 | configIntent.putExtra(RunCommandWidget.TARGET_COMMAND, listItem.getKey()); | ||||
59 | configIntent.putExtra(RunCommandWidget.TARGET_DEVICE, RunCommandWidget.getCurrentDevice().getDeviceId()); | ||||
60 | | ||||
61 | remoteView.setTextViewText(R.id.list_item_entry_title, listItem.getName()); | ||||
62 | remoteView.setTextViewText(R.id.list_item_entry_summary, listItem.getCommand()); | ||||
63 | remoteView.setViewVisibility(R.id.list_item_entry_summary, View.VISIBLE); | ||||
64 | | ||||
65 | remoteView.setOnClickFillInIntent(R.id.list_item_entry, configIntent); | ||||
66 | } | ||||
67 | | ||||
68 | return remoteView; | ||||
69 | } | ||||
70 | | ||||
71 | @Override | ||||
72 | public RemoteViews getLoadingView() { | ||||
73 | return null; | ||||
74 | } | ||||
75 | | ||||
76 | @Override | ||||
77 | public int getViewTypeCount() { | ||||
78 | return 1; | ||||
79 | } | ||||
80 | | ||||
81 | @Override | ||||
82 | public long getItemId(int i) { | ||||
83 | if (RunCommandWidget.getCurrentDevice() != null) | ||||
84 | return RunCommandWidget.getCurrentDevice().getPlugin(RunCommandPlugin.class).getCommandItems().get(i).getKey().hashCode(); | ||||
85 | | ||||
86 | return 0; | ||||
87 | } | ||||
88 | | ||||
89 | @Override | ||||
90 | public boolean hasStableIds() { | ||||
91 | return false; | ||||
92 | } | ||||
93 | } | ||||
94 | No newline at end of file |