jimu-decompiled/sources/com/facebook/share/internal/ShareInternalUtility.java
2025-05-13 19:24:51 +02:00

385 lines
16 KiB
Java

package com.facebook.share.internal;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.util.Pair;
import com.baidu.cloud.media.player.BDCloudMediaPlayer;
import com.facebook.AccessToken;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.HttpMethod;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.internal.AppCall;
import com.facebook.internal.CallbackManagerImpl;
import com.facebook.internal.NativeAppCallAttachmentStore;
import com.facebook.internal.NativeProtocol;
import com.facebook.internal.Utility;
import com.facebook.share.Sharer;
import com.facebook.share.internal.OpenGraphJSONUtility;
import com.facebook.share.model.ShareMedia;
import com.facebook.share.model.ShareMediaContent;
import com.facebook.share.model.ShareOpenGraphAction;
import com.facebook.share.model.ShareOpenGraphContent;
import com.facebook.share.model.SharePhoto;
import com.facebook.share.model.SharePhotoContent;
import com.facebook.share.model.ShareVideo;
import com.facebook.share.model.ShareVideoContent;
import com.ubt.jimu.base.dialog.SimpleQuestionDialog;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes.dex */
public final class ShareInternalUtility {
public static String b(Bundle bundle) {
return bundle.containsKey("postId") ? bundle.getString("postId") : bundle.containsKey("com.facebook.platform.extra.POST_ID") ? bundle.getString("com.facebook.platform.extra.POST_ID") : bundle.getString("post_id");
}
public static String a(Bundle bundle) {
return bundle.containsKey("completionGesture") ? bundle.getString("completionGesture") : bundle.getString("com.facebook.platform.extra.COMPLETION_GESTURE");
}
public static boolean a(int i, int i2, Intent intent, ResultProcessor resultProcessor) {
AppCall a = a(i, i2, intent);
if (a == null) {
return false;
}
NativeAppCallAttachmentStore.a(a.a());
if (resultProcessor == null) {
return true;
}
FacebookException a2 = NativeProtocol.a(NativeProtocol.c(intent));
if (a2 != null) {
if (a2 instanceof FacebookOperationCanceledException) {
resultProcessor.a(a);
} else {
resultProcessor.a(a, a2);
}
} else {
resultProcessor.a(a, NativeProtocol.f(intent));
}
return true;
}
/* JADX INFO: Access modifiers changed from: private */
public static NativeAppCallAttachmentStore.Attachment b(UUID uuid, ShareMedia shareMedia) {
Uri uri;
Bitmap bitmap;
if (shareMedia instanceof SharePhoto) {
SharePhoto sharePhoto = (SharePhoto) shareMedia;
bitmap = sharePhoto.getBitmap();
uri = sharePhoto.getImageUrl();
} else if (shareMedia instanceof ShareVideo) {
uri = ((ShareVideo) shareMedia).getLocalUrl();
bitmap = null;
} else {
uri = null;
bitmap = null;
}
if (bitmap != null) {
return NativeAppCallAttachmentStore.a(uuid, bitmap);
}
if (uri != null) {
return NativeAppCallAttachmentStore.a(uuid, uri);
}
return null;
}
public static ResultProcessor a(final FacebookCallback<Sharer.Result> facebookCallback) {
return new ResultProcessor(facebookCallback) { // from class: com.facebook.share.internal.ShareInternalUtility.1
@Override // com.facebook.share.internal.ResultProcessor
public void a(AppCall appCall, Bundle bundle) {
if (bundle != null) {
String a = ShareInternalUtility.a(bundle);
if (a == null || "post".equalsIgnoreCase(a)) {
ShareInternalUtility.a((FacebookCallback<Sharer.Result>) facebookCallback, ShareInternalUtility.b(bundle));
} else if (SimpleQuestionDialog.KEY_CANCELBUTTON.equalsIgnoreCase(a)) {
ShareInternalUtility.b((FacebookCallback<Sharer.Result>) facebookCallback);
} else {
ShareInternalUtility.a((FacebookCallback<Sharer.Result>) facebookCallback, new FacebookException("UnknownError"));
}
}
}
@Override // com.facebook.share.internal.ResultProcessor
public void a(AppCall appCall) {
ShareInternalUtility.b((FacebookCallback<Sharer.Result>) facebookCallback);
}
@Override // com.facebook.share.internal.ResultProcessor
public void a(AppCall appCall, FacebookException facebookException) {
ShareInternalUtility.a((FacebookCallback<Sharer.Result>) facebookCallback, facebookException);
}
};
}
private static AppCall a(int i, int i2, Intent intent) {
UUID b = NativeProtocol.b(intent);
if (b == null) {
return null;
}
return AppCall.a(b, i);
}
static void b(FacebookCallback<Sharer.Result> facebookCallback) {
a("cancelled", (String) null);
if (facebookCallback != null) {
facebookCallback.onCancel();
}
}
public static void a(final int i) {
CallbackManagerImpl.b(i, new CallbackManagerImpl.Callback() { // from class: com.facebook.share.internal.ShareInternalUtility.2
@Override // com.facebook.internal.CallbackManagerImpl.Callback
public boolean a(int i2, Intent intent) {
return ShareInternalUtility.a(i, i2, intent, ShareInternalUtility.a((FacebookCallback<Sharer.Result>) null));
}
});
}
public static List<String> a(SharePhotoContent sharePhotoContent, final UUID uuid) {
List<SharePhoto> photos;
if (sharePhotoContent == null || (photos = sharePhotoContent.getPhotos()) == null) {
return null;
}
List a = Utility.a((List) photos, (Utility.Mapper) new Utility.Mapper<SharePhoto, NativeAppCallAttachmentStore.Attachment>() { // from class: com.facebook.share.internal.ShareInternalUtility.4
@Override // com.facebook.internal.Utility.Mapper
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public NativeAppCallAttachmentStore.Attachment apply(SharePhoto sharePhoto) {
return ShareInternalUtility.b(uuid, sharePhoto);
}
});
List<String> a2 = Utility.a(a, (Utility.Mapper) new Utility.Mapper<NativeAppCallAttachmentStore.Attachment, String>() { // from class: com.facebook.share.internal.ShareInternalUtility.5
@Override // com.facebook.internal.Utility.Mapper
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public String apply(NativeAppCallAttachmentStore.Attachment attachment) {
return attachment.a();
}
});
NativeAppCallAttachmentStore.a(a);
return a2;
}
public static String a(ShareVideoContent shareVideoContent, UUID uuid) {
if (shareVideoContent == null || shareVideoContent.getVideo() == null) {
return null;
}
NativeAppCallAttachmentStore.Attachment a = NativeAppCallAttachmentStore.a(uuid, shareVideoContent.getVideo().getLocalUrl());
ArrayList arrayList = new ArrayList(1);
arrayList.add(a);
NativeAppCallAttachmentStore.a(arrayList);
return a.a();
}
public static List<Bundle> a(ShareMediaContent shareMediaContent, final UUID uuid) {
List<ShareMedia> media;
if (shareMediaContent == null || (media = shareMediaContent.getMedia()) == null) {
return null;
}
final ArrayList arrayList = new ArrayList();
List<Bundle> a = Utility.a((List) media, (Utility.Mapper) new Utility.Mapper<ShareMedia, Bundle>() { // from class: com.facebook.share.internal.ShareInternalUtility.6
@Override // com.facebook.internal.Utility.Mapper
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public Bundle apply(ShareMedia shareMedia) {
NativeAppCallAttachmentStore.Attachment b = ShareInternalUtility.b(uuid, shareMedia);
arrayList.add(b);
Bundle bundle = new Bundle();
bundle.putString("type", shareMedia.getMediaType().name());
bundle.putString("uri", b.a());
return bundle;
}
});
NativeAppCallAttachmentStore.a(arrayList);
return a;
}
public static JSONObject a(final UUID uuid, ShareOpenGraphContent shareOpenGraphContent) throws JSONException {
Set a;
ShareOpenGraphAction action = shareOpenGraphContent.getAction();
final ArrayList arrayList = new ArrayList();
JSONObject a2 = OpenGraphJSONUtility.a(action, new OpenGraphJSONUtility.PhotoJSONProcessor() { // from class: com.facebook.share.internal.ShareInternalUtility.7
@Override // com.facebook.share.internal.OpenGraphJSONUtility.PhotoJSONProcessor
public JSONObject a(SharePhoto sharePhoto) {
NativeAppCallAttachmentStore.Attachment b = ShareInternalUtility.b(uuid, sharePhoto);
if (b == null) {
return null;
}
arrayList.add(b);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("url", b.a());
if (sharePhoto.getUserGenerated()) {
jSONObject.put("user_generated", true);
}
return jSONObject;
} catch (JSONException e) {
throw new FacebookException("Unable to attach images", e);
}
}
});
NativeAppCallAttachmentStore.a(arrayList);
if (shareOpenGraphContent.getPlaceId() != null && Utility.c(a2.optString("place"))) {
a2.put("place", shareOpenGraphContent.getPlaceId());
}
if (shareOpenGraphContent.getPeopleIds() != null) {
JSONArray optJSONArray = a2.optJSONArray("tags");
if (optJSONArray == null) {
a = new HashSet();
} else {
a = Utility.a(optJSONArray);
}
Iterator<String> it = shareOpenGraphContent.getPeopleIds().iterator();
while (it.hasNext()) {
a.add(it.next());
}
a2.put("tags", new JSONArray((Collection) a));
}
return a2;
}
public static JSONObject a(ShareOpenGraphContent shareOpenGraphContent) throws JSONException {
return OpenGraphJSONUtility.a(shareOpenGraphContent.getAction(), new OpenGraphJSONUtility.PhotoJSONProcessor() { // from class: com.facebook.share.internal.ShareInternalUtility.8
@Override // com.facebook.share.internal.OpenGraphJSONUtility.PhotoJSONProcessor
public JSONObject a(SharePhoto sharePhoto) {
Uri imageUrl = sharePhoto.getImageUrl();
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("url", imageUrl.toString());
return jSONObject;
} catch (JSONException e) {
throw new FacebookException("Unable to attach images", e);
}
}
});
}
public static JSONArray a(JSONArray jSONArray, boolean z) throws JSONException {
JSONArray jSONArray2 = new JSONArray();
for (int i = 0; i < jSONArray.length(); i++) {
Object obj = jSONArray.get(i);
if (obj instanceof JSONArray) {
obj = a((JSONArray) obj, z);
} else if (obj instanceof JSONObject) {
obj = a((JSONObject) obj, z);
}
jSONArray2.put(obj);
}
return jSONArray2;
}
public static JSONObject a(JSONObject jSONObject, boolean z) {
if (jSONObject == null) {
return null;
}
try {
JSONObject jSONObject2 = new JSONObject();
JSONObject jSONObject3 = new JSONObject();
JSONArray names = jSONObject.names();
for (int i = 0; i < names.length(); i++) {
String string = names.getString(i);
Object obj = jSONObject.get(string);
if (obj instanceof JSONObject) {
obj = a((JSONObject) obj, true);
} else if (obj instanceof JSONArray) {
obj = a((JSONArray) obj, true);
}
Pair<String, String> a = a(string);
String str = (String) a.first;
String str2 = (String) a.second;
if (z) {
if (str != null && str.equals("fbsdk")) {
jSONObject2.put(string, obj);
} else {
if (str != null && !str.equals("og")) {
jSONObject3.put(str2, obj);
}
jSONObject2.put(str2, obj);
}
} else if (str != null && str.equals("fb")) {
jSONObject2.put(string, obj);
} else {
jSONObject2.put(str2, obj);
}
}
if (jSONObject3.length() > 0) {
jSONObject2.put("data", jSONObject3);
}
return jSONObject2;
} catch (JSONException unused) {
throw new FacebookException("Failed to create json object from share content");
}
}
public static Pair<String, String> a(String str) {
String str2;
int i;
int indexOf = str.indexOf(58);
if (indexOf == -1 || str.length() <= (i = indexOf + 1)) {
str2 = null;
} else {
str2 = str.substring(0, indexOf);
str = str.substring(i);
}
return new Pair<>(str2, str);
}
static void a(FacebookCallback<Sharer.Result> facebookCallback, String str) {
a("succeeded", (String) null);
if (facebookCallback != null) {
facebookCallback.onSuccess(new Sharer.Result(str));
}
}
static void a(FacebookCallback<Sharer.Result> facebookCallback, FacebookException facebookException) {
a(BDCloudMediaPlayer.OnNativeInvokeListener.ARG_ERROR, facebookException.getMessage());
if (facebookCallback != null) {
facebookCallback.a(facebookException);
}
}
private static void a(String str, String str2) {
AppEventsLogger b = AppEventsLogger.b(FacebookSdk.b());
Bundle bundle = new Bundle();
bundle.putString("fb_share_dialog_outcome", str);
if (str2 != null) {
bundle.putString("error_message", str2);
}
b.a("fb_share_dialog_result", (Double) null, bundle);
}
public static GraphRequest a(AccessToken accessToken, File file, GraphRequest.Callback callback) throws FileNotFoundException {
GraphRequest.ParcelableResourceWithMimeType parcelableResourceWithMimeType = new GraphRequest.ParcelableResourceWithMimeType(ParcelFileDescriptor.open(file, 268435456), "image/png");
Bundle bundle = new Bundle(1);
bundle.putParcelable("file", parcelableResourceWithMimeType);
return new GraphRequest(accessToken, "me/staging_resources", bundle, HttpMethod.POST, callback);
}
public static GraphRequest a(AccessToken accessToken, Uri uri, GraphRequest.Callback callback) throws FileNotFoundException {
if (Utility.d(uri)) {
return a(accessToken, new File(uri.getPath()), callback);
}
if (Utility.c(uri)) {
GraphRequest.ParcelableResourceWithMimeType parcelableResourceWithMimeType = new GraphRequest.ParcelableResourceWithMimeType(uri, "image/png");
Bundle bundle = new Bundle(1);
bundle.putParcelable("file", parcelableResourceWithMimeType);
return new GraphRequest(accessToken, "me/staging_resources", bundle, HttpMethod.POST, callback);
}
throw new FacebookException("The image Uri must be either a file:// or content:// Uri");
}
}