mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-28 20:57:42 +00:00
Simplify failed plugin list creation
Summary: Use some lambdas to simplify the code Test Plan: Denie some permissions, open permission explanation dialogs Reviewers: #kde_connect Subscribers: kdeconnect, mtijink, #kde_connect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D12232
This commit is contained in:
parent
158776456c
commit
a4e2af2c51
@ -277,7 +277,7 @@ public class DeviceFragment extends Fragment {
|
||||
|
||||
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.error_message_container).setVisibility((paired && !reachable) ? View.VISIBLE : View.GONE);
|
||||
@ -296,24 +296,9 @@ public class DeviceFragment extends Fragment {
|
||||
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);
|
||||
@ -419,7 +404,7 @@ public class DeviceFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
void createPluginsList(ConcurrentHashMap<String, Plugin> plugins, int headerText, PluginClickListener onClickListener) {
|
||||
void createPluginsList(ConcurrentHashMap<String, Plugin> plugins, int headerText, FailedPluginListItem.Action action) {
|
||||
if (!plugins.isEmpty()) {
|
||||
|
||||
TextView header = new TextView(mActivity);
|
||||
@ -441,35 +426,10 @@ public class DeviceFragment extends Fragment {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2018 Nicolas Fella <nicolas.fella@gmx.de>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user