Skip to content

Commit

Permalink
Use local banners for extensions for fast load
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiokot committed Jun 8, 2024
1 parent e41d952 commit 77b8cea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 35 deletions.
Binary file added app/src/main/assets/banner-memories.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ua.com.radiokot.photoprism.features.ext.key.activation.view.model

import android.view.View
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.items.AbstractItem
Expand All @@ -11,7 +12,6 @@ import org.koin.core.scope.Scope
import ua.com.radiokot.photoprism.R
import ua.com.radiokot.photoprism.databinding.ListItemGalleryExtensionBinding
import ua.com.radiokot.photoprism.di.DI_SCOPE_SESSION
import ua.com.radiokot.photoprism.extension.hardwareConfigIfAvailable
import ua.com.radiokot.photoprism.features.ext.data.model.GalleryExtension
import ua.com.radiokot.photoprism.features.ext.view.GalleryExtensionResources

Expand All @@ -20,7 +20,8 @@ class GalleryExtensionListItem(
val title: Int,
@StringRes
val description: Int,
val bannerUrl: String,
@DrawableRes
val banner: Int,
) : AbstractItem<GalleryExtensionListItem.ViewHolder>() {
override val layoutRes: Int
get() = R.layout.list_item_gallery_extension
Expand All @@ -30,7 +31,7 @@ class GalleryExtensionListItem(
constructor(source: GalleryExtension) : this(
title = GalleryExtensionResources.getTitle(source),
description = GalleryExtensionResources.getDescription(source),
bannerUrl = GalleryExtensionResources.getBannerUrl(source)
banner = GalleryExtensionResources.getBanner(source)
)

override fun getViewHolder(v: View): ViewHolder =
Expand All @@ -48,14 +49,7 @@ class GalleryExtensionListItem(
override fun bindView(item: GalleryExtensionListItem, payloads: List<Any>) {
view.bannerImageView.contentDescription =
view.bannerImageView.context.getString(item.title)

picasso
.load(item.bannerUrl)
.hardwareConfigIfAvailable()
.placeholder(R.drawable.image_placeholder)
.fit()
.centerCrop()
.into(view.bannerImageView)
view.bannerImageView.setImageResource(item.banner)

view.titleTextView.setText(item.title)
view.descriptionTextView.setText(item.description)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ua.com.radiokot.photoprism.features.ext.store.view.model

import android.view.View
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
Expand All @@ -14,7 +15,6 @@ import org.koin.core.scope.Scope
import ua.com.radiokot.photoprism.R
import ua.com.radiokot.photoprism.databinding.ListItemGalleryExtensionStoreItemBinding
import ua.com.radiokot.photoprism.di.DI_SCOPE_SESSION
import ua.com.radiokot.photoprism.extension.hardwareConfigIfAvailable
import ua.com.radiokot.photoprism.features.ext.store.CURRENCY_NUMBER_FORMAT
import ua.com.radiokot.photoprism.features.ext.view.GalleryExtensionResources
import java.math.BigDecimal
Expand All @@ -26,7 +26,8 @@ class GalleryExtensionStoreListItem(
val title: Int,
@StringRes
val description: Int,
val bannerUrl: String,
@DrawableRes
val banner: Int,
val price: BigDecimal,
/**
* ISO-4217 3-letter code.
Expand All @@ -50,7 +51,7 @@ class GalleryExtensionStoreListItem(
) : this(
title = GalleryExtensionResources.getTitle(source.extension),
description = GalleryExtensionResources.getDescription(source.extension),
bannerUrl = GalleryExtensionResources.getBannerUrl(source.extension),
banner = GalleryExtensionResources.getBanner(source.extension),
price = source.price,
currency = source.currency,
isBuyButtonVisible = !source.isAlreadyActivated,
Expand All @@ -74,14 +75,7 @@ class GalleryExtensionStoreListItem(
override fun bindView(item: GalleryExtensionStoreListItem, payloads: List<Any>) {
view.bannerImageView.contentDescription =
view.bannerImageView.context.getString(item.title)

picasso
.load(item.bannerUrl)
.hardwareConfigIfAvailable()
.placeholder(R.drawable.image_placeholder)
.fit()
.centerCrop()
.into(view.bannerImageView)
view.bannerImageView.setImageResource(item.banner)

view.titleTextView.setText(item.title)
view.descriptionTextView.setText(item.description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ import ua.com.radiokot.photoprism.R
import ua.com.radiokot.photoprism.features.ext.data.model.GalleryExtension

object GalleryExtensionResources {
@DrawableRes
fun getIcon(extension: GalleryExtension): Int = when (extension) {
GalleryExtension.MEMORIES ->
R.drawable.ic_photo_album_white

GalleryExtension.TEST ->
R.drawable.ic_sledding
}

@StringRes
fun getTitle(extension: GalleryExtension): Int = when (extension) {
GalleryExtension.MEMORIES ->
Expand All @@ -33,11 +24,12 @@ object GalleryExtensionResources {
R.string.media_type_unknown
}

fun getBannerUrl(extension: GalleryExtension):String=when(extension){
@DrawableRes
fun getBanner(extension: GalleryExtension): Int = when (extension) {
GalleryExtension.MEMORIES ->
"https://radiokot.com.ua/Radiokot/pp-memories.jpg"
R.drawable.banner_memories

GalleryExtension.TEST ->
"https://img3.teletype.in/files/6e/f5/6ef5b234-528c-400f-8ac7-bb00da2ce2c9.jpeg"
R.drawable.tv_banner
}
}
Binary file added app/src/main/res/drawable/banner_memories.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
android:id="@+id/banner_image_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY"
app:layout_constraintDimensionRatio="H,1:0.6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearance="@style/ShapeAppearance.Material3.Corner.Medium"
tools:background="@android:color/darker_gray"
tools:ignore="ContentDescription" />
tools:ignore="ContentDescription"
tools:srcCompat="@drawable/banner_memories" />

<TextView
android:id="@+id/title_text_view"
Expand Down

0 comments on commit 77b8cea

Please sign in to comment.