package com.discord.stores; import android.content.Context; import com.discord.models.domain.ModelPayload; import com.discord.models.phone.PhoneCountryCode; import com.discord.utilities.persister.Persister; import com.google.gson.Gson; import d0.t.k; import d0.y.b; import d0.z.d.m; import java.io.InputStreamReader; import java.util.List; /* compiled from: StorePhone.kt */ public final class StorePhone extends StoreV2 { private List countryCodes; private PhoneCountryCode defaultCountryCode; private final Dispatcher dispatcher; private PhoneCountryCode selectedCountryCode; private final Persister selectedCountryCodeCache = new Persister<>("CACHE_KEY_PHONE_COUNTRY_CODE_V2", this.selectedCountryCode); public StorePhone(Dispatcher dispatcher) { m.checkNotNullParameter(dispatcher, "dispatcher"); this.dispatcher = dispatcher; PhoneCountryCode.Companion companion = PhoneCountryCode.Companion; this.defaultCountryCode = companion.getDEFAULT_COUNTRY_CODE(); this.selectedCountryCode = companion.getMISSING_COUNTRY_CODE(); } public static final /* synthetic */ List access$getCountryCodes$p(StorePhone storePhone) { List list = storePhone.countryCodes; if (list == null) { m.throwUninitializedPropertyAccessException("countryCodes"); } return list; } public static final /* synthetic */ PhoneCountryCode access$getDefaultCountryCode$p(StorePhone storePhone) { return storePhone.defaultCountryCode; } public static final /* synthetic */ PhoneCountryCode access$getSelectedCountryCode$p(StorePhone storePhone) { return storePhone.selectedCountryCode; } public static final /* synthetic */ void access$setCountryCodes$p(StorePhone storePhone, List list) { storePhone.countryCodes = list; } public static final /* synthetic */ void access$setDefaultCountryCode$p(StorePhone storePhone, PhoneCountryCode phoneCountryCode) { storePhone.defaultCountryCode = phoneCountryCode; } public static final /* synthetic */ void access$setSelectedCountryCode$p(StorePhone storePhone, PhoneCountryCode phoneCountryCode) { storePhone.selectedCountryCode = phoneCountryCode; } /* JADX WARNING: Code restructure failed: missing block: B:10:0x0032, code lost: throw r1; */ /* JADX WARNING: Code restructure failed: missing block: B:8:0x002e, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:9:0x002f, code lost: d0.y.b.closeFinally(r0, r3); */ private final List loadCountryCodesFromDisk(Context context) { InputStreamReader inputStreamReader = new InputStreamReader(context.getAssets().open("data/country-codes.json"), "UTF-8"); Object e = new Gson().e(inputStreamReader, PhoneCountryCode[].class); m.checkNotNullExpressionValue(e, "Gson().fromJson(it, Arra…CountryCode>::class.java)"); List list = k.toList((Object[]) e); b.closeFinally(inputStreamReader, null); return list; } public final PhoneCountryCode getCountryCode() { return m.areEqual(this.selectedCountryCode, PhoneCountryCode.Companion.getMISSING_COUNTRY_CODE()) ? this.defaultCountryCode : this.selectedCountryCode; } public final List getCountryCodes() { List list = this.countryCodes; if (list == null) { m.throwUninitializedPropertyAccessException("countryCodes"); } return list; } @StoreThread public final void handleConnectionOpen(ModelPayload modelPayload) { m.checkNotNullParameter(modelPayload, "payload"); String countryCode = modelPayload.getCountryCode(); if (countryCode != null) { updateDefaultCountryCode(countryCode); } } @Override // com.discord.stores.Store public void init(Context context) { m.checkNotNullParameter(context, "context"); super.init(context); this.countryCodes = loadCountryCodesFromDisk(context); this.selectedCountryCode = this.selectedCountryCodeCache.get(); markChanged(); } @Override // com.discord.stores.StoreV2 @StoreThread public void snapshotData() { super.snapshotData(); Persister.set$default(this.selectedCountryCodeCache, this.selectedCountryCode, false, 2, null); } public final void updateDefaultCountryCode(String str) { m.checkNotNullParameter(str, "alpha2"); this.dispatcher.schedule(new StorePhone$updateDefaultCountryCode$1(this, str)); } public final void updateSelectedCountryCode(PhoneCountryCode phoneCountryCode) { m.checkNotNullParameter(phoneCountryCode, "newSelectedCountryCode"); this.dispatcher.schedule(new StorePhone$updateSelectedCountryCode$1(this, phoneCountryCode)); } }