Android代码12月23日提交
This commit is contained in:
parent
512fd5f50a
commit
a214be6406
|
@ -6,10 +6,12 @@ import java.util.Map;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.http.Body;
|
import retrofit2.http.Body;
|
||||||
|
import retrofit2.http.DELETE;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Header;
|
import retrofit2.http.Header;
|
||||||
import retrofit2.http.POST;
|
import retrofit2.http.POST;
|
||||||
import retrofit2.http.PUT;
|
import retrofit2.http.PUT;
|
||||||
|
import retrofit2.http.Path;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
public interface Api {
|
public interface Api {
|
||||||
|
@ -53,4 +55,8 @@ public interface Api {
|
||||||
//http://127.0.0.1:8080/system/commodity
|
//http://127.0.0.1:8080/system/commodity
|
||||||
@POST("/system/commodity")
|
@POST("/system/commodity")
|
||||||
Call<Result> addCommodity(@Header("Authorization") String token, @Body CommodityListResult.RowsDTO rowsDTO);
|
Call<Result> addCommodity(@Header("Authorization") String token, @Body CommodityListResult.RowsDTO rowsDTO);
|
||||||
|
|
||||||
|
//http://127.0.0.1:8080/system/commodity/{ids}
|
||||||
|
@DELETE("system/commodity/{ids}")
|
||||||
|
Call<Result> removeCommodity(@Header("Authorization") String token, @Path("ids") String ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,6 @@ import androidx.core.graphics.Insets;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.core.view.WindowInsetsCompat;
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
|
@ -14,6 +14,8 @@ import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
public class MineFragment extends Fragment {
|
public class MineFragment extends Fragment {
|
||||||
|
|
||||||
Button logOut;
|
Button logOut;
|
||||||
|
@ -38,6 +40,12 @@ public class MineFragment extends Fragment {
|
||||||
phone = view.findViewById(R.id.textView42);
|
phone = view.findViewById(R.id.textView42);
|
||||||
address = view.findViewById(R.id.textView43);
|
address = view.findViewById(R.id.textView43);
|
||||||
|
|
||||||
|
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("user", Activity.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
name.setText(sharedPreferences.getString("name", ""));
|
||||||
|
phone.setText(sharedPreferences.getString("phone", ""));
|
||||||
|
Glide.with(getContext()).load(sharedPreferences.getString("picture", "")).into(picture);
|
||||||
|
|
||||||
myOrder.setOnClickListener(new View.OnClickListener() {
|
myOrder.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
|
@ -165,6 +165,44 @@ public class NotOnSaleFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
holder.deleteButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int adapterPosition = holder.getAdapterPosition();
|
||||||
|
if(adapterPosition != RecyclerView.NO_POSITION){
|
||||||
|
CommodityListResult.RowsDTO rowsDTO = result.rows.get(adapterPosition);
|
||||||
|
//获取数据
|
||||||
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
|
.baseUrl("http://10.138.63.204:8080/")
|
||||||
|
.addConverterFactory(GsonConverterFactory.create()) //返回结果用Gson解析
|
||||||
|
.build();
|
||||||
|
Api api = retrofit.create(Api.class);
|
||||||
|
|
||||||
|
String ids = String.valueOf(rowsDTO.id);
|
||||||
|
|
||||||
|
Call<Result> deleteCommodityCall = api.removeCommodity("Bearer ", ids);
|
||||||
|
deleteCommodityCall.enqueue(new retrofit2.Callback<Result>() {
|
||||||
|
@Override
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<Result> call, Throwable t) {
|
||||||
|
Log.e("error", t.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -167,6 +167,55 @@ public class OnSaleFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
holder.deleteButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int adapterPosition = holder.getAdapterPosition();
|
||||||
|
if(adapterPosition != RecyclerView.NO_POSITION){
|
||||||
|
CommodityListResult.RowsDTO rowsDTO = result.rows.get(adapterPosition);
|
||||||
|
//获取数据
|
||||||
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
|
.baseUrl("http://10.138.63.204:8080/")
|
||||||
|
.addConverterFactory(GsonConverterFactory.create()) //返回结果用Gson解析
|
||||||
|
.build();
|
||||||
|
Api api = retrofit.create(Api.class);
|
||||||
|
|
||||||
|
String ids = String.valueOf(rowsDTO.id);
|
||||||
|
|
||||||
|
Call<Result> deleteCommodityCall = api.removeCommodity("Bearer ", ids);
|
||||||
|
deleteCommodityCall.enqueue(new retrofit2.Callback<Result>() {
|
||||||
|
@Override
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<Result> call, Throwable t) {
|
||||||
|
Log.e("error", t.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
holder.constraintLayout.setOnClickListener(new View.OnClickListener(){
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int adapterPosition = holder.getAdapterPosition();
|
||||||
|
if(adapterPosition != RecyclerView.NO_POSITION){
|
||||||
|
CommodityListResult.RowsDTO rowsDTO = result.rows.get(adapterPosition);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue