diff --git a/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java b/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java
--- a/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java
+++ b/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java
@@ -15,23 +15,21 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
+ * along with this program. If not, see .
+ */
package org.kde.kdeconnect.UserInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
-import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@@ -279,7 +277,7 @@
boolean paired = device.isPaired();
boolean reachable = device.isReachable();
- boolean onData = NetworkHelper.isOnMobileNetwork(getContext());
+ boolean onData = NetworkHelper.isOnMobileNetwork(DeviceFragment.this.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);
@@ -297,24 +295,9 @@
pluginListItems.add(new PluginItem(p, v -> p.startMainActivity(mActivity)));
}
- createPluginsList(device.getFailedPlugins(), R.string.plugins_failed_to_load, new PluginClickListener() {
- @Override
- void action() {
- plugin.getErrorDialog(mActivity).show();
- }
- });
- createPluginsList(device.getPluginsWithoutPermissions(), R.string.plugins_need_permission, new PluginClickListener() {
- @Override
- void action() {
- plugin.getPermissionExplanationDialog(mActivity).show();
- }
- });
- createPluginsList(device.getPluginsWithoutOptionalPermissions(), R.string.plugins_need_optional_permission, new PluginClickListener() {
- @Override
- void action() {
- plugin.getOptionalPermissionExplanationDialog(mActivity).show();
- }
- });
+ DeviceFragment.this.createPluginsList(device.getFailedPlugins(), R.string.plugins_failed_to_load, (plugin) -> plugin.getErrorDialog(mActivity).show());
+ DeviceFragment.this.createPluginsList(device.getPluginsWithoutPermissions(), R.string.plugins_need_permission, (plugin) -> plugin.getPermissionExplanationDialog(mActivity).show());
+ DeviceFragment.this.createPluginsList(device.getPluginsWithoutOptionalPermissions(), R.string.plugins_need_optional_permission, (plugin) -> plugin.getOptionalPermissionExplanationDialog(mActivity).show());
ListView buttonsList = (ListView) rootView.findViewById(R.id.buttons_list);
ListAdapter adapter = new ListAdapter(mActivity, pluginListItems);
@@ -420,7 +403,7 @@
});
}
- void createPluginsList(ConcurrentHashMap plugins, int headerText, PluginClickListener onClickListener) {
+ void createPluginsList(ConcurrentHashMap plugins, int headerText, FailedPluginListItem.Action action) {
if (!plugins.isEmpty()) {
TextView header = new TextView(mActivity);
@@ -442,35 +425,10 @@
if (plugin == null) {
pluginListItems.add(new SmallEntryItem(pluginKey));
} else {
- PluginClickListener listener = onClickListener.clone();
- listener.plugin = plugin;
- pluginListItems.add(new SmallEntryItem(plugin.getDisplayName(), listener));
+ pluginListItems.add(new FailedPluginListItem(plugin, action));
}
}
}
}
}
-
- private abstract class PluginClickListener implements View.OnClickListener, Cloneable {
-
- Plugin plugin;
-
- @Override
- public void onClick(View v) {
- action();
- }
-
- @Override
- public PluginClickListener clone() {
- try {
- return (PluginClickListener) super.clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- abstract void action();
- }
-
}
diff --git a/src/org/kde/kdeconnect/UserInterface/FailedPluginListItem.java b/src/org/kde/kdeconnect/UserInterface/FailedPluginListItem.java
new file mode 100644
--- /dev/null
+++ b/src/org/kde/kdeconnect/UserInterface/FailedPluginListItem.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018 Nicolas Fella
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.kde.kdeconnect.UserInterface;
+
+import org.kde.kdeconnect.Plugins.Plugin;
+import org.kde.kdeconnect.UserInterface.List.SmallEntryItem;
+
+class FailedPluginListItem extends SmallEntryItem {
+
+ interface Action {
+ void action(Plugin plugin);
+ }
+
+ FailedPluginListItem(Plugin plugin, Action action) {
+ super(plugin.getDisplayName(), (view) -> action.action(plugin));
+ }
+}