From 01e23be6118d68d38a71d186296d440eadcaa197 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 07 六月 2021 18:23:41 +0800
Subject: [PATCH] 特价bug修复

---
 app/src/main/java/com/tejia/lijin/app/ui/main/MineFragment.java |  157 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 86 insertions(+), 71 deletions(-)

diff --git a/app/src/main/java/com/tejia/lijin/app/ui/main/MineFragment.java b/app/src/main/java/com/tejia/lijin/app/ui/main/MineFragment.java
index 8d371c6..a9f02e6 100644
--- a/app/src/main/java/com/tejia/lijin/app/ui/main/MineFragment.java
+++ b/app/src/main/java/com/tejia/lijin/app/ui/main/MineFragment.java
@@ -50,7 +50,9 @@
 import com.nostra13.universalimageloader.core.ImageLoader;
 import com.nostra13.universalimageloader.core.assist.ImageScaleType;
 import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer;
+import com.tejia.lijin.app.ShoppingApplication;
 import com.tejia.lijin.app.ui.message.UserMessageActivity;
+import com.tejia.lijin.app.ui.recommend.GoodsDetailActivity;
 import com.tejia.lijin.app.util.ui.HomeUIUtil;
 import com.umeng.analytics.MobclickAgent;
 import com.viewpagerindicator.CirclePageIndicator;
@@ -91,9 +93,6 @@
 import com.tejia.lijin.app.ui.mine.SettingActivity;
 import com.tejia.lijin.app.ui.mine.ShareHistoryActivity31;
 import com.tejia.lijin.app.ui.mine.WelfareCenterActivity;
-import com.tejia.lijin.app.ui.recommend.GoodsDetailActivityJD;
-import com.tejia.lijin.app.ui.recommend.GoodsDetailActivityPDD;
-import com.tejia.lijin.app.ui.recommend.GoodsDetailActivityTB;
 import com.tejia.lijin.app.ui.recommend.RecommendTopAdapter2;
 import com.tejia.lijin.app.updateApp.UpdateApp;
 import com.tejia.lijin.app.util.JumpActivityUtil;
@@ -128,7 +127,7 @@
 
 public class MineFragment extends RetainViewFragment implements View.OnClickListener, PermissionInterface {
     private TextView tv_user_num;
-    private ImageView iv_portrait;
+    private ImageView iv_portrait, iv_rank;
     private TextView tv_nickName;
 
     //鐢ㄦ埛鏄电О涓庨個璇风爜
@@ -189,11 +188,12 @@
     @Override
     public void onCreateView(View contentView, Bundle savedInstanceState) {
         mineFunctionsManager = new MineFunctionsManager(getContext());
-        String inviteCode = UserUtil.getInviteCode(getContext(), null);
+        String inviteCode = UserUtil.getInviteCode(getContext());
         init(contentView);
         listener(contentView);
         app = new UpdateApp(getActivity(), getResources().getString(R.string.update_key));
         mPermissionsChecker = new PermissionHelper(getActivity(), this);
+//        startActivity(new Intent(getContext(),ShareBrowserActivity.class).putExtra("url","http://vip.tejia.yeshitv.com/index.html"));
     }
 
     private void init(View contentView) {
@@ -221,6 +221,7 @@
                 .displayer(new CircleBitmapDisplayer(300))
                 .build();
 
+        iv_rank = contentView.findViewById(R.id.iv_rank);
         fl_msg = contentView.findViewById(R.id.fl_msg);
         tv_msg_count = contentView.findViewById(R.id.tv_msg_count);
 
@@ -236,8 +237,8 @@
         ll_top = contentView.findViewById(R.id.ll_top);
         view_mine_end_bg = contentView.findViewById(R.id.view_mine_end_bg);
 
-        ll_top.setBackground(HomeUIUtil.getHomeTopBg("#FF227B", "#FF2A3E"));
-        view_mine_end_bg.setBackground(HomeUIUtil.getHomeTopBg("#FF227B", "#FF2A3E"));
+        ll_top.setBackground(HomeUIUtil.getHomeTopBg(getContext()));
+        view_mine_end_bg.setBackground(HomeUIUtil.getHomeTopBg(getContext()));
 
 
         tv_user_numlayout = contentView.findViewById(R.id.tv_user_numlayout);
@@ -312,50 +313,32 @@
     @Override
     public void onResume() {
         super.onResume();
+        initUserView();
         getUserConfig();
-        getUnReadMsgCount(UserUtil.getUid(getContext()) + "");
+        getLijinUserLevel();
+        getUnReadMsgCount(UserUtil.getUid(getContext()));
         MobclickAgent.onPageStart("鎴戠殑");
-        SharedPreferences sp = tv_nickName.getContext().getSharedPreferences("user", MODE_PRIVATE);
-        if (sp.getBoolean("isLogin", false)) {
+        vp_banner.postDelayed(mAutoScroller, 2000);
+    }
+
+    private void initUserView() {
+        if (UserUtil.isLogin(getContext())) {
             tv_user_numlayout.setVisibility(View.VISIBLE);
             tv_user_num.setVisibility(View.VISIBLE);
             ll_nick_name_vip.setVisibility(View.VISIBLE);
             tv_nickName.setVisibility(View.VISIBLE);
-            String uid = sp.getString("uid", "0");
-            if (lastTime > 0 && (System.currentTimeMillis() - lastTime > 30 * 1000)) {
-                clickState = 0;
-            }
-            if (!uid.equalsIgnoreCase("0")) {
-                String userInfo = sp.getString("userinfo", "");
-                if (!StringUtils.isEmpty(userInfo)) {
-                    try {
-                        JSONObject jsonObject = new JSONObject(userInfo);
-                        showInfo(jsonObject);
-                    } catch (JSONException e) {
-                        e.printStackTrace();
-                    }
-                }
-                String rewardInfo = sp.getString("estimatereward", "");
-
-                getUserInfo(uid);
-            }
+            UserInfo user = UserUtil.getUserInfo(getContext());
+            showInfo(user);
+            getUserInfo(UserUtil.getUid(getContext()));
         } else {
             noLogin();
         }
-        vp_banner.postDelayed(mAutoScroller, 2000);
     }
 
     /**
      * 灞曠ず鐢ㄦ埛淇℃伅
      */
-    private void showInfo(JSONObject jsonObject) {
-        if (jsonObject.optJSONObject("data") == null) {
-            return;
-        }
-        JSONObject data = jsonObject.optJSONObject("data");
-        Gson gson = new GsonBuilder().serializeNulls().create();
-        UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("user").toString(), new TypeToken<UserInfo>() {
-        }.getType());
+    private void showInfo(UserInfo info) {
         if (info == null) {
             return;
         }
@@ -471,8 +454,7 @@
 
     @Override
     public void onClick(View v) {
-        final SharedPreferences sp = getActivity().getSharedPreferences("user", Context.MODE_PRIVATE);
-        boolean isLogin = sp.getBoolean("isLogin", false);
+        boolean isLogin = UserUtil.isLogin(getContext());
         clickState = 0;
         switch (v.getId()) {
             case R.id.vp_close:
@@ -486,13 +468,13 @@
                 break;
 
             case R.id.fl_msg:
-                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
+                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()), true))
                     return;
                 startActivity(new Intent(getContext(), UserMessageActivity.class));
                 break;
 
             case R.id.tv_nickname:
-                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
+                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()), true))
                     return;
                 if (!isLogin) {//鐧诲綍娣樺疂
                     UserUtil.jumpLogin(tv_nickName.getContext());
@@ -503,7 +485,7 @@
 
             //澶村儚
             case R.id.iv_portrait:
-                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
+                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()), true))
                     return;
                 UserCustomEvent.userMyInfo(ll_notice.getContext());
                 if (!isLogin) {//鐧诲綍
@@ -515,7 +497,7 @@
                 break;
             //璐︽埛浣欓
             case R.id.ll_balance:
-                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
+                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()), true))
                     return;
                 UserCustomEvent.userBalance(tv_user_num.getContext());
                 if (isLogin) {
@@ -531,7 +513,7 @@
                     }, 200);
 
 
-                    ShoppingApi.getUserMoneyInfo(getContext(), getContext().getSharedPreferences("user", Context.MODE_PRIVATE).getString("uid", ""), new BasicTextHttpResponseHandler() {
+                    ShoppingApi.getUserMoneyInfo(getContext(), UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() {
                         @Override
                         public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                             ll_balance.setEnabled(true);
@@ -562,7 +544,7 @@
 
 
             case R.id.iv_vip:
-                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
+                if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()), true))
                     return;
                 //璺宠浆鍒皏ip
                 if (userInviteLevel != null && !StringUtils.isEmpty(userInviteLevel.getLink()))
@@ -633,14 +615,14 @@
     private UserInviteLevel userInviteLevel;//鐢ㄦ埛閭�璇风瓑绾�
 
     /****鐢ㄦ埛淇℃伅*/
-    private void getUserInfo(final String uid) {
+    private void getUserInfo(final Long uid) {
         ShoppingApi.getUserInfo2(tv_nickName.getContext(), uid, new BasicTextHttpResponseHandler() {
             @Override
             public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                 if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                     JSONObject data = jsonObject.optJSONObject("data");
                     String inviteCode = data.optString("invitCode");
-                    UserUtil.setInviteCode(getContext(), uid, inviteCode);
+                    UserUtil.setInviteCode(getContext(), inviteCode);
                     vipLink = data.optString("vipLink");
                     moduleState = data.optJSONObject("moduleState");
                     if (mineFunctionsManager != null)
@@ -652,23 +634,10 @@
                     if (inviteLevel != null) {
                         userInviteLevel = gson.fromJson(inviteLevel.toString(), UserInviteLevel.class);
                     }
-                    showInfo(jsonObject);//灞曠ず鐢ㄦ埛涓汉淇℃伅
                     final UserInfo info = gson.fromJson(data.optJSONObject("user").toString(), new TypeToken<UserInfo>() {
                     }.getType());
-                    SharedPreferences sp = tv_nickName.getContext().getSharedPreferences("user", MODE_PRIVATE);
-                    SharedPreferences.Editor editor = sp.edit();
-                    editor.putBoolean("isLogin", true);
-                    editor.putBoolean("isFirstInput", false);
-                    editor.putString("uid", info.getId());
-                    editor.putString("openid", info.getOpenid());
-                    editor.putString("portrait", info.getPortrait());
-                    editor.putString("userinfo", jsonObject.toString());
-                    if (StringUtils.isEmpty(info.getWxOpenId())) {
-                        editor.putBoolean("isWxBind", false);
-                    } else {
-                        editor.putBoolean("isWxBind", true);
-                    }
-                    editor.commit();
+                    showInfo(info);//灞曠ず鐢ㄦ埛涓汉淇℃伅
+                    UserUtil.loginSuccess(getContext(),info);
                     /**bindPhone 缁戝畾鎵嬫満寮圭獥*/
                     if (jsonObject.optJSONObject("data").optBoolean("bindPhone", false)) {
                         if (System.currentTimeMillis() - bindPhonetime < 1000) {//灏忎簬1绉掍笉杩涘叆
@@ -694,7 +663,7 @@
                     }
 
                 } else if (jsonObject.optInt("code") == 80001) {
-                    if (tv_nickName.getContext().getSharedPreferences("user", MODE_PRIVATE).getBoolean("isLogin", false)) {
+                    if (UserUtil.isLogin(getContext())) {
                         loginOut();
                         UserUtil.logout(tv_nickName.getContext());
                         noLogin();
@@ -815,12 +784,55 @@
         });
     }
 
+
+    private void getLijinUserLevel() {
+        if (!UserUtil.isLogin(getContext())) {
+            iv_rank.setVisibility(View.GONE);
+            return;
+        }
+
+        ShoppingApi.getLijinUserLevel(getContext(), UserUtil.getUid(getContext()), new BasicTextHttpResponseHandler() {
+            @Override
+            public void onStart() {
+                super.onStart();
+            }
+
+            @Override
+            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
+                if (jsonObject.optInt("code") == 0) {
+                    JSONObject data = jsonObject.optJSONObject("data");
+                    String userLevel = data.optString("userLevel");
+                    final String vipLink = data.optString("lijinVipLink");
+                    try {
+                        iv_rank.setImageResource(getResources().getIdentifier("icon_rank_" + userLevel, "drawable", getContext().getPackageName()));
+                    } catch (Exception e) {
+                    }
+
+                    iv_rank.setOnClickListener(new View.OnClickListener() {
+                        @Override
+                        public void onClick(View v) {
+                            startActivity(new Intent(getContext(), ShareBrowserActivity.class).putExtra("url", vipLink));
+                        }
+                    });
+                    iv_rank.setVisibility(View.VISIBLE);
+                }
+                super.onSuccessPerfect(statusCode, headers, jsonObject);
+            }
+
+            @Override
+            public void onFinish() {
+                super.onFinish();
+            }
+        });
+
+    }
+
     /**
      * 鎴戠殑淇℃伅-鎻愰啋璁板綍
      *
      * @param uid
      */
-    private void user_recordBind(String uid) {
+    private void user_recordBind(Long uid) {
         ShoppingApi.setRecordBind(tv_nickName.getContext(), uid, null);
     }
 
@@ -852,23 +864,26 @@
                 String content = data.getStringExtra(Constant.CODED_CONTENT);
                 if (content.contains("taobao://")) {
 //                    Intent intent = new Intent(tv_user_num.getContext(), GoodsDetailBrowerActivity.class);
-                    Intent intent = new Intent(tv_nickName.getContext(), GoodsDetailActivityTB.class);
+                    Intent intent = new Intent(tv_nickName.getContext(), GoodsDetailActivity.class);
                     String id = content.substring(content.indexOf("//") + 2);
-                    intent.putExtra("id", id);
                     intent.putExtra("from", "scan");
+                    intent.putExtra("goodsId", id);
+                    intent.putExtra("goodsType", com.tejia.lijin.app.util.Constant.GOODS_TYPE_TB);
                     startActivity(intent);
                 } else if (content.contains("jd://")) {
 //                    Intent intent = new Intent(tv_user_num.getContext(), GoodsDetailBrowerActivity.class);
-                    Intent intent = new Intent(tv_nickName.getContext(), GoodsDetailActivityJD.class);
+                    Intent intent = new Intent(tv_nickName.getContext(), GoodsDetailActivity.class);
                     String id = content.substring(content.indexOf("//") + 2);
-                    intent.putExtra("id", id);
+                    intent.putExtra("goodsId", id);
+                    intent.putExtra("goodsType", com.tejia.lijin.app.util.Constant.GOODS_TYPE_JD);
                     intent.putExtra("from", "scan");
                     startActivity(intent);
                 } else if (content.contains("pdd://")) {
 //                    Intent intent = new Intent(tv_user_num.getContext(), GoodsDetailBrowerActivity.class);
-                    Intent intent = new Intent(tv_nickName.getContext(), GoodsDetailActivityPDD.class);
+                    Intent intent = new Intent(tv_nickName.getContext(), GoodsDetailActivity.class);
                     String id = content.substring(content.indexOf("//") + 2);
-                    intent.putExtra("id", id);
+                    intent.putExtra("goodsId", id);
+                    intent.putExtra("goodsType", com.tejia.lijin.app.util.Constant.GOODS_TYPE_PDD);
                     intent.putExtra("from", "scan");
                     startActivity(intent);
                 } else {
@@ -1139,7 +1154,7 @@
      *
      * @param uid
      */
-    private void getUnReadMsgCount(String uid) {
+    private void getUnReadMsgCount(Long uid) {
         ShoppingApi.getUnReadMsgCount(getContext(), uid, new BasicTextHttpResponseHandler() {
             @Override
             public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {

--
Gitblit v1.8.0