InternetPreferenceController V2 (1/n)

Refactor the InternetPreferenceController, migrate to repository and
flow, run data loading on background thread.

Only add Wifi summary for now.

Bug: 339884322
Flag: com.android.settings.flags.internet_preference_controller_v2
Test: manual - on Internet
Test: unit test
Change-Id: Ibd8911bc11b24d4a7e2ef320dea4d38b9c3a864f
This commit is contained in:
Chaohui Wang
2024-06-06 15:28:59 +08:00
parent 2ac12d024f
commit efa1f0e3ed
5 changed files with 249 additions and 5 deletions

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2024 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.network
import android.content.Context
import androidx.lifecycle.LifecycleOwner
import androidx.preference.Preference
import androidx.preference.PreferenceScreen
import com.android.settings.R
import com.android.settings.core.BasePreferenceController
import com.android.settings.wifi.WifiSummaryRepository
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
class InternetPreferenceControllerV2(context: Context, preferenceKey: String) :
BasePreferenceController(context, preferenceKey) {
private var preference: Preference? = null
override fun getAvailabilityStatus() =
if (mContext.resources.getBoolean(R.bool.config_show_internet_settings)) AVAILABLE
else UNSUPPORTED_ON_DEVICE
override fun displayPreference(screen: PreferenceScreen) {
super.displayPreference(screen)
preference = screen.findPreference(preferenceKey)
}
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
WifiSummaryRepository(mContext).summaryFlow()
.collectLatestWithLifecycle(viewLifecycleOwner) {
preference?.summary = it
}
}
}