parent
d5a9627273
commit
038aecc0ee
|
@ -37,6 +37,7 @@ import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
|
import android.widget.ImageView
|
||||||
|
|
||||||
private const val MAX_ITEMS_PER_PAGE = 50
|
private const val MAX_ITEMS_PER_PAGE = 50
|
||||||
|
|
||||||
|
@ -138,14 +139,15 @@ class SitePermissionsExceptionsFragment : Fragment(), View.OnClickListener, Coro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SitePermissionsViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView)
|
class SitePermissionsViewHolder(val view: View, val iconView: ImageView, val siteTextView: TextView) :
|
||||||
|
RecyclerView.ViewHolder(view)
|
||||||
|
|
||||||
class ExceptionsAdapter(private val clickListener: View.OnClickListener) :
|
class ExceptionsAdapter(private val clickListener: View.OnClickListener) :
|
||||||
PagedListAdapter<SitePermissions, SitePermissionsViewHolder>(diffCallback), CoroutineScope {
|
PagedListAdapter<SitePermissions, SitePermissionsViewHolder>(diffCallback), CoroutineScope {
|
||||||
private lateinit var job: Job
|
private lateinit var job: Job
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
get() = Dispatchers.Main + job
|
get() = Main + job
|
||||||
|
|
||||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
||||||
super.onAttachedToRecyclerView(recyclerView)
|
super.onAttachedToRecyclerView(recyclerView)
|
||||||
|
@ -160,25 +162,28 @@ class ExceptionsAdapter(private val clickListener: View.OnClickListener) :
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SitePermissionsViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SitePermissionsViewHolder {
|
||||||
val context = parent.context
|
val context = parent.context
|
||||||
val inflater = LayoutInflater.from(context)
|
val inflater = LayoutInflater.from(context)
|
||||||
val textView = inflater.inflate(R.layout.fragment_site_permissions_exceptions_item, parent, false) as TextView
|
val view = inflater.inflate(R.layout.fragment_site_permissions_exceptions_item, parent, false)
|
||||||
return SitePermissionsViewHolder(textView)
|
val iconView = view.findViewById<ImageView>(R.id.exception_icon)
|
||||||
|
val siteTextView = view.findViewById<TextView>(R.id.exception_text)
|
||||||
|
return SitePermissionsViewHolder(view, iconView, siteTextView)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: SitePermissionsViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: SitePermissionsViewHolder, position: Int) {
|
||||||
val sitePermissions = requireNotNull(getItem(position))
|
val sitePermissions = requireNotNull(getItem(position))
|
||||||
val context = holder.textView.context
|
val context = holder.view.context
|
||||||
|
|
||||||
launch(IO) {
|
launch(IO) {
|
||||||
|
|
||||||
val bitmap = context.components.core.icons
|
val bitmap = context.components.core.icons
|
||||||
.loadIcon(IconRequest(sitePermissions.origin)).await().bitmap
|
.loadIcon(IconRequest("https://${sitePermissions.origin}/")).await().bitmap
|
||||||
launch(Main) {
|
launch(Main) {
|
||||||
val drawable = BitmapDrawable(context.resources, bitmap)
|
val drawable = BitmapDrawable(context.resources, bitmap)
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
holder.iconView.setImageDrawable(drawable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
holder.textView.text = sitePermissions.origin
|
holder.siteTextView.text = sitePermissions.origin
|
||||||
holder.textView.tag = sitePermissions
|
holder.view.tag = sitePermissions
|
||||||
holder.textView.setOnClickListener(clickListener)
|
holder.view.setOnClickListener(clickListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -3,16 +3,31 @@
|
||||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
- 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/. -->
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/exception_item"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/site_permissions_exceptions_item_height"
|
android:layout_height="@dimen/site_permissions_exceptions_item_height"
|
||||||
android:textSize="@dimen/site_permissions_exceptions_item_text_size"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:drawablePadding="16dp"
|
android:gravity="center_vertical"
|
||||||
android:drawableStart="@drawable/ic_internet"
|
|
||||||
android:textColor="?primaryText"
|
|
||||||
android:gravity="start|center_vertical"
|
|
||||||
android:paddingStart="24dp"
|
android:paddingStart="24dp"
|
||||||
android:paddingEnd="24dp"
|
android:paddingEnd="24dp">
|
||||||
android:background="?android:attr/selectableItemBackground"/>
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/exception_icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:importantForAccessibility="no"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:drawableStart="@drawable/ic_internet"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/exception_text"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:textSize="@dimen/site_permissions_exceptions_item_text_size"
|
||||||
|
android:textColor="?primaryText"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue