Просмотр исходного кода

支持h5跳转和解析zip注释的方式来展示会长推广弹窗

zengjiebin лет назад: 7
Родитель
Сommit
e093cc1f49

+ 12 - 6
app/src/main/java/com/sheep/gamegroup/absBase/BaseActivity.java

@@ -4,7 +4,7 @@ import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 
-import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.gamegroup.util.ActionUtil;
 import com.sheep.gamegroup.view.dialog.DialogLoading;
 
 import java.util.concurrent.TimeUnit;
@@ -65,7 +65,11 @@ public abstract class BaseActivity extends AppCompatActivity {
     @Override
     protected void onResume() {
         super.onResume();
-        final Object action = DataUtil.getInstance().getAction(getClass().getSimpleName());
+        checkNextAction(this.getClass().getSimpleName());
+    }
+
+    protected boolean checkNextAction(String key) {
+        final Object action = ActionUtil.getInstance().getAction(key);
         if (action != null) {
             //延时一会儿,不然有可能操作会无效
             Observable.just(1).delay(50L, TimeUnit.MILLISECONDS)
@@ -77,7 +81,13 @@ public abstract class BaseActivity extends AppCompatActivity {
                             doNextAction(action);
                         }
                     });
+            return true;
         }
+        return false;
+    }
+
+    public void doNextAction(Object action) {
+
     }
 
     protected abstract int getLayoutId();
@@ -92,10 +102,6 @@ public abstract class BaseActivity extends AppCompatActivity {
 
     }
 
-    public void doNextAction(Object action) {
-
-    }
-
     @Override
     protected void onDestroy() {
         try {

+ 43 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/CommendApp.java

@@ -1,7 +1,12 @@
 package com.sheep.gamegroup.model.entity;
 
+import android.support.annotation.IntDef;
+import android.support.annotation.StringDef;
+
 import com.sheep.gamegroup.util.ListUtil;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.List;
 
 /**
@@ -102,4 +107,42 @@ public class CommendApp {
     public boolean isGame() {
         return app != null && app.getId() > 0;
     }
+
+    //可以切换到抢任务弹出框
+    public boolean needChange() {
+        return need && !hasNextShow();
+    }
+    public static final int SHOW_NONE = 0;//初始状态
+    public static final int SHOW_GAME = 1;//显示游戏
+    public static final int SHOW_GIFT = 2;//显示礼包
+    public static final int SHOW_TASK = 3;//显示现金任务
+    private int curShow = SHOW_NONE;
+    //还有展示的形式(游戏,礼包,现金任务)
+    public boolean hasNextShow() {
+        return curShow < SHOW_TASK && checkNextShow(curShow + 1) != SHOW_NONE;
+    }
+    //检查是否有下一种展示方式
+    private int checkNextShow(int nextShow) {
+        switch (nextShow){
+            case SHOW_GAME:
+                return isGame() ? nextShow : checkNextShow(nextShow + 1);
+            case SHOW_GIFT:
+                return isGift() ? nextShow : checkNextShow(nextShow + 1);
+            case SHOW_TASK:
+                return isXianJinTask() ? nextShow : SHOW_NONE;//现金任务后没有可切换的展示形式
+        }
+        return SHOW_NONE;
+    }
+    //切换到下一个状态
+    public void changNextShow() {
+        curShow = checkNextShow(curShow + 1);
+    }
+
+    @IntDef({SHOW_GAME, SHOW_GIFT, SHOW_TASK})
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface SHOW_TYPE {
+    }
+    public boolean isShow(@SHOW_TYPE int show) {
+        return curShow == show;
+    }
 }

+ 33 - 0
app/src/main/java/com/sheep/gamegroup/util/ActionUtil.java

@@ -0,0 +1,33 @@
+package com.sheep.gamegroup.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by realicing on 2018/10/16.
+ * realicing@sina.com
+ */
+public class ActionUtil {
+    private static ActionUtil instance = new ActionUtil();
+    private ActionUtil(){
+
+    }
+
+    public static ActionUtil getInstance() {
+        return instance;
+    }
+
+    //-----------------------------------------下一动作部分-----------------------------------------------------结束
+    private Map<String, Object> nextActionMap = new HashMap<>();
+    public void addNextAction(String key, Object item) {
+        nextActionMap.put(key, item);
+    }
+
+    public Object getAction(String key) {
+        Object action = nextActionMap.get(key);
+        if(action != null)
+            nextActionMap.remove(key);
+        return action;
+    }
+    //-----------------------------------------下一动作部分-----------------------------------------------------结束
+}

+ 16 - 2
app/src/main/java/com/sheep/gamegroup/util/ChannelContent.java

@@ -42,6 +42,7 @@ public class ChannelContent {
     private static final String META_INF_FILE_START = "META-INF/pl_channel_";
     private static final String CHANNEL_FILE_MARK = "pl_channel_";
     private String channel_name="";
+    private String gameId;
     private static ChannelContent instance;
     private Properties properties;
     private boolean hasChannelFile = false;
@@ -102,8 +103,17 @@ public class ChannelContent {
             try {
                 PackageInfo packageInfo = ApkUtils.getPackageInfo(SheepApp.getInstance().getPackageName());
                 if(packageInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)) {
-                    channel_name = ZipChannelUtil.readQUA(new File(packageInfo.applicationInfo.sourceDir));
-                    hasChannelFile = !TextUtils.isEmpty(channel_name);
+                    String comment = ZipChannelUtil.readQUA(new File(packageInfo.applicationInfo.sourceDir));
+                    if(!TextUtils.isEmpty(comment)){
+                        hasChannelFile = true;
+                        if(comment.contains(";")){
+                            String[] items = comment.split(";");
+                            channel_name = items[0];
+                            gameId = items[1];
+                        } else {
+                            channel_name = comment;
+                        }
+                    }
                 }
             } catch (IOException e) {
                 e.printStackTrace();
@@ -126,4 +136,8 @@ public class ChannelContent {
         }
         return hashMap;
     }
+
+    public String getGameId() {
+        return gameId;
+    }
 }

+ 0 - 13
app/src/main/java/com/sheep/gamegroup/util/DataUtil.java

@@ -514,17 +514,4 @@ public class DataUtil {
 
 
     //-----------------------------------------数据转换部分-----------------------------------------------------结束
-    //-----------------------------------------下一动作部分-----------------------------------------------------结束
-    private Map<String, Object> nextActionMap = new HashMap<>();
-    public void addNextAction(String key, Object item) {
-        nextActionMap.put(key, item);
-    }
-
-    public Object getAction(String key) {
-        Object action = nextActionMap.get(key);
-        if(action != null)
-            nextActionMap.remove(key);
-        return action;
-    }
-    //-----------------------------------------下一动作部分-----------------------------------------------------结束
 }

+ 50 - 5
app/src/main/java/com/sheep/gamegroup/view/activity/ActMain.java

@@ -6,6 +6,7 @@ import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v4.view.ViewPager;
+import android.text.TextUtils;
 import android.view.View;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
@@ -17,20 +18,25 @@ import com.kfzs.duanduan.view.DialogStorageLow;
 import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.event.BigEvent;
 import com.sheep.gamegroup.model.entity.Container;
-import com.sheep.gamegroup.model.entity.SystemNotification;
+import com.sheep.gamegroup.util.ActionUtil;
+import com.sheep.gamegroup.util.ChannelContent;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.DrawablesHelper;
+import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.MainTab;
+import com.sheep.gamegroup.util.SysAppUtil;
+import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.gamegroup.view.adapter.ViewPagerFragmentAdapter;
+import com.sheep.gamegroup.view.dialog.DialogGameOrTaskOrGift;
 import com.sheep.gamegroup.view.fragment.FgtFind;
-import com.sheep.gamegroup.view.fragment.FgtMainAudit;
 import com.sheep.gamegroup.view.fragment.FgtSmallSheep;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
@@ -55,8 +61,18 @@ public class ActMain extends BaseActivity {
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         StatusBarUtils.setTranslucent(this);
         super.onCreate(savedInstanceState);
+        //第一次进入主页检查是否是会长推广的游戏,并显示弹出框
+        if (DataUtil.getAsBoolean(FIRST_SHOW_MAIN, true)) {
+            DataUtil.putAsBoolean(FIRST_SHOW_MAIN, false);
+            String game_id = ChannelContent.getInstance().getGameId();
+            if (game_id != null) {
+                ActionUtil.getInstance().addNextAction(MiddleSchemeAct.SHOW_DIALOG_GAME_OR_GIFT_TASK, game_id);
+            }
+        }
     }
 
+    public static final String FIRST_SHOW_MAIN = "first_show_main";//是否是第一次显示主页
+
     @BindView(R.id.view_pager_container)
     ViewPager view_pager_container;
     @BindView(R.id.frame_container)
@@ -77,7 +93,7 @@ public class ActMain extends BaseActivity {
         initViewPager();
         initFind();
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-            main_layout.setPadding(0, 0, 0, G.getHasVirtualKey(this) -G.getNoHasVirtualKey(this) );
+            main_layout.setPadding(0, 0, 0, G.getHasVirtualKey(this) - G.getNoHasVirtualKey(this));
 
         }
 
@@ -152,8 +168,8 @@ public class ActMain extends BaseActivity {
                     lastTab.setActivated(false);
                 if (curTab != null)
                     curTab.setActivated(true);
-                if(lastPosition == MainTab.FgtSmallSheep.ordinal() && position != MainTab.FgtSmallSheep.ordinal()){
-                    ((FgtSmallSheep)MainTab.FgtSmallSheep.getFragment()).onPause();
+                if (lastPosition == MainTab.FgtSmallSheep.ordinal() && position != MainTab.FgtSmallSheep.ordinal()) {
+                    ((FgtSmallSheep) MainTab.FgtSmallSheep.getFragment()).onPause();
                 }
                 showFind(position == MainTab.Fgt_Find.ordinal());
                 //更新position
@@ -196,7 +212,9 @@ public class ActMain extends BaseActivity {
             view_pager_container.bringToFront();
         }
     }
+
     private Fragment fgtFind;
+
     public void initFind() {
         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
         Bundle bundle = new Bundle();
@@ -265,11 +283,36 @@ public class ActMain extends BaseActivity {
         return container;
     }
 
+    private int onResumeCount = 0;//调用onResume次数
     @Override
     protected void onResume() {
         super.onResume();
         if (container != null && container.getT() != null)
             container.getT().call(1);
+        if(!checkNextAction(MiddleSchemeAct.SHOW_DIALOG_GAME_OR_GIFT_TASK)){
+            if(onResumeCount == 0) {
+                SysAppUtil.showVersionInfo(this, SpUtils.getIgnoreMd5(), new Action1<Integer>() {
+                    @Override
+                    public void call(Integer integer) {
+                        Jump2View.getInstance().tryShowHalfScreenAd(ActMain.this, getContainer());
+                    }
+                });
+            }
+        }
+        onResumeCount ++;
+    }
+
+    @Override
+    public void doNextAction(Object action) {
+        if (action instanceof String) {
+            String game_id = action.toString();
+            if (TextUtils.isEmpty(game_id)) {
+                if (TestUtil.isTest())
+                    G.showToast("game_id为空");
+            } else {
+                new DialogGameOrTaskOrGift(this, game_id).showDialog();
+            }
+        }
     }
 
     @Override
@@ -278,6 +321,7 @@ public class ActMain extends BaseActivity {
         if (container != null && container.getT() != null)
             container.getT().call(2);
     }
+
     /**
      * 主要的事件广播接收更新处理
      *
@@ -291,6 +335,7 @@ public class ActMain extends BaseActivity {
                 break;
         }
     }
+
     @Override
     protected void onDestroy() {
         super.onDestroy();

+ 17 - 6
app/src/main/java/com/sheep/gamegroup/view/activity/MiddleSchemeAct.java

@@ -6,6 +6,9 @@ import android.net.Uri;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 
+import com.sheep.gamegroup.util.ActionUtil;
+import com.sheep.gamegroup.util.Jump2View;
+import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
@@ -17,7 +20,7 @@ public class MiddleSchemeAct extends Activity {
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setContentView(R.layout.find_item_bottom);
+        setContentView(R.layout.splash_activity);
         checkScheme(getIntent());
     }
 
@@ -29,15 +32,17 @@ public class MiddleSchemeAct extends Activity {
 
     private void checkScheme(Intent intent) {
         String action;
-        if(intent == null || (action = intent.getAction()) == null)
+        if (intent == null || (action = intent.getAction()) == null)
             return;
-        switch (action){
+        switch (action) {
             case Intent.ACTION_VIEW:
                 Uri uri = intent.getData();
-                if(uri != null){
+                String game_id = "";
+                if (uri != null) {
                     // 完整的url信息
-                    String url = uri.toString();
-                    G.showToast(url);
+                    if (TestUtil.isTest())
+                        G.showToast(uri.toString());
+                    game_id = uri.getQueryParameter("game_id");
 //                    LogUtil.println("ActMain", "checkScheme","url: " + url);
 //                    // scheme部分
 //                    String scheme = uri.getScheme();
@@ -74,7 +79,13 @@ public class MiddleSchemeAct extends Activity {
                      * ActMain checkScheme code: 976873
                      */
                 }
+                ActionUtil.getInstance().addNextAction(SHOW_DIALOG_GAME_OR_GIFT_TASK, game_id);
+                Jump2View.getInstance().newTaskTopStartAct(this, SplashAct.class, null);
+                finish();
                 break;
         }
     }
+
+    //展示会长推广弹出框的key
+    public static final String SHOW_DIALOG_GAME_OR_GIFT_TASK = "show_dialog_game_or_gift_task";
 }

+ 27 - 23
app/src/main/java/com/sheep/gamegroup/view/dialog/DialogGameOrTaskOrGift.java

@@ -77,13 +77,14 @@ public class DialogGameOrTaskOrGift {
         if (commendApp == null) {
             resetView();
         } else {
+            commendApp.changNextShow();
             dialog_btn_left.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
                     initData();
                 }
             });
-            if (commendApp.isGift()) {
+            if (commendApp.isShow(CommendApp.SHOW_GIFT)) {
                 final GiftBagApp giftBagApp = commendApp.getHas_gift_bag().get(0);
                 final GiftBag giftBag = giftBagApp.getGift_bag();
                 ViewUtil.setVisibility(dialog_amount_tv, false);
@@ -130,13 +131,13 @@ public class DialogGameOrTaskOrGift {
                         }
                     });
                 }
-            } else if (commendApp.isXianJinTask()) {
+            } else if (commendApp.isShow(CommendApp.SHOW_TASK)) {
                 ViewUtil.setVisibility(dialog_amount_tv, true);
                 ViewUtil.setVisibility2(dialog_gift_code_tv, false);
                 ViewUtil.setVisibility2(dialog_gift_info_tv, false);
                 GlideImageLoader.setGameImage(dialog_iv, commendApp.getRelease_task().getTask().getIcon());
                 ViewUtil.setText(dialog_name_tv, commendApp.getRelease_task().getName());
-                ViewUtil.setText(dialog_amount_tv, commendApp.getRelease_task().getBonusText() + "元");
+                ViewUtil.setText(dialog_amount_tv, activity.getString(R.string.plus_x_yuan, commendApp.getRelease_task().getBonusText()));
                 ViewUtil.setText(dialog_gift_tv, "现金");
                 ViewUtil.setText(dialog_btn_right, "立即赚钱");
                 dialog_btn_right.setOnClickListener(new View.OnClickListener() {
@@ -145,7 +146,7 @@ public class DialogGameOrTaskOrGift {
                         Jump2View.getInstance().goTaskDetailView(activity, commendApp.getRelease_task().getId());
                     }
                 });
-            } else if (commendApp.isGame()) {
+            } else if (commendApp.isShow(CommendApp.SHOW_GAME)) {
                 ViewUtil.setVisibility(dialog_amount_tv, false);
                 ViewUtil.setVisibility2(dialog_gift_code_tv, false);
                 ViewUtil.setVisibility2(dialog_gift_info_tv, false);
@@ -213,25 +214,9 @@ public class DialogGameOrTaskOrGift {
 
     private CommendApp commendApp;
     public static final int FIRST_ORDER = 1;//第一次调用会长推广游戏的接口时,传入的order的默认值
-    private void initData() {
-        if (commendApp == null || commendApp.getNeed()) {
-            SheepApp.getInstance().getNetComponent().getApiService().getGameOrTaskOrGift(gameId, commendApp == null ? FIRST_ORDER : commendApp.getOrder())
-                    .subscribeOn(Schedulers.io())
-                    .observeOn(AndroidSchedulers.mainThread())
-                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                        @Override
-                        public void onNext(BaseMessage baseMessage) {
-                            commendApp = baseMessage.getData(CommendApp.class);
-                            loadData();
-                        }
 
-                        @Override
-                        public void onError(BaseMessage baseMessage) {
-                            resetView();
-                            G.showToast(baseMessage);
-                        }
-                    });
-        } else {
+    private void initData() {
+        if (commendApp != null && commendApp.needChange()) {
             //显示换个频道去赚钱
             ViewUtil.setVisibility(dialog_iv_2, true);//显示换个频道去赚钱图标
             ViewUtil.setVisibility(dialog_tip, true);//显示文字【当前现金任务剩余%s元】
@@ -242,7 +227,7 @@ public class DialogGameOrTaskOrGift {
             ViewUtil.setVisibility2(dialog_gift_code_tv, false);//不显示礼包码
             ViewUtil.setVisibility2(dialog_gift_info_tv, false);//不显示礼包详情
             CashAwarsEntity cashAwarsEntity = DataUtil.getInstance().getCacheResult(ApiKey.CAN_RECEIVE_AWARD, CashAwarsEntity.class);
-            ViewUtil.setText(dialog_tip, activity.getString(R.string.cur_xian_jin_amount,  cashAwarsEntity == null ? "0" : NumberFormatUtils.retainMost2(cashAwarsEntity.getCash())));
+            ViewUtil.setText(dialog_tip, activity.getString(R.string.cur_xian_jin_amount, cashAwarsEntity == null ? "0" : NumberFormatUtils.retainMost2(cashAwarsEntity.getCash())));
             dialog_btn_right.setText("立即去赚钱");
             dialog_btn_right.setOnClickListener(new View.OnClickListener() {
                 @Override
@@ -261,6 +246,25 @@ public class DialogGameOrTaskOrGift {
                     });
                 }
             });
+        } else if(commendApp != null && commendApp.hasNextShow()){
+            loadData();
+        } else {
+            SheepApp.getInstance().getNetComponent().getApiService().getGameOrTaskOrGift(gameId, commendApp == null ? FIRST_ORDER : commendApp.getOrder())
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            commendApp = baseMessage.getData(CommendApp.class);
+                            loadData();
+                        }
+
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            resetView();
+                            G.showToast(baseMessage);
+                        }
+                    });
         }
     }
 }

+ 0 - 7
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -334,13 +334,6 @@ public class SheepApp extends MultiDexApplication {
             ActivityManager.getInstance().pushActivity(activity);
             if (/*activity instanceof SplashAct || */activity instanceof LoginAct) {
                 SysAppUtil.showVersionInfo(activity, SpUtils.getIgnoreMd5());
-            } else if (activity instanceof ActMain) {
-                SysAppUtil.showVersionInfo(activity, SpUtils.getIgnoreMd5(), new Action1<Integer>() {
-                    @Override
-                    public void call(Integer integer) {
-                        Jump2View.getInstance().tryShowHalfScreenAd(activity, ((ActMain) activity).getContainer());
-                    }
-                });
             }
 
             if (mActivityCount == 0) {

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -102,4 +102,5 @@
     <string name="cur_xian_jin_amount">当前现金任务剩余%s元</string>
     <string name="success_copy_inv_code">复制邀请码成功</string>
     <string name="success_copy_code">复制礼包码成功</string>
+    <string name="plus_x_yuan">+%s元</string>
 </resources>