267 lines
12 KiB
Java
267 lines
12 KiB
Java
package com.uiuios.aios.activity;
|
|
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewTreeObserver;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
import com.bumptech.glide.Glide;
|
|
import com.tencent.mmkv.MMKV;
|
|
import com.uiuios.aios.R;
|
|
import com.uiuios.aios.base.BaseDataBindingActivity;
|
|
import com.uiuios.aios.bean.BaseResponse;
|
|
import com.uiuios.aios.bean.GoodsInfo;
|
|
import com.uiuios.aios.bean.RegionInfo;
|
|
import com.uiuios.aios.config.CommonConfig;
|
|
import com.uiuios.aios.databinding.ActivityDetailsBinding;
|
|
import com.uiuios.aios.network.NetInterfaceManager;
|
|
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
|
|
|
import org.reactivestreams.Publisher;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.ButterKnife;
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.rxjava3.annotations.NonNull;
|
|
import io.reactivex.rxjava3.core.Observable;
|
|
import io.reactivex.rxjava3.core.ObservableEmitter;
|
|
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
|
|
import io.reactivex.rxjava3.core.ObservableSource;
|
|
import io.reactivex.rxjava3.core.Observer;
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
|
import io.reactivex.rxjava3.functions.Function;
|
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
|
import retrofit2.Call;
|
|
import retrofit2.Callback;
|
|
import retrofit2.Response;
|
|
import retrofit2.Retrofit;
|
|
|
|
public class DetailsActivity extends BaseDataBindingActivity {
|
|
@BindView(R.id.iv_details)
|
|
ImageView iv_details;
|
|
@BindView(R.id.iv_exit)
|
|
ImageView iv_exit;
|
|
@BindView(R.id.tv_buying_price)
|
|
TextView tv_buying_price;
|
|
@BindView(R.id.tv_original_price)
|
|
TextView tv_original_price;
|
|
@BindView(R.id.tv_stock)
|
|
TextView tv_stock;
|
|
@BindView(R.id.tv_subsidy)
|
|
TextView tv_subsidy;
|
|
@BindView(R.id.tv_price)
|
|
TextView tv_price;
|
|
@BindView(R.id.tv_title)
|
|
TextView tv_title;
|
|
@BindView(R.id.tv_details)
|
|
TextView tv_details;
|
|
@BindView(R.id.tv_certified)
|
|
TextView tv_certified;
|
|
@BindView(R.id.tv_ship)
|
|
TextView tv_ship;
|
|
@BindView(R.id.tv_insurance)
|
|
TextView tv_insurance;
|
|
@BindView(R.id.tv_sale)
|
|
TextView tv_sale;
|
|
@BindView(R.id.tv_type)
|
|
TextView tv_type;
|
|
@BindView(R.id.ll_buy)
|
|
LinearLayout ll_buy;
|
|
|
|
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
|
|
|
private ActivityDetailsBinding mBinding;
|
|
private GoodsInfo mGoodsInfo;
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.activity_details;
|
|
}
|
|
|
|
@Override
|
|
protected boolean setNightMode() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
protected boolean setfitWindow() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 初始化视图
|
|
*/
|
|
@Override
|
|
public void initView() {
|
|
mBinding = DataBindingUtil.setContentView(this, getLayoutId());
|
|
ButterKnife.bind(this);
|
|
Intent intent = getIntent();
|
|
if (intent == null) return;
|
|
GoodsInfo goodsInfo = (GoodsInfo) intent.getSerializableExtra("GoodsInfo");
|
|
if (goodsInfo == null) return;
|
|
mGoodsInfo = goodsInfo;
|
|
Glide.with(iv_details).load(mGoodsInfo.getDetails_img()).into(iv_details);
|
|
ViewTreeObserver observer = iv_details.getViewTreeObserver();
|
|
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
@Override
|
|
public void onGlobalLayout() {
|
|
ViewGroup.LayoutParams layoutParams = iv_details.getLayoutParams();
|
|
int width = iv_details.getWidth();
|
|
layoutParams.height = width;
|
|
iv_details.setLayoutParams(layoutParams);
|
|
}
|
|
});
|
|
iv_exit.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
finish();
|
|
}
|
|
});
|
|
tv_stock.setText("库存:" + mGoodsInfo.getStock());
|
|
BigDecimal d = new BigDecimal(mGoodsInfo.getOriginal_price());
|
|
BigDecimal d2 = new BigDecimal(mGoodsInfo.getBuying_price());
|
|
tv_subsidy.setText("官方补贴" + d.subtract(d2).toString());
|
|
tv_buying_price.setText("¥" + mGoodsInfo.getBuying_price());
|
|
tv_original_price.setText("原价:" + mGoodsInfo.getOriginal_price() + "元");
|
|
tv_price.setText("抢购:" + mGoodsInfo.getBuying_price() + "元");
|
|
tv_title.setText(mGoodsInfo.getGoods_name());
|
|
tv_details.setText(mGoodsInfo.getGoods_desc());
|
|
tv_certified.setText(mGoodsInfo.getEnsure());
|
|
tv_ship.setText(mGoodsInfo.getDeliver_goods());
|
|
tv_insurance.setText(mGoodsInfo.getInsure());
|
|
tv_sale.setText(mGoodsInfo.getAfter_sales());
|
|
ll_buy.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
// Uri uri = Uri.parse(goodsInfo.getJump_url());
|
|
// Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
|
// startActivity(intent);
|
|
|
|
Intent intent = new Intent(DetailsActivity.this, OrderActivity.class);
|
|
intent.putExtra("GoodsInfo", mGoodsInfo);
|
|
startActivity(intent);
|
|
|
|
// NetInterfaceManager.getInstance().getRegionListApi().getRegionList("0")
|
|
// .flatMap(new Function<BaseResponse<List<RegionInfo>>, ObservableSource<?>>() {
|
|
// @Override
|
|
// public ObservableSource<?> apply(BaseResponse<List<RegionInfo>> listBaseResponse) throws Throwable {
|
|
// if (listBaseResponse.code == 200) {
|
|
// List<RegionInfo> regionInfos = listBaseResponse.data;
|
|
// String province = mMMKV.decodeString(CommonConfig.MAP_PROVINCE_KEY, "");
|
|
// Map<String, String> provinceMap = regionInfos.stream().collect(Collectors.toMap(RegionInfo::getArea_name, RegionInfo::getId));
|
|
// if (TextUtils.isEmpty(provinceMap.get(province))) {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("110000000000");
|
|
// } else {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList(provinceMap.get(province));
|
|
// }
|
|
// } else {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("110000000000");
|
|
// }
|
|
// }
|
|
// })
|
|
// .flatMap(new Function<Object, ObservableSource<?>>() {
|
|
// @Override
|
|
// public ObservableSource<?> apply(Object o) throws Throwable {
|
|
// BaseResponse<List<RegionInfo>> listBaseResponse = (BaseResponse<List<RegionInfo>>) o;
|
|
// if (listBaseResponse.code == 200) {
|
|
// List<RegionInfo> regionInfos = listBaseResponse.data;
|
|
// String province = mMMKV.decodeString(CommonConfig.MAP_CITY_KEY, "");
|
|
// Map<String, String> provinceMap = regionInfos.stream().collect(Collectors.toMap(RegionInfo::getArea_name, RegionInfo::getId));
|
|
// if (TextUtils.isEmpty(provinceMap.get(province))) {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("110100000000");
|
|
// } else {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList(provinceMap.get(province));
|
|
// }
|
|
// } else {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("110100000000");
|
|
// }
|
|
// }
|
|
// })
|
|
// .flatMap(new Function<Object, ObservableSource<?>>() {
|
|
// @Override
|
|
// public ObservableSource<?> apply(Object o) throws Throwable {
|
|
// BaseResponse<List<RegionInfo>> listBaseResponse = (BaseResponse<List<RegionInfo>>) o;
|
|
// if (listBaseResponse.code == 200) {
|
|
// List<RegionInfo> regionInfos = listBaseResponse.data;
|
|
// String province = mMMKV.decodeString(CommonConfig.MAP_DISTRICT_KEY, "");
|
|
// Map<String, String> provinceMap = regionInfos.stream().collect(Collectors.toMap(RegionInfo::getArea_name, RegionInfo::getId));
|
|
// if (TextUtils.isEmpty(provinceMap.get(province))) {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("110101000000");
|
|
// } else {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList(provinceMap.get(province));
|
|
// }
|
|
// } else {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("110101000000");
|
|
// }
|
|
// }
|
|
// })
|
|
// .subscribe(new Observer<Object>() {
|
|
// @Override
|
|
// public void onSubscribe(@NonNull Disposable d) {
|
|
// Log.e("getRegionList", "onSubscribe: ");
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onNext(@NonNull Object o) {
|
|
// Log.e("getRegionList", "onNext: ");
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onError(@NonNull Throwable e) {
|
|
// Log.e("getRegionList", "onError: " + e.getMessage());
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onComplete() {
|
|
// Log.e("getRegionList", "onComplete: ");
|
|
// }
|
|
// });
|
|
}
|
|
});
|
|
tv_type.setText(mGoodsInfo.getType());
|
|
}
|
|
|
|
/**
|
|
* 初始化数据
|
|
*/
|
|
@Override
|
|
public void initData() {
|
|
|
|
// NetInterfaceManager.getInstance().getRegionListApi().getRegionList("0")
|
|
// .subscribeOn(Schedulers.io())
|
|
// .observeOn(Schedulers.io())//设定第一次请求结果放在io线程并同时执行第二次 请求
|
|
// .flatMap(new Function<BaseResponse<List<RegionInfo>>, ObservableSource<?>>() {
|
|
// @Override
|
|
// public ObservableSource<?> apply(BaseResponse<List<RegionInfo>> listBaseResponse) throws Throwable {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("0");
|
|
// }
|
|
// })
|
|
// .observeOn(Schedulers.io())//设定第三次请求结果放在io线程并同时执行次 自己的登录请求
|
|
// .flatMap(new Function<Object, ObservableSource<?>>() {
|
|
// @Override
|
|
// public ObservableSource<?> apply(Object o) throws Throwable {
|
|
// return NetInterfaceManager.getInstance().getRegionListApi().getRegionList("0");
|
|
// }
|
|
// })
|
|
// .observeOn(AndroidSchedulers.mainThread())
|
|
// .subscribe();
|
|
}
|
|
}
|