Loading src/com/android/documentsui/JobPanelController.kt +16 −8 Original line number Diff line number Diff line Loading @@ -156,6 +156,9 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() { /** Current menu item being controlled by this class. */ private var mMenuItem: MenuItem? = null /** Current panel popup shown if any. */ private var mPopup: PopupWindow? = null /** Adapter used to display JobProgresses in the recycler list. */ private var mProgressListAdapter: ProgressListAdapter? = null Loading @@ -165,6 +168,10 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() { } private fun updateMenuItem(animate: Boolean) { if (mState == State.INVISIBLE) { mPopup?.dismiss() } mMenuItem?.let { Menus.setEnabledAndVisible(it, mState != State.INVISIBLE) val icon = it.actionView as ProgressBar Loading Loading @@ -207,19 +214,20 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() { mProgressListAdapter = listAdapter val popupWidth = mContext.resources.getDimension(R.dimen.job_progress_panel_width) + mContext.resources.getDimension(R.dimen.job_progress_panel_margin) val popup = PopupWindow( mPopup = PopupWindow( /* contentView= */ panel, /* width= */ popupWidth.toInt(), /* height= */ ViewGroup.LayoutParams.WRAP_CONTENT, /* focusable= */ true ) popup.setOnDismissListener { mProgressListAdapter = null } popup.showAsDropDown( ).apply { setOnDismissListener { mProgressListAdapter = null } showAsDropDown( /* anchor= */ view, /* xoff= */ view.width - popupWidth.toInt(), /* yoff= */ 0 ) } } mMenuItem = menuItem updateMenuItem(animate = false) } Loading tests/functional/com/android/documentsui/JobPanelUiTest.kt +35 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.doesNotExist import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.BoundedMatcher import androidx.test.espresso.matcher.ViewMatchers.hasSibling import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText Loading @@ -41,6 +42,7 @@ import com.android.documentsui.services.JobProgress import com.android.documentsui.testing.MutableJobProgress import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers.allOf import org.junit.After import org.junit.Before import org.junit.Rule Loading Loading @@ -111,4 +113,37 @@ class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() { onView(withId(R.id.job_progress_item_title)).check(matches(withText("Job started"))) onView(withId(R.id.job_progress_item_progress)).check(matches(withProgress(40))) } @Test fun testJobPanelItemDismiss() { val progress1 = MutableJobProgress( id = "jobId1", state = Job.STATE_COMPLETED, msg = "Job1 completed", hasFailures = false, ) val progress2 = MutableJobProgress( id = "jobId2", state = Job.STATE_COMPLETED, msg = "Job2 completed", hasFailures = false, ) sendProgress(arrayListOf(progress1.toJobProgress(), progress2.toJobProgress())) onView(withId(R.id.option_menu_job_progress)) .check(matches(isDisplayed())) .perform(click()) onView(withId(R.id.job_progress_panel_title)).check(matches(isDisplayed())) // Dismiss the first item. onView(allOf(withId(R.id.job_progress_item_dismiss), hasSibling(withText(progress1.msg)))) .perform(click()) onView(withText(progress1.msg)).check(doesNotExist()) // Dismiss the second item. The panel should disappear. onView(allOf(withId(R.id.job_progress_item_dismiss), hasSibling(withText(progress2.msg)))) .perform(click()) onView(withId(R.id.option_menu_job_progress)).check(doesNotExist()) onView(withId(R.id.job_progress_panel_title)).check(doesNotExist()) } } Loading
src/com/android/documentsui/JobPanelController.kt +16 −8 Original line number Diff line number Diff line Loading @@ -156,6 +156,9 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() { /** Current menu item being controlled by this class. */ private var mMenuItem: MenuItem? = null /** Current panel popup shown if any. */ private var mPopup: PopupWindow? = null /** Adapter used to display JobProgresses in the recycler list. */ private var mProgressListAdapter: ProgressListAdapter? = null Loading @@ -165,6 +168,10 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() { } private fun updateMenuItem(animate: Boolean) { if (mState == State.INVISIBLE) { mPopup?.dismiss() } mMenuItem?.let { Menus.setEnabledAndVisible(it, mState != State.INVISIBLE) val icon = it.actionView as ProgressBar Loading Loading @@ -207,19 +214,20 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() { mProgressListAdapter = listAdapter val popupWidth = mContext.resources.getDimension(R.dimen.job_progress_panel_width) + mContext.resources.getDimension(R.dimen.job_progress_panel_margin) val popup = PopupWindow( mPopup = PopupWindow( /* contentView= */ panel, /* width= */ popupWidth.toInt(), /* height= */ ViewGroup.LayoutParams.WRAP_CONTENT, /* focusable= */ true ) popup.setOnDismissListener { mProgressListAdapter = null } popup.showAsDropDown( ).apply { setOnDismissListener { mProgressListAdapter = null } showAsDropDown( /* anchor= */ view, /* xoff= */ view.width - popupWidth.toInt(), /* yoff= */ 0 ) } } mMenuItem = menuItem updateMenuItem(animate = false) } Loading
tests/functional/com/android/documentsui/JobPanelUiTest.kt +35 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.doesNotExist import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.BoundedMatcher import androidx.test.espresso.matcher.ViewMatchers.hasSibling import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText Loading @@ -41,6 +42,7 @@ import com.android.documentsui.services.JobProgress import com.android.documentsui.testing.MutableJobProgress import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers.allOf import org.junit.After import org.junit.Before import org.junit.Rule Loading Loading @@ -111,4 +113,37 @@ class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() { onView(withId(R.id.job_progress_item_title)).check(matches(withText("Job started"))) onView(withId(R.id.job_progress_item_progress)).check(matches(withProgress(40))) } @Test fun testJobPanelItemDismiss() { val progress1 = MutableJobProgress( id = "jobId1", state = Job.STATE_COMPLETED, msg = "Job1 completed", hasFailures = false, ) val progress2 = MutableJobProgress( id = "jobId2", state = Job.STATE_COMPLETED, msg = "Job2 completed", hasFailures = false, ) sendProgress(arrayListOf(progress1.toJobProgress(), progress2.toJobProgress())) onView(withId(R.id.option_menu_job_progress)) .check(matches(isDisplayed())) .perform(click()) onView(withId(R.id.job_progress_panel_title)).check(matches(isDisplayed())) // Dismiss the first item. onView(allOf(withId(R.id.job_progress_item_dismiss), hasSibling(withText(progress1.msg)))) .perform(click()) onView(withText(progress1.msg)).check(doesNotExist()) // Dismiss the second item. The panel should disappear. onView(allOf(withId(R.id.job_progress_item_dismiss), hasSibling(withText(progress2.msg)))) .perform(click()) onView(withId(R.id.option_menu_job_progress)).check(doesNotExist()) onView(withId(R.id.job_progress_panel_title)).check(doesNotExist()) } }