admin
2021-03-27 214f9edd2fe20c20e32630e9b5380cc6271c1eb7
BuWanVideo/src/com/weikou/beibeivideo/util/ad/AdUtil.java
@@ -3,6 +3,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import com.weikou.beibeivideo.entity.ad.AdPositionEnum;
import com.weikou.beibeivideo.entity.ad.AdTypeVO;
import com.weikou.beibeivideo.util.BeibeiConstant;
import com.weikou.beibeivideo.util.downutil.StringUtils;
@@ -23,12 +24,6 @@
        }
    }
    public final static String POSITION_SPLASH = "splash";//开屏
    public final static String POSITION_VIDEO_PLAY_PRE = "videoPlayPre";//视频播放前贴
    public final static String POSITION_EXIT_APP = "exitApp";//APP退出广告
    public final static String POSITION_SEARCH = "videoSearch";//搜索页广告
    public final static String POSITION_VIDEO_DETAIL_FULL_VIDEO = "videoDetailFullVideo";//视频全屏广告
    public static AD_TYPE getSmallExpressAdType() {
        if (BeibeiConstant.AD_TYPE != null && AdTypeVO.TYPE_CSJ.equalsIgnoreCase(BeibeiConstant.AD_TYPE.getExpressSmallType())) {
@@ -63,16 +58,16 @@
     * 获取广告类型
     *
     * @param context
     * @param positionName
     * @param position
     * @return
     */
    public static AD_TYPE getAdType(Context context, String positionName) {
    public static AD_TYPE getAdType(Context context, AdPositionEnum position) {
        SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
        String config = share.getString("config", "");
        if (!StringUtils.isNullOrEmpty(config)) {//万一没设置起就用广点通
            try {
                JSONObject object = new JSONObject(config);
                object = object.optJSONObject(positionName);
                object = object.optJSONObject(position.getPositionName());
                if (object != null)
                    return AD_TYPE.valueOf(object.optString("type"));
            } catch (JSONException e) {
@@ -86,13 +81,13 @@
        return null;
    }
    public static String getAdPid(Context context, String positionName) {
    public static String getAdPid(Context context, AdPositionEnum position) {
        SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
        String config = share.getString("config", "");
        if (!StringUtils.isNullOrEmpty(config)) {//万一没设置起就用广点通
            try {
                JSONObject object = new JSONObject(config);
                object = object.optJSONObject(positionName);
                object = object.optJSONObject(position.getPositionName());
                if (object != null)
                    return object.optString("pid");
            } catch (JSONException e) {
@@ -106,5 +101,61 @@
        return null;
    }
    /**
     * 是否显示PPTV免广告权益
     *
     * @return
     */
    public static boolean showPPTVNoAdReward(Context context) {
        return getAdType(context, AdPositionEnum.pptvNoAdReward) != null;
    }
    //是否已经获得pptv视频免广告权益
    public static boolean isGetPPTVNoAdReward(Context context) {
        SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
        long expireTime = share.getLong("pptvNoAdReward", 0);
        if (System.currentTimeMillis() > expireTime) {
            return false;
        }
        return true;
    }
    public static int getPPTVNoAdRewardLeftTimeWithMinute(Context context) {
        SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
        long expireTime = share.getLong("pptvNoAdReward", 0);
        if (System.currentTimeMillis() > expireTime) {
            return 0;
        } else {
            return (int) ((expireTime - System.currentTimeMillis()) / (1000 * 60));
        }
    }
    public static void setPPTVNoAdRewardSuccess(Context context) {
        int hour = getPPTVNoAdRewardHour(context);
        SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = share.edit();
        editor.putLong("pptvNoAdReward", System.currentTimeMillis() + 1000 * 60 * 60L * hour);
        editor.commit();
    }
    //获取pptv免广告权益的时间(小时记)
    public static int getPPTVNoAdRewardHour(Context context) {
        SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
        return share.getInt("pptvNoAdRewardHour", 3);
    }
    /**
     * 设置pptv无广告权益的时间(小时记)
     *
     * @param context
     * @param hour
     */
    public static void setPPTVNoAdRewardHour(Context context, int hour) {
        SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = share.edit();
        editor.putInt("pptvNoAdRewardHour", hour);
        editor.commit();
    }
}