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 {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.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.constraintlayout:constraintlayout:1.1.3'
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.google.zxing:core:3.3.3'

View File

@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.PreferenceScreen android:title="@string/about_title">
<PreferenceScreen android:title="@string/about_title">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.AboutActivity"/>
</androidx.preference.PreferenceScreen>
</PreferenceScreen>
<androidx.preference.PreferenceCategory android:title="@string/preference_category__my_apps">
<androidx.preference.PreferenceScreen android:title="@string/preference_manage_installed_apps">
<PreferenceCategory android:title="@string/preference_category__my_apps">
<PreferenceScreen android:title="@string/preference_manage_installed_apps">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.installed.InstalledAppsActivity"/>
</androidx.preference.PreferenceScreen>
<androidx.preference.PreferenceScreen
</PreferenceScreen>
<PreferenceScreen
android:title="@string/menu_manage"
android:summary="@string/repositories_summary">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.ManageReposActivity"/>
</androidx.preference.PreferenceScreen>
<androidx.preference.PreferenceScreen
</PreferenceScreen>
<PreferenceScreen
android:key="installHistory"
android:visible="false"
android:title="@string/install_history"
@ -33,10 +33,10 @@
android:action="android.intent.action.MAIN"
android:targetPackage="@string/applicationId"
android:targetClass="org.fdroid.fdroid.views.InstallHistoryActivity"/>
</androidx.preference.PreferenceScreen>
</androidx.preference.PreferenceCategory>
</PreferenceScreen>
</PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/updates">
<PreferenceCategory android:title="@string/updates">
<org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="overWifi"
android:title="@string/over_wifi"
@ -60,9 +60,9 @@
android:title="@string/notify"
android:defaultValue="true"
android:key="updateNotify"/>
</androidx.preference.PreferenceCategory>
</PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/display"
<PreferenceCategory android:title="@string/display"
android:key="pref_category_display">
<ListPreference
android:title="@string/pref_language"
@ -73,9 +73,9 @@
android:defaultValue="light"
android:entries="@array/themeNames"
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">
<SwitchPreference
android:title="@string/show_incompat_versions"
@ -89,9 +89,9 @@
android:title="@string/force_touch_apps"
android:defaultValue="false"
android:key="ignoreTouchscreen"/>
</androidx.preference.PreferenceCategory>
</PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/proxy">
<PreferenceCategory android:title="@string/proxy">
<SwitchPreference
android:key="useTor"
android:summary="@string/useTorSummary"
@ -111,9 +111,9 @@
android:title="@string/proxy_port"
android:summary="@string/proxy_port_summary"
android:dependency="enableProxy"/>
</androidx.preference.PreferenceCategory>
</PreferenceCategory>
<androidx.preference.PreferenceCategory
<PreferenceCategory
android:key="pref_category_privacy"
android:title="@string/privacy">
<SwitchPreference
@ -126,9 +126,9 @@
android:key="preventScreenshots"
android:summary="@string/preventScreenshots_summary"
android:title="@string/preventScreenshots_title"/>
</androidx.preference.PreferenceCategory>
</PreferenceCategory>
<androidx.preference.PreferenceCategory
<PreferenceCategory
android:title="@string/other"
android:key="pref_category_other">
<ListPreference
@ -177,6 +177,6 @@
android:key="privilegedInstaller"
android:persistent="false"
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 androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceFragment;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.CheckBoxPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import android.text.TextUtils;
import android.util.TypedValue;
import info.guardianproject.panic.Panic;
@ -33,7 +34,7 @@ import org.fdroid.fdroid.installer.PrivilegedInstaller;
import java.util.ArrayList;
import java.util.Set;
public class PanicPreferencesFragment extends PreferenceFragment
public class PanicPreferencesFragment extends PreferenceFragmentCompat
implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String PREF_APP = "pref_panic_app";

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<androidx.preference.CheckBoxPreference
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_panic_exit"
android:summary="@string/panic_exit_summary"
android:title="@string/panic_exit_title"/>
<androidx.preference.PreferenceCategory
<PreferenceCategory
android:key="pref_panic_destructive_actions"
android:title="@string/panic_destructive_actions">
<androidx.preference.ListPreference
<ListPreference
android:key="pref_panic_app"
android:summary="@string/panic_app_setting_summary"
android:title="@string/panic_app_setting_title"
@ -33,12 +33,12 @@
android:summary="@string/panic_reset_repos_summary"
android:title="@string/panic_reset_repos_title"/>
</androidx.preference.PreferenceCategory>
</PreferenceCategory>
<androidx.preference.PreferenceCategory
<PreferenceCategory
android:key="pref_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.Bundle;
import androidx.preference.PreferenceFragment;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import androidx.preference.CheckBoxPreference;
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.PrivilegedInstaller;
public class PreferencesFragment extends PreferenceFragment
public class PreferencesFragment extends PreferenceFragmentCompat
implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String TAG = "PreferencesFragment";

View File

@ -1,14 +1,14 @@
package org.fdroid.fdroid.views.main;
import android.annotation.TargetApi;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import androidx.appcompat.app.AppCompatActivity;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.fragment.app.FragmentTransaction;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.views.PreferencesFragment;
@ -58,7 +58,7 @@ public class SettingsView extends FrameLayout {
}
if (currentTransaction == null) {
currentTransaction = activity.getFragmentManager().beginTransaction();
currentTransaction = activity.getSupportFragmentManager().beginTransaction();
}
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");
}
Fragment existingFragment = activity.getFragmentManager().findFragmentByTag("preferences-fragment");
Fragment existingFragment = activity.getSupportFragmentManager().findFragmentByTag("preferences-fragment");
if (existingFragment == null) {
return;
}
if (currentTransaction == null) {
currentTransaction = activity.getFragmentManager().beginTransaction();
currentTransaction = activity.getSupportFragmentManager().beginTransaction();
}
currentTransaction.remove(existingFragment);
currentTransaction.commitAllowingStateLoss();

View File

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