package com.discord.views.sticker; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; import c.a.i.i1; import c.a.l.b; import c.a.z.o0.a; import c.a.z.o0.d; import c.a.z.o0.e; import c.a.z.o0.f; import c.a.z.o0.h; import c.f.g.e.v; import com.discord.api.sticker.BaseSticker; import com.discord.api.sticker.Sticker; import com.discord.api.sticker.StickerFormatType; import com.discord.api.sticker.StickerPartial; import com.discord.app.AppLog; import com.discord.rlottie.RLottieImageView; import com.discord.stores.StoreStream; import com.discord.stores.StoreUserSettings; import com.discord.utilities.apng.ApngUtils; import com.discord.utilities.dsti.StickerUtils; import com.discord.utilities.images.MGImages; import com.discord.utilities.logging.Logger; import com.discord.utilities.rx.ObservableExtensionsKt; import com.facebook.drawee.drawable.ScalingUtils$ScaleType; import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.facebook.drawee.view.SimpleDraweeView; import d0.z.d.m; import java.io.File; import java.util.Objects; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlinx.coroutines.Job; import rx.Observable; import rx.Subscription; /* compiled from: StickerView.kt */ public final class StickerView extends FrameLayout { public final i1 i; public BaseSticker j; public Subscription k; public Job l; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public StickerView(Context context, AttributeSet attributeSet) { super(context, attributeSet); m.checkNotNullParameter(context, "context"); LayoutInflater.from(getContext()).inflate(2131558673, this); int i = 2131365165; SimpleDraweeView simpleDraweeView = (SimpleDraweeView) findViewById(2131365165); if (simpleDraweeView != null) { i = 2131365166; RLottieImageView rLottieImageView = (RLottieImageView) findViewById(2131365166); if (rLottieImageView != null) { i = 2131365167; ImageView imageView = (ImageView) findViewById(2131365167); if (imageView != null) { i1 i1Var = new i1(this, simpleDraweeView, rLottieImageView, imageView); m.checkNotNullExpressionValue(i1Var, "StickerViewBinding.infla…ater.from(context), this)"); this.i = i1Var; return; } } } throw new NullPointerException("Missing required view with ID: ".concat(getResources().getResourceName(i))); } public static final Job a(StickerView stickerView, File file, boolean z2) { Objects.requireNonNull(stickerView); ApngUtils apngUtils = ApngUtils.INSTANCE; SimpleDraweeView simpleDraweeView = stickerView.i.b; m.checkNotNullExpressionValue(simpleDraweeView, "binding.stickerViewImageview"); StickerUtils stickerUtils = StickerUtils.INSTANCE; return apngUtils.renderApngFromFile(file, simpleDraweeView, Integer.valueOf(stickerUtils.getDEFAULT_STICKER_SIZE_PX()), Integer.valueOf(stickerUtils.getDEFAULT_STICKER_SIZE_PX()), z2); } public static /* synthetic */ void d(StickerView stickerView, BaseSticker baseSticker, Integer num, int i) { int i2 = i & 2; stickerView.c(baseSticker, null); } public final CharSequence b(BaseSticker baseSticker) { if (baseSticker instanceof Sticker) { Context context = getContext(); m.checkNotNullExpressionValue(context, "context"); StringBuilder sb = new StringBuilder(); Sticker sticker = (Sticker) baseSticker; sb.append(sticker.h()); sb.append(", "); sb.append(sticker.f()); return b.g(context, 2131893601, new Object[]{sb.toString()}, null, 4); } else if (!(baseSticker instanceof StickerPartial)) { return null; } else { Context context2 = getContext(); m.checkNotNullExpressionValue(context2, "context"); return b.g(context2, 2131893601, new Object[]{((StickerPartial) baseSticker).d()}, null, 4); } } public final void c(BaseSticker baseSticker, Integer num) { m.checkNotNullParameter(baseSticker, "sticker"); BaseSticker baseSticker2 = this.j; if (baseSticker2 != null && baseSticker2.c() == baseSticker.c()) { if (this.k != null) { return; } } BaseSticker baseSticker3 = this.j; if (baseSticker3 != null && (baseSticker3 == null || baseSticker3.c() != baseSticker.c())) { Subscription subscription = this.k; if (subscription != null) { subscription.unsubscribe(); } this.k = null; } this.j = baseSticker; int ordinal = baseSticker.a().ordinal(); if (ordinal == 1) { SimpleDraweeView simpleDraweeView = this.i.b; m.checkNotNullExpressionValue(simpleDraweeView, "binding.stickerViewImageview"); simpleDraweeView.setVisibility(0); ImageView imageView = this.i.d; m.checkNotNullExpressionValue(imageView, "binding.stickerViewPlaceholder"); imageView.setVisibility(8); RLottieImageView rLottieImageView = this.i.f104c; m.checkNotNullExpressionValue(rLottieImageView, "binding.stickerViewLottie"); rLottieImageView.setVisibility(8); SimpleDraweeView simpleDraweeView2 = this.i.b; m.checkNotNullExpressionValue(simpleDraweeView2, "binding.stickerViewImageview"); simpleDraweeView2.setContentDescription(b(baseSticker)); SimpleDraweeView simpleDraweeView3 = this.i.b; m.checkNotNullExpressionValue(simpleDraweeView3, "binding.stickerViewImageview"); MGImages.setImage$default(simpleDraweeView3, StickerUtils.getCDNAssetUrl$default(StickerUtils.INSTANCE, baseSticker, null, false, 6, null), 0, 0, false, null, null, 124, null); SimpleDraweeView simpleDraweeView4 = this.i.b; m.checkNotNullExpressionValue(simpleDraweeView4, "binding.stickerViewImageview"); GenericDraweeHierarchy hierarchy = simpleDraweeView4.getHierarchy(); m.checkNotNullExpressionValue(hierarchy, "binding.stickerViewImageview.hierarchy"); ScalingUtils$ScaleType scalingUtils$ScaleType = ScalingUtils$ScaleType.a; hierarchy.n(v.l); } else if (ordinal == 2) { SimpleDraweeView simpleDraweeView5 = this.i.b; m.checkNotNullExpressionValue(simpleDraweeView5, "binding.stickerViewImageview"); simpleDraweeView5.setVisibility(0); ImageView imageView2 = this.i.d; m.checkNotNullExpressionValue(imageView2, "binding.stickerViewPlaceholder"); imageView2.setVisibility(0); RLottieImageView rLottieImageView2 = this.i.f104c; m.checkNotNullExpressionValue(rLottieImageView2, "binding.stickerViewLottie"); rLottieImageView2.setVisibility(8); this.i.b.setImageDrawable(null); SimpleDraweeView simpleDraweeView6 = this.i.b; m.checkNotNullExpressionValue(simpleDraweeView6, "binding.stickerViewImageview"); GenericDraweeHierarchy hierarchy2 = simpleDraweeView6.getHierarchy(); m.checkNotNullExpressionValue(hierarchy2, "binding.stickerViewImageview.hierarchy"); ScalingUtils$ScaleType scalingUtils$ScaleType2 = ScalingUtils$ScaleType.a; hierarchy2.n(v.l); Sticker sticker = baseSticker instanceof Sticker ? (Sticker) baseSticker : null; StickerUtils stickerUtils = StickerUtils.INSTANCE; Context context = getContext(); m.checkNotNullExpressionValue(context, "context"); Observable j = Observable.j(ObservableExtensionsKt.restSubscribeOn$default(stickerUtils.fetchSticker(context, baseSticker), false, 1, null), StoreUserSettings.observeStickerAnimationSettings$default(StoreStream.Companion.getUserSettings(), false, 1, null), a.i); m.checkNotNullExpressionValue(j, "Observable.combineLatest…lobalAnimationSettings) }"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(j), StickerView.class, (Context) null, new c.a.z.o0.b(this), (Function1) null, (Function0) null, (Function0) null, new d(this, num, baseSticker, sticker), 58, (Object) null); } else if (ordinal != 3) { AppLog appLog = AppLog.g; Logger.e$default(appLog, "Invalid Sticker Format passed to " + StickerView.class + ", type: " + baseSticker.a(), null, null, 6, null); } else { SimpleDraweeView simpleDraweeView7 = this.i.b; m.checkNotNullExpressionValue(simpleDraweeView7, "binding.stickerViewImageview"); simpleDraweeView7.setVisibility(8); ImageView imageView3 = this.i.d; m.checkNotNullExpressionValue(imageView3, "binding.stickerViewPlaceholder"); imageView3.setVisibility(0); RLottieImageView rLottieImageView3 = this.i.f104c; m.checkNotNullExpressionValue(rLottieImageView3, "binding.stickerViewLottie"); rLottieImageView3.setVisibility(0); this.i.f104c.setImageDrawable(null); this.i.f104c.clearAnimation(); StickerUtils stickerUtils2 = StickerUtils.INSTANCE; Context context2 = getContext(); m.checkNotNullExpressionValue(context2, "context"); Observable j2 = Observable.j(ObservableExtensionsKt.restSubscribeOn$default(stickerUtils2.fetchSticker(context2, baseSticker), false, 1, null), StoreUserSettings.observeStickerAnimationSettings$default(StoreStream.Companion.getUserSettings(), false, 1, null), e.i); m.checkNotNullExpressionValue(j2, "Observable.combineLatest…lobalAnimationSettings) }"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(j2), StickerView.class, (Context) null, new f(this), (Function1) null, (Function0) null, (Function0) null, new h(this, num, baseSticker), 58, (Object) null); } } public final Subscription getSubscription() { return this.k; } @Override // android.view.View, android.view.ViewGroup public void onDetachedFromWindow() { super.onDetachedFromWindow(); Subscription subscription = this.k; if (subscription != null) { subscription.unsubscribe(); } this.k = null; } @Override // android.view.View public void setOnClickListener(View.OnClickListener onClickListener) { BaseSticker baseSticker = this.j; StickerFormatType a = baseSticker != null ? baseSticker.a() : null; if (a != null) { int ordinal = a.ordinal(); if (ordinal == 1 || ordinal == 2) { this.i.b.setOnClickListener(onClickListener); } else if (ordinal == 3) { this.i.f104c.setOnClickListener(onClickListener); } } } }