1
0
Fork 0

For #10180: Remove touch delegate when button is disabled.

Also refactored multiple if's into a when.
master
mcarare 2020-04-24 16:05:46 +03:00 committed by Emily Kager
parent 3e13927c25
commit e830da59b7
2 changed files with 36 additions and 15 deletions

View File

@ -18,6 +18,7 @@ import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.top.sites.TopSite import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.components.tips.Tip import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.ext.removeAndDisable import org.mozilla.fenix.ext.removeAndDisable
import org.mozilla.fenix.ext.removeTouchDelegate
import org.mozilla.fenix.home.OnboardingState import org.mozilla.fenix.home.OnboardingState
import org.mozilla.fenix.home.Tab import org.mozilla.fenix.home.Tab
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionHeaderViewHolder import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionHeaderViewHolder
@ -255,6 +256,7 @@ class SessionControlAdapter(
(holder as TabViewHolder).updateTab(it.tab) (holder as TabViewHolder).updateTab(it.tab)
// Always set the visibility to GONE to avoid the play button sticking around from previous draws // Always set the visibility to GONE to avoid the play button sticking around from previous draws
holder.play_pause_button.removeTouchDelegate()
holder.play_pause_button.removeAndDisable() holder.play_pause_button.removeAndDisable()
if (it.shouldUpdateHostname) { holder.updateHostname(it.tab.hostname) } if (it.shouldUpdateHostname) { holder.updateHostname(it.tab.hostname) }

View File

@ -20,6 +20,7 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.increaseTapArea import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.loadIntoView import org.mozilla.fenix.ext.loadIntoView
import org.mozilla.fenix.ext.removeAndDisable import org.mozilla.fenix.ext.removeAndDisable
import org.mozilla.fenix.ext.removeTouchDelegate
import org.mozilla.fenix.ext.showAndEnable import org.mozilla.fenix.ext.showAndEnable
import org.mozilla.fenix.home.Tab import org.mozilla.fenix.home.Tab
import org.mozilla.fenix.home.sessioncontrol.TabSessionInteractor import org.mozilla.fenix.home.sessioncontrol.TabSessionInteractor
@ -48,8 +49,6 @@ class TabViewHolder(
interactor.onCloseTab(tab?.sessionId!!) interactor.onCloseTab(tab?.sessionId!!)
} }
play_pause_button.increaseTapArea(PLAY_PAUSE_BUTTON_EXTRA_DPS)
play_pause_button.setOnClickListener { play_pause_button.setOnClickListener {
when (tab?.mediaState) { when (tab?.mediaState) {
MediaState.State.PLAYING -> { MediaState.State.PLAYING -> {
@ -95,20 +94,38 @@ class TabViewHolder(
internal fun updatePlayPauseButton(mediaState: MediaState.State) { internal fun updatePlayPauseButton(mediaState: MediaState.State) {
with(play_pause_button) { with(play_pause_button) {
if (mediaState == MediaState.State.PLAYING || mediaState == MediaState.State.PAUSED) { invalidate()
this.showAndEnable() when (mediaState) {
} else { MediaState.State.PAUSED -> {
this.removeAndDisable() showAndEnable()
} play_pause_button.increaseTapArea(PLAY_PAUSE_BUTTON_EXTRA_DPS)
contentDescription =
context.getString(R.string.mozac_feature_media_notification_action_play)
setImageDrawable(
AppCompatResources.getDrawable(
context,
R.drawable.play_with_background
)
)
}
if (mediaState == MediaState.State.PLAYING) { MediaState.State.PLAYING -> {
play_pause_button.contentDescription = showAndEnable()
context.getString(R.string.mozac_feature_media_notification_action_pause) play_pause_button.increaseTapArea(PLAY_PAUSE_BUTTON_EXTRA_DPS)
setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.pause_with_background)) contentDescription =
} else { context.getString(R.string.mozac_feature_media_notification_action_pause)
play_pause_button.contentDescription = setImageDrawable(
context.getString(R.string.mozac_feature_media_notification_action_play) AppCompatResources.getDrawable(
setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.play_with_background)) context,
R.drawable.pause_with_background
)
)
}
MediaState.State.NONE -> {
removeTouchDelegate()
removeAndDisable()
}
} }
} }
} }
@ -116,6 +133,7 @@ class TabViewHolder(
internal fun updateTab(tab: Tab) { internal fun updateTab(tab: Tab) {
this.tab = tab this.tab = tab
} }
internal fun updateTitle(text: String) { internal fun updateTitle(text: String) {
tab_title.text = text tab_title.text = text
} }
@ -135,6 +153,7 @@ class TabViewHolder(
internal fun updateSelected(selected: Boolean) { internal fun updateSelected(selected: Boolean) {
selected_border.visibility = if (selected) View.VISIBLE else View.GONE selected_border.visibility = if (selected) View.VISIBLE else View.GONE
} }
internal fun updateCloseButtonDescription(title: String) { internal fun updateCloseButtonDescription(title: String) {
close_tab_button.contentDescription = close_tab_button.contentDescription =
close_tab_button.context.getString(R.string.close_tab_title, title) close_tab_button.context.getString(R.string.close_tab_title, title)