Skip to content

Commit

Permalink
News: try to load the icon directly from the web
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Dec 10, 2020
1 parent 3b2b5cd commit fb983a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ class NewsFragment : BaseFragmentView<RefreshingLayoutBinding>(),
discoverDate = it.discoverDate,
imageUrl = it.elements?.url,
website = it.website?.name,
websiteHostname = it.website?.hostName,
websiteImageUrl = it.website?.iconURL,
lifecycleOwner = this@NewsFragment
)
Timber.d(newsObject.toString())
newsAdapter.add(newsObject)
loadingRecyclerView.loading.visibility = View.INVISIBLE
loadingRecyclerView.container.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ data class News(
val discoverDate: Date?,
val imageUrl: String?,
val website: String?,
val websiteHostname: String?,
val websiteImageUrl: String?,
val lifecycleOwner: LifecycleOwner,
override val layoutRes: Int = R.layout.news_card_view,
Expand Down Expand Up @@ -82,9 +83,19 @@ data class News(
scale(Scale.FILL)
lifecycle(item.lifecycleOwner)
}
} else websiteLogo.visibility = View.GONE
websiteName.text = item.website
?: context.getString(R.string.no_website)
} else {
if (item.websiteHostname != null) {
websiteLogo.load("https://www.google.com/s2/favicons?domain=${item.websiteHostname}") {
scale(Scale.FILL)
lifecycle(item.lifecycleOwner)
}
} else websiteLogo.visibility = View.GONE
}
websiteName.text =
item.website ?: context.getString(R.string.no_website)
// websiteName.text = item.website?.let {
// if (it.length > 20) "${it.take(20)}…" else it
// } ?: context.getString(R.string.no_website)
publishDate.text =
item.discoverDate?.let { formatter.format(it) }
?: context.getString(R.string.no_date)
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/layout/news_card_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@

<com.javinator9889.handwashingreminder.graphics.RecyclingImageView
android:id="@+id/ws_logo"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ws_name"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -107,9 +108,10 @@
android:id="@+id/ws_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:maxWidth="120dp"
android:textSize="12sp"
android:ellipsize="end"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/bullet"
app:layout_constraintStart_toEndOf="@+id/ws_logo"
Expand Down

0 comments on commit fb983a2

Please sign in to comment.