| | |
| | | import android.content.pm.PackageInfo; |
| | | import android.content.pm.PackageManager; |
| | | import android.graphics.Color; |
| | | import android.graphics.Typeface; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.provider.Settings; |
| | | import android.text.TextPaint; |
| | | import android.view.MotionEvent; |
| | | import android.view.View; |
| | | import android.view.Window; |
| | |
| | | import com.alibaba.baichuan.trade.biz.login.AlibcLogin; |
| | | import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.bumptech.glide.Glide; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | |
| | | import com.tejia.lijin.app.BasicTextHttpResponseHandler; |
| | | import com.tejia.lijin.app.R; |
| | | import com.tejia.lijin.app.ShoppingApi; |
| | | import com.tejia.lijin.app.ShoppingApplication; |
| | | import com.tejia.lijin.app.entity.EntityFather; |
| | | import com.tejia.lijin.app.entity.FirstCategory; |
| | | import com.tejia.lijin.app.entity.TrendsType; |
| | | import com.tejia.lijin.app.entity.UserInfo; |
| | | import com.tejia.lijin.app.entity.eventbus.UserProtocolEvent; |
| | | import com.tejia.lijin.app.entity.hongbao.LijinSendInfo; |
| | | import com.tejia.lijin.app.sqlite.HomeConfigSQHelper; |
| | | import com.tejia.lijin.app.ui.BrandRebate.BrandFragment; |
| | | import com.tejia.lijin.app.ui.category.CategoryTypeActivity; |
| | | import com.tejia.lijin.app.ui.dialog.RecommendHbDialog; |
| | | import com.tejia.lijin.app.ui.dialog.RedPacketHintDialog; |
| | | import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog; |
| | | import com.tejia.lijin.app.ui.dialog.UserGuideDialog; |
| | | import com.tejia.lijin.app.ui.dialog.UserProtocolDialog; |
| | | import com.tejia.lijin.app.ui.gmtemplate.GmTemplateFragment; |
| | | import com.tejia.lijin.app.ui.gmtemplate.GmTemplateContentFragment; |
| | | import com.tejia.lijin.app.ui.invite.ShareBrowserActivity; |
| | | import com.tejia.lijin.app.ui.mine.ShoppingTrolleyActivity; |
| | | import com.tejia.lijin.app.ui.recommend.RecommendCategoryFragment; |
| | | import com.tejia.lijin.app.ui.recommend.RecommendFragment; |
| | | import com.tejia.lijin.app.ui.recommend.SearchActivity; |
| | | import com.tejia.lijin.app.ui.subview.HomeRecommendNavIndicator; |
| | | import com.tejia.lijin.app.updateApp.UpdateApp; |
| | | import com.tejia.lijin.app.util.GlideCircleTransform; |
| | | import com.tejia.lijin.app.util.JumpActivityUtil; |
| | | import com.tejia.lijin.app.util.SystemParamsUtil; |
| | | import com.tejia.lijin.app.util.ToolUtil; |
| | | import com.tejia.lijin.app.util.ui.HomeUIUtil; |
| | | import com.tejia.lijin.app.util.umengCustomEvent.CategoryCustomEvent; |
| | |
| | | import com.wpc.library.util.NetUtils; |
| | | import com.wpc.library.util.SystemCommon; |
| | | import com.wpc.library.util.cache.DiskLruCache; |
| | | import com.wpc.library.util.common.DimenUtils; |
| | | import com.wpc.library.util.common.StorageUtils; |
| | | import com.wpc.library.util.common.StringUtils; |
| | | import com.tejia.lijin.app.ui.recommend.RecommendFragment; |
| | | |
| | | import net.lucode.hackware.magicindicator.MagicIndicator; |
| | | import net.lucode.hackware.magicindicator.ViewPagerHelper; |
| | | import net.lucode.hackware.magicindicator.buildins.UIUtil; |
| | | import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator; |
| | | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter; |
| | | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator; |
| | | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; |
| | | import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator; |
| | | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView; |
| | | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView; |
| | | |
| | | import org.apache.http.Header; |
| | |
| | | private int clickState = 0; |
| | | //热门功能 |
| | | private ImageView recommend_top_img; |
| | | |
| | | |
| | | //福利底部提醒 |
| | | private FrameLayout fl_fuli; |
| | | private ImageView iv_fuli_portrait; |
| | | private TextView tv_fuli_title; |
| | | private TextView tv_fuli_sub_title; |
| | | private TextView tv_time_h, tv_time_m, tv_time_s; |
| | | |
| | | |
| | | String tag1 = "config/getHomeConfig"; |
| | | String tag2 = "navbar/getHomeItems"; |
| | |
| | | result = getActivity().getResources().getDimensionPixelSize(resourceId); |
| | | } |
| | | //设置状态栏文字颜色及图标为深色 |
| | | getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
| | | // getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
| | | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, |
| | | result); |
| | | // contentView.findViewById(R.id.v_status_bar).setLayoutParams(params); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } else { |
| | | contentView.findViewById(R.id.v_status_bar).setVisibility(View.GONE); |
| | | if (contentView.findViewById(R.id.v_status_bar) != null) |
| | | contentView.findViewById(R.id.v_status_bar).setVisibility(View.GONE); |
| | | } |
| | | |
| | | |
| | | contentView.findViewById(R.id.tv_course).setOnClickListener(this); |
| | | recommend_top_img = contentView.findViewById(R.id.recommend_top_img);//热门功能 |
| | | fl_search_content = contentView.findViewById(R.id.fl_search_content); |
| | | fl_search_content.setOnClickListener(this); |
| | |
| | | }); |
| | | |
| | | ll_no_data.setOnClickListener(this); |
| | | |
| | | initFuliFloat(contentView); |
| | | |
| | | MainCustomEvent.mainHome(getContext()); |
| | | loadCacheData(); |
| | |
| | | }, false);//强制检测更新-否. |
| | | |
| | | //设置背景色 |
| | | contentView.findViewById(R.id.apl_search).setBackground(HomeUIUtil.getHomeTopBg("#FF227B", "#FF2A3E")); |
| | | magic_indicator.setBackground(HomeUIUtil.getHomeTopBg("#FF227B", "#FF2A3E")); |
| | | contentView.findViewById(R.id.apl_search).setBackground(HomeUIUtil.getHomeTopBg(getContext())); |
| | | magic_indicator.setBackground(HomeUIUtil.getHomeTopBg(getContext())); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | private CommonNavigatorAdapter n1 = new CommonNavigatorAdapter() { |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return mList == null ? 0 : mList.size(); |
| | | } |
| | | |
| | | @Override |
| | | public IPagerTitleView getTitleView(final Context context, final int index) { |
| | | CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(getContext()); |
| | | //设置自定义布局文件及view赋值 |
| | | commonPagerTitleView.setContentView(R.layout.item_recommend_nav); |
| | | commonPagerTitleView.setHovered(false); |
| | | final TextView tvTitle = commonPagerTitleView.findViewById(R.id.tv_title); |
| | | tvTitle.setHighlightColor(context.getResources().getColor(android.R.color.transparent)); |
| | | tvTitle.setText(mList.get(index).getName()); |
| | | tvTitle.setBackground(null); |
| | | |
| | | //tab切换监听 |
| | | commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() { |
| | | @Override |
| | | public void onSelected(int index, int totalCount) { |
| | | tvTitle.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); |
| | | } |
| | | |
| | | @Override |
| | | public void onDeselected(int index, int totalCount) { |
| | | tvTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); |
| | | } |
| | | |
| | | @Override |
| | | public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) { |
| | | |
| | | } |
| | | }); |
| | | |
| | | //tab单个item点击事件监听 |
| | | commonPagerTitleView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | pager.setCurrentItem(index); |
| | | } |
| | | }); |
| | | |
| | | return commonPagerTitleView; |
| | | } |
| | | |
| | | //此为tab指示器回调 |
| | | @Override |
| | | public IPagerIndicator getIndicator(Context context) { |
| | | int height = magic_indicator.getLayoutParams().height; //UIUtil.dip2px(context, 40); |
| | | HomeRecommendNavIndicator indicator = new HomeRecommendNavIndicator(context); |
| | | float navigatorHeight = DimenUtils.sp2px(context, 25); //context.getResources().getDimension(R.dimen.dp_130); |
| | | float borderWidth = UIUtil.dip2px(context, 1); |
| | | float lineHeight = navigatorHeight - 2 * borderWidth; |
| | | indicator.setLineHeight(lineHeight); |
| | | indicator.setRoundRadius(lineHeight / 2); |
| | | indicator.setXOffset(UIUtil.dip2px(context, 5)); |
| | | indicator.setYOffset((height - navigatorHeight) / 2); |
| | | indicator.setColors(Color.parseColor("#FFFFFF")); |
| | | return indicator; |
| | | } |
| | | }; |
| | | |
| | | |
| | | private CommonNavigatorAdapter n2 = new CommonNavigatorAdapter() { |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return mList == null ? 0 : mList.size(); |
| | | } |
| | | |
| | | @Override |
| | | public IPagerTitleView getTitleView(Context context, final int index) { |
| | | ClipPagerTitleView clipPagerTitleView = new ClipPagerTitleView(context); |
| | | clipPagerTitleView.setText(mList.get(index).getName()); |
| | | clipPagerTitleView.setTextColor(Color.parseColor("#FFFFFF")); |
| | | clipPagerTitleView.setClipColor(Color.WHITE); |
| | | clipPagerTitleView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | pager.setCurrentItem(index); |
| | | } |
| | | }); |
| | | return clipPagerTitleView; |
| | | } |
| | | |
| | | //此为tab指示器回调 |
| | | @Override |
| | | public IPagerIndicator getIndicator(Context context) { |
| | | int height = magic_indicator.getLayoutParams().height; //UIUtil.dip2px(context, 40); |
| | | LinePagerIndicator indicator = new LinePagerIndicator(context); |
| | | float navigatorHeight = DimenUtils.sp2px(context, 25); //context.getResources().getDimension(R.dimen.dp_130); |
| | | float borderWidth = UIUtil.dip2px(context, 1); |
| | | float lineHeight = navigatorHeight - 2 * borderWidth; |
| | | indicator.setLineHeight(lineHeight); |
| | | indicator.setRoundRadius(lineHeight / 2); |
| | | indicator.setYOffset((height - navigatorHeight) / 2); |
| | | indicator.setColors(Color.parseColor("#bc2a2a")); |
| | | return indicator; |
| | | } |
| | | }; |
| | | |
| | | |
| | | private void loadHomeNavData() { |
| | | if (adapter == null) { |
| | |
| | | |
| | | if (commonNavigator == null) { |
| | | commonNavigator = new CommonNavigator(getContext()); |
| | | commonNavigator.setAdapter(new CommonNavigatorAdapter() { |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return mList == null ? 0 : mList.size(); |
| | | } |
| | | |
| | | @Override |
| | | public IPagerTitleView getTitleView(Context context, final int index) { |
| | | CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(getContext()); |
| | | //设置自定义布局文件及view赋值 |
| | | commonPagerTitleView.setContentView(R.layout.item_recommend_nav); |
| | | final TextView tvTitle = commonPagerTitleView.findViewById(R.id.tv_title); |
| | | tvTitle.setText(mList.get(index).getName()); |
| | | |
| | | //tab切换监听 |
| | | commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() { |
| | | @Override |
| | | public void onSelected(int index, int totalCount) { |
| | | tvTitle.setBackground(getResources().getDrawable(R.drawable.shape_recommend_nav_highlight_bg)); |
| | | TextPaint paint = tvTitle.getPaint(); |
| | | paint.setFakeBoldText(true); |
| | | } |
| | | |
| | | @Override |
| | | public void onDeselected(int index, int totalCount) { |
| | | tvTitle.setBackground(null); |
| | | TextPaint paint = tvTitle.getPaint(); |
| | | paint.setFakeBoldText(false); |
| | | } |
| | | |
| | | @Override |
| | | public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) { |
| | | |
| | | } |
| | | }); |
| | | |
| | | //tab单个item点击事件监听 |
| | | commonPagerTitleView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | pager.setCurrentItem(index); |
| | | } |
| | | }); |
| | | |
| | | return commonPagerTitleView; |
| | | } |
| | | |
| | | //此为tab指示器回调 |
| | | @Override |
| | | public IPagerIndicator getIndicator(Context context) { |
| | | // LinePagerIndicator indicator = new LinePagerIndicator(context); |
| | | // indicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT); |
| | | return null; |
| | | } |
| | | }); |
| | | commonNavigator.setAdapter(n1); |
| | | //设置给magicIndicator |
| | | magic_indicator.setNavigator(commonNavigator); |
| | | ViewPagerHelper.bind(magic_indicator, pager); |
| | |
| | | } |
| | | }, 1000); |
| | | |
| | | boolean isLogin = sp.getBoolean("isLogin", false); |
| | | boolean isLogin = UserUtil.isLogin(getContext()); |
| | | if (isLogin) { |
| | | String uid = sp.getString("uid", "0"); |
| | | if (!uid.equalsIgnoreCase("0")) { |
| | | getUserInfo(uid); |
| | | } |
| | | getUserInfo(UserUtil.getUid(ShoppingApplication.application)); |
| | | if (accountLogin && floatImgDetail != null) {//弹框需要登陆 |
| | | accountLogin = false; |
| | | final String showTime = floatImgDetail.optString("showTime"); // everyday-每天显示 always-每次进来都显示 |
| | |
| | | if (isLogin && lastRquestHomeConfigUid == null) { |
| | | getHomeConfig(); |
| | | } |
| | | |
| | | getSendingHongbao(); |
| | | } |
| | | |
| | | /* |
| | |
| | | startActivity(intent1); |
| | | } |
| | | } |
| | | break; |
| | | case R.id.tv_course: |
| | | //教程 |
| | | startActivity(new Intent(getContext(), ShareBrowserActivity.class).putExtra("url", SystemParamsUtil.getNewerCourse(getContext()))); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | UserUtil.agreeUserProtocol(getContext()); |
| | | dialog.dismiss(); |
| | | try { |
| | | ShoppingApi.userProtocolListener(getContext(), UserUtil.getUid(getContext()), 2, null); |
| | | } catch (Exception e) { |
| | | } |
| | | if (shownUserGuide) {//用户引导已经显示 |
| | | callback.onFinish(); |
| | | } else {//需要显示用户引导 |
| | |
| | | |
| | | |
| | | private void getHomeConfig() { |
| | | String uid = getContext().getSharedPreferences("user", Context.MODE_PRIVATE).getString("uid", ""); |
| | | if (!StringUtils.isEmpty(uid) && !uid.equalsIgnoreCase("0")) |
| | | lastRquestHomeConfigUid = Long.parseLong(uid); |
| | | Long uid = UserUtil.getUid(ShoppingApplication.application); |
| | | if (uid != null) |
| | | lastRquestHomeConfigUid = uid; |
| | | ShoppingApi.getHomeConfig(ll_recommend_content.getContext(), uid, new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | |
| | | builder.setPositiveButton(new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | final boolean isLogin = getContext().getSharedPreferences("user", |
| | | MODE_PRIVATE).getBoolean("isLogin", false); |
| | | final boolean isLogin = UserUtil.isLogin(getContext()); |
| | | if (accountLogin && !isLogin) { |
| | | clickState = 3; |
| | | UserUtil.jumpLogin(getContext()); |
| | |
| | | builder.setPositiveButton(new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | final boolean isLogin = getContext().getSharedPreferences("user", |
| | | MODE_PRIVATE).getBoolean("isLogin", false); |
| | | final boolean isLogin = UserUtil.isLogin(getContext()); |
| | | if (accountLogin && !isLogin) { |
| | | clickState = 4; |
| | | UserUtil.jumpLogin(getContext()); |
| | |
| | | } |
| | | if (mList.size() == 0) |
| | | pd.show(); |
| | | String uid = ll_recommend_content.getContext().getSharedPreferences("user", |
| | | MODE_PRIVATE).getString("uid", ""); |
| | | ShoppingApi.getHomeNavbar(ll_recommend_content.getContext(), uid, |
| | | |
| | | ShoppingApi.getHomeNavbar(ll_recommend_content.getContext(), UserUtil.getUid(ShoppingApplication.application), |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | CategoryCustomEvent.classHomeList(getContext(), mList.get(position).getName()); |
| | | if (!StringUtils.isEmpty(mList.get(position).getType()) && mList.get(position).getType().equals("commonTemplate")) {//跳转通用模版 |
| | | //新建一个Fragment来展示ViewPager item的内容,并传递参数 |
| | | GmTemplateFragment fragment = new GmTemplateFragment(); |
| | | GmTemplateContentFragment fragment = new GmTemplateContentFragment(); |
| | | Bundle args = new Bundle(); |
| | | args.putString("key", mList.get(position).getParams().getString("key")); |
| | | args.putString("type", mList.get(position).getParams().getInteger("type") + ""); |
| | |
| | | |
| | | String openid; |
| | | |
| | | private void getUserInfo(final String uid) { |
| | | private void getUserInfo(final Long uid) { |
| | | ShoppingApi.getUserInfo2(ll_no_data.getContext(), uid, new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | |
| | | }.getType()); |
| | | openid = info.getOpenid(); |
| | | String inviteCode = data.optString("invitCode"); |
| | | UserUtil.setInviteCode(getContext(), uid, inviteCode); |
| | | UserUtil.setInviteCode(getContext(), inviteCode); |
| | | } |
| | | } |
| | | |
| | |
| | | private void getShopList(String id) { |
| | | //精选 |
| | | SharedPreferences sp = getActivity().getSharedPreferences("user", MODE_PRIVATE); |
| | | ShoppingApi.getShopList(ll_recommend_content.getContext(), 1 + "", id, (sp.getBoolean("isLogin", false) ? sp.getString("uid", "0") : null), new BasicTextHttpResponseHandler() { |
| | | ShoppingApi.getShopList(ll_recommend_content.getContext(), 1 + "", id, UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | |
| | | //精选 |
| | | if (id.equals("0")) { |
| | | SharedPreferences sp = getActivity().getSharedPreferences("user", MODE_PRIVATE); |
| | | ShoppingApi.getHistory(ll_recommend_content.getContext(), "1", (sp.getBoolean("isLogin", false) ? sp.getString("uid", "0") : null), "1", new BasicTextHttpResponseHandler() { |
| | | ShoppingApi.getHistory(ll_recommend_content.getContext(), "1", UserUtil.getUid(ShoppingApplication.application), "1", new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optString("code").equalsIgnoreCase("0")) { |
| | |
| | | */ |
| | | private void getMessage() { |
| | | SharedPreferences sp = ll_recommend_content.getContext().getSharedPreferences("user", MODE_PRIVATE); |
| | | String uid = sp.getString("uid", ""); |
| | | ShoppingApi.getHomeMsgList(ll_recommend_content.getContext(), uid, 1 + "", new BasicTextHttpResponseHandler() { |
| | | ShoppingApi.getHomeMsgList(ll_recommend_content.getContext(), UserUtil.getUid(ShoppingApplication.application), 1 + "", new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | DiskLruCache.Editor editor = cache |
| | |
| | | } |
| | | |
| | | |
| | | private void initFuliFloat(View contentView) { |
| | | fl_fuli = contentView.findViewById(R.id.fl_fuli); |
| | | iv_fuli_portrait = contentView.findViewById(R.id.iv_portrait); |
| | | tv_fuli_title = contentView.findViewById(R.id.tv_title); |
| | | tv_fuli_sub_title = contentView.findViewById(R.id.tv_sub_title); |
| | | tv_time_h = contentView.findViewById(R.id.tv_time_h); |
| | | tv_time_m = contentView.findViewById(R.id.tv_time_m); |
| | | tv_time_s = contentView.findViewById(R.id.tv_time_s); |
| | | fl_fuli.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | showLijinHongBaoDialog(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private Runnable lijinHongBaoRunnable = new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (lijinSendInfo == null) { |
| | | if (fl_fuli != null) |
| | | fl_fuli.setVisibility(View.GONE); |
| | | return; |
| | | } |
| | | |
| | | //倒计时设置 |
| | | int leftTime = (int) ((lijinSendInfo.getExpireTime() - System.currentTimeMillis()) / 1000); |
| | | if (leftTime <= 0) { |
| | | if (fl_fuli != null) |
| | | fl_fuli.setVisibility(View.GONE); |
| | | //移除SharePreference |
| | | SharedPreferences.Editor editor = getContext().getSharedPreferences("lijinHongBao", MODE_PRIVATE).edit(); |
| | | editor.remove(lijinSendInfo.getMd5()); |
| | | editor.commit(); |
| | | return; |
| | | } |
| | | //设置时间 |
| | | int h = leftTime / (60 * 60); |
| | | int m = (leftTime - h * 60 * 60) / 60; |
| | | int s = leftTime % 60; |
| | | if (tv_time_h != null) |
| | | tv_time_h.setText(h < 10 ? ("0" + h) : (h + "")); |
| | | if (tv_time_m != null) |
| | | tv_time_m.setText(m < 10 ? ("0" + m) : (m + "")); |
| | | if (tv_time_s != null) |
| | | tv_time_s.setText(s < 10 ? ("0" + s) : (s + "")); |
| | | if (fl_fuli != null) { |
| | | fl_fuli.postDelayed(lijinHongBaoRunnable, 1000); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | LijinSendInfo lijinSendInfo; |
| | | |
| | | /** |
| | | * 设置福利数据 |
| | | */ |
| | | private void setFuliData() { |
| | | //移除监听 |
| | | fl_fuli.removeCallbacks(lijinHongBaoRunnable); |
| | | if (lijinSendInfo == null) { |
| | | fl_fuli.setVisibility(View.GONE); |
| | | } else { |
| | | fl_fuli.setVisibility(View.VISIBLE); |
| | | tv_fuli_title.setText(lijinSendInfo.getNotifyTitle()); |
| | | tv_fuli_sub_title.setText(lijinSendInfo.getNotifySubtitle()); |
| | | if (lijinHongBaoRunnable != null) |
| | | lijinHongBaoRunnable.run(); |
| | | if (lijinSendInfo.getUser() != null) { |
| | | Glide.with(this).load(lijinSendInfo.getUser().getPortrait()).transform(new GlideCircleTransform(getContext())).into(iv_fuli_portrait); |
| | | } else |
| | | Glide.with(this).load(R.drawable.ic_default_portrait_light).transform(new GlideCircleTransform(getContext())).into(iv_fuli_portrait); |
| | | } |
| | | } |
| | | |
| | | |
| | | //显示礼金红包 |
| | | private void showLijinHongBaoDialog() { |
| | | final SharedPreferences sharedPreferences = getContext().getSharedPreferences("lijinHongBao", MODE_PRIVATE); |
| | | //显示 |
| | | new RecommendHbDialog.Builder(getContext()).setHBInfo(lijinSendInfo).setActionListener(new RecommendHbDialog.Builder.ILijinHongBaoAction() { |
| | | @Override |
| | | public void onClose() { |
| | | if (lijinSendInfo != null && !StringUtils.isNullOrEmpty(lijinSendInfo.getMd5())) { |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | editor.putString(lijinSendInfo.getMd5(), new Gson().toJson(lijinSendInfo)); |
| | | editor.commit(); |
| | | } |
| | | |
| | | setFuliData(); |
| | | } |
| | | |
| | | @Override |
| | | public void onRecieveSuccess() { |
| | | //领取成功 |
| | | //移除sharePrefer |
| | | |
| | | //移除当前的md5 |
| | | if (lijinSendInfo != null) { |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | editor.remove(lijinSendInfo.getMd5()); |
| | | editor.commit(); |
| | | lijinSendInfo = null; |
| | | } |
| | | setFuliData(); |
| | | } |
| | | }).create().show(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取发送中的红包 |
| | | */ |
| | | private synchronized void getSendingHongbao() { |
| | | |
| | | ShoppingApi.getSendingHongBao(getContext(), new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | super.onSuccessPerfect(statusCode, headers, jsonObject); |
| | | if (jsonObject.optInt("code") == 0) { |
| | | JSONObject data = jsonObject.optJSONObject("data"); |
| | | final LijinSendInfo sendInfo = new Gson().fromJson(data.toString(), LijinSendInfo.class); |
| | | lijinSendInfo = sendInfo; |
| | | final SharedPreferences sharedPreferences = getContext().getSharedPreferences("lijinHongBao", MODE_PRIVATE); |
| | | if (StringUtils.isNullOrEmpty(sharedPreferences.getString(sendInfo.getMd5(), ""))) |
| | | showLijinHongBaoDialog(); |
| | | else { |
| | | setFuliData(); |
| | | } |
| | | |
| | | } else { |
| | | lijinSendInfo = null; |
| | | setFuliData(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |