Android代码12月23日更新
This commit is contained in:
parent
a214be6406
commit
ed78b6e686
|
@ -5,7 +5,6 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:usesCleartextTraffic="true"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
@ -14,7 +13,14 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.CourseDesign"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".UpdateCommodityMainActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".AddCommentActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MyOrderActivity"
|
||||
android:exported="false" />
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package com.example.coursedesign;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class AddCommentActivity extends AppCompatActivity {
|
||||
|
||||
TextView back;
|
||||
EditText contentET;
|
||||
Button submit;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_add_comment);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
back = findViewById(R.id.textView39);
|
||||
contentET = findViewById(R.id.editTextText5);
|
||||
submit = findViewById(R.id.button7);
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("comment", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
int userId = sharedPreferences.getInt("userId", 0);
|
||||
int commodityId = sharedPreferences.getInt("commodityId", 0);
|
||||
|
||||
//获取数据
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("http://10.138.63.204:8080/")
|
||||
.addConverterFactory(GsonConverterFactory.create()) //返回结果用Gson解析
|
||||
.build();
|
||||
Api api = retrofit.create(Api.class);
|
||||
|
||||
submit.setOnClickListener(v -> {
|
||||
String content = contentET.getText().toString();
|
||||
CommentListResult.RowsDTO rowsDTO = new CommentListResult.RowsDTO();
|
||||
rowsDTO.personid = userId;
|
||||
rowsDTO.commodityid = commodityId;
|
||||
rowsDTO.content = content;
|
||||
Call<Result> addCommentCall = api.addComment("Bearer ", rowsDTO);
|
||||
addCommentCall.enqueue(new retrofit2.Callback<Result>() {
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code == 200){
|
||||
Toast.makeText(AddCommentActivity.this, "评论成功", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
|
@ -36,10 +36,26 @@ public interface Api {
|
|||
@GET("/system/comment/list2")
|
||||
Call<CommentListResult> getCommentListByCommodityId(@Header("Authorization") String token, @Query("commodityid") Integer commodityId);
|
||||
|
||||
//http://127.0.0.1:8080/system/comment
|
||||
@POST("/system/comment")
|
||||
Call<Result> addComment(@Header("Authorization") String token, @Body CommentListResult.RowsDTO rowsDTO);
|
||||
|
||||
//http://127.0.0.1:8080/system/favorite/list2
|
||||
@GET("/system/favorite/list2")
|
||||
Call<FavoriteListResult> getFavoriteListByPersonId(@Header("Authorization") String token, @Query("personid") Integer personId);
|
||||
|
||||
//http://127.0.0.1:8080/system/favorite/list3
|
||||
@GET("/system/favorite/list3")
|
||||
Call<FavoriteListResult> getFavoriteListByPersonIdAndCommodityId(@Header("Authorization") String token, @Query("personid") Integer personId, @Query("commodityid") Integer commodityId);
|
||||
|
||||
//http://127.0.0.1:8080/system/favorite
|
||||
@POST("/system/favorite")
|
||||
Call<Result> addFavorite(@Header("Authorization") String token, @Body FavoriteListResult.RowsDTO rowsDTO);
|
||||
|
||||
//http://127.0.0.1:8080/system/favorite/{ids}
|
||||
@DELETE("system/favorite/{ids}")
|
||||
Call<Result> removeFavorite(@Header("Authorization") String token, @Path("ids") String ids);
|
||||
|
||||
//http://127.0.0.1:8080/system/order/list2
|
||||
@GET("/system/order/list2")
|
||||
Call<OrderListResult> getOrderListByBuyerId(@Header("Authorization") String token, @Query("buyerid") Integer buyerId);
|
||||
|
@ -59,4 +75,16 @@ public interface Api {
|
|||
//http://127.0.0.1:8080/system/commodity/{ids}
|
||||
@DELETE("system/commodity/{ids}")
|
||||
Call<Result> removeCommodity(@Header("Authorization") String token, @Path("ids") String ids);
|
||||
|
||||
//http://127.0.0.1:8080/system/order
|
||||
@POST("/system/order")
|
||||
Call<Result> addOrder(@Header("Authorization") String token, @Body OrderListResult.RowsDTO rowsDTO);
|
||||
|
||||
//http://127.0.0.1:8080/system/favorite/delete
|
||||
@POST("/system/favorite/delete")
|
||||
Call<Result> removeFavoriteByPersonIdAndCommodityId(@Header("Authorization") String token, @Body FavoriteListResult.RowsDTO rowsDTO);
|
||||
|
||||
//http://127.0.0.1:8080/system/favorite/insert
|
||||
@POST("/system/favorite/insert")
|
||||
Call<Result> addFavoriteByPersonIdAndCommodityId(@Header("Authorization") String token, @Body FavoriteListResult.RowsDTO rowsDTO);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,10 @@ import android.util.Log;
|
|||
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 android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -30,6 +32,10 @@ import com.scwang.smart.refresh.layout.SmartRefreshLayout;
|
|||
import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
||||
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
@ -51,8 +57,14 @@ public class CommodityActivity extends AppCompatActivity {
|
|||
TextView descriptionTV;
|
||||
TextView sellerNameTV;
|
||||
ImageView sellerImage;
|
||||
Button addOrder;
|
||||
Button addComment;
|
||||
ImageView favorite;
|
||||
|
||||
CommentListResult result;
|
||||
CommodityListResult.RowsDTO rowsDTO;
|
||||
FavoriteListResult.RowsDTO rowsDTO2;
|
||||
Boolean isFavorite = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -79,10 +91,17 @@ public class CommodityActivity extends AppCompatActivity {
|
|||
classificationTV = findViewById(R.id.textView34);
|
||||
sellerImage = findViewById(R.id.imageView10);
|
||||
commodityImage = findViewById(R.id.imageView9);
|
||||
addOrder = findViewById(R.id.button5);
|
||||
addComment = findViewById(R.id.button4);
|
||||
favorite = findViewById(R.id.imageView11);
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("commodity", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
int id = sharedPreferences.getInt("id", 0);
|
||||
int commodityId = sharedPreferences.getInt("id", 0);
|
||||
|
||||
SharedPreferences sharedPreferences2 = getSharedPreferences("user", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor2 = sharedPreferences.edit();
|
||||
int userId = sharedPreferences2.getInt("id", 0);
|
||||
|
||||
//获取数据
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
|
@ -91,14 +110,15 @@ public class CommodityActivity extends AppCompatActivity {
|
|||
.build();
|
||||
Api api = retrofit.create(Api.class);
|
||||
|
||||
Call<CommodityListResult> commodityListCall = api.getCommodityListById("Bearer ", id, null);
|
||||
//获取商品信息
|
||||
Call<CommodityListResult> commodityListCall = api.getCommodityListById("Bearer ", commodityId, null);
|
||||
commodityListCall.enqueue(new retrofit2.Callback<CommodityListResult>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<CommodityListResult> call, retrofit2.Response<CommodityListResult> response) {
|
||||
CommodityListResult result = response.body();
|
||||
if(result.code == 200){
|
||||
CommodityListResult.RowsDTO rowsDTO = result.rows.get(0);
|
||||
rowsDTO = result.rows.get(0);
|
||||
commodityNameTV.setText(rowsDTO.name);
|
||||
priceTV.setText("¥" + rowsDTO.price);
|
||||
descriptionTV.setText(rowsDTO.description);
|
||||
|
@ -116,13 +136,13 @@ public class CommodityActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
Call<CommentListResult> commentListCall = api.getCommentListByCommodityId("Bearer ", id);
|
||||
//获取评论信息
|
||||
Call<CommentListResult> commentListCall = api.getCommentListByCommodityId("Bearer ", commodityId);
|
||||
commentListCall.enqueue(new retrofit2.Callback<CommentListResult>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<CommentListResult> call, retrofit2.Response<CommentListResult> response) {
|
||||
result = response.body();
|
||||
Log.e("result", result.toString());
|
||||
if(result.code == 200){
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
@ -130,7 +150,32 @@ public class CommodityActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onFailure(Call<CommentListResult> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
//获取收藏信息
|
||||
Call<FavoriteListResult> favoriteListCall = api.getFavoriteListByPersonIdAndCommodityId("Bearer ", userId, commodityId);
|
||||
favoriteListCall.enqueue(new retrofit2.Callback<FavoriteListResult>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<FavoriteListResult> call, retrofit2.Response<FavoriteListResult> response) {
|
||||
FavoriteListResult result = response.body();
|
||||
if(result.code == 200){
|
||||
if(result.rows.size() == 0){
|
||||
isFavorite = false;
|
||||
favorite.setSelected(false);
|
||||
}else{
|
||||
isFavorite = true;
|
||||
rowsDTO2 = result.rows.get(0);
|
||||
favorite.setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<FavoriteListResult> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -142,7 +187,7 @@ public class CommodityActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||||
|
||||
Call<CommentListResult> commentListCall = api.getCommentListByCommodityId("Bearer ", id);
|
||||
Call<CommentListResult> commentListCall = api.getCommentListByCommodityId("Bearer ", commodityId);
|
||||
commentListCall.enqueue(new retrofit2.Callback<CommentListResult>() {
|
||||
|
||||
@Override
|
||||
|
@ -163,6 +208,147 @@ public class CommodityActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
addOrder.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
OrderListResult.RowsDTO rowsDTO2 = new OrderListResult.RowsDTO();
|
||||
rowsDTO2.buyerid = userId;
|
||||
rowsDTO2.commodityid = commodityId;
|
||||
rowsDTO2.status = "未发货";
|
||||
// 获取当前时间的毫秒数
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
// 将毫秒数转换为Date对象
|
||||
Date date = new Date(currentTimeMillis);
|
||||
// 定义日期格式
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
// 格式化Date对象为字符串
|
||||
rowsDTO2.time = sdf.format(date);
|
||||
|
||||
Call<Result> addOrderCall = api.addOrder("Bearer ", rowsDTO2);
|
||||
addOrderCall.enqueue(new retrofit2.Callback<Result>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code == 200){
|
||||
Toast.makeText(CommodityActivity.this, "下单成功", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
rowsDTO.state = "售出";
|
||||
Call<Result> updateCommodityCall = api.updateCommodity("Bearer ", rowsDTO);
|
||||
updateCommodityCall.enqueue(new retrofit2.Callback<Result>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code == 200){
|
||||
Toast.makeText(CommodityActivity.this, "修改商品状态成功", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
addComment.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("comment", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putInt("userId", userId);
|
||||
editor.putInt("commodityId", commodityId);
|
||||
editor.commit();
|
||||
startActivity(new Intent(CommodityActivity.this, AddCommentActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
favorite.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(isFavorite){
|
||||
Call<Result> removeFavoriteCall = api.removeFavoriteByPersonIdAndCommodityId("Bearer ", rowsDTO2);
|
||||
removeFavoriteCall.enqueue(new retrofit2.Callback<Result>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code == 200){
|
||||
Toast.makeText(CommodityActivity.this, "取消收藏成功", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
isFavorite = false;
|
||||
favorite.setSelected(false);
|
||||
}else {
|
||||
|
||||
//添加收藏
|
||||
FavoriteListResult.RowsDTO rowsDTO = new FavoriteListResult.RowsDTO();
|
||||
rowsDTO.personid = userId;
|
||||
rowsDTO.commodityid = commodityId;
|
||||
Call<Result> addFavoriteCall = api.addFavoriteByPersonIdAndCommodityId("Bearer ", rowsDTO);
|
||||
addFavoriteCall.enqueue(new retrofit2.Callback<Result>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code == 200){
|
||||
Toast.makeText(CommodityActivity.this, "添加收藏成功", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
//获取收藏信息
|
||||
Call<FavoriteListResult> favoriteListCall = api.getFavoriteListByPersonIdAndCommodityId("Bearer ", userId, commodityId);
|
||||
favoriteListCall.enqueue(new retrofit2.Callback<FavoriteListResult>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<FavoriteListResult> call, retrofit2.Response<FavoriteListResult> response) {
|
||||
FavoriteListResult result = response.body();
|
||||
if(result.code == 200){
|
||||
if(result.rows.size() != 0){
|
||||
rowsDTO2 = result.rows.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<FavoriteListResult> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
isFavorite = true;
|
||||
favorite.setSelected(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.example.coursedesign;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
||||
|
@ -190,7 +191,6 @@ public class OnSaleFragment extends Fragment {
|
|||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
|
||||
Result result = response.body();
|
||||
Log.e("error", result.msg);
|
||||
if(result != null && result.code == 200){
|
||||
Toast.makeText(getActivity(), "删除成功", Toast.LENGTH_SHORT).show();
|
||||
notifyDataSetChanged();
|
||||
|
@ -212,7 +212,12 @@ public class OnSaleFragment extends Fragment {
|
|||
int adapterPosition = holder.getAdapterPosition();
|
||||
if(adapterPosition != RecyclerView.NO_POSITION){
|
||||
CommodityListResult.RowsDTO rowsDTO = result.rows.get(adapterPosition);
|
||||
|
||||
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("commodity", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.clear();
|
||||
editor.putInt("id", rowsDTO.id);
|
||||
editor.commit();
|
||||
startActivity(new Intent(getActivity(), UpdateCommodityMainActivity.class));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
package com.example.coursedesign;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class UpdateCommodityMainActivity extends AppCompatActivity {
|
||||
|
||||
TextView back;
|
||||
EditText nameET, priceET, descriptionET;
|
||||
Spinner spinner;
|
||||
Button addCommodityBtn;
|
||||
|
||||
CommodityListResult.RowsDTO commodity = new CommodityListResult.RowsDTO();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_update_commodity_main);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
back = findViewById(R.id.textView53);
|
||||
nameET = findViewById(R.id.editTextText10);
|
||||
priceET = findViewById(R.id.editTextNumber3);
|
||||
descriptionET = findViewById(R.id.editTextText11);
|
||||
spinner = findViewById(R.id.spinner5);
|
||||
addCommodityBtn = findViewById(R.id.button13);
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("commodity", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
commodity.id = sharedPreferences.getInt("id", 0);
|
||||
|
||||
//设置item的被选择的监听
|
||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
//当item被选择后调用此方法
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
//获取我们所选中的内容
|
||||
commodity.classification = parent.getItemAtPosition(position).toString();
|
||||
}
|
||||
//只有当patent中的资源没有时,调用此方法
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//获取数据
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("http://10.138.63.204:8080/")
|
||||
.addConverterFactory(GsonConverterFactory.create()) //返回结果用Gson解析
|
||||
.build();
|
||||
Api api = retrofit.create(Api.class);
|
||||
|
||||
Call<CommodityListResult> commodityListCall = api.getCommodityListById("Bearer ", commodity.id, null);
|
||||
commodityListCall.enqueue(new Callback<CommodityListResult>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<CommodityListResult> call, retrofit2.Response<CommodityListResult> response) {
|
||||
CommodityListResult result = response.body();
|
||||
if(result.code == 200){
|
||||
commodity = result.rows.get(0);
|
||||
nameET.setText(commodity.name);
|
||||
priceET.setText(commodity.price.toString());
|
||||
descriptionET.setText(commodity.description);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CommodityListResult> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
addCommodityBtn.setOnClickListener(v -> {
|
||||
commodity.name = nameET.getText().toString();
|
||||
commodity.price = Double.parseDouble(priceET.getText().toString());
|
||||
commodity.description = descriptionET.getText().toString();
|
||||
commodity.classification = spinner.getSelectedItem().toString();
|
||||
|
||||
Call<Result> updateCommodityCall = api.updateCommodity("Bearer ", commodity);
|
||||
updateCommodityCall.enqueue(new Callback<Result>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code == 200){
|
||||
Toast.makeText(UpdateCommodityMainActivity.this, "修改商品信息成功", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
Log.e("error", t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/background"
|
||||
tools:context=".AddCommentActivity">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="409dp"
|
||||
android:layout_height="729dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/shape"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView38">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextText5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:ems="10"
|
||||
android:inputType="text"
|
||||
android:hint="输入评论"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button7"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="添加评论"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextText5" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView38"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="48dp"
|
||||
android:text="添加评论"
|
||||
android:textColor="@color/teal_200"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView39"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="Back"
|
||||
android:textColor="@color/teal_200"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/textView38"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/textView38" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -160,7 +160,7 @@
|
|||
android:id="@+id/button4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:backgroundTint="#4CAF50"
|
||||
android:text="发布评论"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/background"
|
||||
tools:context=".UpdateCommodityMainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button13"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:backgroundTint="#5FEDFF"
|
||||
android:text="修改商品"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/constraintLayout" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="300dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/shape"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView52">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="@drawable/shape"
|
||||
android:entries="@array/spinner2"
|
||||
app:layout_constraintBottom_toTopOf="@+id/editTextNumber3"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextNumber3" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView56"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="价格"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/editTextNumber3"
|
||||
app:layout_constraintEnd_toStartOf="@+id/editTextNumber3"
|
||||
app:layout_constraintTop_toTopOf="@+id/editTextNumber3" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextNumber3"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:ems="10"
|
||||
android:inputType="number"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView23"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:srcCompat="@android:drawable/ic_menu_gallery" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextText11"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="70dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:ems="15"
|
||||
android:hint="描述一下商品信息"
|
||||
android:inputType="textMultiLine"
|
||||
android:maxLines="4"
|
||||
android:scrollbars="vertical"
|
||||
android:singleLine="false"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextText10"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:ems="10"
|
||||
android:hint="商品名称"
|
||||
android:inputType="text"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/textView54"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/textView54"
|
||||
app:layout_constraintTop_toTopOf="@+id/textView54" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView54"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="商品名称"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView57"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="分类"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/spinner5"
|
||||
app:layout_constraintStart_toStartOf="@+id/textView56"
|
||||
app:layout_constraintTop_toTopOf="@+id/spinner5" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView53"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:text="Back"
|
||||
android:textColor="@color/teal_200"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/textView52"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/textView52" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView52"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="48dp"
|
||||
android:text="修改商品"
|
||||
android:textColor="@color/teal_200"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue