1.广告位上报接口和对已上报进行Sharedference存储
2.对广告位更新资源对Sharedference进行清除
This commit is contained in:
@@ -30,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||||
|
|
||||||
import com.android.MXQConfig;
|
import com.android.MXQConfig;
|
||||||
|
import com.android.SharePreUtils;
|
||||||
import com.android.api.encrytion.UtilEncrypt;
|
import com.android.api.encrytion.UtilEncrypt;
|
||||||
import com.android.database.lib.AdsInfoBean;
|
import com.android.database.lib.AdsInfoBean;
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
@@ -41,6 +42,9 @@ import com.android.monitor.DataBeeObserver;
|
|||||||
import com.android.nebulasdk.ADManager;
|
import com.android.nebulasdk.ADManager;
|
||||||
import com.android.nebulasdk.AppManager;
|
import com.android.nebulasdk.AppManager;
|
||||||
import com.android.nebulasdk.bean.FavNaviBean;
|
import com.android.nebulasdk.bean.FavNaviBean;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
|
import com.android.nebulasdk.presenter.DownLoadAdPresenter;
|
||||||
|
import com.android.nebulasdk.presenter.callback.AppnetCallback;
|
||||||
import com.android.util.GsonUtil;
|
import com.android.util.GsonUtil;
|
||||||
import com.android.util.IntentUtil;
|
import com.android.util.IntentUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
@@ -102,6 +106,7 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
|
|||||||
/**闪屏界面是否结束*/
|
/**闪屏界面是否结束*/
|
||||||
private boolean isSplashEnd=false;
|
private boolean isSplashEnd=false;
|
||||||
private SplashView mSplashView;
|
private SplashView mSplashView;
|
||||||
|
private DownLoadAdPresenter downLoadAdPresenter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -637,6 +642,45 @@ public boolean onGenericMotionEvent(MotionEvent event) {
|
|||||||
LogUtils.loge("onMessageEvent===>"+event.action);
|
LogUtils.loge("onMessageEvent===>"+event.action);
|
||||||
if(MessageEvent.ACTION_UPADATE_DATA_SOURCE.equals(event.action)) {
|
if(MessageEvent.ACTION_UPADATE_DATA_SOURCE.equals(event.action)) {
|
||||||
ADManager.getInstance().updateDownloadTaskBeanTable();
|
ADManager.getInstance().updateDownloadTaskBeanTable();
|
||||||
|
if(isNetworkAvailable()&&ADManager.getInstance().checkTaskQueueClear()){
|
||||||
|
ArrayList<UploadADBean.RecordsBean> uploadAds = ADManager.getInstance().getUploadAds();
|
||||||
|
if(uploadAds.size()>1){
|
||||||
|
if(downLoadAdPresenter==null){
|
||||||
|
downLoadAdPresenter = new DownLoadAdPresenter(new AppnetCallback() {
|
||||||
|
@Override
|
||||||
|
public void onResult(Object data) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter result="+String.valueOf(data));
|
||||||
|
SharePreUtils.savePreference();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewFailureString(int code, String message) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter onViewFailureString="+message);
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionFailure(String message) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter onExceptionFailure="+message);
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServerFailure(int code, String message) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter onServerFailure="+message+"code="+code);
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
downLoadAdPresenter.postDownLoadAds(Launcher.this,uploadAds);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.loge("downLoadAdPresenter net request error"+e.getMessage());
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
//throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
handler.removeCallbacks(runnable);
|
handler.removeCallbacks(runnable);
|
||||||
handler.postDelayed(runnable,1000*5);
|
handler.postDelayed(runnable,1000*5);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.SharePreUtils;
|
||||||
import com.android.monitor.DataBeeObserver;
|
import com.android.monitor.DataBeeObserver;
|
||||||
import com.android.nebulasdk.ADManager;
|
import com.android.nebulasdk.ADManager;
|
||||||
import com.android.nebulasdk.AppManager;
|
import com.android.nebulasdk.AppManager;
|
||||||
@@ -27,7 +28,7 @@ public class MyApplication extends Application {
|
|||||||
DataBeeObserver.init(getApplicationContext());
|
DataBeeObserver.init(getApplicationContext());
|
||||||
AppManager.init(getApplicationContext());
|
AppManager.init(getApplicationContext());
|
||||||
ADManager.init(getApplicationContext());
|
ADManager.init(getApplicationContext());
|
||||||
|
SharePreUtils.getInstance(getApplicationContext());
|
||||||
AdConfig config = new AdConfig.Builder()
|
AdConfig config = new AdConfig.Builder()
|
||||||
.isDebug(false)//是否开始 debug 模式,开启会打印更多log,供开发调试
|
.isDebug(false)//是否开始 debug 模式,开启会打印更多log,供开发调试
|
||||||
.productName("aike")//正式发版时使用正式的PN
|
.productName("aike")//正式发版时使用正式的PN
|
||||||
|
|||||||
102
mylibrary/src/main/java/com/android/SharePreUtils.java
Normal file
102
mylibrary/src/main/java/com/android/SharePreUtils.java
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
package com.android;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.util.GsonUtil;
|
||||||
|
import com.android.util.LogUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SharePreUtils {
|
||||||
|
public static final String SHARERE_NAME="upload_ads_droid";
|
||||||
|
private static SharePreUtils mInstance;
|
||||||
|
private static List<Map<String, Object>> dataList;//处理一对多的关系 key为AdSourceId value 为任务类型值
|
||||||
|
private static SharedPreferences.Editor editor;
|
||||||
|
|
||||||
|
private static SharedPreferences sharedPreferences;
|
||||||
|
public SharePreUtils(Context context) {
|
||||||
|
sharedPreferences=context.getSharedPreferences(SHARERE_NAME,Context.MODE_PRIVATE);
|
||||||
|
editor=sharedPreferences.edit();
|
||||||
|
dataList=getDataList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized static SharePreUtils getInstance(Context context){
|
||||||
|
if(mInstance==null){
|
||||||
|
mInstance=new SharePreUtils(context);
|
||||||
|
}
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
public synchronized static List<Map<String, Object>> getDataList(){
|
||||||
|
if(dataList==null){
|
||||||
|
String adsHasUpload = sharedPreferences.getString("ads_has_upload", "");
|
||||||
|
if(!TextUtils.isEmpty(adsHasUpload)){
|
||||||
|
List<Map<String, Object>> mapList = GsonUtil.GsonToListMaps(adsHasUpload);
|
||||||
|
dataList=mapList;
|
||||||
|
}else{
|
||||||
|
dataList=new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized static void addRelation(String key, Object value) {
|
||||||
|
if(dataList!=null){
|
||||||
|
Map<String, Object> record = new HashMap<>();
|
||||||
|
record.put("relation_key", key);
|
||||||
|
record.put("relation_value", value);
|
||||||
|
dataList.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean filterByKeyValue(String key, Object value) {
|
||||||
|
List<Map<String, Object>> filtered = new ArrayList<>();
|
||||||
|
if(dataList!=null){
|
||||||
|
for (Map<String, Object> record : dataList) {
|
||||||
|
if (key.equals(record.get("relation_key")) &&(value == null ? record.get("relation_value") == null :value.equals(record.get("relation_value")))) {
|
||||||
|
filtered.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogUtils.loge("filterByKeyValue() size"+filtered.size()+"dataList() size"+dataList.size());
|
||||||
|
return filtered.size()==1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized static void savePreference(){
|
||||||
|
if(dataList!=null&&dataList.size()>0){
|
||||||
|
String commitJson = GsonUtil.GsonString(dataList);
|
||||||
|
editor.putString("ads_has_upload",commitJson).apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeKeyFromAllMaps(String keyToRemove) {
|
||||||
|
if (dataList == null || keyToRemove == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> current=new ArrayList<>();
|
||||||
|
// 遍历列表中的每个Map
|
||||||
|
for (Map<String, Object> map : dataList) {
|
||||||
|
if (map != null) {
|
||||||
|
// 使用remove方法删除指定键
|
||||||
|
if(!map.containsKey(keyToRemove)){
|
||||||
|
current.add(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataList=current;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetDataList(){
|
||||||
|
String adsHasUpload = sharedPreferences.getString("ads_has_upload", "");
|
||||||
|
if(!TextUtils.isEmpty(adsHasUpload)&& GsonUtil.isJson(adsHasUpload)){
|
||||||
|
List<Map<String, Object>> mapList = GsonUtil.GsonToListMaps(adsHasUpload);
|
||||||
|
dataList=mapList;
|
||||||
|
}else{
|
||||||
|
dataList=new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,4 +27,8 @@ public interface ServerApi {
|
|||||||
@POST(ServerInterface.POST_LAUNCHER_ADS)
|
@POST(ServerInterface.POST_LAUNCHER_ADS)
|
||||||
Call<String> postLauncherAds(@Body RequestBody requestBody);
|
Call<String> postLauncherAds(@Body RequestBody requestBody);
|
||||||
|
|
||||||
|
@Headers({"Content-type:application/json;charset=UTF-8"})
|
||||||
|
@POST(ServerInterface.POST_DOWNLOAD_ADS)
|
||||||
|
Call<String> postDownLoadAds(@Body RequestBody requestBody);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public class ServerInterface {
|
|||||||
/**上传事件信息*/
|
/**上传事件信息*/
|
||||||
public static final String POST_EVENTINFO_DEVICE="/app-api/third/launcher/ad/play/callback";
|
public static final String POST_EVENTINFO_DEVICE="/app-api/third/launcher/ad/play/callback";
|
||||||
|
|
||||||
|
public static final String POST_DOWNLOAD_ADS="/app-api/launcher/ad/cb";
|
||||||
|
|
||||||
private static final boolean USER_DEBUG=false;
|
private static final boolean USER_DEBUG=false;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package com.android.api.biz;
|
|||||||
import com.android.api.biz.OnBaseListener;
|
import com.android.api.biz.OnBaseListener;
|
||||||
import com.android.database.lib.RecordEventBean;
|
import com.android.database.lib.RecordEventBean;
|
||||||
import com.android.nebulasdk.bean.EventDataInfo;
|
import com.android.nebulasdk.bean.EventDataInfo;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -19,8 +20,8 @@ public interface Biz {
|
|||||||
void postLauncherAds(Map<String ,String > map, OnBaseListener listener);
|
void postLauncherAds(Map<String ,String > map, OnBaseListener listener);
|
||||||
//记录设备事件的接口
|
//记录设备事件的接口
|
||||||
void postEventData(List<EventDataInfo> recordEventBeans, OnBaseListener listener);
|
void postEventData(List<EventDataInfo> recordEventBeans, OnBaseListener listener);
|
||||||
|
//上传各个广告位下载状态
|
||||||
|
void postDownloadAd(UploadADBean uploadADBean, OnBaseListener listener);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.android.api.biz.bizimpl;
|
|||||||
|
|
||||||
import com.android.api.biz.Biz;
|
import com.android.api.biz.Biz;
|
||||||
import com.android.nebulasdk.bean.EventDataInfo;
|
import com.android.nebulasdk.bean.EventDataInfo;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.android.api.ServerApi;
|
import com.android.api.ServerApi;
|
||||||
import com.android.api.biz.BaseBiz;
|
import com.android.api.biz.BaseBiz;
|
||||||
@@ -110,5 +111,38 @@ public class BizImpl extends BaseBiz implements Biz {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postDownloadAd(UploadADBean uploadADBean, OnBaseListener listener) {
|
||||||
|
RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), GsonUtil.GsonString(uploadADBean));
|
||||||
|
getStringRetrofit().create(ServerApi.class).postDownLoadAds(requestBody).enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<String> call, Response<String> response) {
|
||||||
|
if(call != null){
|
||||||
|
if (response.body() != null) {
|
||||||
|
LogUtils.loge("postLauncherAds response==>" + GsonUtil.GsonString(response.body()));
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
listener.onResponse(response.body());
|
||||||
|
} else {
|
||||||
|
listener.onFailure(response.message(), response.raw().code());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
listener.onFailure("The server is busy, please try again later", response.raw().code());
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
LogUtils.loge("postDownloadAd Biz>>>>>>>>>>>>>>>>>>call == null<<<<<<<<<<<<<<<<<<");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<String> call, Throwable t) {
|
||||||
|
if (call.isExecuted()) {
|
||||||
|
call.cancel();
|
||||||
|
}
|
||||||
|
LogUtils.loge("recoedDeviceEvent Biz服务器未响应请求失败==>" + GsonUtil.GsonString(t.getMessage()));
|
||||||
|
listener.onFailure("The server is busy, please try again later", 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,4 +289,9 @@ public class DownLoadManeger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public boolean checkTaskQueueClear(){
|
||||||
|
LogUtils.loge("checkTaskQueueClear() size="+TaskQueue.getInstance().getAllTask().size());
|
||||||
|
return TaskQueue.getInstance().size()==0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.SharePreUtils;
|
||||||
import com.android.database.AdsInfoBeanDao;
|
import com.android.database.AdsInfoBeanDao;
|
||||||
import com.android.database.DaoManager;
|
import com.android.database.DaoManager;
|
||||||
import com.android.database.lib.AdsInfoBean;
|
import com.android.database.lib.AdsInfoBean;
|
||||||
@@ -14,6 +15,7 @@ import com.android.download.DownLoadManeger;
|
|||||||
import com.android.eventbaus.EventBusUtils;
|
import com.android.eventbaus.EventBusUtils;
|
||||||
import com.android.eventbaus.MessageEvent;
|
import com.android.eventbaus.MessageEvent;
|
||||||
import com.android.nebulasdk.bean.ADInfo;
|
import com.android.nebulasdk.bean.ADInfo;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
import com.android.util.FileUtil;
|
import com.android.util.FileUtil;
|
||||||
import com.android.util.GsonUtil;
|
import com.android.util.GsonUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
@@ -115,6 +117,7 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
// if(adsInfoBean.getAdId()==aDInfo.getAdId()){ //是同一个任务,根据版本号更新新资源
|
// if(adsInfoBean.getAdId()==aDInfo.getAdId()){ //是同一个任务,根据版本号更新新资源
|
||||||
LogUtils.loge("aDInfo.getAdVersion()|adsInfoBean.getAdVersion():"+aDInfo.getAdVersion()+"|"+adsInfoBean.getAdVersion());
|
LogUtils.loge("aDInfo.getAdVersion()|adsInfoBean.getAdVersion():"+aDInfo.getAdVersion()+"|"+adsInfoBean.getAdVersion());
|
||||||
if(Long.valueOf(aDInfo.getAdVersion())!=adsInfoBean.getAdVersion()){ //更新新资源
|
if(Long.valueOf(aDInfo.getAdVersion())!=adsInfoBean.getAdVersion()){ //更新新资源
|
||||||
|
SharePreUtils.removeKeyFromAllMaps(String.valueOf(adsInfoBean.getAdResourceId()));
|
||||||
LogUtils.loge("广告位"+adsInfoBean.getId()+"已存在,是同一个任务同步资源,需要删除缓存文件:"+GsonUtil.GsonString(adsInfoBean));//先删除旧任务的缓存文件,再更新数据
|
LogUtils.loge("广告位"+adsInfoBean.getId()+"已存在,是同一个任务同步资源,需要删除缓存文件:"+GsonUtil.GsonString(adsInfoBean));//先删除旧任务的缓存文件,再更新数据
|
||||||
String dbLocalFilePath=adsInfoBean.getLocalFilePath();
|
String dbLocalFilePath=adsInfoBean.getLocalFilePath();
|
||||||
if(!TextUtils.isEmpty(dbLocalFilePath)) {
|
if(!TextUtils.isEmpty(dbLocalFilePath)) {
|
||||||
@@ -493,5 +496,62 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkTaskQueueClear(){
|
||||||
|
return DownLoadManeger.getInstance().checkTaskQueueClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<UploadADBean.RecordsBean> getUploadAds(){
|
||||||
|
List<AdsInfoBean> adsInfoBeanList = DaoManager.getInstance().queryByKeyList(AdsInfoBean.class, "state", "1");
|
||||||
|
ArrayList<UploadADBean.RecordsBean> uploadAdList=new ArrayList<>();
|
||||||
|
for (int i = 0; i < adsInfoBeanList.size(); i++) {
|
||||||
|
AdsInfoBean adsInfoBean = adsInfoBeanList.get(i);
|
||||||
|
String appUrl=adsInfoBean.getAppUrl();
|
||||||
|
if(!TextUtils.isEmpty(adsInfoBean.getAppUrl())){
|
||||||
|
int lastIndex = appUrl.lastIndexOf("/");
|
||||||
|
String fileName=lastIndex==-1?appUrl:appUrl.substring(lastIndex+1);
|
||||||
|
String filePath = FileUtil.getBakPath(mContext,1)+"/"+fileName;
|
||||||
|
String tmpFilePath = FileUtil.getBakPath(mContext, 1) + "/" + fileName + "-tmp";
|
||||||
|
File tmpFile=new File(tmpFilePath);
|
||||||
|
File file =new File(filePath);
|
||||||
|
if((PakageInstallUtil.checkAppInstall(mContext,adsInfoBean.getInfo()))&& !PakageInstallUtil.checkAppUpdate(mContext,adsInfoBean.getInfo(),(int) adsInfoBean.getAppVersion())){
|
||||||
|
if(!SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(2))){
|
||||||
|
LogUtils.loge("===================="+i);
|
||||||
|
SharePreUtils.addRelation(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(2));
|
||||||
|
UploadADBean.RecordsBean recordsBean = new UploadADBean.RecordsBean();
|
||||||
|
recordsBean.setAdResourceId(adsInfoBean.getAdResourceId());
|
||||||
|
recordsBean.setType(2);
|
||||||
|
uploadAdList.add(recordsBean);
|
||||||
|
}
|
||||||
|
LogUtils.loge("==============resid"+adsInfoBean.getAdResourceId());
|
||||||
|
}else if(file.exists()||(tmpFile.exists()&&tmpFile.length()==adsInfoBean.getAppSize())){
|
||||||
|
if(!SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(1))){
|
||||||
|
SharePreUtils.addRelation(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(1));
|
||||||
|
UploadADBean.RecordsBean recordsBean = new UploadADBean.RecordsBean();
|
||||||
|
recordsBean.setAdResourceId(adsInfoBean.getAdResourceId());
|
||||||
|
recordsBean.setType(1);
|
||||||
|
uploadAdList.add(recordsBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!TextUtils.isEmpty(adsInfoBean.getLocalFilePath())){
|
||||||
|
File file = new File(adsInfoBean.getLocalFilePath());
|
||||||
|
File tmpFile=new File(adsInfoBean.getLocalFilePath()+"-tmp");
|
||||||
|
if(file.exists()||(tmpFile.exists()&&tmpFile.length()==adsInfoBean.getAdSize())){
|
||||||
|
if(!SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(0))){
|
||||||
|
LogUtils.loge("===================="+i);
|
||||||
|
SharePreUtils.addRelation(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(0));
|
||||||
|
UploadADBean.RecordsBean recordsBean = new UploadADBean.RecordsBean();
|
||||||
|
recordsBean.setAdResourceId(adsInfoBean.getAdResourceId());
|
||||||
|
recordsBean.setType(0);
|
||||||
|
uploadAdList.add(recordsBean);
|
||||||
|
}
|
||||||
|
LogUtils.loge("==============resid"+adsInfoBean.getAdResourceId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(uploadAdList.size()>0){
|
||||||
|
LogUtils.loge(GsonUtil.GsonString(uploadAdList));
|
||||||
|
}
|
||||||
|
return uploadAdList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.android.nebulasdk.bean;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UploadADBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mac : 9C:00:D3:86:31:DF
|
||||||
|
* cpu : 1747248796593488611d7d3114575b9
|
||||||
|
* records : [{"adId":494,"type":0,"ts":1763450525769},{"adId":494,"type":2,"ts":1763450525769},{"adId":494,"type":0,"ts":1763450925769},{"adId":396,"type":0,"ts":1763450525769}]
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String mac;
|
||||||
|
private String cpu;
|
||||||
|
private List<RecordsBean> records;
|
||||||
|
|
||||||
|
public String getMac() {
|
||||||
|
return mac;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMac(String mac) {
|
||||||
|
this.mac = mac;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCpu() {
|
||||||
|
return cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCpu(String cpu) {
|
||||||
|
this.cpu = cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RecordsBean> getRecords() {
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecords(List<RecordsBean> records) {
|
||||||
|
this.records = records;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RecordsBean {
|
||||||
|
/**
|
||||||
|
* adId : 494
|
||||||
|
* type : 0
|
||||||
|
* ts : 1763450525769
|
||||||
|
*/
|
||||||
|
|
||||||
|
private long adResourceId;
|
||||||
|
private int type;
|
||||||
|
//private long ts;
|
||||||
|
|
||||||
|
public long getAdResourceId() {
|
||||||
|
return adResourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdResourceId(long adId) {
|
||||||
|
this.adResourceId = adId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public long getTs() {
|
||||||
|
// return ts;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setTs(long ts) {
|
||||||
|
// this.ts = ts;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.android.nebulasdk.presenter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.MXQConfig;
|
||||||
|
import com.android.api.ServerInterface;
|
||||||
|
import com.android.api.biz.Biz;
|
||||||
|
import com.android.api.biz.OnBaseListener;
|
||||||
|
import com.android.api.biz.bizimpl.BizImpl;
|
||||||
|
import com.android.api.response.EventResponse;
|
||||||
|
import com.android.nebulasdk.bean.ADInfoResponse;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
|
import com.android.nebulasdk.presenter.callback.AppnetCallback;
|
||||||
|
import com.android.util.DeviceUtil;
|
||||||
|
import com.android.util.GsonUtil;
|
||||||
|
import com.android.util.LogUtils;
|
||||||
|
import com.android.util.RKDeviceUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class DownLoadAdPresenter {
|
||||||
|
private Biz biz;
|
||||||
|
private AppnetCallback mAppnetCallback;
|
||||||
|
|
||||||
|
public DownLoadAdPresenter(AppnetCallback mAppnetCallback) {
|
||||||
|
this.mAppnetCallback = mAppnetCallback;
|
||||||
|
biz = new BizImpl(ServerInterface.createHttpUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void postDownLoadAds(Context context,ArrayList<UploadADBean.RecordsBean> recordsBeans){
|
||||||
|
UploadADBean uploadADBean=new UploadADBean();
|
||||||
|
String cpuId ="";
|
||||||
|
if(MXQConfig.ALLWINNER_PLATFORM.equalsIgnoreCase(MXQConfig.getManufacturer())) {
|
||||||
|
cpuId = DeviceUtil.getCpu();
|
||||||
|
}else if(MXQConfig.RK_PLATFORM.equalsIgnoreCase(MXQConfig.getManufacturer())){
|
||||||
|
cpuId = RKDeviceUtil.getCpu();
|
||||||
|
}
|
||||||
|
uploadADBean.setCpu(cpuId);
|
||||||
|
uploadADBean.setMac(DeviceUtil.getEthernetMac());
|
||||||
|
uploadADBean.setRecords(recordsBeans);
|
||||||
|
biz.postDownloadAd(uploadADBean, new OnBaseListener() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String result) {
|
||||||
|
LogUtils.loge(GsonUtil.GsonString(result));
|
||||||
|
if(GsonUtil.isJson(result)){
|
||||||
|
try {
|
||||||
|
EventResponse eventResponse = GsonUtil.GsonToBean(result, EventResponse.class);
|
||||||
|
if (eventResponse.getCode() == ServerInterface.SUCCESS) {
|
||||||
|
mAppnetCallback.onResult(eventResponse.getData());
|
||||||
|
} else {
|
||||||
|
mAppnetCallback.onViewFailureString(eventResponse.getCode(), eventResponse.getMsg());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
mAppnetCallback.onExceptionFailure("json 解析异常:"+e.getMessage());
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
mAppnetCallback.onServerFailure(0,"获取签到信息,服务器繁忙··");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(String e, int code) {
|
||||||
|
mAppnetCallback.onServerFailure(code,e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user