* For #2754 Add tab cards to share sheet * For #2754: Fix background near rounded corners and ShareButtonAppearanceTest * Add license to share_tab_itemnightly-build-test
parent
ac2611d744
commit
de93b05cac
@ -0,0 +1,60 @@
|
||||
/* 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.share.listadapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.synthetic.main.share_tab_item.view.*
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.loadIntoView
|
||||
import org.mozilla.fenix.share.ShareTab
|
||||
|
||||
class ShareTabsAdapter :
|
||||
ListAdapter<ShareTab, ShareTabsAdapter.ShareTabViewHolder>(ShareTabDiffCallback()) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ShareTabViewHolder(
|
||||
LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.share_tab_item, parent, false)
|
||||
)
|
||||
|
||||
override fun onBindViewHolder(holder: ShareTabViewHolder, position: Int) =
|
||||
holder.bind(getItem(position))
|
||||
|
||||
fun setTabs(tabs: List<ShareTab>) {
|
||||
submitList(tabs.toMutableList())
|
||||
}
|
||||
|
||||
inner class ShareTabViewHolder(
|
||||
itemView: View
|
||||
) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
fun bind(item: ShareTab) = with(itemView) {
|
||||
context.components.core.icons.loadIntoView(itemView.share_tab_favicon, item.url)
|
||||
itemView.share_tab_title.text = item.title
|
||||
itemView.share_tab_url.text = item.url
|
||||
}
|
||||
}
|
||||
|
||||
private class ShareTabDiffCallback : DiffUtil.ItemCallback<ShareTab>() {
|
||||
override fun areItemsTheSame(
|
||||
oldItem: ShareTab,
|
||||
newItem: ShareTab
|
||||
): Boolean {
|
||||
return oldItem.url == newItem.url
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(
|
||||
oldItem: ShareTab,
|
||||
newItem: ShareTab
|
||||
): Boolean {
|
||||
return oldItem.url == newItem.url && oldItem.title == newItem.title
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/share_tab_favicon"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:padding="8dp"
|
||||
android:background="@drawable/favicon_background"
|
||||
android:backgroundTint="?above"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/share_tab_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:textSize="20sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textColor="?contrastText"
|
||||
tools:text="Download Firefox - Free Web Browser"
|
||||
app:layout_constraintStart_toEndOf="@id/share_tab_favicon"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/share_tab_url"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textColor="?secondaryText"
|
||||
tools:text="https://www.mozilla.org/en-US/firefox/new/"
|
||||
app:layout_constraintStart_toStartOf="@id/share_tab_title"
|
||||
app:layout_constraintTop_toBottomOf="@id/share_tab_title"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue