diff --git a/app/src/main/java/com/example/bpa/helper/T.java b/app/src/main/java/com/example/bpa/helper/T.java index 284ac41..2c5bc2f 100644 --- a/app/src/main/java/com/example/bpa/helper/T.java +++ b/app/src/main/java/com/example/bpa/helper/T.java @@ -7,10 +7,18 @@ import android.widget.Toast; * 自定义打印吐司函数 */ public class T { + + /** + * 信息通知+吐司弹窗 + * @param context + * @param str + */ public static void show(Context context, String str){ //Toast.makeText(context, str, (int)0).show(); ToastUtil.showToast(str); Log.i(context.getPackageName(),str); } + + } diff --git a/app/src/main/java/com/example/bpa/view/adapter/sp_adapter.java b/app/src/main/java/com/example/bpa/view/adapter/sp_adapter.java index 71cf5cd..186eaf7 100644 --- a/app/src/main/java/com/example/bpa/view/adapter/sp_adapter.java +++ b/app/src/main/java/com/example/bpa/view/adapter/sp_adapter.java @@ -42,6 +42,7 @@ public class sp_adapter extends ArrayAdapter { //分别获取 image view 和 textview 的实例 TextView name = view.findViewById(R.id.name); TextView sort = view.findViewById(R.id.sort); + TextView status = view.findViewById(R.id.status); TextView time = view.findViewById(R.id.time); Button button = view.findViewById(R.id.button_item); @@ -49,11 +50,14 @@ public class sp_adapter extends ArrayAdapter { Button button_down = view.findViewById(R.id.button_item_Down); Button button_update = view.findViewById(R.id.button_item_update); Button button_xf = view.findViewById(R.id.button_xf); + Button button_qy = view.findViewById(R.id.button_qy); + Button button_jy = view.findViewById(R.id.button_jy); // 设置要显示的图片和文字 name.setText(bpa_goods.name); time.setText(bpa_goods.createTime); sort.setText(bpa_goods.sort+""); + status.setText(bpa_goods.status==1?"启用":"禁用"); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -114,6 +118,31 @@ public class sp_adapter extends ArrayAdapter { } } }); + button_qy.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + try + { + mListener.clickListener(view,bpa_goods); + } catch (Exception e) + { + T.show(view.getContext(),"商品启用出错:"+e.getMessage()); + } + } + }); + button_jy.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + try + { + mListener.clickListener(view,bpa_goods); + } catch (Exception e) + { + T.show(view.getContext(),"商品禁用出错:"+e.getMessage()); + } + } + }); + return view; } } \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/fragment/HomeFragment.java b/app/src/main/java/com/example/bpa/view/fragment/HomeFragment.java index f43a398..e6e1383 100644 --- a/app/src/main/java/com/example/bpa/view/fragment/HomeFragment.java +++ b/app/src/main/java/com/example/bpa/view/fragment/HomeFragment.java @@ -5,22 +5,121 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; +import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ListView; import com.example.bpa.R; +import com.example.bpa.app.BusinessServer; +import com.example.bpa.db.QueryDB; +import com.example.bpa.db.mode.BPA_GOODS; +import com.example.bpa.helper.Json; +import com.example.bpa.helper.T; +import com.example.bpa.view.adapter.sp_adapter; +import com.example.bpa.view.from.add_pf_activity; +import com.example.bpa.view.from.yfpf_activity; +import com.example.bpa.view.inteface.MyClickListener; + +import java.util.ArrayList; /** * 主页界面 */ -public class HomeFragment extends Fragment { +public class HomeFragment extends Fragment implements View.OnClickListener, MyClickListener { + + //region 变量 + /** + * 界面实例 + */ + public View view; + /** + * 表格显示 + */ + public ListView datatab; + /** + * 商品数据 + */ + public ArrayList bpa_goods=new ArrayList<>(); + //endregion + //region 私有函数 @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_home, container,false); + view = inflater.inflate(R.layout.fragment_home, container,false); + Init(); return view; } + //endregion + + //region 公共函数 + /** + * 初始化 + */ + private void Init(){ + datatab= view.findViewById(R.id.datatab); + Initdata();//初始化数据 + RegisterMessage();//消息中心事件接收 + } + /** + * 初始化按钮事件 + */ + private void initEvents() { + + } + /** + * 初始化数据加载 + */ + public void Initdata() + { + try{ + bpa_goods= QueryDB.GetGoodsALL(); + sp_adapter adapter = new sp_adapter(view.getContext(), R.layout.sp_item, bpa_goods,this); + datatab.setAdapter(adapter); + }catch(Exception e){ + + } + } + //endregion + + //region 点击事件 + /** + * 本页面点击事件监听22 + * + * @param v + */ + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.buttonaddpf://新建配方 + + break; + } + } + + /** + * 接口方法,响应ListView按钮点击事件 + */ + @Override + public void clickListener(View v,Object data) { + switch (v.getId()) + { + case R.id.button_item://删除按钮 + + break; + + } + } + //endregion + + //region 接收事件 + public void RegisterMessage() + { + + } + //endregion } \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/from/add_pf_activity.java b/app/src/main/java/com/example/bpa/view/from/add_pf_activity.java index ab18b99..d3c2fd5 100644 --- a/app/src/main/java/com/example/bpa/view/from/add_pf_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/add_pf_activity.java @@ -204,7 +204,7 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi BPA_GOODS goodx = new BPA_GOODS(); goodx.name = name; goodx.sort = bpa_goods.size() + 1; - goodx.status = 1; + goodx.status = 0; goodx.deviceID = ConfigName.getInstance().DeviceId; goodx.userID = ConfigName.getInstance().user.userID; QueryDB.AddGoods(goodx); diff --git a/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java b/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java index 53bfb76..7ea7de5 100644 --- a/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java @@ -179,6 +179,20 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList BusinessServer.get().AddCommodity(((BPA_GOODS)data).id); T.show(this, "下发成功!"); break; + case R.id.button_qy://启用按钮 + BPA_GOODS good3=(BPA_GOODS)data; + good3.status=1; + QueryDB.UpdateGoods(good3); + Initdata(); + T.show(this, good3.name+"-启用成功!"); + break; + case R.id.button_jy://下发按钮 + BPA_GOODS good4=(BPA_GOODS)data; + good4.status=0; + QueryDB.UpdateGoods(good4); + Initdata(); + T.show(this, good4.name+"-禁用成功!"); + break; } } //endregion diff --git a/app/src/main/res/layout/datatab/layout/sp_item.xml b/app/src/main/res/layout/datatab/layout/sp_item.xml index bbe1b4e..0473081 100644 --- a/app/src/main/res/layout/datatab/layout/sp_item.xml +++ b/app/src/main/res/layout/datatab/layout/sp_item.xml @@ -18,7 +18,7 @@ + android:layout_weight="2"> + android:layout_weight="2"> + android:layout_weight="0.5"> + android:layout_weight="0.5"> + + + @@ -75,7 +90,7 @@ android:textColor="@color/foreground" android:layout_centerVertical="true" android:layout_marginLeft="20dp" - android:layout_width="60dp" + android:layout_width="40dp" android:layout_height="26dp" />