forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#20349: Add inactive tab grouping to tabs tray
- Loading branch information
1 parent
7e56440
commit 9c1eb5a
Showing
31 changed files
with
664 additions
and
162 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
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
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/mozilla/fenix/tabstray/browser/ConcatAdapter.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,13 @@ | ||
/* 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 androidx.recyclerview.widget.ConcatAdapter | ||
|
||
val ConcatAdapter.browserAdapter | ||
get() = adapters.find { it is BrowserTabsAdapter } as BrowserTabsAdapter | ||
|
||
val ConcatAdapter.inactiveTabsAdapter | ||
get() = adapters.find { it is InactiveTabsAdapter } as InactiveTabsAdapter |
99 changes: 99 additions & 0 deletions
99
app/src/main/java/org/mozilla/fenix/tabstray/browser/InactiveTabViewHolder.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,99 @@ | ||
/* 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.annotation.StringRes | ||
import androidx.recyclerview.widget.RecyclerView | ||
import mozilla.components.browser.toolbar.MAX_URI_LENGTH | ||
import mozilla.components.concept.tabstray.Tab | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.databinding.InactiveFooterItemBinding | ||
import org.mozilla.fenix.databinding.InactiveTabListItemBinding | ||
import org.mozilla.fenix.ext.components | ||
import org.mozilla.fenix.ext.loadIntoView | ||
import org.mozilla.fenix.ext.toShortUrl | ||
import org.mozilla.fenix.tabstray.browser.AutoCloseInterval.Manual | ||
import org.mozilla.fenix.tabstray.browser.AutoCloseInterval.OneDay | ||
import org.mozilla.fenix.tabstray.browser.AutoCloseInterval.OneMonth | ||
import org.mozilla.fenix.tabstray.browser.AutoCloseInterval.OneWeek | ||
|
||
sealed class InactiveTabViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
class HeaderHolder(itemView: View) : InactiveTabViewHolder(itemView) { | ||
companion object { | ||
const val LAYOUT_ID = R.layout.inactive_header_item | ||
} | ||
} | ||
|
||
class TabViewHolder( | ||
itemView: View, | ||
private val browserTrayInteractor: BrowserTrayInteractor | ||
) : InactiveTabViewHolder(itemView) { | ||
|
||
private val binding = InactiveTabListItemBinding.bind(itemView) | ||
|
||
fun bind(tab: Tab) { | ||
val components = itemView.context.components | ||
val makePrettyUrl: (String) -> String = { | ||
it.toShortUrl(components.publicSuffixList).take(MAX_URI_LENGTH) | ||
} | ||
|
||
itemView.setOnClickListener { | ||
browserTrayInteractor.open(tab) | ||
} | ||
|
||
binding.siteListItem.apply { | ||
components.core.icons.loadIntoView(iconView, tab.url) | ||
setText(tab.title, makePrettyUrl(tab.url)) | ||
setSecondaryButton( | ||
R.drawable.mozac_ic_close, | ||
R.string.content_description_close_button | ||
) { | ||
browserTrayInteractor.close(tab) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.inactive_tab_list_item | ||
} | ||
} | ||
|
||
class FooterHolder(itemView: View) : InactiveTabViewHolder(itemView) { | ||
|
||
val binding = InactiveFooterItemBinding.bind(itemView) | ||
|
||
fun bind(interval: AutoCloseInterval) { | ||
val context = itemView.context | ||
val stringRes = when (interval) { | ||
Manual, OneDay -> { | ||
itemView.visibility = View.GONE | ||
null | ||
} | ||
OneWeek -> { | ||
context.getString(interval.description) | ||
} | ||
OneMonth -> { | ||
context.getString(interval.description) | ||
} | ||
} | ||
if (stringRes != null) { | ||
binding.inactiveDescription.text = | ||
context.getString(R.string.inactive_tabs_description, stringRes) | ||
} | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.inactive_footer_item | ||
} | ||
} | ||
} | ||
|
||
enum class AutoCloseInterval(@StringRes val description: Int) { | ||
Manual(0), | ||
OneDay(0), | ||
OneWeek(R.string.inactive_tabs_7_days), | ||
OneMonth(R.string.inactive_tabs_30_days) | ||
} |
Oops, something went wrong.