From 2eec3de87b6b616a69a46c1f97c2397159031d2f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 21 十一月 2023 18:01:43 +0800
Subject: [PATCH] 广告升级/bug修复

---
 BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java |  173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 173 insertions(+), 0 deletions(-)

diff --git a/BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java b/BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java
index ae80b98..1052ca0 100644
--- a/BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java
+++ b/BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java
@@ -1,11 +1,24 @@
 package com.weikou.beibeivideo.util;
 
 import android.content.Context;
+import android.content.Intent;
 import android.content.SharedPreferences;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import com.umeng.commonsdk.debug.I;
+import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
+import com.weikou.beibeivideo.BeibeiVideoAPI;
+import com.weikou.beibeivideo.entity.UserInfo;
+import com.weikou.beibeivideo.entity.vo.UserInfoVO;
+import com.weikou.beibeivideo.ui.login.LoginActivity;
+import com.weikou.beibeivideo.ui.login.PhoneLoginActivity;
+import com.weikou.beibeivideo.ui.mine.MyFavouriteActivity;
 import com.weikou.beibeivideo.util.downutil.StringUtils;
+
+import org.apache.http.Header;
+import org.json.JSONObject;
+
 
 import static android.content.Context.MODE_PRIVATE;
 
@@ -27,6 +40,8 @@
             return false;
         else
             return true;
+
+
     }
 
 
@@ -53,4 +68,162 @@
         String uid = preferences.getString("LoginUid", "");
         return uid;
     }
+
+
+    public static boolean isLogin(Context context) {
+        String uid = getLoginUid(context);
+        return !StringUtils.isNullOrEmpty(uid);
+    }
+
+    public static UserInfo getLoginUserInfo(Context context) {
+
+        UserInfoVO vo = getLoginUserInfoDetail(context);
+        if (vo != null) {
+            UserInfo userInfo = new UserInfo();
+            userInfo.setId(vo.getId());
+            userInfo.setNickname(vo.getNickName());
+            userInfo.setPortrait(vo.getPortrait());
+            return userInfo;
+        }
+
+        SharedPreferences sp_user = context.getSharedPreferences("user",
+                Context.MODE_PRIVATE);
+        String uid = sp_user.getString("LoginUid", "");
+        boolean isLogin = !com.lcjian.library.util.common.StringUtils.isEmpty(uid);// 鑾峰彇鐧诲綍鐘舵��
+        if (isLogin) {
+            UserInfo userInfo = new UserInfo();
+            userInfo.setId(uid);
+            String portrait = sp_user.getString("portrait", "");// 鐢ㄦ埛澶村儚
+            String name = sp_user.getString("name", "");// 鐢ㄦ埛鍚嶇О
+            userInfo.setNickname(name);
+            userInfo.setPortrait(portrait);
+            return userInfo;
+        } else {
+            return null;
+        }
+    }
+
+
+    /**
+     * 鑾峰彇鐢ㄦ埛璇︽儏(鏂扮増鏈�)
+     *
+     * @param context
+     * @return
+     */
+    public static UserInfoVO getLoginUserInfoDetail(Context context) {
+        SharedPreferences sp_user = context.getSharedPreferences("user",
+                Context.MODE_PRIVATE);
+        String detail = sp_user.getString("detail", "");
+
+        if (StringUtils.isNullOrEmpty(detail)) {
+            return null;
+        } else {
+            return new Gson().fromJson(detail, UserInfoVO.class);
+        }
+    }
+
+    /**
+     * 淇濆瓨鐢ㄦ埛璇︽儏
+     *
+     * @param context
+     * @param vo
+     */
+    public static void saveLoginUserDetail(Context context, UserInfoVO vo) {
+        if (context == null || vo == null)
+            return;
+        SharedPreferences.Editor editor = context.getSharedPreferences("user",
+                Context.MODE_PRIVATE).edit();
+        editor.putString("detail", new Gson().toJson(vo));
+        editor.commit();
+    }
+
+
+    /**
+     * 閫�鍑虹櫥褰�
+     *
+     * @param context
+     */
+    public static void logout(Context context) {
+        SharedPreferences.Editor editor = context.getSharedPreferences("user",
+                Context.MODE_PRIVATE).edit();
+        editor.remove("detail");
+        editor.remove("LoginUid");
+        editor.remove("portrait");
+        editor.remove("name");
+        editor.putBoolean("PushType", false);
+        editor.commit();
+    }
+
+
+    public static void updateUserInfo(Context context, IUserInfoUpdateListener listener) {
+        if (context == null)
+            return;
+        String loginUid = UserUtil.getLoginUid(context);
+        if (com.lcjian.library.util.common.StringUtils.isEmpty(loginUid)) {
+            if (listener != null)
+                listener.noLogin();
+            return;
+        }
+        BeibeiVideoAPI.getPersonInfo(context, UserUtil.getUid(context), loginUid, new BasicTextHttpResponseHandler() {
+            @Override
+            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
+                if (jsonObject.optBoolean("IsPost")) {
+                    JSONObject data = jsonObject.optJSONObject("Data");
+                    UserInfoVO userInfoVO = new Gson().fromJson(data.toString(), UserInfoVO.class);
+                    //缂撳瓨璧锋潵
+                    if (userInfoVO != null && userInfoVO.getId() != null) {
+                        UserUtil.saveLoginUserDetail(context, userInfoVO);
+                    }
+                    if (listener != null)
+                        listener.onSuccess();
+                } else {
+                    if (listener != null)
+                        listener.onFail(jsonObject.optString("Error"));
+                }
+            }
+
+            @Override
+            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
+                super.onFailure(statusCode, headers, responseString, throwable);
+                if (listener != null)
+                    listener.onFail(responseString);
+            }
+        });
+
+    }
+
+    public interface IUserInfoUpdateListener {
+        public void noLogin();
+
+        public void onSuccess();
+
+        public void onFail(String msg);
+
+    }
+
+    public static boolean isVIP(Context context) {
+
+        UserInfoVO vo = getLoginUserInfoDetail(context);
+        if (vo == null) {
+            return false;
+        }
+        if (vo.getVipExpireTime() == null) {
+            return false;
+        }
+
+        if (System.currentTimeMillis() > vo.getVipExpireTime().longValue()) {
+            return false;
+        }
+
+        return true;
+    }
+
+    public static void toLogin(Context context){
+        Intent intent=new Intent(context, LoginActivity.class);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        context.startActivity(intent);
+
+    }
+
+
 }

--
Gitblit v1.8.0