version:4.4
fix: update:增加下单,微信支付,优化资讯分类
This commit is contained in:
@@ -3,6 +3,8 @@ 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;
|
||||
@@ -12,16 +14,46 @@ 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 AppCompatActivity {
|
||||
public class DetailsActivity extends BaseDataBindingActivity {
|
||||
@BindView(R.id.iv_details)
|
||||
ImageView iv_details;
|
||||
@BindView(R.id.iv_exit)
|
||||
@@ -53,23 +85,17 @@ public class DetailsActivity extends AppCompatActivity {
|
||||
@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 void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
UltimateBarX.statusBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
.light(true)
|
||||
.apply();
|
||||
UltimateBarX.navigationBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
.light(true)
|
||||
.apply();
|
||||
setContentView(R.layout.activity_details);
|
||||
public void initView() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_details);
|
||||
ButterKnife.bind(this);
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) return;
|
||||
@@ -94,7 +120,9 @@ public class DetailsActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
tv_stock.setText("库存:" + mGoodsInfo.getStock());
|
||||
tv_subsidy.setText("官方补贴" + (mGoodsInfo.getOriginal_price() - mGoodsInfo.getBuying_price()));
|
||||
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() + "元");
|
||||
@@ -107,13 +135,117 @@ public class DetailsActivity extends AppCompatActivity {
|
||||
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);
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
196
app/src/main/java/com/uiuios/aios/activity/GoodsActivity.java
Normal file
196
app/src/main/java/com/uiuios/aios/activity/GoodsActivity.java
Normal file
@@ -0,0 +1,196 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.GoodsListAdapter;
|
||||
import com.uiuios.aios.base.BaseDataBindingActivity;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.GoodsInfo;
|
||||
import com.uiuios.aios.bean.GoodsList;
|
||||
import com.uiuios.aios.bean.GoodsType;
|
||||
import com.uiuios.aios.databinding.ActivityGoodsBinding;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class GoodsActivity extends BaseDataBindingActivity {
|
||||
private static final String TAG = GoodsActivity.class.getSimpleName();
|
||||
|
||||
private ActivityGoodsBinding mBinding;
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
private GoodsListAdapter mGoodsAdapter;
|
||||
|
||||
private HashMap<String, GoodsType> mGoodsTypeMap;
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_goods);
|
||||
mBinding.setListener(new Listener());
|
||||
mRecyclerView = mBinding.recyclerView;
|
||||
mGoodsAdapter = new GoodsListAdapter();
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
mRecyclerView.setAdapter(mGoodsAdapter);
|
||||
|
||||
mBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
Log.e(TAG, "onTabSelected: " + tab.getText());
|
||||
if (tab.getText() != null && !TextUtils.isEmpty(tab.getText())) {
|
||||
String text = tab.getText().toString();
|
||||
if (mGoodsTypeMap.get(text) != null) {
|
||||
getAllGoods(mGoodsTypeMap.get(text).getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
Log.e(TAG, "onTabUnselected: " + tab.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
Log.e(TAG, "onTabReselected: " + tab.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
getGoodsType();
|
||||
}
|
||||
|
||||
private void getGoodsType() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getGoodsTypeListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<GoodsType>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getGoodsType", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<GoodsType>> listBaseResponse) {
|
||||
Log.e("getGoodsType", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
mBinding.tabLayout.setVisibility(View.VISIBLE);
|
||||
List<GoodsType> goodsTypeList = listBaseResponse.data;
|
||||
List<String> typeString = goodsTypeList.stream().map(GoodsType::getName).collect(Collectors.toList());
|
||||
String[] type = new String[goodsTypeList.size()];
|
||||
type = typeString.toArray(type);
|
||||
mGoodsTypeMap = new HashMap<>();
|
||||
for (int i = 0; i < type.length; i++) {
|
||||
mGoodsTypeMap.put(type[i], goodsTypeList.get(i));
|
||||
TabLayout.Tab tab = mBinding.tabLayout.newTab();//关键的创建一个Tab,注意这里使用的是已经实例的mTablayout创建的Tab,很容易疏忽使用new Tablayout().new Tab()的方式创建,这个是会报错的.
|
||||
tab.setText(type[i]);
|
||||
if (i == 0) {
|
||||
mBinding.tabLayout.addTab(tab, 0, true);//设置选择的item
|
||||
} else {
|
||||
mBinding.tabLayout.addTab(tab);
|
||||
}
|
||||
}
|
||||
getAllGoods(goodsTypeList.get(0).getId());
|
||||
} else {
|
||||
mBinding.tabLayout.setVisibility(View.GONE);
|
||||
getAllGoods();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getGoodsType", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getGoodsType", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void getAllGoods(int type) {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getGoodsListObservable(type)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(getGoodsListObservable());
|
||||
}
|
||||
|
||||
|
||||
private void getAllGoods() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getGoodsListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(getGoodsListObservable());
|
||||
}
|
||||
|
||||
private Observer<BaseResponse<GoodsList>> getGoodsListObservable() {
|
||||
return new Observer<BaseResponse<GoodsList>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAllGoods", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<GoodsList> listBaseResponse) {
|
||||
Log.e("getAllGoods", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
GoodsList goodsList = listBaseResponse.data;
|
||||
List<GoodsInfo> goodsInfos = goodsList.getData();
|
||||
mGoodsAdapter.setGoodsInfoList(goodsInfos);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mBinding.clNodata.setVisibility(View.GONE);
|
||||
} else {
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mBinding.clNodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAllGoods", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAllGoods", "onComplete: ");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public class Listener {
|
||||
public void back(View view) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.ArticleAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.ArticleInfo;
|
||||
import com.uiuios.aios.bean.ArticleList;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
@@ -69,16 +70,17 @@ public class InfoListActivity extends BaseActivity {
|
||||
public void initData() {
|
||||
NetInterfaceManager.getInstance().getArticleListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<ArticleInfo>>>() {
|
||||
.subscribe(new Observer<BaseResponse<ArticleList>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getArticle", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<ArticleInfo>> listBaseResponse) {
|
||||
public void onNext(@NonNull BaseResponse<ArticleList> listBaseResponse) {
|
||||
Log.e("getArticle", "onNext: " + listBaseResponse);
|
||||
List<ArticleInfo> articleInfoList = listBaseResponse.data;
|
||||
ArticleList articleList = listBaseResponse.data;
|
||||
List<ArticleInfo> articleInfoList = articleList.getData();
|
||||
if (articleInfoList != null && articleInfoList.size() != 0) {
|
||||
iv1.setVisibility(android.view.View.GONE);
|
||||
mArticleAdapter.setArticleBeanList(articleInfoList);
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.InformationAdapter;
|
||||
import com.uiuios.aios.adapter.TitleAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.base.BaseDataBindingActivity;
|
||||
import com.uiuios.aios.base.DataBindingActivity;
|
||||
import com.uiuios.aios.bean.ArticleInfo;
|
||||
import com.uiuios.aios.bean.ArticleList;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.CategoryBean;
|
||||
import com.uiuios.aios.databinding.ActivityInformationBinding;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -28,54 +35,66 @@ import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class InformationActivity extends BaseActivity {
|
||||
public class InformationActivity extends DataBindingActivity {
|
||||
private static final String TAG = InformationActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.rv_title)
|
||||
RecyclerView rv_title;
|
||||
@BindView(R.id.tabLayout)
|
||||
TabLayout tabLayout;
|
||||
@BindView(R.id.root)
|
||||
ConstraintLayout root;
|
||||
@BindView(R.id.rv_video)
|
||||
RecyclerView rv_video;
|
||||
@BindView(R.id.cl_nodata)
|
||||
ConstraintLayout cl_nodata;
|
||||
|
||||
private TitleAdapter mTitleAdapter;
|
||||
private ActivityInformationBinding mBinding;
|
||||
private InformationAdapter mInformationAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_information;
|
||||
}
|
||||
private HashMap<String, CategoryBean> mCategoryMap;
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_information);
|
||||
ButterKnife.bind(this);
|
||||
mTitleAdapter = new TitleAdapter();
|
||||
mTitleAdapter.setTitleChangeCallback(new TitleAdapter.TitleChangeCallback() {
|
||||
@Override
|
||||
public void onTitleChange(CategoryBean categoryBean) {
|
||||
int id = categoryBean.getId();
|
||||
if (id == -100) {
|
||||
UltimateBarX.statusBarOnly(this)
|
||||
.transparent()
|
||||
.apply();
|
||||
|
||||
} else {
|
||||
UltimateBarX.addStatusBarTopPadding(tabLayout);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
rv_title.setLayoutManager(linearLayoutManager);
|
||||
rv_title.setAdapter(mTitleAdapter);
|
||||
|
||||
mInformationAdapter =new InformationAdapter();
|
||||
LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(this);
|
||||
mInformationAdapter = new InformationAdapter();
|
||||
LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(this);
|
||||
linearLayoutManager1.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
rv_video.setLayoutManager(linearLayoutManager1);
|
||||
rv_video.setAdapter(mInformationAdapter);
|
||||
|
||||
mBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
Log.e(TAG, "onTabSelected: " + tab.getText());
|
||||
if (tab.getText() != null && !TextUtils.isEmpty(tab.getText())) {
|
||||
String text = tab.getText().toString();
|
||||
if (mCategoryMap.get(text) != null) {
|
||||
getArticleList(mCategoryMap.get(text).getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
Log.e(TAG, "onTabUnselected: " + tab.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
Log.e(TAG, "onTabReselected: " + tab.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
getCategorys();
|
||||
getArticleList();
|
||||
}
|
||||
|
||||
private void getCategorys() {
|
||||
@@ -91,9 +110,26 @@ public class InformationActivity extends BaseActivity {
|
||||
public void onNext(@NonNull BaseResponse<List<CategoryBean>> listBaseResponse) {
|
||||
Log.e("getCategorys", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
mTitleAdapter.setCategoryList(listBaseResponse.data);
|
||||
mBinding.tabLayout.setVisibility(View.VISIBLE);
|
||||
List<CategoryBean> categoryList = listBaseResponse.data;
|
||||
List<String> typeString = categoryList.stream().map(CategoryBean::getName).collect(Collectors.toList());
|
||||
String[] type = new String[categoryList.size()];
|
||||
type = typeString.toArray(type);
|
||||
mCategoryMap = new HashMap<>();
|
||||
for (int i = 0; i < type.length; i++) {
|
||||
mCategoryMap.put(type[i], categoryList.get(i));
|
||||
TabLayout.Tab tab = mBinding.tabLayout.newTab();//关键的创建一个Tab,注意这里使用的是已经实例的mTablayout创建的Tab,很容易疏忽使用new Tablayout().new Tab()的方式创建,这个是会报错的.
|
||||
tab.setText(type[i]);
|
||||
if (i == 0) {
|
||||
mBinding.tabLayout.addTab(tab, 0, true);//设置选择的item
|
||||
} else {
|
||||
mBinding.tabLayout.addTab(tab);
|
||||
}
|
||||
}
|
||||
getArticleList(categoryList.get(0).getId());
|
||||
} else {
|
||||
mTitleAdapter.setCategoryList(null);
|
||||
mBinding.tabLayout.setVisibility(View.GONE);
|
||||
getArticleList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,38 +147,55 @@ public class InformationActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void getArticleList() {
|
||||
NetInterfaceManager.getInstance().getArticleListObservable()
|
||||
NetInterfaceManager.getInstance()
|
||||
.getArticleListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<ArticleInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getArticle", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<ArticleInfo>> listBaseResponse) {
|
||||
Log.e("getArticle", "onNext: " + listBaseResponse);
|
||||
List<ArticleInfo> articleInfoList = listBaseResponse.data;
|
||||
if (articleInfoList != null && articleInfoList.size() != 0) {
|
||||
mInformationAdapter.setArticleInfos(articleInfoList);
|
||||
rv_video.setVisibility(View.VISIBLE);
|
||||
cl_nodata.setVisibility(android.view.View.GONE);
|
||||
} else {
|
||||
rv_video.setVisibility(android.view.View.GONE);
|
||||
cl_nodata.setVisibility(android.view.View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getArticle", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getArticle", "onComplete: ");
|
||||
}
|
||||
});
|
||||
.subscribe(getArticleListObserver());
|
||||
}
|
||||
|
||||
private void getArticleList(int id) {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getArticleListObservable(id)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(getArticleListObserver());
|
||||
}
|
||||
|
||||
private Observer<BaseResponse<ArticleList>> getArticleListObserver() {
|
||||
return new Observer<BaseResponse<ArticleList>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getArticle", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<ArticleList> listBaseResponse) {
|
||||
Log.e("getArticle", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
ArticleList articleList = listBaseResponse.data;
|
||||
List<ArticleInfo> articleInfoList = articleList.getData();
|
||||
if (articleInfoList != null && articleInfoList.size() != 0) {
|
||||
mInformationAdapter.setArticleInfos(articleInfoList);
|
||||
rv_video.setVisibility(View.VISIBLE);
|
||||
cl_nodata.setVisibility(android.view.View.GONE);
|
||||
} else {
|
||||
rv_video.setVisibility(android.view.View.GONE);
|
||||
cl_nodata.setVisibility(android.view.View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
rv_video.setVisibility(android.view.View.GONE);
|
||||
cl_nodata.setVisibility(android.view.View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getArticle", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getArticle", "onComplete: ");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
177
app/src/main/java/com/uiuios/aios/activity/OrderActivity.java
Normal file
177
app/src/main/java/com/uiuios/aios/activity/OrderActivity.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.BuildConfig;
|
||||
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.OrderBean;
|
||||
import com.uiuios.aios.databinding.ActivityOrderBinding;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class OrderActivity extends BaseDataBindingActivity {
|
||||
private static final String TAG = OrderActivity.class.getSimpleName();
|
||||
|
||||
private ActivityOrderBinding mBinding;
|
||||
|
||||
private GoodsInfo mGoodsInfo;
|
||||
private int mStock;
|
||||
private int mNumer = 1;
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_order);
|
||||
mBinding.ivReduce.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String numberString = mBinding.editText.getText().toString();
|
||||
int number = Integer.parseInt(numberString);
|
||||
if (number > 1) {
|
||||
mBinding.editText.setText(String.valueOf(number - 1));
|
||||
mNumer = number - 1;
|
||||
mBinding.tvPay.setText("立即支付 ¥" + multi(mGoodsInfo.getBuying_price(), mNumer));
|
||||
}
|
||||
}
|
||||
});
|
||||
mBinding.ivAdd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String numberString = mBinding.editText.getText().toString();
|
||||
int number = Integer.parseInt(numberString);
|
||||
if (number < mStock) {
|
||||
mBinding.editText.setText(String.valueOf(number + 1));
|
||||
mNumer = number + 1;
|
||||
mBinding.tvPay.setText("立即支付 ¥" + multi(mGoodsInfo.getBuying_price(), mNumer));
|
||||
}
|
||||
}
|
||||
});
|
||||
mBinding.editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
Log.e("editText", "beforeTextChanged: " + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
Log.e("editText", "onTextChanged: " + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
Log.e("editText", "afterTextChanged: " + s);
|
||||
String numberString = s.toString();
|
||||
if (TextUtils.isEmpty(s)) {
|
||||
return;
|
||||
}
|
||||
int number = Integer.parseInt(numberString);
|
||||
if (number > mStock) {
|
||||
mNumer = mStock;
|
||||
mBinding.tvPay.setText("立即支付 ¥" + multi(mGoodsInfo.getBuying_price(), mNumer));
|
||||
} else if (number == 0) {
|
||||
mNumer = 1;
|
||||
mBinding.editText.setText("1");
|
||||
mBinding.tvPay.setText("立即支付 ¥" + multi(mGoodsInfo.getBuying_price(), mNumer));
|
||||
} else {
|
||||
mNumer = number;
|
||||
mBinding.tvPay.setText("立即支付 ¥" + multi(mGoodsInfo.getBuying_price(), mNumer));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String multi(String v1, int v2) {
|
||||
BigDecimal b1 = new BigDecimal(v1);
|
||||
BigDecimal b2 = new BigDecimal(String.valueOf(v2));
|
||||
return b1.multiply(b2).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) return;
|
||||
GoodsInfo goodsInfo = (GoodsInfo) intent.getSerializableExtra("GoodsInfo");
|
||||
if (goodsInfo == null) return;
|
||||
mGoodsInfo = goodsInfo;
|
||||
mBinding.setGoodsInfo(mGoodsInfo);
|
||||
mBinding.tvPrice.setText("券后¥" + mGoodsInfo.getBuying_price());
|
||||
mBinding.tvOriginalPrice.setText("券前¥" + mGoodsInfo.getOriginal_price());
|
||||
mStock = mGoodsInfo.getStock();
|
||||
mBinding.tvStock.setText("库存:" + mStock);
|
||||
mBinding.tvPay.setText("立即支付 ¥" + mGoodsInfo.getBuying_price());
|
||||
mBinding.clPay.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
creactOrder();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void creactOrder() {
|
||||
Map<String, RequestBody> params = new HashMap<>();
|
||||
params.put("goods_id", NetInterfaceManager.convertToRequestBody(mGoodsInfo.getId()));
|
||||
params.put("num", NetInterfaceManager.convertToRequestBody(mBinding.editText.getText().toString()));
|
||||
params.put("sn", NetInterfaceManager.convertToRequestBody(RemoteManager.getInstance().getSerial()));
|
||||
params.put("desktop_app_package", NetInterfaceManager.convertToRequestBody(BuildConfig.APPLICATION_ID));
|
||||
NetInterfaceManager.getInstance().getGoodsBuyObservable(params)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<OrderBean>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("goodsPay", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<OrderBean> baseResponse) {
|
||||
Log.e("goodsPay", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
OrderBean orderBean = baseResponse.data;
|
||||
Intent intent1 = new Intent(OrderActivity.this, PayActivity.class);
|
||||
intent1.putExtra("OrderBean", orderBean);
|
||||
startActivity(intent1);
|
||||
} else {
|
||||
ToastUtil.show("下单失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("goodsPay", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("goodsPay", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
185
app/src/main/java/com/uiuios/aios/activity/PayActivity.java
Normal file
185
app/src/main/java/com/uiuios/aios/activity/PayActivity.java
Normal file
@@ -0,0 +1,185 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.base.BaseDataBindingActivity;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.OrderBean;
|
||||
import com.uiuios.aios.bean.WxpayBean;
|
||||
import com.uiuios.aios.databinding.ActivityPayBinding;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.BitmapUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.functions.Consumer;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class PayActivity extends BaseDataBindingActivity {
|
||||
private static final String TAG = PayActivity.class.getSimpleName();
|
||||
|
||||
private ActivityPayBinding mBinding;
|
||||
|
||||
private OrderBean mOrderBean;
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_pay);
|
||||
mBinding.tvRefresh.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getWechatPayQrcode(mOrderBean);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) return;
|
||||
OrderBean orderBean = (OrderBean) intent.getSerializableExtra("OrderBean");
|
||||
if (orderBean == null) return;
|
||||
mOrderBean = orderBean;
|
||||
getWechatPayQrcode(mOrderBean);
|
||||
}
|
||||
|
||||
private Disposable mCountdownSubscribe;
|
||||
|
||||
private void getWechatPayQrcode(OrderBean orderBean) {
|
||||
if (orderBean == null) return;
|
||||
NetInterfaceManager.getInstance()
|
||||
.getOrderPayObservable(orderBean.getOrder_sn(), orderBean.getOrder_id())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<WxpayBean>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getOrderPayObservable", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<WxpayBean> wxpayBeanBaseResponse) {
|
||||
Log.e("getOrderPayObservable", "onNext: " + wxpayBeanBaseResponse);
|
||||
if (wxpayBeanBaseResponse.code == 200) {
|
||||
WxpayBean wxpayBean = wxpayBeanBaseResponse.data;
|
||||
mBinding.setWxpayBean(wxpayBean);
|
||||
mBinding.tvOrderId.setText("订单编号:" + wxpayBean.getOrder_sn());
|
||||
long expireTime = wxpayBean.getTime_expire();
|
||||
mBinding.ivWxQrcode.setImageBitmap(BitmapUtils.createQRImage(wxpayBean.getCode_url(), 400, 400));
|
||||
initCountdown(expireTime);
|
||||
checkOrder(wxpayBean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getOrderPayObservable", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getOrderPayObservable", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initCountdown(long second) {
|
||||
if (mCountdownSubscribe != null && !mCountdownSubscribe.isDisposed()) {
|
||||
mCountdownSubscribe.dispose();
|
||||
}
|
||||
mCountdownSubscribe = Observable.interval(1, TimeUnit.SECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<Long>() {
|
||||
|
||||
@Override
|
||||
public void accept(Long aLong) throws Exception {
|
||||
long timestamp = System.currentTimeMillis() / 1000;
|
||||
Log.e("initCountdown", "accept: time_expire = " + second);
|
||||
Log.e("initCountdown", "accept: aLong = " + aLong);
|
||||
Log.e("initCountdown", "accept: timestamp = " + timestamp);
|
||||
if (timestamp >= second) {
|
||||
mBinding.ivWxQrcode.setImageDrawable(getDrawable(R.drawable.qrcode_expired));
|
||||
if (mCountdownSubscribe != null && !mCountdownSubscribe.isDisposed()) {
|
||||
mCountdownSubscribe.dispose();
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Disposable mCheckOrderSubscribe;
|
||||
|
||||
private void checkOrder(WxpayBean wxpayBean) {
|
||||
if (mCheckOrderSubscribe != null && !mCheckOrderSubscribe.isDisposed()) {
|
||||
mCheckOrderSubscribe.dispose();
|
||||
}
|
||||
mCheckOrderSubscribe = Observable.interval(5, TimeUnit.SECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<Long>() {
|
||||
|
||||
@Override
|
||||
public void accept(Long aLong) throws Exception {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getOrderPayCheckObservable(wxpayBean.getOrder_sn(), wxpayBean.getOrder_id())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkOrder", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("checkOrder", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
if (mCountdownSubscribe != null && !mCountdownSubscribe.isDisposed()) {
|
||||
mCountdownSubscribe.dispose();
|
||||
}
|
||||
if (mCheckOrderSubscribe != null && !mCheckOrderSubscribe.isDisposed()) {
|
||||
mCheckOrderSubscribe.dispose();
|
||||
}
|
||||
ToastUtil.show("支付成功");
|
||||
finish();
|
||||
} else {
|
||||
Log.e("checkOrder", "onNext: " + "支付失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkOrder", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkOrder", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import com.uiuios.aios.adapter.GoodsListAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.GoodsInfo;
|
||||
import com.uiuios.aios.bean.GoodsList;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
@@ -76,16 +77,17 @@ public class SpikeListActivity extends BaseActivity {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getGoodsListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<GoodsInfo>>>() {
|
||||
.subscribe(new Observer<BaseResponse<GoodsList>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getGoods", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<GoodsInfo>> listBaseResponse) {
|
||||
public void onNext(@NonNull BaseResponse<GoodsList> listBaseResponse) {
|
||||
Log.e("getGoods", "onNext: " + listBaseResponse);
|
||||
List<GoodsInfo> goodsInfos = listBaseResponse.data;
|
||||
GoodsList goodsList = listBaseResponse.data;
|
||||
List<GoodsInfo> goodsInfos = goodsList.getData();
|
||||
if (goodsInfos != null && goodsInfos.size() != 0) {
|
||||
iv1.setVisibility(android.view.View.GONE);
|
||||
mGoodsAdapter.setGoodsInfoList(goodsInfos);
|
||||
|
||||
Reference in New Issue
Block a user