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

344 lines
13 KiB
Java

package com.facebook.share.internal;
import android.graphics.Bitmap;
import android.net.Uri;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.internal.Utility;
import com.facebook.internal.Validate;
import com.facebook.share.model.ShareContent;
import com.facebook.share.model.ShareLinkContent;
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.ShareOpenGraphObject;
import com.facebook.share.model.ShareOpenGraphValueContainer;
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 java.util.Iterator;
import java.util.List;
import java.util.Locale;
/* loaded from: classes.dex */
public class ShareContentValidation {
private static Validator a;
private static Validator b;
private static class Validator {
private boolean a;
private Validator() {
this.a = false;
}
public void a(ShareLinkContent shareLinkContent) {
ShareContentValidation.b(shareLinkContent, this);
}
public void a(SharePhotoContent sharePhotoContent) {
ShareContentValidation.b(sharePhotoContent, this);
}
public void a(ShareVideoContent shareVideoContent) {
ShareContentValidation.b(shareVideoContent, this);
}
public void a(ShareMediaContent shareMediaContent) {
ShareContentValidation.b(shareMediaContent, this);
}
public void a(ShareOpenGraphContent shareOpenGraphContent) {
this.a = true;
ShareContentValidation.b(shareOpenGraphContent, this);
}
public void a(ShareOpenGraphAction shareOpenGraphAction) {
ShareContentValidation.b(shareOpenGraphAction, this);
}
public void a(ShareOpenGraphObject shareOpenGraphObject) {
ShareContentValidation.b(shareOpenGraphObject, this);
}
public void a(ShareOpenGraphValueContainer shareOpenGraphValueContainer, boolean z) {
ShareContentValidation.b(shareOpenGraphValueContainer, this, z);
}
public void a(SharePhoto sharePhoto) {
ShareContentValidation.d(sharePhoto, this);
}
public void a(ShareVideo shareVideo) {
ShareContentValidation.b(shareVideo, this);
}
public void a(ShareMedia shareMedia) {
ShareContentValidation.a(shareMedia, this);
}
public boolean a() {
return this.a;
}
}
private static class WebShareValidator extends Validator {
private WebShareValidator() {
super();
}
@Override // com.facebook.share.internal.ShareContentValidation.Validator
public void a(ShareVideoContent shareVideoContent) {
throw new FacebookException("Cannot share ShareVideoContent via web sharing dialogs");
}
@Override // com.facebook.share.internal.ShareContentValidation.Validator
public void a(ShareMediaContent shareMediaContent) {
throw new FacebookException("Cannot share ShareMediaContent via web sharing dialogs");
}
@Override // com.facebook.share.internal.ShareContentValidation.Validator
public void a(SharePhoto sharePhoto) {
ShareContentValidation.e(sharePhoto, this);
}
}
private static void c(SharePhoto sharePhoto, Validator validator) {
a(sharePhoto);
Bitmap bitmap = sharePhoto.getBitmap();
Uri imageUrl = sharePhoto.getImageUrl();
if (bitmap == null && Utility.e(imageUrl) && !validator.a()) {
throw new FacebookException("Cannot set the ImageUrl of a SharePhoto to the Uri of an image on the web when sharing SharePhotoContent");
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void d(SharePhoto sharePhoto, Validator validator) {
c(sharePhoto, validator);
if (sharePhoto.getBitmap() == null && Utility.e(sharePhoto.getImageUrl())) {
return;
}
Validate.a(FacebookSdk.b());
}
/* JADX INFO: Access modifiers changed from: private */
public static void e(SharePhoto sharePhoto, Validator validator) {
a(sharePhoto);
}
public static void b(ShareContent shareContent) {
a(shareContent, b());
}
private static Validator b() {
if (a == null) {
a = new WebShareValidator();
}
return a;
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareLinkContent shareLinkContent, Validator validator) {
Uri imageUrl = shareLinkContent.getImageUrl();
if (imageUrl != null && !Utility.e(imageUrl)) {
throw new FacebookException("Image Url must be an http:// or https:// url");
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(SharePhotoContent sharePhotoContent, Validator validator) {
List<SharePhoto> photos = sharePhotoContent.getPhotos();
if (photos != null && !photos.isEmpty()) {
if (photos.size() <= 6) {
Iterator<SharePhoto> it = photos.iterator();
while (it.hasNext()) {
validator.a(it.next());
}
return;
}
throw new FacebookException(String.format(Locale.ROOT, "Cannot add more than %d photos.", 6));
}
throw new FacebookException("Must specify at least one Photo in SharePhotoContent.");
}
public static void a(ShareContent shareContent) {
a(shareContent, a());
}
private static Validator a() {
if (b == null) {
b = new Validator();
}
return b;
}
private static void a(ShareContent shareContent, Validator validator) throws FacebookException {
if (shareContent != null) {
if (shareContent instanceof ShareLinkContent) {
validator.a((ShareLinkContent) shareContent);
return;
}
if (shareContent instanceof SharePhotoContent) {
validator.a((SharePhotoContent) shareContent);
return;
}
if (shareContent instanceof ShareVideoContent) {
validator.a((ShareVideoContent) shareContent);
return;
} else if (shareContent instanceof ShareOpenGraphContent) {
validator.a((ShareOpenGraphContent) shareContent);
return;
} else {
if (shareContent instanceof ShareMediaContent) {
validator.a((ShareMediaContent) shareContent);
return;
}
return;
}
}
throw new FacebookException("Must provide non-null content to share");
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareVideoContent shareVideoContent, Validator validator) {
validator.a(shareVideoContent.getVideo());
SharePhoto previewPhoto = shareVideoContent.getPreviewPhoto();
if (previewPhoto != null) {
validator.a(previewPhoto);
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareVideo shareVideo, Validator validator) {
if (shareVideo != null) {
Uri localUrl = shareVideo.getLocalUrl();
if (localUrl != null) {
if (!Utility.c(localUrl) && !Utility.d(localUrl)) {
throw new FacebookException("ShareVideo must reference a video that is on the device");
}
return;
}
throw new FacebookException("ShareVideo does not have a LocalUrl specified");
}
throw new FacebookException("Cannot share a null ShareVideo");
}
private static void a(SharePhoto sharePhoto) {
if (sharePhoto != null) {
Bitmap bitmap = sharePhoto.getBitmap();
Uri imageUrl = sharePhoto.getImageUrl();
if (bitmap == null && imageUrl == null) {
throw new FacebookException("SharePhoto does not have a Bitmap or ImageUrl specified");
}
return;
}
throw new FacebookException("Cannot share a null SharePhoto");
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareMediaContent shareMediaContent, Validator validator) {
List<ShareMedia> media = shareMediaContent.getMedia();
if (media != null && !media.isEmpty()) {
if (media.size() <= 6) {
Iterator<ShareMedia> it = media.iterator();
while (it.hasNext()) {
validator.a(it.next());
}
return;
}
throw new FacebookException(String.format(Locale.ROOT, "Cannot add more than %d media.", 6));
}
throw new FacebookException("Must specify at least one medium in ShareMediaContent.");
}
public static void a(ShareMedia shareMedia, Validator validator) {
if (shareMedia instanceof SharePhoto) {
validator.a((SharePhoto) shareMedia);
} else {
if (shareMedia instanceof ShareVideo) {
validator.a((ShareVideo) shareMedia);
return;
}
throw new FacebookException(String.format(Locale.ROOT, "Invalid media type: %s", shareMedia.getClass().getSimpleName()));
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareOpenGraphContent shareOpenGraphContent, Validator validator) {
validator.a(shareOpenGraphContent.getAction());
String previewPropertyName = shareOpenGraphContent.getPreviewPropertyName();
if (!Utility.c(previewPropertyName)) {
if (shareOpenGraphContent.getAction().get(previewPropertyName) != null) {
return;
}
throw new FacebookException("Property \"" + previewPropertyName + "\" was not found on the action. The name of the preview property must match the name of an action property.");
}
throw new FacebookException("Must specify a previewPropertyName.");
}
private static void a(String str, boolean z) {
if (z) {
String[] split = str.split(":");
if (split.length >= 2) {
for (String str2 : split) {
if (str2.isEmpty()) {
throw new FacebookException("Invalid key found in Open Graph dictionary: %s", str);
}
}
return;
}
throw new FacebookException("Open Graph keys must be namespaced: %s", str);
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareOpenGraphAction shareOpenGraphAction, Validator validator) {
if (shareOpenGraphAction != null) {
if (!Utility.c(shareOpenGraphAction.getActionType())) {
validator.a(shareOpenGraphAction, false);
return;
}
throw new FacebookException("ShareOpenGraphAction must have a non-empty actionType");
}
throw new FacebookException("Must specify a non-null ShareOpenGraphAction");
}
private static void a(Object obj, Validator validator) {
if (obj instanceof ShareOpenGraphObject) {
validator.a((ShareOpenGraphObject) obj);
} else if (obj instanceof SharePhoto) {
validator.a((SharePhoto) obj);
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareOpenGraphObject shareOpenGraphObject, Validator validator) {
if (shareOpenGraphObject != null) {
validator.a(shareOpenGraphObject, true);
return;
}
throw new FacebookException("Cannot share a null ShareOpenGraphObject");
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(ShareOpenGraphValueContainer shareOpenGraphValueContainer, Validator validator, boolean z) {
for (String str : shareOpenGraphValueContainer.keySet()) {
a(str, z);
Object obj = shareOpenGraphValueContainer.get(str);
if (obj instanceof List) {
for (Object obj2 : (List) obj) {
if (obj2 != null) {
a(obj2, validator);
} else {
throw new FacebookException("Cannot put null objects in Lists in ShareOpenGraphObjects and ShareOpenGraphActions");
}
}
} else {
a(obj, validator);
}
}
}
}