forked from mozilla-mobile/fenix
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#21236: Separate tabs with the same search term int…
…o a different section (mozilla-mobile#21177) * For mozilla-mobile#21236: Separate tabs with the same search term into a different section in tabs tray * Issue mozilla-mobile#21236: Scroll to selected tab + various tab fixes for groupings * Issue mozilla-mobile#21236: Fix failing test Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
- Loading branch information
1 parent
2696a5e
commit 7b321a0
Showing
31 changed files
with
1,159 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
app/src/main/java/org/mozilla/fenix/tabstray/browser/BrowserTabGridViewHolder.kt
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
app/src/main/java/org/mozilla/fenix/tabstray/browser/BrowserTabListViewHolder.kt
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
app/src/main/java/org/mozilla/fenix/tabstray/browser/BrowserTabViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* 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/. */ | ||
|
||
package org.mozilla.fenix.tabstray.browser | ||
|
||
import android.view.View | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import androidx.appcompat.widget.AppCompatImageButton | ||
import androidx.core.content.ContextCompat | ||
import androidx.recyclerview.widget.RecyclerView | ||
import mozilla.components.browser.tabstray.TabsTrayStyling | ||
import mozilla.components.concept.base.images.ImageLoader | ||
import mozilla.components.concept.tabstray.Tab | ||
import mozilla.components.concept.tabstray.TabsTray | ||
import mozilla.components.support.base.observer.Observable | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.databinding.TabTrayGridItemBinding | ||
import org.mozilla.fenix.ext.increaseTapArea | ||
import kotlin.math.max | ||
import org.mozilla.fenix.selection.SelectionHolder | ||
import org.mozilla.fenix.tabstray.TabsTrayStore | ||
|
||
sealed class BrowserTabViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
/** | ||
* A RecyclerView ViewHolder implementation for "tab" items with grid layout. | ||
* | ||
* @param imageLoader [ImageLoader] used to load tab thumbnails. | ||
* @param browserTrayInteractor [BrowserTrayInteractor] handling tabs interactions in a tab tray. | ||
* @param store [TabsTrayStore] containing the complete state of tabs tray and methods to update that. | ||
* @param selectionHolder [SelectionHolder]<[Tab]> for helping with selecting any number of displayed [Tab]s. | ||
* @param itemView [View] that displays a "tab". | ||
* @param featureName [String] representing the name of the feature displaying tabs. Used in telemetry reporting. | ||
*/ | ||
class GridViewHolder( | ||
imageLoader: ImageLoader, | ||
override val browserTrayInteractor: BrowserTrayInteractor, | ||
store: TabsTrayStore, | ||
selectionHolder: SelectionHolder<Tab>? = null, | ||
itemView: View, | ||
featureName: String | ||
) : AbstractBrowserTabViewHolder(itemView, imageLoader, store, selectionHolder, featureName) { | ||
|
||
private val closeButton: AppCompatImageButton = itemView.findViewById(R.id.mozac_browser_tabstray_close) | ||
|
||
override val thumbnailSize: Int | ||
get() = max( | ||
itemView.resources.getDimensionPixelSize(R.dimen.tab_tray_grid_item_thumbnail_height), | ||
itemView.resources.getDimensionPixelSize(R.dimen.tab_tray_grid_item_thumbnail_width) | ||
) | ||
|
||
override fun updateSelectedTabIndicator(showAsSelected: Boolean) { | ||
val binding = TabTrayGridItemBinding.bind(itemView) | ||
binding.tabTrayGridItem.background = if (showAsSelected) { | ||
AppCompatResources.getDrawable(itemView.context, R.drawable.tab_tray_grid_item_selected_border) | ||
} else { | ||
null | ||
} | ||
return | ||
} | ||
|
||
override fun bind( | ||
tab: Tab, | ||
isSelected: Boolean, | ||
styling: TabsTrayStyling, | ||
observable: Observable<TabsTray.Observer> | ||
) { | ||
super.bind(tab, isSelected, styling, observable) | ||
|
||
closeButton.increaseTapArea(GRID_ITEM_CLOSE_BUTTON_EXTRA_DPS) | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.tab_tray_grid_item | ||
} | ||
} | ||
|
||
/** | ||
* A RecyclerView ViewHolder implementation for "tab" items with list layout. | ||
* | ||
* @param imageLoader [ImageLoader] used to load tab thumbnails. | ||
* @param browserTrayInteractor [BrowserTrayInteractor] handling tabs interactions in a tab tray. | ||
* @param store [TabsTrayStore] containing the complete state of tabs tray and methods to update that. | ||
* @param selectionHolder [SelectionHolder]<[Tab]> for helping with selecting any number of displayed [Tab]s. | ||
* @param itemView [View] that displays a "tab". | ||
* @param featureName [String] representing the name of the feature displaying tabs. Used in telemetry reporting. | ||
*/ | ||
class ListViewHolder( | ||
imageLoader: ImageLoader, | ||
override val browserTrayInteractor: BrowserTrayInteractor, | ||
store: TabsTrayStore, | ||
selectionHolder: SelectionHolder<Tab>? = null, | ||
itemView: View, | ||
featureName: String | ||
) : AbstractBrowserTabViewHolder(itemView, imageLoader, store, selectionHolder, featureName) { | ||
override val thumbnailSize: Int | ||
get() = max( | ||
itemView.resources.getDimensionPixelSize(R.dimen.tab_tray_list_item_thumbnail_height), | ||
itemView.resources.getDimensionPixelSize(R.dimen.tab_tray_list_item_thumbnail_width) | ||
) | ||
|
||
override fun updateSelectedTabIndicator(showAsSelected: Boolean) { | ||
val color = if (showAsSelected) { | ||
R.color.tab_tray_item_selected_background_normal_theme | ||
} else { | ||
R.color.tab_tray_item_background_normal_theme | ||
} | ||
itemView.setBackgroundColor( | ||
ContextCompat.getColor( | ||
itemView.context, | ||
color | ||
) | ||
) | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.tab_tray_item | ||
} | ||
} | ||
} |
Oops, something went wrong.