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

Commit 3472a285 authored by Austin Tankiang's avatar Austin Tankiang
Browse files

Hide popup when all jobs are dismissed

Bug: 407674482
Test: atest -c 'DocumentsUIGoogleTests:com.android.documentsui.JobPanelUiTest'
Flag: com.android.documentsui.flags.visual_signals_ro
Change-Id: Id7184e03e33f65550903a19cbdf4a3125a587785
parent ba14c86e
Loading
Loading
Loading
Loading
+16 −8
Original line number Original line Diff line number Diff line
@@ -156,6 +156,9 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() {
    /** Current menu item being controlled by this class. */
    /** Current menu item being controlled by this class. */
    private var mMenuItem: MenuItem? = null
    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. */
    /** Adapter used to display JobProgresses in the recycler list. */
    private var mProgressListAdapter: ProgressListAdapter? = null
    private var mProgressListAdapter: ProgressListAdapter? = null


@@ -165,6 +168,10 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() {
    }
    }


    private fun updateMenuItem(animate: Boolean) {
    private fun updateMenuItem(animate: Boolean) {
        if (mState == State.INVISIBLE) {
            mPopup?.dismiss()
        }

        mMenuItem?.let {
        mMenuItem?.let {
            Menus.setEnabledAndVisible(it, mState != State.INVISIBLE)
            Menus.setEnabledAndVisible(it, mState != State.INVISIBLE)
            val icon = it.actionView as ProgressBar
            val icon = it.actionView as ProgressBar
@@ -207,19 +214,20 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() {
            mProgressListAdapter = listAdapter
            mProgressListAdapter = listAdapter
            val popupWidth = mContext.resources.getDimension(R.dimen.job_progress_panel_width) +
            val popupWidth = mContext.resources.getDimension(R.dimen.job_progress_panel_width) +
                    mContext.resources.getDimension(R.dimen.job_progress_panel_margin)
                    mContext.resources.getDimension(R.dimen.job_progress_panel_margin)
            val popup = PopupWindow(
            mPopup = PopupWindow(
                /* contentView= */ panel,
                /* contentView= */ panel,
                /* width= */ popupWidth.toInt(),
                /* width= */ popupWidth.toInt(),
                /* height= */ ViewGroup.LayoutParams.WRAP_CONTENT,
                /* height= */ ViewGroup.LayoutParams.WRAP_CONTENT,
                /* focusable= */ true
                /* focusable= */ true
            )
            ).apply {
            popup.setOnDismissListener { mProgressListAdapter = null }
                setOnDismissListener { mProgressListAdapter = null }
            popup.showAsDropDown(
                showAsDropDown(
                    /* anchor= */ view,
                    /* anchor= */ view,
                    /* xoff= */ view.width - popupWidth.toInt(),
                    /* xoff= */ view.width - popupWidth.toInt(),
                    /* yoff= */ 0
                    /* yoff= */ 0
                )
                )
            }
            }
        }
        mMenuItem = menuItem
        mMenuItem = menuItem
        updateMenuItem(animate = false)
        updateMenuItem(animate = false)
    }
    }
+35 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.BoundedMatcher
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.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.withText
@@ -41,6 +42,7 @@ import com.android.documentsui.services.JobProgress
import com.android.documentsui.testing.MutableJobProgress
import com.android.documentsui.testing.MutableJobProgress
import org.hamcrest.Description
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.junit.After
import org.junit.After
import org.junit.Before
import org.junit.Before
import org.junit.Rule
import org.junit.Rule
@@ -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_title)).check(matches(withText("Job started")))
        onView(withId(R.id.job_progress_item_progress)).check(matches(withProgress(40)))
        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())
    }
}
}