1301 lines
57 KiB
Java
1301 lines
57 KiB
Java
package com.sl.house_property;
|
||
|
||
import android.app.ProgressDialog;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.graphics.Rect;
|
||
import android.net.Uri;
|
||
import android.os.Bundle;
|
||
import android.support.annotation.NonNull;
|
||
import android.support.v4.app.Fragment;
|
||
import android.support.v7.widget.LinearLayoutManager;
|
||
import android.text.TextPaint;
|
||
import android.text.TextUtils;
|
||
import android.util.Log;
|
||
import android.view.Gravity;
|
||
import android.view.LayoutInflater;
|
||
import android.view.MotionEvent;
|
||
import android.view.View;
|
||
import android.view.ViewTreeObserver;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.Toast;
|
||
|
||
import com.bumptech.glide.Glide;
|
||
import com.bumptech.glide.request.RequestOptions;
|
||
import com.cutil.ScreenUtils;
|
||
import com.google.gson.Gson;
|
||
import com.google.gson.internal.LinkedTreeMap;
|
||
import com.google.gson.reflect.TypeToken;
|
||
import com.gyf.immersionbar.ImmersionBar;
|
||
import com.lxj.xpopup.XPopup;
|
||
import com.lzy.ninegrid.ImageInfo;
|
||
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;
|
||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
|
||
import com.selectpicker.OptionsPopupWindow;
|
||
import com.sl.house_property.databinding.FragmentMainBinding;
|
||
import com.sl.house_property.databinding.ItemCommentBinding;
|
||
import com.sl.house_property.databinding.ItemDiscoveryBinding;
|
||
import com.sl.house_property.discovery.GoodsInfoDialog;
|
||
import com.sl.house_property.discovery.HistoryRecordActivity;
|
||
import com.sl.house_property.discovery.PropertyActivity;
|
||
import com.sl.house_property.discovery.ShareCodeActivity;
|
||
import com.sl.house_property.order.SettleActivity;
|
||
import com.sl.house_property.user.MyMarketShopActivity;
|
||
import com.squareup.picasso.Picasso;
|
||
import com.youth.banner.Banner;
|
||
import com.youth.banner.BannerConfig;
|
||
import com.youth.banner.Transformer;
|
||
import com.youth.banner.loader.ImageLoader;
|
||
|
||
import org.json.JSONArray;
|
||
import org.json.JSONException;
|
||
import org.json.JSONObject;
|
||
|
||
import java.lang.reflect.Type;
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import adapter.BaseRecycleViewAdapter;
|
||
import entity.Advert_carouseleEntity;
|
||
import entity.DiscoveryListEntity;
|
||
import entity.GoodsDetailEntity;
|
||
import entity.HomelistitemEntity;
|
||
import entity.MainF1Entity;
|
||
import entity.RegisterUser;
|
||
import http.ApiConfig;
|
||
import my_loader.Loader;
|
||
import my_loader.Resultcode;
|
||
import my_view.CommentDialog;
|
||
import my_view.tao_bao_refresh.FullyGridLayoutManager;
|
||
import rx.Subscription;
|
||
import rx.functions.Action1;
|
||
import tools.Config;
|
||
import utils.CommonUtils;
|
||
import utils.DateUtils;
|
||
import utils.KeyboardUtil;
|
||
import utils.Md5;
|
||
import utils.UtilHelpers;
|
||
|
||
|
||
/**
|
||
* A simple {@link Fragment} subclass.
|
||
* Activities that contain this fragment must implement the
|
||
* {@link Main1Fragment.OnFragmentInteractionListener} interface
|
||
* to handle interaction events.
|
||
* Use the {@link Main1Fragment#newInstance} factory method to
|
||
* create an instance of this fragment.
|
||
*/
|
||
public class MainFragment extends BaseFragment<FragmentMainBinding> implements View.OnClickListener, MainTabActivity.MyOnTouchListener {
|
||
// 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";
|
||
BaseActivity baseActivity;
|
||
// TODO: Rename and change types of parameters
|
||
private String mParam1;
|
||
private String mParam2;
|
||
private ArrayList<DiscoveryListEntity> discoveryListEntities = new ArrayList<>();
|
||
private OnFragmentInteractionListener mListener;
|
||
private ProgressDialog progressDialog;
|
||
private Loader mGankLoader;
|
||
|
||
private ArrayList<String> mBannerImages;
|
||
|
||
private List<String> bannerTitile;
|
||
|
||
private BaseRecycleViewAdapter baseRecycleViewAdapterh;
|
||
|
||
private BaseRecycleViewAdapter baseRecycleViewAdapterv;
|
||
private RegisterUser user;
|
||
|
||
public MainFragment() {
|
||
// 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 Main1Fragment.
|
||
*/
|
||
// TODO: Rename and change types and number of parameters
|
||
public static MainFragment newInstance(String param1, String param2) {
|
||
MainFragment fragment = new MainFragment();
|
||
Bundle args = new Bundle();
|
||
args.putString(ARG_PARAM1, param1);
|
||
args.putString(ARG_PARAM2, param2);
|
||
fragment.setArguments(args);
|
||
return fragment;
|
||
}
|
||
|
||
@Override
|
||
public void onResume() {
|
||
super.onResume();
|
||
RegisterUser user1;
|
||
if (user == null) {
|
||
|
||
user1 =
|
||
Config.getInstance(getActivity()).getUser();
|
||
if (user1 != null) {
|
||
Map<String, String> map = new HashMap<>();
|
||
if (user1 != null) {
|
||
map.put("userid", user1.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
map.put("app", "Advert");
|
||
map.put("class", "Advertr_an_AdvertHomeList");
|
||
map.put("sign", Md5.md5("Advert" + "Advertr_an_AdvertHomeList" + Md5.secret));
|
||
getGankList(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), 0, false);
|
||
user = user1;
|
||
}
|
||
;
|
||
}
|
||
}
|
||
|
||
private ArrayList<HomelistitemEntity> list;
|
||
|
||
@Override
|
||
public void onCreate(Bundle savedInstanceState) {
|
||
super.onCreate(savedInstanceState);
|
||
if (getArguments() != null) {
|
||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
private void getGankList(final String myurl, Map<String, String> map, String string, final int getcode1) {
|
||
|
||
progressDialog.setMessage(string);
|
||
|
||
//map.put("")
|
||
progressDialog.setCancelable(false);
|
||
progressDialog.show();
|
||
mDataBinding.getRoot().postDelayed(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
progressDialog.dismiss();
|
||
//setToast(1, getString(R.string.timeout));
|
||
}
|
||
}, 13000);
|
||
mGankLoader = new Loader();
|
||
/* Map<String,String> map=new HashMap<String,String>();
|
||
map.put("phone");*/
|
||
mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
||
@Override
|
||
public void call(Resultcode resultcode) {
|
||
progressDialog.dismiss();
|
||
//setToast(0,resultcode.status);
|
||
if ((!(resultcode.status == 0))) {
|
||
Toast.makeText(getContext(), resultcode.msg, Toast.LENGTH_SHORT).show();
|
||
return;
|
||
}
|
||
switch (getcode1) {
|
||
|
||
case 0:
|
||
Gson gs = new Gson();
|
||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||
String s = gs.toJson(adta);
|
||
try {
|
||
JSONObject jsonObject = new JSONObject(s);
|
||
JSONArray jsonArray = jsonObject.getJSONArray("home");
|
||
Type type = new TypeToken<ArrayList<HomelistitemEntity>>() {
|
||
}.getType();
|
||
list = new Gson().fromJson(jsonArray.toString(), type);
|
||
if (list == null || list.isEmpty()) {
|
||
return;
|
||
}
|
||
final ArrayList<String> strings = new ArrayList<>();
|
||
for (int i = 0; i < list.size(); i++) {
|
||
strings.add(list.get(i).getAddress());
|
||
}
|
||
OptionsPopupWindow alarmOptionPop = new OptionsPopupWindow(getContext());
|
||
alarmOptionPop.setPicker(strings);
|
||
|
||
alarmOptionPop.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {
|
||
@Override
|
||
public void onOptionsSelect(int position, int option2, int options3) {
|
||
if (list.size() > 0) {
|
||
mDataBinding.tv1Address.setText(list.get(position).getAddress());
|
||
}
|
||
|
||
}
|
||
});
|
||
|
||
alarmOptionPop.showAtLocation(mDataBinding.getRoot(), Gravity.BOTTOM, 0, 0);
|
||
} catch (JSONException e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
|
||
break;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}, new Action1<Throwable>() {
|
||
@Override
|
||
public void call(Throwable throwable) {
|
||
progressDialog.dismiss();
|
||
//
|
||
Toast.makeText(getContext(), getString(R.string.getdatafailure), Toast.LENGTH_SHORT).show();
|
||
|
||
throwable.printStackTrace();
|
||
}
|
||
});
|
||
|
||
|
||
}
|
||
|
||
@Override
|
||
protected void onCreateVew(LayoutInflater inflater, Bundle savedInstanceState) {
|
||
super.onCreateVew(inflater, savedInstanceState);
|
||
baseActivity = (BaseActivity) getActivity();
|
||
// progressDialog = new ProgressDialog(baseActivity);
|
||
// progressDialog.show();
|
||
// progressDialog.setMessage(getActivity().getString(R.string.loading));
|
||
progressDialog = new ProgressDialog(getContext());
|
||
intRecycleView();
|
||
//getGankList(ApiConfig.GETHOMEBANNER,new HashMap<String, String>(),getString(R.string.loading),0);
|
||
mDataBinding.taobaoRefreshLayout.setOnRefreshLoadMoreListener(onrefalshlister);
|
||
// mDataBinding.taobaoRefreshLayout.postDelayed(new Runnable() {
|
||
// @Override
|
||
// public void run() {
|
||
// /* configFragments();
|
||
// intRecycleHorization();
|
||
// intRecycleVerization();*/
|
||
// user =
|
||
// Config.getInstance(getActivity()).getUser();
|
||
// Map<String, String> map = new HashMap<>();
|
||
// if (user != null) {
|
||
// map.put("userid", user.getUserid());
|
||
// } else {
|
||
// map.put("userid", 0 + "");
|
||
// }
|
||
// map.put("app", "Advert");
|
||
// map.put("class", "Advertr_an_AdvertHomeList");
|
||
// map.put("sign", Md5.md5("Advert" + "Advertr_an_AdvertHomeList" + Md5.secret));
|
||
// getGankList(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), 0, true);
|
||
// }
|
||
// }, 0);
|
||
mDataBinding.scan.setOnClickListener(this);
|
||
mDataBinding.entrancegurd.setOnClickListener(this);
|
||
mDataBinding.cargara.setOnClickListener(this);
|
||
mDataBinding.moew1.setOnClickListener(this);
|
||
//mDataBinding.moew2.setOnClickListener(this);
|
||
View banner = mDataBinding.l3;
|
||
LinearLayout.LayoutParams bannerLP = (LinearLayout.LayoutParams) banner.getLayoutParams();
|
||
bannerLP.width = ScreenUtils.getScreenWidth();
|
||
banner.setLayoutParams(bannerLP);
|
||
mDataBinding.taobaoRefreshLayout.autoRefresh();
|
||
mDataBinding.tv1Address.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
if (list == null || list.isEmpty()) {
|
||
Map<String, String> map = new HashMap<>();
|
||
RegisterUser registerUser = Config.getInstance(getContext()).getUser();
|
||
if (registerUser != null) {
|
||
map.put("userid", registerUser.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
|
||
map.put("sign", Md5.md5("Cas" + "GetMyAddress" + Md5.secret));
|
||
map.put("app", "Cas");
|
||
map.put("class", "GetMyAddress");
|
||
getGankList(ApiConfig.BASE_URL, map, "", 0);
|
||
return;
|
||
}
|
||
final ArrayList<String> strings = new ArrayList<>();
|
||
for (int i = 0; i < list.size(); i++) {
|
||
strings.add(list.get(i).getAddress());
|
||
}
|
||
OptionsPopupWindow alarmOptionPop = new OptionsPopupWindow(getContext());
|
||
alarmOptionPop.setPicker(strings);
|
||
|
||
alarmOptionPop.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {
|
||
@Override
|
||
public void onOptionsSelect(int position, int option2, int options3) {
|
||
if (list.size() > 0) {
|
||
mDataBinding.tv1Address.setText(list.get(position).getAddress());
|
||
}
|
||
|
||
}
|
||
});
|
||
|
||
alarmOptionPop.showAtLocation(mDataBinding.getRoot(), Gravity.BOTTOM, 0, 0);
|
||
|
||
}
|
||
});
|
||
|
||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||
activity.registerMyOnTouchListener(this);
|
||
final RegisterUser user =
|
||
Config.getInstance(getActivity()).getUser();
|
||
Map<String, String> map = new HashMap<>();
|
||
if (user != null) {
|
||
map.put("userid", user.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
map.put("app", "Advert");
|
||
map.put("class", "Advertr_an_AdvertHomeList");
|
||
map.put("sign", Md5.md5("Advert" + "Advertr_an_AdvertHomeList" + Md5.secret));
|
||
getGankList(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), 0, false);
|
||
|
||
mDataBinding.service.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
// Intent intent = new Intent(getContext(), PropertyActivity.class);
|
||
// startActivity(intent);
|
||
Intent intent = new Intent(getContext(), HistoryRecordActivity.class);
|
||
intent.putExtra("userId", user.getUserid());
|
||
intent.putExtra("userName", user.getNickname());
|
||
intent.putExtra("title", "物业服务");
|
||
startActivity(intent);
|
||
}
|
||
});
|
||
}
|
||
|
||
// TODO: Rename method, update argument and hook method into UI event
|
||
public void onButtonPressed(Uri uri) {
|
||
if (mListener != null) {
|
||
mListener.onFragmentInteraction(uri);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onAttach(Context context) {
|
||
super.onAttach(context);
|
||
if (context instanceof OnFragmentInteractionListener) {
|
||
mListener = (OnFragmentInteractionListener) context;
|
||
} else {
|
||
// throw new RuntimeException(context.toString()
|
||
// + " must implement OnFragmentInteractionListener");
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onDetach() {
|
||
super.onDetach();
|
||
mListener = null;
|
||
}
|
||
|
||
@Override
|
||
protected int getLayoutId() {
|
||
return R.layout.fragment_main;
|
||
}
|
||
|
||
@Override
|
||
protected void loadData() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onClick(View view) {
|
||
Intent intent = null;
|
||
switch (view.getId()) {
|
||
case R.id.scan:
|
||
if ((Config.getInstance(MainFragment.this.getContext()).getUser() == null)) {
|
||
intent = new Intent(MainFragment.this.getContext(), LoginActivity.class);
|
||
} else {
|
||
intent = new Intent(getActivity(), QRcodeActivity.class);
|
||
}
|
||
startActivity(intent);
|
||
break;
|
||
case R.id.entrancegurd://门禁
|
||
if ((Config.getInstance(MainFragment.this.getContext()).getUser() == null)) {
|
||
intent = new Intent(MainFragment.this.getContext(), LoginActivity.class);
|
||
} else {
|
||
intent = new Intent(getActivity(), CodeActivity.class);
|
||
}
|
||
startActivity(intent);
|
||
break;
|
||
case R.id.cargara://车库
|
||
Toast.makeText(getContext(), "功能正在开发", Toast.LENGTH_SHORT).show();
|
||
// if ((Config.getInstance(MainFragment.this.getContext()).getUser() == null)) {
|
||
// intent = new Intent(MainFragment.this.getContext(), LoginActivity.class);
|
||
// } else {
|
||
// intent = new Intent(getActivity(), CarGarageActivity.class);
|
||
// }
|
||
// startActivity(intent);
|
||
break;
|
||
case R.id.moew1:
|
||
intent = new Intent(getActivity(), MyMarketShopActivity.class);
|
||
startActivity(intent);
|
||
break;
|
||
// case R.id.moew2:
|
||
// if ((Config.getInstance(MainFragment.this.getContext()).getUser() == null)) {
|
||
// intent = new Intent(MainFragment.this.getContext(), LoginActivity.class);
|
||
// } else {
|
||
// intent = new Intent(getActivity(), NewlistActivity.class);
|
||
// }
|
||
// startActivity(intent);
|
||
// break;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* This interface must be implemented by activities that contain this
|
||
* fragment to allow an interaction in this fragment to be communicated
|
||
* to the activity and potentially other fragments contained in that
|
||
* activity.
|
||
* <p>
|
||
* See the Android Training lesson <a href=
|
||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
||
* >Communicating with Other Fragments</a> for more information.
|
||
*/
|
||
public interface OnFragmentInteractionListener {
|
||
// TODO: Update argument type and name
|
||
void onFragmentInteraction(Uri uri);
|
||
}
|
||
|
||
private void configFragments(ArrayList<Advert_carouseleEntity> user) {//banner事件
|
||
// mDataBinding.banner.removeAllViews();
|
||
mDataBinding.banner.releaseBanner();
|
||
bannerTitile = new ArrayList<>();
|
||
mBannerImages = new ArrayList<>();
|
||
for (int i = 0; i < user.size(); i++) {
|
||
Advert_carouseleEntity advertCarouseleEntity = user.get(i);
|
||
if (advertCarouseleEntity == null) {
|
||
bannerTitile.add("");
|
||
} else {
|
||
bannerTitile.add(advertCarouseleEntity.getAdvert_source());
|
||
}
|
||
mBannerImages.add(advertCarouseleEntity.getAdvert_img());
|
||
}
|
||
Banner banner = mDataBinding.banner;
|
||
banner.setBannerTitles(bannerTitile);
|
||
banner.setImageLoader(new ImageLoader() {
|
||
@Override
|
||
public void displayImage(Context context, Object path, ImageView imageView) {
|
||
Picasso.with(context).load((String) path)
|
||
.into(imageView);
|
||
}
|
||
});
|
||
banner.setImages(mBannerImages);
|
||
banner.setBannerAnimation(Transformer.Default);
|
||
banner.setDelayTime(5000);
|
||
banner.isAutoPlay(true);
|
||
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
|
||
banner.setIndicatorGravity(BannerConfig.CENTER);
|
||
banner.start();
|
||
|
||
/*mDataBinding.banner.setOnBannerClickListener(new OnBannerClickListener() {
|
||
@Override
|
||
public void OnBannerClick(int i) {
|
||
Intent intent = new Intent(getContext(), NewsDetailActivity.class);
|
||
// intent.putExtra("url", homegridentityvArrayList.get(position).getMessage_url());
|
||
// intent.putExtra("titile", homegridentityvArrayList.get(position).getMessage_title());
|
||
startActivity(intent);
|
||
}
|
||
});*/
|
||
TextPaint tp = mDataBinding.usershoptextid.getPaint();
|
||
|
||
tp.setFakeBoldText(true);
|
||
// TextPaint tp1 = mDataBinding.userommunitybutextid.getPaint();
|
||
// tp1.setFakeBoldText(true);
|
||
|
||
}
|
||
|
||
private int currentKeyboardH;
|
||
private int editTextBodyHeight;
|
||
|
||
public void updateEditTextBodyVisible(int visibility) {
|
||
mDataBinding.llComment.setVisibility(visibility);
|
||
if (View.VISIBLE == visibility) {
|
||
mDataBinding.llComment.requestFocus();
|
||
//弹出键盘
|
||
CommonUtils.showSoftInput(mDataBinding.etComment.getContext(), mDataBinding.etComment);
|
||
|
||
} else if (View.GONE == visibility) {
|
||
//隐藏键盘
|
||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||
activity.visibilyBottom(View.VISIBLE);
|
||
CommonUtils.hideSoftInput(mDataBinding.etComment.getContext(), mDataBinding.etComment);
|
||
}
|
||
}
|
||
|
||
private void setViewTreeObserver() {
|
||
final ViewTreeObserver swipeRefreshLayoutVTO = mDataBinding.myl1.getViewTreeObserver();
|
||
swipeRefreshLayoutVTO.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||
@Override
|
||
public void onGlobalLayout() {
|
||
Rect r = new Rect();
|
||
mDataBinding.myl1.getWindowVisibleDisplayFrame(r);
|
||
int statusBarH = ImmersionBar.getStatusBarHeight(getActivity());//状态栏高度
|
||
int screenH = mDataBinding.myl1.getRootView().getHeight();
|
||
if (r.top != statusBarH) {
|
||
//r.top代表的是状态栏高度,在沉浸式状态栏时r.top=0,通过getStatusBarHeight获取状态栏高度
|
||
r.top = statusBarH;
|
||
}
|
||
int keyboardH = screenH - (r.bottom - r.top);
|
||
|
||
if (keyboardH == currentKeyboardH) {//有变化时才处理,否则会陷入死循环
|
||
return;
|
||
}
|
||
currentKeyboardH = keyboardH;
|
||
editTextBodyHeight = mDataBinding.llComment.getHeight();
|
||
if (keyboardH < 150) {//说明是隐藏键盘的情况
|
||
updateEditTextBodyVisible(View.GONE);
|
||
return;
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
private void getlist(int mypage) {
|
||
RegisterUser user =
|
||
Config.getInstance(getContext()).getUser();
|
||
Map<String, String> map = new HashMap<>();
|
||
if (user != null) {
|
||
map.put("userid", user.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
map.put("app", "Goods");
|
||
map.put("type", "1");
|
||
map.put("class", "IndexGoodsLists");
|
||
map.put("page", mypage + "");
|
||
map.put("sign", Md5.md5("Goods" + "IndexGoodsLists" + Md5.secret));
|
||
getGankList2(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), mypage);
|
||
}
|
||
|
||
/**
|
||
* 获取控件左上顶点Y坐标
|
||
*
|
||
* @param view
|
||
* @return
|
||
*/
|
||
private int getCoordinateY(View view) {
|
||
int[] coordinate = new int[2];
|
||
view.getLocationOnScreen(coordinate);
|
||
return coordinate[1];
|
||
}
|
||
|
||
private void intRecycleView() {
|
||
mDataBinding.tvSendComment.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
setViewTreeObserver();
|
||
}
|
||
});
|
||
mDataBinding.scrollViewExtend.setOnTouchListener(new View.OnTouchListener() {
|
||
@Override
|
||
public boolean onTouch(View v, MotionEvent event) {
|
||
if (mDataBinding.llComment.getVisibility() == View.VISIBLE) {
|
||
updateEditTextBodyVisible(View.GONE);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
});
|
||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(baseActivity);
|
||
mDataBinding.recyView.setNestedScrollingEnabled(false);//禁止rcyc嵌套滑动
|
||
mDataBinding.recyView.setLayoutManager(linearLayoutManager);
|
||
BaseRecycleViewAdapter<DiscoveryListEntity, ItemDiscoveryBinding> baseRecycleViewAdapter = new BaseRecycleViewAdapter(getActivity(), R.layout.item_discovery);
|
||
baseRecycleViewAdapter.setHasStableIds(true);
|
||
|
||
discoveryListEntities = new ArrayList<>();
|
||
baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||
@Override
|
||
public void onBindViewHolder(Object b, final int position) {
|
||
if (!(position >= discoveryListEntities.size())) {
|
||
final ItemDiscoveryBinding homeGridAdapterItemBinding = (ItemDiscoveryBinding) b;
|
||
// homeGridAdapterItemBinding.setMyentity(discoveryListEntities.get(position));
|
||
final DiscoveryListEntity discoveryListEntity = discoveryListEntities.get(position);
|
||
homeGridAdapterItemBinding.tvNikeName.setText(discoveryListEntity.getNickname());
|
||
homeGridAdapterItemBinding.tvContent.setText(discoveryListEntity.getGoods_detail());
|
||
|
||
// Picasso.with(getActivity()).load(discoveryListEntity.getAvatar())
|
||
// .placeholder(R.mipmap.icon_default_rectangle)
|
||
// .transform(new PicassoRoundTransform())
|
||
// .into(homeGridAdapterItemBinding.imageHead);
|
||
|
||
homeGridAdapterItemBinding.ivComment.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(final View v) {
|
||
final CommentDialog commentDialog = new CommentDialog(baseActivity);
|
||
commentDialog.setShowBug(discoveryListEntity.getType() == 2);
|
||
commentDialog.setPraise(discoveryListEntity.getIs_like() == 1);
|
||
final int mBottomY = getCoordinateY(homeGridAdapterItemBinding.ivComment) + homeGridAdapterItemBinding.ivComment.getHeight();
|
||
commentDialog.setOnCommentOperateListener(new CommentDialog.OnCommentOperateListener() {
|
||
@Override
|
||
public void click(int type) {
|
||
|
||
if (type == 1 || type == 2) {
|
||
//点赞/取消
|
||
commentDialog.dismiss();
|
||
like(discoveryListEntity.getGoods_id(), position);
|
||
} else if (type == 3) {
|
||
mDataBinding.llComment.setVisibility(View.VISIBLE);
|
||
mDataBinding.etComment.requestFocus();
|
||
mDataBinding.etComment.setHint("评论");
|
||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||
KeyboardUtil.showSoftInput(getContext());
|
||
activity.visibilyBottom(View.GONE);
|
||
commentPosition = position;
|
||
commentDialog.dismiss();
|
||
mDataBinding.etComment.setText("");
|
||
homeGridAdapterItemBinding.ivComment.postDelayed(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
int y = getCoordinateY(mDataBinding.llComment) - 20;
|
||
//评论时滑动到对应item底部和输入框顶部对齐
|
||
mDataBinding.scrollViewExtend.smoothScrollBy(0, mBottomY - y);
|
||
}
|
||
}, 300);
|
||
|
||
|
||
} else if (type == 4) {
|
||
// addCart(discoveryListEntity.getGoods_id(),discoveryListEntity.)
|
||
getGoodsDetail(discoveryListEntity.getGoods_id(), discoveryListEntity, type);
|
||
commentDialog.dismiss();
|
||
|
||
} else if (type == 5) {
|
||
getGoodsDetail(discoveryListEntity.getGoods_id(), discoveryListEntity, type);
|
||
commentDialog.dismiss();
|
||
}
|
||
}
|
||
});
|
||
new XPopup.Builder(baseActivity).hasShadowBg(false).atView(homeGridAdapterItemBinding.ivComment).asCustom(commentDialog)
|
||
.show();
|
||
|
||
}
|
||
});
|
||
|
||
|
||
if (discoveryListEntity.getLike().isEmpty()) {
|
||
homeGridAdapterItemBinding.tvLike.setVisibility(View.GONE);
|
||
} else {
|
||
homeGridAdapterItemBinding.tvLike.setVisibility(View.VISIBLE);
|
||
StringBuilder likeString = new StringBuilder();
|
||
for (int i = 0; i < discoveryListEntity.getLike().size(); i++) {
|
||
if (i != 0 && i != discoveryListEntity.getLike().size() - 1) {
|
||
likeString.append(",");
|
||
}
|
||
likeString.append(discoveryListEntity.getLike().get(i).getNickname());
|
||
|
||
}
|
||
homeGridAdapterItemBinding.tvLike.setText(likeString.toString());
|
||
|
||
homeGridAdapterItemBinding.tvTime.setText(DateUtils.getDate(discoveryListEntity.getCtime()));
|
||
|
||
}
|
||
if (discoveryListEntity.getDis_content().isEmpty()) {
|
||
homeGridAdapterItemBinding.rvComment.setVisibility(View.GONE);
|
||
} else {
|
||
homeGridAdapterItemBinding.rvComment.setVisibility(View.VISIBLE);
|
||
FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(), 1);
|
||
mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
||
mgr.setSmoothScrollbarEnabled(true);
|
||
homeGridAdapterItemBinding.rvComment.setLayoutManager(mgr);
|
||
BaseRecycleViewAdapter<DiscoveryListEntity.Dis_content, ItemCommentBinding> baseRecycleViewAdapter = new BaseRecycleViewAdapter(getActivity(), R.layout.item_comment);
|
||
homeGridAdapterItemBinding.rvComment.setAdapter(baseRecycleViewAdapter);
|
||
final ArrayList<DiscoveryListEntity.Dis_content> dis_content = discoveryListEntity.getDis_content();
|
||
baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||
@Override
|
||
public void onBindViewHolder(Object b, int position) {
|
||
ItemCommentBinding itemCommentBinding = (ItemCommentBinding) b;
|
||
itemCommentBinding.tvName.setText(dis_content.get(position).getNickname() + ": ");
|
||
itemCommentBinding.tvInfo.setText(dis_content.get(position).getContents());
|
||
if (dis_content.get(position).getReply().isEmpty()) {
|
||
itemCommentBinding.llHf.setVisibility(View.GONE);
|
||
|
||
} else {
|
||
itemCommentBinding.llHf.setVisibility(View.VISIBLE);
|
||
itemCommentBinding.tvName2.setText(discoveryListEntity.getNickname());
|
||
itemCommentBinding.tvInfo2.setText("回复");
|
||
itemCommentBinding.tvName3.setText(dis_content.get(position).getNickname() + ":");
|
||
itemCommentBinding.tvInfo3.setText(dis_content.get(position).getReply());
|
||
|
||
}
|
||
}
|
||
});
|
||
baseRecycleViewAdapter.setData(dis_content);
|
||
|
||
}
|
||
|
||
|
||
RequestOptions requestOptions = new RequestOptions();
|
||
requestOptions.placeholder(R.mipmap.icon_default_rectangle);
|
||
requestOptions.error(R.mipmap.icon_default_rectangle);
|
||
|
||
Glide.with(getContext()).load(discoveryListEntity.getAvatar())
|
||
.apply(requestOptions)
|
||
.into(homeGridAdapterItemBinding.imageHead);
|
||
homeGridAdapterItemBinding.imageHead.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
Intent intent = new Intent(getContext(), HistoryRecordActivity.class);
|
||
intent.putExtra("userId", discoveryListEntity.getUserid());
|
||
intent.putExtra("userName", discoveryListEntity.getNickname());
|
||
intent.putExtra("title", discoveryListEntity.getNickname());
|
||
startActivity(intent);
|
||
}
|
||
});
|
||
ArrayList<ImageInfo> imageInfos = new ArrayList<>();
|
||
|
||
if (discoveryListEntity.getPic().size() > 0) {
|
||
|
||
// Log.e("pic", discoveryListEntity.getPic().get(0));
|
||
for (int i = 0; i < discoveryListEntity.getPic().size(); i++) {
|
||
if (discoveryListEntity.getPic().get(i).endsWith(".mp4") || discoveryListEntity.getPic().get(i).endsWith(".avi")) {
|
||
ImageInfo imageInfo = new ImageInfo();
|
||
imageInfo.setType(2);
|
||
imageInfo.setBigImageUrl(discoveryListEntity.getPic().get(i));
|
||
imageInfo.setThumbnailUrl(discoveryListEntity.getPic().get(i));
|
||
imageInfos.add(imageInfo);
|
||
} else {
|
||
ImageInfo imageInfo = new ImageInfo();
|
||
imageInfo.setType(1);
|
||
imageInfo.setBigImageUrl(discoveryListEntity.getPic().get(i));
|
||
imageInfo.setThumbnailUrl(discoveryListEntity.getPic().get(i));
|
||
imageInfos.add(imageInfo);
|
||
}
|
||
|
||
}
|
||
|
||
} else if (!TextUtils.isEmpty(discoveryListEntity.getThumb())){
|
||
ImageInfo imageInfo = new ImageInfo();
|
||
imageInfo.setType(1);
|
||
imageInfo.setBigImageUrl(discoveryListEntity.getThumb());
|
||
imageInfo.setThumbnailUrl(discoveryListEntity.getThumb());
|
||
imageInfos.add(imageInfo);
|
||
}
|
||
homeGridAdapterItemBinding.nineGrid.setAdapter(new NineGridViewClickAdapter(getContext(), imageInfos));
|
||
}
|
||
}
|
||
});
|
||
mDataBinding.recyView.setAdapter(baseRecycleViewAdapter);
|
||
|
||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||
mDataBinding.tvSendComment.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
|
||
if (commentPosition != -1) {
|
||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||
CommonUtils.hideSoftInput(getContext(), mDataBinding.etComment);
|
||
mDataBinding.llComment.setVisibility(View.GONE);
|
||
activity.visibilyBottom(View.VISIBLE);
|
||
Log.e("xxx", discoveryListEntities.get(commentPosition).getGoods_id());
|
||
comment(discoveryListEntities.get(commentPosition).getGoods_id(), commentPosition, "", mDataBinding.etComment.getText().toString());
|
||
}
|
||
}
|
||
});
|
||
}
|
||
private int commentPosition = -1;
|
||
@Override
|
||
public boolean onTouch(MotionEvent ev) {
|
||
switch (ev.getAction()) {
|
||
|
||
case MotionEvent.ACTION_DOWN:
|
||
//点击空白处隐藏键盘,隐藏输入框相关
|
||
if (getActivity().getCurrentFocus() != null && getActivity().getCurrentFocus().getId() == R.id.tv_send_comment) {
|
||
return false;
|
||
}
|
||
boolean b = UtilHelpers.hideKeyboard(ev, getActivity().getCurrentFocus(), getActivity());
|
||
if (b) {
|
||
CommonUtils.hideSoftInput(mDataBinding.etComment.getContext(), mDataBinding.etComment);
|
||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||
activity.visibilyBottom(View.VISIBLE);
|
||
mDataBinding.llComment.setVisibility(View.GONE);
|
||
}
|
||
break;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
private void getGoodsDetail(final String goodsId, final DiscoveryListEntity entity, final int goodtype) {
|
||
final RegisterUser user =
|
||
Config.getInstance(getContext()).getUser();
|
||
Map<String, String> map = new HashMap<>();
|
||
if (user != null) {
|
||
map.put("userid", user.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
map.put("app", "Goods");
|
||
map.put("class", "GoodsInfo");
|
||
map.put("goods_id", goodsId);
|
||
map.put("sign", Md5.md5("Goods" + "GoodsInfo" + Md5.secret));
|
||
progressDialog.setMessage("获取信息中");
|
||
progressDialog.setCancelable(false);
|
||
mGankLoader = new Loader();
|
||
Subscription subscription = mGankLoader.getMovie(ApiConfig.BASE_URL, map)
|
||
.subscribe(new Action1<Resultcode>() {
|
||
@Override
|
||
public void call(Resultcode resultcode) {
|
||
progressDialog.dismiss();
|
||
if (resultcode.status == 0) {
|
||
Gson gs = new Gson();
|
||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||
String s = gs.toJson(adta);
|
||
|
||
try {
|
||
|
||
JSONObject jsonObject = new JSONObject(s);
|
||
org.json.JSONArray array = jsonObject.getJSONArray("info");
|
||
final Type type = new TypeToken<ArrayList<GoodsDetailEntity>>() {
|
||
}.getType();
|
||
ArrayList<GoodsDetailEntity> o = gs.fromJson(array.toString(), type);
|
||
|
||
GoodsInfoDialog goodsInfoDialog = new GoodsInfoDialog(baseActivity, entity, o);
|
||
goodsInfoDialog.setOnConfirmListener(new GoodsInfoDialog.OnGoodsSelectPropertyListener() {
|
||
@Override
|
||
public void onSelect(String code, int num) {
|
||
if (goodtype == 4) {
|
||
Intent intent = new Intent(baseActivity, SettleActivity.class);
|
||
intent.putExtra("goodsType", 1);
|
||
intent.putExtra("goods_id", goodsId);
|
||
intent.putExtra("product_code", code);
|
||
intent.putExtra("sale_num", num + "");
|
||
startActivity(intent);
|
||
} else if (goodtype == 5) {
|
||
addCart(goodsId, code, num + "");
|
||
}
|
||
|
||
}
|
||
});
|
||
new XPopup.Builder(baseActivity).asCustom(goodsInfoDialog).show();
|
||
|
||
} catch (JSONException e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
} else {
|
||
baseActivity.setToast(resultcode.msg);
|
||
}
|
||
}
|
||
}, new Action1<Throwable>() {
|
||
@Override
|
||
public void call(Throwable throwable) {
|
||
progressDialog.dismiss();
|
||
baseActivity.setToast(2, "获取信息失败");
|
||
throwable.printStackTrace();
|
||
}
|
||
});
|
||
baseActivity.addSubscription(subscription);
|
||
}
|
||
|
||
private void comment(String goodsId, final int position, String reply_id, final String content) {
|
||
final RegisterUser user =
|
||
Config.getInstance(getContext()).getUser();
|
||
Map<String, String> map = new HashMap<>();
|
||
if (user != null) {
|
||
map.put("userid", user.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
map.put("app", "Goods");
|
||
map.put("class", "DisGoods");
|
||
map.put("goods_id", goodsId);
|
||
if (!TextUtils.isEmpty(reply_id)) {
|
||
map.put("reply_id", reply_id);
|
||
}
|
||
|
||
map.put("contents", content);
|
||
map.put("sign", Md5.md5("Goods" + "DisGoods" + Md5.secret));
|
||
progressDialog.setMessage("提交中");
|
||
progressDialog.setCancelable(false);
|
||
// progressDialog.show();
|
||
|
||
mGankLoader = new Loader();
|
||
Subscription subscription = mGankLoader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||
|
||
|
||
@Override
|
||
public void call(Resultcode resultcode) {
|
||
|
||
progressDialog.dismiss();
|
||
if (!(resultcode.status == 0)) {
|
||
baseActivity.setToast(1, resultcode.msg);
|
||
}
|
||
if (resultcode.status == 0) {
|
||
String nickname = user.getNickname();
|
||
BaseRecycleViewAdapter adapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||
DiscoveryListEntity.Dis_content dis_content = new DiscoveryListEntity.Dis_content();
|
||
dis_content.setContents(content);
|
||
dis_content.setNickname(nickname);
|
||
dis_content.setReply("");
|
||
DiscoveryListEntity discoveryListEntity = discoveryListEntities.get(position);
|
||
ArrayList<DiscoveryListEntity.Dis_content> dis_content1 = discoveryListEntity.getDis_content();
|
||
dis_content1.add(dis_content);
|
||
|
||
discoveryListEntity.setDis_content(dis_content1);
|
||
adapter.upDateOne(position,discoveryListEntity);
|
||
// BaseRecycleViewAdapter adapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||
// if (discoveryListEntities.get(position).getDis_content().isEmpty()) {
|
||
// DiscoveryListEntity.Dis_content dis_content = new DiscoveryListEntity.Dis_content();
|
||
// dis_content.setContents(content);
|
||
//
|
||
// }
|
||
//
|
||
// adapter.upDateOne(position, discoveryListEntities.get(position));
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}, new Action1<Throwable>() {
|
||
@Override
|
||
public void call(Throwable throwable) {
|
||
progressDialog.dismiss();
|
||
baseActivity.setToast(2, "提交失败");
|
||
throwable.printStackTrace();
|
||
}
|
||
});
|
||
|
||
baseActivity.addSubscription(subscription);
|
||
|
||
}
|
||
|
||
// public void intRecycleHorization(final ArrayList<Advertorial_listEntity> advertorial_list) {
|
||
//
|
||
// FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(), 1);
|
||
// mgr.setOrientation(FullyGridLayoutManager.HORIZONTAL);
|
||
// mgr.setSmoothScrollbarEnabled(true);
|
||
// // mDataBinding.fragmentRecyclerviewHorization.setLayoutManager(mgr);
|
||
// baseRecycleViewAdapterh = new BaseRecycleViewAdapter(getActivity(), R.layout.fragment_recyclerview_horization_item);
|
||
//
|
||
// baseRecycleViewAdapterh.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||
// @Override
|
||
// public void onBindViewHolder(Object b, final int position) {
|
||
// FragmentRecyclerviewHorizationItemBinding homeGridAdapterItemBinding = (FragmentRecyclerviewHorizationItemBinding) b;
|
||
// homeGridAdapterItemBinding.setMyentity(advertorial_list.get(position));
|
||
// if (advertorial_list.get(position).getAdvertorial_picture_array().size() > 0) {
|
||
// Picasso.with(getActivity()).load(advertorial_list.get(position).getAdvertorial_picture_array().get(0))
|
||
// .placeholder(R.mipmap.icon_default_rectangle)
|
||
// .transform(new PicassoRoundTransform())
|
||
// .into(homeGridAdapterItemBinding.imageView);
|
||
// }
|
||
// homeGridAdapterItemBinding.fragmentRecyclerviewHorizationItem.setOnClickListener(new View.OnClickListener() {
|
||
// @Override
|
||
// public void onClick(View view) {
|
||
// Intent intent = new Intent(getActivity(), NewsDetailActivity.class);
|
||
// intent.putExtra("url", advertorial_list.get(position).getAdvertorial_url());
|
||
// intent.putExtra("titile", advertorial_list.get(position).getAdvertorial_title());
|
||
// startActivity(intent);
|
||
// /* Intent intent=new Intent(getActivity(),CommodityActivity.class);
|
||
// intent.putExtra("homegridentity",advertorial_list.get(position));
|
||
// startActivity(intent);*/
|
||
// }
|
||
// });
|
||
//
|
||
// }
|
||
// });
|
||
//
|
||
// mDataBinding.fragmentRecyclerviewHorization.setAdapter(baseRecycleViewAdapterh);
|
||
// baseRecycleViewAdapterh.setData(advertorial_list);
|
||
//
|
||
//
|
||
// }
|
||
|
||
// private void intRecycleVerization(final ArrayList<Message_listEntity> message_list) {
|
||
// mDataBinding.myversion.setVisibility(View.VISIBLE);
|
||
// FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(), 1);
|
||
// mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
||
// mgr.setSmoothScrollbarEnabled(true);
|
||
// mDataBinding.recyView.setLayoutManager(mgr);
|
||
// baseRecycleViewAdapterv = new BaseRecycleViewAdapter(getActivity(), R.layout.fragment_recyclerview_vorization_item);
|
||
//
|
||
// baseRecycleViewAdapterv.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||
// @Override
|
||
// public void onBindViewHolder(Object b, final int position) {
|
||
// if (!(position >= message_list.size())) {
|
||
// FragmentRecyclerviewVorizationItemBinding homeGridAdapterItemBinding = (FragmentRecyclerviewVorizationItemBinding) b;
|
||
// homeGridAdapterItemBinding.setMyentity(message_list.get(position));
|
||
//
|
||
// Picasso.with(getActivity()).load(message_list.get(position).getMessage_picture())
|
||
// .placeholder(R.mipmap.icon_default_rectangle)
|
||
// .transform(new PicassoRoundTransform())
|
||
// .into(homeGridAdapterItemBinding.imageView);
|
||
// homeGridAdapterItemBinding.fragmentRecyclerviewVorizationItem.setOnClickListener(new View.OnClickListener() {
|
||
// @Override
|
||
// public void onClick(View view) {
|
||
//
|
||
//
|
||
// Intent intent = new Intent(getActivity(), NewsDetailActivity.class);
|
||
// intent.putExtra("url", message_list.get(position).getMessage_url());
|
||
// intent.putExtra("titile", message_list.get(position).getMessage_title());
|
||
// startActivity(intent);
|
||
// }
|
||
// });
|
||
// }
|
||
//
|
||
// }
|
||
// });
|
||
//
|
||
// mDataBinding.recyView.setAdapter(baseRecycleViewAdapterv);
|
||
// baseRecycleViewAdapterv.setData(message_list);
|
||
//
|
||
// }
|
||
|
||
|
||
//如果你需要考虑更好的体验,可以这么操作
|
||
@Override
|
||
public void onStart() {
|
||
super.onStart();
|
||
//开始轮播
|
||
mDataBinding.banner.startAutoPlay();
|
||
}
|
||
|
||
@Override
|
||
public void onStop() {
|
||
super.onStop();
|
||
//结束轮播
|
||
mDataBinding.banner.stopAutoPlay();
|
||
}
|
||
|
||
private int page = 1;
|
||
|
||
private OnRefreshLoadMoreListener onrefalshlister = new OnRefreshLoadMoreListener() {
|
||
@Override
|
||
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
||
page = 1;
|
||
getlist(page);
|
||
}
|
||
|
||
@Override
|
||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||
getlist(1);
|
||
|
||
}
|
||
|
||
|
||
};
|
||
|
||
private void getGankList2(String myurl, Map<String, String> map, String msg, final int requstecode) {
|
||
progressDialog.setMessage(msg);
|
||
progressDialog.setCancelable(false);
|
||
// if (page>1){
|
||
// progressDialog.show();
|
||
// }
|
||
|
||
|
||
mGankLoader = new Loader();
|
||
Subscription subscription = mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
||
|
||
|
||
@Override
|
||
public void call(Resultcode resultcode) {
|
||
|
||
mDataBinding.taobaoRefreshLayout.finishRefresh();
|
||
mDataBinding.taobaoRefreshLayout.finishLoadMore();
|
||
progressDialog.dismiss();
|
||
if (!(resultcode.status == 0)) {
|
||
baseActivity.setToast(1, resultcode.msg);
|
||
}
|
||
if (resultcode.status == 0) {
|
||
// intRecycleView();
|
||
Gson gs = new Gson();
|
||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||
String s = gs.toJson(adta);
|
||
try {
|
||
JSONObject jsonObject = new JSONObject(s);
|
||
org.json.JSONArray array = jsonObject.getJSONArray("info");
|
||
Type type = new TypeToken<ArrayList<DiscoveryListEntity>>() {
|
||
}.getType();
|
||
ArrayList<DiscoveryListEntity> o = new Gson().fromJson(array.toString(), type);
|
||
if (page == 1) {
|
||
|
||
discoveryListEntities.clear();
|
||
discoveryListEntities.addAll(o);
|
||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||
page++;
|
||
} else {
|
||
discoveryListEntities.addAll(o);
|
||
|
||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||
// Log.e("sizi", discoveryListEntities.size() + "");
|
||
// int count = jsonObject.getInt("count");
|
||
if (o.isEmpty()) {
|
||
mDataBinding.taobaoRefreshLayout.finishLoadMoreWithNoMoreData();
|
||
} else {
|
||
|
||
page++;
|
||
|
||
}
|
||
}
|
||
|
||
|
||
} catch (Exception e) {
|
||
e.fillInStackTrace();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}, new Action1<Throwable>() {
|
||
@Override
|
||
public void call(Throwable throwable) {
|
||
progressDialog.dismiss();
|
||
mDataBinding.taobaoRefreshLayout.finishRefresh();
|
||
mDataBinding.taobaoRefreshLayout.finishLoadMore();
|
||
baseActivity.setToast(2, getString(R.string.getdatafailure));
|
||
throwable.printStackTrace();
|
||
}
|
||
});
|
||
|
||
baseActivity.addSubscription(subscription);
|
||
}
|
||
|
||
private void getGankList(String myurl, Map<String, String> map, String msg, final int requstecode, final boolean isshowdilaog) {
|
||
mGankLoader = new Loader();
|
||
Subscription subscription = mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
||
@Override
|
||
public void call(Resultcode resultcode) {
|
||
// mDataBinding.taobaoRefreshLayout.finishRefresh();
|
||
if (!(resultcode.status == 0)) {
|
||
baseActivity.setToast(1, resultcode.msg);
|
||
}
|
||
if (resultcode.status == 0) {
|
||
// baseActivity.setToast(0,resultcode.msg);
|
||
if (requstecode == 0) {
|
||
Gson gs = new Gson();
|
||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||
String s = gs.toJson(adta);
|
||
MainF1Entity user = gs.fromJson(s, MainF1Entity.class);//把JSON字符串转为对象
|
||
configFragments(user.getAdvert_carousel());
|
||
//intRecycleHorization(user.getAdvertorial_list());
|
||
// intRecycleVerization(user.getMessage_list());
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}, new Action1<Throwable>() {
|
||
@Override
|
||
public void call(Throwable throwable) {
|
||
// mDataBinding.taobaoRefreshLayout.finishRefresh();
|
||
baseActivity.setToast(2, getString(R.string.getdatafailure));
|
||
throwable.printStackTrace();
|
||
}
|
||
});
|
||
|
||
baseActivity.addSubscription(subscription);
|
||
}
|
||
|
||
private void like(String goodsId, final int position) {
|
||
final RegisterUser user =
|
||
Config.getInstance(getContext()).getUser();
|
||
Map<String, String> map = new HashMap<>();
|
||
if (user != null) {
|
||
map.put("userid", user.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
map.put("app", "Goods");
|
||
map.put("class", "AddUp");
|
||
map.put("goods_id", goodsId);
|
||
map.put("sign", Md5.md5("Goods" + "AddUp" + Md5.secret));
|
||
progressDialog.setMessage("提交中");
|
||
progressDialog.setCancelable(false);
|
||
// progressDialog.show();
|
||
|
||
mGankLoader = new Loader();
|
||
Subscription subscription = mGankLoader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||
|
||
|
||
@Override
|
||
public void call(Resultcode resultcode) {
|
||
|
||
progressDialog.dismiss();
|
||
if (!(resultcode.status == 0)) {
|
||
baseActivity.setToast(1, resultcode.msg);
|
||
}
|
||
if (resultcode.status == 0) {
|
||
BaseRecycleViewAdapter adapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||
if (discoveryListEntities.get(position).getIs_like() == 1) {
|
||
discoveryListEntities.get(position).setIs_like(0);
|
||
ArrayList<DiscoveryListEntity.Like> like = discoveryListEntities.get(position).getLike();
|
||
for (int i = 0; i < like.size(); i++) {
|
||
if (user.getUserid().equals(like.get(i).getUserid())) {
|
||
like.remove(i);
|
||
break;
|
||
}
|
||
}
|
||
discoveryListEntities.get(position).setLike(like);
|
||
} else {
|
||
discoveryListEntities.get(position).setIs_like(1);
|
||
DiscoveryListEntity.Like like = new DiscoveryListEntity.Like();
|
||
like.setNickname(user.getNickname());
|
||
like.setUserid(user.getUserid());
|
||
discoveryListEntities.get(position).getLike().add(like);
|
||
}
|
||
|
||
adapter.upDateOne(position, discoveryListEntities.get(position));
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}, new Action1<Throwable>() {
|
||
@Override
|
||
public void call(Throwable throwable) {
|
||
progressDialog.dismiss();
|
||
baseActivity.setToast(2, "提交失败");
|
||
throwable.printStackTrace();
|
||
}
|
||
});
|
||
|
||
baseActivity.addSubscription(subscription);
|
||
|
||
}
|
||
|
||
private void addCart(String goods_id, String product_code, String goodsNum) {
|
||
RegisterUser user =
|
||
Config.getInstance(getContext()).getUser();
|
||
Map<String, String> map = new HashMap<>();
|
||
if (user != null) {
|
||
map.put("userid", user.getUserid());
|
||
} else {
|
||
map.put("userid", 0 + "");
|
||
}
|
||
map.put("app", "Goods");
|
||
map.put("class", "AddCart");
|
||
map.put("goods_id", goods_id);
|
||
map.put("product_code", product_code);
|
||
map.put("num", goodsNum);
|
||
map.put("sign", Md5.md5("Goods" + "AddCart" + Md5.secret));
|
||
progressDialog.setMessage("提交中");
|
||
progressDialog.setCancelable(false);
|
||
mGankLoader = new Loader();
|
||
Subscription subscribe = mGankLoader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||
@Override
|
||
public void call(Resultcode resultcode) {
|
||
progressDialog.dismiss();
|
||
if (resultcode.status == 0) {
|
||
baseActivity.setToast(0, "成功加入购物车");
|
||
} else {
|
||
baseActivity.setToast(3, resultcode.msg);
|
||
}
|
||
}
|
||
}, new Action1<Throwable>() {
|
||
@Override
|
||
public void call(Throwable throwable) {
|
||
progressDialog.dismiss();
|
||
baseActivity.setToast(2, "提交失败");
|
||
throwable.printStackTrace();
|
||
}
|
||
});
|
||
baseActivity.addSubscription(subscribe);
|
||
}
|
||
} |