version:1.9
fix: update:修改包名,添加推送
This commit is contained in:
331
app/src/main/java/com/uiui/aios/fragment/SecondFragment.java
Normal file
331
app/src/main/java/com/uiui/aios/fragment/SecondFragment.java
Normal file
@@ -0,0 +1,331 @@
|
||||
package com.uiui.aios.fragment;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.base.BaseFragment;
|
||||
import com.uiui.aios.bean.ActivityBean;
|
||||
import com.uiui.aios.bean.ArticleInfo;
|
||||
import com.uiui.aios.bean.BaseResponse;
|
||||
import com.uiui.aios.bean.DemandBean;
|
||||
import com.uiui.aios.bean.GoodsInfo;
|
||||
import com.uiui.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link SecondFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class SecondFragment extends BaseFragment {
|
||||
private static final String TAG = SecondFragment.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.iv_img)
|
||||
ImageView iv_img;
|
||||
@BindView(R.id.tv_goods_name)
|
||||
TextView tv_goods_name;
|
||||
@BindView(R.id.tv_goods_desc)
|
||||
TextView tv_goods_desc;
|
||||
@BindView(R.id.tv_buying_price)
|
||||
TextView tv_buying_price;
|
||||
@BindView(R.id.progressBar)
|
||||
ProgressBar progressBar;
|
||||
@BindView(R.id.tv_snapup)
|
||||
TextView tv_snapup;
|
||||
|
||||
@BindView(R.id.iv_aimg)
|
||||
ImageView iv_aimg;
|
||||
@BindView(R.id.tv_title)
|
||||
TextView tv_title;
|
||||
@BindView(R.id.tv_content)
|
||||
TextView tv_content;
|
||||
|
||||
@BindView(R.id.iv_avatar_a)
|
||||
ImageView iv_avatar_a;
|
||||
@BindView(R.id.tv_title_a)
|
||||
TextView tv_title_a;
|
||||
|
||||
@BindView(R.id.iv_avatar_d)
|
||||
ImageView iv_avatar_d;
|
||||
@BindView(R.id.tv_title_d)
|
||||
TextView tv_title_d;
|
||||
@BindView(R.id.tv_price)
|
||||
TextView tv_price;
|
||||
|
||||
@BindView(R.id.cl_activity)
|
||||
ConstraintLayout cl_activity;
|
||||
|
||||
@BindView(R.id.cl_demand)
|
||||
ConstraintLayout cl_demand;
|
||||
|
||||
private View rootView;
|
||||
private Context mContext;
|
||||
private ContentResolver mCRv;
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
public SecondFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment SecondFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static SecondFragment newInstance(String param1, String param2) {
|
||||
SecondFragment fragment = new SecondFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
rootView = inflater.inflate(R.layout.fragment_second, container, false);
|
||||
mContext = rootView.getContext();
|
||||
mCRv = mContext.getContentResolver();
|
||||
ButterKnife.bind(this, rootView);
|
||||
initView();
|
||||
initData();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
getGoods();
|
||||
getArticle();
|
||||
getActivityList();
|
||||
getDemandList();
|
||||
}
|
||||
|
||||
private void getDemandList() {
|
||||
NetInterfaceManager.getInstance().getDemandListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<DemandBean>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getDemandList", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<DemandBean>> listBaseResponse) {
|
||||
Log.e("getDemandList", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<DemandBean> demandBeans = listBaseResponse.data;
|
||||
if (demandBeans != null && demandBeans.size() != 0) {
|
||||
DemandBean demandBean = demandBeans.get(0);
|
||||
setDemand(demandBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getDemandList", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getDemandList", "onComplete: ");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setDemand(DemandBean demandBean) {
|
||||
Glide.with(iv_avatar_d).load(demandBean.getAvatar()).into(iv_avatar_d);
|
||||
tv_title_d.setText(demandBean.getTitle());
|
||||
tv_price.setText(String.valueOf(demandBean.getPrice()));
|
||||
}
|
||||
|
||||
private void getActivityList() {
|
||||
NetInterfaceManager.getInstance().getActivityListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<ActivityBean>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getActivityList", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<ActivityBean>> listBaseResponse) {
|
||||
Log.e("getActivityList", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<ActivityBean> activityBeans = listBaseResponse.data;
|
||||
if (activityBeans != null && activityBeans.size() != 0) {
|
||||
ActivityBean activityBean = activityBeans.get(0);
|
||||
setActivity(activityBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getActivityList", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getActivityList", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setActivity(ActivityBean activity) {
|
||||
Glide.with(iv_avatar_a).load(activity.getAvatar()).into(iv_avatar_a);
|
||||
tv_title_a.setText(activity.getTitle());
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
cl_activity.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openApp();
|
||||
}
|
||||
});
|
||||
cl_demand.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openApp();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openApp(){
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
/*知道要跳转应用的包命与目标Activity*/
|
||||
ComponentName componentName = new ComponentName("com.uiui.city", "com.uiui.city.activity.MainActivity");
|
||||
intent.setComponent(componentName);
|
||||
intent.putExtra("", "");//这里Intent传值
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void getGoods() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getGoodsListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<GoodsInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getGoods", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<GoodsInfo>> listBaseResponse) {
|
||||
Log.e("getGoods", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<GoodsInfo> goodsInfoList = listBaseResponse.data;
|
||||
if (goodsInfoList != null && goodsInfoList.size() != 0) {
|
||||
GoodsInfo goodsInfo = goodsInfoList.get(0);
|
||||
setGoodsInfo(goodsInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getGoods", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getGoods", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setGoodsInfo(GoodsInfo goodsInfo) {
|
||||
Glide.with(iv_img).load(goodsInfo.getImg()).into(iv_img);
|
||||
tv_goods_name.setText(goodsInfo.getGoods_name());
|
||||
tv_goods_desc.setText(goodsInfo.getGoods_desc());
|
||||
tv_buying_price.setText(String.valueOf(goodsInfo.getBuying_price()));
|
||||
}
|
||||
|
||||
private void getArticle() {
|
||||
NetInterfaceManager.getInstance().getArticleListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.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);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<ArticleInfo> articleInfos = listBaseResponse.data;
|
||||
if (articleInfos != null && articleInfos.size() != 0) {
|
||||
ArticleInfo articleInfo = articleInfos.get(0);
|
||||
setArticleInfo(articleInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getArticle", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getArticle", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setArticleInfo(ArticleInfo articleInfo) {
|
||||
Glide.with(iv_aimg).load(articleInfo.getImg()).into(iv_aimg);
|
||||
tv_title.setText(articleInfo.getTitle());
|
||||
tv_content.setText(articleInfo.getContent());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user