From 54e5224f2066e1e9cb03788fd472a3f30c93fadb Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Wed, 28 Dec 2022 19:24:07 +0100 Subject: [PATCH] Fix minifier deleting "unused" xml that were actually used --- .../FindMyPhonePlugin/FindMyPhonePlugin.java | 2 +- .../FindMyPhoneSettingsFragment.java | 4 ++-- .../Plugins/MousePadPlugin/MousePadPlugin.java | 6 ++++++ .../Plugins/MprisPlugin/MprisPlugin.java | 6 ++++++ src/org/kde/kdeconnect/Plugins/Plugin.java | 3 ++- .../RemoteKeyboardPlugin.java | 7 +++++++ .../Plugins/SMSPlugin/SMSPlugin.java | 7 +++++++ .../Plugins/SftpPlugin/SftpPlugin.java | 2 +- .../SftpPlugin/SftpSettingsFragment.java | 4 ++-- .../Plugins/SharePlugin/SharePlugin.java | 2 +- .../SharePlugin/ShareSettingsFragment.java | 4 ++-- .../TelephonyPlugin/TelephonyPlugin.java | 7 +++++++ .../UserInterface/PluginSettingsFragment.java | 18 +++++++++++------- 13 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java index 59d8e106..e9beb9ad 100644 --- a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java @@ -211,6 +211,6 @@ public class FindMyPhonePlugin extends Plugin { @Override public PluginSettingsFragment getSettingsFragment(Activity activity) { - return FindMyPhoneSettingsFragment.newInstance(getPluginKey()); + return FindMyPhoneSettingsFragment.newInstance(getPluginKey(), R.xml.findmyphoneplugin_preferences); } } diff --git a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneSettingsFragment.java b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneSettingsFragment.java index f9aed9d4..334ac52f 100644 --- a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneSettingsFragment.java +++ b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneSettingsFragment.java @@ -28,9 +28,9 @@ public class FindMyPhoneSettingsFragment extends PluginSettingsFragment { private SharedPreferences sharedPreferences; private Preference ringtonePreference; - public static FindMyPhoneSettingsFragment newInstance(@NonNull String pluginKey) { + public static FindMyPhoneSettingsFragment newInstance(@NonNull String pluginKey, int layout) { FindMyPhoneSettingsFragment fragment = new FindMyPhoneSettingsFragment(); - fragment.setArguments(pluginKey); + fragment.setArguments(pluginKey, layout); return fragment; } diff --git a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java index d2b403d1..cb8380f3 100644 --- a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java @@ -13,6 +13,7 @@ import android.graphics.drawable.Drawable; import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.Plugins.PluginFactory; +import org.kde.kdeconnect.UserInterface.PluginSettingsFragment; import org.kde.kdeconnect_tp.R; import androidx.core.content.ContextCompat; @@ -54,6 +55,11 @@ public class MousePadPlugin extends Plugin { return true; } + @Override + public PluginSettingsFragment getSettingsFragment(Activity activity) { + return PluginSettingsFragment.newInstance(getPluginKey(), R.xml.mousepadplugin_preferences); + } + @Override public boolean hasMainActivity() { return true; diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java index 97e4b370..060658af 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -19,6 +19,7 @@ import androidx.core.content.ContextCompat; import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.Plugins.PluginFactory; +import org.kde.kdeconnect.UserInterface.PluginSettingsFragment; import org.kde.kdeconnect_tp.R; import java.net.MalformedURLException; @@ -254,6 +255,11 @@ public class MprisPlugin extends Plugin { return true; } + @Override + public PluginSettingsFragment getSettingsFragment(Activity activity) { + return PluginSettingsFragment.newInstance(getPluginKey(), R.xml.mprisplugin_preferences); + } + @Override public boolean onCreate() { MprisMediaSession.getInstance().onCreate(context.getApplicationContext(), this, device.getDeviceId()); diff --git a/src/org/kde/kdeconnect/Plugins/Plugin.java b/src/org/kde/kdeconnect/Plugins/Plugin.java index 9f70666b..09b01c59 100644 --- a/src/org/kde/kdeconnect/Plugins/Plugin.java +++ b/src/org/kde/kdeconnect/Plugins/Plugin.java @@ -166,7 +166,8 @@ public abstract class Plugin { * @return The PluginSettingsFragment used to display this plugins settings */ public PluginSettingsFragment getSettingsFragment(Activity activity) { - return PluginSettingsFragment.newInstance(getPluginKey()); + throw new RuntimeException("Plugin doesn't reimplement getSettingsFragment: " + getPluginKey()); + } /** diff --git a/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java b/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java index a9c6fd6f..f9f97106 100644 --- a/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java @@ -6,6 +6,7 @@ package org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin; +import android.app.Activity; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.os.SystemClock; @@ -24,6 +25,7 @@ import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.Plugins.PluginFactory; import org.kde.kdeconnect.UserInterface.MainActivity; import org.kde.kdeconnect.UserInterface.StartActivityAlertDialogFragment; +import org.kde.kdeconnect.UserInterface.PluginSettingsFragment; import org.kde.kdeconnect_tp.R; import java.util.ArrayList; @@ -159,6 +161,11 @@ public class RemoteKeyboardPlugin extends Plugin implements SharedPreferences.On return true; } + @Override + public PluginSettingsFragment getSettingsFragment(Activity activity) { + return PluginSettingsFragment.newInstance(getPluginKey(), R.xml.remotekeyboardplugin_preferences); + } + @Override public boolean hasMainActivity() { return false; diff --git a/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java b/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java index 4422e037..13e07054 100644 --- a/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java @@ -8,6 +8,7 @@ package org.kde.kdeconnect.Plugins.SMSPlugin; +import android.app.Activity; import android.Manifest; import android.annotation.SuppressLint; import android.content.BroadcastReceiver; @@ -36,6 +37,7 @@ import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.Plugins.PluginFactory; import org.kde.kdeconnect.Plugins.TelephonyPlugin.TelephonyPlugin; +import org.kde.kdeconnect.UserInterface.PluginSettingsFragment; import org.kde.kdeconnect_tp.BuildConfig; import org.kde.kdeconnect_tp.R; @@ -557,6 +559,11 @@ public class SMSPlugin extends Plugin { return true; } + @Override + public PluginSettingsFragment getSettingsFragment(Activity activity) { + return PluginSettingsFragment.newInstance(getPluginKey(), R.xml.smsplugin_preferences); + } + @Override public String[] getSupportedPacketTypes() { return new String[]{ diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java index deecff82..eb9f2506 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java @@ -263,7 +263,7 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref @Override public PluginSettingsFragment getSettingsFragment(Activity activity) { - return SftpSettingsFragment.newInstance(getPluginKey()); + return SftpSettingsFragment.newInstance(getPluginKey(), R.xml.sftpplugin_preferences); } @Override diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java index 91602fea..cf1b89dc 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java @@ -64,9 +64,9 @@ public class SftpSettingsFragment private ActionMode actionMode; private JSONObject savedActionModeState; - public static SftpSettingsFragment newInstance(@NonNull String pluginKey) { + public static SftpSettingsFragment newInstance(@NonNull String pluginKey, int layout) { SftpSettingsFragment fragment = new SftpSettingsFragment(); - fragment.setArguments(pluginKey); + fragment.setArguments(pluginKey, layout); return fragment; } diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index dcb718f1..b30419fa 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -197,7 +197,7 @@ public class SharePlugin extends Plugin { @Override public PluginSettingsFragment getSettingsFragment(Activity activity) { - return ShareSettingsFragment.newInstance(getPluginKey()); + return ShareSettingsFragment.newInstance(getPluginKey(), R.xml.shareplugin_preferences); } void sendUriList(final ArrayList uriList) { diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java index 1ef3cb86..abe0ecfe 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java @@ -37,9 +37,9 @@ public class ShareSettingsFragment extends PluginSettingsFragment { private Preference filePicker; - public static ShareSettingsFragment newInstance(@NonNull String pluginKey) { + public static ShareSettingsFragment newInstance(@NonNull String pluginKey, int layout) { ShareSettingsFragment fragment = new ShareSettingsFragment(); - fragment.setArguments(pluginKey); + fragment.setArguments(pluginKey, layout); return fragment; } diff --git a/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java b/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java index d4ea3a0f..a8672f9d 100644 --- a/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java @@ -6,6 +6,7 @@ package org.kde.kdeconnect.Plugins.TelephonyPlugin; +import android.app.Activity; import android.Manifest; import android.content.BroadcastReceiver; import android.content.Context; @@ -26,6 +27,7 @@ import org.kde.kdeconnect.Helpers.ContactsHelper; import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.Plugins.PluginFactory; +import org.kde.kdeconnect.UserInterface.PluginSettingsFragment; import org.kde.kdeconnect_tp.R; import java.util.Map; @@ -318,4 +320,9 @@ public class TelephonyPlugin extends Plugin { public boolean hasSettings() { return true; } + + @Override + public PluginSettingsFragment getSettingsFragment(Activity activity) { + return PluginSettingsFragment.newInstance(getPluginKey(), R.xml.telephonyplugin_preferences); + } } diff --git a/src/org/kde/kdeconnect/UserInterface/PluginSettingsFragment.java b/src/org/kde/kdeconnect/UserInterface/PluginSettingsFragment.java index 0fd27ef1..03b2356f 100644 --- a/src/org/kde/kdeconnect/UserInterface/PluginSettingsFragment.java +++ b/src/org/kde/kdeconnect/UserInterface/PluginSettingsFragment.java @@ -18,28 +18,33 @@ import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.Plugins.PluginFactory; import org.kde.kdeconnect_tp.R; +import android.util.Log; import java.util.Locale; public class PluginSettingsFragment extends PreferenceFragmentCompat { private static final String ARG_PLUGIN_KEY = "plugin_key"; + private static final String ARG_LAYOUT = "layout"; private String pluginKey; + private int layout; protected Device device; protected Plugin plugin; - public static PluginSettingsFragment newInstance(@NonNull String pluginKey) { + public static PluginSettingsFragment newInstance(@NonNull String pluginKey, int settingsLayout) { PluginSettingsFragment fragment = new PluginSettingsFragment(); - fragment.setArguments(pluginKey); + fragment.setArguments(pluginKey, settingsLayout); return fragment; } public PluginSettingsFragment() {} - protected Bundle setArguments(@NonNull String pluginKey) { + protected Bundle setArguments(@NonNull String pluginKey, int settingsLayout) { Bundle args = new Bundle(); args.putString(ARG_PLUGIN_KEY, pluginKey); + args.putInt(ARG_LAYOUT, settingsLayout); + setArguments(args); @@ -52,7 +57,8 @@ public class PluginSettingsFragment extends PreferenceFragmentCompat { throw new RuntimeException("You must provide a pluginKey by calling setArguments(@NonNull String pluginKey)"); } - pluginKey = getArguments().getString(ARG_PLUGIN_KEY); + this.pluginKey = getArguments().getString(ARG_PLUGIN_KEY); + this.layout = getArguments().getInt(ARG_LAYOUT); this.device = getDeviceOrThrow(getDeviceId()); this.plugin = device.getPlugin(pluginKey); @@ -67,9 +73,7 @@ public class PluginSettingsFragment extends PreferenceFragmentCompat { prefsManager.setSharedPreferencesMode(Context.MODE_PRIVATE); } - int resFile = getResources().getIdentifier(pluginKey.toLowerCase(Locale.ENGLISH) + "_preferences", "xml", - requireContext().getPackageName()); - addPreferencesFromResource(resFile); + addPreferencesFromResource(layout); } @Override