代码拉取完成,页面将自动刷新
/*
* Copyright (c) 2020. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
* Vestibulum commodo. Ut rhoncus gravida arcu.
*/
package com.shide.businessuser.UI;
import android.app.Activity;
import android.content.Context;
import android.nfc.Tag;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.shide.businessuser.R;
import com.shide.businessuser.Utils.FuctionUtils;
import com.shide.businessuser.Utils.LogUtil;
import com.shide.businessuser.Utils.MessageEvent;
import com.shide.businessuser.http.GlobleURL;
import com.shide.businessuser.http.GsonUtils;
import com.shide.businessuser.http.OkhttpUtils;
import com.shide.businessuser.http.ParJson;
import com.shide.businessuser.http.entity.ErrorInfo;
import com.shide.businessuser.http.entity.Product;
import com.shide.businessuser.http.entity.exchargeInfo;
import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.Response;
public class PopWin_downShelf_goods extends PopupWindow {
private Button btnSure;
private Button btnCancel;
private Context mContext;
private Button btn_back_scan;
private Product product;
private Button btnDeleteGoods;
private Button btnDownShelf;
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public PopWin_downShelf_goods(Context context) {
super(context);
mContext = context;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.popwin_down_shelf_product, null);
// 设置SelectPicPopupWindow的View
this.setContentView(view);
PopWinUtils.setBasicStyle(context,this);
initView(view);
}
private void initView(View view) {
btnDeleteGoods = (Button) view.findViewById(R.id.btn_deleteGoods);
btnDownShelf = (Button) view.findViewById(R.id.btn_down_shelf);
ImageView img_cancel= view.findViewById(R.id.imageView_cancel);
img_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
btnDeleteGoods.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteGoods();
}
});
btnDownShelf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
downGoods();
}
});
}
/**
* 显示popupWindow
* @param parent
*/
public void showPopupWindow(View parent) {
if (!this.isShowing()) {
this.showAtLocation(parent, Gravity.CENTER, 0, 0);
} else {
this.dismiss();
}
}
private void downGoods() {
if (product != null) {
FormBody.Builder builder = new FormBody.Builder();
builder.add("id", product.getId());
builder.add("shelf", "2");
OkhttpUtils.post_token_Json(GlobleURL.UpOrDownShelf, builder, new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("PopWin_downShelf_goods",e.getMessage());
Toast.makeText(mContext, "请检查网络", Toast.LENGTH_SHORT).show();
dismiss();
}
});
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
String json = response.body().string();
Boolean error = ParJson.isError(json);
if (response.code() == 401){
FuctionUtils.BackLogin(response,mContext);
return;
}
if (error) {
ErrorInfo errorData = ParJson.getErrorData(json);
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("pop_downshelf",errorData.getMessage());
// Toast.makeText(mContext, errorData.getMessage(), Toast.LENGTH_SHORT).show();
// FuctionUtils.BackLogin(response,mContext);
dismiss();
}
});
}else{
exchargeInfo ei = GsonUtils.JsonToObject(json, exchargeInfo.class);
if (ei != null) {
if (ei.getCode().equals("200")){
MessageEvent messageEvent = new MessageEvent();
messageEvent.setCode(MessageEvent.UP_DOWN_GOODS);
EventBus.getDefault().post(messageEvent);
handler.sendEmptyMessage(0);
}
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, ei.getMsg(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
});
}
}
private void deleteGoods(){
if (product != null) {
HttpUrl.Builder urlBuilder = HttpUrl.parse(GlobleURL.DeletGoods).newBuilder();
urlBuilder.addQueryParameter("id",product.getId());
OkhttpUtils.delete(urlBuilder, new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("PopWin_downShelf_goods.this",e.getMessage());
Toast.makeText(mContext, "请检查网络", Toast.LENGTH_SHORT).show();
dismiss();
}
});
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
String json = response.body().string();
Boolean error = ParJson.isError(json);
if (response.code() == 401){
FuctionUtils.BackLogin(response,mContext);
return;
}
if (error) {
ErrorInfo errorData = ParJson.getErrorData(json);
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("pop_downshelf",errorData.getMessage());
//Toast.makeText(mContext, errorData.getMessage(), Toast.LENGTH_SHORT).show();
//FuctionUtils.BackLogin(response,mContext);
dismiss();
}
});
}else{
exchargeInfo ei = GsonUtils.JsonToObject(json, exchargeInfo.class);
if (ei != null) {
if (ei.getCode().equals("200")){
MessageEvent messageEvent = new MessageEvent();
messageEvent.setCode(MessageEvent.UP_DOWN_GOODS);
EventBus.getDefault().post(messageEvent);
handler.sendEmptyMessage(0);
}
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, ei.getMsg(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
});
}
}
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what == 0){
dismiss();
}
}
};
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。