| | |
| | | package com.dayu.pipirrapp.fragment; |
| | | |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageInfo; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Bundle; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.dayu.pipirrapp.activity.ChangePSActivity; |
| | | import com.dayu.pipirrapp.activity.InspectListActivity; |
| | | import com.dayu.pipirrapp.activity.IssueListActivity; |
| | | import com.dayu.pipirrapp.activity.LoginActivity; |
| | | import com.dayu.pipirrapp.bean.db.LoginBean; |
| | | import com.dayu.pipirrapp.dao.DaoSingleton; |
| | | import com.dayu.pipirrapp.databinding.FragmentMyBinding; |
| | | import com.dayu.pipirrapp.tool.InspectionUtils; |
| | | import com.dayu.pipirrapp.utils.CleanDataUtils; |
| | | import com.dayu.pipirrapp.utils.CommonKeyName; |
| | | import com.dayu.pipirrapp.utils.SharedPreferencesHelper; |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.view.ConfirmDialog; |
| | | import com.dayu.pipirrapp.view.TipUtil; |
| | | import com.jeremyliao.liveeventbus.LiveEventBus; |
| | | |
| | | /** |
| | | * author: zuo |
| | | * Date: 2023/12/20 |
| | | * Time: 10:16 |
| | | * 备注:我的 |
| | | */ |
| | | public class MyFragment extends BaseFragment{ |
| | | public class MyFragment extends BaseFragment { |
| | | FragmentMyBinding binding; |
| | | |
| | | @Nullable |
| | | @Override |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | binding = FragmentMyBinding.inflate(inflater, container, false); |
| | | initView(); |
| | | initData(); |
| | | return binding.getRoot(); |
| | | } |
| | | |
| | | private void initView() { |
| | | binding.changePSRL.setOnClickListener(v -> { |
| | | Intent intent = new Intent(MyFragment.this.getContext(), ChangePSActivity.class); |
| | | MyFragment.this.getActivity().startActivity(intent); |
| | | }); |
| | | //退出登录 |
| | | binding.loginOutRL.setOnClickListener((v) -> { |
| | | int inspectionState = SharedPreferencesHelper.getInstance(this.getContext()).get(CommonKeyName.inspectionState, 0); |
| | | if (inspectionState == InspectionUtils.NO_INSPECTION) { |
| | | ConfirmDialog confirmDialog = new ConfirmDialog(MyFragment.this.getActivity(), "确定退出吗?", (confirmDialog1, v12) -> { |
| | | try { |
| | | confirmDialog1.dismiss(); |
| | | CleanDataUtils.cleanUserData(MyFragment.this.getContext()); |
| | | Intent intent = new Intent(MyFragment.this.getContext(), LoginActivity.class); |
| | | MyFragment.this.getActivity().startActivity(intent); |
| | | MyFragment.this.getActivity().finish(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | confirmDialog.show(); |
| | | } else { |
| | | TipUtil.show(MyFragment.this.getActivity(), "您还未结束巡检,请结束巡检后退出!"); |
| | | } |
| | | |
| | | |
| | | }); |
| | | LoginBean loginBean = DaoSingleton.getInstance(MyFragment.this.getContext()).loginDao().findFirst(); |
| | | if (loginBean != null) { |
| | | binding.name.setText(loginBean.getName()); |
| | | binding.phone.setText(loginBean.getPhone()); |
| | | } |
| | | // 清除缓存 |
| | | binding.cleanDataRL.setOnClickListener(v -> { |
| | | ConfirmDialog confirmDialog = new ConfirmDialog(MyFragment.this.getActivity(), "确定清除缓存吗?", (dialog, v1) -> { |
| | | try { |
| | | dialog.dismiss(); |
| | | CleanDataUtils.cleanData(MyFragment.this.getContext()); |
| | | ToastUtil.showToast(MyFragment.this.getActivity(), "清除成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | confirmDialog.show(); |
| | | |
| | | }); |
| | | |
| | | binding.issueListRL.setOnClickListener(v -> { |
| | | Intent intent = new Intent(MyFragment.this.getContext(), IssueListActivity.class); |
| | | MyFragment.this.getActivity().startActivity(intent); |
| | | }); |
| | | binding.refreshDataRL.setOnClickListener(v -> { |
| | | ConfirmDialog confirmDialog = new ConfirmDialog(MyFragment.this.getActivity(), "确定更新本地数据吗?", (confirmDialog1, v12) -> { |
| | | try { |
| | | LiveEventBus.get(CommonKeyName.refreshData).post(true); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | confirmDialog.show(); |
| | | // 发送刷新事件通知MapFragment刷新数据 |
| | | |
| | | }); |
| | | binding.inspectListRL.setOnClickListener(v -> { |
| | | Intent intent = new Intent(MyFragment.this.getContext(), InspectListActivity.class); |
| | | MyFragment.this.getActivity().startActivity(intent); |
| | | }); |
| | | binding.versionRL.setOnClickListener(v -> { |
| | | }); |
| | | } |
| | | |
| | | private void initData() { |
| | | LoginBean loginBean = DaoSingleton.getInstance(MyFragment.this.getContext()).loginDao().findFirst(); |
| | | if (loginBean != null) { |
| | | binding.name.setText(loginBean.getName()); |
| | | binding.phone.setText(loginBean.getPhone()); |
| | | } |
| | | // |
| | | try { |
| | | PackageInfo packageInfo = MyFragment.this.getActivity().getPackageManager().getPackageInfo(MyFragment.this.getActivity().getPackageName(), 0); |
| | | binding.versionText.setText(packageInfo.versionName); |
| | | } catch (PackageManager.NameNotFoundException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | |
| | | } |
| | | } |