Pārlūkot izejas kodu

修改多次点击卡顿bug

liujiangyao 8 gadi atpakaļ
vecāks
revīzija
502829f78b

+ 20 - 9
app/src/main/java/com/kfzs/duanduan/react/TabsHelper.java

@@ -17,6 +17,7 @@ import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.jiuyan.samllsheep.R;
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -31,6 +32,10 @@ import rx.schedulers.Schedulers;
  */
 
 public class TabsHelper {
+
+    //多次点击预防
+    public static final int MIN_CLICK_DELAY_TIME = 1000;
+    private long lastClickTime = 0;
     private ActMain activity;
 
     LinearLayout other_container;
@@ -94,16 +99,22 @@ public class TabsHelper {
             view.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
-                    checkViewState(position);
-                    view_pager_container.setCurrentItem(position, false);
-                    int sheepPosition = MainTab.FgtSmallSheep.ordinal();
-                    FgtSmallSheep fgtSmallSheep = (FgtSmallSheep) fragmentList.get(sheepPosition);
-                    if(position == sheepPosition){
-                        fgtSmallSheep.onResume();
-                    } else {
-                        fgtSmallSheep.onPause();
+                    long currentTime = Calendar.getInstance().getTimeInMillis();
+                    if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
+                        lastClickTime = currentTime;
+
+                        checkViewState(position);
+                        view_pager_container.setCurrentItem(position, false);
+                        int sheepPosition = MainTab.FgtSmallSheep.ordinal();
+                        FgtSmallSheep fgtSmallSheep = (FgtSmallSheep) fragmentList.get(sheepPosition);
+                        if(position == sheepPosition){
+                            fgtSmallSheep.onResume();
+                        } else {
+                            fgtSmallSheep.onPause();
+                        }
+                        checkWhichPage(position);
                     }
-                    checkWhichPage(position);
+
                 }
             });
             index++;