mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-17 19:29:02 +00:00
add support for animated images in more places
This commit is contained in:
parent
4d6435b007
commit
675c8cfbb8
3 changed files with 77 additions and 63 deletions
|
|
@ -13,7 +13,7 @@
|
|||
android:layout_width="@dimen/gear_image_size"
|
||||
android:layout_height="@dimen/gear_image_size"
|
||||
actualImageScaleType="fitCenter"
|
||||
android:layout_marginRight="@dimen/row_padding"/>
|
||||
android:layout_marginEnd="@dimen/row_padding"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.facebook.imagepipeline.image.ImageInfo
|
|||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.helpers.AppConfigManager
|
||||
import com.habitrpg.android.habitica.models.Avatar
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import io.reactivex.functions.Consumer
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
|
@ -121,7 +122,7 @@ class AvatarView : View {
|
|||
multiDraweeHolder.add(draweeHolder)
|
||||
|
||||
val controller = Fresco.newDraweeControllerBuilder()
|
||||
.setUri(IMAGE_URI_ROOT + getFileName(layerName))
|
||||
.setUri(IMAGE_URI_ROOT + DataBindingUtils.getFullFilename(layerName, null))
|
||||
.setControllerListener(object : BaseControllerListener<ImageInfo>() {
|
||||
override fun onFinalImageSet(
|
||||
id: String?,
|
||||
|
|
@ -382,18 +383,7 @@ class AvatarView : View {
|
|||
return bounds
|
||||
}
|
||||
|
||||
private fun getFileName(imageName: String): String {
|
||||
val name = when {
|
||||
FILENAME_MAP.containsKey(imageName) -> FILENAME_MAP[imageName]
|
||||
imageName.startsWith("handleless") -> "chair_$imageName"
|
||||
else -> imageName
|
||||
}
|
||||
return name + if (FILEFORMAT_MAP.containsKey(imageName)) {
|
||||
"." + FILEFORMAT_MAP[imageName]
|
||||
} else {
|
||||
".png"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun onLayerComplete() {
|
||||
if (numberLayersInProcess.decrementAndGet() == 0) {
|
||||
|
|
@ -528,50 +518,9 @@ class AvatarView : View {
|
|||
companion object {
|
||||
const val IMAGE_URI_ROOT = "https://habitica-assets.s3.amazonaws.com/mobileApp/images/"
|
||||
private const val TAG = "AvatarView"
|
||||
val FILEFORMAT_MAP: Map<String, String>
|
||||
val FILENAME_MAP: Map<String, String>
|
||||
private val FULL_HERO_RECT = Rect(0, 0, 140, 147)
|
||||
private val COMPACT_HERO_RECT = Rect(0, 0, 114, 114)
|
||||
private val HERO_ONLY_RECT = Rect(0, 0, 90, 90)
|
||||
|
||||
init {
|
||||
val tempMap = HashMap<String, String>()
|
||||
tempMap["head_special_1"] = "gif"
|
||||
tempMap["broad_armor_special_1"] = "gif"
|
||||
tempMap["slim_armor_special_1"] = "gif"
|
||||
tempMap["head_special_0"] = "gif"
|
||||
tempMap["slim_armor_special_0"] = "gif"
|
||||
tempMap["broad_armor_special_0"] = "gif"
|
||||
tempMap["weapon_special_critical"] = "gif"
|
||||
tempMap["weapon_special_0"] = "gif"
|
||||
tempMap["shield_special_0"] = "gif"
|
||||
tempMap["Pet-Wolf-Cerberus"] = "gif"
|
||||
tempMap["armor_special_ks2019"] = "gif"
|
||||
tempMap["slim_armor_special_ks2019"] = "gif"
|
||||
tempMap["broad_armor_special_ks2019"] = "gif"
|
||||
tempMap["eyewear_special_ks2019"] = "gif"
|
||||
tempMap["head_special_ks2019"] = "gif"
|
||||
tempMap["shield_special_ks2019"] = "gif"
|
||||
tempMap["weapon_special_ks2019"] = "gif"
|
||||
tempMap["Pet-Gryphon-Gryphatrice"] = "gif"
|
||||
tempMap["Mount_Head_Gryphon-Gryphatrice"] = "gif"
|
||||
tempMap["Mount_Body_Gryphon-Gryphatrice"] = "gif"
|
||||
tempMap["background_clocktower"] = "gif"
|
||||
tempMap["background_airship"] = "gif"
|
||||
tempMap["background_steamworks"] = "gif"
|
||||
FILEFORMAT_MAP = Collections.unmodifiableMap(tempMap)
|
||||
|
||||
|
||||
val tempNameMap = HashMap<String, String>()
|
||||
tempNameMap["head_special_1"] = "ContributorOnly-Equip-CrystalHelmet"
|
||||
tempNameMap["armor_special_1"] = "ContributorOnly-Equip-CrystalArmor"
|
||||
tempNameMap["head_special_0"] = "BackerOnly-Equip-ShadeHelmet"
|
||||
tempNameMap["armor_special_0"] = "BackerOnly-Equip-ShadeArmor"
|
||||
tempNameMap["shield_special_0"] = "BackerOnly-Shield-TormentedSkull"
|
||||
tempNameMap["weapon_special_0"] = "BackerOnly-Weapon-DarkSoulsBlade"
|
||||
tempNameMap["weapon_special_critical"] = "weapon_special_critical"
|
||||
tempNameMap["Pet-Wolf-Cerberus"] = "Pet-Wolf-Cerberus"
|
||||
FILENAME_MAP = Collections.unmodifiableMap(tempNameMap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,41 +14,48 @@ import com.facebook.common.executors.CallerThreadExecutor
|
|||
import com.facebook.common.references.CloseableReference
|
||||
import com.facebook.datasource.DataSource
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.drawee.interfaces.DraweeController
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
|
||||
import com.facebook.imagepipeline.image.CloseableImage
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
||||
import com.habitrpg.android.habitica.R
|
||||
import java.util.*
|
||||
|
||||
|
||||
fun SimpleDraweeView.loadImage(imageName: String, imageFormat: String = "png") {
|
||||
fun SimpleDraweeView.loadImage(imageName: String, imageFormat: String? = null) {
|
||||
DataBindingUtils.loadImage(this, imageName, imageFormat)
|
||||
}
|
||||
|
||||
object DataBindingUtils {
|
||||
|
||||
fun loadImage(view: SimpleDraweeView?, imageName: String) {
|
||||
loadImage(view, imageName, "png")
|
||||
loadImage(view, imageName, null)
|
||||
}
|
||||
|
||||
fun loadImage(view: SimpleDraweeView?, imageName: String?, imageFormat: String = "png") {
|
||||
fun loadImage(view: SimpleDraweeView?, imageName: String?, imageFormat: String? = null) {
|
||||
if (view != null && imageName != null && view.visibility == View.VISIBLE) {
|
||||
val fullname = "$imageName.$imageFormat"
|
||||
val fullname = getFullFilename(imageName, imageFormat)
|
||||
if (view.tag == fullname) {
|
||||
return
|
||||
}
|
||||
view.tag = fullname
|
||||
view.setImageURI("https://habitica-assets.s3.amazonaws.com/mobileApp/images/$fullname")
|
||||
val controller: DraweeController = Fresco.newDraweeControllerBuilder()
|
||||
.setUri("https://habitica-assets.s3.amazonaws.com/mobileApp/images/$fullname")
|
||||
.setAutoPlayAnimations(true)
|
||||
.setOldController(view.controller)
|
||||
.build()
|
||||
view.controller = controller
|
||||
}
|
||||
}
|
||||
|
||||
fun loadImage(imageName: String, imageResult: (Bitmap) -> Unit) {
|
||||
loadImage(imageName, "png", imageResult)
|
||||
loadImage(imageName, null, imageResult)
|
||||
}
|
||||
|
||||
fun loadImage(imageName: String, imageFormat: String = "png", imageResult: (Bitmap) -> Unit) {
|
||||
fun loadImage(imageName: String, imageFormat: String?, imageResult: (Bitmap) -> Unit) {
|
||||
val imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource("https://habitica-assets.s3.amazonaws.com/mobileApp/images/$imageName.$imageFormat".toUri())
|
||||
.newBuilderWithSource("https://habitica-assets.s3.amazonaws.com/mobileApp/images/${getFullFilename(imageName, imageFormat)}".toUri())
|
||||
.build()
|
||||
|
||||
val imagePipeline = Fresco.getImagePipeline()
|
||||
|
|
@ -68,6 +75,19 @@ object DataBindingUtils {
|
|||
}, CallerThreadExecutor.getInstance())
|
||||
}
|
||||
|
||||
fun getFullFilename(imageName: String, imageFormat: String?): String {
|
||||
val name = when {
|
||||
FILENAME_MAP.containsKey(imageName) -> FILENAME_MAP[imageName]
|
||||
imageName.startsWith("handleless") -> "chair_$imageName"
|
||||
else -> imageName
|
||||
}
|
||||
return name + if (imageFormat == null && FILEFORMAT_MAP.containsKey(imageName)) {
|
||||
"." + FILEFORMAT_MAP[imageName]
|
||||
} else {
|
||||
".${imageFormat ?: "png"}"
|
||||
}
|
||||
}
|
||||
|
||||
fun setForegroundTintColor(view: TextView, color: Int) {
|
||||
var thisColor = color
|
||||
if (thisColor > 0) {
|
||||
|
|
@ -105,4 +125,49 @@ object DataBindingUtils {
|
|||
|
||||
override fun willChangeBounds(): Boolean = true
|
||||
}
|
||||
|
||||
private val FILEFORMAT_MAP: Map<String, String>
|
||||
private val FILENAME_MAP: Map<String, String>
|
||||
|
||||
init {
|
||||
val tempMap = HashMap<String, String>()
|
||||
tempMap["head_special_1"] = "gif"
|
||||
tempMap["broad_armor_special_1"] = "gif"
|
||||
tempMap["slim_armor_special_1"] = "gif"
|
||||
tempMap["head_special_0"] = "gif"
|
||||
tempMap["slim_armor_special_0"] = "gif"
|
||||
tempMap["broad_armor_special_0"] = "gif"
|
||||
tempMap["weapon_special_critical"] = "gif"
|
||||
tempMap["weapon_special_0"] = "gif"
|
||||
tempMap["shield_special_0"] = "gif"
|
||||
tempMap["Pet-Wolf-Cerberus"] = "gif"
|
||||
tempMap["armor_special_ks2019"] = "gif"
|
||||
tempMap["slim_armor_special_ks2019"] = "gif"
|
||||
tempMap["broad_armor_special_ks2019"] = "gif"
|
||||
tempMap["eyewear_special_ks2019"] = "gif"
|
||||
tempMap["head_special_ks2019"] = "gif"
|
||||
tempMap["shield_special_ks2019"] = "gif"
|
||||
tempMap["weapon_special_ks2019"] = "gif"
|
||||
tempMap["Pet-Gryphon-Gryphatrice"] = "gif"
|
||||
tempMap["Mount_Head_Gryphon-Gryphatrice"] = "gif"
|
||||
tempMap["Mount_Body_Gryphon-Gryphatrice"] = "gif"
|
||||
tempMap["background_clocktower"] = "gif"
|
||||
tempMap["background_airship"] = "gif"
|
||||
tempMap["Pet_HatchingPotion_Veggie"] = "gif"
|
||||
tempMap["Pet_HatchingPotion_Dessert"] = "gif"
|
||||
tempMap["Pet-HatchingPotion-Dessert"] = "gif"
|
||||
FILEFORMAT_MAP = Collections.unmodifiableMap(tempMap)
|
||||
|
||||
|
||||
val tempNameMap = HashMap<String, String>()
|
||||
tempNameMap["head_special_1"] = "ContributorOnly-Equip-CrystalHelmet"
|
||||
tempNameMap["armor_special_1"] = "ContributorOnly-Equip-CrystalArmor"
|
||||
tempNameMap["head_special_0"] = "BackerOnly-Equip-ShadeHelmet"
|
||||
tempNameMap["armor_special_0"] = "BackerOnly-Equip-ShadeArmor"
|
||||
tempNameMap["shield_special_0"] = "BackerOnly-Shield-TormentedSkull"
|
||||
tempNameMap["weapon_special_0"] = "BackerOnly-Weapon-DarkSoulsBlade"
|
||||
tempNameMap["weapon_special_critical"] = "weapon_special_critical"
|
||||
tempNameMap["Pet-Wolf-Cerberus"] = "Pet-Wolf-Cerberus"
|
||||
FILENAME_MAP = Collections.unmodifiableMap(tempNameMap)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue