397 lines
14 KiB
Java
397 lines
14 KiB
Java
package com.sl.house_property;
|
|
|
|
import android.app.ProgressDialog;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.support.v4.app.Fragment;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
|
|
import com.dalong.refreshlayout.OnRefreshListener;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.internal.LinkedTreeMap;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.sl.house_property.f1.AddcararageIttemActivity;
|
|
import com.sl.house_property.user.MyMarketShopActivity;
|
|
import com.sl.house_property.user.MyshopEditAcitivity;
|
|
import com.sl.house_property.databinding.FragmentF1recyclerviewVorizationItemBinding;
|
|
import com.sl.house_property.databinding.FragmentMain1Binding;
|
|
import com.squareup.picasso.Picasso;
|
|
import com.squareup.picasso.Target;
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
import java.lang.reflect.Type;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import adapter.BaseRecycleViewAdapter;
|
|
import entity.Advertorial_listEntity;
|
|
import entity.RegisterUser;
|
|
import my_loader.Loader;
|
|
import my_loader.Resultcode;
|
|
import my_view.tao_bao_refresh.FullyGridLayoutManager;
|
|
import tools.Config;
|
|
import tools.PicassoRoundTransform;
|
|
import http.ApiConfig;
|
|
import rx.Subscription;
|
|
import rx.functions.Action1;
|
|
import utils.Md5;
|
|
|
|
|
|
/**
|
|
* 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 Main1Fragment extends BaseFragment<FragmentMain1Binding> implements View.OnClickListener {
|
|
// 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 OnFragmentInteractionListener mListener;
|
|
private ProgressDialog progressDialog;
|
|
|
|
private boolean isRefrash = false;
|
|
|
|
private int myeditcode = 1000;
|
|
|
|
|
|
private Loader mGankLoader;
|
|
private ArrayList<Advertorial_listEntity> homegridentityvArrayList;
|
|
public String imgme = null;
|
|
|
|
public Main1Fragment() {
|
|
// 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 Main1Fragment newInstance(String param1, String param2) {
|
|
Main1Fragment fragment = new Main1Fragment();
|
|
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
|
|
protected void onCreateVew(final LayoutInflater inflater, Bundle savedInstanceState) {
|
|
super.onCreateVew(inflater, savedInstanceState);
|
|
|
|
baseActivity = (BaseActivity) getActivity();
|
|
progressDialog = new ProgressDialog(baseActivity);
|
|
/* mylist=new ArrayList<>();
|
|
getGankList(ApiConfig.GETHOMEBANNER,new HashMap<String, String>(),getString(R.string.loading),0);*/
|
|
baseActivity = (BaseActivity) getActivity();
|
|
progressDialog = new ProgressDialog(baseActivity);
|
|
// progressDialog.show();
|
|
// progressDialog.setMessage(getActivity().getString(R.string.loading));
|
|
mDataBinding.taobaoRefreshLayout.setOnRefreshListener(onrefalshlister);
|
|
|
|
intRecycleVerization();
|
|
getlist(0);
|
|
mDataBinding.fabu.setOnClickListener(this);
|
|
mDataBinding.liulan.setOnClickListener(this);
|
|
mDataBinding.taobaoRefreshLayout.setAutoRefresh(true);
|
|
}
|
|
|
|
@Override
|
|
protected void loadData() {
|
|
getlist(0);
|
|
}
|
|
|
|
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", "Advertorial");
|
|
map.put("class", "Advertorial_an_AdvertorialHomeList");
|
|
map.put("sign", Md5.md5("Advertorial" + "Advertorial_an_AdvertorialHomeList" + Md5.secret));
|
|
getGankList(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), mypage);
|
|
}
|
|
|
|
// 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_main1;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
Intent intent = null;
|
|
switch (view.getId()) {
|
|
case R.id.fabu:
|
|
intent = null;
|
|
if ((Config.getInstance(Main1Fragment.this.getContext()).getUser() == null)) {
|
|
intent = new Intent(Main1Fragment.this.getContext(), LoginActivity.class);
|
|
startActivity(intent);
|
|
} else {
|
|
intent = new Intent(Main1Fragment.this.getContext(), MyshopEditAcitivity.class);
|
|
startActivityForResult(intent, myeditcode);
|
|
}
|
|
break;
|
|
case R.id.liulan:
|
|
intent = new Intent(getActivity(), MyMarketShopActivity.class);
|
|
intent.putExtra("type", 1);
|
|
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 in+formation.
|
|
*/
|
|
public interface OnFragmentInteractionListener {
|
|
// TODO: Update argument type and name
|
|
void onFragmentInteraction(Uri uri);
|
|
}
|
|
|
|
private OnRefreshListener onrefalshlister = new OnRefreshListener() {
|
|
@Override
|
|
public void onRefresh() {
|
|
getlist(0);
|
|
//getGankList(ApiConfig.GETHOMEBANNER,new HashMap<String, String>(),getString(R.string.loading),0);
|
|
mDataBinding.taobaoRefreshLayout.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
mDataBinding.taobaoRefreshLayout.stopRefresh(true);
|
|
}
|
|
}, 10000);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onLoadMore() {
|
|
mDataBinding.taobaoRefreshLayout.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
mDataBinding.taobaoRefreshLayout.stopLoadMore(true);
|
|
}
|
|
}, 1000);
|
|
|
|
}
|
|
};
|
|
|
|
private void intRecycleVerization() {
|
|
FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(), 1);
|
|
mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
|
mgr.setSmoothScrollbarEnabled(true);
|
|
mDataBinding.recyView.setLayoutManager(mgr);
|
|
BaseRecycleViewAdapter baseRecycleViewAdapter = new BaseRecycleViewAdapter(getActivity(), R.layout.fragment_f1recyclerview_vorization_item);
|
|
homegridentityvArrayList = new ArrayList<>();
|
|
baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
|
@Override
|
|
public void onBindViewHolder(Object b, final int position) {
|
|
if (!(position >= homegridentityvArrayList.size())) {
|
|
FragmentF1recyclerviewVorizationItemBinding homeGridAdapterItemBinding = (FragmentF1recyclerviewVorizationItemBinding) b;
|
|
homeGridAdapterItemBinding.setMyentity(homegridentityvArrayList.get(position));
|
|
if (homegridentityvArrayList.get(position).getAdvertorial_picture_array().size() > 0)
|
|
Picasso.with(getActivity()).load(homegridentityvArrayList.get(position).getAdvertorial_picture_array().get(0))
|
|
.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", homegridentityvArrayList.get(position).getAdvertorial_url());
|
|
intent.putExtra("titile", homegridentityvArrayList.get(position).getAdvertorial_title());
|
|
startActivity(intent);
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
mDataBinding.recyView.setAdapter(baseRecycleViewAdapter);
|
|
baseRecycleViewAdapter.setData(homegridentityvArrayList);
|
|
|
|
mDataBinding.recyView.setFocusableInTouchMode(false); //设置不需要焦点
|
|
mDataBinding.recyView.requestFocus(); //设置焦点不需要
|
|
}
|
|
|
|
|
|
private void addRecycleVerization(ArrayList<Advertorial_listEntity> lsit) {
|
|
mDataBinding.maincontrol.setVisibility(View.VISIBLE);
|
|
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
|
|
|
homegridentityvArrayList = lsit;
|
|
baseRecycleViewAdapter.setData(homegridentityvArrayList);
|
|
|
|
}
|
|
|
|
|
|
private void getGankList(String myurl, Map<String, String> map, String msg, final int requstecode) {
|
|
progressDialog.setMessage(msg);
|
|
progressDialog.setCancelable(false);
|
|
// progressDialog.show();
|
|
|
|
mGankLoader = new Loader();
|
|
Subscription subscription = mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
|
|
|
|
|
@Override
|
|
public void call(Resultcode resultcode) {
|
|
mDataBinding.taobaoRefreshLayout.stopRefresh(true);
|
|
mDataBinding.taobaoRefreshLayout.stopLoadMore(true);
|
|
progressDialog.dismiss();
|
|
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);
|
|
|
|
ArrayList<Advertorial_listEntity> list = null;
|
|
try {
|
|
JSONObject jsonObject = new JSONObject(s);
|
|
org.json.JSONArray array1 = jsonObject.getJSONArray("advert_info");
|
|
if (array1.length() > 0) {
|
|
String img = array1.getJSONObject(0).optString("advert_img");
|
|
configTopImage(img);
|
|
imgme = img;
|
|
|
|
}
|
|
org.json.JSONArray array = jsonObject.getJSONArray("advertorial_list");
|
|
Type type = new TypeToken<ArrayList<Advertorial_listEntity>>() {
|
|
}.getType();
|
|
list = new Gson().fromJson(array.toString(), type);
|
|
addRecycleVerization(list);
|
|
|
|
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}, new Action1<Throwable>() {
|
|
@Override
|
|
public void call(Throwable throwable) {
|
|
progressDialog.dismiss();
|
|
|
|
baseActivity.setToast(2, getString(R.string.getdatafailure));
|
|
throwable.printStackTrace();
|
|
}
|
|
});
|
|
|
|
baseActivity.addSubscription(subscription);
|
|
}
|
|
|
|
private Target target = new Target() {
|
|
@Override
|
|
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
|
|
Drawable drawable = new BitmapDrawable(bitmap);
|
|
mDataBinding.mylilin.setBackground(drawable);
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onBitmapFailed(Drawable errorDrawable) {
|
|
}
|
|
|
|
@Override
|
|
public void onPrepareLoad(Drawable placeHolderDrawable) {
|
|
}
|
|
};
|
|
|
|
private void configTopImage(String img) {
|
|
Picasso
|
|
.with(getActivity())
|
|
.load(img)
|
|
/*.load("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3896007654,1833866819&fm=200&gp=0.jpg")*/
|
|
.into(target);
|
|
|
|
|
|
}
|
|
|
|
// @Override
|
|
// public void onResume() {
|
|
// super.onResume();
|
|
// if(isRefrash){
|
|
// getlist(0);
|
|
// }else{
|
|
// isRefrash = true;
|
|
// }
|
|
// }
|
|
|
|
} |