package com.weikou.beibeivideo.util.ad;
|
|
import android.app.Activity;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
|
import com.weikou.beibeivideo.entity.HomeAd;
|
import com.weikou.beibeivideo.ui.media.VideoDetailActivity2;
|
import com.weikou.beibeivideo.util.CustomShareDialog;
|
import com.weikou.beibeivideo.util.downutil.DownFiles;
|
|
import org.json.JSONObject;
|
|
import java.util.Iterator;
|
|
public class HomeAdUtil {
|
|
public static void jump(HomeAd homeAd, Activity context) {
|
Intent intent = null;
|
if (homeAd.getLinkType() == 1) {
|
intent = new Intent(context,
|
VideoDetailActivity2.class);
|
intent.putExtra("video_info", homeAd
|
.getVideo());
|
intent.putExtra("from", "homeAd");
|
} else if (homeAd.getLinkType() == 5) {
|
try {
|
JSONObject object = new JSONObject(homeAd.getParams()
|
.replace("\\", ""));
|
String thumb = object.optString("thumb");
|
String title = object.optString("title");
|
String desc = object.optString("desc");
|
String path = object.optString("path");
|
String username = object.optString("username");
|
String url = object.optString("url");
|
|
CustomShareDialog.Builder builder = new CustomShareDialog.Builder(context);
|
builder.setMessage(desc);
|
builder.setUrl(url);
|
builder.setContentImage(thumb);
|
builder.setTitle(title);
|
builder.setPath(path);
|
builder.setUserName(username);
|
builder.setNegativeButton("取消分享", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
}
|
});
|
builder.create().show();
|
} catch (Exception e) {
|
|
}
|
|
} else {
|
try {
|
intent = new Intent(context, Class
|
.forName(homeAd.getClazz()));
|
JSONObject object = new JSONObject(homeAd.getParams()
|
.replace("\\", ""));
|
if (homeAd.getClazz().contains("FXBrowserActivity") && object.optString("url").endsWith(".apk")) {
|
startDownLoadFile(context, object.optString("url"));
|
return;
|
}
|
if (homeAd.getParams() != null) {
|
@SuppressWarnings("unchecked")
|
Iterator<String> its = object.keys();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = object.optString(key);
|
intent.putExtra(key, value);
|
intent.putExtra("isPush", true);
|
}
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
if (context != null && intent != null)
|
context.startActivity(intent);
|
}
|
|
|
private static void startDownLoadFile(Context context, String url) {
|
new DownFiles(context, new DownFiles.IProgress() {
|
@Override
|
public void getProgress(int p) {
|
//TODO 处理进度
|
}
|
}).execute(url);
|
}
|
|
|
}
|