billyyoyo лет назад: 6
Родитель
Сommit
57c4239ac9

+ 2 - 7
app/src/main/java/com/sheep/gamegroup/util/DataUtil.java

@@ -6,6 +6,7 @@ import android.content.Intent;
 import android.media.projection.MediaProjectionManager;
 import android.os.Bundle;
 import android.text.TextUtils;
+import android.util.Log;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -210,13 +211,7 @@ public class DataUtil {
     }
 
     public void getUserVIPDays(Action2<String, Integer> action) {
-        CommonUtil.getInstance().getUserInfo(false, (user) -> {
-            if (!user.isVIP()) return;
-            long days = (user.getVip_time() - System.currentTimeMillis() / 1000) / (24 * 60 * 60);
-            if (days >= 0 && days <= 7) {
-                action.call(user.getId() + "_" + user.getVip_time(), (int) days);
-            }
-        });
+
     }
 
     //-----------------------------------------用户信息部分-----------------------------------------------------结束

+ 21 - 11
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -120,6 +120,7 @@ import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.GlideApp;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import com.umeng.socialize.ShareAction;
 import com.umeng.socialize.UMShareListener;
 import com.umeng.socialize.bean.SHARE_MEDIA;
@@ -1817,18 +1818,27 @@ public class ViewUtil {
         }
     }
 
-    public static void showVipWillOver(Context context, String flag, int days) {
-        int curr = DataUtil.getAsInt("vip_" + flag, -1);
-        if (curr == -1 || days < curr) {
-            DataUtil.putAsInt("vip_" + flag, days);
-            showConfirmDialog(context, "温馨提示", "您的会员剩余" + days + "天过期, 为保障您的会员权益请立即续费~!",
-                    "下次再说", "立即续费", diag -> {
+    public static void showVipWillOver(Context context) {
+        CommonUtil.getInstance().getUserInfo(false, (user) -> {
+            if (!user.isVIP()) return;
+            long days = (user.getVip_time() - System.currentTimeMillis() / 1000) / (24 * 60 * 60);
+            LogUtil.logI("VIP has " + days + " days");
+            if (days >= 0 && days <= 7) {
+                String flag = user.getId() + "_" + user.getVip_time();
+                int curr = SpUtils.getAsInt("vip_" + flag, -1);
+                LogUtil.logI("VIP has " + days + " days"+", record "+curr+" days");
+                if (curr == -1 || days < curr) {
+                    SpUtils.putAsInt("vip_" + flag, (int)days);
+                    showConfirmDialog(context, "温馨提示", "您的会员剩余" + days + "天过期, 为保障您的会员权益请立即续费~!",
+                            "下次再说", "立即续费", diag -> {
 
-                    },
-                    dialog -> {
-                        Jump2View.getInstance().gotoVip(context);
-                    }).show();
-        }
+                            },
+                            dialog -> {
+                                Jump2View.getInstance().gotoVip(context);
+                            }).show();
+                }
+            }
+        });
     }
 
     //3.4.7添加 -- 展示商城优惠券领取对话框

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

@@ -479,7 +479,7 @@ public class ActMain extends BaseActYmPermissionCheck {
     public void onEventMainThread(BigEvent event) {
         switch (event.getEventTypes()) {
             case CHECK_VIP:
-                DataUtil.getInstance().getUserVIPDays((flag, days) -> ViewUtil.showVipWillOver(this, flag, days));
+                ViewUtil.showVipWillOver(this);
                 break;
             case STORAGE_LOW:
                 DialogStorageLow.showDialog(null);

+ 12 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/SpUtils.java

@@ -184,9 +184,21 @@ public class SpUtils {
         editor.commit();
     }
 
+    public static void putAsInt(String key, int value) {
+        SharedPreferences sp = SheepApp.getInstance().getSharedPreferences("app", Context.MODE_PRIVATE);
+        SharedPreferences.Editor editor = sp.edit();
+        editor.putInt(key, value);
+        editor.commit();
+    }
+
     public static boolean getAsBoolean(String key, boolean defaultValue) {
         SharedPreferences sp = SheepApp.getInstance().getSharedPreferences("app", Context.MODE_PRIVATE);
         return sp.getBoolean(key, defaultValue);
     }
 
+    public static int getAsInt(String key, int defaultValue) {
+        SharedPreferences sp = SheepApp.getInstance().getSharedPreferences("app", Context.MODE_PRIVATE);
+        return sp.getInt(key, defaultValue);
+    }
+
 }