CloudGoogleFragment.java 源代码


package activity.cloud1.fragment;

import activity.cloud.api.GoogleApiFactory;
import activity.cloud.bean.PieData;
import activity.cloud.re.HttpThrowable;
import activity.cloud.re.MyCallBack;
import activity.cloud.utils.DateUtils;
import activity.cloud.view.MyChart;
import activity.cloud1.CloudInfoGoogleActivity;
import activity.cloud1.activity.GoogleCloudPlaybackActivity;
import activity.cloud1.bean.GetGoogleServiceBack;
import activity.cloud1.bean.GetGoogleServiceReq;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import base.HiFragment;
import bean.MyCamera;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import com.hichip.campro.R;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.meizu.cloud.pushsdk.notification.model.AdvanceSetting;
import com.meizu.cloud.pushsdk.notification.model.AdvertisementOption;
import common.HiDataValue;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import utils.HiLogcatUtil;
import utils.TimeUtil;

public class CloudGoogleFragment extends HiFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private static final int ECS_CALL_BACK = 1114;
    private static final int OSS_CALL_BACK = 1115;
    public static boolean isRefresh = false;
    public static boolean isUpdatePackage = false;

    private CloudInfoGoogleActivity f978activity;
    private int copyStartPosition;
    private String endTime;
    private boolean fragmentCreated;
    private View layoutView;
    LinearLayout llCloudInfo;
    LinearLayout llDaysInfo;
    LinearLayout llUseSpace;
    LinearLayout ll_content;
    private MyCamera mCamera;
    private String mParam1;
    MyChart pieChart;
    ProgressBar process;
    RelativeLayout rlTimesInfo;
    private long serviceTime;
    private String startTime;
    TextView tvDesc;
    TextView tvGoFee;
    TextView tvInfoNo;
    TextView tvLastSpace;
    TextView tvLastSpacePre;
    TextView tvLaveDays;
    TextView tvLaveTime;
    TextView tvOrderList;
    TextView tvSearchTime;
    TextView tvTime;
    TextView tvTotalSpace;
    TextView tvUseSpace;
    TextView tvUseSpacePer;
    TextView tv_nothing;
    Unbinder unbinder;
    private String uuid;
    public int videoSaveDays = 0;
    float useSpace = 0.0f;
    private boolean mFirst = true;
    byte[] cloudSizeInfo = new byte[64];
    private SimpleDateFormat format = new SimpleDateFormat(TimeUtil.FORMAT_DATE_TIME_FULL);
    private DecimalFormat numberFormat = new DecimalFormat("#0.00");
    private boolean noDBFile = false;

    public static CloudGoogleFragment newInstance(String str, CloudInfoGoogleActivity cloudInfoGoogleActivity) {
        CloudGoogleFragment cloudGoogleFragment = new CloudGoogleFragment();
        Bundle bundle = new Bundle();
        bundle.putString(ARG_PARAM1, str);
        cloudGoogleFragment.f978activity = cloudInfoGoogleActivity;
        cloudGoogleFragment.setArguments(bundle);
        return cloudGoogleFragment;
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (getArguments() != null) {
            this.mParam1 = getArguments().getString(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_cloud_info_google, viewGroup, false);
        this.layoutView = inflate;
        this.unbinder = ButterKnife.bind(this, inflate);
        initView();
        initData();
        setListener();
        this.fragmentCreated = true;
        return this.layoutView;
    }

    private void setListener() {
        this.tvGoFee.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CloudGoogleFragment.this.lambda$setListener$0$CloudGoogleFragment(view);
            }
        });
        this.tvOrderList.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CloudGoogleFragment.this.lambda$setListener$1$CloudGoogleFragment(view);
            }
        });
    }

    public void lambda$setListener$0$CloudGoogleFragment(View view) {
        this.f978activity.viewPager.setCurrentItem(1, true);
    }

    public void lambda$setListener$1$CloudGoogleFragment(View view) {
        if (this.mCamera == null || getContext() == null) {
            return;
        }
        Intent intent = new Intent(getContext(), (Class<?>) GoogleCloudPlaybackActivity.class);
        intent.putExtra(HiDataValue.EXTRAS_KEY_UID, this.mCamera.getUid());
        getContext().startActivity(intent);
    }

    private void initView() {
        if (!TextUtils.isEmpty(this.mParam1)) {
            this.uuid = this.mParam1;
        }
        if (TextUtils.isEmpty(this.uuid)) {
            return;
        }
        for (MyCamera myCamera : HiDataValue.CameraList) {
            if (this.uuid.equals(myCamera.getUid())) {
                this.mCamera = myCamera;
                return;
            }
        }
    }

    @Override
    public void setUserVisibleHint(boolean z) {
        super.setUserVisibleHint(z);
        if (z && this.fragmentCreated) {
            if (this.videoSaveDays == 0 || isUpdatePackage) {
                isUpdatePackage = false;
                initData();
            }
        }
    }

    private void initData() {
        showJuHuaDialog();
        if (this.tvInfoNo == null) {
            return;
        }
        int i = 1000;
        if (Locale.getDefault().getLanguage().equals("zh")) {
            i = Locale.getDefault().getCountry().equals("CN") ? 1001 : 1003;
        } else if (Locale.getDefault().getLanguage().equals("de")) {
            i = 1002;
        } else if (Locale.getDefault().getLanguage().equals("fr")) {
            i = 1004;
        } else if (Locale.getDefault().getLanguage().equals("es")) {
            i = 1005;
        } else if (Locale.getDefault().getLanguage().equals(AdvertisementOption.PRIORITY_VALID_TIME)) {
            i = 1006;
        } else if (Locale.getDefault().getLanguage().equals("ko")) {
            i = 1007;
        } else if (Locale.getDefault().getLanguage().equals("ja")) {
            i = 1008;
        } else if (Locale.getDefault().getLanguage().equals(AdvanceSetting.NETWORK_TYPE)) {
            i = 1009;
        } else if (Locale.getDefault().getLanguage().equals("tr")) {
            i = 1010;
        } else if (Locale.getDefault().getLanguage().equals("vi")) {
            i = 1012;
        } else if (Locale.getDefault().getLanguage().equals("pl")) {
            i = 1013;
        } else if (Locale.getDefault().getLanguage().equals("ru")) {
            i = 1014;
        }
        HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, i + "");
        GetGoogleServiceReq getGoogleServiceReq = new GetGoogleServiceReq(this.uuid, i, DateUtils.getDate());
        HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, getGoogleServiceReq.toString());
        GoogleApiFactory.getApi().GetGoogleService(getGoogleServiceReq).enqueue(new MyCallBack<GetGoogleServiceBack>() {
            @Override
            public void onSuccess(GetGoogleServiceBack getGoogleServiceBack) {
                Date date;
                Date date2;
                HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, getGoogleServiceBack.toString());
                if (CloudGoogleFragment.this.tvDesc == null) {
                    return;
                }
                CloudGoogleFragment.this.mCamera.setVideoSaveDays(getGoogleServiceBack.getVideoSaveDays());
                CloudGoogleFragment.isRefresh = false;
                CloudGoogleFragment.this.videoSaveDays = getGoogleServiceBack.getVideoSaveDays();
                CloudGoogleFragment.this.startTime = getGoogleServiceBack.getStartDate();
                CloudGoogleFragment.this.endTime = getGoogleServiceBack.getEndDate();
                CloudGoogleFragment.this.tvInfoNo.setVisibility(8);
                Date date3 = null;
                try {
                    date = CloudGoogleFragment.this.format.parse(getGoogleServiceBack.getStartDate());
                    try {
                        date2 = CloudGoogleFragment.this.format.parse(getGoogleServiceBack.getEndDate());
                        try {
                            date3 = CloudGoogleFragment.this.format.parse(getGoogleServiceBack.getDate());
                        } catch (ParseException e) {
                            e = e;
                            e.printStackTrace();
                            CloudGoogleFragment.this.dismissJuHuaDialog();
                            CloudGoogleFragment.this.tvDesc.setTextColor(ViewCompat.MEASURED_STATE_MASK);
                            CloudGoogleFragment.this.tvDesc.setText(getGoogleServiceBack.getServiceDesc());
                            if (date2 != null) {
                                return;
                            } else {
                                return;
                            }
                        }
                    } catch (ParseException e2) {
                        e = e2;
                        date2 = null;
                    }
                } catch (ParseException e3) {
                    e = e3;
                    date = null;
                    date2 = null;
                }
                if (date2 != null || date3 == null) {
                    return;
                }
                CloudGoogleFragment.this.serviceTime = date3.getTime() + 28800000;
                if (date2.getTime() > date3.getTime() + 28800000) {
                    CloudGoogleFragment.this.mCamera.setCloudEndTime(getGoogleServiceBack.getEndDate());
                    CloudGoogleFragment.this.tvDesc.setTextColor(ViewCompat.MEASURED_STATE_MASK);
                    CloudGoogleFragment.this.tvDesc.setText(getGoogleServiceBack.getServiceDesc());
                    if (!CloudGoogleFragment.this.noDBFile) {
                        CloudGoogleFragment.this.initPieChart(date, date2);
                        return;
                    } else {
                        CloudGoogleFragment.this.useSpace = 0.0f;
                        CloudGoogleFragment.this.initPieChart(date, date2);
                        return;
                    }
                }
                CloudGoogleFragment.this.tvDesc.setTextColor(Color.parseColor("#d38487"));
                CloudGoogleFragment.this.tvDesc.setText(CloudGoogleFragment.this.getString(R.string.package_timeout_title) + getGoogleServiceBack.getServiceDesc());
                CloudGoogleFragment cloudGoogleFragment = CloudGoogleFragment.this;
                cloudGoogleFragment.useSpace = (float) cloudGoogleFragment.videoSaveDays;
                CloudGoogleFragment.this.initPieChart(date, date2);
            }

            @Override
            public void onError(Throwable th, String str) {
                HiLogcatUtil.d("errMsg: " + str);
                if (th instanceof HttpThrowable) {
                    CloudGoogleFragment.this.dismissJuHuaDialog();
                    if (CloudGoogleFragment.this.tvInfoNo == null || CloudGoogleFragment.this.tvOrderList == null || CloudGoogleFragment.this.llDaysInfo == null || CloudGoogleFragment.this.llUseSpace == null || CloudGoogleFragment.this.tvGoFee == null || CloudGoogleFragment.this.ll_content == null) {
                        return;
                    }
                    CloudGoogleFragment.this.tvInfoNo.setVisibility(0);
                    CloudGoogleFragment.this.tvOrderList.setVisibility(8);
                    CloudGoogleFragment.this.llDaysInfo.setVisibility(8);
                    CloudGoogleFragment.this.llUseSpace.setVisibility(8);
                    CloudGoogleFragment.this.tvGoFee.setText(CloudGoogleFragment.this.getString(R.string.buy_package_now));
                    CloudGoogleFragment.this.ll_content.setVisibility(0);
                }
            }
        });
    }

    public void initPieChart(Date date, Date date2) {
        int i;
        double d;
        this.llDaysInfo.setVisibility(0);
        if (this.videoSaveDays <= 0) {
            return;
        }
        dismissJuHuaDialog();
        this.tv_nothing.setVisibility(8);
        this.ll_content.setVisibility(0);
        Date convertTimezone = convertTimezone(date, TimeZone.getTimeZone("GMT+8:00"), Calendar.getInstance().getTimeZone());
        Date convertTimezone2 = convertTimezone(date2, TimeZone.getTimeZone("GMT+8:00"), Calendar.getInstance().getTimeZone());
        String format = this.format.format(convertTimezone);
        String format2 = this.format.format(convertTimezone2);
        this.tvTime.setText(getString(R.string.package_start_time) + format + "—" + format2 + displayTimeZone(Calendar.getInstance().getTimeZone()));
        String format3 = this.format.format(convertTimezone(new Date(this.serviceTime), TimeZone.getTimeZone("GMT+8:00"), Calendar.getInstance().getTimeZone()));
        this.tvSearchTime.setText(getString(R.string.package_check_time) + format3 + displayTimeZone(Calendar.getInstance().getTimeZone()));
        int i2 = -1;
        try {
            i = DateUtils.daysBetween(this.startTime, this.endTime);
            try {
                i2 = DateUtils.daysBetween(format3, this.endTime);
            } catch (ParseException e) {
                e = e;
                e.printStackTrace();
                int i3 = i * 1000;
                this.process.setMax(i3);
                if (i2 <= 0) {
                }
                ArrayList arrayList = new ArrayList();
                arrayList.add(new PieData(this.useSpace, R.color.use_color));
                arrayList.add(new PieData(this.videoSaveDays - this.useSpace, R.color.color_state_onling));
                this.pieChart.setmStartAngle(270.0f);
                this.pieChart.setData(arrayList);
                int i4 = this.videoSaveDays;
                d = i4 - this.useSpace;
                if (d < 0.0d) {
                }
                String str = this.numberFormat.format((this.useSpace / this.videoSaveDays) * 100.0f) + "%";
                float f = 1.0f - (this.useSpace / this.videoSaveDays);
                String str2 = this.numberFormat.format(f * 100.0f) + "%";
                if (this.useSpace < 0.01f) {
                }
            }
        } catch (ParseException e2) {
            e = e2;
            i = 0;
        }
        int i32 = i * 1000;
        this.process.setMax(i32);
        if (i2 <= 0) {
            this.process.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_horizontal_list));
            int i5 = i - i2;
            if (new BigDecimal(Double.valueOf(i5).toString()).divide(new BigDecimal(Double.valueOf(i).toString()), 2, RoundingMode.HALF_UP).floatValue() < 0.02f) {
                this.process.setProgress(0);
            } else {
                setProcess(this.process, i5 * 1000);
            }
            this.tvLaveDays.setText(i2 + getString(R.string.day));
            this.tvOrderList.setVisibility(0);
        } else {
            this.llUseSpace.setVisibility(8);
            this.tvLaveDays.setText(PushConstants.PUSH_TYPE_NOTIFY + getString(R.string.day));
            this.process.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_horizontal_list_red));
            setProcess(this.process, i32);
        }
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(new PieData(this.useSpace, R.color.use_color));
        arrayList2.add(new PieData(this.videoSaveDays - this.useSpace, R.color.color_state_onling));
        this.pieChart.setmStartAngle(270.0f);
        this.pieChart.setData(arrayList2);
        int i42 = this.videoSaveDays;
        d = i42 - this.useSpace;
        if (d < 0.0d) {
            this.useSpace = i42 * 0.01f;
            d = i42 * 0.99f;
        }
        String str3 = this.numberFormat.format((this.useSpace / this.videoSaveDays) * 100.0f) + "%";
        float f2 = 1.0f - (this.useSpace / this.videoSaveDays);
        String str22 = this.numberFormat.format(f2 * 100.0f) + "%";
        if (this.useSpace < 0.01f) {
            this.tvUseSpace.setText(this.numberFormat.format(this.useSpace) + " GB");
            this.tvUseSpacePer.setText(str3);
            this.tvLastSpace.setText(this.numberFormat.format(d) + " GB");
            this.tvLastSpacePre.setText(str22);
            this.tvTotalSpace.setText(getString(R.string.total_size) + " " + this.videoSaveDays + " GB");
            return;
        }
        this.tvUseSpace.setText(this.numberFormat.format(this.useSpace * 1024.0f) + " MB");
        this.tvUseSpacePer.setText(str3);
        this.tvLastSpace.setText(this.numberFormat.format(((this.videoSaveDays * 1024) - (this.useSpace * 1024.0f)) / 1024.0f) + " GB");
        this.tvLastSpacePre.setText(str22);
        this.tvTotalSpace.setText(getString(R.string.total_size) + " " + this.videoSaveDays + " GB");
    }

    private void setProcess(final ProgressBar progressBar, int i) {
        ValueAnimator duration = ValueAnimator.ofInt(0, i).setDuration(1000L);
        duration.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                progressBar.setProgress(((Integer) valueAnimator.getAnimatedValue()).intValue());
            }
        });
        duration.start();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        HiLogcatUtil.iTag(HiLogcatUtil.TAG_Google, "CloudGoogleFragment onDestroyView ");
        this.unbinder.unbind();
    }

    public Date convertTimezone(Date date, TimeZone timeZone, TimeZone timeZone2) {
        Calendar calendar = Calendar.getInstance();
        long time = date.getTime();
        calendar.setTimeZone(timeZone);
        calendar.setTimeInMillis(time);
        int i = calendar.get(15);
        calendar.setTimeZone(timeZone2);
        calendar.setTimeInMillis(time);
        return new Date((time + (calendar.get(15) + calendar.get(16))) - i);
    }

    private String displayTimeZone(TimeZone timeZone) {
        long hours = TimeUnit.MILLISECONDS.toHours(timeZone.getRawOffset());
        long abs = Math.abs(TimeUnit.MILLISECONDS.toMinutes(timeZone.getRawOffset()) - TimeUnit.HOURS.toMinutes(hours));
        return hours > 0 ? String.format("(GMT+%d:%02d)", Long.valueOf(hours), Long.valueOf(abs)) : String.format("(GMT%d:%02d)", Long.valueOf(hours), Long.valueOf(abs));
    }
}