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

添加随便打优惠弹出框

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

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/module/game/fragment/FgtGameCenter.java

@@ -55,7 +55,7 @@ public class FgtGameCenter extends BaseFragment {
         backBtn.setVisibility((getActivity() instanceof ActMain) ? View.GONE : View.VISIBLE);
         TitleFragmentListAdapter mAdapter = new TitleFragmentListAdapter(getChildFragmentManager());
         mAdapter.add(new FgtPlayGame(), "玩转游戏");
-        mAdapter.add(new FgtGiftCenter(), "礼包中心");
+        mAdapter.add(new com.sheep.gamegroup.view.fragment.FgtGiftCenter(), "礼包中心");
         pager.setAdapter(mAdapter);
         indicator.setupWithViewPager(pager);
         CommonUtil.getInstance().reflex(indicator, getActivity(), false, G.WIDTH - G.getRealPix(144));

+ 9 - 1
app/src/main/java/com/sheep/gamegroup/module/game/util/HpRefreshWelfareHelper.java

@@ -3,6 +3,7 @@ import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
 
+import com.sheep.gamegroup.absBase.AbsObserver;
 import com.sheep.gamegroup.model.entity.Release_task;
 import com.sheep.gamegroup.module.game.adapter.AdpRefreshWelfare;
 import com.sheep.gamegroup.util.CommonUtil;
@@ -54,7 +55,14 @@ public class HpRefreshWelfareHelper {
         hp_refresh_welfare.setAdapter(new AdpRefreshWelfare(R.layout.item_hp_refresh_welfare, refreshWelfareList).setChangeOne(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
-                refreshData();
+                refreshWelfareList.clear();
+                ViewUtil.notifyDataSetChanged(hp_refresh_welfare);
+                ViewUtil.delay2(new AbsObserver<Integer>(){
+                    @Override
+                    public void onNext(Integer o) {
+                        refreshData();
+                    }
+                }, 100);
             }
         }));
     }

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

@@ -336,6 +336,13 @@ public class ViewUtil {
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(observer);
     }
+    public static void delay2(Observer<Integer> observer, long delay) {
+        io.reactivex.Observable.just(1)
+                .delay(delay, TimeUnit.MILLISECONDS)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(observer);
+    }
 
     public static void setChecked(Checkable view, boolean checked) {
         if (view != null)

+ 181 - 0
app/src/main/java/com/sheep/gamegroup/util/viewHelper/PopupWindowUtil.java

@@ -0,0 +1,181 @@
+package com.sheep.gamegroup.util.viewHelper;
+
+import android.app.Activity;
+import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
+import android.support.annotation.LayoutRes;
+import android.support.v4.widget.PopupWindowCompat;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.PopupWindow;
+
+import com.sheep.gamegroup.absBase.AbsObserver;
+import com.sheep.gamegroup.util.ViewUtil;
+
+
+/**
+ * Created by realicing on 2019/3/26.
+ * realicing@sina.com
+ */
+public class PopupWindowUtil {
+    public static void delayShowLayout(Activity activity, PopupWindowParams popupWindowParams) {
+        ViewUtil.delay2(new AbsObserver<Integer>(){
+            @Override
+            public void onNext(Integer integer) {
+                PopupWindow popWindow = PopupWindowUtil.showLayout(activity, popupWindowParams);
+                if(popupWindowParams.getShowTime() > 0) {
+                    ViewUtil.delay2(new AbsObserver<Integer>() {
+                        @Override
+                        public void onNext(Integer integer) {
+                            try {
+                                popWindow.dismiss();
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    }, popupWindowParams.getShowTime());
+                }
+            }
+        }, popupWindowParams.getDelay());
+
+    }
+    public static PopupWindow showLayout(Activity activity, PopupWindowParams popupWindowParams) {
+        // 用于PopupWindow的View
+        View contentView= LayoutInflater.from(activity).inflate(popupWindowParams.layoutId, null, false);
+        // 创建PopupWindow对象,其中:
+        // 第一个参数是用于PopupWindow中的View,第二个参数是PopupWindow的宽度,
+        // 第三个参数是PopupWindow的高度,第四个参数指定PopupWindow能否获得焦点
+        PopupWindow window=new PopupWindow(contentView, popupWindowParams.width, popupWindowParams.height);
+        // 设置PopupWindow的背景
+        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
+        // 设置PopupWindow是否能响应外部点击事件
+        window.setOutsideTouchable(popupWindowParams.outsideTouchable);
+        // 设置PopupWindow是否能响应点击事件
+        window.setTouchable(popupWindowParams.focusable);
+        // 显示PopupWindow,其中:
+        // 第一个参数是PopupWindow的锚点,第二和第三个参数分别是PopupWindow相对锚点的x、y偏移
+        try {
+            PopupWindowCompat.showAsDropDown(window, popupWindowParams.anchor, popupWindowParams.xoff, popupWindowParams.yoff, popupWindowParams.gravity);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        // 或者也可以调用此方法显示PopupWindow,其中:
+        // 第一个参数是PopupWindow的父View,第二个参数是PopupWindow相对父View的位置,
+        // 第三和第四个参数分别是PopupWindow相对父View的x、y偏移
+        // window.showAtLocation(parent, gravity, x, y);
+        return window;
+    }
+   public static class PopupWindowParams {
+        private @LayoutRes int layoutId;
+        private long delay;
+        private long showTime;
+        private int width = WindowManager.LayoutParams.WRAP_CONTENT;
+        private int height = WindowManager.LayoutParams.WRAP_CONTENT;
+        private View anchor;
+        private int xoff = 0;
+        private int yoff = 0;
+        private boolean outsideTouchable = false;
+        private boolean focusable = true;
+        private int gravity = Gravity.NO_GRAVITY;
+
+       public PopupWindowParams(int layoutId) {
+           this.layoutId = layoutId;
+       }
+
+       public int getLayoutId() {
+            return layoutId;
+        }
+
+        public long getDelay() {
+            return delay;
+        }
+
+        public PopupWindowParams setDelay(long delay) {
+            this.delay = delay;
+            return this;
+        }
+
+        public long getShowTime() {
+            return showTime;
+        }
+
+        public PopupWindowParams setShowTime(long showTime) {
+            this.showTime = showTime;
+            return this;
+        }
+
+        public int getWidth() {
+            return width;
+        }
+
+        public PopupWindowParams setWidth(int width) {
+            this.width = width;
+            return this;
+        }
+
+        public int getHeight() {
+            return height;
+        }
+
+        public PopupWindowParams setHeight(int height) {
+            this.height = height;
+            return this;
+        }
+
+        public View getAnchor() {
+            return anchor;
+        }
+
+        public PopupWindowParams setAnchor(View anchor) {
+            this.anchor = anchor;
+            return this;
+        }
+
+        public int getXoff() {
+            return xoff;
+        }
+
+        public PopupWindowParams setXoff(int xoff) {
+            this.xoff = xoff;
+            return this;
+        }
+
+        public int getYoff() {
+            return yoff;
+        }
+
+        public PopupWindowParams setYoff(int yoff) {
+            this.yoff = yoff;
+            return this;
+        }
+
+        public boolean isFocusable() {
+            return focusable;
+        }
+
+        public PopupWindowParams setFocusable(boolean focusable) {
+            this.focusable = focusable;
+            return this;
+        }
+
+        public boolean isOutsideTouchable() {
+            return outsideTouchable;
+        }
+
+        public PopupWindowParams setOutsideTouchable(boolean outsideTouchable) {
+            this.outsideTouchable = outsideTouchable;
+            return this;
+        }
+
+        public int getGravity() {
+            return gravity;
+        }
+
+        public PopupWindowParams setGravity(int gravity) {
+            this.gravity = gravity;
+            return this;
+        }
+    }
+}

+ 7 - 0
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtSmallSheep.java

@@ -89,6 +89,7 @@ import com.sheep.gamegroup.util.ViewHolder;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.util.string.SpannableSb;
 import com.sheep.gamegroup.util.viewHelper.LayoutParamsUtil;
+import com.sheep.gamegroup.util.viewHelper.PopupWindowUtil;
 import com.sheep.gamegroup.view.activity.ActMsg;
 import com.sheep.gamegroup.view.activity.ActWebX5SBD;
 import com.sheep.gamegroup.view.activity.NotificationsUtils;
@@ -1177,6 +1178,12 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         CommonUtil.getInstance().callActionWithUserInfo(item -> userEntity = item);
         if (onResumeCount > 0)
             refreshTaskList();
+        if(onResumeCount == 0){
+            //延时显示随便打弹出框提示
+            PopupWindowUtil.delayShowLayout(activity, new PopupWindowUtil.PopupWindowParams(R.layout.pop_show_sbd_tip).setAnchor(to_search_but_rl)
+                    .setGravity(Gravity.BOTTOM).setXoff(G.getRealPix(16))
+                    .setDelay(100L).setShowTime(5000L).setOutsideTouchable(true).setFocusable(false));
+        }
         onResumeCount++;
     }
 

+ 8 - 5
app/src/main/res/layout/fgt_play_game.xml

@@ -19,11 +19,6 @@
 
             <include layout="@layout/homepage_item_banner" />
 
-            <include
-                android:id="@+id/hp_refresh_welfare_box"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                layout="@layout/inclue_hp_refresh_welfare_box" />
             <android.support.v7.widget.RecyclerView
                 android:id="@+id/play_game_center_type_list"
                 android:layout_width="match_parent"
@@ -31,6 +26,14 @@
                 android:layout_marginStart="2dp"
                 android:layout_marginEnd="2dp"/>
 
+            <include
+                android:id="@+id/hp_refresh_welfare_box"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone"
+                android:layout_marginTop="10dp"
+                layout="@layout/inclue_hp_refresh_welfare_box" />
+
             <android.support.v7.widget.RecyclerView
                 android:id="@+id/play_game_act"
                 android:layout_width="match_parent"

+ 1 - 0
app/src/main/res/layout/homepage_act_layout.xml

@@ -107,6 +107,7 @@
                     android:id="@+id/hp_refresh_welfare_box"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
+                    android:visibility="gone"
                     layout="@layout/inclue_hp_refresh_welfare_box"
                     android:layout_below="@id/home_award_container" />
 

+ 3 - 1
app/src/main/res/layout/item_hp_refresh_welfare.xml

@@ -2,7 +2,9 @@
 <android.support.constraint.ConstraintLayout 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_height="wrap_content"
+    android:paddingTop="11dp"
+    android:paddingBottom="19dp">
 
     <ImageView
         android:id="@+id/item_icon_iv"

+ 21 - 0
app/src/main/res/layout/pop_show_sbd_tip.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:layout_width="100dp"
+        android:layout_height="wrap_content"
+        android:adjustViewBounds="true"
+        android:scaleType="fitXY"
+        android:src="@mipmap/bg_sbd_tip" />
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="话费充30送70"
+        android:paddingTop="5dp"
+        android:layout_centerInParent="true"
+        android:textColor="#ffffffff"
+        android:textSize="12sp" />
+</RelativeLayout>

BIN
app/src/main/res/mipmap-xxhdpi/bg_sbd_tip.png