package com.evernote.client.android; import android.app.Activity; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; import androidx.fragment.app.FragmentActivity; import com.evernote.client.android.asyncclient.EvernoteClientFactory; import com.evernote.client.android.helper.Cat; import com.evernote.client.android.helper.EvernotePreconditions; import com.evernote.client.android.login.EvernoteLoginActivity; import com.evernote.client.android.login.EvernoteLoginFragment; import java.util.Locale; public final class EvernoteSession { private static final Cat CAT = new Cat("EvernoteSession"); public static final String HOST_CHINA = "https://app.yinxiang.com"; public static final String HOST_PRODUCTION = "https://www.evernote.com"; public static final String HOST_SANDBOX = "https://sandbox.evernote.com"; public static final int REQUEST_CODE_LOGIN = 14390; public static final String SCREEN_NAME_INTERNATIONAL = "Evernote International"; public static final String SCREEN_NAME_YXBIJI = "印象笔记"; private static EvernoteSession sInstance = null; private Context mApplicationContext; private AuthenticationResult mAuthenticationResult; private String mConsumerKey; private String mConsumerSecret; private EvernoteClientFactory.Builder mEvernoteClientFactoryBuilder; private EvernoteService mEvernoteService; private ThreadLocal<EvernoteClientFactory> mFactoryThreadLocal; private boolean mForceAuthenticationInThirdPartyApp; private Locale mLocale; private boolean mSupportAppLinkedNotebooks; public static class Builder { private final Context mContext; private EvernoteService mEvernoteService = EvernoteService.SANDBOX; private boolean mForceAuthenticationInThirdPartyApp; private Locale mLocale = Locale.getDefault(); private boolean mSupportAppLinkedNotebooks = true; public Builder(Context context) { EvernotePreconditions.checkNotNull(context); this.mContext = context.getApplicationContext(); } private EvernoteSession build(EvernoteSession evernoteSession) { evernoteSession.mApplicationContext = this.mContext; evernoteSession.mLocale = this.mLocale; evernoteSession.mSupportAppLinkedNotebooks = this.mSupportAppLinkedNotebooks; evernoteSession.mEvernoteService = this.mEvernoteService; evernoteSession.mForceAuthenticationInThirdPartyApp = this.mForceAuthenticationInThirdPartyApp; return evernoteSession; } public EvernoteSession build(String str, String str2) { EvernoteSession evernoteSession = new EvernoteSession(); evernoteSession.mConsumerKey = (String) EvernotePreconditions.checkNotEmpty(str); evernoteSession.mConsumerSecret = (String) EvernotePreconditions.checkNotEmpty(str2); evernoteSession.mAuthenticationResult = AuthenticationResult.fromPreferences(this.mContext); return build(evernoteSession); } public EvernoteSession buildForSingleUser(String str, String str2) { EvernoteSession evernoteSession = new EvernoteSession(); evernoteSession.mAuthenticationResult = new AuthenticationResult((String) EvernotePreconditions.checkNotEmpty(str), (String) EvernotePreconditions.checkNotEmpty(str2), this.mSupportAppLinkedNotebooks); return build(evernoteSession); } public Builder setEvernoteService(EvernoteService evernoteService) { this.mEvernoteService = (EvernoteService) EvernotePreconditions.checkNotNull(evernoteService); return this; } public Builder setForceAuthenticationInThirdPartyApp(boolean z10) { this.mForceAuthenticationInThirdPartyApp = z10; return this; } public Builder setLocale(Locale locale) { this.mLocale = (Locale) EvernotePreconditions.checkNotNull(locale); return this; } public Builder setSupportAppLinkedNotebooks(boolean z10) { this.mSupportAppLinkedNotebooks = z10; return this; } } public enum EvernoteService implements Parcelable { SANDBOX, PRODUCTION; public static final Parcelable.Creator<EvernoteService> CREATOR = new Parcelable.Creator<EvernoteService>() { /* class com.evernote.client.android.EvernoteSession.EvernoteService.AnonymousClass1 */ @Override // android.os.Parcelable.Creator public EvernoteService createFromParcel(Parcel parcel) { return EvernoteService.values()[parcel.readInt()]; } @Override // android.os.Parcelable.Creator public EvernoteService[] newArray(int i10) { return new EvernoteService[i10]; } }; public int describeContents() { return 0; } public void writeToParcel(Parcel parcel, int i10) { parcel.writeInt(ordinal()); } } private EvernoteSession() { } public static EvernoteSession getInstance() { return sInstance; } public EvernoteSession asSingleton() { sInstance = this; return this; } public void authenticate(Activity activity) { activity.startActivityForResult(EvernoteLoginActivity.createIntent(activity, this.mConsumerKey, this.mConsumerSecret, this.mSupportAppLinkedNotebooks, this.mLocale), REQUEST_CODE_LOGIN); } public void authenticate(FragmentActivity fragmentActivity) { authenticate(fragmentActivity, EvernoteLoginFragment.create(this.mConsumerKey, this.mConsumerSecret, this.mSupportAppLinkedNotebooks, this.mLocale)); } public void authenticate(FragmentActivity fragmentActivity, EvernoteLoginFragment evernoteLoginFragment) { evernoteLoginFragment.show(fragmentActivity.getSupportFragmentManager(), EvernoteLoginFragment.TAG); } public Context getApplicationContext() { return this.mApplicationContext; } public String getAuthToken() { AuthenticationResult authenticationResult = this.mAuthenticationResult; if (authenticationResult != null) { return authenticationResult.getAuthToken(); } return null; } public AuthenticationResult getAuthenticationResult() { return this.mAuthenticationResult; } public synchronized EvernoteClientFactory getEvernoteClientFactory() { EvernoteClientFactory evernoteClientFactory; if (this.mFactoryThreadLocal == null) { this.mFactoryThreadLocal = new ThreadLocal<>(); } if (this.mEvernoteClientFactoryBuilder == null) { this.mEvernoteClientFactoryBuilder = new EvernoteClientFactory.Builder(this); } evernoteClientFactory = this.mFactoryThreadLocal.get(); if (evernoteClientFactory == null) { evernoteClientFactory = this.mEvernoteClientFactoryBuilder.build(); this.mFactoryThreadLocal.set(evernoteClientFactory); } return evernoteClientFactory; } /* access modifiers changed from: protected */ public EvernoteService getEvernoteService() { return this.mEvernoteService; } /* access modifiers changed from: package-private */ public boolean isForceAuthenticationInThirdPartyApp() { return this.mForceAuthenticationInThirdPartyApp; } public synchronized boolean isLoggedIn() { return this.mAuthenticationResult != null; } public synchronized boolean logOut() { if (!isLoggedIn()) { return false; } this.mAuthenticationResult.clear(); this.mAuthenticationResult = null; EvernoteUtil.removeAllCookies(getApplicationContext()); return true; } /* access modifiers changed from: protected */ public synchronized void setAuthenticationResult(AuthenticationResult authenticationResult) { this.mAuthenticationResult = authenticationResult; } public synchronized void setEvernoteClientFactoryBuilder(EvernoteClientFactory.Builder builder) { this.mEvernoteClientFactoryBuilder = (EvernoteClientFactory.Builder) EvernotePreconditions.checkNotNull(builder); this.mFactoryThreadLocal = null; } }