Commit 23cfb489 authored by jyx's avatar jyx

体验试玩积分墙任务

parent dd6c3969
package com.mints.goodmoney.ad.video;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.text.TextUtils;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.common.AppConfig;
import com.mints.goodmoney.common.Constant;
import com.mints.goodmoney.manager.TrackManager;
import com.mints.goodmoney.mvp.model.VideoAdingBean;
import com.mints.goodmoney.mvp.model.WeightBean;
import com.mints.goodmoney.service.AppInstallService;
import com.mints.goodmoney.utils.AppUtil;
import com.mints.goodmoney.utils.LogUtil;
import com.mints.goodmoney.utils.ToastUtil;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
......@@ -77,6 +82,45 @@ public class VideoAdingManager {
weightList = new ArrayList<>();
}
// APP下载回调广播
private BroadcastReceiver mReceiverBroadcastReceiver = null;
private void registerBroad() {
if (AppConfig.isSuperTask) {
return;
}
if (mReceiverBroadcastReceiver != null) {
return;
}
activity.startService(new Intent(activity, AppInstallService.class));
mReceiverBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
try {
String pkg = intent.getStringExtra("pkg");
String appName = AppUtil.INSTANCE.getAppName(pkg, activity);
TrackManager.getInstance().saveInstallAppRecord(pkg, appName, "");
} catch (Exception e) {
e.printStackTrace();
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(AppInstallService.APP_INSTALL_ACTION);
activity.registerReceiver(this.mReceiverBroadcastReceiver, intentFilter);
}
/**
* 初始化广告权重
*/
......@@ -323,6 +367,11 @@ public class VideoAdingManager {
shVideoAdManager = null;
}
if (mReceiverBroadcastReceiver != null) {
activity.stopService(new Intent(activity, AppInstallService.class));
activity.unregisterReceiver(mReceiverBroadcastReceiver);
}
activity = null;
}
......@@ -380,6 +429,9 @@ public class VideoAdingManager {
@Override
public void ylhVideoAdDownload() {
isVideoAdDownload = true;
// 注册下载任务监听
registerBroad();
}
});
ylhVideoAdManager.loadAd(activity, bean.getCurCoin(), bean.getCarrierType(), bean.getExtraId());
......@@ -415,6 +467,9 @@ public class VideoAdingManager {
@Override
public void csjVideoDownload() {
isVideoAdDownload = true;
// 注册下载任务监听
registerBroad();
}
});
csjVideoAdManager.loadAd(activity, bean.getCurCoin(), bean.getCarrierType(), bean.getExtraId());
......@@ -448,6 +503,9 @@ public class VideoAdingManager {
@Override
public void wnVideoAdDownload() {
isVideoAdDownload = true;
// 注册下载任务监听
registerBroad();
}
});
wnVideoAdManager.loadAd(activity, bean.getCurCoin(), bean.getCarrierType(), bean.getExtraId());
......@@ -481,6 +539,9 @@ public class VideoAdingManager {
@Override
public void mhVideoAdDownload() {
isVideoAdDownload = true;
// 注册下载任务监听
registerBroad();
}
});
......@@ -515,6 +576,9 @@ public class VideoAdingManager {
@Override
public void csjFullVedioDownload() {
isVideoAdDownload = true;
// 注册下载任务监听
registerBroad();
}
});
......@@ -549,6 +613,9 @@ public class VideoAdingManager {
@Override
public void shVideoAdDownload() {
isVideoAdDownload = true;
// 注册下载任务监听
registerBroad();
}
});
......
package com.mints.goodmoney.ad.video;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.SystemClock;
import com.mints.goodmoney.MintsApplication;
......@@ -11,6 +13,7 @@ import com.mints.goodmoney.manager.TtCsjAdManager;
import com.mints.goodmoney.manager.YlhAdManager;
import com.mints.goodmoney.mvp.presenters.YlhVideoAdPresenter;
import com.mints.goodmoney.mvp.views.VideoAdManagerView;
import com.mints.goodmoney.service.AppInstallService;
import com.mints.goodmoney.utils.LogUtil;
import com.mints.goodmoney.utils.ToastUtil;
import com.qq.e.ads.rewardvideo.RewardVideoAD;
......
......@@ -12,12 +12,9 @@ import androidx.appcompat.app.AppCompatActivity;
import com.mints.goodmoney.R;
import com.mints.goodmoney.call.business.RingtoneHelper;
import com.mints.goodmoney.call.business.VideoDBHelper;
import com.mints.goodmoney.call.permission.PermissionActivity;
import com.mints.goodmoney.call.permission.PermissionManager;
import com.mints.goodmoney.ui.activitys.MainActivity;
/**
* 设置成功
* 作者:孟崔广
......
......@@ -115,4 +115,9 @@ public class AppConfig {
*/
public static int wzReadCoin = 300;
/**
* 是否是超级翻倍标识
*/
public static boolean isSuperTask = false;
}
......@@ -89,6 +89,7 @@ object Constant {
const val MAIN_CUR_COIN = "main_cur_coin" //当前金币展示
const val MAIN_EXTRA_ID = "main_extra_id" //额外ID
const val MAIN_CARRIER_TYPE = "main_carrier_type" //载体
const val MAIN_AID = "main_aid" // 体验安装过APP的aid
// 载体
......@@ -133,6 +134,7 @@ object Constant {
const val CARRIER_SHARE_NEWS = "SHARE_NEWS" //分享新闻
const val CARRIER_CPD = "CPD" //珊瑚CPD下载试玩任务
const val CARRIER_CPD_SYD = "CPD_SYD" //SYDCPD下载试玩任务
const val CARRIER_CPD_USEAPP = "CPD_USEAPP" //积分墙体验试玩下载过的APP
const val CHALLENGE_SHAREFRIEND = "CHALLENGE_SHAREFRIEND" //邀请好友
......
......@@ -32,7 +32,7 @@ public class TrackManager {
private void init() {
trackPresenter = new TrackPresenter();
trackPresenter.attachView((MintsApplication) MintsApplication.getContext());
trackPresenter.attachView(MintsApplication.getContext());
}
/**
......@@ -104,4 +104,10 @@ public class TrackManager {
trackPresenter.firstApiWithUid();
}
}
public void saveInstallAppRecord(String pkg, String name, String icon) {
if (trackPresenter != null && !TextUtils.isEmpty(UserManager.getInstance().getUserID())) {
trackPresenter.saveInstallAppRecord(pkg, name, icon);
}
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
import java.util.List;
public class TaskCpdBean implements Serializable {
/**
* needSeconds : 60
* list : [{"date":"2021-01-28","icon":"2021-01-28","name":"2021-01-28","pkg":"2021-01-28","day":"2021-01-28","coin":"2021-01-28"}]
*/
private int needSeconds;
private List<ListBean> list;
public int getNeedSeconds() {
return needSeconds;
}
public void setNeedSeconds(int needSeconds) {
this.needSeconds = needSeconds;
}
public List<ListBean> getList() {
return list;
}
public void setList(List<ListBean> list) {
this.list = list;
}
public static class ListBean implements Serializable {
/**
* date : 2021-01-28
* icon : 2021-01-28
* name : 2021-01-28
* pkg : 2021-01-28
* day : 2021-01-28
* coin : 2021-01-28
*/
private String date;
private String icon;
private String name;
private String pkg;
private String day;
private String aid;
private int coin;
public String getAid() {
return aid;
}
public void setAid(String aid) {
this.aid = aid;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPkg() {
return pkg;
}
public void setPkg(String pkg) {
this.pkg = pkg;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
public int getCoin() {
return coin;
}
public void setCoin(int coin) {
this.coin = coin;
}
}
}
......@@ -16,6 +16,16 @@ public class TzTaskBean {
private String currentPkgName;
private String downLoadPkgName;
public String getAid() {
return aid;
}
public void setAid(String aid) {
this.aid = aid;
}
private String aid;
public TzTaskBean(String icon, String title,String description, boolean isShCpd,int coin, int state, String downLoadPkgName) {
this.icon = icon;
this.title = title;
......
package com.mints.goodmoney.mvp.presenters;
import com.mints.goodmoney.manager.AppHttpManager;
import com.mints.goodmoney.mvp.model.BaseResponse;
import com.mints.goodmoney.mvp.model.TaskCpdBean;
import com.mints.goodmoney.mvp.views.TaskCpdHistoryView;
import com.mints.library.net.neterror.BaseSubscriber;
import com.mints.library.net.neterror.Throwable;
public class TaskCpdHistoryPresenter extends BasePresenter<TaskCpdHistoryView> {
/**
* 获取首页喝水信息
*/
public void getCpdUseAppModelMsg() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.getCpdUseAppModelMsg(),
new BaseSubscriber<BaseResponse<TaskCpdBean>>() {
@Override
public void onCompleted() {
if (isLinkView()) return;
view.hideLoading();
}
@Override
public void onError(Throwable e) {
if (isLinkView()) return;
view.hideLoading();
view.showToast(e.getMessage());
view.getCpdUseAppModelMsgFail();
}
@Override
public void onNext(BaseResponse<TaskCpdBean> baseResponse) {
if (isLinkView()) return;
int code = baseResponse.getStatus();
String message = baseResponse.getMessage();
TaskCpdBean data = baseResponse.getData();
switch (code) {
case 200://成功
if (data != null) {
view.getCpdUseAppModelMsgSuc(data);
} else {
view.getCpdUseAppModelMsgFail();
}
break;
default:
view.getCpdUseAppModelMsgFail();
view.showToast(message);
break;
}
}
});
}
}
......@@ -219,4 +219,30 @@ public class TrackPresenter extends BaseTrackPresenter {
}
});
}
/**
* 首页是否显示微转
*/
public void saveInstallAppRecord(String pkg, String name, String icon) {
HashMap<String, Object> vo = new HashMap<>();
vo.put("pkg", pkg);
vo.put("name", name);
vo.put("icon", icon);
AppHttpManager.getInstance(loanApplication)
.call(loanService.saveInstallAppRecord(vo),
new BaseSubscriber<BaseResponse<JsonObject>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(BaseResponse<JsonObject> baseResponse) {
}
});
}
}
package com.mints.goodmoney.mvp.views;
import com.mints.goodmoney.mvp.model.TaskCpdBean;
public interface TaskCpdHistoryView extends BaseView {
void getCpdUseAppModelMsgSuc(TaskCpdBean taskCpdBean);
void getCpdUseAppModelMsgFail();
}
......@@ -19,6 +19,7 @@ import com.mints.goodmoney.mvp.model.MealBean;
import com.mints.goodmoney.mvp.model.MorningClockBean;
import com.mints.goodmoney.mvp.model.MyInfo;
import com.mints.goodmoney.mvp.model.SignCardBean;
import com.mints.goodmoney.mvp.model.TaskCpdBean;
import com.mints.goodmoney.mvp.model.UserBean;
import com.mints.goodmoney.mvp.model.UserTaskMsgBean;
import com.mints.goodmoney.mvp.model.Version;
......@@ -552,6 +553,22 @@ public interface LoanService {
@POST("api/firstApiWithUid")
Observable<BaseResponse<JsonObject>> firstApiWithUid(@Body Map<String, Object> vo);
/**
* 保存激励视频安装APP包名
*
* @return
*/
@POST("api/saveInstallAppRecord")
Observable<BaseResponse<JsonObject>> saveInstallAppRecord(@Body Map<String, Object> vo);
/**
* 保存激励视频安装APP包名
*
* @return
*/
@POST("api/getCpdUseAppModelMsg")
Observable<BaseResponse<TaskCpdBean>> getCpdUseAppModelMsg();
/**
* 默认http工厂
*/
......
......@@ -17,6 +17,7 @@ import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.common.DeviceInfo.Companion.instance
import com.mints.goodmoney.manager.AppTryPlayManager
import com.mints.goodmoney.manager.TrackManager
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.VideoAdingBean
import com.mints.goodmoney.mvp.presenters.AwardPresenter
......@@ -26,6 +27,7 @@ import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.widgets.countdowntimer.CountDownTimerSupport
import com.mints.goodmoney.ui.widgets.countdowntimer.OnCountDownTimerListener
import com.mints.goodmoney.utils.*
import com.mints.goodmoney.utils.AppUtil.getAppName
import com.mints.goodmoney.utils.rxutil.CommonRxTask
import com.mints.goodmoney.utils.rxutil.RxjavaUtil
import com.umeng.analytics.MobclickAgent
......@@ -47,11 +49,9 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
private var curCoin = 0 //传入金币
private var extraId = ""//传入key
private var carrierType = ""//传入载体
private var aid = ""//传入体验任务的aid
private var loadVideoFailCount = 0 // 视频失败次数
// 超级翻倍领取标识
private var isSuperTask = false
// 超级翻倍领取状态 0-去下载 1-去试玩 2-试玩时间不足 3-领取奖励 4-放弃试玩
private var superTaskStatus = 0
private var mCurrentPkg: String? = null
......@@ -281,13 +281,18 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
}
tvAwardNext.text = "我知道了"
}
Constant.CARRIER_HIGH_ACTIVITY, Constant.CARRIER_CPD, Constant.CARRIER_CPD_SYD -> {
Constant.CARRIER_HIGH_ACTIVITY, Constant.CARRIER_CPD, Constant.CARRIER_CPD_SYD, Constant.CARRIER_CPD_USEAPP -> {
if (curCoin > 0) {
tvAwardContent.text = "试玩奖励${curCoin}金币"
tvAwardNext.text = "领取金币"
val vo = HashMap<String, Any>()
vo["carrierType"] = carrierType
if (carrierType == Constant.CARRIER_CPD_USEAPP) {
vo["aid"] = aid
}
awardPresenter.reportAddCoinMsg(vo)
} else {
tvAwardContent.text = "很遗憾,试玩时间不足"
tvAwardNext.text = "我知道了"
......@@ -338,6 +343,7 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
curCoin = it.getInt(Constant.MAIN_CUR_COIN, 0)
extraId = it.getString(Constant.MAIN_EXTRA_ID, "")
carrierType = it.getString(Constant.MAIN_CARRIER_TYPE, "")
aid = it.getString(Constant.MAIN_AID, "")
}
}
......@@ -360,6 +366,7 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
override fun onDestroy() {
super.onDestroy()
AppConfig.isSuperTask = false
awardPresenter.setHighTaskType("0")
mTimer?.stop()
......@@ -564,8 +571,8 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
carrierType == Constant.CARRIER_BLESSINGBAG_DOUBLE || // 首页福袋翻倍
carrierType == Constant.CARRIER_SMALLHOMEVEDIO_DOUBLE || // 短视频红包翻倍
carrierType == Constant.CARRIER_HOMEVEDIO_DOUBLE) { // 小视频红包翻倍
isSuperTask = showHigh
if (isSuperTask) {
AppConfig.isSuperTask = showHigh
if (AppConfig.isSuperTask) {
refreshHighTask(highCoin)
}
}
......@@ -702,13 +709,16 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent == null) return
// 非高额任务不监听下载安装
if (isSuperTask) {
if (AppConfig.isSuperTask) {
try {
val pkg = intent.getStringExtra("pkg")
mCurrentPkg = pkg
awardPresenter.setHighTaskType("3")
val appName = getAppName(pkg, this@AwardActivity)
TrackManager.getInstance().saveInstallAppRecord(pkg, appName, "")
} catch (e: Exception) {
e.printStackTrace()
}
......
......@@ -13,6 +13,7 @@ import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.manager.AppTryPlayManager
import com.mints.goodmoney.manager.DownloadApkManager
import com.mints.goodmoney.manager.TrackManager
import com.mints.goodmoney.mvp.model.CpdModelBean
import com.mints.goodmoney.mvp.model.TzTaskBean
import com.mints.goodmoney.mvp.presenters.TaskPresenter
......@@ -510,6 +511,10 @@ class TaskActivity : BaseActivity(), TaskView,
if (mFakeTaskList[position].isShCpd) {
// 上报珊瑚安装完成
mDownloadProcess?.reportInstallSuccess(false)
// 上报安装过的APP
val coralAd = mFakeTaskList[position].coralAd
TrackManager.getInstance().saveInstallAppRecord(coralAd.packageName, coralAd.title, coralAd.icon)
} else {
val trackerBean = mFakeTaskList[position].trackerBean
if (trackerBean != null) {
......
......@@ -8,8 +8,10 @@ import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.adapter.MessageFragAdapter
import com.mints.goodmoney.ui.fragment.TaskCpdFragment
import com.mints.goodmoney.ui.fragment.TaskCpdHistoryFragment
import com.mints.goodmoney.ui.widgets.CustomDialogAsApple
import com.mints.goodmoney.ui.widgets.DialogListener
import com.mints.goodmoney.utils.CacheUtil
import kotlinx.android.synthetic.main.activity_task_cpd.*
import kotlinx.android.synthetic.main.header_layout.*
......@@ -31,6 +33,8 @@ class TaskCpdActivity : BaseActivity(), View.OnClickListener {
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
CacheUtil.clearAllCache(context)
initViewAndData()
initListener()
}
......@@ -52,12 +56,14 @@ class TaskCpdActivity : BaseActivity(), View.OnClickListener {
private fun initViewAndData() {
val tabs: MutableList<String> = ArrayList()
val fragments: MutableList<Fragment> = ArrayList()
tabs.add("标签1")
tabs.add("试玩")
fragments.add(TaskCpdFragment())
AppConfig.useAppCpdModelShow = true
if (AppConfig.useAppCpdModelShow) {
tabs.add("标签2")
fragments.add(TaskCpdFragment())
tabs.add("点击")
fragments.add(TaskCpdHistoryFragment())
xtTaskCpd.visibility = View.VISIBLE
} else {
xtTaskCpd.visibility = View.GONE
......
package com.mints.goodmoney.ui.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mints.goodmoney.R
import com.mints.goodmoney.mvp.model.TzTaskBean
import com.mints.goodmoney.ui.adapter.listener.OnItemChildClickListener
import com.mints.goodmoney.ui.adapter.listener.OnItemClickListener
import com.mints.library.utils.GlideUtils
import com.tz.sdk.core.ui.ADContainer
class TaskCpdHistoryAdapter(val dataList: List<TzTaskBean>, val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var mCurrentPosition = 0
private var needUseTime = 30
lateinit var mOnItemClickListener: OnItemClickListener
lateinit var mOnItemChildClickListener: OnItemChildClickListener
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.item_task_recy_cpd_history, parent, false)
return CPDViewHolder(view)
}
override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {
val data = dataList[position]
val holder = viewHolder as BaseViewHolder
GlideUtils.loadImageViewLoding(context, data.icon, holder.ivAvatar, R.mipmap.ic_launcher_main, R.mipmap.ic_launcher_main)
holder.tvTitle.text = data.title
holder.tvCoin.text = "+" + data.coin + "金币"
holder.itemTvtext.text = "打开应用体验" + needUseTime + "秒,返回领取"
when (data.state) {
1 -> {
holder.btnSubmit.text = "去试玩"
}
2 -> {
holder.btnSubmit.text = "立即领取"
}
3 -> {
holder.btnSubmit.text = "已完成"
}
4 -> {
holder.btnSubmit.text = "继续试玩"
}
}
if (::mOnItemClickListener.isInitialized) {
holder.itemView.setOnClickListener {
setPosition(position)
mOnItemClickListener.onItemClick(it, position)
}
}
if (::mOnItemChildClickListener.isInitialized) {
if (holder.btnSubmit.visibility == View.VISIBLE) {
holder.btnSubmit.setOnClickListener {
setPosition(position)
mOnItemChildClickListener.onItemChildClick(it, position)
}
} else {
holder.btnSubmit.setOnClickListener(null)
}
}
}
fun getPosition() = mCurrentPosition
fun setNeedUseTime(needUseTime: Int) {
this.needUseTime = needUseTime
}
private fun setPosition(currentPosition: Int) {
this.mCurrentPosition = currentPosition
notifyDataSetChanged()
}
fun setOnItemClickListener(listener: OnItemClickListener) {
mOnItemClickListener = listener
}
fun setOnItemChildClickListener(listener: OnItemChildClickListener) {
mOnItemChildClickListener = listener
}
override fun getItemCount() = dataList.size
inner class SHViewHolder(view: View) : BaseViewHolder(view) {
val adContainer: ADContainer = view.findViewById(R.id.ad_container)
}
inner class CPDViewHolder(view: View) : BaseViewHolder(view)
open class BaseViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val ivAvatar: ImageView = view.findViewById(R.id.item_iv_avatar)
val tvTitle: TextView = view.findViewById(R.id.item_tv_title)
val tvCoin: TextView = view.findViewById(R.id.item_tv_coin)
val itemTvtext: TextView = view.findViewById(R.id.item_tv_text)
val btnSubmit: Button = view.findViewById(R.id.item_btn_submit)
}
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.manager.AppTryPlayManager
import com.mints.goodmoney.manager.DownloadApkManager
import com.mints.goodmoney.manager.TrackManager
import com.mints.goodmoney.mvp.model.CpdModelBean
import com.mints.goodmoney.mvp.model.TzTaskBean
import com.mints.goodmoney.mvp.presenters.TaskPresenter
......@@ -22,7 +23,6 @@ import com.mints.goodmoney.ui.activitys.AwardActivity
import com.mints.goodmoney.ui.adapter.TaskAdapter
import com.mints.goodmoney.ui.adapter.listener.OnItemChildClickListener
import com.mints.goodmoney.ui.fragment.base.BaseFragment
import com.mints.goodmoney.ui.widgets.CustomDialogAsApple
import com.mints.goodmoney.ui.widgets.DialogListener
import com.mints.goodmoney.ui.widgets.TaskCpdDialog
import com.mints.goodmoney.ui.widgets.TaskDialog
......@@ -34,7 +34,6 @@ import com.scwang.smartrefresh.layout.listener.OnRefreshListener
import com.tz.sdk.coral.ad.CoralAD
import com.tz.sdk.coral.callback.h5.DownloadProcess
import kotlinx.android.synthetic.main.activity_task.*
import kotlinx.android.synthetic.main.header_layout.*
class TaskCpdFragment : BaseFragment(), TaskView,
OnRefreshListener,
......@@ -51,8 +50,6 @@ class TaskCpdFragment : BaseFragment(), TaskView,
private var taskDialog: TaskDialog? = null
private var taskCpdDialog: TaskCpdDialog? = null
private lateinit var cdaa: CustomDialogAsApple
// 天卓下载广告请求
private var mCoralDownload: CoralDownload? = null
private var mDownloadProcess: DownloadProcess? = null
......@@ -108,6 +105,15 @@ class TaskCpdFragment : BaseFragment(), TaskView,
srl_task.setOnRefreshListener(this)
}
override fun onHiddenChanged(hidden: Boolean) {
if (hidden) { // 不在最前端界面显示
onPause()
} else { // 重新显示到最前端中
onResume()
}
super.onHiddenChanged(hidden)
}
override fun onResume() {
super.onResume()
......@@ -354,11 +360,6 @@ class TaskCpdFragment : BaseFragment(), TaskView,
super.onDestroy()
}
// override fun onBackPressed() {
// super.onBackPressed()
// backDialog()
// }
override fun onItemChildClick(view: View?, position: Int) {
when (mFakeTaskList[position].state) {
// 0 立即下载, 1 去试玩, 2 领取奖励 3 已领取 4 继续试玩
......@@ -450,7 +451,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
}
DownloadApkManager.setOnMyDownloadListener(this@TaskCpdFragment)
DownloadApkManager.downloadApk(requireActivity(), mFakeTaskList[position].app_url, mFakeTaskList[position].currentPkgName)
DownloadApkManager.downloadApk(requireActivity(), mFakeTaskList[position].app_url, mFakeTaskList[position].downLoadPkgName)
}
})
taskCpdDialog?.setData(mFakeTaskList[position].title, mFakeTaskList[position].description, mFakeTaskList[position].icon, needUseTime, mCoin)
......@@ -486,6 +487,9 @@ class TaskCpdFragment : BaseFragment(), TaskView,
mTaskAdapter!!.notifyItemChanged(position)
if (mFakeTaskList[position].isShCpd) {
// 上报后台珊瑚安装完成
TrackManager.getInstance().saveInstallAppRecord(pkg, mFakeTaskList[position].title, mFakeTaskList[position].icon)
// 上报珊瑚安装完成
mDownloadProcess?.reportInstallSuccess(false)
} else {
......@@ -595,26 +599,6 @@ class TaskCpdFragment : BaseFragment(), TaskView,
taskPresenter.getShCpdTime()
}
private fun backDialog() {
cdaa = CustomDialogAsApple(context, object : DialogListener() {
override fun onClick(v: View) {
if (cdaa.isShowing) {
cdaa.dismiss()
}
when (v.id) {
R.id.dialog_btn_right -> {
// finish()
}
}
}
})
cdaa.setTitle("提示")
cdaa.setContent("退出当前页面将会重置当前任务状态")
cdaa.setLeft("取消")
cdaa.setRight("确定")
cdaa.show()
}
/**
* 开始下载
*/
......
package com.mints.goodmoney.ui.fragment
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.AppTryPlayManager
import com.mints.goodmoney.mvp.model.TaskCpdBean
import com.mints.goodmoney.mvp.model.TzTaskBean
import com.mints.goodmoney.mvp.presenters.TaskCpdHistoryPresenter
import com.mints.goodmoney.mvp.views.TaskCpdHistoryView
import com.mints.goodmoney.ui.activitys.AwardActivity
import com.mints.goodmoney.ui.adapter.TaskCpdHistoryAdapter
import com.mints.goodmoney.ui.adapter.listener.OnItemChildClickListener
import com.mints.goodmoney.ui.fragment.base.LazyLoadBaseFragment
import com.mints.goodmoney.utils.*
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshListener
import kotlinx.android.synthetic.main.activity_task.*
class TaskCpdHistoryFragment : LazyLoadBaseFragment(), TaskCpdHistoryView,
OnRefreshListener,
OnItemChildClickListener {
private val taskCpdHistoryPresenter by lazy { TaskCpdHistoryPresenter() }
private var mTaskAdapter: TaskCpdHistoryAdapter? = null
private val mFakeTaskList: MutableList<TzTaskBean> = arrayListOf()
// 试完时间不足弹窗
private var tryTimeOut = false
private var needUseTime = -1
override fun initViewsAndEvents() {}
private fun initView() {
val linearLayoutManager = LinearLayoutManager(mContext)
recy_task.layoutManager = linearLayoutManager
mTaskAdapter = TaskCpdHistoryAdapter(mFakeTaskList, mContext)
recy_task.adapter = mTaskAdapter
mTaskAdapter?.setOnItemChildClickListener(this)
}
override fun onFragmentFirstVisible() {
super.onFragmentFirstVisible()
taskCpdHistoryPresenter.attachView(this)
initView()
initListener()
loadData()
}
private fun initListener() {
srl_task.setOnRefreshListener(this)
}
override fun onHiddenChanged(hidden: Boolean) {
if (hidden) { // 不在最前端界面显示
onPause()
} else { // 重新显示到最前端中
onResume()
}
super.onHiddenChanged(hidden)
}
override fun onResume() {
super.onResume()
try {
if (needUseTime != -1) {
refreshDemoTask()
}
} catch (e: Exception) {
LogUtil.e(e.printStackTrace())
}
}
override fun getContentViewLayoutID() = R.layout.activity_task
override fun onRefresh(refreshLayout: RefreshLayout) {
loadData()
}
override fun onDestroyView() {
taskCpdHistoryPresenter.detachView()
super.onDestroyView()
}
override fun onItemChildClick(view: View?, position: Int) {
when (mFakeTaskList[position].state) {
// 0 立即下载, 1 去试玩, 2 领取奖励 3 已领取 4 继续试玩
1 -> {
mTaskAdapter?.let {
val currentPkgName = mFakeTaskList[it.getPosition()].downLoadPkgName
if (currentPkgName == null) {
showToast("任务异常,请重试~")
mFakeTaskList[it.getPosition()].state = 3
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
showToast("未找到当前APP、可能被卸载,请重试~")
// 重置当前列表状态
mFakeTaskList[it.getPosition()].state = 3
it.notifyItemChanged(it.getPosition())
}
}
}
}
2 -> {
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, mFakeTaskList[position].coin)
mTaskAdapter?.let {
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_CPD_USEAPP)
}
bundle.putString(Constant.MAIN_AID, mFakeTaskList[position].aid)
readyGo(AwardActivity::class.java, bundle)
mFakeTaskList[position].state = 3
}
3 -> {
showToast("当前任务已完成,试试其他任务吧!")
}
4 -> {
mTaskAdapter?.let {
val currentPkgName = mFakeTaskList[it.getPosition()].downLoadPkgName
if (currentPkgName == null) {
showToast("任务异常,请重试~")
mFakeTaskList[it.getPosition()].state = 3
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
showToast("未找到当前APP、可能被卸载,请重试~")
// 重置当前列表状态
mFakeTaskList[it.getPosition()].state = 3
it.notifyItemChanged(it.getPosition())
}
}
}
}
}
}
/**
* 刷新高额任务
*/
private fun refreshDemoTask() {
mTaskAdapter?.let {
val position = it.getPosition()
if (mFakeTaskList.size == 0 || mFakeTaskList[position].state == 3) return
val currentPkgName = mFakeTaskList[position].downLoadPkgName
if (currentPkgName != null) {
// 时间为0
if (needUseTime == 0) {
mFakeTaskList[position].state = 2
it.notifyItemChanged(position)
}
if (AppTryPlayManager.getTryPlayIsOK(currentPkgName, needUseTime)) {
// 完成试玩任务
mFakeTaskList[position].state = 2
it.notifyItemChanged(position)
} else {
if (AppTryPlayManager.getTryPlayIsOK(currentPkgName, 5)) {
// 试玩时间不足
if (tryTimeOut) {
return
}
tryTimeOut = true
mFakeTaskList[position].state = 4
it.notifyItemChanged(it.getPosition())
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, 0)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_CPD_USEAPP)
readyGo(AwardActivity::class.java, bundle)
} else {
// 试玩时间不足5秒
mFakeTaskList[position].state = 1
it.notifyItemChanged(it.getPosition())
}
}
}
}
}
private fun loadData() {
taskCpdHistoryPresenter.getCpdUseAppModelMsg()
}
override fun getCpdUseAppModelMsgSuc(taskCpdBean: TaskCpdBean) {
mFakeTaskList.clear()
needUseTime = taskCpdBean.needSeconds
for (bean in taskCpdBean.list) {
val tzTaskBean = TzTaskBean(bean.icon, bean.name, "", false, bean.coin, 1, bean.pkg)
tzTaskBean.aid = bean.aid
mFakeTaskList.add(tzTaskBean)
}
notifyDataAndShowAd()
}
override fun getCpdUseAppModelMsgFail() {
notifyDataAndShowAd()
}
private fun notifyDataAndShowAd() {
hideLoading()
srl_task.finishRefresh()
mTaskAdapter?.notifyDataSetChanged()
if (mFakeTaskList.size == 0) {
iv_empty.visibility = View.VISIBLE
return
} else {
iv_empty.visibility = View.GONE
}
}
}
\ No newline at end of file
......@@ -21,6 +21,18 @@ import com.mints.goodmoney.MintsApplication
*/
object AppUtil {
fun getAppName(pkgName: String, context: Context): String {
var info: PackageInfo? = null
val pm: PackageManager = context.packageManager
try {
info = pm.getPackageInfo(pkgName, PackageManager.GET_ACTIVITIES)
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
return info?.applicationInfo?.loadLabel(pm).toString()
}
/**
* 是否有应用使用情况权限
* @return flag
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/white"
android:orientation="vertical">
......@@ -12,22 +12,21 @@
android:id="@+id/xtTaskCpd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:xTabIndicatorColor="#F28335"
app:xTabIndicatorHeight="4dp"
app:xTabIndicatorRoundX="30dp"
app:xTabIndicatorRoundY="30dp"
android:visibility="gone"
app:xTabIndicatorWidth="20dp"
app:xTabMode="scrollable"
app:xTabSelectedTextColor="@color/color_FF9837"
app:xTabSelectedTextSize="18sp"
app:xTabTextColor="#000"
app:xTabTextSize="14sp" />
app:xTabTextSize="16sp" />
<com.mints.goodmoney.ui.widgets.MyViewPager
android:id="@+id/vpTaskCpd"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/shape_dialog_bg"
android:paddingTop="6dp"
android:paddingBottom="6dp">
<ImageView
android:id="@+id/item_iv_avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:src="@mipmap/ic_launcher_main" />
<TextView
android:id="@+id/item_tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/item_iv_avatar"
android:layout_marginTop="3dp"
android:layout_toEndOf="@id/item_iv_avatar"
android:maxLength="7"
android:lines="1"
android:ellipsize="end"/>
<TextView
android:id="@+id/item_tv_coin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/item_iv_avatar"
android:layout_marginStart="5dp"
android:layout_marginTop="3dp"
android:layout_toEndOf="@id/item_tv_title"
android:drawablePadding="2dp"
android:text="+300金币"
android:textColor="@color/color_FF9837"
android:textSize="16sp"
app:drawableStartCompat="@mipmap/ic_draw_gold" />
<TextView
android:id="@+id/item_tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/item_iv_avatar"
android:layout_marginBottom="3dp"
android:layout_toEndOf="@id/item_iv_avatar"
android:text="打开应用体验3秒,返回领取"
android:textColor="@color/color_ccc"
android:textSize="12sp" />
<Button
android:id="@+id/item_btn_submit"
android:layout_width="80dp"
android:layout_height="32dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:background="@drawable/shape_btn_switch"
android:textColor="@color/white" />
</RelativeLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment