discord-jadx/app/src/main/java/com/discord/stores/StoreUserSettingsSystem.java

343 lines
13 KiB
Java

package com.discord.stores;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import c.d.b.a.a;
import com.discord.models.domain.ModelPayload;
import com.discord.models.domain.ModelUserSettings;
import com.discord.models.domain.auth.ModelLoginResult;
import com.discord.models.domain.auth.ModelUserSettingsBootstrap;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
import com.discord.utilities.cache.SharedPreferenceExtensionsKt;
import d0.z.d.m;
import java.util.concurrent.TimeUnit;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreUserSettingsSystem.kt */
public final class StoreUserSettingsSystem extends StoreV2 {
public static final Companion Companion = new Companion(null);
private static final boolean DEFAULT_IS_CLIENT_SYNC_ENABLED = true;
private final Function1<Integer, Unit> onFontScaleUpdated;
private Settings settings;
/* compiled from: StoreUserSettingsSystem.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: StoreUserSettingsSystem.kt */
public static final class Settings {
private final int fontScale;
private final String locale;
private final String theme;
public Settings(String str, String str2, int i) {
m.checkNotNullParameter(str, "theme");
m.checkNotNullParameter(str2, "locale");
this.theme = str;
this.locale = str2;
this.fontScale = i;
}
public static /* synthetic */ Settings copy$default(Settings settings, String str, String str2, int i, int i2, Object obj) {
if ((i2 & 1) != 0) {
str = settings.theme;
}
if ((i2 & 2) != 0) {
str2 = settings.locale;
}
if ((i2 & 4) != 0) {
i = settings.fontScale;
}
return settings.copy(str, str2, i);
}
public final String component1() {
return this.theme;
}
public final String component2() {
return this.locale;
}
public final int component3() {
return this.fontScale;
}
public final Settings copy(String str, String str2, int i) {
m.checkNotNullParameter(str, "theme");
m.checkNotNullParameter(str2, "locale");
return new Settings(str, str2, i);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Settings)) {
return false;
}
Settings settings = (Settings) obj;
return m.areEqual(this.theme, settings.theme) && m.areEqual(this.locale, settings.locale) && this.fontScale == settings.fontScale;
}
public final int getFontScale() {
return this.fontScale;
}
public final String getLocale() {
return this.locale;
}
public final String getTheme() {
return this.theme;
}
public int hashCode() {
String str = this.theme;
int i = 0;
int hashCode = (str != null ? str.hashCode() : 0) * 31;
String str2 = this.locale;
if (str2 != null) {
i = str2.hashCode();
}
return ((hashCode + i) * 31) + this.fontScale;
}
public String toString() {
StringBuilder L = a.L("Settings(theme=");
L.append(this.theme);
L.append(", locale=");
L.append(this.locale);
L.append(", fontScale=");
return a.z(L, this.fontScale, ")");
}
}
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: kotlin.jvm.functions.Function1<? super java.lang.Integer, kotlin.Unit> */
/* JADX WARN: Multi-variable type inference failed */
public StoreUserSettingsSystem(Function1<? super Integer, Unit> function1) {
m.checkNotNullParameter(function1, "onFontScaleUpdated");
this.onFontScaleUpdated = function1;
}
public static final /* synthetic */ Settings access$getSettings$p(StoreUserSettingsSystem storeUserSettingsSystem) {
Settings settings = storeUserSettingsSystem.settings;
if (settings == null) {
m.throwUninitializedPropertyAccessException("settings");
}
return settings;
}
public static final /* synthetic */ void access$setSettings$p(StoreUserSettingsSystem storeUserSettingsSystem, Settings settings) {
storeUserSettingsSystem.settings = settings;
}
@StoreThread
private final void handleUserSettings(ModelUserSettings modelUserSettings) {
handleUserSettingsThemeUpdate(modelUserSettings.getTheme());
handleUserSettingsLocaleUpdate(modelUserSettings.getLocale());
}
private final void handleUserSettingsLocaleUpdate(String str) {
if (str != null && getIsLocaleSyncEnabled()) {
setLocale$default(this, str, false, null, 4, null);
}
}
@StoreThread
private final void handleUserSettingsThemeUpdate(String str) {
if (str != null && getIsThemeSyncEnabled()) {
setTheme$default(this, str, false, null, 4, null);
}
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreUserSettingsSystem */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ void setLocale$default(StoreUserSettingsSystem storeUserSettingsSystem, String str, boolean z2, Function0 function0, int i, Object obj) {
if ((i & 4) != 0) {
function0 = null;
}
storeUserSettingsSystem.setLocale(str, z2, function0);
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreUserSettingsSystem */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ void setTheme$default(StoreUserSettingsSystem storeUserSettingsSystem, String str, boolean z2, Function0 function0, int i, Object obj) {
if ((i & 4) != 0) {
function0 = null;
}
storeUserSettingsSystem.setTheme(str, z2, function0);
}
public final int getFontScale() {
Settings settings = this.settings;
if (settings == null) {
m.throwUninitializedPropertyAccessException("settings");
}
return settings.getFontScale();
}
public final boolean getIsLocaleSyncEnabled() {
return getPrefs().getBoolean("CACHE_KEY_LOCALE_SYNC", true);
}
public final boolean getIsThemeSyncEnabled() {
return getPrefsSessionDurable().getBoolean("CACHE_KEY_THEME_SYNC", true);
}
public final String getLocale() {
Settings settings = this.settings;
if (settings == null) {
m.throwUninitializedPropertyAccessException("settings");
}
return settings.getLocale();
}
public final String getTheme() {
Settings settings = this.settings;
if (settings == null) {
m.throwUninitializedPropertyAccessException("settings");
}
return settings.getTheme();
}
@StoreThread
public final void handleConnectionOpen(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
ModelUserSettings userSettings = modelPayload.getUserSettings();
m.checkNotNullExpressionValue(userSettings, "payload.userSettings");
handleUserSettings(userSettings);
}
@StoreThread
public final void handleLoginResult(ModelLoginResult modelLoginResult) {
m.checkNotNullParameter(modelLoginResult, "loginResult");
ModelUserSettingsBootstrap userSettings = modelLoginResult.getUserSettings();
String str = null;
handleUserSettingsThemeUpdate(userSettings != null ? userSettings.getTheme() : null);
ModelUserSettingsBootstrap userSettings2 = modelLoginResult.getUserSettings();
if (userSettings2 != null) {
str = userSettings2.getLocale();
}
handleUserSettingsLocaleUpdate(str);
}
@StoreThread
public final void handlePreLogout() {
setIsSyncThemeEnabled(true);
setIsLocaleSyncEnabled(true);
String str = ModelUserSettings.LOCALE_DEFAULT;
m.checkNotNullExpressionValue(str, "ModelUserSettings.LOCALE_DEFAULT");
setLocale$default(this, str, false, null, 4, null);
setFontScale(-1);
}
@StoreThread
public final void handleUserSettingsUpdate(ModelUserSettings modelUserSettings) {
m.checkNotNullParameter(modelUserSettings, "userSettings");
handleUserSettings(modelUserSettings);
}
@Override // com.discord.stores.Store
@StoreThread
public void init(Context context) {
m.checkNotNullParameter(context, "context");
super.init(context);
Resources resources = context.getResources();
m.checkNotNullExpressionValue(resources, "context.resources");
String stringNonNull = SharedPreferenceExtensionsKt.getStringNonNull(getPrefsSessionDurable(), "CACHE_KEY_THEME", (resources.getConfiguration().uiMode & 48) != 32 ? "light" : "dark");
SharedPreferences prefs = getPrefs();
String str = ModelUserSettings.LOCALE_DEFAULT;
m.checkNotNullExpressionValue(str, "ModelUserSettings.LOCALE_DEFAULT");
this.settings = new Settings(stringNonNull, SharedPreferenceExtensionsKt.getStringNonNull(prefs, "CACHE_KEY_LOCALE", str), getPrefs().getInt("CACHE_KEY_FONT_SCALE", -1));
}
public final Observable<Settings> observeSettings(boolean z2) {
Observable connectRx$default = ObservationDeck.connectRx$default(ObservationDeckProvider.get(), new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserSettingsSystem$observeSettings$1(this), 14, null);
if (z2) {
connectRx$default = connectRx$default.O(1500, TimeUnit.MILLISECONDS);
}
Observable<Settings> r = connectRx$default.r();
m.checkNotNullExpressionValue(r, "ObservationDeckProvider\n… .distinctUntilChanged()");
return r;
}
public final void setFontScale(int i) {
Settings settings = this.settings;
if (settings == null) {
m.throwUninitializedPropertyAccessException("settings");
}
this.settings = Settings.copy$default(settings, null, null, i, 3, null);
SharedPreferences.Editor edit = getPrefs().edit();
m.checkExpressionValueIsNotNull(edit, "editor");
edit.putInt("CACHE_KEY_FONT_SCALE", i);
edit.apply();
markChanged();
this.onFontScaleUpdated.invoke(Integer.valueOf(i));
}
public final void setIsLocaleSyncEnabled(boolean z2) {
SharedPreferences.Editor edit = getPrefs().edit();
m.checkExpressionValueIsNotNull(edit, "editor");
edit.putBoolean("CACHE_KEY_LOCALE_SYNC", z2);
edit.apply();
}
public final void setIsSyncThemeEnabled(boolean z2) {
SharedPreferences.Editor edit = getPrefsSessionDurable().edit();
m.checkExpressionValueIsNotNull(edit, "editor");
edit.putBoolean("CACHE_KEY_THEME_SYNC", z2);
edit.apply();
}
public final void setLocale(String str, boolean z2, Function0<Unit> function0) {
m.checkNotNullParameter(str, "locale");
if (!getIsLocaleSyncEnabled() || !z2 || !(function0 == null || function0.mo1invoke() == null)) {
Settings settings = this.settings;
if (settings == null) {
m.throwUninitializedPropertyAccessException("settings");
}
this.settings = Settings.copy$default(settings, null, str, 0, 5, null);
SharedPreferences.Editor edit = getPrefs().edit();
m.checkExpressionValueIsNotNull(edit, "editor");
edit.putString("CACHE_KEY_LOCALE", str);
edit.apply();
markChanged();
return;
}
throw new IllegalArgumentException("API callback required.");
}
public final void setTheme(String str, boolean z2, Function0<Unit> function0) {
m.checkNotNullParameter(str, "theme");
if (!getIsThemeSyncEnabled() || !z2 || !(function0 == null || function0.mo1invoke() == null)) {
if (m.areEqual(getTheme(), "pureEvil") && m.areEqual(str, "dark")) {
str = "pureEvil";
}
Settings settings = this.settings;
if (settings == null) {
m.throwUninitializedPropertyAccessException("settings");
}
this.settings = Settings.copy$default(settings, str, null, 0, 6, null);
SharedPreferences.Editor edit = getPrefsSessionDurable().edit();
m.checkExpressionValueIsNotNull(edit, "editor");
edit.putString("CACHE_KEY_THEME", str);
edit.apply();
markChanged();
return;
}
throw new IllegalArgumentException("API callback required.");
}
}