2021-03-26 14:33:46 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2021-05-10 20:24:04 +00:00
|
|
|
package org.mozilla.fenix.tabstray.browser
|
2021-03-26 14:33:46 +00:00
|
|
|
|
Support tab movement/reordering (#22751)
* Adds basic support for tab reordering via drag-and-drop selected tabs
* ktlint/detekt formatting
* Use defaultTabsFilter (now not private) instead of getter
* Convert from position+filter API to target+placeAfter
Unfortunately I still need the filter passed around a bit
* Handle inactive tabs' holder being children of the RecyclerView of the normal tabs
Don't go through LayoutManager needlessly
* Non-working use tabID the whole way. Does not compile.
* Fix to do direct tab ID and use grid setting directly
* Remove non-null assertion. Now fully works for "other" tabs.
* Prevent grouped tabs from being dragged
* Remove unused import
* Add/fix comments
* Do API version check and use deprecated startDrag if too old.
* Build process fails: both outdated and too new, so reverting to just too new
* Use deprecated function and suppress warning
* fix space
* Suppress "TooManyFunctions" on DefaultTabsTrayController
* Repeatedly update tab movement during drag
* Remove multi-tab movement, only allow dragging if tab groups disabled, fix tab positioning during movement
I'm forced to suppress LongParameterList to get the settings information where it needs to go though
* Remove settings argument and corresponding long args suppression: instead get settings from parent AbstractBrowserTrayList's context
* New UI: Select a tab and then, while holding down, start dragging
* Revert to using before/after boolean to accomodate delays
Move drag transparency to start of drag
* Use new BlankDragShadowBuilder and DraggableItemAnimator to handle tab movement
* Replace Pair<>s with data classes
* Only drag if exactly 1 tab selected, don't consume drag event if not used
* Auto-scroll tab tray while dragging near top/bottom edge
* Remove unexpected scrolling on tab bind (triggered when tab is selected)
* Fix broken scroll behavior during dragging
* Cleanup for ktlint/detekt
* Constantly set elevation during drag in case of update
Clean code at drag start
* Add custom drag start behavior
* Add drag distance constant, do all touch-drag behavior in OnTouchListener
* Disable parent vertical scrolling on drag start, fix detekt ComplexCondition
* Minor cleanup/comments
* Revert removal of scroll on bind, this was related to something different
* Correction to prepareForDrop to match documentation- doesn't seem to have any effect
* Simplify via unchecked typecast, use ViewCompat
* Use ViewConfiguration.scaledTouchSlop instead of arbitrary 30px
* Added tabReorderingFeature flag, split drag interactor to separate function to satisfy complexity requirement
Co-authored-by: Steven Knipe <ssk97@case.edu>
Co-authored-by: ssk97 <knipesteven@gmail.com>
Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
2021-12-08 16:36:49 +00:00
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.graphics.PointF
|
|
|
|
import android.view.MotionEvent
|
2021-03-26 14:33:46 +00:00
|
|
|
import android.view.View
|
Support tab movement/reordering (#22751)
* Adds basic support for tab reordering via drag-and-drop selected tabs
* ktlint/detekt formatting
* Use defaultTabsFilter (now not private) instead of getter
* Convert from position+filter API to target+placeAfter
Unfortunately I still need the filter passed around a bit
* Handle inactive tabs' holder being children of the RecyclerView of the normal tabs
Don't go through LayoutManager needlessly
* Non-working use tabID the whole way. Does not compile.
* Fix to do direct tab ID and use grid setting directly
* Remove non-null assertion. Now fully works for "other" tabs.
* Prevent grouped tabs from being dragged
* Remove unused import
* Add/fix comments
* Do API version check and use deprecated startDrag if too old.
* Build process fails: both outdated and too new, so reverting to just too new
* Use deprecated function and suppress warning
* fix space
* Suppress "TooManyFunctions" on DefaultTabsTrayController
* Repeatedly update tab movement during drag
* Remove multi-tab movement, only allow dragging if tab groups disabled, fix tab positioning during movement
I'm forced to suppress LongParameterList to get the settings information where it needs to go though
* Remove settings argument and corresponding long args suppression: instead get settings from parent AbstractBrowserTrayList's context
* New UI: Select a tab and then, while holding down, start dragging
* Revert to using before/after boolean to accomodate delays
Move drag transparency to start of drag
* Use new BlankDragShadowBuilder and DraggableItemAnimator to handle tab movement
* Replace Pair<>s with data classes
* Only drag if exactly 1 tab selected, don't consume drag event if not used
* Auto-scroll tab tray while dragging near top/bottom edge
* Remove unexpected scrolling on tab bind (triggered when tab is selected)
* Fix broken scroll behavior during dragging
* Cleanup for ktlint/detekt
* Constantly set elevation during drag in case of update
Clean code at drag start
* Add custom drag start behavior
* Add drag distance constant, do all touch-drag behavior in OnTouchListener
* Disable parent vertical scrolling on drag start, fix detekt ComplexCondition
* Minor cleanup/comments
* Revert removal of scroll on bind, this was related to something different
* Correction to prepareForDrop to match documentation- doesn't seem to have any effect
* Simplify via unchecked typecast, use ViewCompat
* Use ViewConfiguration.scaledTouchSlop instead of arbitrary 30px
* Added tabReorderingFeature flag, split drag interactor to separate function to satisfy complexity requirement
Co-authored-by: Steven Knipe <ssk97@case.edu>
Co-authored-by: ssk97 <knipesteven@gmail.com>
Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
2021-12-08 16:36:49 +00:00
|
|
|
import android.view.ViewConfiguration
|
2021-03-26 14:33:46 +00:00
|
|
|
import android.widget.ImageButton
|
|
|
|
import android.widget.ImageView
|
|
|
|
import android.widget.TextView
|
|
|
|
import androidx.annotation.VisibleForTesting
|
|
|
|
import androidx.appcompat.content.res.AppCompatResources
|
|
|
|
import androidx.appcompat.widget.AppCompatImageButton
|
Support tab movement/reordering (#22751)
* Adds basic support for tab reordering via drag-and-drop selected tabs
* ktlint/detekt formatting
* Use defaultTabsFilter (now not private) instead of getter
* Convert from position+filter API to target+placeAfter
Unfortunately I still need the filter passed around a bit
* Handle inactive tabs' holder being children of the RecyclerView of the normal tabs
Don't go through LayoutManager needlessly
* Non-working use tabID the whole way. Does not compile.
* Fix to do direct tab ID and use grid setting directly
* Remove non-null assertion. Now fully works for "other" tabs.
* Prevent grouped tabs from being dragged
* Remove unused import
* Add/fix comments
* Do API version check and use deprecated startDrag if too old.
* Build process fails: both outdated and too new, so reverting to just too new
* Use deprecated function and suppress warning
* fix space
* Suppress "TooManyFunctions" on DefaultTabsTrayController
* Repeatedly update tab movement during drag
* Remove multi-tab movement, only allow dragging if tab groups disabled, fix tab positioning during movement
I'm forced to suppress LongParameterList to get the settings information where it needs to go though
* Remove settings argument and corresponding long args suppression: instead get settings from parent AbstractBrowserTrayList's context
* New UI: Select a tab and then, while holding down, start dragging
* Revert to using before/after boolean to accomodate delays
Move drag transparency to start of drag
* Use new BlankDragShadowBuilder and DraggableItemAnimator to handle tab movement
* Replace Pair<>s with data classes
* Only drag if exactly 1 tab selected, don't consume drag event if not used
* Auto-scroll tab tray while dragging near top/bottom edge
* Remove unexpected scrolling on tab bind (triggered when tab is selected)
* Fix broken scroll behavior during dragging
* Cleanup for ktlint/detekt
* Constantly set elevation during drag in case of update
Clean code at drag start
* Add custom drag start behavior
* Add drag distance constant, do all touch-drag behavior in OnTouchListener
* Disable parent vertical scrolling on drag start, fix detekt ComplexCondition
* Minor cleanup/comments
* Revert removal of scroll on bind, this was related to something different
* Correction to prepareForDrop to match documentation- doesn't seem to have any effect
* Simplify via unchecked typecast, use ViewCompat
* Use ViewConfiguration.scaledTouchSlop instead of arbitrary 30px
* Added tabReorderingFeature flag, split drag interactor to separate function to satisfy complexity requirement
Co-authored-by: Steven Knipe <ssk97@case.edu>
Co-authored-by: ssk97 <knipesteven@gmail.com>
Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
2021-12-08 16:36:49 +00:00
|
|
|
import androidx.core.view.ViewCompat
|
2021-04-03 06:13:12 +00:00
|
|
|
import androidx.core.view.isInvisible
|
2021-03-25 21:22:41 +00:00
|
|
|
import androidx.core.view.isVisible
|
2021-03-26 14:33:46 +00:00
|
|
|
import mozilla.components.browser.state.selector.findTabOrCustomTab
|
2021-10-18 18:29:38 +00:00
|
|
|
import mozilla.components.browser.state.state.TabSessionState
|
2021-03-26 14:33:46 +00:00
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
2022-05-18 02:08:16 +00:00
|
|
|
import mozilla.components.browser.tabstray.SelectableTabViewHolder
|
2021-10-18 18:29:38 +00:00
|
|
|
import mozilla.components.browser.tabstray.TabsTray
|
2021-03-26 14:33:46 +00:00
|
|
|
import mozilla.components.browser.tabstray.TabsTrayStyling
|
|
|
|
import mozilla.components.browser.tabstray.thumbnail.TabThumbnailView
|
|
|
|
import mozilla.components.concept.base.images.ImageLoadRequest
|
|
|
|
import mozilla.components.concept.base.images.ImageLoader
|
|
|
|
import mozilla.components.concept.engine.mediasession.MediaSession
|
2022-10-11 17:56:50 +00:00
|
|
|
import mozilla.components.support.ktx.kotlin.MAX_URI_LENGTH
|
2022-03-09 12:11:47 +00:00
|
|
|
import mozilla.telemetry.glean.private.NoExtras
|
2022-04-05 12:21:41 +00:00
|
|
|
import org.mozilla.fenix.GleanMetrics.Tab
|
2021-03-26 14:33:46 +00:00
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.increaseTapArea
|
|
|
|
import org.mozilla.fenix.ext.removeAndDisable
|
|
|
|
import org.mozilla.fenix.ext.removeTouchDelegate
|
|
|
|
import org.mozilla.fenix.ext.showAndEnable
|
|
|
|
import org.mozilla.fenix.ext.toShortUrl
|
2021-04-03 06:13:12 +00:00
|
|
|
import org.mozilla.fenix.selection.SelectionHolder
|
2021-05-10 20:24:04 +00:00
|
|
|
import org.mozilla.fenix.tabstray.TabsTrayState
|
|
|
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
2021-03-26 14:33:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A RecyclerView ViewHolder implementation for "tab" items.
|
2021-07-26 09:56:48 +00:00
|
|
|
*
|
|
|
|
* @param itemView [View] that displays a "tab".
|
|
|
|
* @param imageLoader [ImageLoader] used to load tab thumbnails.
|
|
|
|
* @param trayStore [TabsTrayStore] containing the complete state of tabs tray and methods to update that.
|
|
|
|
* @param featureName [String] representing the name of the feature displaying tabs. Used in telemetry reporting.
|
|
|
|
* @param store [BrowserStore] containing the complete state of the browser and methods to update that.
|
2021-03-26 14:33:46 +00:00
|
|
|
*/
|
2021-07-26 09:56:48 +00:00
|
|
|
@Suppress("LongParameterList")
|
2021-05-11 05:33:30 +00:00
|
|
|
abstract class AbstractBrowserTabViewHolder(
|
2021-03-25 21:22:41 +00:00
|
|
|
itemView: View,
|
2021-03-26 14:33:46 +00:00
|
|
|
private val imageLoader: ImageLoader,
|
2021-04-03 06:13:12 +00:00
|
|
|
private val trayStore: TabsTrayStore,
|
2021-10-18 18:29:38 +00:00
|
|
|
private val selectionHolder: SelectionHolder<TabSessionState>?,
|
2021-07-26 09:56:48 +00:00
|
|
|
internal val featureName: String,
|
2021-03-26 14:33:46 +00:00
|
|
|
private val store: BrowserStore = itemView.context.components.core.store,
|
2022-05-18 02:08:16 +00:00
|
|
|
) : SelectableTabViewHolder(itemView) {
|
2021-03-26 14:33:46 +00:00
|
|
|
|
|
|
|
private val faviconView: ImageView? =
|
|
|
|
itemView.findViewById(R.id.mozac_browser_tabstray_favicon_icon)
|
|
|
|
private val titleView: TextView = itemView.findViewById(R.id.mozac_browser_tabstray_title)
|
|
|
|
private val closeView: AppCompatImageButton =
|
|
|
|
itemView.findViewById(R.id.mozac_browser_tabstray_close)
|
|
|
|
private val thumbnailView: TabThumbnailView =
|
|
|
|
itemView.findViewById(R.id.mozac_browser_tabstray_thumbnail)
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
internal val urlView: TextView? = itemView.findViewById(R.id.mozac_browser_tabstray_url)
|
|
|
|
private val playPauseButtonView: ImageButton = itemView.findViewById(R.id.play_pause_button)
|
|
|
|
|
2021-04-03 07:07:52 +00:00
|
|
|
abstract val browserTrayInteractor: BrowserTrayInteractor
|
|
|
|
abstract val thumbnailSize: Int
|
|
|
|
|
2021-10-18 18:29:38 +00:00
|
|
|
override var tab: TabSessionState? = null
|
2021-03-26 14:33:46 +00:00
|
|
|
|
Support tab movement/reordering (#22751)
* Adds basic support for tab reordering via drag-and-drop selected tabs
* ktlint/detekt formatting
* Use defaultTabsFilter (now not private) instead of getter
* Convert from position+filter API to target+placeAfter
Unfortunately I still need the filter passed around a bit
* Handle inactive tabs' holder being children of the RecyclerView of the normal tabs
Don't go through LayoutManager needlessly
* Non-working use tabID the whole way. Does not compile.
* Fix to do direct tab ID and use grid setting directly
* Remove non-null assertion. Now fully works for "other" tabs.
* Prevent grouped tabs from being dragged
* Remove unused import
* Add/fix comments
* Do API version check and use deprecated startDrag if too old.
* Build process fails: both outdated and too new, so reverting to just too new
* Use deprecated function and suppress warning
* fix space
* Suppress "TooManyFunctions" on DefaultTabsTrayController
* Repeatedly update tab movement during drag
* Remove multi-tab movement, only allow dragging if tab groups disabled, fix tab positioning during movement
I'm forced to suppress LongParameterList to get the settings information where it needs to go though
* Remove settings argument and corresponding long args suppression: instead get settings from parent AbstractBrowserTrayList's context
* New UI: Select a tab and then, while holding down, start dragging
* Revert to using before/after boolean to accomodate delays
Move drag transparency to start of drag
* Use new BlankDragShadowBuilder and DraggableItemAnimator to handle tab movement
* Replace Pair<>s with data classes
* Only drag if exactly 1 tab selected, don't consume drag event if not used
* Auto-scroll tab tray while dragging near top/bottom edge
* Remove unexpected scrolling on tab bind (triggered when tab is selected)
* Fix broken scroll behavior during dragging
* Cleanup for ktlint/detekt
* Constantly set elevation during drag in case of update
Clean code at drag start
* Add custom drag start behavior
* Add drag distance constant, do all touch-drag behavior in OnTouchListener
* Disable parent vertical scrolling on drag start, fix detekt ComplexCondition
* Minor cleanup/comments
* Revert removal of scroll on bind, this was related to something different
* Correction to prepareForDrop to match documentation- doesn't seem to have any effect
* Simplify via unchecked typecast, use ViewCompat
* Use ViewConfiguration.scaledTouchSlop instead of arbitrary 30px
* Added tabReorderingFeature flag, split drag interactor to separate function to satisfy complexity requirement
Co-authored-by: Steven Knipe <ssk97@case.edu>
Co-authored-by: ssk97 <knipesteven@gmail.com>
Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
2021-12-08 16:36:49 +00:00
|
|
|
internal var beingDragged: Boolean = false
|
|
|
|
private var touchStartPoint: PointF? = null
|
|
|
|
|
2021-03-26 14:33:46 +00:00
|
|
|
/**
|
|
|
|
* Displays the data of the given session and notifies the given observable about events.
|
|
|
|
*/
|
|
|
|
@Suppress("ComplexMethod", "LongMethod")
|
|
|
|
override fun bind(
|
2021-10-18 18:29:38 +00:00
|
|
|
tab: TabSessionState,
|
2021-03-26 14:33:46 +00:00
|
|
|
isSelected: Boolean,
|
|
|
|
styling: TabsTrayStyling,
|
2021-10-18 18:29:38 +00:00
|
|
|
delegate: TabsTray.Delegate,
|
2021-03-26 14:33:46 +00:00
|
|
|
) {
|
|
|
|
this.tab = tab
|
Support tab movement/reordering (#22751)
* Adds basic support for tab reordering via drag-and-drop selected tabs
* ktlint/detekt formatting
* Use defaultTabsFilter (now not private) instead of getter
* Convert from position+filter API to target+placeAfter
Unfortunately I still need the filter passed around a bit
* Handle inactive tabs' holder being children of the RecyclerView of the normal tabs
Don't go through LayoutManager needlessly
* Non-working use tabID the whole way. Does not compile.
* Fix to do direct tab ID and use grid setting directly
* Remove non-null assertion. Now fully works for "other" tabs.
* Prevent grouped tabs from being dragged
* Remove unused import
* Add/fix comments
* Do API version check and use deprecated startDrag if too old.
* Build process fails: both outdated and too new, so reverting to just too new
* Use deprecated function and suppress warning
* fix space
* Suppress "TooManyFunctions" on DefaultTabsTrayController
* Repeatedly update tab movement during drag
* Remove multi-tab movement, only allow dragging if tab groups disabled, fix tab positioning during movement
I'm forced to suppress LongParameterList to get the settings information where it needs to go though
* Remove settings argument and corresponding long args suppression: instead get settings from parent AbstractBrowserTrayList's context
* New UI: Select a tab and then, while holding down, start dragging
* Revert to using before/after boolean to accomodate delays
Move drag transparency to start of drag
* Use new BlankDragShadowBuilder and DraggableItemAnimator to handle tab movement
* Replace Pair<>s with data classes
* Only drag if exactly 1 tab selected, don't consume drag event if not used
* Auto-scroll tab tray while dragging near top/bottom edge
* Remove unexpected scrolling on tab bind (triggered when tab is selected)
* Fix broken scroll behavior during dragging
* Cleanup for ktlint/detekt
* Constantly set elevation during drag in case of update
Clean code at drag start
* Add custom drag start behavior
* Add drag distance constant, do all touch-drag behavior in OnTouchListener
* Disable parent vertical scrolling on drag start, fix detekt ComplexCondition
* Minor cleanup/comments
* Revert removal of scroll on bind, this was related to something different
* Correction to prepareForDrop to match documentation- doesn't seem to have any effect
* Simplify via unchecked typecast, use ViewCompat
* Use ViewConfiguration.scaledTouchSlop instead of arbitrary 30px
* Added tabReorderingFeature flag, split drag interactor to separate function to satisfy complexity requirement
Co-authored-by: Steven Knipe <ssk97@case.edu>
Co-authored-by: ssk97 <knipesteven@gmail.com>
Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
2021-12-08 16:36:49 +00:00
|
|
|
beingDragged = false
|
2021-03-26 14:33:46 +00:00
|
|
|
|
|
|
|
updateTitle(tab)
|
|
|
|
updateUrl(tab)
|
|
|
|
updateFavicon(tab)
|
2021-10-18 18:29:38 +00:00
|
|
|
updateCloseButtonDescription(tab.content.title)
|
2021-03-26 14:33:46 +00:00
|
|
|
updateSelectedTabIndicator(isSelected)
|
2021-04-03 06:13:12 +00:00
|
|
|
updateMediaState(tab)
|
|
|
|
|
2021-04-14 02:20:27 +00:00
|
|
|
if (selectionHolder != null) {
|
|
|
|
setSelectionInteractor(tab, selectionHolder, browserTrayInteractor)
|
|
|
|
} else {
|
2022-05-18 02:08:16 +00:00
|
|
|
itemView.setOnClickListener {
|
|
|
|
browserTrayInteractor.onTabSelected(tab, featureName)
|
|
|
|
}
|
2021-04-03 06:13:12 +00:00
|
|
|
}
|
2021-03-26 14:33:46 +00:00
|
|
|
|
2022-11-02 20:20:48 +00:00
|
|
|
loadIntoThumbnailView(thumbnailView, tab.id)
|
2021-04-03 06:13:12 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 02:08:16 +00:00
|
|
|
override fun showTabIsMultiSelectEnabled(selectedMaskView: View?, isSelected: Boolean) {
|
2021-08-18 09:00:20 +00:00
|
|
|
selectedMaskView?.isVisible = isSelected
|
2021-04-03 06:13:12 +00:00
|
|
|
closeView.isInvisible = trayStore.state.mode is TabsTrayState.Mode.Select
|
|
|
|
}
|
|
|
|
|
2021-10-18 18:29:38 +00:00
|
|
|
private fun updateFavicon(tab: TabSessionState) {
|
|
|
|
if (tab.content.icon != null) {
|
2021-04-03 06:13:12 +00:00
|
|
|
faviconView?.visibility = View.VISIBLE
|
2021-10-18 18:29:38 +00:00
|
|
|
faviconView?.setImageBitmap(tab.content.icon)
|
2021-04-03 06:13:12 +00:00
|
|
|
} else {
|
|
|
|
faviconView?.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 18:29:38 +00:00
|
|
|
private fun updateTitle(tab: TabSessionState) {
|
2021-10-07 17:37:20 +00:00
|
|
|
val title = tab.content.title.ifEmpty {
|
2021-10-18 18:29:38 +00:00
|
|
|
tab.content.url
|
2021-04-03 06:13:12 +00:00
|
|
|
}
|
|
|
|
titleView.text = title
|
|
|
|
}
|
|
|
|
|
2021-10-18 18:29:38 +00:00
|
|
|
private fun updateUrl(tab: TabSessionState) {
|
2021-04-03 06:13:12 +00:00
|
|
|
// Truncate to MAX_URI_LENGTH to prevent the UI from locking up for
|
|
|
|
// extremely large URLs such as data URIs or bookmarklets. The same
|
|
|
|
// is done in the toolbar and awesomebar:
|
|
|
|
// https://github.com/mozilla-mobile/fenix/issues/1824
|
|
|
|
// https://github.com/mozilla-mobile/android-components/issues/6985
|
2021-10-18 18:29:38 +00:00
|
|
|
urlView?.text = tab.content.url
|
2021-04-03 06:13:12 +00:00
|
|
|
.toShortUrl(itemView.context.components.publicSuffixList)
|
|
|
|
.take(MAX_URI_LENGTH)
|
|
|
|
}
|
2021-03-26 14:33:46 +00:00
|
|
|
|
2021-04-03 06:13:12 +00:00
|
|
|
private fun updateCloseButtonDescription(title: String) {
|
|
|
|
closeView.contentDescription =
|
|
|
|
closeView.context.getString(R.string.close_tab_title, title)
|
|
|
|
}
|
|
|
|
|
2021-10-18 18:29:38 +00:00
|
|
|
private fun updateMediaState(tab: TabSessionState) {
|
2021-03-26 14:33:46 +00:00
|
|
|
// Media state
|
|
|
|
playPauseButtonView.increaseTapArea(PLAY_PAUSE_BUTTON_EXTRA_DPS)
|
|
|
|
|
|
|
|
with(playPauseButtonView) {
|
|
|
|
invalidate()
|
|
|
|
val sessionState = store.state.findTabOrCustomTab(tab.id)
|
|
|
|
when (sessionState?.mediaSessionState?.playbackState) {
|
|
|
|
MediaSession.PlaybackState.PAUSED -> {
|
|
|
|
showAndEnable()
|
|
|
|
contentDescription =
|
|
|
|
context.getString(R.string.mozac_feature_media_notification_action_play)
|
|
|
|
setImageDrawable(
|
|
|
|
AppCompatResources.getDrawable(context, R.drawable.media_state_play),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaSession.PlaybackState.PLAYING -> {
|
|
|
|
showAndEnable()
|
|
|
|
contentDescription =
|
|
|
|
context.getString(R.string.mozac_feature_media_notification_action_pause)
|
|
|
|
setImageDrawable(
|
|
|
|
AppCompatResources.getDrawable(context, R.drawable.media_state_pause),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
removeTouchDelegate()
|
|
|
|
removeAndDisable()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setOnClickListener {
|
|
|
|
when (sessionState?.mediaSessionState?.playbackState) {
|
|
|
|
MediaSession.PlaybackState.PLAYING -> {
|
2022-04-05 12:21:41 +00:00
|
|
|
Tab.mediaPause.record(NoExtras())
|
2021-03-26 14:33:46 +00:00
|
|
|
sessionState.mediaSessionState?.controller?.pause()
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaSession.PlaybackState.PAUSED -> {
|
2022-04-05 12:21:41 +00:00
|
|
|
Tab.mediaPlay.record(NoExtras())
|
2021-03-26 14:33:46 +00:00
|
|
|
sessionState.mediaSessionState?.controller?.play()
|
|
|
|
}
|
|
|
|
else -> throw AssertionError(
|
|
|
|
"Play/Pause button clicked without play/pause state.",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 21:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 06:13:12 +00:00
|
|
|
private fun loadIntoThumbnailView(thumbnailView: ImageView, id: String) {
|
|
|
|
imageLoader.loadIntoView(thumbnailView, ImageLoadRequest(id, thumbnailSize))
|
2021-03-25 21:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 06:13:12 +00:00
|
|
|
private fun setSelectionInteractor(
|
2021-10-18 18:29:38 +00:00
|
|
|
item: TabSessionState,
|
|
|
|
holder: SelectionHolder<TabSessionState>,
|
2021-07-26 09:56:48 +00:00
|
|
|
interactor: BrowserTrayInteractor,
|
2021-04-03 06:13:12 +00:00
|
|
|
) {
|
|
|
|
itemView.setOnClickListener {
|
2022-05-18 02:08:16 +00:00
|
|
|
interactor.onMultiSelectClicked(item, holder, featureName)
|
2021-03-26 14:33:46 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 06:13:12 +00:00
|
|
|
itemView.setOnLongClickListener {
|
2022-05-18 02:08:16 +00:00
|
|
|
interactor.onLongClicked(item, holder)
|
2021-03-26 14:33:46 +00:00
|
|
|
}
|
Support tab movement/reordering (#22751)
* Adds basic support for tab reordering via drag-and-drop selected tabs
* ktlint/detekt formatting
* Use defaultTabsFilter (now not private) instead of getter
* Convert from position+filter API to target+placeAfter
Unfortunately I still need the filter passed around a bit
* Handle inactive tabs' holder being children of the RecyclerView of the normal tabs
Don't go through LayoutManager needlessly
* Non-working use tabID the whole way. Does not compile.
* Fix to do direct tab ID and use grid setting directly
* Remove non-null assertion. Now fully works for "other" tabs.
* Prevent grouped tabs from being dragged
* Remove unused import
* Add/fix comments
* Do API version check and use deprecated startDrag if too old.
* Build process fails: both outdated and too new, so reverting to just too new
* Use deprecated function and suppress warning
* fix space
* Suppress "TooManyFunctions" on DefaultTabsTrayController
* Repeatedly update tab movement during drag
* Remove multi-tab movement, only allow dragging if tab groups disabled, fix tab positioning during movement
I'm forced to suppress LongParameterList to get the settings information where it needs to go though
* Remove settings argument and corresponding long args suppression: instead get settings from parent AbstractBrowserTrayList's context
* New UI: Select a tab and then, while holding down, start dragging
* Revert to using before/after boolean to accomodate delays
Move drag transparency to start of drag
* Use new BlankDragShadowBuilder and DraggableItemAnimator to handle tab movement
* Replace Pair<>s with data classes
* Only drag if exactly 1 tab selected, don't consume drag event if not used
* Auto-scroll tab tray while dragging near top/bottom edge
* Remove unexpected scrolling on tab bind (triggered when tab is selected)
* Fix broken scroll behavior during dragging
* Cleanup for ktlint/detekt
* Constantly set elevation during drag in case of update
Clean code at drag start
* Add custom drag start behavior
* Add drag distance constant, do all touch-drag behavior in OnTouchListener
* Disable parent vertical scrolling on drag start, fix detekt ComplexCondition
* Minor cleanup/comments
* Revert removal of scroll on bind, this was related to something different
* Correction to prepareForDrop to match documentation- doesn't seem to have any effect
* Simplify via unchecked typecast, use ViewCompat
* Use ViewConfiguration.scaledTouchSlop instead of arbitrary 30px
* Added tabReorderingFeature flag, split drag interactor to separate function to satisfy complexity requirement
Co-authored-by: Steven Knipe <ssk97@case.edu>
Co-authored-by: ssk97 <knipesteven@gmail.com>
Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
2021-12-08 16:36:49 +00:00
|
|
|
setDragInteractor(item, holder, interactor)
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
|
private fun setDragInteractor(
|
|
|
|
item: TabSessionState,
|
|
|
|
holder: SelectionHolder<TabSessionState>,
|
|
|
|
interactor: BrowserTrayInteractor,
|
|
|
|
) {
|
|
|
|
// Since I immediately pass the event to onTouchEvent if it's not a move
|
|
|
|
// The ClickableViewAccessibility warning isn't useful
|
|
|
|
itemView.setOnTouchListener { view, motionEvent ->
|
|
|
|
when (motionEvent.actionMasked) {
|
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
|
|
touchStartPoint = PointF(motionEvent.x, motionEvent.y)
|
|
|
|
}
|
|
|
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
|
|
|
touchStartPoint = null
|
|
|
|
}
|
|
|
|
MotionEvent.ACTION_MOVE -> {
|
|
|
|
val touchStart = touchStartPoint
|
|
|
|
val selected = holder.selectedItems
|
|
|
|
val selectsOnlyThis = (selected.size == 1 && selected.contains(item))
|
2022-11-01 10:50:12 +00:00
|
|
|
if (selectsOnlyThis && touchStart != null) {
|
2022-07-13 20:53:30 +00:00
|
|
|
// If the parent is null then return early and mark the event as unhandled
|
2021-12-08 23:19:40 +00:00
|
|
|
val parent = itemView.parent as? AbstractBrowserTrayList ?: return@setOnTouchListener false
|
|
|
|
|
Support tab movement/reordering (#22751)
* Adds basic support for tab reordering via drag-and-drop selected tabs
* ktlint/detekt formatting
* Use defaultTabsFilter (now not private) instead of getter
* Convert from position+filter API to target+placeAfter
Unfortunately I still need the filter passed around a bit
* Handle inactive tabs' holder being children of the RecyclerView of the normal tabs
Don't go through LayoutManager needlessly
* Non-working use tabID the whole way. Does not compile.
* Fix to do direct tab ID and use grid setting directly
* Remove non-null assertion. Now fully works for "other" tabs.
* Prevent grouped tabs from being dragged
* Remove unused import
* Add/fix comments
* Do API version check and use deprecated startDrag if too old.
* Build process fails: both outdated and too new, so reverting to just too new
* Use deprecated function and suppress warning
* fix space
* Suppress "TooManyFunctions" on DefaultTabsTrayController
* Repeatedly update tab movement during drag
* Remove multi-tab movement, only allow dragging if tab groups disabled, fix tab positioning during movement
I'm forced to suppress LongParameterList to get the settings information where it needs to go though
* Remove settings argument and corresponding long args suppression: instead get settings from parent AbstractBrowserTrayList's context
* New UI: Select a tab and then, while holding down, start dragging
* Revert to using before/after boolean to accomodate delays
Move drag transparency to start of drag
* Use new BlankDragShadowBuilder and DraggableItemAnimator to handle tab movement
* Replace Pair<>s with data classes
* Only drag if exactly 1 tab selected, don't consume drag event if not used
* Auto-scroll tab tray while dragging near top/bottom edge
* Remove unexpected scrolling on tab bind (triggered when tab is selected)
* Fix broken scroll behavior during dragging
* Cleanup for ktlint/detekt
* Constantly set elevation during drag in case of update
Clean code at drag start
* Add custom drag start behavior
* Add drag distance constant, do all touch-drag behavior in OnTouchListener
* Disable parent vertical scrolling on drag start, fix detekt ComplexCondition
* Minor cleanup/comments
* Revert removal of scroll on bind, this was related to something different
* Correction to prepareForDrop to match documentation- doesn't seem to have any effect
* Simplify via unchecked typecast, use ViewCompat
* Use ViewConfiguration.scaledTouchSlop instead of arbitrary 30px
* Added tabReorderingFeature flag, split drag interactor to separate function to satisfy complexity requirement
Co-authored-by: Steven Knipe <ssk97@case.edu>
Co-authored-by: ssk97 <knipesteven@gmail.com>
Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
2021-12-08 16:36:49 +00:00
|
|
|
// Prevent scrolling if the user tries to start drag vertically
|
|
|
|
parent.requestDisallowInterceptTouchEvent(true)
|
|
|
|
// Only start deselect+drag if the user drags far enough
|
|
|
|
val dist = PointF.length(touchStart.x - motionEvent.x, touchStart.y - motionEvent.y)
|
|
|
|
if (dist > ViewConfiguration.get(parent.context).scaledTouchSlop) {
|
|
|
|
interactor.deselect(item) // Exit selection mode
|
|
|
|
touchStartPoint = null
|
|
|
|
val dragOffset = PointF(motionEvent.x, motionEvent.y)
|
|
|
|
val shadow = BlankDragShadowBuilder()
|
|
|
|
ViewCompat.startDragAndDrop(itemView, null, shadow, TabDragData(item, dragOffset), 0)
|
|
|
|
}
|
|
|
|
return@setOnTouchListener true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
view.onTouchEvent(motionEvent)
|
|
|
|
}
|
2021-03-26 14:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
internal const val PLAY_PAUSE_BUTTON_EXTRA_DPS = 24
|
|
|
|
internal const val GRID_ITEM_CLOSE_BUTTON_EXTRA_DPS = 24
|
|
|
|
}
|
|
|
|
}
|