Loading src/com/android/documentsui/JobPanelController.kt +25 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ import android.widget.ProgressBar import android.widget.TextView import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.ListAdapter Loading Loading @@ -78,7 +80,8 @@ private class VerticalMarginItemDecoration( class JobPanelController( private val activityContext: Context, private val viewModel: JobPanelViewModel, ) : BroadcastReceiver() { ) : BroadcastReceiver(), DefaultLifecycleObserver { companion object { private const val TAG = "JobPanelController" private const val MAX_PROGRESS = 100 Loading Loading @@ -324,6 +327,10 @@ class JobPanelController( )) itemAnimator = null adapter = listAdapter if (viewModel.listState != null) { layoutManager?.onRestoreInstanceState(viewModel.listState) viewModel.listState = null } } progressListAdapter = listAdapter val popupWidth = Loading @@ -338,7 +345,10 @@ class JobPanelController( /* height= */ ViewGroup.LayoutParams.WRAP_CONTENT, /* focusable= */ true ).apply { setOnDismissListener { progressListAdapter = null } setOnDismissListener { progressListAdapter = null popup = null } showAsDropDown( /* anchor= */ view, /* xoff= */ 0, Loading @@ -347,11 +357,24 @@ class JobPanelController( ) } } // Restore the popup if we had saved state. if (viewModel.listState != null) { progressIcon.callOnClick() } menuItem = newMenuItem // Don't animate for the initial state update. updateMenuItem(viewModel.getMenuState(), animate = false) } override fun onDestroy(owner: LifecycleOwner) { // We need to save the popup's UI state and manually dismiss the popup, as it somehow // stays alive even if the activity is destroyed due to a configuration change. viewModel.listState = popup?.contentView ?.findViewById<RecyclerView>(R.id.job_progress_list)?.layoutManager ?.onSaveInstanceState() popup?.dismiss() } override fun onReceive(context: Context?, intent: Intent) { val progresses = intent.getParcelableArrayListExtra( FileOperationService.EXTRA_PROGRESS, Loading src/com/android/documentsui/JobPanelViewModel.kt +2 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.documentsui import android.os.Parcelable import android.util.Log import androidx.lifecycle.ViewModel import com.android.documentsui.base.SharedMinimal.DEBUG Loading Loading @@ -49,6 +50,7 @@ class JobPanelViewModel : ViewModel() { /** List of jobs currently tracked. */ private val _currentJobs = LinkedHashMap<String, ProgressViewModel>() val currentJobs: Map<String, ProgressViewModel> get() = _currentJobs var listState: Parcelable? = null /** * Gets the state of the toolbar progress icon based off the current jobs tracked. Loading src/com/android/documentsui/files/FilesActivity.java +4 −2 Original line number Diff line number Diff line Loading @@ -148,8 +148,10 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler mInjector.getModel()::getItemUri, mInjector.getModel()::getItemCount); if (isVisualSignalsFlagEnabled()) { menuManager.setJobPanelController(new JobPanelController(this, new ViewModelProvider(this).get(JobPanelViewModel.class))); JobPanelController jobPanelController = new JobPanelController(this, new ViewModelProvider(this).get(JobPanelViewModel.class)); getLifecycle().addObserver(jobPanelController); menuManager.setJobPanelController(jobPanelController); } mInjector.menuManager = menuManager; Loading Loading
src/com/android/documentsui/JobPanelController.kt +25 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ import android.widget.ProgressBar import android.widget.TextView import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.ListAdapter Loading Loading @@ -78,7 +80,8 @@ private class VerticalMarginItemDecoration( class JobPanelController( private val activityContext: Context, private val viewModel: JobPanelViewModel, ) : BroadcastReceiver() { ) : BroadcastReceiver(), DefaultLifecycleObserver { companion object { private const val TAG = "JobPanelController" private const val MAX_PROGRESS = 100 Loading Loading @@ -324,6 +327,10 @@ class JobPanelController( )) itemAnimator = null adapter = listAdapter if (viewModel.listState != null) { layoutManager?.onRestoreInstanceState(viewModel.listState) viewModel.listState = null } } progressListAdapter = listAdapter val popupWidth = Loading @@ -338,7 +345,10 @@ class JobPanelController( /* height= */ ViewGroup.LayoutParams.WRAP_CONTENT, /* focusable= */ true ).apply { setOnDismissListener { progressListAdapter = null } setOnDismissListener { progressListAdapter = null popup = null } showAsDropDown( /* anchor= */ view, /* xoff= */ 0, Loading @@ -347,11 +357,24 @@ class JobPanelController( ) } } // Restore the popup if we had saved state. if (viewModel.listState != null) { progressIcon.callOnClick() } menuItem = newMenuItem // Don't animate for the initial state update. updateMenuItem(viewModel.getMenuState(), animate = false) } override fun onDestroy(owner: LifecycleOwner) { // We need to save the popup's UI state and manually dismiss the popup, as it somehow // stays alive even if the activity is destroyed due to a configuration change. viewModel.listState = popup?.contentView ?.findViewById<RecyclerView>(R.id.job_progress_list)?.layoutManager ?.onSaveInstanceState() popup?.dismiss() } override fun onReceive(context: Context?, intent: Intent) { val progresses = intent.getParcelableArrayListExtra( FileOperationService.EXTRA_PROGRESS, Loading
src/com/android/documentsui/JobPanelViewModel.kt +2 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.documentsui import android.os.Parcelable import android.util.Log import androidx.lifecycle.ViewModel import com.android.documentsui.base.SharedMinimal.DEBUG Loading Loading @@ -49,6 +50,7 @@ class JobPanelViewModel : ViewModel() { /** List of jobs currently tracked. */ private val _currentJobs = LinkedHashMap<String, ProgressViewModel>() val currentJobs: Map<String, ProgressViewModel> get() = _currentJobs var listState: Parcelable? = null /** * Gets the state of the toolbar progress icon based off the current jobs tracked. Loading
src/com/android/documentsui/files/FilesActivity.java +4 −2 Original line number Diff line number Diff line Loading @@ -148,8 +148,10 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler mInjector.getModel()::getItemUri, mInjector.getModel()::getItemCount); if (isVisualSignalsFlagEnabled()) { menuManager.setJobPanelController(new JobPanelController(this, new ViewModelProvider(this).get(JobPanelViewModel.class))); JobPanelController jobPanelController = new JobPanelController(this, new ViewModelProvider(this).get(JobPanelViewModel.class)); getLifecycle().addObserver(jobPanelController); menuManager.setJobPanelController(jobPanelController); } mInjector.menuManager = menuManager; Loading