Use androidx.preference artifact

- use PreferenceFragmentCompat
- this requires androidx Fragments
- explicit declaration of androidx widgets in preferences.xml
  no longer required
This commit is contained in:
Dominik Schürmann 2020-07-01 21:42:23 +02:00
parent 8f81bf0cb9
commit 78e81fb781
7 changed files with 74 additions and 70 deletions

View File

@ -136,16 +136,18 @@ android {
dependencies { dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.gridlayout:gridlayout:1.0.0' implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0' implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0' implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.palette:palette:1.0.0' implementation 'androidx.palette:palette:1.0.0'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'com.google.zxing:core:3.3.3' implementation 'com.google.zxing:core:3.3.3'

View File

@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.PreferenceScreen android:title="@string/about_title"> <PreferenceScreen android:title="@string/about_title">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.AboutActivity"/> android:targetClass="org.fdroid.fdroid.AboutActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
<androidx.preference.PreferenceCategory android:title="@string/preference_category__my_apps"> <PreferenceCategory android:title="@string/preference_category__my_apps">
<androidx.preference.PreferenceScreen android:title="@string/preference_manage_installed_apps"> <PreferenceScreen android:title="@string/preference_manage_installed_apps">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.installed.InstalledAppsActivity"/> android:targetClass="org.fdroid.fdroid.views.installed.InstalledAppsActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
<androidx.preference.PreferenceScreen <PreferenceScreen
android:title="@string/menu_manage" android:title="@string/menu_manage"
android:summary="@string/repositories_summary"> android:summary="@string/repositories_summary">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.ManageReposActivity"/> android:targetClass="org.fdroid.fdroid.views.ManageReposActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
<androidx.preference.PreferenceScreen <PreferenceScreen
android:key="installHistory" android:key="installHistory"
android:visible="false" android:visible="false"
android:title="@string/install_history" android:title="@string/install_history"
@ -33,10 +33,10 @@
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.InstallHistoryActivity"/> android:targetClass="org.fdroid.fdroid.views.InstallHistoryActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/updates"> <PreferenceCategory android:title="@string/updates">
<org.fdroid.fdroid.views.LiveSeekBarPreference <org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="overWifi" android:key="overWifi"
android:title="@string/over_wifi" android:title="@string/over_wifi"
@ -60,9 +60,9 @@
android:title="@string/notify" android:title="@string/notify"
android:defaultValue="true" android:defaultValue="true"
android:key="updateNotify"/> android:key="updateNotify"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/display" <PreferenceCategory android:title="@string/display"
android:key="pref_category_display"> android:key="pref_category_display">
<ListPreference <ListPreference
android:title="@string/pref_language" android:title="@string/pref_language"
@ -73,9 +73,9 @@
android:defaultValue="light" android:defaultValue="light"
android:entries="@array/themeNames" android:entries="@array/themeNames"
android:entryValues="@array/themeValues"/> android:entryValues="@array/themeValues"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/appcompatibility" <PreferenceCategory android:title="@string/appcompatibility"
android:key="pref_category_appcompatibility"> android:key="pref_category_appcompatibility">
<SwitchPreference <SwitchPreference
android:title="@string/show_incompat_versions" android:title="@string/show_incompat_versions"
@ -89,9 +89,9 @@
android:title="@string/force_touch_apps" android:title="@string/force_touch_apps"
android:defaultValue="false" android:defaultValue="false"
android:key="ignoreTouchscreen"/> android:key="ignoreTouchscreen"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/proxy"> <PreferenceCategory android:title="@string/proxy">
<SwitchPreference <SwitchPreference
android:key="useTor" android:key="useTor"
android:summary="@string/useTorSummary" android:summary="@string/useTorSummary"
@ -111,9 +111,9 @@
android:title="@string/proxy_port" android:title="@string/proxy_port"
android:summary="@string/proxy_port_summary" android:summary="@string/proxy_port_summary"
android:dependency="enableProxy"/> android:dependency="enableProxy"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory <PreferenceCategory
android:key="pref_category_privacy" android:key="pref_category_privacy"
android:title="@string/privacy"> android:title="@string/privacy">
<SwitchPreference <SwitchPreference
@ -126,9 +126,9 @@
android:key="preventScreenshots" android:key="preventScreenshots"
android:summary="@string/preventScreenshots_summary" android:summary="@string/preventScreenshots_summary"
android:title="@string/preventScreenshots_title"/> android:title="@string/preventScreenshots_title"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory <PreferenceCategory
android:title="@string/other" android:title="@string/other"
android:key="pref_category_other"> android:key="pref_category_other">
<ListPreference <ListPreference
@ -177,6 +177,6 @@
android:key="privilegedInstaller" android:key="privilegedInstaller"
android:persistent="false" android:persistent="false"
android:dependency="expert"/> android:dependency="expert"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
</androidx.preference.PreferenceScreen> </PreferenceScreen>

View File

@ -15,13 +15,14 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.ColorInt; import androidx.annotation.ColorInt;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.preference.PreferenceFragment;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.preference.CheckBoxPreference; import androidx.preference.CheckBoxPreference;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.TypedValue; import android.util.TypedValue;
import info.guardianproject.panic.Panic; import info.guardianproject.panic.Panic;
@ -33,7 +34,7 @@ import org.fdroid.fdroid.installer.PrivilegedInstaller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
public class PanicPreferencesFragment extends PreferenceFragment public class PanicPreferencesFragment extends PreferenceFragmentCompat
implements SharedPreferences.OnSharedPreferenceChangeListener { implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String PREF_APP = "pref_panic_app"; private static final String PREF_APP = "pref_panic_app";

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<androidx.preference.CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="pref_panic_exit" android:key="pref_panic_exit"
android:summary="@string/panic_exit_summary" android:summary="@string/panic_exit_summary"
android:title="@string/panic_exit_title"/> android:title="@string/panic_exit_title"/>
<androidx.preference.PreferenceCategory <PreferenceCategory
android:key="pref_panic_destructive_actions" android:key="pref_panic_destructive_actions"
android:title="@string/panic_destructive_actions"> android:title="@string/panic_destructive_actions">
<androidx.preference.ListPreference <ListPreference
android:key="pref_panic_app" android:key="pref_panic_app"
android:summary="@string/panic_app_setting_summary" android:summary="@string/panic_app_setting_summary"
android:title="@string/panic_app_setting_title" android:title="@string/panic_app_setting_title"
@ -33,12 +33,12 @@
android:summary="@string/panic_reset_repos_summary" android:summary="@string/panic_reset_repos_summary"
android:title="@string/panic_reset_repos_title"/> android:title="@string/panic_reset_repos_title"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory <PreferenceCategory
android:key="pref_panic_apps_to_uninstall" android:key="pref_panic_apps_to_uninstall"
android:title="@string/panic_apps_to_uninstall"> android:title="@string/panic_apps_to_uninstall">
</androidx.preference.PreferenceCategory> </PreferenceCategory>
</androidx.preference.PreferenceScreen> </PreferenceScreen>

View File

@ -34,6 +34,7 @@ import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.preference.PreferenceFragment; import androidx.preference.PreferenceFragment;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import androidx.preference.CheckBoxPreference; import androidx.preference.CheckBoxPreference;
import androidx.preference.EditTextPreference; import androidx.preference.EditTextPreference;
@ -59,7 +60,7 @@ import org.fdroid.fdroid.data.RepoProvider;
import org.fdroid.fdroid.installer.InstallHistoryService; import org.fdroid.fdroid.installer.InstallHistoryService;
import org.fdroid.fdroid.installer.PrivilegedInstaller; import org.fdroid.fdroid.installer.PrivilegedInstaller;
public class PreferencesFragment extends PreferenceFragment public class PreferencesFragment extends PreferenceFragmentCompat
implements SharedPreferences.OnSharedPreferenceChangeListener { implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String TAG = "PreferencesFragment"; public static final String TAG = "PreferencesFragment";

View File

@ -1,14 +1,14 @@
package org.fdroid.fdroid.views.main; package org.fdroid.fdroid.views.main;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context; import android.content.Context;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.fragment.app.FragmentTransaction;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.views.PreferencesFragment; import org.fdroid.fdroid.views.PreferencesFragment;
@ -58,7 +58,7 @@ public class SettingsView extends FrameLayout {
} }
if (currentTransaction == null) { if (currentTransaction == null) {
currentTransaction = activity.getFragmentManager().beginTransaction(); currentTransaction = activity.getSupportFragmentManager().beginTransaction();
} }
currentTransaction.replace(getId(), new PreferencesFragment(), "preferences-fragment"); currentTransaction.replace(getId(), new PreferencesFragment(), "preferences-fragment");
@ -76,13 +76,13 @@ public class SettingsView extends FrameLayout {
throw new IllegalArgumentException("Cannot add a SettingsView to activities which are not an AppCompatActivity"); throw new IllegalArgumentException("Cannot add a SettingsView to activities which are not an AppCompatActivity");
} }
Fragment existingFragment = activity.getFragmentManager().findFragmentByTag("preferences-fragment"); Fragment existingFragment = activity.getSupportFragmentManager().findFragmentByTag("preferences-fragment");
if (existingFragment == null) { if (existingFragment == null) {
return; return;
} }
if (currentTransaction == null) { if (currentTransaction == null) {
currentTransaction = activity.getFragmentManager().beginTransaction(); currentTransaction = activity.getSupportFragmentManager().beginTransaction();
} }
currentTransaction.remove(existingFragment); currentTransaction.remove(existingFragment);
currentTransaction.commitAllowingStateLoss(); currentTransaction.commitAllowingStateLoss();

View File

@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.PreferenceScreen android:title="@string/about_title"> <PreferenceScreen android:title="@string/about_title">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.AboutActivity"/> android:targetClass="org.fdroid.fdroid.AboutActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
<androidx.preference.PreferenceCategory android:title="@string/preference_category__my_apps"> <PreferenceCategory android:title="@string/preference_category__my_apps">
<androidx.preference.PreferenceScreen android:title="@string/preference_manage_installed_apps"> <PreferenceScreen android:title="@string/preference_manage_installed_apps">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.installed.InstalledAppsActivity"/> android:targetClass="org.fdroid.fdroid.views.installed.InstalledAppsActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
<androidx.preference.PreferenceScreen <PreferenceScreen
android:title="@string/menu_manage" android:title="@string/menu_manage"
android:summary="@string/repositories_summary"> android:summary="@string/repositories_summary">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.ManageReposActivity"/> android:targetClass="org.fdroid.fdroid.views.ManageReposActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
<androidx.preference.PreferenceScreen <PreferenceScreen
android:key="installHistory" android:key="installHistory"
android:visible="false" android:visible="false"
android:title="@string/install_history" android:title="@string/install_history"
@ -33,10 +33,10 @@
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId" android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.InstallHistoryActivity"/> android:targetClass="org.fdroid.fdroid.views.InstallHistoryActivity"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/updates"> <PreferenceCategory android:title="@string/updates">
<org.fdroid.fdroid.views.LiveSeekBarPreference <org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="overWifi" android:key="overWifi"
android:title="@string/over_wifi" android:title="@string/over_wifi"
@ -60,9 +60,9 @@
android:title="@string/notify" android:title="@string/notify"
android:defaultValue="true" android:defaultValue="true"
android:key="updateNotify"/> android:key="updateNotify"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/display" <PreferenceCategory android:title="@string/display"
android:key="pref_category_display"> android:key="pref_category_display">
<ListPreference <ListPreference
android:title="@string/pref_language" android:title="@string/pref_language"
@ -73,9 +73,9 @@
android:defaultValue="light" android:defaultValue="light"
android:entries="@array/themeNames" android:entries="@array/themeNames"
android:entryValues="@array/themeValues"/> android:entryValues="@array/themeValues"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/appcompatibility" <PreferenceCategory android:title="@string/appcompatibility"
android:key="pref_category_appcompatibility"> android:key="pref_category_appcompatibility">
<SwitchPreference <SwitchPreference
android:title="@string/show_incompat_versions" android:title="@string/show_incompat_versions"
@ -89,9 +89,9 @@
android:title="@string/force_touch_apps" android:title="@string/force_touch_apps"
android:defaultValue="false" android:defaultValue="false"
android:key="ignoreTouchscreen"/> android:key="ignoreTouchscreen"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/local_repo"> <PreferenceCategory android:title="@string/local_repo">
<EditTextPreference <EditTextPreference
android:key="localRepoName" android:key="localRepoName"
android:title="@string/local_repo_name"/> android:title="@string/local_repo_name"/>
@ -100,9 +100,9 @@
android:defaultValue="true" android:defaultValue="true"
android:title="@string/scan_removable_storage_title" android:title="@string/scan_removable_storage_title"
android:summary="@string/scan_removable_storage_summary"/> android:summary="@string/scan_removable_storage_summary"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/proxy"> <PreferenceCategory android:title="@string/proxy">
<SwitchPreference <SwitchPreference
android:key="useTor" android:key="useTor"
android:summary="@string/useTorSummary" android:summary="@string/useTorSummary"
@ -122,9 +122,9 @@
android:title="@string/proxy_port" android:title="@string/proxy_port"
android:summary="@string/proxy_port_summary" android:summary="@string/proxy_port_summary"
android:dependency="enableProxy"/> android:dependency="enableProxy"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory <PreferenceCategory
android:key="pref_category_privacy" android:key="pref_category_privacy"
android:title="@string/privacy"> android:title="@string/privacy">
<SwitchPreference <SwitchPreference
@ -144,17 +144,17 @@
android:summary="@string/hide_on_long_search_press_summary" android:summary="@string/hide_on_long_search_press_summary"
android:title="@string/hide_on_long_search_press_title"/> android:title="@string/hide_on_long_search_press_title"/>
<androidx.preference.PreferenceScreen <PreferenceScreen
android:summary="@string/panic_settings_summary" android:summary="@string/panic_settings_summary"
android:title="@string/panic_settings"> android:title="@string/panic_settings">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetClass="org.fdroid.fdroid.panic.PanicPreferencesActivity" android:targetClass="org.fdroid.fdroid.panic.PanicPreferencesActivity"
android:targetPackage="@string/applicationId"/> android:targetPackage="@string/applicationId"/>
</androidx.preference.PreferenceScreen> </PreferenceScreen>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
<androidx.preference.PreferenceCategory <PreferenceCategory
android:title="@string/other" android:title="@string/other"
android:key="pref_category_other"> android:key="pref_category_other">
<ListPreference <ListPreference
@ -208,6 +208,6 @@
android:key="privilegedInstaller" android:key="privilegedInstaller"
android:persistent="false" android:persistent="false"
android:dependency="expert"/> android:dependency="expert"/>
</androidx.preference.PreferenceCategory> </PreferenceCategory>
</androidx.preference.PreferenceScreen> </PreferenceScreen>