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