Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4cbf887d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Convert SavedAccessPoints to DashboardFragment (step 1)"

parents 1d7ee9b9 d5547c68
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -2112,8 +2112,6 @@
    <string name="wifi_forget_dialog_message">All passwords for this network will be deleted</string>
    <!-- Wi-Fi Advanced Settings --> <skip />
    <!-- Wi-Fi settings screen, Saved networks, settings section.  This is a header shown above Saved networks wifi settings. [CHAR LIMIT=30] -->
    <string name="wifi_saved_access_points_titlebar">Saved networks</string>
    <!-- Wi-Fi settings screen, Saved networks summary.  This shows below the "Saved networks" item and indicates the number of networks a user has saved. -->
    <plurals name="wifi_saved_access_points_summary">
        <item quantity="one">1 network</item>
+10 −2
Original line number Diff line number Diff line
@@ -14,7 +14,15 @@
     limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/wifi_saved_access_points_titlebar">
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:key="saved_access_points"
    android:title="@string/wifi_saved_access_points_label">

    <PreferenceCategory
        android:key="saved_access_points_category"
        android:layout="@layout/preference_category_no_label"
        settings:controller="com.android.settings.wifi.savedaccesspoints.SavedAccessPointsPreferenceController"/>

</PreferenceScreen>
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.wifi.savedaccesspoints;


import android.content.Context;

import com.android.settings.core.BasePreferenceController;

/**
 * Controller that manages a PrferenceGroup, which contains a list of saved access points.
 */
public class SavedAccessPointsPreferenceController extends BasePreferenceController {

    public SavedAccessPointsPreferenceController(Context context,
            String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }
}
+23 −26
Original line number Diff line number Diff line
@@ -20,51 +20,38 @@ import android.annotation.Nullable;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.icu.text.Collator;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.wifi.WifiConfigUiBase;
import com.android.settings.wifi.WifiDialog;
import com.android.settings.wifi.WifiSettings;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.AccessPointPreference;
import com.android.settingslib.wifi.WifiSavedConfigUtils;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * UI to manage saved networks/access points.
 * TODO(b/64806699): convert to {@link DashboardFragment} with {@link PreferenceController}s
 */
public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
public class SavedAccessPointsWifiSettings extends DashboardFragment
        implements WifiDialog.WifiDialogListener {
    private static final String TAG = "SavedAccessPoints";
    @VisibleForTesting
    static final int MSG_UPDATE_PREFERENCES = 1;
    private static final Comparator<AccessPoint> SAVED_NETWORK_COMPARATOR =
            new Comparator<AccessPoint>() {
        final Collator mCollator = Collator.getInstance();
        @Override
        public int compare(AccessPoint ap1, AccessPoint ap2) {
            return mCollator.compare(
                    nullToEmpty(ap1.getConfigName()), nullToEmpty(ap2.getConfigName()));
        }

        private String nullToEmpty(String string) {
            return (string == null) ? "" : string;
        }
    };

    @VisibleForTesting
    final WifiManager.ActionListener mForgetListener = new WifiManager.ActionListener() {
@@ -94,6 +81,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
        public void onSuccess() {
            postUpdatePreference();
        }

        @Override
        public void onFailure(int reason) {
            Activity activity = getActivity();
@@ -122,9 +110,18 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.wifi_display_saved_access_points);
    protected int getPreferenceScreenResId() {
        return R.xml.wifi_display_saved_access_points;
    }

    @Override
    protected String getLogTag() {
        return TAG;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
    }

@@ -154,7 +151,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment

        final List<AccessPoint> accessPoints =
                WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
        Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
        Collections.sort(accessPoints, SavedNetworkComparator.INSTANCE);
        cacheRemoveAllPrefs(preferenceScreen);

        final int accessPointsSize = accessPoints.size();
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.wifi.savedaccesspoints;

import android.icu.text.Collator;

import com.android.settingslib.wifi.AccessPoint;

import java.util.Comparator;

public final class SavedNetworkComparator {
    public static final Comparator<AccessPoint> INSTANCE =
            new Comparator<AccessPoint>() {
                final Collator mCollator = Collator.getInstance();

                @Override
                public int compare(AccessPoint ap1, AccessPoint ap2) {
                    return mCollator.compare(
                            nullToEmpty(ap1.getConfigName()), nullToEmpty(ap2.getConfigName()));
                }

                private String nullToEmpty(String string) {
                    return (string == null) ? "" : string;
                }
            };
}
Loading