From dbfcbb1aa3423966feb8a176f05e97dce32690ed Mon Sep 17 00:00:00 2001 From: liup <1454939542@qq.com> Date: Wed, 11 Sep 2024 11:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=88=B0=E6=96=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/ConfigName.java | 3 +- .../bnframework/common/helper/SdCart.java | 139 ++++++++++++++++-- .../home/fragment/HomeFragmentSBKZ.java | 20 +++ .../fragment/from/BunkerSetupActivity.java | 10 +- .../fragment/SystemSystemsetFragment.java | 2 +- .../home/fragment/mode/add_silos_message.java | 16 -- .../home/fragment/mode/jingdutiao1.java | 5 +- .../main/res/layout/activity_bunkersetup.xml | 3 +- 8 files changed, 161 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java index 0880314e..99d5aace 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java @@ -36,7 +36,8 @@ import java.util.concurrent.ConcurrentHashMap; public class ConfigName { public static boolean isTEST = false; public boolean is800WithFeeding = false;//是否是800带投料版 有5个投料位 - public boolean isPhoneVersion = true;//是否适配手机 + public boolean isPhoneVersion = false;//是否适配手机 + public boolean isHighVersion = false;//是否适配高版本 public double scale = 1; //region 单例模式 diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java b/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java index ee4e15eb..98953666 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java +++ b/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java @@ -5,12 +5,15 @@ import android.content.Context; import android.os.Environment; import android.util.Log; +import com.apkfuns.logutils.LogUtils; import com.bonait.bnframework.MainApplication; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.file.DBHelper; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; /** @@ -46,13 +49,7 @@ public class SdCart { * 初始化数据库到SD卡 */ public void initSD() { -// File sdDir = null; -// boolean sdCardExist = Environment.getExternalStorageState().equals( -// Environment.MEDIA_MOUNTED); -// if (sdCardExist) { -// sdDir = Environment.getExternalStorageDirectory(); -// ConfigName.getInstance().sdCardPath = sdDir.toString(); -// } + ConfigName.getInstance().sdCardPath = ConfigName.getFileRoot(MainApplication.getContext()); ConfigName.getInstance().appResRoot = ConfigName.getInstance().sdCardPath +ConfigName.dataPath; @@ -68,10 +65,28 @@ public class SdCart { if(!file.exists())//文件不存在那么创建数据库 { Log.i("日志","初始化数据库:文件不存在准备新建!"); - //1.复制本地文件到SD卡 - copyFilesFassets(ConfigName.getInstance().dishesCon, ConfigName.getInstance().dbPath); - //2.创建数据库结构 - DBHelper.getInstance(ConfigName.getInstance().dishesCon).CreateTables(); + + //复制文件 + if(!ConfigName.getInstance().isHighVersion){ + + File sdDir = null; + String dbPath = ""; + boolean sdCardExist = Environment.getExternalStorageState().equals( + Environment.MEDIA_MOUNTED); + if (sdCardExist) { + sdDir = Environment.getExternalStorageDirectory(); + dbPath = sdDir.toString()+ConfigName.dataPath; + } + File file2 = new File(dbPath); + if(file2.exists()){ + copyDirectory(dbPath,ConfigName.getInstance().appResRoot); + } + }else { + //1.复制本地文件到SD卡 + copyFilesFassets(ConfigName.getInstance().dishesCon, ConfigName.getInstance().dbPath); + //2.创建数据库结构 + DBHelper.getInstance(ConfigName.getInstance().dishesCon).CreateTables(); + } } ConfigName.getInstance(). AuthorizeCodePath=ConfigName.getInstance().appResRoot + "/AuthorizeCode.aes"; @@ -108,7 +123,109 @@ public class SdCart { } catch (Exception e) { e.printStackTrace(); + LogUtils.d("copyFilesFassets Exception"); + } + } + + + + + /** + * 复制目录及其子目录中的所有文件到另一个目录 + * + * @param srcDir 源目录路径 + * @param destDir 目标目录路径 + * @return 复制是否成功 + */ + public static boolean copyDirectory(String srcDir, String destDir) { + LogUtils.d("copyDirectory srcDir="+srcDir+";destDir="+destDir); + File srcFile = new File(srcDir); + File destFile = new File(destDir); + + // 如果源目录不存在,则返回false + if (!srcFile.exists()) { + LogUtils.d("copyDirectory 如果源目录不存在"); + return false; + } + // 如果目标目录不存在,则创建它 + if (!destFile.exists()) { + destFile.mkdirs(); + } + LogUtils.d("copyDirectory =="); + // 列出源目录下的所有文件和文件夹 + File[] files = srcFile.listFiles(); + + if (files != null) { + for (File file : files) { + // 构造源和目标文件路径 + String srcFilePath = file.getAbsolutePath(); + String destFilePath = destDir + File.separator + file.getName(); + + // 如果是文件,则直接复制 + if (file.isFile()) { + copyFile(srcFilePath, destFilePath); + } + // 如果是目录,则递归复制 + else if (file.isDirectory()) { + copyDirectory(srcFilePath, destFilePath); + } + } + } + LogUtils.d("copyDirectory true"); + return true; + } + + /** + * 复制单个文件 + * + * @param sourceFile 源文件路径 + * @param destFile 目标文件路径 + * @return 复制是否成功 + */ + private static boolean copyFile(String sourceFile, String destFile) { + File sourceFileObj = new File(sourceFile); + File destFileObj = new File(destFile); + + if (!sourceFileObj.isFile()) { + // 如果源文件不存在,则复制失败 + LogUtils.d("copyFile 如果源文件不存在"); + + return false; + } + + // 确保目标文件所在的目录存在 + File destFileParentDir = destFileObj.getParentFile(); + if (!destFileParentDir.exists()) { + destFileParentDir.mkdirs(); + } + + FileInputStream fis = null; + FileOutputStream fos = null; + + try { + fis = new FileInputStream(sourceFileObj); + fos = new FileOutputStream(destFileObj); + + byte[] buffer = new byte[1024]; + int length; + while ((length = fis.read(buffer)) > 0) { + fos.write(buffer, 0, length); + } + + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } finally { + LogUtils.d("copyFile true"); + // 关闭流 + try { + if (fis != null) fis.close(); + if (fos != null) fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java index 61062d8a..fb6ab8b9 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java @@ -250,6 +250,26 @@ public class HomeFragmentSBKZ extends BaseFragment { tv5.setVisibility(ConfigName.getInstance().is800WithFeeding?View.VISIBLE:View.GONE); } + @Override + public void onResume() { + super.onResume(); + ArrayList silosArrayList = QueryDB.GetSilosALL(); + List nameList = new ArrayList<>(); + if(!silosArrayList.isEmpty()) { + for (BPA_SILOS silos : silosArrayList) { + List materials = QueryDB.GetMaterialBySilosID(silos.id); + if (!materials.isEmpty()) { + nameList.add(silos.num + "料仓:" + materials.get(0).name); + } else { + nameList.add(silos.num + "料仓:未设置"); + } + } + ArrayAdapter adapter_kk = new ArrayAdapter<>(getContext(), R.layout.spinner_text_item20, nameList); + adapter_kk.setDropDownViewResource(R.layout.spinner_dropdown_item20); + spinner_silos.setAdapter(adapter_kk); + } + } + @Override public void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java index 9e8b556a..d01ed036 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java @@ -142,11 +142,11 @@ public class BunkerSetupActivity extends BaseActivity { DataBus.getInstance().GetLc(); if(ConfigName.getInstance().silosAuto){ binding.llSilosAuto.removeAllViews(); -// for (lcMode item : DataBus.getInstance().lcModes) { -// jingdutiao1 view = new jingdutiao1(this); -// view.SetValue(item,myClickListener); -// binding.llSilosAuto.addView(view); -// } + for (lcMode item : DataBus.getInstance().lcModes) { + jingdutiao1 view = new jingdutiao1(this); + view.SetValue(item,myClickListener); + binding.llSilosAuto.addView(view); + } }else { for (lcMode item : DataBus.getInstance().lcModes) { if (item.num == 1) { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java index b006edc8..f8bd2c3b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java @@ -316,7 +316,7 @@ public class SystemSystemsetFragment extends BaseFragment { if(size>newSize){ for(int i=size-1;i>=newSize;i--){ QueryDB.DeleteSilos(silosArrayList.get(i)); - QueryDB.DeleteSilosAndMaterial(silosandmaterials.get(i)); + QueryDB.DeleteSilosAndMaterial(silosArrayList.get(i).id); } }else if(size