Merge pull request #6447 from thundernest/fix_reply_to_view
Fix "reply to" view appearing unexpectedly
This commit is contained in:
commit
b95e1655ca
3 changed files with 16 additions and 50 deletions
|
@ -53,9 +53,7 @@ class ReplyToPresenter(private val view: ReplyToView) {
|
|||
}
|
||||
|
||||
fun onNonRecipientFieldFocused() {
|
||||
if (view.isVisible && view.getAddresses().isEmpty()) {
|
||||
view.isVisible = false
|
||||
}
|
||||
view.hideIfBlank()
|
||||
}
|
||||
|
||||
fun onSaveInstanceState(outState: Bundle) {
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.fsck.k9.view.RecipientSelectView.Recipient
|
|||
private const val VIEW_INDEX_REPLY_TO_EXPANDER_VISIBLE = 0
|
||||
private const val VIEW_INDEX_REPLY_TO_EXPANDER_HIDDEN = 1
|
||||
|
||||
class ReplyToView(activity: MessageCompose) : View.OnClickListener {
|
||||
class ReplyToView(activity: MessageCompose) {
|
||||
private val replyToView: RecipientSelectView = activity.findViewById(R.id.reply_to)
|
||||
private val replyToWrapper: View = activity.findViewById(R.id.reply_to_wrapper)
|
||||
private val replyToDivider: View = activity.findViewById(R.id.reply_to_divider)
|
||||
|
@ -24,29 +24,33 @@ class ReplyToView(activity: MessageCompose) : View.OnClickListener {
|
|||
private val textWatchers = mutableSetOf<TextWatcher>()
|
||||
|
||||
init {
|
||||
replyToExpander.setOnClickListener(this)
|
||||
activity.findViewById<View>(R.id.reply_to_label).setOnClickListener(this)
|
||||
replyToExpander.setOnClickListener {
|
||||
isVisible = true
|
||||
replyToView.requestFocus()
|
||||
}
|
||||
|
||||
activity.findViewById<View>(R.id.reply_to_label).setOnClickListener {
|
||||
replyToView.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
var isVisible: Boolean
|
||||
get() = replyToView.isVisible
|
||||
get() = replyToWrapper.isVisible
|
||||
set(visible) {
|
||||
replyToDivider.isVisible = visible
|
||||
replyToView.isVisible = visible
|
||||
replyToWrapper.isVisible = visible
|
||||
|
||||
if (visible && replyToExpanderContainer.displayedChild == VIEW_INDEX_REPLY_TO_EXPANDER_VISIBLE) {
|
||||
replyToView.requestFocus()
|
||||
replyToExpanderContainer.displayedChild = VIEW_INDEX_REPLY_TO_EXPANDER_HIDDEN
|
||||
} else if (replyToExpanderContainer.displayedChild == VIEW_INDEX_REPLY_TO_EXPANDER_HIDDEN) {
|
||||
replyToExpanderContainer.displayedChild = VIEW_INDEX_REPLY_TO_EXPANDER_VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick(view: View) {
|
||||
when (view.id) {
|
||||
R.id.reply_to_expander -> isVisible = true
|
||||
R.id.reply_to_label -> replyToView.requestFocus()
|
||||
fun hideIfBlank() {
|
||||
if (isVisible && replyToView.text.isBlank()) {
|
||||
isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,12 @@ package com.fsck.k9.activity.compose
|
|||
|
||||
import android.os.Bundle
|
||||
import com.fsck.k9.Identity
|
||||
import com.fsck.k9.K9RobolectricTest
|
||||
import com.fsck.k9.RobolectricTest
|
||||
import com.fsck.k9.mail.Address
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.never
|
||||
import org.mockito.kotlin.stubbing
|
||||
import org.mockito.kotlin.verify
|
||||
|
||||
|
@ -16,7 +15,7 @@ private const val REPLY_TO_ADDRESS = "reply-to@example.com"
|
|||
private const val REPLY_TO_ADDRESS_2 = "reply-to2@example.com"
|
||||
private const val REPLY_TO_ADDRESS_3 = "reply-to3@example.com"
|
||||
|
||||
class ReplyToPresenterTest : K9RobolectricTest() {
|
||||
class ReplyToPresenterTest : RobolectricTest() {
|
||||
private val view = mock<ReplyToView>()
|
||||
private val replyToPresenter = ReplyToPresenter(view)
|
||||
|
||||
|
@ -115,39 +114,4 @@ class ReplyToPresenterTest : K9RobolectricTest() {
|
|||
verify(view).silentlyRemoveAddresses(Address.parse(replyToOne))
|
||||
verify(view).silentlyAddAddresses(Address.parse(replyToTwo))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnNonRecipientFieldFocused_notVisible_expectNoChange() {
|
||||
stubbing(view) {
|
||||
on { isVisible } doReturn false
|
||||
}
|
||||
|
||||
replyToPresenter.onNonRecipientFieldFocused()
|
||||
|
||||
verify(view, never()).isVisible = false
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnNonRecipientFieldFocused_noContentFieldVisible_expectHide() {
|
||||
stubbing(view) {
|
||||
on { isVisible } doReturn true
|
||||
on { getAddresses() } doReturn emptyArray()
|
||||
}
|
||||
|
||||
replyToPresenter.onNonRecipientFieldFocused()
|
||||
|
||||
verify(view).isVisible = false
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnNonRecipientFieldFocused_withContentFieldVisible_expectNoChange() {
|
||||
stubbing(view) {
|
||||
on { isVisible } doReturn true
|
||||
on { getAddresses() } doReturn Address.parse(REPLY_TO_ADDRESS)
|
||||
}
|
||||
|
||||
replyToPresenter.onNonRecipientFieldFocused()
|
||||
|
||||
verify(view, never()).isVisible = false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue