From 1981dee5aec45793d3c4ebdbc4e637528c71b3c5 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 03 二月 2021 19:20:47 +0800 Subject: [PATCH] 'PPTV' --- BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java | 144 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 144 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..50fa2fe 100644 --- a/BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java +++ b/BuWanVideo/src/com/weikou/beibeivideo/util/UserUtil.java @@ -2,10 +2,20 @@ import android.content.Context; import android.content.SharedPreferences; +import android.view.View; +import com.bumptech.glide.Glide; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.weikou.beibeivideo.BasicTextHttpResponseHandler; +import com.weikou.beibeivideo.BeibeiVideoAPI; +import com.weikou.beibeivideo.R; +import com.weikou.beibeivideo.entity.UserInfo; +import com.weikou.beibeivideo.entity.vo.UserInfoVO; import com.weikou.beibeivideo.util.downutil.StringUtils; + +import org.apache.http.Header; +import org.json.JSONObject; import static android.content.Context.MODE_PRIVATE; @@ -53,4 +63,138 @@ 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); + + } + + } -- Gitblit v1.8.0