Snaptube v4.40.0.4401610版本的 MD5 值为:ca2b95dcff63007195db02a6c93091b9

以下内容为反编译后的 BaseModel.java 源代码,内容仅作参考


package com.avocarrot.androidsdk;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Base64;
import com.avocarrot.androidsdk.DynamicConfiguration;
import com.avocarrot.vastparser.Vast;
import com.avocarrot.vastparser.model.MediaFile;
import io.fabric.sdk.android.services.events.EventsFilesManager;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import net.pubnative.mediation.broadcast.MediationEventBus;
import org.json.JSONArray;
import org.json.JSONObject;
public class BaseModel implements Parcelable, Serializable {
    public static final Parcelable.Creator<BaseModel> CREATOR = new Parcelable.Creator<BaseModel>() {
        @Override
        public BaseModel createFromParcel(Parcel parcel) {
            return new BaseModel(parcel);
        }

        @Override
        public BaseModel[] newArray(int i) {
            return new BaseModel[i];
        }
    };
    private AdChoices adChoices;
    private List<String> clickUrls;
    private List<String> companionClickUrls;
    private String ctaText;
    private String description;
    private String destinationUrl;
    private List<ExtraFieldModel> extra;
    private String fireImpressionEvent;
    protected CreativeModel icon;
    private String id;
    protected CreativeModel image;
    private List<String> impressionUrls;
    String provider;
    private Double rating;
    private String requestId;
    String source;
    private long timestamp;
    private String title;
    private HashMap<String, List<String>> trackers;
    protected String vasttag;
    protected VideoModel video;
    private List<String> videocClickUrls;

    public BaseModel(JSONObject jSONObject, String str) {
        List<String> arrayList;
        this.requestId = "";
        this.trackers = new HashMap<>();
        this.fireImpressionEvent = null;
        this.timestamp = 0L;
        if (jSONObject != null) {
            this.requestId = str;
            str = (TextUtils.isEmpty(str) || str.equalsIgnoreCase("null")) ? UUID.randomUUID().toString() : str;
            this.title = jSONObject.optString("headline");
            this.description = jSONObject.optString("subHeadline");
            this.ctaText = jSONObject.optString("ctaText");
            this.destinationUrl = jSONObject.optString("destinationUrl");
            this.rating = Double.valueOf(jSONObject.optDouble("rating", -1.0d));
            this.impressionUrls = new ArrayList();
            this.clickUrls = new ArrayList();
            this.companionClickUrls = new ArrayList();
            this.videocClickUrls = new ArrayList();
            JSONArray optJSONArray = jSONObject.optJSONArray("trackers");
            if (optJSONArray != null) {
                int length = optJSONArray.length();
                for (int i = 0; i < length; i++) {
                    JSONObject optJSONObject = optJSONArray.optJSONObject(i);
                    if (optJSONObject != null) {
                        String optString = optJSONObject.optString("type", "");
                        if ("impression".equalsIgnoreCase(optString)) {
                            String optString2 = optJSONObject.optString("url");
                            if (!TextUtils.isEmpty(optString2)) {
                                this.impressionUrls.add(optString2);
                            }
                        } else if ("click".equalsIgnoreCase(optString)) {
                            String optString3 = optJSONObject.optString("url");
                            if (!TextUtils.isEmpty(optString3)) {
                                this.clickUrls.add(optString3);
                            }
                        } else if ("companionClick".equalsIgnoreCase(optString)) {
                            String optString4 = optJSONObject.optString("url");
                            if (!TextUtils.isEmpty(optString4)) {
                                this.companionClickUrls.add(optString4);
                            }
                        } else if ("videoClick".equalsIgnoreCase(optString)) {
                            String optString5 = optJSONObject.optString("url");
                            if (!TextUtils.isEmpty(optString5)) {
                                this.videocClickUrls.add(optString5);
                            }
                        } else {
                            String optString6 = optJSONObject.optString("url");
                            if (TextUtils.isEmpty(optString6)) {
                                break;
                            }
                            String convertAvocarrotEventsToVast = Utils.convertAvocarrotEventsToVast(optString);
                            if (this.trackers.containsKey(convertAvocarrotEventsToVast)) {
                                arrayList = this.trackers.get(convertAvocarrotEventsToVast);
                            } else {
                                arrayList = new ArrayList<>();
                                this.trackers.put(convertAvocarrotEventsToVast, arrayList);
                            }
                            arrayList.add(optString6);
                        }
                    }
                }
            }
            this.image = new CreativeModel(jSONObject.optJSONObject("image"));
            this.icon = new CreativeModel(jSONObject.optJSONObject("iconImage"));
            JSONObject optJSONObject2 = jSONObject.optJSONObject("video");
            if (optJSONObject2 != null) {
                this.fireImpressionEvent = optJSONObject2.optString("fireImpressionEvent", null);
                this.vasttag = optJSONObject2.optString("vasttag", null);
            }
            this.adChoices = new AdChoices(jSONObject.optJSONObject("adChoices"));
            this.provider = jSONObject.optString(MediationEventBus.PARAM_PROVIDER);
            this.source = jSONObject.optString("source");
            this.extra = ExtraFieldModel.createList(jSONObject.optJSONArray("extra"));
            this.id = str + EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR + jSONObject.optString("id");
            this.timestamp = System.currentTimeMillis();
        }
    }

    public boolean isValid() {
        return !TextUtils.isEmpty(this.title) && ((this.image != null && this.image.isValid()) || (this.icon != null && this.icon.isValid()));
    }

    public String getId() {
        return this.id;
    }

    public String getTitle() {
        return this.title;
    }

    public String getDescription() {
        return this.description;
    }

    public String getCTAText() {
        return this.ctaText;
    }

    public List<String> getImpressionUrls() {
        return this.impressionUrls;
    }

    public List<String> getClickUrls() {
        return this.clickUrls;
    }

    public List<String> getCompanionClickUrls() {
        return this.companionClickUrls;
    }

    public List<String> getVideocClickUrls() {
        return this.videocClickUrls;
    }

    public String getDestinationUrl() {
        return this.destinationUrl;
    }

    public CreativeModel getImage() {
        return this.image;
    }

    public CreativeModel getIcon() {
        return this.icon;
    }

    public VideoModel getVideo() {
        return this.video;
    }

    public AdChoices getAdChoices() {
        return this.adChoices;
    }

    public Double getRating() {
        return this.rating;
    }

    public String getRatingImageUrl() {
        if (getRating().doubleValue() >= 0.0d) {
            String str = "00";
            try {
                str = Integer.toString((int) ((this.rating.doubleValue() * 10.0d) + 100.0d)).substring(1);
            } catch (Exception e) {
            }
            return "https://s3.amazonaws.com/avocarrot-assets/media/images/ads/ratings/##.png".replace("##", str);
        }
        return null;
    }

    public List<ExtraFieldModel> getExtra() {
        return this.extra;
    }

    public boolean hasExpired(String str) {
        return System.currentTimeMillis() - this.timestamp > ((long) DynamicConfiguration.getIntFallbackToDefault(str, DynamicConfiguration.Settings.bufferTimeout).intValue());
    }

    public String getVastTag() {
        return this.vasttag;
    }

    public boolean hasVastTag() {
        return !TextUtils.isEmpty(this.vasttag);
    }

    public String getFireImpressionEvent() {
        return this.fireImpressionEvent;
    }

    boolean hasFireImpressionEvent() {
        return !TextUtils.isEmpty(this.fireImpressionEvent);
    }

    public void failToLoadVast() {
        this.vasttag = null;
    }

    public void appendVastData(Vast vast, MediaFile mediaFile, String str, BaseListener baseListener) {
        this.video = new VideoModel(vast, str, mediaFile, DynamicConfiguration.getBoolean(DynamicConfiguration.GENERAL, DynamicConfiguration.Settings.autoplay), DynamicConfiguration.getBoolean(DynamicConfiguration.GENERAL, DynamicConfiguration.Settings.videoPausable), DynamicConfiguration.getBoolean(DynamicConfiguration.GENERAL, DynamicConfiguration.Settings.mute), baseListener, this);
        if (TextUtils.isEmpty(this.title)) {
            this.title = vast.getAdTitle();
        }
        if (TextUtils.isEmpty(this.description)) {
            this.description = vast.getDescription();
        }
        if (TextUtils.isEmpty(this.destinationUrl)) {
            this.destinationUrl = vast.getClickThrough();
            this.clickUrls.addAll(vast.getClickTracking());
        }
    }

    public HashMap<String, List<String>> getTrackers() {
        return this.trackers;
    }

    public boolean equals(Object obj) {
        return obj != null && getClass() == obj.getClass() && TextUtils.equals(this.id, ((BaseModel) obj).id);
    }

    public BaseModel(BaseModel baseModel) {
        this.requestId = "";
        this.trackers = new HashMap<>();
        this.fireImpressionEvent = null;
        this.timestamp = 0L;
        this.id = baseModel.id;
        this.requestId = baseModel.requestId;
        this.impressionUrls = baseModel.impressionUrls;
        this.clickUrls = baseModel.clickUrls;
        this.videocClickUrls = baseModel.getVideocClickUrls();
        this.companionClickUrls = baseModel.getCompanionClickUrls();
        this.destinationUrl = baseModel.destinationUrl;
        this.title = baseModel.title;
        this.fireImpressionEvent = baseModel.getFireImpressionEvent();
        this.description = baseModel.description;
        this.ctaText = baseModel.ctaText;
        this.image = baseModel.image;
        this.icon = baseModel.icon;
        this.video = baseModel.video;
        this.vasttag = baseModel.vasttag;
        this.rating = baseModel.rating;
        this.extra = baseModel.extra;
        this.trackers = baseModel.trackers;
        this.timestamp = baseModel.timestamp;
        this.provider = baseModel.provider;
        this.source = baseModel.source;
        this.adChoices = baseModel.adChoices;
    }

    public String getProvider() {
        return this.provider;
    }

    public int hashCode() {
        return super.hashCode() + this.id.hashCode();
    }

    public BaseModel(Parcel parcel) {
        this.requestId = "";
        this.trackers = new HashMap<>();
        this.fireImpressionEvent = null;
        this.timestamp = 0L;
        this.id = parcel.readString();
        this.requestId = parcel.readString();
        this.impressionUrls = new ArrayList();
        parcel.readStringList(this.impressionUrls);
        this.clickUrls = new ArrayList();
        parcel.readStringList(this.clickUrls);
        this.companionClickUrls = new ArrayList();
        parcel.readStringList(this.companionClickUrls);
        this.videocClickUrls = new ArrayList();
        parcel.readStringList(this.videocClickUrls);
        this.destinationUrl = parcel.readString();
        this.title = parcel.readString();
        this.description = parcel.readString();
        this.ctaText = parcel.readString();
        this.image = (CreativeModel) parcel.readParcelable(getClass().getClassLoader());
        this.icon = (CreativeModel) parcel.readParcelable(getClass().getClassLoader());
        this.video = (VideoModel) parcel.readParcelable(getClass().getClassLoader());
        this.rating = Double.valueOf(parcel.readDouble());
        this.extra = new ArrayList();
        parcel.readList(this.extra, ExtraFieldModel.class.getClassLoader());
        this.vasttag = parcel.readString();
        this.fireImpressionEvent = parcel.readString();
        this.trackers = parcel.readHashMap(getClass().getClassLoader());
        this.timestamp = parcel.readLong();
        this.provider = parcel.readString();
        this.source = parcel.readString();
        this.adChoices = (AdChoices) parcel.readParcelable(AdChoices.class.getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.id);
        parcel.writeString(this.requestId);
        parcel.writeStringList(this.impressionUrls);
        parcel.writeStringList(this.clickUrls);
        parcel.writeStringList(this.companionClickUrls);
        parcel.writeStringList(this.videocClickUrls);
        parcel.writeString(this.destinationUrl);
        parcel.writeString(this.title);
        parcel.writeString(this.description);
        parcel.writeString(this.ctaText);
        parcel.writeParcelable(this.image, i);
        parcel.writeParcelable(this.icon, i);
        parcel.writeParcelable(this.video, i);
        parcel.writeDouble(this.rating.doubleValue());
        parcel.writeList(this.extra);
        parcel.writeString(this.vasttag);
        parcel.writeString(this.fireImpressionEvent);
        parcel.writeMap(this.trackers);
        parcel.writeLong(this.timestamp);
        parcel.writeString(this.provider);
        parcel.writeString(this.source);
        parcel.writeParcelable(this.adChoices, i);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public String toCache() throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        new ObjectOutputStream(byteArrayOutputStream).writeObject(this);
        return Base64.encodeToString(byteArrayOutputStream.toByteArray(), 0);
    }

    public static BaseModel fromCache(String str) throws IOException, ClassNotFoundException {
        return (BaseModel) new ObjectInputStream(new ByteArrayInputStream(Base64.decode(str, 0))).readObject();
    }
}