Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Issue #2624: Reader view controls should hide when back button pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
csadilek authored and jonalmeida committed May 3, 2019
1 parent 7586cc1 commit 04dd505
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ class ReaderViewFeature(
override fun onBackPressed(): Boolean {
activeSession?.let {
if (it.readerMode) {
hideReaderView()
if (controlsPresenter.areControlsVisible()) {
hideControls()
} else {
hideReaderView()
}
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package mozilla.components.feature.readerview.internal

import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.readerview.view.ReaderViewControlsView
import mozilla.components.support.ktx.android.view.isVisible

/**
* Presenter implementation that will update the view whenever the feature is started.
Expand All @@ -28,6 +29,13 @@ internal class ReaderViewControlsPresenter(
}
}

/**
* Checks whether or not the ReaderView controls are visible.
*/
fun areControlsVisible(): Boolean {
return view.asView().isVisible()
}

/**
* Hides the controls.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package mozilla.components.feature.readerview

import android.content.Context
import android.view.View
import androidx.test.core.app.ApplicationProvider
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
Expand Down Expand Up @@ -402,6 +403,35 @@ class ReaderViewFeatureTest {
verify(readerViewFeature).showReaderView(eq(selectedSession))
}

@Test
fun `on back pressed closes controls then reader view`() {
val engine: Engine = mock()
val session: Session = mock()
val sessionManager: SessionManager = mock()
`when`(sessionManager.selectedSession).thenReturn(session)

val controlsView: ReaderViewControlsView = mock()
val view: View = mock()
`when`(controlsView.asView()).thenReturn(view)

val readerViewFeature = spy(ReaderViewFeature(context, engine, sessionManager, controlsView))
assertFalse(readerViewFeature.onBackPressed())

readerViewFeature.observeSelected()
assertFalse(readerViewFeature.onBackPressed())

`when`(session.readerMode).thenReturn(true)
`when`(view.visibility).thenReturn(View.VISIBLE)
assertTrue(readerViewFeature.onBackPressed())
verify(readerViewFeature, never()).hideReaderView()
verify(readerViewFeature, times(1)).hideControls()

`when`(view.visibility).thenReturn(View.GONE)
assertTrue(readerViewFeature.onBackPressed())
verify(readerViewFeature, times(1)).hideReaderView()
verify(readerViewFeature, times(1)).hideControls()
}

private fun prepareFeatureForTest(port: Port, session: Session = mock()): ReaderViewFeature {
val engine = mock(Engine::class.java)
val sessionManager: SessionManager = mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

package mozilla.components.feature.readerview.internal

import android.view.View
import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.readerview.view.ReaderViewControlsView
import mozilla.components.support.test.any
import mozilla.components.support.test.mock
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mockito.Mockito.`when`
import org.mockito.Mockito.verify
Expand All @@ -33,6 +36,20 @@ class ReaderViewControlsPresenterTest {
verify(view).showControls()
}

@Test
fun `are controls visible`() {
val controlsView: ReaderViewControlsView = mock()
val view: View = mock()
`when`(controlsView.asView()).thenReturn(view)
val presenter = ReaderViewControlsPresenter(controlsView, mock())

`when`(view.visibility).thenReturn(View.GONE)
assertFalse(presenter.areControlsVisible())

`when`(view.visibility).thenReturn(View.VISIBLE)
assertTrue(presenter.areControlsVisible())
}

@Test
fun `hide updates the visibility of the controls`() {
val view: ReaderViewControlsView = mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class ReaderViewIntegration(
}

override fun onBackPressed(): Boolean {
readerViewButton.setSelected(false)
return feature.onBackPressed()
}
}

0 comments on commit 04dd505

Please sign in to comment.