package com.discord.widgets.settings; import android.content.ContentResolver; import android.content.Context; import android.hardware.camera2.CameraManager; import android.os.Build; import android.view.View; import android.widget.SeekBar; import android.widget.TextView; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import c.a.d.j; import c.d.b.a.a; import com.discord.R; import com.discord.app.AppFragment; import com.discord.app.AppLog; import com.discord.databinding.WidgetSettingsAppearanceBinding; import com.discord.models.domain.ModelUserSettings; import com.discord.models.user.MeUser; import com.discord.stores.StoreStream; import com.discord.stores.StoreUser; import com.discord.utilities.accessibility.AccessibilityUtils; import com.discord.utilities.analytics.ChatInputComponentTypes; import com.discord.utilities.font.FontUtils; import com.discord.utilities.icon.IconUtils; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.time.ClockFactory; import com.discord.utilities.time.TimeUtils; import com.discord.utilities.view.ToastManager; import com.discord.utilities.view.text.LinkifiedTextView; import com.discord.utilities.viewbinding.FragmentViewBindingDelegate; import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt; import com.discord.views.CheckedSetting; import com.facebook.drawee.view.SimpleDraweeView; import d0.g; import d0.t.n; import d0.z.d.m; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import kotlin.Lazy; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.reflect.KProperty; import rx.Observable; import rx.subjects.BehaviorSubject; /* compiled from: WidgetSettingsAppearance.kt */ public final class WidgetSettingsAppearance extends AppFragment { public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.a0(WidgetSettingsAppearance.class, "binding", "getBinding()Lcom/discord/databinding/WidgetSettingsAppearanceBinding;", 0)}; public static final Companion Companion = new Companion(null); private static final int EASTER_EGG_UNLOCK_TIMEOUT = 5; private static final int HOLY_LIGHT_UNLOCK_COUNT = 5; private static final int PURE_EVIL_HINT_COUNT = 3; private static final int PURE_EVIL_UNLOCK_COUNT = 8; private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetSettingsAppearance$binding$2.INSTANCE, null, 2, null); private final AtomicInteger holyLightEasterEggCounter = new AtomicInteger(0); private final BehaviorSubject newFontScaleSubject = BehaviorSubject.j0(); private final AtomicInteger pureEvilEasterEggCounter = new AtomicInteger(0); private final Lazy pureEvilEasterEggSubject$delegate = g.lazy(WidgetSettingsAppearance$pureEvilEasterEggSubject$2.INSTANCE); private ToastManager toastManager = new ToastManager(); /* compiled from: WidgetSettingsAppearance.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final void launch(Context context) { m.checkNotNullParameter(context, "context"); j.e(context, WidgetSettingsAppearance.class, null, 4); } } /* compiled from: WidgetSettingsAppearance.kt */ public static final class Model { public static final Companion Companion = new Companion(null); private final boolean canSeePureEvil; private final String currentTheme; private final int fontScale; private final MeUser meUser; /* compiled from: WidgetSettingsAppearance.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final Observable get(Observable observable) { m.checkNotNullParameter(observable, "easterEggPureEvil"); StoreStream.Companion companion = StoreStream.Companion; Observable i = Observable.i(StoreUser.observeMe$default(companion.getUsers(), false, 1, null), companion.getUserSettingsSystem().observeSettings(false), observable, WidgetSettingsAppearance$Model$Companion$get$1.INSTANCE); m.checkNotNullExpressionValue(i, "Observable\n .… )\n }"); return i; } } public Model(String str, boolean z2, int i, MeUser meUser) { m.checkNotNullParameter(str, "currentTheme"); m.checkNotNullParameter(meUser, "meUser"); this.currentTheme = str; this.canSeePureEvil = z2; this.fontScale = i; this.meUser = meUser; } public static /* synthetic */ Model copy$default(Model model, String str, boolean z2, int i, MeUser meUser, int i2, Object obj) { if ((i2 & 1) != 0) { str = model.currentTheme; } if ((i2 & 2) != 0) { z2 = model.canSeePureEvil; } if ((i2 & 4) != 0) { i = model.fontScale; } if ((i2 & 8) != 0) { meUser = model.meUser; } return model.copy(str, z2, i, meUser); } public final String component1() { return this.currentTheme; } public final boolean component2() { return this.canSeePureEvil; } public final int component3() { return this.fontScale; } public final MeUser component4() { return this.meUser; } public final Model copy(String str, boolean z2, int i, MeUser meUser) { m.checkNotNullParameter(str, "currentTheme"); m.checkNotNullParameter(meUser, "meUser"); return new Model(str, z2, i, meUser); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Model)) { return false; } Model model = (Model) obj; return m.areEqual(this.currentTheme, model.currentTheme) && this.canSeePureEvil == model.canSeePureEvil && this.fontScale == model.fontScale && m.areEqual(this.meUser, model.meUser); } public final boolean getCanSeePureEvil() { return this.canSeePureEvil; } public final String getCurrentTheme() { return this.currentTheme; } public final int getFontScale() { return this.fontScale; } public final MeUser getMeUser() { return this.meUser; } public int hashCode() { String str = this.currentTheme; int i = 0; int hashCode = (str != null ? str.hashCode() : 0) * 31; boolean z2 = this.canSeePureEvil; if (z2) { z2 = true; } int i2 = z2 ? 1 : 0; int i3 = z2 ? 1 : 0; int i4 = z2 ? 1 : 0; int i5 = (((hashCode + i2) * 31) + this.fontScale) * 31; MeUser meUser = this.meUser; if (meUser != null) { i = meUser.hashCode(); } return i5 + i; } public String toString() { StringBuilder P = a.P("Model(currentTheme="); P.append(this.currentTheme); P.append(", canSeePureEvil="); P.append(this.canSeePureEvil); P.append(", fontScale="); P.append(this.fontScale); P.append(", meUser="); P.append(this.meUser); P.append(")"); return P.toString(); } } public WidgetSettingsAppearance() { super(R.layout.widget_settings_appearance); } public static final /* synthetic */ void access$configureUI(WidgetSettingsAppearance widgetSettingsAppearance, Model model) { widgetSettingsAppearance.configureUI(model); } public static final /* synthetic */ WidgetSettingsAppearanceBinding access$getBinding$p(WidgetSettingsAppearance widgetSettingsAppearance) { return widgetSettingsAppearance.getBinding(); } public static final /* synthetic */ String access$getFontScaleString(WidgetSettingsAppearance widgetSettingsAppearance, int i, boolean z2) { return widgetSettingsAppearance.getFontScaleString(i, z2); } public static final /* synthetic */ AtomicInteger access$getHolyLightEasterEggCounter$p(WidgetSettingsAppearance widgetSettingsAppearance) { return widgetSettingsAppearance.holyLightEasterEggCounter; } public static final /* synthetic */ BehaviorSubject access$getNewFontScaleSubject$p(WidgetSettingsAppearance widgetSettingsAppearance) { return widgetSettingsAppearance.newFontScaleSubject; } public static final /* synthetic */ AtomicInteger access$getPureEvilEasterEggCounter$p(WidgetSettingsAppearance widgetSettingsAppearance) { return widgetSettingsAppearance.pureEvilEasterEggCounter; } public static final /* synthetic */ BehaviorSubject access$getPureEvilEasterEggSubject$p(WidgetSettingsAppearance widgetSettingsAppearance) { return widgetSettingsAppearance.getPureEvilEasterEggSubject(); } public static final /* synthetic */ ToastManager access$getToastManager$p(WidgetSettingsAppearance widgetSettingsAppearance) { return widgetSettingsAppearance.toastManager; } public static final /* synthetic */ void access$setToastManager$p(WidgetSettingsAppearance widgetSettingsAppearance, ToastManager toastManager) { widgetSettingsAppearance.toastManager = toastManager; } public static final /* synthetic */ void access$showHolyLight(WidgetSettingsAppearance widgetSettingsAppearance) { widgetSettingsAppearance.showHolyLight(); } public static final /* synthetic */ void access$tryEnableTorchMode(WidgetSettingsAppearance widgetSettingsAppearance, boolean z2) { widgetSettingsAppearance.tryEnableTorchMode(z2); } public static final /* synthetic */ void access$updateTheme(WidgetSettingsAppearance widgetSettingsAppearance, String str) { widgetSettingsAppearance.updateTheme(str); } private final void configureFontScalingUI(int i) { FragmentActivity activity; ContentResolver contentResolver; int systemFontScaleInt = (i != -1 || (activity = getActivity()) == null || (contentResolver = activity.getContentResolver()) == null) ? i : FontUtils.INSTANCE.getSystemFontScaleInt(contentResolver); TextView textView = getBinding().d; m.checkNotNullExpressionValue(textView, "binding.settingsAppearanceFontScalePlatform"); textView.setText(getFontScaleString(systemFontScaleInt, i == -1)); SeekBar seekBar = getBinding().f; m.checkNotNullExpressionValue(seekBar, "binding.settingsAppearanceFontScalingSeekbar"); seekBar.setProgress(systemFontScaleInt - 80); } private final void configureThemeOption(CheckedSetting checkedSetting, String str) { checkedSetting.setOnCheckedListener(new WidgetSettingsAppearance$configureThemeOption$1(this, str)); } private final void configureUI(Model model) { boolean z2 = !m.areEqual(model.getCurrentTheme(), ModelUserSettings.THEME_LIGHT); getBinding().l.g(!z2, false); CheckedSetting checkedSetting = getBinding().l; m.checkNotNullExpressionValue(checkedSetting, "binding.settingsAppearanceThemeLightRadio"); configureThemeOption(checkedSetting, ModelUserSettings.THEME_LIGHT); getBinding().l.e(new WidgetSettingsAppearance$configureUI$1(this)); getBinding().j.g(z2, false); CheckedSetting checkedSetting2 = getBinding().j; m.checkNotNullExpressionValue(checkedSetting2, "binding.settingsAppearanceThemeDarkRadio"); configureThemeOption(checkedSetting2, ModelUserSettings.THEME_DARK); getBinding().j.e(new WidgetSettingsAppearance$configureUI$2(this, model)); if (m.areEqual(model.getCurrentTheme(), ModelUserSettings.THEME_PURE_EVIL)) { CheckedSetting.d(getBinding().m, null, 1); } getBinding().m.g(m.areEqual(model.getCurrentTheme(), ModelUserSettings.THEME_PURE_EVIL), false); CheckedSetting checkedSetting3 = getBinding().m; m.checkNotNullExpressionValue(checkedSetting3, "binding.settingsAppearanceThemePureEvilSwitch"); checkedSetting3.setVisibility(model.getCanSeePureEvil() ? 0 : 8); getBinding().m.setOnCheckedListener(new WidgetSettingsAppearance$configureUI$3(this, model)); configureFontScalingUI(model.getFontScale()); getBinding().f.setOnSeekBarChangeListener(new WidgetSettingsAppearance$configureUI$4(this)); getBinding().e.setOnClickListener(WidgetSettingsAppearance$configureUI$5.INSTANCE); setupMessage(model); for (TextView textView : n.listOf((Object[]) new TextView[]{getBinding().k, getBinding().h, getBinding().f1995c})) { AccessibilityUtils accessibilityUtils = AccessibilityUtils.INSTANCE; m.checkNotNullExpressionValue(textView, "header"); accessibilityUtils.setViewIsHeading(textView); } } private final WidgetSettingsAppearanceBinding getBinding() { return (WidgetSettingsAppearanceBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]); } private final String getFontScaleString(int i, boolean z2) { if (z2) { return i + "% (" + getString(R.string.accessibility_font_scaling_use_os) + ')'; } return i + "% (" + getString(R.string.accessibility_font_scaling_use_app) + ')'; } public static /* synthetic */ String getFontScaleString$default(WidgetSettingsAppearance widgetSettingsAppearance, int i, boolean z2, int i2, Object obj) { if ((i2 & 2) != 0) { z2 = true; } return widgetSettingsAppearance.getFontScaleString(i, z2); } private final BehaviorSubject getPureEvilEasterEggSubject() { return (BehaviorSubject) this.pureEvilEasterEggSubject$delegate.getValue(); } private final void setupMessage(Model model) { SimpleDraweeView simpleDraweeView = getBinding().b.f1793c; m.checkNotNullExpressionValue(simpleDraweeView, "binding.chatItem.chatListAdapterItemTextAvatar"); IconUtils.setIcon$default(simpleDraweeView, model.getMeUser(), R.dimen.avatar_size_standard, null, null, null, 56, null); TextView textView = getBinding().b.e; m.checkNotNullExpressionValue(textView, "binding.chatItem.chatListAdapterItemTextTag"); textView.setVisibility(8); TextView textView2 = getBinding().b.d; m.checkNotNullExpressionValue(textView2, "binding.chatItem.chatListAdapterItemTextName"); textView2.setText(model.getMeUser().getUsername()); TextView textView3 = getBinding().b.f; m.checkNotNullExpressionValue(textView3, "binding.chatItem.chatListAdapterItemTextTimestamp"); textView3.setText(TimeUtils.toReadableTimeString$default(requireContext(), ClockFactory.get().currentTimeMillis(), null, 4, null)); LinkifiedTextView linkifiedTextView = getBinding().b.b; m.checkNotNullExpressionValue(linkifiedTextView, "binding.chatItem.chatListAdapterItemText"); linkifiedTextView.setText(getString(R.string.user_settings_appearance_preview_message_1)); } private final void showHolyLight() { c.a.d.m.d(getContext(), R.string.theme_holy_light_reveal, 0, this.toastManager); tryEnableTorchMode(true); View view = getBinding().g; m.checkNotNullExpressionValue(view, "binding.settingsAppearanceHolyLight"); view.setVisibility(0); Observable c02 = Observable.c0(3, TimeUnit.SECONDS); m.checkNotNullExpressionValue(c02, "Observable\n .timer(3, TimeUnit.SECONDS)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(c02, this, null, 2, null), WidgetSettingsAppearance.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetSettingsAppearance$showHolyLight$1(this), 62, (Object) null); } private final void tryEnableTorchMode(boolean z2) { String str; if (Build.VERSION.SDK_INT >= 23) { Context context = getContext(); CameraManager cameraManager = (CameraManager) (context != null ? context.getSystemService(ChatInputComponentTypes.CAMERA) : null); if (cameraManager != null) { try { String[] cameraIdList = cameraManager.getCameraIdList(); if (cameraIdList != null && (str = cameraIdList[0]) != null) { cameraManager.setTorchMode(str, z2); } } catch (Exception e) { AppLog.g.w("Unable to turn on flashlight", e); } } } } private final void updateTheme(String str) { StoreStream.Companion.getUserSettingsSystem().setTheme(str, true, new WidgetSettingsAppearance$updateTheme$1(this, str)); } @Override // com.discord.app.AppFragment, androidx.fragment.app.Fragment public void onDestroyView() { this.toastManager.close(); super.onDestroyView(); } @Override // com.discord.app.AppFragment public void onViewBound(View view) { m.checkNotNullParameter(view, "view"); super.onViewBound(view); setActionBarTitle(R.string.appearance); setActionBarSubtitle(R.string.user_settings); AppFragment.setActionBarDisplayHomeAsUpEnabled$default(this, false, 1, null); SeekBar seekBar = getBinding().f; m.checkNotNullExpressionValue(seekBar, "binding.settingsAppearanceFontScalingSeekbar"); seekBar.setMax(70); } @Override // com.discord.app.AppFragment public void onViewBoundOrOnResume() { super.onViewBoundOrOnResume(); Model.Companion companion = Model.Companion; BehaviorSubject pureEvilEasterEggSubject = getPureEvilEasterEggSubject(); m.checkNotNullExpressionValue(pureEvilEasterEggSubject, "pureEvilEasterEggSubject"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(companion.get(pureEvilEasterEggSubject), this, null, 2, null), WidgetSettingsAppearance.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetSettingsAppearance$onViewBoundOrOnResume$1(this), 62, (Object) null); Observable o = this.newFontScaleSubject.o(400, TimeUnit.MILLISECONDS); m.checkNotNullExpressionValue(o, "newFontScaleSubject\n …0, TimeUnit.MILLISECONDS)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(o, this, null, 2, null), WidgetSettingsAppearance.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, WidgetSettingsAppearance$onViewBoundOrOnResume$2.INSTANCE, 62, (Object) null); CheckedSetting checkedSetting = getBinding().i; m.checkNotNullExpressionValue(checkedSetting, "binding.settingsAppearanceSyncSwitch"); checkedSetting.setChecked(StoreStream.Companion.getUserSettingsSystem().getIsThemeSyncEnabled()); getBinding().i.setOnCheckedListener(WidgetSettingsAppearance$onViewBoundOrOnResume$3.INSTANCE); } }