Przeglądaj źródła

会长推广弹出框添加下载进度回调;
进入首页前通过接口检查是否可以弹出会长推广页面;
会长推广弹出框取消后,或者接下来的抢任务弹出框取消后,尝试显示弹窗广告

zengjiebin 7 lat temu
rodzic
commit
c365873559

+ 6 - 1
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -92,7 +92,12 @@ public interface ApiService {
      * 会长推广显示游戏、现金任务、礼包
      */
     @GET("app/find/commend_app")
-    Observable<BaseMessage> getGameOrTaskOrGift(@Query("game_id") String game_id, @Query("order") int order);
+    Observable<BaseMessage> getCommendApp(@Query("game_id") String game_id, @Query("order") int order);
+    /**
+     * 查询用户是否可以弹窗推荐应用
+     */
+    @GET("app/find/can/commend_app")
+    Observable<BaseMessage> canGetCommendApp(@Query("game_id") String game_id);
     /**
      * @return ,
      * 主页抢任务

+ 11 - 1
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -2062,6 +2062,13 @@ public class CommonUtil {
      * 下载回调 状态修改
      */
     public void setEventResultViewStatus(BigEvent event, View view) {
+        setEventResultViewStatus(event, view, true);
+    }
+
+    /**
+     * 下载回调 状态修改
+     */
+    public void setEventResultViewStatus(BigEvent event, View view, boolean isShowSpeed) {
         if (event.getData() instanceof DownloadTask) {
             DownloadTask task = (DownloadTask) event.getData();
             String url = task.getKey();
@@ -2074,7 +2081,10 @@ public class CommonUtil {
                         if (tvProgress == null) {
                             return;
                         }
-                        tvProgress.setText(String.format(Locale.CHINA, "%d%%(%s)", Math.abs(p), speed));//添加下载速度
+                        if(isShowSpeed)
+                            tvProgress.setText(String.format(Locale.CHINA, "%d%%(%s)", Math.abs(p), speed));//添加下载速度
+                        else
+                            tvProgress.setText(String.format(Locale.CHINA, "%d%%", Math.abs(p)));
 
                     } catch (Exception e) {
                         e.printStackTrace();

+ 43 - 11
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -9,7 +9,6 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.text.TextUtils;
-import android.util.Log;
 import android.view.Gravity;
 import android.view.View;
 
@@ -18,6 +17,7 @@ import com.sheep.gamegroup.model.entity.Advertising;
 import com.sheep.gamegroup.model.entity.Agreement;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.CheckUserLabel;
+import com.sheep.gamegroup.model.entity.CommendApp;
 import com.sheep.gamegroup.model.entity.Container;
 import com.sheep.gamegroup.model.entity.CreditCard;
 import com.sheep.gamegroup.model.entity.DialogConfig;
@@ -120,7 +120,6 @@ import com.sheep.jiuyan.samllsheep.service.ListenerShotService;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 
-import org.afinal.simplecache.ApiKey;
 import org.xutils.ex.DbException;
 
 import java.io.File;
@@ -257,19 +256,52 @@ public class Jump2View {
 
 
     /**
+     * 跳到首页面前检查是否展示会长推广弹出框
+     *
+     * @param context
+     * @param object
+     */
+    public void checkCommendApp(final Context context, final Object object) {
+        if (DataUtil.getAsBoolean(ActMain.FIRST_SHOW_MAIN, true)) {
+            String game_id = ChannelContent.getInstance().getGameId();
+            SheepApp.getInstance().getNetComponent().getApiService().canGetCommendApp(game_id)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            CommendApp result = baseMessage.getData(CommendApp.class);
+                            if(!result.getNeed()){//不需要展示
+                                DataUtil.putAsBoolean(ActMain.FIRST_SHOW_MAIN, false);
+                            }
+                            goHomePageView(context, object);
+                        }
+
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            //默认不展示
+                            DataUtil.putAsBoolean(ActMain.FIRST_SHOW_MAIN, false);
+                            goHomePageView(context, object);
+                        }
+                    });
+            return;
+        }
+        goHomePageView(context, object);
+    }
+    /**
      * 跳到首页面
      *
      * @param context
-     * @param o
+     * @param object
      */
-    public void goHomePageView(final Context context, Object o) {
+    public void goHomePageView(final Context context, Object object) {
         final Intent intent = new Intent(context, ActMain.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        if (o instanceof String) {
+        if (object instanceof String) {
             //统计用户登录信息
             UMConfigUtils.onProfileSignIn();
             //从登录界面过来//新注册用户才添加到数据库,并设置可以显示
             NewbieTaskRecord newbie_task_record = new NewbieTaskRecord();
-            newbie_task_record.setUser_id((String) o);
+            newbie_task_record.setUser_id((String) object);
             newbie_task_record.setDontShowNewbieTaskDialog(false);
             MyDbManager.getInstance().saveOrUpdate(newbie_task_record);
             checkOrGoHomePage((Activity) context);
@@ -332,7 +364,7 @@ public class Jump2View {
                 checkLabel(activity, new Action1<BaseMessage>() {
                     @Override
                     public void call(BaseMessage baseMessage) {
-                        goHomePageView(activity, null);
+                        checkCommendApp(activity, null);
                         activity.finish();
                     }
                 });
@@ -857,8 +889,8 @@ public class Jump2View {
             G.showToast(R.string.service_data_error);
             return;
         }
-        //检查url是否是http或者https开头并添加
-        if (!url.startsWith("http") && !url.startsWith("https") && !url.contains("://")) {
+        //检查url是否是http开头并添加
+        if (!url.startsWith("http") && !url.contains("://")) {
             url = "http://" + url;
         }
         try {
@@ -882,8 +914,8 @@ public class Jump2View {
             G.showToast(R.string.service_data_error);
             return;
         }
-        //检查url是否是http或者https开头并添加
-        if (!url.startsWith("http") && !url.startsWith("https") && !url.contains("://")) {
+        //检查url是否是http开头并添加
+        if (!url.startsWith("http") && !url.contains("://")) {
             url = "http://" + url;
         }
         Intent intent = new Intent(context, ActWeb.class);

+ 8 - 0
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -3,6 +3,7 @@ package com.sheep.gamegroup.util;
 import android.app.Activity;
 import android.app.Dialog;
 import android.content.ComponentName;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
@@ -608,6 +609,13 @@ public class SysAppUtil {
                 });
             }
             dialog = ViewUtil.showMsgDialog(activity, dialogConfig);
+            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
+                @Override
+                public void onDismiss(DialogInterface dialogInterface) {
+                    if (action1 != null)
+                        action1.call(0);
+                }
+            });
         }
     }
 

+ 10 - 0
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -64,6 +64,7 @@ import com.sheep.gamegroup.model.entity.PayEntity;
 import com.sheep.gamegroup.model.entity.RobTask;
 import com.sheep.gamegroup.model.entity.TaskEty;
 import com.sheep.gamegroup.util.glide.RoundedCornersTransformation;
+import com.sheep.gamegroup.view.activity.ActMain;
 import com.sheep.gamegroup.view.activity.PersonalInfoAct;
 import com.sheep.gamegroup.view.activity.SplashAct;
 import com.sheep.gamegroup.view.activity.TaskDetailAct;
@@ -318,6 +319,15 @@ public class ViewUtil {
                 mAlertDialog.dismiss();
             }
         });
+        mAlertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
+            @Override
+            public void onDismiss(DialogInterface dialogInterface) {
+                if (mActivity instanceof ActMain && DataUtil.getAsBoolean("tryShowHalfScreenAd", false)) {
+                    DataUtil.putAsBoolean("tryShowHalfScreenAd", false);
+                    Jump2View.getInstance().tryShowHalfScreenAd(mActivity, ((ActMain) mActivity).getContainer());
+                }
+            }
+        });
         try {
             mAlertDialog.show();
         } catch (Exception e) {

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/ActBindMobileRegister.java

@@ -192,7 +192,7 @@ public class ActBindMobileRegister extends BaseActivity {
                             DataUtil.getInstance().initUserEntity(loginEty.getUser());
                         }
                         if(TextUtils.isEmpty(SheepApp.getInstance().getGameCode())){
-                            Jump2View.getInstance().goHomePageView(activity, EntityUtils.getUserCode(loginEty));
+                            Jump2View.getInstance().checkCommendApp(activity, EntityUtils.getUserCode(loginEty));
                         }else {
                             CertificationUtil.newInstance().authCerticicationCode(activity);
                         }

+ 16 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/ActMain.java

@@ -42,7 +42,6 @@ import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -319,7 +318,11 @@ public class ActMain extends BaseActivity {
         super.onResume();
         if (container != null && container.getT() != null)
             container.getT().call(1);
-        if(!checkNextAction(MiddleSchemeAct.SHOW_DIALOG_GAME_OR_GIFT_TASK)){
+        if(checkNextAction(MiddleSchemeAct.SHOW_DIALOG_GAME_OR_GIFT_TASK)) {
+            if(onResumeCount == 0) {
+                DataUtil.putAsBoolean("tryShowHalfScreenAd", true);
+            }
+        } else {
             if(onResumeCount == 0) {
                 SysAppUtil.showVersionInfo(this, SpUtils.getIgnoreMd5(), new Action1<Integer>() {
                     @Override
@@ -352,6 +355,13 @@ public class ActMain extends BaseActivity {
             container.getT().call(2);
     }
 
+    //包含更新进度的view的view(会长推广弹出框中有下载进度用到)
+    private View progressView;
+
+    public void setProgressView(View progressView) {
+        this.progressView = progressView;
+    }
+
     /**
      * 主要的事件广播接收更新处理
      *
@@ -363,6 +373,10 @@ public class ActMain extends BaseActivity {
             case STORAGE_LOW:
                 DialogStorageLow.showDialog(this);
                 break;
+            default:
+                if(progressView != null)
+                    CommonUtil.getInstance().setEventResultViewStatus(event, progressView, false);
+                break;
         }
     }
 

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/ActUserLabelList.java

@@ -158,7 +158,7 @@ public class ActUserLabelList extends BaseActivity {
                         .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                             @Override
                             public void onNext(BaseMessage baseMessage) {
-                                Jump2View.getInstance().goHomePageView(ActUserLabelList.this, null);
+                                Jump2View.getInstance().checkCommendApp(ActUserLabelList.this, null);
                                 finish();
                             }
 
@@ -166,7 +166,7 @@ public class ActUserLabelList extends BaseActivity {
                             public void onError(BaseMessage baseMessage) {
                                 G.showToast(baseMessage);
                                 if(BuildConfig.DEBUG){
-                                    Jump2View.getInstance().goHomePageView(ActUserLabelList.this, null);
+                                    Jump2View.getInstance().checkCommendApp(ActUserLabelList.this, null);
                                     finish();
                                 }
                             }

+ 3 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/LoginAct.java

@@ -259,7 +259,7 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
     public void NetSuccess(int code, String msg, String invitation_code) {
         hideProgress();
         if(TextUtils.isEmpty(SheepApp.getInstance().getGameCode())){
-            Jump2View.getInstance().goHomePageView(this, invitation_code);
+            Jump2View.getInstance().checkCommendApp(this, invitation_code);
         }else {
             CertificationUtil.newInstance().authCerticicationCode(activity);
         }
@@ -314,7 +314,7 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
     }
     private void goMain(String openId) {
         SpUtils.saveToken(getApplicationContext(), openId);
-        Jump2View.getInstance().goHomePageView(this, null);
+        Jump2View.getInstance().checkCommendApp(this, null);
         ActivityManager.getInstance().endActivity(LoginAct.class);
         finish();
     }
@@ -364,7 +364,7 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
                         }
 
                         if(TextUtils.isEmpty(SheepApp.getInstance().getGameCode())){
-                            Jump2View.getInstance().goHomePageView(activity, EntityUtils.getUserCode(loginEty));
+                            Jump2View.getInstance().checkCommendApp(activity, EntityUtils.getUserCode(loginEty));
                         }else {
                             CertificationUtil.newInstance().authCerticicationCode(activity);
                         }

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/MiddleAct.java

@@ -153,7 +153,7 @@ public class MiddleAct extends Activity {
 
             case 1://跳转到首页: id 0,小绵羊 1,游戏
                 if (msg.getId() == 0)
-                    Jump2View.getInstance().goHomePageView(activity, msg.getId() % MainTab.values().length);
+                    Jump2View.getInstance().checkCommendApp(activity, msg.getId() % MainTab.values().length);
                 else if (msg.getId() == 1)
                     Jump2View.getInstance().goMainGame(activity);
                 break;

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/SplashAct.java

@@ -200,7 +200,7 @@ public class SplashAct extends BaseActivity implements EasyPermissions.Permissio
         activity = this;
         GlideImageLoader.setImage(login_bg_img, "http://cdngame.kuaifazs.com/login_bg_img.png");
 //        if(BuildConfig.DEBUG){
-//            Jump2View.getInstance().goHomePageView(activity, null);
+//            Jump2View.getInstance().checkCommendApp(activity, null);
 //        } else {
 //            mHandler.sendEmptyMessageDelayed(1, 500);
 //        }

+ 41 - 12
app/src/main/java/com/sheep/gamegroup/view/dialog/DialogGameOrTaskOrGift.java

@@ -1,6 +1,7 @@
 package com.sheep.gamegroup.view.dialog;
 
 import android.app.Activity;
+import android.content.DialogInterface;
 import android.support.v7.app.AlertDialog;
 import android.text.TextUtils;
 import android.view.View;
@@ -8,6 +9,7 @@ import android.widget.ImageView;
 import android.widget.TextView;
 
 import com.kfzs.duanduan.utils.NumberFormatUtils;
+import com.sheep.gamegroup.helper.DownloadHelper;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.CashAwarsEntity;
 import com.sheep.gamegroup.model.entity.CommendApp;
@@ -21,6 +23,7 @@ import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.StringUtils;
 import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.view.activity.ActMain;
 import com.sheep.gamegroup.view.adapter.GiftCenterAdapter;
 import com.sheep.gamegroup.view.adapter.WelfareAdapter;
 import com.sheep.jiuyan.samllsheep.BuildConfig;
@@ -36,6 +39,7 @@ import rx.functions.Action1;
 import rx.schedulers.Schedulers;
 
 import static com.sheep.gamegroup.util.UMConfigUtils.Event.GIFT_BAG_COPY_CODE;
+import static com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST;
 
 
 public class DialogGameOrTaskOrGift {
@@ -74,6 +78,7 @@ public class DialogGameOrTaskOrGift {
         ViewUtil.setVisibility2(dialog_gift_info_tv, false);
         dialog_btn_left.setText("换一个");
         dialog_btn_right.setText("立即下载");
+        dialog_btn_right.setTag("null");
     }
 
     private void loadData() {
@@ -99,6 +104,7 @@ public class DialogGameOrTaskOrGift {
                 ViewUtil.setText(dialog_gift_tv, giftBag.getGiftName());
                 ViewUtil.setText(dialog_gift_code_tv, giftBagApp.getCode());
                 ViewUtil.setText(dialog_gift_info_tv, giftBag.getUseMethod());
+                dialog_btn_right.setTag("null");
                 if (giftBagApp.isReceived()) {//已经领取礼包
                     ViewUtil.setText(dialog_btn_right, "复制礼包码");
                     dialog_btn_right.setOnClickListener(new View.OnClickListener() {
@@ -159,24 +165,16 @@ public class DialogGameOrTaskOrGift {
                 GlideImageLoader.setGameImage(dialog_iv, commendApp.getApp().getIcon());
                 ViewUtil.setText(dialog_name_tv, commendApp.getApp().getName());
                 ViewUtil.setText(dialog_gift_tv, commendApp.getApp().getManufacturer());//这里显示的是开发商名字
-                ViewUtil.setText(dialog_btn_right, "立即下载");
-                dialog_btn_right.setOnClickListener(new View.OnClickListener() {
-                    @Override
-                    public void onClick(View view) {
-                        ViewUtil.setText(dialog_btn_right, "正在下载");
-                        DownloadService.sysDownload(activity, commendApp.getApp().getDownload_url(), commendApp.getApp().getName());
-                    }
-                });
+                commendApp.getApp().getFindAppHelper().getDownloadHelper().updateDownloadTaskView(activity, commendApp.getApp(), dialog_btn_right);
+                dialog_btn_right.setTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + commendApp.getApp().getDownload_url());
             } else {
                 if (BuildConfig.DEBUG)
                     G.showToast("不是礼包,不是现金任务,不是游戏,还可能是什么");
             }
         }
-
     }
 
     private void bindViews(View view) {
-
         dialog_iv = (ImageView) view.findViewById(R.id.dialog_iv);
         dialog_name_tv = (TextView) view.findViewById(R.id.dialog_name_tv);
         dialog_iv_2 = (ImageView) view.findViewById(R.id.dialog_iv_2);
@@ -190,6 +188,9 @@ public class DialogGameOrTaskOrGift {
         dialog_btn_left = (TextView) view.findViewById(R.id.dialog_btn_left);
         dialog_btn_center = view.findViewById(R.id.dialog_btn_center);
         dialog_btn_right = (TextView) view.findViewById(R.id.dialog_btn_right);
+        if(activity instanceof ActMain){
+            ((ActMain) activity).setProgressView(view);
+        }
     }
 
     private AlertDialog mAlertDialog;
@@ -203,11 +204,25 @@ public class DialogGameOrTaskOrGift {
             @Override
             public void onClick(View v) {
                 mAlertDialog.dismiss();
+                onCancelOrClickClose();
             }
         };
 
         bindViews(view);
-
+        mAlertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
+            @Override
+            public void onDismiss(DialogInterface dialogInterface) {
+                if(activity instanceof ActMain){
+                    ((ActMain) activity).setProgressView(null);
+                }
+            }
+        });
+        mAlertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+            @Override
+            public void onCancel(DialogInterface dialogInterface) {
+                onCancelOrClickClose();
+            }
+        });
         final View dialog_close = view.findViewById(R.id.dialog_close);
         dialog_close.setOnClickListener(onClickListener);
         try {
@@ -220,6 +235,15 @@ public class DialogGameOrTaskOrGift {
         return mAlertDialog;
     }
 
+    private void onCancelOrClickClose() {
+        if(activity instanceof ActMain) {
+            if (DataUtil.getAsBoolean("tryShowHalfScreenAd", false)) {
+                DataUtil.putAsBoolean("tryShowHalfScreenAd", false);
+                Jump2View.getInstance().tryShowHalfScreenAd(activity, ((ActMain) activity).getContainer());
+            }
+        }
+    }
+
     private CommendApp commendApp;
     public static final int FIRST_ORDER = 1;//第一次调用会长推广游戏的接口时,传入的order的默认值
 
@@ -229,7 +253,7 @@ public class DialogGameOrTaskOrGift {
         } else if(commendApp != null && commendApp.hasNextShow()){
             loadData();
         } else {
-            SheepApp.getInstance().getNetComponent().getApiService().getGameOrTaskOrGift(gameId, commendApp == null ? FIRST_ORDER : commendApp.getOrder())
+            SheepApp.getInstance().getNetComponent().getApiService().getCommendApp(gameId, commendApp == null ? FIRST_ORDER : commendApp.getOrder())
                     .subscribeOn(Schedulers.io())
                     .observeOn(AndroidSchedulers.mainThread())
                     .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
@@ -247,6 +271,7 @@ public class DialogGameOrTaskOrGift {
                         @Override
                         public void onError(BaseMessage baseMessage) {
                             if(commendApp == null){//没有获取到过commendApp的情况下,直接弹出抢任务弹出框
+                                mAlertDialog.dismiss();
                                 showTaskDialog();
                             } else {
                                 showChange();
@@ -289,6 +314,10 @@ public class DialogGameOrTaskOrGift {
                     ViewUtil.newInstance().showRobDutyDialog(activity, robTask);
                 } else {
                     G.showToast("任务已被抢光!请实时关注任务发布!");
+                    if (activity instanceof ActMain && DataUtil.getAsBoolean("tryShowHalfScreenAd", false)) {
+                        DataUtil.putAsBoolean("tryShowHalfScreenAd", false);
+                        Jump2View.getInstance().tryShowHalfScreenAd(activity, ((ActMain) activity).getContainer());
+                    }
                 }
             }
         });