Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

For #1919- Websites' icons are not displayed on Site permissions Exceptions #3050

Merged
merged 1 commit into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import kotlin.coroutines.CoroutineContext
import android.graphics.drawable.BitmapDrawable
import android.widget.ImageView

private const val MAX_ITEMS_PER_PAGE = 50

Expand Down Expand Up @@ -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) :
PagedListAdapter<SitePermissions, SitePermissionsViewHolder>(diffCallback), CoroutineScope {
private lateinit var job: Job

override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job
get() = Main + job

override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
Expand All @@ -160,25 +162,28 @@ class ExceptionsAdapter(private val clickListener: View.OnClickListener) :
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SitePermissionsViewHolder {
val context = parent.context
val inflater = LayoutInflater.from(context)
val textView = inflater.inflate(R.layout.fragment_site_permissions_exceptions_item, parent, false) as TextView
return SitePermissionsViewHolder(textView)
val view = inflater.inflate(R.layout.fragment_site_permissions_exceptions_item, parent, false)
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) {
val sitePermissions = requireNotNull(getItem(position))
val context = holder.textView.context
val context = holder.view.context

launch(IO) {

val bitmap = context.components.core.icons
.loadIcon(IconRequest(sitePermissions.origin)).await().bitmap
.loadIcon(IconRequest("https://${sitePermissions.origin}/")).await().bitmap
launch(Main) {
val drawable = BitmapDrawable(context.resources, bitmap)
holder.textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
holder.iconView.setImageDrawable(drawable)
}
}
holder.textView.text = sitePermissions.origin
holder.textView.tag = sitePermissions
holder.textView.setOnClickListener(clickListener)
holder.siteTextView.text = sitePermissions.origin
holder.view.tag = sitePermissions
holder.view.setOnClickListener(clickListener)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@
- 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/. -->

<TextView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/exception_item"
android:layout_width="match_parent"
android:layout_height="@dimen/site_permissions_exceptions_item_height"
android:textSize="@dimen/site_permissions_exceptions_item_text_size"
android:drawablePadding="16dp"
android:drawableStart="@drawable/ic_internet"
android:textColor="?primaryText"
android:gravity="start|center_vertical"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:background="?android:attr/selectableItemBackground"/>
android:paddingEnd="24dp">

<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>