244 lines
9.0 KiB
Java
244 lines
9.0 KiB
Java
package com.facebook.share.internal;
|
|
|
|
import android.app.Dialog;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Parcel;
|
|
import android.os.Parcelable;
|
|
import android.text.Html;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.TextView;
|
|
import androidx.fragment.app.DialogFragment;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
import com.baidu.cloud.media.player.BDCloudMediaPlayer;
|
|
import com.facebook.AccessToken;
|
|
import com.facebook.FacebookRequestError;
|
|
import com.facebook.GraphRequest;
|
|
import com.facebook.GraphResponse;
|
|
import com.facebook.HttpMethod;
|
|
import com.facebook.R$id;
|
|
import com.facebook.R$layout;
|
|
import com.facebook.R$string;
|
|
import com.facebook.R$style;
|
|
import com.facebook.devicerequests.internal.DeviceRequestsHelper;
|
|
import com.facebook.internal.Validate;
|
|
import com.facebook.share.model.ShareContent;
|
|
import com.facebook.share.model.ShareLinkContent;
|
|
import com.facebook.share.model.ShareOpenGraphContent;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class DeviceShareDialogFragment extends DialogFragment {
|
|
private static ScheduledThreadPoolExecutor p;
|
|
private ProgressBar j;
|
|
private TextView k;
|
|
private Dialog l;
|
|
private volatile RequestState m;
|
|
private volatile ScheduledFuture n;
|
|
private ShareContent o;
|
|
|
|
private static class RequestState implements Parcelable {
|
|
public static final Parcelable.Creator<RequestState> CREATOR = new Parcelable.Creator<RequestState>() { // from class: com.facebook.share.internal.DeviceShareDialogFragment.RequestState.1
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public RequestState createFromParcel(Parcel parcel) {
|
|
return new RequestState(parcel);
|
|
}
|
|
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public RequestState[] newArray(int i) {
|
|
return new RequestState[i];
|
|
}
|
|
};
|
|
private long expiresIn;
|
|
private String userCode;
|
|
|
|
RequestState() {
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public int describeContents() {
|
|
return 0;
|
|
}
|
|
|
|
public long getExpiresIn() {
|
|
return this.expiresIn;
|
|
}
|
|
|
|
public String getUserCode() {
|
|
return this.userCode;
|
|
}
|
|
|
|
public void setExpiresIn(long j) {
|
|
this.expiresIn = j;
|
|
}
|
|
|
|
public void setUserCode(String str) {
|
|
this.userCode = str;
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
parcel.writeString(this.userCode);
|
|
parcel.writeLong(this.expiresIn);
|
|
}
|
|
|
|
protected RequestState(Parcel parcel) {
|
|
this.userCode = parcel.readString();
|
|
this.expiresIn = parcel.readLong();
|
|
}
|
|
}
|
|
|
|
private void o() {
|
|
if (isAdded()) {
|
|
FragmentTransaction a = getFragmentManager().a();
|
|
a.d(this);
|
|
a.a();
|
|
}
|
|
}
|
|
|
|
private static synchronized ScheduledThreadPoolExecutor q() {
|
|
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor;
|
|
synchronized (DeviceShareDialogFragment.class) {
|
|
if (p == null) {
|
|
p = new ScheduledThreadPoolExecutor(1);
|
|
}
|
|
scheduledThreadPoolExecutor = p;
|
|
}
|
|
return scheduledThreadPoolExecutor;
|
|
}
|
|
|
|
private Bundle v() {
|
|
ShareContent shareContent = this.o;
|
|
if (shareContent == null) {
|
|
return null;
|
|
}
|
|
if (shareContent instanceof ShareLinkContent) {
|
|
return WebDialogParameters.a((ShareLinkContent) shareContent);
|
|
}
|
|
if (shareContent instanceof ShareOpenGraphContent) {
|
|
return WebDialogParameters.a((ShareOpenGraphContent) shareContent);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void x() {
|
|
Bundle v = v();
|
|
if (v == null || v.size() == 0) {
|
|
a(new FacebookRequestError(0, "", "Failed to get share content"));
|
|
}
|
|
v.putString(AccessToken.ACCESS_TOKEN_KEY, Validate.a() + "|" + Validate.b());
|
|
v.putString("device_info", DeviceRequestsHelper.a());
|
|
new GraphRequest(null, "device/share", v, HttpMethod.POST, new GraphRequest.Callback() { // from class: com.facebook.share.internal.DeviceShareDialogFragment.2
|
|
@Override // com.facebook.GraphRequest.Callback
|
|
public void a(GraphResponse graphResponse) {
|
|
FacebookRequestError a = graphResponse.a();
|
|
if (a != null) {
|
|
DeviceShareDialogFragment.this.a(a);
|
|
return;
|
|
}
|
|
JSONObject b = graphResponse.b();
|
|
RequestState requestState = new RequestState();
|
|
try {
|
|
requestState.setUserCode(b.getString("user_code"));
|
|
requestState.setExpiresIn(b.getLong(AccessToken.EXPIRES_IN_KEY));
|
|
DeviceShareDialogFragment.this.a(requestState);
|
|
} catch (JSONException unused) {
|
|
DeviceShareDialogFragment.this.a(new FacebookRequestError(0, "", "Malformed server response"));
|
|
}
|
|
}
|
|
}).b();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
|
RequestState requestState;
|
|
View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
|
|
if (bundle != null && (requestState = (RequestState) bundle.getParcelable("request_state")) != null) {
|
|
a(requestState);
|
|
}
|
|
return onCreateView;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, android.content.DialogInterface.OnDismissListener
|
|
public void onDismiss(DialogInterface dialogInterface) {
|
|
super.onDismiss(dialogInterface);
|
|
if (this.n != null) {
|
|
this.n.cancel(true);
|
|
}
|
|
a(-1, new Intent());
|
|
}
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, androidx.fragment.app.Fragment
|
|
public void onSaveInstanceState(Bundle bundle) {
|
|
super.onSaveInstanceState(bundle);
|
|
if (this.m != null) {
|
|
bundle.putParcelable("request_state", this.m);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.DialogFragment
|
|
public Dialog a(Bundle bundle) {
|
|
this.l = new Dialog(getActivity(), R$style.com_facebook_auth_dialog);
|
|
View inflate = getActivity().getLayoutInflater().inflate(R$layout.com_facebook_device_auth_dialog_fragment, (ViewGroup) null);
|
|
this.j = (ProgressBar) inflate.findViewById(R$id.progress_bar);
|
|
this.k = (TextView) inflate.findViewById(R$id.confirmation_code);
|
|
((Button) inflate.findViewById(R$id.cancel_button)).setOnClickListener(new View.OnClickListener() { // from class: com.facebook.share.internal.DeviceShareDialogFragment.1
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
DeviceShareDialogFragment.this.l.dismiss();
|
|
}
|
|
});
|
|
((TextView) inflate.findViewById(R$id.com_facebook_device_auth_instructions)).setText(Html.fromHtml(getString(R$string.com_facebook_device_auth_instructions)));
|
|
this.l.setContentView(inflate);
|
|
x();
|
|
return this.l;
|
|
}
|
|
|
|
private void a(int i, Intent intent) {
|
|
DeviceRequestsHelper.a(this.m.getUserCode());
|
|
if (isAdded()) {
|
|
FragmentActivity activity = getActivity();
|
|
activity.setResult(i, intent);
|
|
activity.finish();
|
|
}
|
|
}
|
|
|
|
public void a(ShareContent shareContent) {
|
|
this.o = shareContent;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void a(FacebookRequestError facebookRequestError) {
|
|
o();
|
|
Intent intent = new Intent();
|
|
intent.putExtra(BDCloudMediaPlayer.OnNativeInvokeListener.ARG_ERROR, facebookRequestError);
|
|
a(-1, intent);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void a(RequestState requestState) {
|
|
this.m = requestState;
|
|
this.k.setText(requestState.getUserCode());
|
|
this.k.setVisibility(0);
|
|
this.j.setVisibility(8);
|
|
this.n = q().schedule(new Runnable() { // from class: com.facebook.share.internal.DeviceShareDialogFragment.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
DeviceShareDialogFragment.this.l.dismiss();
|
|
}
|
|
}, requestState.getExpiresIn(), TimeUnit.SECONDS);
|
|
}
|
|
}
|