Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/UserInterface/PluginPreference.java
Show All 23 Lines | 17 | public PluginPreference(final SettingsActivity activity, final String pluginKey, final Device device) { | |||
---|---|---|---|---|---|
24 | 24 | | |||
25 | PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(activity, pluginKey); | 25 | PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(activity, pluginKey); | ||
26 | setTitle(info.getDisplayName()); | 26 | setTitle(info.getDisplayName()); | ||
27 | setSummary(info.getDescription()); | 27 | setSummary(info.getDescription()); | ||
28 | setChecked(device.isPluginEnabled(pluginKey)); | 28 | setChecked(device.isPluginEnabled(pluginKey)); | ||
29 | 29 | | |||
30 | Plugin plugin = device.getPlugin(pluginKey, true); | 30 | Plugin plugin = device.getPlugin(pluginKey, true); | ||
31 | if (info.hasSettings() && plugin != null) { | 31 | if (info.hasSettings() && plugin != null) { | ||
32 | this.listener = new View.OnClickListener() { | 32 | this.listener = v -> { | ||
33 | @Override | 33 | Plugin plugin1 = device.getPlugin(pluginKey, true); | ||
34 | public void onClick(View v) { | 34 | if (plugin1 != null) { | ||
35 | Plugin plugin = device.getPlugin(pluginKey, true); | 35 | plugin1.startPreferencesActivity(activity); | ||
36 | if (plugin != null) { | | |||
37 | plugin.startPreferencesActivity(activity); | | |||
38 | } else { //Could happen if the device is not connected anymore | 36 | } else { //Could happen if the device is not connected anymore | ||
39 | activity.finish(); //End this activity so we go to the "device not reachable" screen | 37 | activity.finish(); //End this activity so we go to the "device not reachable" screen | ||
40 | } | 38 | } | ||
41 | } | | |||
42 | }; | 39 | }; | ||
43 | } else { | 40 | } else { | ||
44 | this.listener = null; | 41 | this.listener = null; | ||
45 | } | 42 | } | ||
46 | 43 | | |||
47 | } | 44 | } | ||
48 | 45 | | |||
49 | @Override | 46 | @Override | ||
50 | protected void onBindView(View root) { | 47 | protected void onBindView(View root) { | ||
51 | super.onBindView(root); | 48 | super.onBindView(root); | ||
52 | final View button = root.findViewById(R.id.settingsButton); | 49 | final View button = root.findViewById(R.id.settingsButton); | ||
53 | 50 | | |||
54 | if (listener == null) { | 51 | if (listener == null) { | ||
55 | button.setVisibility(View.GONE); | 52 | button.setVisibility(View.GONE); | ||
56 | } else { | 53 | } else { | ||
57 | button.setEnabled(isChecked()); | 54 | button.setEnabled(isChecked()); | ||
58 | button.setOnClickListener(listener); | 55 | button.setOnClickListener(listener); | ||
59 | } | 56 | } | ||
60 | 57 | | |||
61 | root.setOnClickListener(new View.OnClickListener() { | 58 | root.setOnClickListener(v -> { | ||
62 | @Override | | |||
63 | public void onClick(View v) { | | |||
64 | boolean newState = !device.isPluginEnabled(pluginKey); | 59 | boolean newState = !device.isPluginEnabled(pluginKey); | ||
65 | setChecked(newState); //It actually works on API<14 | 60 | setChecked(newState); //It actually works on API<14 | ||
66 | button.setEnabled(newState); | 61 | button.setEnabled(newState); | ||
67 | device.setPluginEnabled(pluginKey, newState); | 62 | device.setPluginEnabled(pluginKey, newState); | ||
68 | } | | |||
69 | }); | 63 | }); | ||
70 | } | 64 | } | ||
71 | 65 | | |||
72 | } | 66 | } |