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

363 lines
14 KiB
Java

package com.discord.stores;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import b.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 Dispatcher dispatcher;
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 String _locale;
private final int fontScale;
private final String theme;
public Settings(String str, String str2, int i) {
m.checkNotNullParameter(str, "theme");
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");
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() {
String str = this._locale;
if (str != null) {
return str;
}
String defaultLocale = ModelUserSettings.getDefaultLocale();
m.checkNotNullExpressionValue(defaultLocale, "ModelUserSettings.getDefaultLocale()");
return defaultLocale;
}
public final String getTheme() {
return this.theme;
}
public final String get_locale() {
return this._locale;
}
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 R = a.R("Settings(theme=");
R.append(this.theme);
R.append(", _locale=");
R.append(this._locale);
R.append(", fontScale=");
return a.A(R, 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, Dispatcher dispatcher) {
m.checkNotNullParameter(function1, "onFontScaleUpdated");
m.checkNotNullParameter(dispatcher, "dispatcher");
this.onFontScaleUpdated = function1;
this.dispatcher = dispatcher;
}
public static final /* synthetic */ Function1 access$getOnFontScaleUpdated$p(StoreUserSettingsSystem storeUserSettingsSystem) {
return storeUserSettingsSystem.onFontScaleUpdated;
}
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;
}
public static final /* synthetic */ void access$setThemeInternal(StoreUserSettingsSystem storeUserSettingsSystem, String str, boolean z2, Function0 function0) {
storeUserSettingsSystem.setThemeInternal(str, z2, function0);
}
@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()) {
setThemeInternal$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);
}
@StoreThread
private final void setThemeInternal(String str, boolean z2, Function0<Unit> function0) {
if (!getIsThemeSyncEnabled() || !z2 || !(function0 == null || function0.mo1invoke() == null)) {
if (m.areEqual(getTheme(), ModelUserSettings.THEME_PURE_EVIL) && m.areEqual(str, ModelUserSettings.THEME_DARK)) {
str = ModelUserSettings.THEME_PURE_EVIL;
}
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.checkNotNullExpressionValue(edit, "editor");
edit.putString("CACHE_KEY_THEME", str);
edit.apply();
markChanged();
return;
}
throw new IllegalArgumentException("API callback required.");
}
/* 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 setThemeInternal$default(StoreUserSettingsSystem storeUserSettingsSystem, String str, boolean z2, Function0 function0, int i, Object obj) {
if ((i & 4) != 0) {
function0 = null;
}
storeUserSettingsSystem.setThemeInternal(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);
setLocale$default(this, null, 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");
this.settings = new Settings(SharedPreferenceExtensionsKt.getStringNonNull(getPrefsSessionDurable(), "CACHE_KEY_THEME", (resources.getConfiguration().uiMode & 48) != 32 ? ModelUserSettings.THEME_LIGHT : ModelUserSettings.THEME_DARK), getPrefs().getString("CACHE_KEY_LOCALE", null), 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> q = connectRx$default.q();
m.checkNotNullExpressionValue(q, "ObservationDeckProvider\n… .distinctUntilChanged()");
return q;
}
public final void setFontScale(int i) {
SharedPreferences.Editor edit = getPrefs().edit();
m.checkNotNullExpressionValue(edit, "editor");
edit.putInt("CACHE_KEY_FONT_SCALE", i);
edit.apply();
this.dispatcher.schedule(new StoreUserSettingsSystem$setFontScale$2(this, i));
}
public final void setIsLocaleSyncEnabled(boolean z2) {
SharedPreferences.Editor edit = getPrefs().edit();
m.checkNotNullExpressionValue(edit, "editor");
edit.putBoolean("CACHE_KEY_LOCALE_SYNC", z2);
edit.apply();
}
public final void setIsSyncThemeEnabled(boolean z2) {
SharedPreferences.Editor edit = getPrefsSessionDurable().edit();
m.checkNotNullExpressionValue(edit, "editor");
edit.putBoolean("CACHE_KEY_THEME_SYNC", z2);
edit.apply();
}
public final void setLocale(String str, boolean z2, Function0<Unit> function0) {
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.checkNotNullExpressionValue(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");
this.dispatcher.schedule(new StoreUserSettingsSystem$setTheme$1(this, str, z2, function0));
}
}