会员到期提醒

会员到期提醒:还有一天、当天,一个月(七天一提醒) 等。

 //会员提醒   19.1.15
                            try {
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
//                                Date date = sdf.parse(bean.getData().get(0).getBeginDate());
                                Date date = new Date();
                                Date date1 = sdf.parse(bean.getData().get(0).getEndDate());
                                long month = getDifferMonth(date, date1);
                                int days = (int) ((date1.getTime() - date.getTime()) / (1000 * 3600 * 24));

                                if (month < 1 ){
                                    long currentClickTime = System.currentTimeMillis();
                                    if (date1.getDate() - date.getDate() == 1) {//还有一天会员到期
                                        if (SPUtils.getPrefLong(getActivity().getApplicationContext(), "TIME_1_DAYStoday", 0) != date.getDate()) {
                                            showMemberTime("会员还有" + (date1.getDate() - date.getDate()) + "天到期,请尽快续费",(date1.getDate() - date.getDate()));// 2018-03-29
                                        }
                                        SPUtils.setSettingLong(getActivity().getApplicationContext(), "TIME_1_DAYSNew", currentClickTime);
                                    } else if (date1.getDate() - date.getDate() == 0) {//会员到期当天
                                        if (SPUtils.getPrefLong(getActivity().getApplicationContext(), "TIME_0_DAYStoday", 0) != date.getDate()) {
                                            showMemberTime("会员今天到期,请尽快续费",0);// 2019-1-15
                                        }
                                        SPUtils.setSettingLong(getActivity().getApplicationContext(), "TIME_0_DAYSNew", currentClickTime);
                                    } else {
                                        //判断是否是已经间隔了7天以后,再显示该dialog
                                        long lastClickTime = SPUtils.getPrefLong(getActivity().getApplicationContext(), "TIME_7_DAYSNew", 0);
                                        if (isSevenDayClick(lastClickTime)) {
                                        } else {
                                            if (SPUtils.getPrefLong(getActivity().getApplicationContext(), "TIME_7_DAYStoday", 0) != date.getDate()) {
                                                showMemberTime("会员还有" + (date1.getDate() - date.getDate()) + "天到期,请尽快续费",(date1.getDate() - date.getDate()));// 2018-03-29
                                            }
//                                            long currentClickTime = System.currentTimeMillis();
                                            SPUtils.setSettingLong(getActivity().getApplicationContext(), "TIME_7_DAYSNew", currentClickTime);
                                        }
                                    }
                                } else if (month == 1) {
                                    if (SPUtils.getPrefLong(getActivity().getApplicationContext(), "TIME_7_DAYStoday", 0) != date.getDate()) {
                                        showMemberTime("会员还有" + ((getCurrentMonthLastDay()- date.getDate())+date1.getDate()) + "天到期,请尽快续费",((getCurrentMonthLastDay()- date.getDate())+date1.getDate()) );// 2018-03-29
                                    }
                                }
                                Log.e("====-=--",(getCurrentMonthLastDay()- date.getDate())+date1.getDate()+"");
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

 

 /**
     * 取得当月天数
     * */
    public   int getCurrentMonthLastDay()
    {
        Calendar a = Calendar.getInstance();
        a.set(Calendar.DATE, 1);//把日期设置为当月第一天
        a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
        int maxDate = a.get(Calendar.DATE);
        return maxDate;
    }

    private void showMemberTime( String time,int days) {
        mDialogTime = new Dialog(getActivity());
        mDialogTime.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mDialogTime.setCancelable(true);//点击返回不消失
        mDialogTime.setCanceledOnTouchOutside(true);//点击外部不消失
        Window window = mDialogTime.getWindow();
        window.setContentView(R.layout.dialog_to_dai_li);
        TextView tvContent = (TextView) window.findViewById(R.id.dialog_text);
        TextView tvConfirm = window.findViewById(R.id.dialog_sure);
        View tvCancel = window.findViewById(R.id.dialog_cancel);
        tvContent.setText(time);


        mDialogTime.show();
        if(days == 0){
            SPUtils.setSettingLong(getActivity().getApplicationContext(), "TIME_0_DAYStoday", new Date().getDate());

        }else if(days == 1){
            SPUtils.setSettingLong(getActivity().getApplicationContext(), "TIME_1_DAYStoday", new Date().getDate());

        }else{
            SPUtils.setSettingLong(getActivity().getApplicationContext(), "TIME_7_DAYStoday", new Date().getDate());

        }

        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialogTime.dismiss();
            }
        });

        tvCancel.setVisibility(View.GONE);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialogTime.dismiss();
            }
        });
    }

    boolean isSevenDayClick(long lastClickTime) {
        boolean flag = true;
        long currentClickTime = System.currentTimeMillis();
        if ((currentClickTime - lastClickTime) >= MIN_DELAY_TIME) {
            flag = false;
        }
        return flag;
    }
    /**
     * 获取两个日期的月数差
     *
     * @param fromDate
     * @param toDate
     * @return
     */
    public long getDifferMonth(Date fromDate, Date toDate) {
        Calendar fromDateCal = Calendar.getInstance();
        Calendar toDateCal = Calendar.getInstance();
        fromDateCal.setTime(fromDate);
        toDateCal.setTime(toDate);

        int fromYear = fromDateCal.get(Calendar.YEAR);
        int toYear = toDateCal.get((Calendar.YEAR));
        if (fromYear == toYear) {
            return Math.abs(fromDateCal.get(Calendar.MONTH) - toDateCal.get(Calendar.MONTH));
        } else {
            int fromMonth = 12 - (fromDateCal.get(Calendar.MONTH) + 1);
            int toMonth = toDateCal.get(Calendar.MONTH) + 1;
            return Math.abs(toYear - fromYear - 1) * 12 + fromMonth + toMonth;
        }
    }

 

 

  • 2
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值