导航菜单

页面标题

页面副标题

自健身 v3.3.4 - WebViewActivity.java 源代码

正在查看: 自健身 v3.3.4 应用的 WebViewActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mu.gymtrain.Activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.constraintlayout.widget.Group;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.mu.gymtrain.Adapter.AppointmentClassAdapter;
import com.mu.gymtrain.Adapter.ShopListAdapter;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Bean.AppointmentEntity;
import com.mu.gymtrain.Bean.AppointmentSubmitJsonEntity;
import com.mu.gymtrain.Bean.AppointmentSuccessBean;
import com.mu.gymtrain.Http.HttpCallBack;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.DateUtils;
import com.mu.gymtrain.Utils.DisplayUtil;
import com.mu.gymtrain.Utils.FinalTools;
import com.mu.gymtrain.Utils.PreferenceUtils;
import com.mu.gymtrain.view.DialogUtils;
import com.tencent.open.SocialConstants;
import java.util.ArrayList;
import java.util.List;

public class WebViewActivity extends BaseActivity implements BaseQuickAdapter.OnItemClickListener {
    public static final int CHECKED_ENABLE_NO = 3;
    public static final int CHECKED_ENABLE_YES = 2;
    public static final int CHECKED_ING = 1;
    private ShopListAdapter adapter;
    private DialogUtils appointmentClassDialog;
    private Group appointmentGroup;
    private AppointmentClassAdapter classAdapter;
    private TextView content;
    private String gymId;
    private String json;
    private ArrayList<AppointmentSubmitJsonEntity.JsonEntity> mJsonList;
    private DialogUtils mPositiveDialog;
    private RecyclerView recyclerView;

    @BindView(R.id.title_righttext)
    TextView rightText;
    private List<AppointmentEntity.DataBean.PreserveInfoBeanXX> shopClassInfoList;
    private PopupWindow shopWindow;
    private Group successGroup;
    private DialogUtils textDialog;

    @BindView(R.id.title_left)
    ImageView titleLeft;

    @BindView(R.id.title_middle)
    TextView titleMiddle;
    private String todayTime;
    private String tomorrowTime;
    private TextView tvDate;
    private TextView tvPositiveShopName;
    private TextView tvShopName;
    private TextView tvTime;
    private TextView tvTitle;
    private TextView tvToday;
    private TextView tvTomorrow;

    @BindView(R.id.web)
    WebView webView;
    private int mCurrentShopPosition = -1;
    private int CURRENT_DATE = 0;
    private int checkPosition = -1;
    private int prePosition = -1;
    private int nextPoition = -1;

    public int getContentLayout() {
        return R.layout.activity_webview;
    }

    public void initData() {
        initTextDialog();
        initShopPopWindow();
        initPositiveAppointmentDialog();
    }

    public void initView() {
        WebSettings settings = this.webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setAllowFileAccess(true);
        settings.setBuiltInZoomControls(false);
        settings.setSupportZoom(false);
        settings.setDisplayZoomControls(false);
        this.webView.addJavascriptInterface(this, "android");
        this.webView.setWebChromeClient(new WebChromeClient());
        this.webView.loadUrl(getIntent().getStringExtra(SocialConstants.PARAM_URL));
        String stringExtra = getIntent().getStringExtra(FinalTools.INTENT_COMMON);
        this.titleMiddle.setText(TextUtils.isEmpty(stringExtra) ? "详情页" : stringExtra);
        if (!TextUtils.isEmpty(stringExtra) && stringExtra.equals("关于我们")) {
            this.rightText.setText("用户协议");
            this.rightText.setTextColor(-1);
            this.rightText.setBackgroundResource(R.drawable.round_btn_red);
            ViewGroup.LayoutParams layoutParams = this.rightText.getLayoutParams();
            layoutParams.height = 70;
            layoutParams.width = 170;
            this.rightText.setLayoutParams(layoutParams);
        }
        this.webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(final WebView view, final String url) {
                WebViewActivity.this.dismissProgress();
                super.onPageFinished(view, url);
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                WebViewActivity.this.showProgress();
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                super.onReceivedError(view, request, error);
            }
        });
    }

    @OnClick({R.id.title_left, R.id.title_righttext})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == 2131297253) {
            finish();
        } else {
            if (id != 2131297257) {
                return;
            }
            Intent intent = new Intent((Context) this, (Class<?>) WebViewActivity.class);
            intent.putExtra(SocialConstants.PARAM_URL, "https://www.zijianshen.com/index.php/app/home/get_contract");
            intent.putExtra(FinalTools.INTENT_COMMON, getString(R.string.title_user_protocol));
            startActivity(intent);
        }
    }

    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.imgAppointmentClose:
                this.appointmentClassDialog.dismiss();
                finish();
                break;
            case R.id.imgPositiveClose:
                this.mPositiveDialog.dismiss();
                finish();
                break;
            case R.id.imgTextClose:
                this.textDialog.dismiss();
                finish();
                break;
            case R.id.tvAppointment:
                this.textDialog.dismiss();
                showAppointmentDialog();
                break;
            case R.id.tvPositiveAppointment:
                this.mPositiveDialog.dismiss();
                submit();
                break;
            case R.id.tvShopName:
                this.shopWindow.showAsDropDown(this.tvShopName, -((int) ((DisplayUtil.getScreenSize(this).x * 0.5f) / 3.0f)), 15);
                break;
            case R.id.tvSubmitAppointmentTime:
                this.tvPositiveShopName.setText(this.tvShopName.getText().toString());
                String date = this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(0).getDate();
                String date2 = this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(1).getDate();
                TextView textView = this.tvDate;
                if (this.CURRENT_DATE != 0) {
                    date = date2;
                }
                textView.setText(date);
                this.mJsonList = new ArrayList<>();
                for (int i = 0; i < getClassTimeList().size(); i++) {
                    if (getClassTimeList().get(i).getCheckClassState() == 1) {
                        String start_time = getClassTimeList().get(i).getStart_time();
                        AppointmentSubmitJsonEntity.JsonEntity jsonEntity = new AppointmentSubmitJsonEntity.JsonEntity();
                        jsonEntity.setGym_id(this.gymId);
                        jsonEntity.setStart_time(this.tvDate.getText().toString() + " " + start_time);
                        jsonEntity.setEnd_time(this.tvDate.getText().toString() + " " + getClassTimeList().get(i).getEnd_time());
                        this.mJsonList.add(jsonEntity);
                    }
                }
                ArrayList<AppointmentSubmitJsonEntity.JsonEntity> arrayList = this.mJsonList;
                if (arrayList == null || arrayList.size() == 0) {
                    showToast("请选择时间");
                    break;
                } else {
                    this.appointmentClassDialog.dismiss();
                    this.json = new Gson().toJson(this.mJsonList);
                    String start_time2 = this.mJsonList.get(0).getStart_time();
                    ArrayList<AppointmentSubmitJsonEntity.JsonEntity> arrayList2 = this.mJsonList;
                    this.tvTime.setText(start_time2.substring(10, start_time2.length()) + "-" + arrayList2.get(arrayList2.size() - 1).getEnd_time().substring(10, start_time2.length()));
                    this.mPositiveDialog.show();
                    break;
                }
                break;
            case R.id.tvToday:
                if (this.CURRENT_DATE == 1) {
                    this.checkPosition = -1;
                    this.prePosition = -1;
                    this.nextPoition = -1;
                    for (int i2 = 0; i2 < getClassTimeList().size(); i2++) {
                        getClassTimeList().get(i2).setCheckClassState(2);
                    }
                }
                this.CURRENT_DATE = 0;
                this.classAdapter.setDate(this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(0).getDate());
                this.tvToday.setTextColor(getResources().getColor(R.color.orange));
                this.tvTomorrow.setTextColor(getResources().getColor(R.color.main_text_color));
                this.classAdapter.setNewData(getClassTimeList());
                break;
            case R.id.tvTomorrow:
                if (this.CURRENT_DATE == 0) {
                    this.checkPosition = -1;
                    this.prePosition = -1;
                    this.nextPoition = -1;
                    for (int i3 = 0; i3 < getClassTimeList().size(); i3++) {
                        getClassTimeList().get(i3).setCheckClassState(2);
                    }
                }
                this.CURRENT_DATE = 1;
                this.classAdapter.setDate(this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(1).getDate());
                this.tvToday.setTextColor(getResources().getColor(R.color.main_text_color));
                this.tvTomorrow.setTextColor(getResources().getColor(R.color.orange));
                this.classAdapter.setNewData(getClassTimeList());
                break;
        }
    }

    private void submit() {
        showProgress();
        HttpHelper.getInstance().getRetrofitService(this).postAppointmentInfo(getToken(), this.json).enqueue(new HttpCallBack<AppointmentSuccessBean>() {
            @Override
            public void onSuccess(AppointmentSuccessBean appointmentSuccessBean, String json) {
                WebViewActivity.this.dismissProgress();
                if (appointmentSuccessBean.getCode() == 10000) {
                    WebViewActivity.this.showSuccessDialog();
                } else {
                    WebViewActivity.this.showToast(appointmentSuccessBean.getMessage());
                }
            }

            @Override
            public void onFail(String str) {
                WebViewActivity.this.dismissProgress();
                WebViewActivity.this.showToast(str);
            }
        });
    }

    public void showSuccessDialog() {
        this.successGroup.setVisibility(0);
        this.appointmentGroup.setVisibility(8);
        this.textDialog.show();
    }

    private void getGymsAppointmentInfo() {
        showProgress();
        HttpHelper.getInstance().getRetrofitService(this).getGymAppointment(getToken()).enqueue(new HttpCallBack<AppointmentEntity>() {
            @Override
            public void onSuccess(AppointmentEntity appointmentEntity, String json) {
                WebViewActivity.this.dismissProgress();
                if (appointmentEntity == null || appointmentEntity.getCode() != 10000) {
                    return;
                }
                WebViewActivity.this.shopClassInfoList = appointmentEntity.getData().getPreserve_info();
                WebViewActivity.this.adapter.setNewData(WebViewActivity.this.shopClassInfoList);
                WebViewActivity.this.tvTitle.setText("预约提示");
                WebViewActivity.this.content.setText(appointmentEntity.getData().getPreserve_notice());
                WebViewActivity.this.successGroup.setVisibility(8);
                WebViewActivity.this.appointmentGroup.setVisibility(0);
                WebViewActivity.this.textDialog.show();
            }

            @Override
            public void onFail(String str) {
                WebViewActivity.this.showToast(str);
                WebViewActivity.this.dismissProgress();
            }
        });
    }

    private void showAppointmentDialog() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_appointment_time_layout, (ViewGroup) null, false);
        this.appointmentClassDialog = new DialogUtils.Builder(this).setContentView(inflate).setOutCancelEnable(false).create();
        inflate.findViewById(R.id.imgAppointmentClose).setOnClickListener(this);
        inflate.findViewById(R.id.tvSubmitAppointmentTime).setOnClickListener(this);
        TextView textView = (TextView) inflate.findViewById(R.id.tvShopName);
        this.tvShopName = textView;
        textView.setOnClickListener(this);
        this.recyclerView = inflate.findViewById(2131297022);
        this.tvToday = (TextView) inflate.findViewById(R.id.tvToday);
        this.tvTomorrow = (TextView) inflate.findViewById(R.id.tvTomorrow);
        this.tvToday.setOnClickListener(this);
        this.tvTomorrow.setOnClickListener(this);
        String string = PreferenceUtils.getInstance().getString("currentgym", "");
        String string2 = PreferenceUtils.getInstance().getString("currentgymid", "");
        this.gymId = string2;
        if (!TextUtils.isEmpty(string2)) {
            int i = 0;
            while (true) {
                if (i >= this.shopClassInfoList.size()) {
                    break;
                }
                if (this.gymId.equals(this.shopClassInfoList.get(i).getGym_id())) {
                    this.mCurrentShopPosition = i;
                    break;
                }
                i++;
            }
        }
        if (!TextUtils.isEmpty(string) && this.mCurrentShopPosition != -1) {
            this.tvShopName.setText(string);
        } else {
            this.tvShopName.setText(this.shopClassInfoList.get(0).getGym_name());
            this.mCurrentShopPosition = 0;
            this.gymId = this.shopClassInfoList.get(0).getGym_id();
        }
        this.todayTime = this.shopClassInfoList.get(0).getPreserve_info().get(0).getDate();
        TextView textView2 = this.tvToday;
        StringBuilder sb = new StringBuilder();
        sb.append("丨 ");
        String str = this.todayTime;
        sb.append(str.substring(5, str.length()));
        sb.append("(今天)");
        textView2.setText(sb.toString());
        this.tomorrowTime = this.shopClassInfoList.get(0).getPreserve_info().get(1).getDate();
        this.tvTomorrow.setText("丨 " + this.tomorrowTime.substring(5, this.todayTime.length()) + "(明天)");
        AppointmentClassAdapter appointmentClassAdapter = new AppointmentClassAdapter(getClassTimeList());
        this.classAdapter = appointmentClassAdapter;
        appointmentClassAdapter.setDate(DateUtils.getCurrentTime("yyyy-MM-dd"));
        this.classAdapter.setOnItemClickListener(this);
        this.recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        this.recyclerView.setAdapter(this.classAdapter);
        this.appointmentClassDialog.show();
    }

    private void initPositiveAppointmentDialog() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_positive_appointment_layout, (ViewGroup) null, false);
        inflate.findViewById(R.id.imgPositiveClose).setOnClickListener(this);
        inflate.findViewById(R.id.tvPositiveAppointment).setOnClickListener(this);
        this.tvPositiveShopName = (TextView) inflate.findViewById(R.id.tvShopName);
        this.tvDate = (TextView) inflate.findViewById(R.id.tvDate);
        this.tvTime = (TextView) inflate.findViewById(R.id.tvTime);
        this.mPositiveDialog = new DialogUtils.Builder(this).setContentView(inflate).setOutCancelEnable(false).create();
    }

    public void initTextDialog() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_appointment_text_layout, (ViewGroup) null, false);
        inflate.findViewById(R.id.tvAppointment).setOnClickListener(this);
        inflate.findViewById(R.id.imgTextClose).setOnClickListener(this);
        this.tvTitle = (TextView) inflate.findViewById(R.id.tvTitle);
        this.content = (TextView) inflate.findViewById(2131297190);
        this.successGroup = inflate.findViewById(R.id.successGroup);
        this.appointmentGroup = inflate.findViewById(R.id.appointmentGroup);
        this.textDialog = new DialogUtils.Builder(this).setContentView(inflate).setOutCancelEnable(false).create();
    }

    private void initShopPopWindow() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.popwindow_ck_push_layout, (ViewGroup) null, false);
        RecyclerView findViewById = inflate.findViewById(2131297022);
        findViewById.setLayoutManager(new LinearLayoutManager(this));
        ShopListAdapter shopListAdapter = new ShopListAdapter();
        this.adapter = shopListAdapter;
        findViewById.setAdapter(shopListAdapter);
        this.adapter.setOnItemClickListener(this);
        PopupWindow popupWindow = new PopupWindow((Context) this);
        this.shopWindow = popupWindow;
        popupWindow.setContentView(inflate);
        PopupWindow popupWindow2 = this.shopWindow;
        double d = DisplayUtil.getScreenSize(this).x;
        Double.isNaN(d);
        popupWindow2.setWidth((int) (d * 0.5d));
        this.shopWindow.setHeight(-2);
        this.shopWindow.setOutsideTouchable(true);
        this.shopWindow.setBackgroundDrawable(new ColorDrawable(0));
        this.shopWindow.setAnimationStyle(R.style.popwindowUpAnim);
    }

    @JavascriptInterface
    public void makeAnAppointment() {
        getGymsAppointmentInfo();
    }

    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        if (adapter instanceof AppointmentClassAdapter) {
            int i = this.checkPosition;
            int i2 = 0;
            if (i == -1) {
                this.checkPosition = position;
                getClassTimeList().get(position).setCheckClassState(1);
                while (i2 < adapter.getData().size()) {
                    if (position - 1 != i2 && position + 1 != i2 && position != i2) {
                        getClassTimeList().get(i2).setCheckClassState(3);
                    }
                    i2++;
                }
            } else if (i == position) {
                int i3 = this.prePosition;
                if (i3 != -1) {
                    this.checkPosition = i3;
                    this.prePosition = -1;
                    if (i3 - 1 >= 0) {
                        getClassTimeList().get(this.checkPosition - 1).setCheckClassState(2);
                    }
                } else {
                    int i4 = this.nextPoition;
                    if (i4 != -1) {
                        this.checkPosition = i4;
                        this.nextPoition = -1;
                        if (i4 + 1 < getClassTimeList().size()) {
                            getClassTimeList().get(this.checkPosition + 1).setCheckClassState(2);
                        }
                    } else {
                        this.checkPosition = -1;
                        while (i2 < getClassTimeList().size()) {
                            getClassTimeList().get(i2).setCheckClassState(2);
                            i2++;
                        }
                    }
                }
                getClassTimeList().get(position).setCheckClassState(2);
            } else {
                int i5 = this.prePosition;
                if (i5 == -1 && i - 1 == position) {
                    this.prePosition = position;
                    getClassTimeList().get(position).setCheckClassState(1);
                    while (i2 < adapter.getData().size()) {
                        if (this.prePosition != i2 && i2 != this.checkPosition) {
                            getClassTimeList().get(i2).setCheckClassState(3);
                        }
                        i2++;
                    }
                } else if (i5 == position) {
                    this.prePosition = -1;
                    getClassTimeList().get(position).setCheckClassState(2);
                    if (this.checkPosition + 1 < getClassTimeList().size()) {
                        getClassTimeList().get(this.checkPosition + 1).setCheckClassState(2);
                    }
                } else {
                    int i6 = this.nextPoition;
                    if (i6 == -1 && i + 1 == position) {
                        this.nextPoition = position;
                        getClassTimeList().get(position).setCheckClassState(1);
                        while (i2 < adapter.getData().size()) {
                            if (this.nextPoition != i2 && i2 != this.checkPosition) {
                                getClassTimeList().get(i2).setCheckClassState(3);
                            }
                            i2++;
                        }
                    } else if (i6 == position) {
                        this.nextPoition = -1;
                        getClassTimeList().get(position).setCheckClassState(2);
                        if (this.checkPosition - 1 >= 0) {
                            getClassTimeList().get(this.checkPosition - 1).setCheckClassState(2);
                        }
                    }
                }
            }
            this.classAdapter.notifyDataSetChanged();
            return;
        }
        if (adapter instanceof ShopListAdapter) {
            this.mCurrentShopPosition = position;
            this.shopWindow.dismiss();
            AppointmentEntity.DataBean.PreserveInfoBeanXX preserveInfoBeanXX = (AppointmentEntity.DataBean.PreserveInfoBeanXX) adapter.getData().get(position);
            this.gymId = preserveInfoBeanXX.getGym_id();
            this.tvShopName.setText(preserveInfoBeanXX.getGym_name());
            if (this.CURRENT_DATE == 0) {
                this.tvToday.setTextColor(getResources().getColor(R.color.orange));
                this.tvTomorrow.setTextColor(getResources().getColor(R.color.main_text_color));
            } else {
                this.tvToday.setTextColor(getResources().getColor(R.color.main_text_color));
                this.tvTomorrow.setTextColor(getResources().getColor(R.color.orange));
            }
            this.tvToday.setText(getTodayTime());
            this.tvTomorrow.setText(getTomorrowTime());
            this.classAdapter.setNewData(getClassTimeList());
        }
    }

    List<AppointmentEntity.DataBean.PreserveInfoBeanXX> getShopList() {
        return this.shopClassInfoList;
    }

    List<AppointmentEntity.DataBean.PreserveInfoBeanXX.PreserveInfoBeanX.PreserveInfoBean> getTodayList() {
        return this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(0).getPreserve_info();
    }

    List<AppointmentEntity.DataBean.PreserveInfoBeanXX.PreserveInfoBeanX.PreserveInfoBean> getTomorrowList() {
        return this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(1).getPreserve_info();
    }

    String getTodayTime() {
        String date = this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(0).getDate();
        return "丨 " + date.substring(5, date.length()) + "(今天)";
    }

    String getTomorrowTime() {
        String date = this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(1).getDate();
        return "丨 " + date.substring(5, date.length()) + "(明天)";
    }

    List<AppointmentEntity.DataBean.PreserveInfoBeanXX.PreserveInfoBeanX.PreserveInfoBean> getClassTimeList() {
        return this.shopClassInfoList.get(this.mCurrentShopPosition).getPreserve_info().get(this.CURRENT_DATE).getPreserve_info();
    }
}