discord-jadx/app/src/main/java/com/discord/widgets/user/presence/ViewHolderPlatformRichPrese...

141 lines
8.2 KiB
Java

package com.discord.widgets.user.presence;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.MainThread;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.view.ViewKt;
import androidx.fragment.app.FragmentManager;
import c.a.l.b;
import com.discord.api.activity.Activity;
import com.discord.api.activity.ActivityTimestamps;
import com.discord.api.application.Application;
import com.discord.models.user.User;
import com.discord.stores.StoreStream;
import com.discord.utilities.color.ColorCompat;
import com.discord.utilities.icon.IconUtils;
import com.discord.utilities.images.MGImages;
import com.discord.utilities.platform.Platform;
import com.discord.utilities.presence.ActivityUtilsKt;
import com.discord.utilities.presence.PresenceUtils;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.streams.StreamContext;
import com.discord.utilities.view.extensions.ViewExtensions;
import com.facebook.drawee.view.SimpleDraweeView;
import d0.z.d.m;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import rx.Observable;
import rx.subscriptions.CompositeSubscription;
/* compiled from: ViewHolderPlatformRichPresence.kt */
public final class ViewHolderPlatformRichPresence extends ViewHolderUserRichPresence {
private final CompositeSubscription subscriptions = new CompositeSubscription();
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public ViewHolderPlatformRichPresence(View view, SimpleDraweeView simpleDraweeView, SimpleDraweeView simpleDraweeView2, TextView textView, TextView textView2, TextView textView3, View view2, Button button) {
super(view, simpleDraweeView, simpleDraweeView2, textView, textView2, null, textView3, null, view2, button, null, 3);
m.checkNotNullParameter(view, "root");
m.checkNotNullParameter(simpleDraweeView, "richPresenceImageLarge");
m.checkNotNullParameter(simpleDraweeView2, "richPresenceImageSmall");
m.checkNotNullParameter(textView, "richPresenceHeader");
m.checkNotNullParameter(textView2, "richPresenceTitle");
m.checkNotNullParameter(textView3, "richPresenceTime");
m.checkNotNullParameter(view2, "richPresenceTextContainer");
m.checkNotNullParameter(button, "richPresencePrimaryButton");
}
private final void configureImages(Platform platform, ModelRichPresence modelRichPresence) {
Application primaryApplication;
String str = null;
super.configureAssetUi(modelRichPresence != null ? modelRichPresence.getPrimaryActivity() : null, null);
Integer whitePlatformImage = platform.getWhitePlatformImage();
SimpleDraweeView richPresenceImageSmall = getRichPresenceImageSmall();
if (richPresenceImageSmall != null) {
ViewKt.setVisible(richPresenceImageSmall, (whitePlatformImage == null || platform == Platform.NONE) ? false : true);
}
if (platform != Platform.NONE) {
Button richPresencePrimaryButton = getRichPresencePrimaryButton();
if (richPresencePrimaryButton != null) {
Button richPresencePrimaryButton2 = getRichPresencePrimaryButton();
Integer colorResId = platform.getColorResId();
richPresencePrimaryButton.setBackgroundColor(ColorCompat.getColor(richPresencePrimaryButton2, colorResId != null ? colorResId.intValue() : 0));
}
SimpleDraweeView richPresenceImageSmall2 = getRichPresenceImageSmall();
Resources resources = richPresenceImageSmall2 != null ? richPresenceImageSmall2.getResources() : null;
Drawable drawable = (whitePlatformImage == null || resources == null) ? null : ResourcesCompat.getDrawable(resources, whitePlatformImage.intValue(), null);
SimpleDraweeView richPresenceImageSmall3 = getRichPresenceImageSmall();
if (richPresenceImageSmall3 != null) {
richPresenceImageSmall3.setImageDrawable(drawable);
}
}
if (platform == Platform.XBOX && platform.getPlatformImage() != null) {
MGImages.setImage$default(MGImages.INSTANCE, getRichPresenceImageLarge(), platform.getPlatformImage().intValue(), (MGImages.ChangeDetector) null, 4, (Object) null);
} else if (getRichPresenceImageLarge().getVisibility() != 0) {
if (!(modelRichPresence == null || (primaryApplication = modelRichPresence.getPrimaryApplication()) == null)) {
long f = primaryApplication.f();
String e = primaryApplication.e();
if (e == null) {
e = "";
}
str = IconUtils.getApplicationIcon$default(f, e, 0, 4, null);
}
getRichPresenceImageLarge().setVisibility(0);
MGImages.setImage$default(getRichPresenceImageLarge(), str, 0, 0, false, null, null, 124, null);
}
}
@Override // com.discord.widgets.user.presence.ViewHolderUserRichPresence
@MainThread
public void configureUi(FragmentManager fragmentManager, StreamContext streamContext, boolean z2, User user, Context context, ModelRichPresence modelRichPresence, boolean z3) {
m.checkNotNullParameter(fragmentManager, "fragmentManager");
m.checkNotNullParameter(context, "applicationContext");
disposeSubscriptions();
Activity primaryActivity = modelRichPresence != null ? modelRichPresence.getPrimaryActivity() : null;
if (primaryActivity == null || !ActivityUtilsKt.isGamePlatform(primaryActivity)) {
getRoot().setVisibility(8);
return;
}
getRoot().setVisibility(0);
Platform from = ActivityUtilsKt.isXboxActivity(primaryActivity) ? Platform.XBOX : Platform.Companion.from(primaryActivity.j());
TextView richPresenceHeader = getRichPresenceHeader();
Context context2 = getRichPresenceHeader().getContext();
m.checkNotNullExpressionValue(context2, "richPresenceHeader.context");
richPresenceHeader.setText(PresenceUtils.getActivityHeader(context2, primaryActivity));
getRichPresenceTitle().setText(primaryActivity.h());
TextView richPresenceTime = getRichPresenceTime();
ActivityTimestamps o = primaryActivity.o();
ViewExtensions.setTextAndVisibilityBy(richPresenceTime, o != null ? friendlyTime(o) : null);
getRichPresenceTextContainer().setSelected(true);
Button richPresencePrimaryButton = getRichPresencePrimaryButton();
if (richPresencePrimaryButton != null) {
ViewKt.setVisible(richPresencePrimaryButton, from.getEnabled());
}
Button richPresencePrimaryButton2 = getRichPresencePrimaryButton();
if (richPresencePrimaryButton2 != null) {
Context context3 = getRoot().getContext();
m.checkNotNullExpressionValue(context3, "root.context");
richPresencePrimaryButton2.setText(b.g(context3, 2131894281, new Object[]{from.getProperName()}, null, 4));
}
if (from.getEnabled()) {
Observable r = StoreStream.Companion.getUserConnections().observeConnectedAccounts().F(new ViewHolderPlatformRichPresence$configureUi$1(from)).r();
m.checkNotNullExpressionValue(r, "StoreStream\n .g… .distinctUntilChanged()");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(r), ViewHolderPlatformRichPresence.class, (Context) null, new ViewHolderPlatformRichPresence$configureUi$2(this.subscriptions), (Function1) null, (Function0) null, (Function0) null, new ViewHolderPlatformRichPresence$configureUi$3(this), 58, (Object) null);
Button richPresencePrimaryButton3 = getRichPresencePrimaryButton();
if (richPresencePrimaryButton3 != null) {
richPresencePrimaryButton3.setOnClickListener(new ViewHolderPlatformRichPresence$configureUi$4(from));
}
}
configureImages(from, modelRichPresence);
}
@Override // com.discord.widgets.user.presence.ViewHolderUserRichPresence
public void disposeSubscriptions() {
super.disposeSubscriptions();
this.subscriptions.b();
}
}