Browse Source

添加清理缓存功能

ychk 4 weeks ago
parent
commit
4884f8243d

+ 2 - 2
app/src/main/java/com/tofly/yxpc/ui/activity/SettingActivity.java

@@ -66,7 +66,7 @@ public class SettingActivity extends PhotoActivity {
         if (!TextUtils.isEmpty(NetWorkUrl.getFileUrl(AccountManager.getAvatar()))) {
             Glide.with(this)
                     .load(NetWorkUrl.getFileUrl(AccountManager.getAvatar()))
-                    .apply(new RequestOptions().error(R.mipmap.my_heard))
+                    .apply(new RequestOptions().error(R.mipmap.icon_my_heard))
                     .into(binding.circleImgPortrait);
         }
         binding.tvName.setText(AccountManager.getUserRealName() == null ? "" : AccountManager.getUserRealName());
@@ -157,7 +157,7 @@ public class SettingActivity extends PhotoActivity {
             if (!TextUtils.isEmpty(fileResponse.getFileName())) {
                 Glide.with(this)
                         .load(NetWorkUrl.getFileUrl(fileResponse.getFileName()))
-                        .apply(new RequestOptions().error(R.mipmap.my_heard))
+                        .apply(new RequestOptions().error(R.mipmap.icon_my_heard))
                         .into(binding.circleImgPortrait);
                 Map<String, Object> map = new HashMap<>();
                 map.put("realName", AccountManager.getUserRealName());

+ 1 - 1
app/src/main/java/com/tofly/yxpc/ui/adapter/BigPictureAdapter.java

@@ -108,7 +108,7 @@ public class BigPictureAdapter extends BaseQuickAdapter<FileBean, BaseViewHolder
                     tvFile.setVisibility(View.GONE);
                     imageView.setVisibility(View.VISIBLE);
                     //加载默认音频文件图标
-                    imageView.setImageResource(R.mipmap.record_file);
+                    imageView.setImageResource(R.mipmap.icon_record_file);
                     imageView.setOnClickListener(v -> {
                         //点击音频实现播放
                         if (mp3Player == null) {

+ 47 - 1
app/src/main/java/com/tofly/yxpc/ui/fragment/IndexFragment.java

@@ -343,11 +343,57 @@ public class IndexFragment extends LatteDelegate {
     public <T> void getResultOne(T response) {
         new Thread(() -> {
             if (response != null) {
-                DaoUtilsStore.getInstance().getWaterMeterTaskEntityDbUtils().delete(DaoUtilsStore.getInstance().getWaterMeterTaskEntityDbUtils().queryByQueryBuilder(WaterMeterTaskEntityDao.Properties.CheckUser.eq(AccountManager.getUserId())));
                 List<WaterMeterTaskEntity> waterMeterTaskEntities = (List<WaterMeterTaskEntity>) response;
+                List<WaterMeterTaskEntity> oldTaskList = DaoUtilsStore.getInstance().getWaterMeterTaskEntityDbUtils().queryByQueryBuilder(WaterMeterTaskEntityDao.Properties.CheckUser.eq(AccountManager.getUserId()));
+                if (!oldTaskList.isEmpty()) {
+                    List<WaterMeterTaskEntity> deleteTaskList = new ArrayList<>();
+                    if (!waterMeterTaskEntities.isEmpty()) {
+                        for (WaterMeterTaskEntity taskEntity : oldTaskList) {
+                            boolean isRepeat = false;
+                            for (WaterMeterTaskEntity taskEntity1 : waterMeterTaskEntities) {
+                                if (taskEntity.getId().equals(taskEntity1.getId())) {
+                                    isRepeat = true;
+                                    break;
+                                }
+                            }
+                            if (!isRepeat) {
+                                deleteTaskList.add(taskEntity);
+                            }
+                        }
+                    } else {
+                        deleteTaskList.addAll(oldTaskList);
+                    }
+                    if (!deleteTaskList.isEmpty()) {
+                        List<WaterMeterEntity> deleteList = new ArrayList<>();
+                        for (WaterMeterTaskEntity taskEntity : deleteTaskList) {
+                            deleteList.addAll(DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().queryByQueryBuilder(WaterMeterEntityDao.Properties.TaskId.eq(taskEntity.getId()), WaterMeterEntityDao.Properties.State.notEq(3)));
+                        }
+                        if (!deleteList.isEmpty()) {
+                            DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().delete(deleteList);
+                        }
+                    }
+                }
+                DaoUtilsStore.getInstance().getWaterMeterTaskEntityDbUtils().delete(DaoUtilsStore.getInstance().getWaterMeterTaskEntityDbUtils().queryByQueryBuilder(WaterMeterTaskEntityDao.Properties.CheckUser.eq(AccountManager.getUserId())));
                 DaoUtilsStore.getInstance().getWaterMeterTaskEntityDbUtils().insertMulti(waterMeterTaskEntities, true);
                 for (WaterMeterTaskEntity waterMeterTaskEntity : waterMeterTaskEntities) {
                     if (waterMeterTaskEntity.getYxswWaterMeterInspectDto() != null && !waterMeterTaskEntity.getYxswWaterMeterInspectDto().isEmpty()) {
+                        List<WaterMeterEntity> oldSbdjEntity = DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().queryByQueryBuilder(WaterMeterEntityDao.Properties.TaskId.eq(waterMeterTaskEntity.getId()));
+                        List<WaterMeterEntity> deleteList = new ArrayList<>();
+                        for (WaterMeterEntity waterMeter : oldSbdjEntity) {
+                            boolean isRepeat = false;
+                            for (WaterMeterEntity waterMeter1 : waterMeterTaskEntity.getYxswWaterMeterInspectDto()) {
+                                if (waterMeter.getId().equals(waterMeter1.getId())) {
+                                    isRepeat = true;
+                                    break;
+                                }
+                            }
+                            if (!isRepeat && waterMeter.getState() != 3) {
+                                deleteList.add(waterMeter);
+                            }
+                        }
+                        if (!deleteList.isEmpty()) {
+                            DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().delete(deleteList);
+                        }
                         for (WaterMeterEntity sbdjEntity : waterMeterTaskEntity.getYxswWaterMeterInspectDto()) {
                             sbdjEntity.setTaskId(waterMeterTaskEntity.getId());
                             sbdjEntity.setCheckUser(waterMeterTaskEntity.getCheckUser());

+ 68 - 46
app/src/main/java/com/tofly/yxpc/ui/fragment/MeFragment.java

@@ -2,9 +2,6 @@ package com.tofly.yxpc.ui.fragment;
 
 import android.content.Intent;
 import android.text.TextUtils;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.TextView;
 
 import com.bumptech.glide.Glide;
 import com.bumptech.glide.request.RequestOptions;
@@ -14,31 +11,24 @@ import com.tofly.latte_core.utils.AccountManager;
 import com.tofly.yxpc.R;
 import com.tofly.yxpc.base.MyApp;
 import com.tofly.yxpc.base.NetWorkUrl;
+import com.tofly.yxpc.databinding.FragmentMyBinding;
+import com.tofly.yxpc.entity.WaterMeterEntity;
+import com.tofly.yxpc.greenDao.WaterMeterEntityDao;
 import com.tofly.yxpc.ui.activity.AboutSystemActivity;
 import com.tofly.yxpc.ui.activity.LoginActivity;
 import com.tofly.yxpc.ui.activity.SettingActivity;
 import com.tofly.yxpc.ui.impl.MyImpl;
 import com.tofly.yxpc.utils.DialogUtils;
-import com.tofly.yxpc.widget.CircleImageView;
+import com.tofly.yxpc.utils.db.DaoUtilsStore;
 
-import butterknife.BindView;
-import butterknife.OnClick;
+import java.util.List;
 
 /**
  * @author ychk
  */
 public class MeFragment extends LatteDelegate {
 
-    @BindView(R.id.cimg_head_portrait)
-    CircleImageView cimgHeadPortrait;
-    @BindView(R.id.ll_head_portrait)
-    LinearLayout llHeadPortrait;
-    @BindView(R.id.tv_user_name)
-    TextView tvUserName;
-    @BindView(R.id.ll_about_system)
-    LinearLayout llAboutSystem;
-    @BindView(R.id.tv_login_out)
-    TextView tvLoginOut;
+    private FragmentMyBinding binding;
 
     @Override
     protected LatteContract.LattePresenter createPresenter() {
@@ -47,11 +37,69 @@ public class MeFragment extends LatteDelegate {
 
     @Override
     public Object setLayout() {
-        return R.layout.fragment_my;
+        binding = FragmentMyBinding.inflate(getLayoutInflater());
+        return binding.getRoot();
     }
 
+    private void initListener() {
+        binding.llHeadPortrait.setOnClickListener(v -> {
+            if (MyApp.getInstance().isOverTime()) {
+                Intent intent = new Intent(requireContext(), SettingActivity.class);
+                requireContext().startActivity(intent);
+            }
+        });
+
+        binding.llClear.setOnClickListener(v -> {
+            if (MyApp.getInstance().isOverTime()) {
+                List<WaterMeterEntity> list = DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().queryByQueryBuilder(
+                        WaterMeterEntityDao.Properties.CheckUser.eq(AccountManager.getUserId()));
+                if (list.isEmpty()) {
+                    onMessage("本地无缓存数据,无需清理缓存");
+                } else {
+                    long draftSize = DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().queryCountByQueryBuilder(
+                            WaterMeterEntityDao.Properties.CheckUser.eq(AccountManager.getUserId()),
+                            WaterMeterEntityDao.Properties.State.eq(1)
+                    );
+                    long localSize = DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().queryCountByQueryBuilder(
+                            WaterMeterEntityDao.Properties.CheckUser.eq(AccountManager.getUserId()),
+                            WaterMeterEntityDao.Properties.State.eq(2)
+                    );
+                    String message;
+                    if (draftSize > 0) {
+                        message = "本地存在草稿数据,是否确定清除缓存?";
+                    } else if (localSize > 0) {
+                        message = "本地存在已稽查未上传数据,是否确定清除缓存?";
+                    } else {
+                        message = "是否确定清理本地缓存?";
+                    }
+                    DialogUtils.showDialog(requireContext(), "提示", message, false, (dialog, which) -> {
+                        DaoUtilsStore.getInstance().getWaterMeterEntityDbUtils().delete(list);
+                    });
+                }
+            }
+        });
+
+        binding.llAboutSystem.setOnClickListener(v -> {
+            if (MyApp.getInstance().isOverTime()) {
+                Intent intent = new Intent(requireContext(), AboutSystemActivity.class);
+                requireContext().startActivity(intent);
+            }
+        });
+
+        binding.tvLoginOut.setOnClickListener(v -> {
+            if (MyApp.getInstance().isOverTime()) {
+                DialogUtils.showDialog(requireContext(), "是否确定退出", "", true, (dialog, which) -> {
+                    requireActivity().finish();
+                    startActivity(new Intent(getContext(), LoginActivity.class));
+                });
+            }
+        });
+    }
+
+
     @Override
     public void initView() {
+        initListener();
     }
 
     @Override
@@ -60,32 +108,6 @@ public class MeFragment extends LatteDelegate {
         loadData();
     }
 
-    @OnClick({R.id.ll_head_portrait, R.id.ll_about_system, R.id.tv_login_out})
-    public void onClick(View view) {
-        if (!MyApp.getInstance().isOverTime()) {
-            return;
-        }
-        Intent intent = null;
-        switch (view.getId()) {
-            case R.id.ll_head_portrait:
-                intent = new Intent(requireContext(), SettingActivity.class);
-                requireContext().startActivity(intent);
-                break;
-            case R.id.ll_about_system:
-                intent = new Intent(requireContext(), AboutSystemActivity.class);
-                requireContext().startActivity(intent);
-                break;
-            case R.id.tv_login_out:
-                DialogUtils.showDialog(requireContext(), "是否确定退出", "", true, (dialog, which) -> {
-                    requireActivity().finish();
-                    startActivity(new Intent(getContext(), LoginActivity.class));
-                });
-                break;
-            default:
-                break;
-        }
-    }
-
     /**
      * 加载基础信息
      */
@@ -94,11 +116,11 @@ public class MeFragment extends LatteDelegate {
             Glide.with(requireContext())
                     .load(NetWorkUrl.getFileUrl(AccountManager.getAvatar()))
                     .apply(new RequestOptions().error(R.mipmap.icon_head_portrait))
-                    .into(cimgHeadPortrait);
+                    .into(binding.cimgHeadPortrait);
         } else {
-            cimgHeadPortrait.setBackgroundResource(R.mipmap.icon_head_portrait);
+            binding.cimgHeadPortrait.setBackgroundResource(R.mipmap.icon_head_portrait);
         }
-        tvUserName.setText(AccountManager.getUserRealName() == null ? "" : AccountManager.getUserRealName());
+        binding.tvUserName.setText(AccountManager.getUserRealName() == null ? "" : AccountManager.getUserRealName());
     }
 
     @Override

+ 1 - 1
app/src/main/res/layout/activity_img_text_navit.xml

@@ -160,7 +160,7 @@
                     android:layout_height="@dimen/dp_22"
                     android:layout_alignParentRight="true"
                     android:layout_centerVertical="true"
-                    android:background="@mipmap/photo"/>
+                    android:background="@mipmap/icon_photo"/>
             </RelativeLayout>
             <androidx.recyclerview.widget.RecyclerView
                 android:id="@+id/rv_picture_dh"

+ 1 - 1
app/src/main/res/layout/activity_setting.xml

@@ -37,7 +37,7 @@
                 android:layout_width="@dimen/dp_40"
                 android:layout_height="@dimen/dp_40"
                 android:layout_marginEnd="2dp"
-                android:src="@mipmap/my_heard" />
+                android:src="@mipmap/icon_my_heard" />
 
             <ImageView
                 android:id="@+id/img_portrait"

+ 1 - 1
app/src/main/res/layout/activity_unregister.xml

@@ -100,7 +100,7 @@
                     android:layout_height="@dimen/dp_22"
                     android:layout_alignParentRight="true"
                     android:layout_centerVertical="true"
-                    android:background="@mipmap/photo" />
+                    android:background="@mipmap/icon_photo" />
             </RelativeLayout>
 
             <androidx.recyclerview.widget.RecyclerView

+ 32 - 3
app/src/main/res/layout/fragment_my.xml

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -70,7 +69,7 @@
                     android:layout_height="wrap_content"
                     android:layout_marginStart="@dimen/dp_15"
                     android:layout_weight="1"
-                    android:drawableLeft="@mipmap/setting"
+                    android:drawableStart="@mipmap/icon_setting"
                     android:drawablePadding="@dimen/dp_10"
                     android:gravity="center_vertical"
                     android:text="设置"
@@ -86,6 +85,36 @@
                     android:padding="@dimen/dp_10" />
             </LinearLayout>
 
+            <View
+                style="@style/line_gray"
+                android:background="@color/bg_gray" />
+
+            <LinearLayout
+                android:id="@+id/ll_clear"
+                style="@style/detail_linear"
+                android:background="@color/white"
+                android:minHeight="@dimen/dp_50">
+
+                <TextView
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_marginStart="@dimen/dp_15"
+                    android:layout_weight="1"
+                    android:drawableStart="@mipmap/icon_clear"
+                    android:drawablePadding="@dimen/dp_10"
+                    android:text="清楚缓存数据"
+                    android:textColor="@color/color_333"
+                    android:textSize="@dimen/sp_16" />
+
+                <ImageView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginStart="@dimen/dp_5"
+                    android:layout_marginEnd="@dimen/dp_5"
+                    android:background="@mipmap/icon_arrow_right"
+                    android:padding="@dimen/dp_10" />
+            </LinearLayout>
+
             <View
                 style="@style/line_gray"
                 android:background="@color/bg_gray" />
@@ -101,7 +130,7 @@
                     android:layout_height="wrap_content"
                     android:layout_marginStart="@dimen/dp_15"
                     android:layout_weight="1"
-                    android:drawableLeft="@mipmap/aboat"
+                    android:drawableStart="@mipmap/aboat"
                     android:drawablePadding="@dimen/dp_10"
                     android:text="关于系统"
                     android:textColor="@color/color_333"

BIN
app/src/main/res/mipmap-hdpi/icon_clear.png


app/src/main/res/mipmap-hdpi/my_heard.png → app/src/main/res/mipmap-hdpi/icon_my_heard.png


app/src/main/res/mipmap-hdpi/photo.png → app/src/main/res/mipmap-hdpi/icon_photo.png


app/src/main/res/mipmap-hdpi/setting.png → app/src/main/res/mipmap-hdpi/icon_setting.png


app/src/main/res/mipmap-hdpi/up.png → app/src/main/res/mipmap-hdpi/icon_up.png


app/src/main/res/mipmap-xxhdpi/record_file.png → app/src/main/res/mipmap-xxhdpi/icon_record_file.png