@@ -1,7 +1,7 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project version="4"> | |||
<component name="ExternalStorageConfigurationManager" enabled="true" /> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK"> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK"> | |||
<output url="file://$PROJECT_DIR$/build/classes" /> | |||
</component> | |||
<component name="ProjectType"> | |||
@@ -14,6 +14,7 @@ import androidx.fragment.app.FragmentManager; | |||
import androidx.fragment.app.FragmentTransaction; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.config.DataBus; | |||
import com.example.bpa.view.fragment.CloudFragment; | |||
import com.example.bpa.view.fragment.HeplerFragment; | |||
import com.example.bpa.view.fragment.HomeFragment; | |||
@@ -71,6 +72,7 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen | |||
clist_title.setText(ConfigName.getInstance().Shop_Name); | |||
//ShowFragment(homeFragment,"系统主页"); | |||
ShowFragment(systemCapabilitiesFragment,"功能菜单"); | |||
DataBus.getInstance().UpdateMainGoods(); | |||
} | |||
/** | |||
* 初始化按钮事件 | |||
@@ -2,6 +2,7 @@ package com.example.bpa.app; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.config.DataBus; | |||
import com.example.bpa.db.QueryDB; | |||
import com.example.bpa.db.mode.BPA_SYSTEMSET; | |||
import com.example.bpa.db.mode.BPA_USER; | |||
@@ -1,5 +1,15 @@ | |||
package com.example.bpa.config; | |||
import com.example.bpa.R; | |||
import com.example.bpa.db.QueryDB; | |||
import com.example.bpa.db.mode.BPA_GOODS; | |||
import com.example.bpa.view.mode.mainGoods; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* 单例模式 | |||
* 数据中心 | |||
@@ -8,7 +18,13 @@ public class DataBus { | |||
//region 单例模式 | |||
private static DataBus mInstance; //实例变量设置私有,防止直接通过类名访问 | |||
private DataBus() { //默认构造函数私有,防止类外直接new创建对象 | |||
private DataBus() { | |||
//默认构造函数私有,防止类外直接new创建对象 | |||
//测试添加图片 | |||
good_picMap.put(0, R.mipmap.milktea_1); | |||
good_picMap.put(1, R.mipmap.milktea_2); | |||
good_picMap.put(2,R.mipmap.milktea_3); | |||
good_picMap.put(3,R.mipmap.milktea_4); | |||
} | |||
public static synchronized DataBus getInstance() { //静态同步方法作为唯一的实例对象获取方式 | |||
@@ -20,6 +36,30 @@ public class DataBus { | |||
//endregion | |||
//region 数据中心 | |||
/** | |||
* 主界面商品列表 | |||
*/ | |||
public List<mainGoods> mainGoods = new ArrayList<mainGoods>(); | |||
public Map<Integer,Integer> good_picMap = new HashMap<Integer,Integer>(); | |||
/** | |||
* 更新商品主界面商品列表 | |||
*/ | |||
public void UpdateMainGoods(){ | |||
mainGoods.clear(); | |||
ArrayList<BPA_GOODS> res = QueryDB.GetGoodsStateALL(); | |||
if (res.size()>0){ | |||
for (BPA_GOODS good:res){ | |||
mainGoods newgood = new mainGoods(); | |||
newgood.id = good.id; | |||
newgood.name = good.name; | |||
newgood.message = ""; | |||
mainGoods.add(newgood); | |||
} | |||
} | |||
} | |||
//endregion | |||
} |
@@ -526,6 +526,22 @@ public class QueryDB { | |||
} | |||
return data; | |||
} | |||
/** | |||
* 获取所有启用的商品 | |||
* | |||
* @return | |||
*/ | |||
public static ArrayList<BPA_GOODS> GetGoodsStateALL() { | |||
String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序 | |||
String where = "isDelete=? and status=?"; | |||
String[] args = new String[]{"0","1"}; | |||
ArrayList<BPA_GOODS> data = new ArrayList<>(); | |||
ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby); | |||
for (Object k : obj) { | |||
data.add((BPA_GOODS) k); | |||
} | |||
return data; | |||
} | |||
/** | |||
* 判断商品数据是否存在 | |||
@@ -0,0 +1,94 @@ | |||
package com.example.bpa.view.adapter; | |||
import android.content.Context; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.Button; | |||
import android.widget.ImageView; | |||
import android.widget.TextView; | |||
import androidx.annotation.NonNull; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.example.bpa.R; | |||
import com.example.bpa.app.BusinessServer; | |||
import com.example.bpa.config.DataBus; | |||
import com.example.bpa.db.mode.BPA_GOODS; | |||
import com.example.bpa.helper.T; | |||
import com.example.bpa.view.mode.mainGoods; | |||
import java.util.List; | |||
import java.util.Random; | |||
public class maingoods_adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | |||
private final LayoutInflater mLayoutInflater; | |||
private Context context; | |||
List<mainGoods> mainGoods = DataBus.getInstance().mainGoods; | |||
public maingoods_adapter(Context context) { | |||
this.context = context; | |||
mLayoutInflater = LayoutInflater.from(context); | |||
} | |||
@NonNull | |||
@Override | |||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |||
View inflate = mLayoutInflater.inflate(R.layout.maingoods, parent, false); | |||
return new maingoods_adapter.MyLCViewHolder(inflate); | |||
} | |||
@Override | |||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | |||
try { | |||
if (holder instanceof maingoods_adapter.MyLCViewHolder) { | |||
maingoods_adapter.MyLCViewHolder myViewHolder = (maingoods_adapter.MyLCViewHolder) holder; | |||
myViewHolder.goodname.setText(mainGoods.get(position).name); | |||
myViewHolder.id = mainGoods.get(position).id; | |||
int num = (int) new Random().nextInt(DataBus.getInstance().good_picMap.size());//随机商品图片 | |||
myViewHolder.good_pic.setImageResource(DataBus.getInstance().good_picMap.get(num)); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mainGoods.size(); | |||
} | |||
public static class MyLCViewHolder extends RecyclerView.ViewHolder { | |||
TextView goodname; | |||
Button goodmake; | |||
ImageView good_pic; | |||
public String id; | |||
public MyLCViewHolder(View view) { | |||
super(view); | |||
goodname = (TextView) view.findViewById(R.id.goodname); | |||
goodmake = (Button) view.findViewById(R.id.goodmake); | |||
good_pic = (ImageView)view.findViewById(R.id.good_pic); | |||
goodmake.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
BusinessServer.get().AddCommodity(id); | |||
T.show(view.getContext(),"开始制作商品:"+goodname.getText().toString()); | |||
} | |||
}); | |||
} | |||
} | |||
} |
@@ -4,6 +4,8 @@ import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import androidx.fragment.app.Fragment; | |||
import androidx.recyclerview.widget.LinearLayoutManager; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import android.content.Intent; | |||
import android.os.Bundle; | |||
@@ -15,11 +17,14 @@ import android.widget.ListView; | |||
import com.example.bpa.R; | |||
import com.example.bpa.app.BusinessServer; | |||
import com.example.bpa.config.DataBus; | |||
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.maingoods_adapter; | |||
import com.example.bpa.view.adapter.sp_adapter; | |||
import com.example.bpa.view.control.MyLayoutManager; | |||
import com.example.bpa.view.from.add_pf_activity; | |||
import com.example.bpa.view.from.yfpf_activity; | |||
import com.example.bpa.view.inteface.MyClickListener; | |||
@@ -32,6 +37,10 @@ import java.util.ArrayList; | |||
public class HomeFragment extends Fragment implements View.OnClickListener, MyClickListener { | |||
//region 变量 | |||
/** | |||
* 商品列表 | |||
*/ | |||
RecyclerView good_recyclerView; | |||
/** | |||
* 界面实例 | |||
*/ | |||
@@ -61,7 +70,8 @@ public class HomeFragment extends Fragment implements View.OnClickListener, MyCl | |||
* 初始化 | |||
*/ | |||
private void Init(){ | |||
datatab= view.findViewById(R.id.datatab); | |||
// datatab= view.findViewById(R.id.datatab); | |||
good_recyclerView = view.findViewById(R.id.good_recyclerView); | |||
Initdata();//初始化数据 | |||
RegisterMessage();//消息中心事件接收 | |||
} | |||
@@ -77,9 +87,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener, MyCl | |||
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); | |||
MyLayoutManager layout = new MyLayoutManager(); | |||
layout.setAutoMeasureEnabled(true); | |||
good_recyclerView.setLayoutManager(layout); | |||
maingoods_adapter goodadapter = new maingoods_adapter( getContext()); | |||
good_recyclerView.setAdapter(goodadapter); | |||
DataBus.getInstance().UpdateMainGoods();//更新商品 | |||
// 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){ | |||
} | |||
@@ -0,0 +1,9 @@ | |||
package com.example.bpa.view.mode; | |||
public class mainGoods { | |||
public String id; | |||
public String name; | |||
public String message; | |||
} |
@@ -0,0 +1,7 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:shape="rectangle" | |||
> | |||
<solid android:color="#9F14EA09"/> | |||
<corners android:radius="25dp"/> | |||
</shape> |
@@ -0,0 +1,7 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<ripple xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:color="#E5514E" | |||
> | |||
<item android:drawable="@drawable/btn_ripple_good"/> | |||
</ripple> |
@@ -1,6 +1,5 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" | |||
xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
@@ -10,32 +9,53 @@ | |||
android:layout_marginTop="20dp" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_marginBottom="20dp"> | |||
<RelativeLayout | |||
android:layout_width="260dp" | |||
android:layout_height="400dp"> | |||
<ImageView | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_centerVertical="true" | |||
android:layout_centerInParent="true" | |||
android:scaleType="fitXY" | |||
android:src="@mipmap/rqbk"> | |||
</ImageView> | |||
</RelativeLayout> | |||
android:layout_marginBottom="20dp" | |||
android:orientation="vertical"> | |||
<RelativeLayout | |||
android:layout_width="260dp" | |||
android:layout_marginLeft="20dp" | |||
android:layout_height="400dp"> | |||
<ImageView | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_margin="10dp"> | |||
<androidx.recyclerview.widget.RecyclerView | |||
android:id="@+id/good_recyclerView" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_centerInParent="true" | |||
android:scaleType="fitXY" | |||
android:src="@mipmap/rqbk"> | |||
</ImageView> | |||
android:layout_height="wrap_content" | |||
android:scrollbarStyle="outsideOverlay" | |||
> | |||
</androidx.recyclerview.widget.RecyclerView> | |||
</RelativeLayout> | |||
<!-- <RelativeLayout--> | |||
<!-- android:layout_width="wrap_content"--> | |||
<!-- android:layout_height="0dp"--> | |||
<!-- android:layout_weight="1"--> | |||
<!-- android:layout_margin="10dp">--> | |||
<!-- </RelativeLayout>--> | |||
<!-- <RelativeLayout--> | |||
<!-- android:layout_width="260dp"--> | |||
<!-- android:layout_height="400dp">--> | |||
<!-- <ImageView--> | |||
<!-- android:layout_width="match_parent"--> | |||
<!-- android:layout_height="match_parent"--> | |||
<!-- android:layout_centerInParent="true"--> | |||
<!-- android:scaleType="fitXY"--> | |||
<!-- android:src="@mipmap/rqbk"></ImageView>--> | |||
<!-- </RelativeLayout>--> | |||
<!-- <RelativeLayout--> | |||
<!-- android:layout_width="260dp"--> | |||
<!-- android:layout_marginLeft="20dp"--> | |||
<!-- android:layout_height="400dp">--> | |||
<!-- <ImageView--> | |||
<!-- android:layout_width="match_parent"--> | |||
<!-- android:layout_height="match_parent"--> | |||
<!-- android:layout_centerInParent="true"--> | |||
<!-- android:scaleType="fitXY"--> | |||
<!-- android:src="@mipmap/rqbk">--> | |||
<!-- </ImageView>--> | |||
<!-- </RelativeLayout>--> | |||
</LinearLayout> | |||
</RelativeLayout> |
@@ -0,0 +1,68 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="180dp" | |||
android:layout_height="130dp" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="@mipmap/bg_f3" | |||
android:layout_margin="10dp" | |||
> | |||
<RelativeLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_marginLeft="12dp" | |||
android:layout_marginRight="12dp" | |||
android:layout_marginTop="8dp" | |||
android:layout_marginBottom="8dp"> | |||
<ImageView | |||
android:id="@+id/good_pic" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_gravity="center_vertical" | |||
android:adjustViewBounds="true" | |||
android:alpha="0.8" | |||
android:scaleType="centerCrop" | |||
android:src="@mipmap/milktea_1" /> | |||
<RelativeLayout | |||
android:layout_margin="0dp" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="@mipmap/bg_text1"> | |||
<TextView | |||
android:id="@+id/goodname" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginLeft="15dp" | |||
android:layout_marginTop="22dp" | |||
android:text="原味奶茶" | |||
android:textColor="@color/white" | |||
android:textSize="14dp" | |||
android:textStyle="bold" | |||
android:typeface="serif" /> | |||
<Button | |||
android:id="@+id/goodmake" | |||
android:layout_width="100dp" | |||
android:layout_height="20dp" | |||
android:layout_gravity="center_vertical" | |||
android:layout_alignParentBottom="true" | |||
android:layout_alignParentRight="true" | |||
android:layout_marginRight="18dp" | |||
android:layout_marginBottom="23dp" | |||
android:textColor="@color/white" | |||
android:background="@drawable/ripple_goods" | |||
android:text="make" /> | |||
</RelativeLayout> | |||
</RelativeLayout> | |||
</LinearLayout> | |||
</LinearLayout> |