diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml new file mode 100644 index 00000000..02b915b8 --- /dev/null +++ b/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 40a49cd5..9dccfee8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,13 @@ +import java.text.DateFormat +import java.text.SimpleDateFormat + apply plugin: 'com.android.application' //apply plugin: 'com.jakewharton.butterknife' - +def releaseTime() { + DateFormat df = new SimpleDateFormat("yyyyMMddHHmm") + return df.format(Calendar.getInstance(Locale.CHINA).getTime()) +} android { compileSdk rootProject.ext.compileSdkVersion @@ -59,6 +65,11 @@ android { buildFeatures { viewBinding = true } + applicationVariants.all { variant -> + variant.outputs.all { + outputFileName = "boluo-v${defaultConfig.versionCode}-${releaseTime()}"+"-unsigned-${variant.name}.apk" + } + } } dependencies { @@ -184,4 +195,7 @@ dependencies { implementation "com.github.bumptech.glide:okhttp3-integration:4.16.0" implementation 'com.squareup.retrofit2:converter-gson:2.5.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0' + + //leak 内存泄漏检测 + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-alpha-3' } diff --git a/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java index 23858bbe..13ca1d32 100644 --- a/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java @@ -315,7 +315,7 @@ public class BottomNavigationNewActivity extends BaseActivity { */ private void MakeThread() { LogUtils.d("MakeThread()"); - ExecuteTheRecipe.context = this; +// ExecuteTheRecipe.context = this; mainTread = new Thread(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/ImageChooseActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/ImageChooseActivity.java index 959d0098..cc62310e 100644 --- a/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/ImageChooseActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/ImageChooseActivity.java @@ -1,22 +1,25 @@ package com.bonait.bnframework.ViewModel.ActivityViewModel; -import androidx.recyclerview.widget.RecyclerView; - import android.os.Bundle; import android.os.Environment; import android.view.View; +import androidx.recyclerview.widget.RecyclerView; + import com.bonait.bnframework.R; +import com.bonait.bnframework.ViewModel.Adapter.image_sp_adapter; +import com.bonait.bnframework.ViewModel.CustomView.image_sp; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.MyLayoutManager; -import com.bonait.bnframework.ViewModel.Adapter.image_sp_adapter; -import com.bonait.bnframework.ViewModel.CustomView.image_sp; +import com.bonait.bnframework.event.ImageSelectEvent; import com.qmuiteam.qmui.widget.QMUITopBarLayout; +import org.greenrobot.eventbus.EventBus; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -30,7 +33,7 @@ public class ImageChooseActivity extends BaseActivity { QMUITopBarLayout mTopBar;//顶部标题 @BindView(R.id.recycler_view) RecyclerView recyclerView;//image列表 - private static final String CACHE_PATH= Environment.getExternalStorageDirectory().getAbsolutePath()+"/hblxiaochaodb/WebImage"; + public static final String CACHE_PATH= Environment.getExternalStorageDirectory().getAbsolutePath()+"/hblxiaochaodb/WebImage"; List data =new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -74,6 +77,12 @@ public class ImageChooseActivity extends BaseActivity { image_sp sp=(image_sp)data; MessageManager.getInstance().sendMessage(MessageName.ClickImage,sp.url); finish(); + recyclerView.postDelayed(new Runnable() { + @Override + public void run() { + EventBus.getDefault().post(new ImageSelectEvent(CACHE_PATH+"/"+sp.url)); + } + },500); } @Override public void clickListenerNew(View v, int k, Object data) { diff --git a/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/LoginActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/LoginActivity.java index cb57865c..c57360ca 100644 --- a/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/LoginActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/LoginActivity.java @@ -4,7 +4,6 @@ import android.animation.ObjectAnimator; import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; -import androidx.core.widget.NestedScrollView; import android.text.Editable; import android.text.InputType; import android.text.TextUtils; @@ -22,9 +21,14 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; +import androidx.core.widget.NestedScrollView; +import androidx.lifecycle.LifecycleObserver; + +import com.bonait.bnframework.Model.AppLoginPo; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.base.BaseActivity; +import com.bonait.bnframework.common.bg.SnowView; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.Constants; import com.bonait.bnframework.common.constant.SPConstants; @@ -38,7 +42,6 @@ import com.bonait.bnframework.common.utils.KeyboardToolUtils; import com.bonait.bnframework.common.utils.PreferenceUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.manager.ActivityLifecycleManager; -import com.bonait.bnframework.Model.AppLoginPo; import com.bonait.bnframework.test.TestActivity; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.HttpParams; @@ -92,6 +95,8 @@ public class LoginActivity extends BaseActivity implements Validator.ValidationL ImageView imgPass; @BindView(R.id.rl_title) RelativeLayout rl_title; + @BindView(R.id.snowView) + SnowView snowView; private long exitTime = 0; private int screenHeight = 0;//屏幕高度 @@ -124,16 +129,9 @@ public class LoginActivity extends BaseActivity implements Validator.ValidationL * 对布局进行缩放 */ private void initView(){ - DisplayManager.scaleView(mEtAccount); - DisplayManager.scaleView(mEtPassword); - DisplayManager.scaleView(mCleanPassword); - DisplayManager.scaleView(mIvCleanAccount); - DisplayManager.scaleView(mIvShowPwd); - DisplayManager.scaleView(cbCheckbox); - DisplayManager.scaleView(mContent); - DisplayManager.scaleView(imgAccount); - DisplayManager.scaleView(imgPass); - DisplayManager.scaleView(rl_title); + DisplayManager.scaleViewGroup(findViewById(R.id.root)); + + getLifecycle().addObserver((LifecycleObserver) snowView); } /** @@ -544,4 +542,16 @@ public class LoginActivity extends BaseActivity implements Validator.ValidationL } return super.onKeyDown(keyCode, event); } + + @Override + public void onDetachedFromWindow() { + super.onDetachedFromWindow(); + getLifecycle().removeObserver((LifecycleObserver) snowView); + + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } } diff --git a/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home1Fragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home1Fragment.java index 012998ec..720abaf4 100644 --- a/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home1Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home1Fragment.java @@ -6,14 +6,6 @@ import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.RecyclerView; - import android.os.CountDownTimer; import android.util.Log; import android.view.LayoutInflater; @@ -23,23 +15,30 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + import com.bonait.bnframework.R; +import com.bonait.bnframework.ViewModel.ActivityViewModel.CpxzActivity; +import com.bonait.bnframework.ViewModel.Adapter.lc_adapter; +import com.bonait.bnframework.ViewModel.CustomView.MyStatus; +import com.bonait.bnframework.ViewModel.CustomView.huoli_control; +import com.bonait.bnframework.ViewModel.CustomView.imagebutton_control; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_GOODS_OLD; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; +import com.bonait.bnframework.common.db.mode.BPA_GOODS_OLD; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.MyLayoutManager; -import com.bonait.bnframework.ViewModel.Adapter.lc_adapter; -import com.bonait.bnframework.ViewModel.ActivityViewModel.CpxzActivity; -import com.bonait.bnframework.ViewModel.CustomView.MyStatus; -import com.bonait.bnframework.ViewModel.CustomView.huoli_control; -import com.bonait.bnframework.ViewModel.CustomView.imagebutton_control; import com.capton.colorfulprogressbar.ColorfulProgressbar; import com.litao.slider.NiftySlider; import com.orhanobut.logger.Logger; @@ -452,7 +451,7 @@ public class Home1Fragment extends BaseFragment { * 商品制作线程 */ public void MakeThread() { - ExecuteTheRecipe.context = context; +// ExecuteTheRecipe.context = context; new Thread(new Runnable() { @Override diff --git a/app/src/main/java/com/bonait/bnframework/common/base/BaseActivity.java b/app/src/main/java/com/bonait/bnframework/common/base/BaseActivity.java index efa5e108..b3b20a82 100644 --- a/app/src/main/java/com/bonait/bnframework/common/base/BaseActivity.java +++ b/app/src/main/java/com/bonait/bnframework/common/base/BaseActivity.java @@ -129,6 +129,7 @@ public class BaseActivity extends QMUIActivity implements EasyPermissions.Permis @Override protected void onDestroy() { + ActiveMax.destroy(this); super.onDestroy(); LogUtils.d(getClassName()+"生命周期 onDestroy()"); } diff --git a/app/src/main/java/com/bonait/bnframework/common/bg/SnowView.java b/app/src/main/java/com/bonait/bnframework/common/bg/SnowView.java index 193b7787..cc93f95f 100644 --- a/app/src/main/java/com/bonait/bnframework/common/bg/SnowView.java +++ b/app/src/main/java/com/bonait/bnframework/common/bg/SnowView.java @@ -4,11 +4,14 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; -import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; import android.widget.RelativeLayout; +import androidx.annotation.NonNull; +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleEventObserver; +import androidx.lifecycle.LifecycleOwner; import com.bonait.bnframework.common.bg.mode.SnowBean; import com.bonait.bnframework.common.helper.Tools; @@ -18,7 +21,7 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; -public class SnowView extends RelativeLayout { +public class SnowView extends RelativeLayout implements LifecycleEventObserver { // private final String SNOW = "❄"; // private final String SNOW = "☀❆★❉❈❀✿❃❁"; private final String SNOW = "❄"; @@ -173,6 +176,15 @@ public class SnowView extends RelativeLayout { return detector.onTouchEvent(event); } + @Override + public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) { + switch (event) { + case ON_DESTROY: + destroy(); + break; + } + } + private class MyGestureDetector implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener { @Override diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS.java index 2a00ae66..2b3a3d9c 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS.java @@ -32,11 +32,6 @@ public class BPA_GOODS extends ModeBase { */ public String classifyId; - /** - * 用来区分是否已下载,本地使用 - */ - public boolean isLocal; - @Override public String toString() { diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_PROCESS_DETAIL.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_PROCESS_DETAIL.java index 5b7bd4fd..5eb3a30f 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_PROCESS_DETAIL.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_PROCESS_DETAIL.java @@ -7,7 +7,7 @@ package com.bonait.bnframework.common.db.mode; */ public class BPA_GOODS_PROCESS_DETAIL extends ModeBase{ /** - * 商品属性组合id + * 商品属性组合名称 a-b */ public String goodsSubAttributeGroupId; /** diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_SUBATTRIBUTE_GROUP.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_SUBATTRIBUTE_GROUP.java index 6a55d179..2ea68d2b 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_SUBATTRIBUTE_GROUP.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_SUBATTRIBUTE_GROUP.java @@ -11,7 +11,7 @@ public class BPA_GOODS_SUBATTRIBUTE_GROUP extends ModeBase{ */ public String name; /** - * 子属性id组合 xxx,xxxx,xxx + * 子属性id组合 xxx,xxxx,xxx 暂时不用id匹配 用name匹配 */ public String subAttributeIdList; /** diff --git a/app/src/main/java/com/bonait/bnframework/common/db/util/GoodsProcessDetailDBUtil.java b/app/src/main/java/com/bonait/bnframework/common/db/util/GoodsProcessDetailDBUtil.java index dfd299db..74401103 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/util/GoodsProcessDetailDBUtil.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/util/GoodsProcessDetailDBUtil.java @@ -80,15 +80,15 @@ public class GoodsProcessDetailDBUtil { } /** - * 根据商品属性组合id查询旗下的工序列表 + * 根据商品属性组合查询旗下的工序列表 * - * @param goodsSubAttributeGroupId + * @param name * @return */ - public static ArrayList getByGoodsSubAttributeGroupId(String goodsSubAttributeGroupId) { + public static ArrayList getByGoodsSubAttributeGroupName(String name) { String orderby = QueryDB.Desc_Sort_Up + ',' + QueryDB.Desc_Time_Up; String where = "isDelete=? and goodsSubAttributeGroupId=?"; - String[] args = new String[]{"0", goodsSubAttributeGroupId}; + String[] args = new String[]{"0", name}; ArrayList data = new ArrayList<>(); ArrayList obj = QueryDB.Get(BPA_GOODS_PROCESS_DETAIL.class, where, args, orderby); for (Object item : obj) { diff --git a/app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeGroupDBUtil.java b/app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeGroupDBUtil.java index 9a34200d..259d01a7 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeGroupDBUtil.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeGroupDBUtil.java @@ -6,7 +6,6 @@ import com.apkfuns.logutils.LogUtils; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.file.DBHelper; -import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL; import com.bonait.bnframework.common.db.mode.BPA_GOODS_SUBATTRIBUTE_GROUP; import java.util.ArrayList; @@ -60,7 +59,7 @@ public class SubAttributeGroupDBUtil { public static boolean deleteByGoodsId(String goodsId) { boolean result = true; SQLiteDatabase db = DBHelper.getInstance(ConfigName.getInstance().dishesCon).getWritableDatabase(); - long delete = db.delete(BPA_GOODS_PROCESS_DETAIL.class.getSimpleName(), "goodsId=?", + long delete = db.delete(BPA_GOODS_SUBATTRIBUTE_GROUP.class.getSimpleName(), "goodsId=?", new String[]{goodsId}); if(delete <= 0){ result = false; diff --git a/app/src/main/java/com/bonait/bnframework/common/glide/GlideUtil.java b/app/src/main/java/com/bonait/bnframework/common/glide/GlideUtil.java index 0ba632ac..db4742cc 100644 --- a/app/src/main/java/com/bonait/bnframework/common/glide/GlideUtil.java +++ b/app/src/main/java/com/bonait/bnframework/common/glide/GlideUtil.java @@ -2,14 +2,18 @@ package com.bonait.bnframework.common.glide; import android.content.Context; import android.graphics.drawable.Drawable; +import android.view.View; import android.widget.ImageView; import androidx.annotation.Nullable; +import com.bonait.bnframework.common.glide.transform.FitXYRoundRadiusTransform; +import com.bonait.bnframework.common.utils.DimensUtil; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; /** @@ -25,6 +29,27 @@ public class GlideUtil { throw new AssertionError(); } +// public static String exchangeUrl(String path){ +// String result=path; +// if(!TextUtils.isEmpty(PATH_PRE)&&!TextUtils.isEmpty(path)) { +// if(!path.contains("http:")&&!path.contains("https:")){ +// if(path.contains(".png")||path.contains(".jpg")||path.contains(".jpeg")||path.contains(".gif")){ +// if(TEST) { +// result = PATH_PRE + path.replace("images", "modules"); +// }else{ +// result = PATH_PRE + path; +// } +// if(first){ +// LogUtils.d("GlideUtil exchangeUrl result:"+result); +// first=false; +// } +// } +// } +// } +//// LogUtils.i("GlideUtil exchangeUrl"+result); +// return result; +// } + public static void showImage(Context context, String path, ImageView imageView,int placeId) { if (context == null||path==null) { return; @@ -53,4 +78,39 @@ public class GlideUtil { .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE_DURATION)) .into(imageView); } + + public static void showImageWithRadius(Context context, String path, ImageView imageView,int placeId,int radius) { + if (context == null||path==null) { + return; + } + setType(imageView); + GlideApp.with(context) + .load(path) + .addListener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, + Target target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, + Target target, DataSource dataSource, + boolean isFirstResource) { + if (imageView == null) { + return false; + } + imageView.setBackground(null); + return false; + } + }) + .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE_DURATION)) +// .apply(RequestOptions.bitmapTransform(new RoundedCorners(RADIUS))) + .apply(new RequestOptions().transform(new FitXYRoundRadiusTransform(DimensUtil.getDimens(radius)))) + .into(imageView); + } + + private static void setType(ImageView imageView){//硬件加速 + imageView.setLayerType(View.LAYER_TYPE_HARDWARE,null); + } } diff --git a/app/src/main/java/com/bonait/bnframework/common/glide/transform/FitXYRoundRadiusTransform.java b/app/src/main/java/com/bonait/bnframework/common/glide/transform/FitXYRoundRadiusTransform.java new file mode 100644 index 00000000..7defac5f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/glide/transform/FitXYRoundRadiusTransform.java @@ -0,0 +1,95 @@ +package com.bonait.bnframework.common.glide.transform; + +import android.graphics.Bitmap; + +import androidx.annotation.NonNull; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +import com.bumptech.glide.util.Util; + +import java.nio.ByteBuffer; +import java.security.MessageDigest; + +/** + * @author: wx + * @date: 2023/1/29 + */ +public class FitXYRoundRadiusTransform extends BitmapTransformation { + + // 此处用实际类的完整路径 + private static final String ID = "com.amt.module_common.util.image.FitXYRoundRadiusTransform"; + private static final byte[] ID_BYTES = ID.getBytes(CHARSET); + + private final int roundingRadius; + + private boolean isLeftTop = true; + private boolean isRightTop = true; + private boolean isLeftBottom = true; + private boolean isRightBottom = true; + + + public FitXYRoundRadiusTransform(int roundingRadius) { + this.roundingRadius = roundingRadius; + } + + public FitXYRoundRadiusTransform(int roundingRadius, boolean leftTop, boolean rightTop, boolean leftBottom, boolean rightBottom) { + this.roundingRadius = roundingRadius; + setNeedCorner(leftTop, rightTop, leftBottom, rightBottom); + } + + /** + * 需要设置圆角的部分 + * + * @param leftTop 左上角 + * @param rightTop 右上角 + * @param leftBottom 左下角 + * @param rightBottom 右下角 + */ + public void setNeedCorner(boolean leftTop, boolean rightTop, boolean leftBottom, boolean rightBottom) { + isLeftTop = leftTop; + isRightTop = rightTop; + isLeftBottom = leftBottom; + isRightBottom = rightBottom; + } + + @Override + protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { + + Bitmap bitmap = TransformationFitXYUtils.fitXY(pool, toTransform, outWidth, outHeight); + + return TransformationFitXYUtils.roundCrop(pool, bitmap, + isLeftTop ? roundingRadius : 0, + isRightTop ? roundingRadius : 0, + isRightBottom ? roundingRadius : 0, + isLeftBottom ? roundingRadius : 0); + } + + + @Override + public boolean equals(Object o) { + if (o instanceof FitXYRoundRadiusTransform) { + FitXYRoundRadiusTransform other = (FitXYRoundRadiusTransform) o; + return roundingRadius == other.roundingRadius; + } + return false; + } + + @Override + public int hashCode() { + return Util.hashCode(ID.hashCode(), Util.hashCode(roundingRadius)); + } + + @Override + public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { + messageDigest.update(ID_BYTES); + + byte[] radiusData = ByteBuffer.allocate(4).putInt(roundingRadius).array(); + messageDigest.update(radiusData); + } + + + + + +} diff --git a/app/src/main/java/com/bonait/bnframework/common/glide/transform/GlideBorderTransform.java b/app/src/main/java/com/bonait/bnframework/common/glide/transform/GlideBorderTransform.java new file mode 100644 index 00000000..9b521c62 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/glide/transform/GlideBorderTransform.java @@ -0,0 +1,67 @@ +package com.bonait.bnframework.common.glide.transform; + +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; + +import androidx.annotation.NonNull; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +import com.bumptech.glide.load.resource.bitmap.TransformationUtils; + +import java.security.MessageDigest; + +/** + * Glide边框转换 + * + * @author song.zheng@androidmov.com + */ +public class GlideBorderTransform extends BitmapTransformation { + private final float borderWidth; + private final int borderColor; + + public GlideBorderTransform(float borderWidth, int borderColor) { + super(); + this.borderWidth = borderWidth; + this.borderColor = borderColor; + } + + @Override + protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, + int outHeight) { + Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); + return border(pool, bitmap); + } + + private Bitmap border(BitmapPool pool, Bitmap source) { + if (source == null) { + return null; + } + Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(result); + Paint paint = new Paint(); + paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); + paint.setAntiAlias(true); + RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); + canvas.drawRect(rectF, paint); + paint.reset(); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(borderWidth); + paint.setColor(borderColor); + paint.setAntiAlias(true); + canvas.drawRect(rectF, paint); + return result; + } + + public String getId() { + return getClass().getName() + Math.round(borderWidth); + } + + @Override + public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { + + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/glide/transform/GlideRoundTransform.java b/app/src/main/java/com/bonait/bnframework/common/glide/transform/GlideRoundTransform.java new file mode 100644 index 00000000..715ab8c1 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/glide/transform/GlideRoundTransform.java @@ -0,0 +1,64 @@ +package com.bonait.bnframework.common.glide.transform; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; + +import androidx.annotation.NonNull; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +import com.bumptech.glide.load.resource.bitmap.TransformationUtils; + +import java.security.MessageDigest; + +/** + * Glide圆角转换 + * + * @author song.zheng@androidmov.com + */ +public class GlideRoundTransform extends BitmapTransformation { + private static float radius = 0f; + + public GlideRoundTransform(Context context) { + this(context, 8); + } + + public GlideRoundTransform(Context context, int px) { + super(); + radius = px; + } + + @Override + protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, + int outHeight) { + Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); + return roundCrop(pool, bitmap); + } + + private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { + if (source == null) { + return null; + } + Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(result); + Paint paint = new Paint(); + paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); + paint.setAntiAlias(true); + RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); + canvas.drawRoundRect(rectF, radius, radius, paint); + return result; + } + + public String getId() { + return getClass().getName() + Math.round(radius); + } + + @Override + public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { + + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/glide/transform/RoundRadiusTransform.java b/app/src/main/java/com/bonait/bnframework/common/glide/transform/RoundRadiusTransform.java new file mode 100644 index 00000000..60141bb9 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/glide/transform/RoundRadiusTransform.java @@ -0,0 +1,85 @@ +package com.bonait.bnframework.common.glide.transform; + +import android.graphics.Bitmap; + +import androidx.annotation.NonNull; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +import com.bumptech.glide.load.resource.bitmap.TransformationUtils; +import com.bumptech.glide.util.Util; + +import java.nio.ByteBuffer; +import java.security.MessageDigest; + +/** + * @author: wx + * @date: 2023/1/29 + */ +public class RoundRadiusTransform extends BitmapTransformation { + + // 此处用实际类的完整路径 + private static final String ID = "com.amt.module_common.util.image.RoundRadiusTransform"; + private static final byte[] ID_BYTES = ID.getBytes(CHARSET); + + private final int roundingRadius; + + private boolean isLeftTop, isRightTop, isLeftBottom, isRightBottom; + + private static RoundRadiusTransform mInstance; + + public RoundRadiusTransform(int roundingRadius) { + this.roundingRadius = roundingRadius; + } + public RoundRadiusTransform(int roundingRadius,boolean leftTop, boolean rightTop, boolean leftBottom, boolean rightBottom) { + this.roundingRadius = roundingRadius; + setNeedCorner(leftTop, rightTop, leftBottom, rightBottom); + } + + /** + * 需要设置圆角的部分 + * + * @param leftTop 左上角 + * @param rightTop 右上角 + * @param leftBottom 左下角 + * @param rightBottom 右下角 + */ + public void setNeedCorner(boolean leftTop, boolean rightTop, boolean leftBottom, boolean rightBottom) { + isLeftTop = leftTop; + isRightTop = rightTop; + isLeftBottom = leftBottom; + isRightBottom = rightBottom; + } + + @Override + protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { + return TransformationUtils.roundedCorners(pool, toTransform, + isLeftTop ? roundingRadius : 0, + isRightTop ? roundingRadius : 0, + isRightBottom ? roundingRadius : 0, + isLeftBottom ? roundingRadius : 0); + } + + + @Override + public boolean equals(Object o) { + if (o instanceof RoundRadiusTransform) { + RoundRadiusTransform other = (RoundRadiusTransform) o; + return roundingRadius == other.roundingRadius; + } + return false; + } + + @Override + public int hashCode() { + return Util.hashCode(ID.hashCode(), Util.hashCode(roundingRadius)); + } + + @Override + public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { + messageDigest.update(ID_BYTES); + + byte[] radiusData = ByteBuffer.allocate(4).putInt(roundingRadius).array(); + messageDigest.update(radiusData); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/glide/transform/TransformationFitXYUtils.java b/app/src/main/java/com/bonait/bnframework/common/glide/transform/TransformationFitXYUtils.java new file mode 100644 index 00000000..e9442506 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/glide/transform/TransformationFitXYUtils.java @@ -0,0 +1,155 @@ +package com.bonait.bnframework.common.glide.transform; + +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.RectF; + +import androidx.annotation.NonNull; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.TransformationUtils; +import com.bumptech.glide.util.Synthetic; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; + +/** + * @author Nov + * @date 23.7.11 + */ +public class TransformationFitXYUtils { + private static final Lock BITMAP_DRAWABLE_LOCK = + new NoLock(); + + @NonNull + private static Bitmap.Config getNonNullConfig(@NonNull Bitmap bitmap) { + return bitmap.getConfig() != null ? bitmap.getConfig() : Bitmap.Config.ARGB_8888; + } + + private static void applyMatrix( + @NonNull Bitmap inBitmap, @NonNull Bitmap targetBitmap, Matrix matrix) { + BITMAP_DRAWABLE_LOCK.lock(); + try { + Canvas canvas = new Canvas(targetBitmap); + canvas.drawBitmap(inBitmap, matrix, DEFAULT_PAINT); + clear(canvas); + } finally { + BITMAP_DRAWABLE_LOCK.unlock(); + } + } + + public static final int PAINT_FLAGS = Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG; + private static final Paint DEFAULT_PAINT = new Paint(PAINT_FLAGS); + + private static final class NoLock implements Lock { + + @Synthetic + NoLock() { + } + + @Override + public void lock() { + // do nothing + } + + @Override + public void lockInterruptibly() throws InterruptedException { + // do nothing + } + + @Override + public boolean tryLock() { + return true; + } + + @Override + public boolean tryLock(long time, @NonNull TimeUnit unit) throws InterruptedException { + return true; + } + + @Override + public void unlock() { + // do nothing + } + + @NonNull + @Override + public Condition newCondition() { + throw new UnsupportedOperationException("Should not be called"); + } + } + + private static void clear(Canvas canvas) { + canvas.setBitmap(null); + } + + + public static Bitmap fitXY( + @NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int width, int height) { + + if (inBitmap.getWidth() == width && inBitmap.getHeight() == height) { + return inBitmap; + } + final float widthPercentage = width / (float) inBitmap.getWidth(); + final float heightPercentage = height / (float) inBitmap.getHeight(); + int targetWidth = (int) (widthPercentage * inBitmap.getWidth()); + int targetHeight = (int) (heightPercentage * inBitmap.getHeight()); + + Bitmap.Config config = getNonNullConfig(inBitmap); + Bitmap toReuse = pool.get(targetWidth, targetHeight, config); + TransformationUtils.setAlpha(inBitmap, toReuse); + Matrix matrix = new Matrix(); + matrix.setScale(widthPercentage, heightPercentage); + applyMatrix(inBitmap, toReuse, matrix); + return toReuse; + } + + public static Bitmap roundCrop(BitmapPool pool, + Bitmap source, + float topLeft, + float topRight, + float bottomRight, + float bottomLeft) { + if (source == null) return null; + + Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + if (result == null) { + result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + } + BitmapShader shader = + new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); + + Paint paint = new Paint(); + paint.setShader(shader); + paint.setAntiAlias(true); + RectF rect = new RectF(0f, 0f, source.getWidth(), source.getHeight()); + BITMAP_DRAWABLE_LOCK.lock(); + try { + Canvas canvas = new Canvas(result); + Path path = new Path(); + path.addRoundRect( + rect, + new float[]{ + topLeft, + topLeft, + topRight, + topRight, + bottomRight, + bottomRight, + bottomLeft, + bottomLeft + }, + Path.Direction.CW); + canvas.drawPath(path, paint); + clear(canvas); + } finally { + BITMAP_DRAWABLE_LOCK.unlock(); + } + return result; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/ActiveMax.java b/app/src/main/java/com/bonait/bnframework/common/helper/ActiveMax.java index 0ef76f41..d8760326 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/ActiveMax.java +++ b/app/src/main/java/com/bonait/bnframework/common/helper/ActiveMax.java @@ -1,18 +1,9 @@ package com.bonait.bnframework.common.helper; -import android.annotation.SuppressLint; -import android.app.ActionBar; import android.app.Activity; import android.os.Build; -import android.os.Handler; -import android.os.Looper; import android.view.View; import android.view.ViewTreeObserver; -import android.view.WindowInsets; -import android.view.WindowManager; - -import com.qmuiteam.qmui.util.QMUINotchHelper; -import com.qmuiteam.qmui.util.QMUIStatusBarHelper; import java.util.ArrayList; import java.util.List; @@ -49,6 +40,14 @@ public class ActiveMax { // activity.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(setOnSystemUiVisibilityChangeListener); } + public static void destroy(Activity activity){ + if(activity!=null){ + activities.remove(activity); + activity.getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(keyboardVisibilityListener); + } + + } + /** * 状态栏变化后事件 */ @@ -111,4 +110,5 @@ public class ActiveMax { // 非全屏显示,显示状态栏和导航栏 activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } + } diff --git a/app/src/main/java/com/bonait/bnframework/common/utils/DimensUtil.java b/app/src/main/java/com/bonait/bnframework/common/utils/DimensUtil.java new file mode 100644 index 00000000..ce0127de --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/utils/DimensUtil.java @@ -0,0 +1,75 @@ +package com.bonait.bnframework.common.utils; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Rect; +import android.graphics.drawable.AnimationDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.NinePatchDrawable; + +import com.bonait.bnframework.MainApplication; + + +/** + * @author: HY + * @date: 2022/11/30 + * @description + **/ +public class DimensUtil { + /** + * 正数 + * + * @param px + * @return + */ + public static int getDimens(int px) { +// LogUtils.d(px + " >>getDimens >>>"); + String paramString = "dp_" + px; + int id = MainApplication.getContext().getResources().getIdentifier(paramString, "dimen", + MainApplication.getContext().getPackageName()); + + int result = (int) MainApplication.getContext().getResources().getDimension(id); +// LogUtils.d(px + " >>getDimens >>>" + result); + return result; + } + + public static float getDimensSp(int sp) { + String paramString = "sp_" + sp; + int id = MainApplication.getContext().getResources().getIdentifier(paramString, "dimen", + MainApplication.getContext().getPackageName()); + + float result_sp = MainApplication.getContext().getResources().getDimension(id); + final float fontScale = MainApplication.getContext().getResources().getDisplayMetrics().scaledDensity; + float result_px = result_sp / fontScale; +// LogUtils.d(sp + " >>getDimensSp >>>" + result_sp + ">>>result_px " + result_px); + return result_px; + } + /** + * 点9 图片需要特殊处理下 + * @return + */ + public static Drawable getFocusDrawable() { +// BitmapFactory.Options options = new BitmapFactory.Options(); +// options.inDensity = 160;//mdpi -----> 160 +// Bitmap bitmap = BitmapFactory.decodeResource(MainApplication.getContext().getResources(), +// R.drawable.bg_card_focus, options); +// Drawable drawable = new NinePatchDrawable(MainApplication.getContext().getResources(), +// bitmap, bitmap.getNinePatchChunk(), new Rect(), null); + + //呼吸灯 + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inDensity = 160; + AnimationDrawable animationDrawable = new AnimationDrawable(); + animationDrawable.setOneShot(false); + int[] drawableIds = new int[]{}; + for (int drawableId : drawableIds) { + Bitmap bitmap = BitmapFactory.decodeResource(MainApplication.getContext().getResources(), drawableId, + options); + animationDrawable.addFrame(new NinePatchDrawable( + MainApplication.getContext().getResources(), bitmap, bitmap.getNinePatchChunk(), new Rect(), + null), 100); + } + return animationDrawable; + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/common/utils/ProcessValueUtil.java b/app/src/main/java/com/bonait/bnframework/common/utils/ProcessValueUtil.java new file mode 100644 index 00000000..c790bf1f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/utils/ProcessValueUtil.java @@ -0,0 +1,39 @@ +package com.bonait.bnframework.common.utils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 16:34. + */ +public class ProcessValueUtil { + public static HashMap dealProcessValue(String value){ + //工序名称和值 + HashMap formulation = new HashMap<>(); + if(!value.isEmpty()){ + List data = new ArrayList<>(); + if (value.contains("|")) { + String[] res = value.split("[|]"); + data.addAll(Arrays.asList(res)); + } else { + data.add(value); + } + for (String item : data) { + if (item.contains(",")) { + String[] wl = item.split("[,]"); + if (wl.length == 2) { + String name = wl[0]; + String val = wl[1]; + formulation.put(name, val); + } + } + } + } + + return formulation; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/event/FreshLocalGoodsEvent.java b/app/src/main/java/com/bonait/bnframework/event/FreshLocalGoodsEvent.java new file mode 100644 index 00000000..f46adef9 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/event/FreshLocalGoodsEvent.java @@ -0,0 +1,12 @@ +package com.bonait.bnframework.event; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 15:13. + */ +public class FreshLocalGoodsEvent { + public FreshLocalGoodsEvent(){ + + } +} diff --git a/app/src/main/java/com/bonait/bnframework/event/ImageSelectEvent.java b/app/src/main/java/com/bonait/bnframework/event/ImageSelectEvent.java new file mode 100644 index 00000000..e40181e9 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/event/ImageSelectEvent.java @@ -0,0 +1,13 @@ +package com.bonait.bnframework.event; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 9:12. + */ +public class ImageSelectEvent { + public String url; + public ImageSelectEvent(String url){ + this.url = url; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/activity/EditClassifyActivity.java b/app/src/main/java/com/bonait/bnframework/ui/activity/EditClassifyActivity.java index a4a884d3..a83e92a5 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/activity/EditClassifyActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ui/activity/EditClassifyActivity.java @@ -190,9 +190,12 @@ public class EditClassifyActivity extends BaseActivity { }); } + + @SuppressLint("NonConstantResourceId") @OnClick({R.id.btn_add_classify,R.id.btn_add_attribute,R.id.btn_delete_attribute,R.id.btn_add_subattribute,R.id.btn_delete_classify}) public void onViewClicked(View view) { + switch (view.getId()){ case R.id.btn_add_classify://添加分类 AlertDialogUtils.showCancelAndConfirmDialog(this, R.layout.dialog_add_classify, (layoutView, xCom) -> { diff --git a/app/src/main/java/com/bonait/bnframework/ui/activity/EditProcessActivity.java b/app/src/main/java/com/bonait/bnframework/ui/activity/EditProcessActivity.java new file mode 100644 index 00000000..8628c728 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/ui/activity/EditProcessActivity.java @@ -0,0 +1,9 @@ +package com.bonait.bnframework.ui.activity; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 17:26. + */ +public class EditProcessActivity { +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/adapter/ClassifySpinnerAdapter.java b/app/src/main/java/com/bonait/bnframework/ui/adapter/ClassifySpinnerAdapter.java new file mode 100644 index 00000000..1fda7279 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/ui/adapter/ClassifySpinnerAdapter.java @@ -0,0 +1,60 @@ +package com.bonait.bnframework.ui.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.utils.DisplayManager; + +import java.util.List; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 13:45. + */ +public class ClassifySpinnerAdapter extends BaseAdapter { + private Context context; + private List data; + public ClassifySpinnerAdapter(@NonNull Context context ,List data) { + this.context = context; + this.data = data; + } + + @Override + public int getCount() { + return data.size(); + } + + @Override + public String getItem(int i) { + return data.get(i); + } + + @Override + public long getItemId(int i) { + return 0; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + if(convertView == null){ + convertView = LayoutInflater.from(context).inflate(R.layout.item_spinner_text, null); + } + TextView textView = convertView.findViewById(R.id.textViewCustom); + textView.setText(getItem(position)); + if(textView.getTextSize()>34||textView.getTextSize()<30){ + DisplayManager.scaleViewGroup(convertView.findViewById(R.id.root)); + } + + return convertView; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/adapter/CloudGoodsAdapter.java b/app/src/main/java/com/bonait/bnframework/ui/adapter/CloudGoodsAdapter.java index 86e49ee7..9fcc6c23 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/adapter/CloudGoodsAdapter.java +++ b/app/src/main/java/com/bonait/bnframework/ui/adapter/CloudGoodsAdapter.java @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseAdapter; import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.util.GoodsDBUtil; import com.bonait.bnframework.common.glide.GlideUtil; import com.bonait.bnframework.common.utils.DisplayManager; import com.bonait.bnframework.common.utils.ToastUtils; @@ -49,7 +50,7 @@ public abstract class CloudGoodsAdapter extends BaseAdapter { + + private List subAttributeAdapters = new ArrayList<>(); + private int resource1; + public List datas; + public SelectAttributeListAdapter(@NonNull Context context, int resource, @NonNull List objects) { + super(context, resource, objects); + subAttributeAdapters.clear(); + this.resource1 = resource; + datas = objects; + } + + //每个子项被滚动到屏幕内的时候会被调用 + @SuppressLint("MissingInflatedId") + @NonNull + @Override + public View getView(int position, @Nullable View view, @NonNull ViewGroup parent) { + BPA_ATTRIBUTE bean = (BPA_ATTRIBUTE) datas.get(position);//得到当前项选中item实例 + //为每一个子项加载设定的布局 + if (view == null){ + view = LayoutInflater.from(getContext()).inflate(resource1, parent, false); + //分别获取 image view 和 textview 的实例 + TextView name = view.findViewById(R.id.attribute_name); + RecyclerView recyclerView = view.findViewById(R.id.recycle_sub_attribute); + if(name.getTextSize()>34||name.getTextSize()<30){ + DisplayManager.scaleViewGroup(view.findViewById(R.id.root)); + } + name.setText(bean.name+":"); + + if(recyclerView.getAdapter()==null && position == subAttributeAdapters.size()){ + List subattributeList = SubAttributeDBUtil.getByParentAttributeId(bean.id); + SelectSubAttributeAdapter adapter = new SelectSubAttributeAdapter(); + adapter.setNewData(subattributeList); + adapter.setCurrentPosition(-1); + recyclerView.setAdapter(adapter); + LogUtils.d(" SelectAttributeListAdapter getView position="+position); + if(position == subAttributeAdapters.size()){ + subAttributeAdapters.add(adapter); + } + } + } + return view; + } + + /** + * 判断是否都选中 + * @return + */ + public boolean isAllSelected(){ + boolean select = true; + for (SelectSubAttributeAdapter adapter:subAttributeAdapters){ + LogUtils.d(" getSubAttributeList adapter.getCurrentPosition() = "+adapter.getCurrentPosition()); + if(adapter.getCurrentPosition() < 0){ + select = false; + } + } + return select; + } + + /** + * 返回选中的子属性组合 “a-b”形式 + */ + public String getSubAttributeList(){ + StringBuilder list = new StringBuilder(); + for (SelectSubAttributeAdapter adapter:subAttributeAdapters){ + if(adapter.getCurrentPosition() >= 0 && adapter.getData().size()>adapter.getCurrentPosition()){ + list.append(adapter.getData().get(adapter.getCurrentPosition()).name).append("-"); + } + } + String groupName = list.substring(0,list.length()-1); + LogUtils.d(" getSubAttributeList groupName="+groupName); + return groupName; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/adapter/SelectSubAttributeAdapter.java b/app/src/main/java/com/bonait/bnframework/ui/adapter/SelectSubAttributeAdapter.java new file mode 100644 index 00000000..9bfbfa6b --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/ui/adapter/SelectSubAttributeAdapter.java @@ -0,0 +1,69 @@ +package com.bonait.bnframework.ui.adapter; + +import android.annotation.SuppressLint; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.bonait.bnframework.common.base.BaseAdapter; +import com.bonait.bnframework.common.db.mode.BPA_SUBATTRIBUTE; +import com.bonait.bnframework.common.utils.DisplayManager; +import com.bonait.bnframework.databinding.ItemSelectSubattributeBinding; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 9:50. + */ +public class SelectSubAttributeAdapter extends BaseAdapter { + + + @NonNull + @Override + public SelectSubAttributeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new SelectSubAttributeAdapter.ViewHolder(ItemSelectSubattributeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull SelectSubAttributeAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) { + try { + if(holder.binding.name.getTextSize()>34||holder.binding.name.getTextSize()<30){ + DisplayManager.scaleViewGroup(holder.binding.getRoot()); + } + BPA_SUBATTRIBUTE subattribute = mData.get(position); + holder.binding.name.setText(subattribute.name+""); + holder.binding.name.setSelected(mCurrentPosition == position); + + holder.binding.name.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int last = mCurrentPosition; + mCurrentPosition = position; + notifyItemChanged(last); + notifyItemChanged(mCurrentPosition); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + protected void onItemClick(View v, int position) { + + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + private ItemSelectSubattributeBinding binding; + + + public ViewHolder(ItemSelectSubattributeBinding view) { + super(view.getRoot()); + binding = view; + } + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/dialog/AddGoodsDialog.java b/app/src/main/java/com/bonait/bnframework/ui/dialog/AddGoodsDialog.java new file mode 100644 index 00000000..de7985a5 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/ui/dialog/AddGoodsDialog.java @@ -0,0 +1,273 @@ +package com.bonait.bnframework.ui.dialog; + +import android.annotation.SuppressLint; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.AdapterView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + +import com.apkfuns.logutils.LogUtils; +import com.bonait.bnframework.R; +import com.bonait.bnframework.ViewModel.ActivityViewModel.ImageChooseActivity; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.mode.BPA_GOODS_CLASSIFY; +import com.bonait.bnframework.common.db.util.GoodsClassifyDBUtil; +import com.bonait.bnframework.common.db.util.GoodsDBUtil; +import com.bonait.bnframework.common.glide.GlideUtil; +import com.bonait.bnframework.common.utils.DimensUtil; +import com.bonait.bnframework.common.utils.DisplayManager; +import com.bonait.bnframework.databinding.DialogAddGoodsBinding; +import com.bonait.bnframework.event.FreshLocalGoodsEvent; +import com.bonait.bnframework.event.ImageSelectEvent; +import com.bonait.bnframework.ui.adapter.ClassifySpinnerAdapter; +import com.bonait.bnframework.ui.widget.NewToastUtil; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.ButterKnife; +import butterknife.OnClick; + +/** + * @author: liup + * @description: + * @date: 2024/5/14 16:10. + */ +public class AddGoodsDialog extends DialogFragment { + private String TAG = " AddGoodsDialog =>"; + private DialogAddGoodsBinding viewBinding; + private ClassifySpinnerAdapter spinnerAdapter; + private ArrayList classifyList = new ArrayList<>(); + private int classifyPosition = -1; + private String picUrl = ""; + public boolean isDismiss = false; + + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setStyle(STYLE_NORMAL, R.style.DialogLeft); + if(getArguments()!=null){ + classifyPosition = getArguments().getInt("classifyPosition"); + } + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + viewBinding = DialogAddGoodsBinding.inflate(inflater,container,false); + ButterKnife.bind(this, viewBinding.getRoot()); + DisplayManager.scaleViewGroup(viewBinding.getRoot()); + return viewBinding.getRoot(); + } + + + + @Override + public void onStart() { + super.onStart(); + if(getDialog()!=null){ + Window window = getDialog().getWindow(); + assert window != null; + window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + WindowManager.LayoutParams params = window.getAttributes(); + params.gravity = Gravity.CENTER; + params.width = ViewGroup.LayoutParams.MATCH_PARENT; + params.height = ViewGroup.LayoutParams.MATCH_PARENT; + window.setAttributes(params); + } + updateClassifyData(classifyPosition); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initView(); + } + + private void initView(){ + viewBinding.layoutClassify.spinnerClassify.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + classifyPosition = i; + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + } + + /** + * 点击事件 + * + * @param view + */ + @SuppressLint("NonConstantResourceId") + @OnClick({R.id.btn_close1, R.id.btn_close2, + R.id.btn_next1,R.id.btn_next2,R.id.btn_last1, + R.id.good_image,R.id.btn_last2}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.btn_close1: + case R.id.btn_close2: + case R.id.btn_last1: + dismiss(); + break; + case R.id.btn_next1: + changePage(2); + break; + case R.id.btn_next2: + submit(); + break; + case R.id.btn_last2: + changePage(1); + break; + case R.id.good_image: + Intent intent = new Intent(getContext(), ImageChooseActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + break; + } + } + + /** + * 上一步 下一步切换 + * @param pos + */ + @SuppressLint("SetTextI18n") + public void changePage(int pos){ + switch (pos){ + case 1: + viewBinding.layoutName.getRoot().setVisibility(View.GONE); + viewBinding.layoutClassify.getRoot().setVisibility(View.VISIBLE); + + break; + case 2: + if(classifyList.isEmpty() || classifyPosition < 0 || classifyPosition>=classifyList.size()){ + if(getContext()!=null){ + NewToastUtil.showToast(getContext(),"请选择分类", Toast.LENGTH_SHORT); + } + return; + } + viewBinding.layoutClassify.getRoot().setVisibility(View.GONE); + viewBinding.layoutName.getRoot().setVisibility(View.VISIBLE); + viewBinding.layoutName.title2.setText(viewBinding.layoutClassify.spinnerClassify.getSelectedItem().toString()+""); + break; + } + } + + /** + * 最后一步提交 + */ + private void submit(){ + String name = viewBinding.layoutName.editName.getText().toString(); + LogUtils.d(TAG+" name="+name); + if(name.isEmpty()){ + if(getContext()!=null){ + NewToastUtil.showToast(getContext(),"名称不能为空", Toast.LENGTH_SHORT); + } + return; + } + if(GoodsDBUtil.getByName(name)!=null){ + if(getContext()!=null){ + NewToastUtil.showToast(getContext(),"已有菜品,请换一个名称", Toast.LENGTH_SHORT); + } + return; + } + BPA_GOODS_CLASSIFY classify = classifyList.get(classifyPosition); + BPA_GOODS goods = new BPA_GOODS(); + goods.name = name; + goods.classifyId = classify.id; + goods.url = picUrl; + GoodsDBUtil.add(goods); + dismiss(); + EventBus.getDefault().post(new FreshLocalGoodsEvent()); + } + + + /** + * 更新分类数据 + * @param position + */ + public void updateClassifyData(int position){ + classifyPosition = position; + classifyList.clear(); + classifyList.addAll(GoodsClassifyDBUtil.getAll()); + List classifyNameList = new ArrayList<>(); + for(BPA_GOODS_CLASSIFY bean: classifyList){ + classifyNameList.add(bean.name); + } + LogUtils.d(" updateClassifyData getContext()="+getContext()); + if(getContext()!=null){ + spinnerAdapter = new ClassifySpinnerAdapter(getContext(), classifyNameList); +// spinnerAdapter.setDropDownViewResource(R.layout.item_h90_spinner_dropdown_text32); + + viewBinding.layoutClassify.spinnerClassify.setAdapter(spinnerAdapter); + viewBinding.layoutClassify.spinnerClassify.setSelection(position); + } + } + + + /** + * 更新图片 + * @param url + */ + public void updateImage(String url){ + picUrl = url; + LogUtils.d(TAG+" updateCircleImage url="+url); + GlideUtil.showImageWithRadius(getContext(),url,viewBinding.layoutName.goodImage, + R.mipmap.loading123, DimensUtil.getDimens(0)); + } + + @Override + public void onDismiss(@NonNull DialogInterface dialog) { + LogUtils.d(TAG+" onDismiss "); + isDismiss = true; + } + + @Override + public void onResume() { + super.onResume(); + LogUtils.d(TAG+" onResume "); + EventBus.getDefault().register(this); + isDismiss = false; + } + + @Override + public void onPause() { + super.onPause(); + LogUtils.d(TAG+" onPause "); + + EventBus.getDefault().unregister(this); + } + + @Override + public void onDestroy() { + super.onDestroy(); + LogUtils.d(TAG+" onDestroy "); + } + + //接收图片选择事件 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onImageSelectEvent(ImageSelectEvent event){ + updateImage(event.url); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/dialog/EditGoodsDialog.java b/app/src/main/java/com/bonait/bnframework/ui/dialog/EditGoodsDialog.java new file mode 100644 index 00000000..991a7c5a --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/ui/dialog/EditGoodsDialog.java @@ -0,0 +1,382 @@ +package com.bonait.bnframework.ui.dialog; + +import android.annotation.SuppressLint; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + +import com.apkfuns.logutils.LogUtils; +import com.bonait.bnframework.R; +import com.bonait.bnframework.ViewModel.ActivityViewModel.DiyUpdate1Activity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.ImageChooseActivity; +import com.bonait.bnframework.common.db.mode.BPA_ATTRIBUTE; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL; +import com.bonait.bnframework.common.db.mode.BPA_GOODS_SUBATTRIBUTE_GROUP; +import com.bonait.bnframework.common.db.util.AttributeDBUtil; +import com.bonait.bnframework.common.db.util.GoodsDBUtil; +import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil; +import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil; +import com.bonait.bnframework.common.glide.GlideUtil; +import com.bonait.bnframework.common.utils.DimensUtil; +import com.bonait.bnframework.common.utils.DisplayManager; +import com.bonait.bnframework.common.utils.ProcessValueUtil; +import com.bonait.bnframework.databinding.DialogEditGoodsBinding; +import com.bonait.bnframework.event.FreshLocalGoodsEvent; +import com.bonait.bnframework.event.ImageSelectEvent; +import com.bonait.bnframework.ui.adapter.SelectAttributeListAdapter; +import com.bonait.bnframework.ui.widget.NewToastUtil; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; + +import butterknife.ButterKnife; +import butterknife.OnClick; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 14:33. + */ +public class EditGoodsDialog extends DialogFragment { + private String TAG = " EditGoodsDialog =>"; + private DialogEditGoodsBinding viewBinding; + private String picUrl = ""; + private String goodId = ""; + private BPA_GOODS goods; + public boolean isDismiss = false; + /** + * 属性列表 + */ + private List attributeList = new ArrayList<>(); + /** + * 1-6个主料仓名称 + */ + ArrayList mainFoods = new ArrayList<>(); + /** + * 属性组合 + */ + private SelectAttributeListAdapter selectAttributeListAdapter; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setStyle(STYLE_NORMAL, R.style.DialogLeft); + if(getArguments()!=null){ + goodId = getArguments().getString("goodId"); + } + goods = GoodsDBUtil.getById(goodId); + if(goods!=null){ + attributeList = AttributeDBUtil.getByClassify(goods.classifyId); + } + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + viewBinding = DialogEditGoodsBinding.inflate(inflater,container,false); + ButterKnife.bind(this, viewBinding.getRoot()); + DisplayManager.scaleViewGroup(viewBinding.getRoot()); + return viewBinding.getRoot(); + } + + @Override + public void onStart() { + super.onStart(); + if(getDialog()!=null){ + Window window = getDialog().getWindow(); + assert window != null; + window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + WindowManager.LayoutParams params = window.getAttributes(); + params.gravity = Gravity.CENTER; + params.width = ViewGroup.LayoutParams.MATCH_PARENT; + params.height = ViewGroup.LayoutParams.MATCH_PARENT; + window.setAttributes(params); + } + updateNameLayout(); + updateAttributeData(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + } + + /** + * 点击事件 + * + * @param view + */ + @SuppressLint("NonConstantResourceId") + @OnClick({R.id.btn_close1, R.id.btn_close2,R.id.btn_close3, + R.id.btn_next1,R.id.btn_next2,R.id.btn_next3,R.id.btn_last1,R.id.btn_last3, + R.id.good_image,R.id.btn_last2}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.btn_close1: + case R.id.btn_close2: + case R.id.btn_close3: + case R.id.btn_last1: + dismiss(); + break; + case R.id.btn_next1: + String name = viewBinding.layoutName.editName.getText().toString(); + if(name.isEmpty()){ + if(getContext()!=null){ + NewToastUtil.showToast(getContext(),"名称不能为空", Toast.LENGTH_SHORT); + } + return; + } + //更新商品名称和图片 + goods.name = viewBinding.layoutName.editName.getText().toString(); + goods.url = picUrl; + GoodsDBUtil.update(goods); + EventBus.getDefault().post(new FreshLocalGoodsEvent()); + + if(attributeList.isEmpty()){ + changePage(3); + }else { + changePage(2); + } + break; + case R.id.btn_next2: + if(!selectAttributeListAdapter.isAllSelected()){ + if(getContext()!=null){ + NewToastUtil.showToast(getContext(),"请选择每行对应的子属性", Toast.LENGTH_SHORT); + } + return; + } + changePage(3); + break; + case R.id.btn_last3: + jumpToCook(); + break; + case R.id.btn_next3: + jumpToEdit(); + break; + case R.id.btn_last2: + changePage(1); + break; + case R.id.good_image: + Intent intent = new Intent(getContext(), ImageChooseActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + break; + } + } + + /** + * 上一步 下一步切换 + * @param pos + */ + @SuppressLint("SetTextI18n") + public void changePage(int pos){ + switch (pos){ + case 1: + viewBinding.layoutName.getRoot().setVisibility(View.VISIBLE); + viewBinding.layoutMainfoods.getRoot().setVisibility(View.GONE); + viewBinding.layoutAttribute.getRoot().setVisibility(View.GONE); + break; + case 2: + + viewBinding.layoutName.getRoot().setVisibility(View.GONE); + viewBinding.layoutMainfoods.getRoot().setVisibility(View.GONE); + viewBinding.layoutAttribute.getRoot().setVisibility(View.VISIBLE); + break; + case 3: + + addAttributeGroup(); + updateMainFoodsName(selectAttributeListAdapter.getSubAttributeList()); + + LogUtils.d(TAG+" submit mainFoods="+ mainFoods); + viewBinding.layoutName.getRoot().setVisibility(View.GONE); + viewBinding.layoutAttribute.getRoot().setVisibility(View.GONE); + viewBinding.layoutMainfoods.getRoot().setVisibility(View.VISIBLE); + viewBinding.layoutMainfoods.title3.setText(goods.name+"-"+selectAttributeListAdapter.getSubAttributeList()); + break; + } + } + + /** + * 添加属性组 + */ + private void addAttributeGroup(){ + BPA_GOODS_SUBATTRIBUTE_GROUP subattributeGroup = new BPA_GOODS_SUBATTRIBUTE_GROUP(); + subattributeGroup.goodsId = goods.id; + subattributeGroup.maketime = 0; + subattributeGroup.name = ""; + if(selectAttributeListAdapter != null && selectAttributeListAdapter.datas!=null && !selectAttributeListAdapter.datas.isEmpty()){ + subattributeGroup.name = selectAttributeListAdapter.getSubAttributeList(); + } + SubAttributeGroupDBUtil.add(subattributeGroup); + } + + /** + * 将工序里的主料名称读出来 + */ + private void updateMainFoodsName(String groupName){ + viewBinding.layoutMainfoods.editName1.setText(""); + viewBinding.layoutMainfoods.editName2.setText(""); + viewBinding.layoutMainfoods.editName3.setText(""); + viewBinding.layoutMainfoods.editName4.setText(""); + viewBinding.layoutMainfoods.editName5.setText(""); + viewBinding.layoutMainfoods.editName6.setText(""); + ArrayList list = GoodsProcessDetailDBUtil.getByGoodsSubAttributeGroupName(groupName); + for(BPA_GOODS_PROCESS_DETAIL bean:list ){ + String processname = bean.processname; + if(processname.contains("主料")){ + String processvalue = bean.processvalue; + if(!processvalue.isEmpty()){ + HashMap params = ProcessValueUtil.dealProcessValue(processvalue); + if(!params.isEmpty()){ + int position = 0;//几号位 + String name = "";//主料名称 + for (HashMap.Entry entry : params.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if(key.contains("名称")){ + name = value; + }else if(key.contains("位置")){ + position = Integer.parseInt(value.replace("号位","")); + } + } + updateName(position,name); + } + } + } + } + } + + /** + * 更新单个主料仓名称 + */ + private void updateName(int position,String name){ + switch (position){ + case 1: + viewBinding.layoutMainfoods.editName1.setText(name); + break; + case 2: + viewBinding.layoutMainfoods.editName2.setText(name); + break; + case 3: + viewBinding.layoutMainfoods.editName3.setText(name); + break; + case 4: + viewBinding.layoutMainfoods.editName4.setText(name); + break; + case 5: + viewBinding.layoutMainfoods.editName5.setText(name); + break; + case 6: + viewBinding.layoutMainfoods.editName6.setText(name); + break; + } + } + + /** + * 跳转去烹饪页面 + */ + private void jumpToCook(){ + //TODO + dismiss(); + } + + /** + * 跳转去编辑页面 + */ + private void jumpToEdit(){ + mainFoods.clear(); + mainFoods.add(viewBinding.layoutMainfoods.editName1.getText().toString()); + mainFoods.add(viewBinding.layoutMainfoods.editName2.getText().toString()); + mainFoods.add(viewBinding.layoutMainfoods.editName3.getText().toString()); + mainFoods.add(viewBinding.layoutMainfoods.editName4.getText().toString()); + mainFoods.add(viewBinding.layoutMainfoods.editName5.getText().toString()); + mainFoods.add(viewBinding.layoutMainfoods.editName6.getText().toString()); + //TODO + Intent intent = new Intent(getContext(), DiyUpdate1Activity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putStringArrayListExtra("mainFoods",mainFoods); + intent.putExtra("attributeGroupName",selectAttributeListAdapter.getSubAttributeList()); + startActivity(intent); + dismiss(); + } + + /** + * 更新名称 + */ + private void updateNameLayout(){ + viewBinding.layoutName.editName.setText(Objects.requireNonNull(GoodsDBUtil.getById(goodId)).name); + } + + /** + * 刷新属性数据 + */ + public void updateAttributeData(){ + LogUtils.d(TAG+" updateAttributeData"); + selectAttributeListAdapter = new SelectAttributeListAdapter(getContext(), R.layout.item_select_attribute_list,attributeList); + viewBinding.layoutAttribute.listAttribute.setAdapter(selectAttributeListAdapter); + } + + /** + * 更新图片 + * @param url + */ + public void updateImage(String url){ + picUrl = url; + LogUtils.d(TAG+" updateCircleImage url="+url); + GlideUtil.showImageWithRadius(getContext(),url,viewBinding.layoutName.goodImage, + R.mipmap.loading123, DimensUtil.getDimens(0)); + } + + @Override + public void onDismiss(@NonNull DialogInterface dialog) { + LogUtils.d(TAG+" onDismiss "); + isDismiss = true; + } + + @Override + public void onResume() { + super.onResume(); + LogUtils.d(TAG+" onResume "); + EventBus.getDefault().register(this); + isDismiss = false; + } + + @Override + public void onPause() { + super.onPause(); + LogUtils.d(TAG+" onPause "); + EventBus.getDefault().unregister(this); + } + + @Override + public void onDestroy() { + super.onDestroy(); + + LogUtils.d(TAG+" onDestroy "); + } + //接收图片选择事件 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onImageSelectEvent(ImageSelectEvent event){ + updateImage(event.url); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/fragment/CloudGoodsFragment.java b/app/src/main/java/com/bonait/bnframework/ui/fragment/CloudGoodsFragment.java index bcf793a2..d1a9c84b 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/fragment/CloudGoodsFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ui/fragment/CloudGoodsFragment.java @@ -1,7 +1,6 @@ package com.bonait.bnframework.ui.fragment; import android.annotation.SuppressLint; -import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -11,34 +10,25 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.lifecycle.ViewModelProvider; import com.apkfuns.logutils.LogUtils; import com.bonait.bnframework.Model.GoodsClassifyBean; -import com.bonait.bnframework.Model.ProcessValueUtil; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.db.mode.BPA_ATTRIBUTE; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODS_CLASSIFY; -import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL; -import com.bonait.bnframework.common.db.mode.BPA_GOODS_SUBATTRIBUTE_GROUP; -import com.bonait.bnframework.common.db.mode.BPA_SUBATTRIBUTE; -import com.bonait.bnframework.common.db.util.AttributeDBUtil; -import com.bonait.bnframework.common.db.util.GoodsClassifyDBUtil; import com.bonait.bnframework.common.db.util.GoodsDBUtil; -import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil; -import com.bonait.bnframework.common.db.util.SubAttributeDBUtil; -import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil; import com.bonait.bnframework.common.utils.DisplayManager; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.databinding.FragmentCloudGoodsBinding; -import com.bonait.bnframework.databinding.FragmentLocalGoodsBinding; +import com.bonait.bnframework.ui.viewmodel.HomeGoodsViewModel; import com.bonait.bnframework.ui.adapter.ClassifyAdapter; import com.bonait.bnframework.ui.adapter.CloudGoodsAdapter; import java.util.ArrayList; -import java.util.List; +import java.util.Objects; /** * @author: liup @@ -52,6 +42,13 @@ public class CloudGoodsFragment extends BaseFragment { private ArrayList goodsList = new ArrayList<>(); private ArrayList classifyList = new ArrayList<>(); private static final int MSG_FRESH_GOODS= 1; + private HomeGoodsViewModel viewModel; + + public static CloudGoodsFragment newInstance(HomeGoodsViewModel viewModel){ + CloudGoodsFragment fragment = new CloudGoodsFragment(); + fragment.viewModel = viewModel; + return fragment; + }; private Handler handler = new Handler(Looper.getMainLooper()){ @Override @@ -75,10 +72,18 @@ public class CloudGoodsFragment extends BaseFragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + viewModel = new ViewModelProvider(getActivity()).get(HomeGoodsViewModel.class); initView(); + initData(); updateData(); } + private void initData(){ + viewModel.cloudGoodsList.observe(getViewLifecycleOwner(),data->{ + updateData(); + }); + } + @Override protected int backViewInitOffset() { return 0; @@ -123,11 +128,13 @@ public class CloudGoodsFragment extends BaseFragment { private void dealClassifyData(){ classifyList.clear(); - for (GoodsClassifyBean bean : ConfigName.getInstance().cloudGoodsList){ - BPA_GOODS_CLASSIFY goodsClassify = new BPA_GOODS_CLASSIFY(); - goodsClassify.id = bean.getGoodsTypeId(); - goodsClassify.name = bean.getGoodsTypeName(); - classifyList.add(goodsClassify); + if(viewModel.cloudGoodsList.getValue()!=null){ + for (GoodsClassifyBean bean : Objects.requireNonNull(viewModel.cloudGoodsList.getValue())){ + BPA_GOODS_CLASSIFY goodsClassify = new BPA_GOODS_CLASSIFY(); + goodsClassify.id = bean.getGoodsTypeId(); + goodsClassify.name = bean.getGoodsTypeName(); + classifyList.add(goodsClassify); + } } classifyAdapter.setNewData(classifyList); } @@ -183,81 +190,7 @@ public class CloudGoodsFragment extends BaseFragment { ToastUtils.warning("请勿重复下载,本地商品已存在!!!"); return false; }else { - //商品不存在情况 - //判断分类是否存在 - if(GoodsClassifyDBUtil.getByName(goodsClassify.name)==null){ - GoodsClassifyDBUtil.add(goodsClassify); - } - //添加商品 - GoodsDBUtil.add(goods); - //添加属性 - for (GoodsClassifyBean bean : ConfigName.getInstance().cloudGoodsList){ - if(goodsClassify.id.equals(bean.getGoodsTypeId())){ - for(GoodsClassifyBean.GoodsAttributeListBean goodsAttributeListBean: bean.getGoodsAttributeList() ){ - //判断是否已有属性 不存在则添加 - if(!AttributeDBUtil.isExist(goodsClassify.id,goodsAttributeListBean.getGoodsAttributeName())){ - BPA_ATTRIBUTE attribute = new BPA_ATTRIBUTE(); - attribute.name = goodsAttributeListBean.getGoodsAttributeName(); - attribute.id = goodsAttributeListBean.getGoodsAttributeId(); - attribute.classifyId = goodsClassify.id; - AttributeDBUtil.add(attribute); - LogUtils.d(" 添加属性 成功"+goodsAttributeListBean.getGoodsAttributeName()); - }else { - LogUtils.d(" 已存在属性 "+goodsAttributeListBean.getGoodsAttributeName()); - } - //添加子属性 - for(GoodsClassifyBean.GoodsAttributeListBean.GoodsAttributeValueListBean goodsAttributeValueListBean :goodsAttributeListBean.getGoodsAttributeValueList() ){ - //判断是否已有子属性 不存在则添加 - if(!SubAttributeDBUtil.isExist(goodsAttributeListBean.getGoodsAttributeId(),goodsAttributeValueListBean.getAttributeValue())){ - BPA_SUBATTRIBUTE subattribute = new BPA_SUBATTRIBUTE(); - subattribute.parentAttributeId = goodsAttributeListBean.getGoodsAttributeId(); - subattribute.name = goodsAttributeValueListBean.getAttributeValue(); - subattribute.id = goodsAttributeValueListBean.getGoodsAttributeValueId(); - SubAttributeDBUtil.add(subattribute); - LogUtils.d(" 添加子属性 成功"+goodsAttributeValueListBean.getAttributeValue()); - }else { - LogUtils.d(" 已存在子属性 "+goodsAttributeValueListBean.getAttributeValue()); - } - } - - - - } - for(GoodsClassifyBean.GoodsInfoListBean goodsInfoListBean: bean.getGoodsInfoList() ){ - if(goodsInfoListBean.getGoodsName().equals(goods.name)){ - List groupList = new ArrayList<>(); - GoodsProcessDetailDBUtil.deleteByGoodsId(goods.id); - for (GoodsClassifyBean.GoodsInfoListBean.GoodsTechnologyActionListBean goodsTechnologyActionListBean:goodsInfoListBean.getGoodsTechnologyActionList()){ - //添加子属性组合 - //TODO 需确定getGoodsAttributeId 是用id列表还是name组合 app上新增的id和云端的肯定不匹配 建议用name组合 - if(!groupList.contains(goodsTechnologyActionListBean.getGoodsAttributeId())){ - if(!SubAttributeGroupDBUtil.isExist(goods.id,goodsTechnologyActionListBean.getGoodsAttributeId())){ - BPA_GOODS_SUBATTRIBUTE_GROUP group = new BPA_GOODS_SUBATTRIBUTE_GROUP(); - group.name = goodsTechnologyActionListBean.getGoodsAttributeId(); - group.id = goodsTechnologyActionListBean.getGoodsAttributeId(); - group.goodsId = goods.id; - groupList.add(goodsTechnologyActionListBean.getGoodsAttributeId()); - SubAttributeGroupDBUtil.add(group); - } - } - BPA_GOODS_PROCESS_DETAIL processDetail = new BPA_GOODS_PROCESS_DETAIL(); - processDetail.goodsSubAttributeGroupId = goodsTechnologyActionListBean.getGoodsAttributeId(); - processDetail.materialType = goodsTechnologyActionListBean.getStepName().contains("液体")?0:1; - String value = ProcessValueUtil.dealProcessJsonToValue(goodsTechnologyActionListBean.getActionJson()); - processDetail.processms = ""; - processDetail.processname = goodsTechnologyActionListBean.getStepName(); - processDetail.processvalue = value; - GoodsProcessDetailDBUtil.add(processDetail); - - } - } - break; - } - break; - } - } - - //添加所有工序 + viewModel.downLoadCloudGoods(goods,goodsClassify); } return true; } diff --git a/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeFoodsFragment.java b/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeFoodsFragment.java index 0f86fec9..61312156 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeFoodsFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeFoodsFragment.java @@ -13,23 +13,18 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; +import androidx.lifecycle.ViewModelProvider; import com.apkfuns.logutils.LogUtils; -import com.bonait.bnframework.Model.GoodsClassifyBean; import com.bonait.bnframework.R; import com.bonait.bnframework.Service.ModbusHelper; import com.bonait.bnframework.common.base.BaseFragment; -import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.common.model.ResListAPI; import com.bonait.bnframework.common.utils.DisplayManager; import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.databinding.FragmentHomeFoodsBinding; -import com.lzy.okgo.OkGo; -import com.lzy.okgo.model.HttpHeaders; -import com.lzy.okgo.model.Response; +import com.bonait.bnframework.ui.viewmodel.HomeGoodsViewModel; import com.orhanobut.logger.Logger; import butterknife.ButterKnife; @@ -53,6 +48,8 @@ public class HomeFoodsFragment extends BaseFragment { public Activity activity = null; + private HomeGoodsViewModel viewModel; + private Handler handler = new Handler(Looper.getMainLooper()){ @Override public void handleMessage(@NonNull Message msg) { @@ -83,6 +80,8 @@ public class HomeFoodsFragment extends BaseFragment { super.onViewCreated(view, savedInstanceState); context = getContext(); activity = getActivity(); + viewModel = new ViewModelProvider(getActivity()).get(HomeGoodsViewModel.class); + DisplayManager.scaleViewGroup(viewBinding.getRoot()); initTopBar(); SelectTab(1); @@ -121,39 +120,9 @@ public class HomeFoodsFragment extends BaseFragment { private void requestData(){ if (NetworkUtils.checkNetworkAvailable(context)) { - if(ConfigName.getInstance().cloudGoodsList.isEmpty()){ - //TODO 对接后台接口 - if (ConfigName.getInstance().organizeMode == null) { - return; - } + if(!viewModel.hasData){ ToastUtils.info("正在请求云端数据"); - OkGo.>get(String.format(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetGoods, - ConfigName.getInstance().organizeMode.id, ConfigName.getInstance().DeviceId)) - .tag(context) - .headers(new HttpHeaders("TenantId", ConfigName.getInstance().organizeMode.companyId)) - .execute(new JsonDialogCallback>(context) { - @Override - public void onSuccess(Response> response) { - ResListAPI allDataResAPI = response.body(); - - if (allDataResAPI.succeeded && allDataResAPI.data != null && allDataResAPI.data.size() > 0) { - ConfigName.getInstance().cloudGoodsList.clear(); - ConfigName.getInstance().cloudGoodsList.addAll(allDataResAPI.data); - } - if(handler!=null){ - handler.post(new Runnable() { - @Override - public void run() { - if(fragment!=null){ - if(fragment instanceof CloudGoodsFragment){ - ((CloudGoodsFragment) fragment).updateData(); - } - } - } - }); - } - } - }); + viewModel.fetchCloudData(context); } } else { ToastUtils.warning("无网络,请先连接网络!!!"); @@ -190,7 +159,7 @@ public class HomeFoodsFragment extends BaseFragment { if(index == 1){ fragment = new LocalGoodsFragment(); }else { - fragment = new CloudGoodsFragment(); + fragment = CloudGoodsFragment.newInstance(viewModel); } getChildFragmentManager().beginTransaction() .replace(R.id.frame, fragment) diff --git a/app/src/main/java/com/bonait/bnframework/ui/fragment/LocalGoodsFragment.java b/app/src/main/java/com/bonait/bnframework/ui/fragment/LocalGoodsFragment.java index ca34f2df..e02842c2 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/fragment/LocalGoodsFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ui/fragment/LocalGoodsFragment.java @@ -29,8 +29,15 @@ import com.bonait.bnframework.common.utils.DisplayManager; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.databinding.DialogDeleteClassifyBinding; import com.bonait.bnframework.databinding.FragmentLocalGoodsBinding; +import com.bonait.bnframework.event.FreshLocalGoodsEvent; import com.bonait.bnframework.ui.adapter.ClassifyAdapter; import com.bonait.bnframework.ui.adapter.LocalGoodsAdapter; +import com.bonait.bnframework.ui.dialog.AddGoodsDialog; +import com.bonait.bnframework.ui.dialog.EditGoodsDialog; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; @@ -47,6 +54,9 @@ public class LocalGoodsFragment extends BaseFragment { private ArrayList goodsList = new ArrayList<>(); private ArrayList classifyList = new ArrayList<>(); private static final int MSG_FRESH_GOODS= 1; + private Long FRESH_DELAY_TIME = 200L; + private AddGoodsDialog addGoodsDialog; + private EditGoodsDialog editGoodsDialog; private Handler handler = new Handler(Looper.getMainLooper()){ @Override @@ -91,7 +101,17 @@ public class LocalGoodsFragment extends BaseFragment { @Override protected void onItemClick(View v, int position) { - + if(!ConfigName.getInstance().user.name.equals("一般用户")){ + if(editGoodsDialog == null){ + editGoodsDialog= new EditGoodsDialog(); + } + Bundle bundle = new Bundle(); + bundle.putString("goodId",mData.get(position).id); + editGoodsDialog.setArguments(bundle); + if(getActivity()!=null){ + editGoodsDialog.show(getActivity().getSupportFragmentManager(),"editGoods"); + } + } } @Override @@ -123,7 +143,7 @@ public class LocalGoodsFragment extends BaseFragment { @Override protected void addGoods() { - + addGoodsDialog(); } }; viewBinding.recyclerGoods.setAdapter(goodsAdapter); @@ -133,12 +153,30 @@ public class LocalGoodsFragment extends BaseFragment { protected void onItemClick(View v, int position) { LogUtils.d("分类列表点击 position="+position+" name = "+mData.get(position).name); handler.removeMessages(MSG_FRESH_GOODS); - handler.sendEmptyMessageDelayed(MSG_FRESH_GOODS,500L);//避免快速点击 + handler.sendEmptyMessageDelayed(MSG_FRESH_GOODS,FRESH_DELAY_TIME);//避免快速点击 } }; + classifyAdapter.setCurrentPosition(0); viewBinding.recyclerClassify.setAdapter(classifyAdapter); } + /** + * 添加菜品弹窗 + */ + public void addGoodsDialog(){ + if(!classifyList.isEmpty() && getActivity()!=null){ + LogUtils.d(" addGoodsDialog addGoodsDialog="+addGoodsDialog); + if(addGoodsDialog == null){ + addGoodsDialog = new AddGoodsDialog(); + } + Bundle bundle = new Bundle(); + bundle.putInt("classifyPosition",classifyAdapter.getCurrentPosition()); + addGoodsDialog.setArguments(bundle); + addGoodsDialog.show(getActivity().getSupportFragmentManager(), "addGoods"); + } + } + + /** * 初始化数据加载 */ @@ -163,13 +201,22 @@ public class LocalGoodsFragment extends BaseFragment { public void onPause() { super.onPause(); LogUtils.d("LocalGoodsFragment onPause"); + EventBus.getDefault().unregister(this); + if(addGoodsDialog!=null && addGoodsDialog.isDismiss){ + addGoodsDialog.onDestroy(); + addGoodsDialog = null; + } + if(editGoodsDialog!=null && editGoodsDialog.isDismiss){ + editGoodsDialog.onDestroy(); + editGoodsDialog = null; + } } @Override public void onResume() { super.onResume(); LogUtils.d("LocalGoodsFragment onResume"); - + EventBus.getDefault().register(this); } @Override @@ -190,5 +237,22 @@ public class LocalGoodsFragment extends BaseFragment { handler.removeCallbacksAndMessages(null); handler = null; } + if(addGoodsDialog!=null){ + addGoodsDialog.onDestroy(); + addGoodsDialog = null; + } + if(editGoodsDialog!=null){ + editGoodsDialog.onDestroy(); + editGoodsDialog = null; + } + } + + //接收图片选择事件 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onImageSelectEvent(FreshLocalGoodsEvent event){ + if(handler!=null){ + handler.removeMessages(MSG_FRESH_GOODS); + handler.sendEmptyMessageDelayed(MSG_FRESH_GOODS,FRESH_DELAY_TIME);//避免快速点击 + } } } diff --git a/app/src/main/java/com/bonait/bnframework/ui/viewmodel/HomeGoodsViewModel.java b/app/src/main/java/com/bonait/bnframework/ui/viewmodel/HomeGoodsViewModel.java new file mode 100644 index 00000000..59e45b2c --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/ui/viewmodel/HomeGoodsViewModel.java @@ -0,0 +1,146 @@ +package com.bonait.bnframework.ui.viewmodel; + +import android.content.Context; + +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +import com.apkfuns.logutils.LogUtils; +import com.bonait.bnframework.Model.GoodsClassifyBean; +import com.bonait.bnframework.Model.ProcessValueUtil; +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.db.mode.BPA_ATTRIBUTE; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.mode.BPA_GOODS_CLASSIFY; +import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL; +import com.bonait.bnframework.common.db.mode.BPA_GOODS_SUBATTRIBUTE_GROUP; +import com.bonait.bnframework.common.db.mode.BPA_SUBATTRIBUTE; +import com.bonait.bnframework.common.db.util.AttributeDBUtil; +import com.bonait.bnframework.common.db.util.GoodsClassifyDBUtil; +import com.bonait.bnframework.common.db.util.GoodsDBUtil; +import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil; +import com.bonait.bnframework.common.db.util.SubAttributeDBUtil; +import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil; +import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; +import com.bonait.bnframework.common.model.ResListAPI; +import com.bonait.bnframework.common.utils.NetworkUtils; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.HttpHeaders; +import com.lzy.okgo.model.Response; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author: liup + * @description: + * @date: 2024/5/14 9:33. + */ +public class HomeGoodsViewModel extends ViewModel { + + public MutableLiveData> cloudGoodsList = new MutableLiveData<>(); + public boolean hasData = false; + + public void fetchCloudData(Context context){ + if (NetworkUtils.checkNetworkAvailable(context)) { + if (ConfigName.getInstance().organizeMode == null) { + return; + } + OkGo.>get(String.format(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetGoods, + ConfigName.getInstance().organizeMode.id, ConfigName.getInstance().DeviceId)) + .tag(context) + .headers(new HttpHeaders("TenantId", ConfigName.getInstance().organizeMode.companyId)) + .execute(new JsonDialogCallback>(context) { + @Override + public void onSuccess(Response> response) { + ResListAPI allDataResAPI = response.body(); + + if (allDataResAPI.succeeded && allDataResAPI.data != null && allDataResAPI.data.size() > 0) { +// ConfigName.getInstance().cloudGoodsList.clear(); +// ConfigName.getInstance().cloudGoodsList.addAll(allDataResAPI.data); + cloudGoodsList.setValue(allDataResAPI.data); + hasData = true; + } + } + }); + } + + } + + + public void downLoadCloudGoods(BPA_GOODS goods, BPA_GOODS_CLASSIFY goodsClassify){ + //商品不存在情况 + //判断分类是否存在 + if(GoodsClassifyDBUtil.getByName(goodsClassify.name)==null){ + GoodsClassifyDBUtil.add(goodsClassify); + } + //添加商品 + GoodsDBUtil.add(goods); + //添加属性 + for (GoodsClassifyBean bean : ConfigName.getInstance().cloudGoodsList){ + if(goodsClassify.id.equals(bean.getGoodsTypeId())){ + for(GoodsClassifyBean.GoodsAttributeListBean goodsAttributeListBean: bean.getGoodsAttributeList() ){ + //判断是否已有属性 不存在则添加 + if(!AttributeDBUtil.isExist(goodsClassify.id,goodsAttributeListBean.getGoodsAttributeName())){ + BPA_ATTRIBUTE attribute = new BPA_ATTRIBUTE(); + attribute.name = goodsAttributeListBean.getGoodsAttributeName(); + attribute.id = goodsAttributeListBean.getGoodsAttributeId(); + attribute.classifyId = goodsClassify.id; + AttributeDBUtil.add(attribute); + LogUtils.d(" 添加属性 成功"+goodsAttributeListBean.getGoodsAttributeName()); + }else { + LogUtils.d(" 已存在属性 "+goodsAttributeListBean.getGoodsAttributeName()); + } + //添加子属性 + for(GoodsClassifyBean.GoodsAttributeListBean.GoodsAttributeValueListBean goodsAttributeValueListBean :goodsAttributeListBean.getGoodsAttributeValueList() ){ + //判断是否已有子属性 不存在则添加 + if(!SubAttributeDBUtil.isExist(goodsAttributeListBean.getGoodsAttributeId(),goodsAttributeValueListBean.getAttributeValue())){ + BPA_SUBATTRIBUTE subattribute = new BPA_SUBATTRIBUTE(); + subattribute.parentAttributeId = goodsAttributeListBean.getGoodsAttributeId(); + subattribute.name = goodsAttributeValueListBean.getAttributeValue(); + subattribute.id = goodsAttributeValueListBean.getGoodsAttributeValueId(); + SubAttributeDBUtil.add(subattribute); + LogUtils.d(" 添加子属性 成功"+goodsAttributeValueListBean.getAttributeValue()); + }else { + LogUtils.d(" 已存在子属性 "+goodsAttributeValueListBean.getAttributeValue()); + } + } + + } + for(GoodsClassifyBean.GoodsInfoListBean goodsInfoListBean: bean.getGoodsInfoList() ){ + if(goodsInfoListBean.getGoodsName().equals(goods.name)){ + List groupList = new ArrayList<>(); + GoodsProcessDetailDBUtil.deleteByGoodsId(goods.id); + for (GoodsClassifyBean.GoodsInfoListBean.GoodsTechnologyActionListBean goodsTechnologyActionListBean:goodsInfoListBean.getGoodsTechnologyActionList()){ + //添加子属性组合 + //TODO 需确定getGoodsAttributeId 是用id列表还是name组合 app上新增的id和云端的肯定不匹配 建议用name组合 + if(!groupList.contains(goodsTechnologyActionListBean.getGoodsAttributeId())){ + if(!SubAttributeGroupDBUtil.isExist(goods.id,goodsTechnologyActionListBean.getGoodsAttributeId())){ + BPA_GOODS_SUBATTRIBUTE_GROUP group = new BPA_GOODS_SUBATTRIBUTE_GROUP(); + group.name = goodsTechnologyActionListBean.getGoodsAttributeId(); + group.id = goodsTechnologyActionListBean.getGoodsAttributeId(); + group.goodsId = goods.id; + groupList.add(goodsTechnologyActionListBean.getGoodsAttributeId()); + SubAttributeGroupDBUtil.add(group); + } + } + + //添加所有工序 + BPA_GOODS_PROCESS_DETAIL processDetail = new BPA_GOODS_PROCESS_DETAIL(); + processDetail.goodsSubAttributeGroupId = goodsTechnologyActionListBean.getGoodsAttributeId(); + processDetail.materialType = goodsTechnologyActionListBean.getStepName().contains("液体")?0:1; + String value = ProcessValueUtil.dealProcessJsonToValue(goodsTechnologyActionListBean.getActionJson()); + processDetail.processms = ""; + processDetail.processname = goodsTechnologyActionListBean.getStepName(); + processDetail.processvalue = value; + GoodsProcessDetailDBUtil.add(processDetail); + + } + } + break; + } + break; + } + } + } +} diff --git a/app/src/main/java/com/bonait/bnframework/ui/widget/NewToastUtil.java b/app/src/main/java/com/bonait/bnframework/ui/widget/NewToastUtil.java new file mode 100644 index 00000000..40fe5e83 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/ui/widget/NewToastUtil.java @@ -0,0 +1,70 @@ +package com.bonait.bnframework.ui.widget; + +import android.content.Context; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.style.ForegroundColorSpan; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Toast; + +import androidx.core.content.ContextCompat; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.utils.DimensUtil; +import com.bonait.bnframework.common.utils.DisplayManager; +import com.bonait.bnframework.databinding.ViewLayoutToastBinding; + +/** + * @author: liup + * @description: + * @date: 2024/5/15 11:10. + */ +public class NewToastUtil { + + public static void showToast(Context context,String message,int duration){ + Toast toast = new Toast(context); + String content = message; + if(message.length() > 50){ + content = message.substring(0,50)+"..."; + } + View layout = LayoutInflater.from(context).inflate(R.layout.view_layout_toast,null); + ViewLayoutToastBinding binding = ViewLayoutToastBinding.bind(layout); + DisplayManager.scaleViewGroup(binding.getRoot()); + binding.toastText.setText(content); + toast.setGravity(Gravity.BOTTOM,0,DimensUtil.getDimens(180)); + toast.setDuration(duration); + toast.setView(layout); + toast.show(); + } + + + /** + * 设置部分字体颜色 + * @param context + * @param message + * @param colorText + * @param duration + */ + public void showToastTextColor(Context context,String message,String colorText,int color,int duration){ + Toast toast = new Toast(context); + String content = message; + if(message.length() > 50){ + content = message.substring(0,50)+"..."; + } + View layout = LayoutInflater.from(context).inflate(R.layout.view_layout_toast,null); + ViewLayoutToastBinding binding = ViewLayoutToastBinding.bind(layout); + DisplayManager.scaleViewGroup(binding.getRoot()); + SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(content); + int index = content.indexOf(colorText); + if(index>0){ + spannableStringBuilder.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, color)),index,index+colorText.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); + } + binding.toastText.setText(spannableStringBuilder); + toast.setGravity(Gravity.BOTTOM,0,DimensUtil.getDimens(180)); + toast.setDuration(duration); + toast.setView(layout); + toast.show(); + } +} diff --git a/app/src/main/res/drawable/bg_round25_green_btn.xml b/app/src/main/res/drawable/bg_round25_green_btn.xml new file mode 100644 index 00000000..4d0bd159 --- /dev/null +++ b/app/src/main/res/drawable/bg_round25_green_btn.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/bg_round25_top_yellow.xml b/app/src/main/res/drawable/bg_round25_top_yellow.xml new file mode 100644 index 00000000..ef93b80e --- /dev/null +++ b/app/src/main/res/drawable/bg_round25_top_yellow.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/drawable/selector_select_sub_attribute_bg.xml b/app/src/main/res/drawable/selector_select_sub_attribute_bg.xml new file mode 100644 index 00000000..cf347b61 --- /dev/null +++ b/app/src/main/res/drawable/selector_select_sub_attribute_bg.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_select_sub_attribute_color.xml b/app/src/main/res/drawable/selector_select_sub_attribute_color.xml new file mode 100644 index 00000000..81834133 --- /dev/null +++ b/app/src/main/res/drawable/selector_select_sub_attribute_color.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_dishtest.xml b/app/src/main/res/layout/activity_dishtest.xml index cbb76716..d1d41f3e 100644 --- a/app/src/main/res/layout/activity_dishtest.xml +++ b/app/src/main/res/layout/activity_dishtest.xml @@ -616,7 +616,7 @@ F diff --git a/app/src/main/res/layout/dialog/layout/dialog_add_goods.xml b/app/src/main/res/layout/dialog/layout/dialog_add_goods.xml new file mode 100644 index 00000000..83770c79 --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/dialog_add_goods.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog/layout/dialog_delete_classify.xml b/app/src/main/res/layout/dialog/layout/dialog_delete_classify.xml index 7939bcee..e24c0d17 100644 --- a/app/src/main/res/layout/dialog/layout/dialog_delete_classify.xml +++ b/app/src/main/res/layout/dialog/layout/dialog_delete_classify.xml @@ -47,9 +47,9 @@ android:textColor="@color/white" android:text="确认" android:background="@drawable/bg_round25_yellow_btn" - android:layout_gravity="bottom|right" + android:layout_gravity="bottom" android:layout_marginBottom="@dimen/dp_20" - android:layout_marginRight="@dimen/dp_40" + android:layout_marginLeft="@dimen/dp_500" /> diff --git a/app/src/main/res/layout/dialog/layout/dialog_edit_goods.xml b/app/src/main/res/layout/dialog/layout/dialog_edit_goods.xml new file mode 100644 index 00000000..8cf99e07 --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/dialog_edit_goods.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog/layout/item_h90_spinner_dropdown_text32.xml b/app/src/main/res/layout/dialog/layout/item_h90_spinner_dropdown_text32.xml new file mode 100644 index 00000000..a2bb2d65 --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/item_h90_spinner_dropdown_text32.xml @@ -0,0 +1,12 @@ + + diff --git a/app/src/main/res/layout/dialog/layout/item_h90_spinner_text32.xml b/app/src/main/res/layout/dialog/layout/item_h90_spinner_text32.xml new file mode 100644 index 00000000..433064e3 --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/item_h90_spinner_text32.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/app/src/main/res/layout/dialog/layout/layout_add_goods_mainfood.xml b/app/src/main/res/layout/dialog/layout/layout_add_goods_mainfood.xml new file mode 100644 index 00000000..59323aa5 --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/layout_add_goods_mainfood.xml @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog/layout/layout_add_goods_name.xml b/app/src/main/res/layout/dialog/layout/layout_add_goods_name.xml new file mode 100644 index 00000000..aba7df71 --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/layout_add_goods_name.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog/layout/layout_add_goods_sel_classify.xml b/app/src/main/res/layout/dialog/layout/layout_add_goods_sel_classify.xml new file mode 100644 index 00000000..275863fb --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/layout_add_goods_sel_classify.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog/layout/layout_edit_goods_name.xml b/app/src/main/res/layout/dialog/layout/layout_edit_goods_name.xml new file mode 100644 index 00000000..2648e601 --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/layout_edit_goods_name.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog/layout/layout_edit_goods_sub_attribute.xml b/app/src/main/res/layout/dialog/layout/layout_edit_goods_sub_attribute.xml new file mode 100644 index 00000000..24cdd7ed --- /dev/null +++ b/app/src/main/res/layout/dialog/layout/layout_edit_goods_sub_attribute.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_local_goods.xml b/app/src/main/res/layout/fragment_local_goods.xml index 387360bc..54028ce3 100644 --- a/app/src/main/res/layout/fragment_local_goods.xml +++ b/app/src/main/res/layout/fragment_local_goods.xml @@ -62,6 +62,7 @@ app:spanCount="3" android:layout_height="match_parent"> + \ No newline at end of file diff --git a/app/src/main/res/layout/item/layout/item_local_goods.xml b/app/src/main/res/layout/item/layout/item_local_goods.xml index 43d40750..c5b0ec39 100644 --- a/app/src/main/res/layout/item/layout/item_local_goods.xml +++ b/app/src/main/res/layout/item/layout/item_local_goods.xml @@ -3,13 +3,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="@dimen/dp_185" - android:layout_height="@dimen/dp_215" - android:paddingBottom="@dimen/dp_30" + android:layout_height="@dimen/dp_185" > - + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item/layout/item_select_subattribute.xml b/app/src/main/res/layout/item/layout/item_select_subattribute.xml new file mode 100644 index 00000000..97d1f07d --- /dev/null +++ b/app/src/main/res/layout/item/layout/item_select_subattribute.xml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item/layout/item_spinner_text.xml b/app/src/main/res/layout/item/layout/item_spinner_text.xml new file mode 100644 index 00000000..589eb1e2 --- /dev/null +++ b/app/src/main/res/layout/item/layout/item_spinner_text.xml @@ -0,0 +1,24 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/item/layout/view_layout_toast.xml b/app/src/main/res/layout/item/layout/view_layout_toast.xml new file mode 100644 index 00000000..76ff4285 --- /dev/null +++ b/app/src/main/res/layout/item/layout/view_layout_toast.xml @@ -0,0 +1,34 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cf87ff95..4468358d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -135,4 +135,6 @@ #E24CAF50 #CCCBCB + #823E17 + #567722 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c5a08dd3..62f2b8b1 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -309,8 +309,45 @@ + + + + + + +