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

Commit d9a37220 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Refresh the DataUsageList when resume

Like when back from AppDataUsage page.

Bug: 295260929
Test: manual - on DataUsageList
Change-Id: I0b1698e47f06cbe731794a2a6b04e9c9ac9450d8
parent 55b8e790
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
            return Unit.INSTANCE;
        });
        if (mCycles != null) {
            Log.d(TAG, "setInitialCycles: " + mCycles + " " + mSelectedCycle);
            controller.setInitialCycles(mCycles, mSelectedCycle);
        }
    }
+0 −4
Original line number Diff line number Diff line
@@ -17,9 +17,7 @@
package com.android.settings.datausage

import android.content.Context
import android.util.SparseBooleanArray
import androidx.annotation.OpenForTesting
import androidx.core.util.keyIterator
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
@@ -27,8 +25,6 @@ import androidx.lifecycle.repeatOnLifecycle
import androidx.preference.PreferenceGroup
import androidx.preference.PreferenceScreen
import com.android.settings.core.BasePreferenceController
import com.android.settings.datausage.lib.AppDataUsageRepository.Companion.getAppUid
import com.android.settings.datausage.lib.AppDataUsageRepository.Companion.getAppUidList
import com.android.settings.datausage.lib.AppPreferenceRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+1 −10
Original line number Diff line number Diff line
@@ -55,9 +55,6 @@ open class DataUsageList : DataUsageBaseFragment(), MobileDataEnabledListener.Cl
    @VisibleForTesting
    var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID

    // Spinner will keep the selected cycle even after paused, this only keeps the displayed cycle,
    // which need be cleared when resumed.
    private var lastDisplayedUsageData: NetworkUsageData? = null
    private lateinit var usageAmount: Preference
    private var subscriptionInfoEntity: SubscriptionInfoEntity? = null
    private lateinit var dataUsageListAppsController: DataUsageListAppsController
@@ -77,7 +74,7 @@ open class DataUsageList : DataUsageBaseFragment(), MobileDataEnabledListener.Cl
            finish()
            return
        }
        billingCycleRepository = createBillingCycleRepository();
        billingCycleRepository = createBillingCycleRepository()
        if (!billingCycleRepository.isBandwidthControlEnabled()) {
            Log.w(TAG, "No bandwidth control; leaving")
            finish()
@@ -120,7 +117,6 @@ open class DataUsageList : DataUsageBaseFragment(), MobileDataEnabledListener.Cl
    override fun onResume() {
        super.onResume()
        dataStateListener.start(subId)
        lastDisplayedUsageData = null
        updatePolicy()
    }

@@ -188,11 +184,6 @@ open class DataUsageList : DataUsageBaseFragment(), MobileDataEnabledListener.Cl
     * Updates the chart and detail data when initial loaded or selected cycle changed.
     */
    private fun updateSelectedCycle(usageData: NetworkUsageData) {
        if (usageData == lastDisplayedUsageData) {
            // Avoid duplicate update to avoid page flash.
            return
        }
        lastDisplayedUsageData = usageData
        Log.d(TAG, "showing cycle $usageData")

        usageAmount.title = usageData.getDataUsedString(requireContext())
+22 −16
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ open class DataUsageListHeaderController(
    sourceMetricsCategory: Int,
    viewLifecycleOwner: LifecycleOwner,
    private val onCyclesLoad: (usageDataList: List<NetworkUsageData>) -> Unit,
    private val onItemSelected: (usageData: NetworkUsageData) -> Unit,
    private val updateSelectedCycle: (usageData: NetworkUsageData) -> Unit,
    private val repository: INetworkCycleDataRepository =
        NetworkCycleDataRepository(header.context, template),
) {
@@ -53,6 +53,17 @@ open class DataUsageListHeaderController(

    private val configureButton: View = header.requireViewById(R.id.filter_settings)
    private val cycleSpinner: Spinner = header.requireViewById(R.id.filter_spinner)

    private val cycleListener = object : AdapterView.OnItemSelectedListener {
        override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
            setSelectedCycle(position)
        }

        override fun onNothingSelected(parent: AdapterView<*>?) {
            // ignored
        }
    }

    private val cycleAdapter = CycleAdapter(context, object : SpinnerInterface {
        override fun setAdapter(cycleAdapter: CycleAdapter) {
            cycleSpinner.adapter = cycleAdapter
@@ -62,21 +73,15 @@ open class DataUsageListHeaderController(

        override fun setSelection(position: Int) {
            cycleSpinner.setSelection(position)
        }
    })
    private var cycles: List<NetworkUsageData> = emptyList()

    private val cycleListener = object : AdapterView.OnItemSelectedListener {
        override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
            if (0 <= position && position < cycleAdapter.count) {
                cycles.getOrNull(position)?.let(onItemSelected)
            if (cycleSpinner.onItemSelectedListener == null) {
                cycleSpinner.onItemSelectedListener = cycleListener
            } else {
                setSelectedCycle(position)
            }
        }
    })

        override fun onNothingSelected(parent: AdapterView<*>?) {
            // ignored
        }
    }
    private var cycles: List<NetworkUsageData> = emptyList()

    init {
        configureButton.setOnClickListener {
@@ -114,11 +119,12 @@ open class DataUsageListHeaderController(
    }

    private fun updateCycleData() {
        cycleSpinner.onItemSelectedListener = cycleListener
        // calculate policy cycles based on available data
        // generate cycle list based on policy and available history
        cycleAdapter.updateCycleList(cycles.map { Range(it.startTime, it.endTime) })
        cycleSpinner.visibility = View.VISIBLE
        onCyclesLoad(cycles)
    }

    private fun setSelectedCycle(position: Int) {
        cycles.getOrNull(position)?.let(updateSelectedCycle)
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ class AppDataUsageRepository(

    private fun bindStats(
        buckets: List<Bucket>,
        profiles: MutableList<UserHandle>,
        profiles: List<UserHandle>,
        knownItems: SparseArray<AppItem>,
        items: ArrayList<AppItem>,
    ) {
Loading