396 lines
15 KiB
Java
396 lines
15 KiB
Java
package com.sl.house_property;
|
|
|
|
import android.app.ProgressDialog;
|
|
import android.content.Context;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.support.v4.app.Fragment;
|
|
import android.view.LayoutInflater;
|
|
import android.widget.AbsListView;
|
|
import android.widget.ListView;
|
|
import android.widget.RadioButton;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.internal.LinkedTreeMap;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.sl.house_property.databinding.FragmentMain3Binding;
|
|
|
|
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 entity.Serve_categoryeNTITY;
|
|
import entity.SimpleEntity;
|
|
import my_loader.Loader;
|
|
import my_loader.Resultcode;
|
|
import my_view.two_recy_view.adapter.LeftAdapter;
|
|
import my_view.two_recy_view.adapter.RightAdapter;
|
|
import my_view.two_recy_view.model.LeftMenu;
|
|
import my_view.two_recy_view.model.RightMenu;
|
|
import my_view.two_recy_view.model.RightMenuItem;
|
|
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 Main3Fragment extends BaseFragment<FragmentMain3Binding> {
|
|
// 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;
|
|
private int leftcount=10;
|
|
private int rightcount=15;
|
|
ArrayList<Serve_categoryeNTITY> list;
|
|
private OnFragmentInteractionListener mListener;
|
|
private ArrayList<RadioButton> radioButtons;
|
|
private Loader mGankLoader;
|
|
private BaseActivity baseActivity;
|
|
|
|
public Main3Fragment() {
|
|
// Required empty public constructor
|
|
}
|
|
private ListView leftListView;
|
|
private ListView rightListView;//两个listView
|
|
private LeftAdapter leftAdapter;//左边适配器
|
|
private RightAdapter rightAdapter;//右边适配器
|
|
private List<LeftMenu> leftMenu;//左边菜单名称
|
|
private List<RightMenu> rightMenu;//右边菜单 包括标题和显示的图片
|
|
private List<RightMenuItem> rightItemMenu;//只包括显示的图片
|
|
private int currentItem = 0;//设置当前条目
|
|
/**
|
|
* 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 Main3Fragment newInstance(String param1, String param2) {
|
|
Main3Fragment fragment = new Main3Fragment();
|
|
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
|
|
return inflater.inflate(R.layout.fragment_main1, container, false);
|
|
}*/
|
|
|
|
// 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_main3;
|
|
}
|
|
|
|
@Override
|
|
protected void loadData() {
|
|
|
|
}
|
|
@Override
|
|
protected void onCreateVew(LayoutInflater inflater, Bundle savedInstanceState) {
|
|
super.onCreateVew(inflater, savedInstanceState);
|
|
baseActivity=(BaseActivity)getActivity();
|
|
progressDialog=new ProgressDialog(baseActivity);
|
|
String f3list[]=getContext().getResources().getStringArray(R.array.f3list);
|
|
|
|
getList( );
|
|
}
|
|
private void getList( ) {
|
|
Map<String,String> map=new HashMap<>();
|
|
/* RegisterUser user=
|
|
Config.getInstance(getContext()).getUser();
|
|
|
|
if(user!=null){
|
|
map.put("userid",user.getUserid());}
|
|
else { map.put("userid",0+"");}*/
|
|
map.put("app", "Category");
|
|
map.put("class", "Category_an_ServeCategoryList");
|
|
map.put("sign", Md5.md5("Category"+"Category_an_ServeCategoryList"+Md5.secret));
|
|
map.put("category_type", "personal");
|
|
//分类类型 企业 firm ,个人 personal
|
|
getGankList(ApiConfig.BASE_URL,map, getResources().getString(R.string.requsting),0);
|
|
}
|
|
|
|
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) {
|
|
// 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);
|
|
JSONObject jsonObject= null;
|
|
try {
|
|
jsonObject = new JSONObject(s);
|
|
org.json.JSONArray array =jsonObject.getJSONArray("serve_category");
|
|
Type type = new TypeToken<ArrayList<Serve_categoryeNTITY>>(){}.getType();
|
|
list = new Gson().fromJson(array.toString(), type);
|
|
confirmRight(list );
|
|
|
|
//intRecycleVerization(list1);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
try {
|
|
jsonObject = new JSONObject(s);
|
|
org.json.JSONArray array =jsonObject.getJSONArray("card_count");
|
|
ArrayList<String> strings=new ArrayList<>();
|
|
for (int i = 0; i <array.length() ; i++) {
|
|
strings.add("");
|
|
}
|
|
//intRecycleVerization2(strings);
|
|
|
|
} 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 void confirmRight(ArrayList<Serve_categoryeNTITY> list){
|
|
intRecycleVerization(list);
|
|
}
|
|
|
|
private void intRecycleVerization(ArrayList<Serve_categoryeNTITY> list) {
|
|
|
|
leftMenu = new ArrayList<>();
|
|
ArrayList<String> stringArrayList=new ArrayList<>();
|
|
for (int j = 0; j < list.size(); j++) {
|
|
LeftMenu menu = new LeftMenu();
|
|
menu.setLeftMenu(list.get(j).getServe_category_name());
|
|
leftMenu.add(menu);
|
|
stringArrayList.add(list.get(j).getServe_category_icon());
|
|
}
|
|
|
|
rightMenu = new ArrayList<>();
|
|
for (int j = 0; j < list.size(); j++) {
|
|
rightItemMenu = new ArrayList<>();
|
|
for (int n = 0; n < list.get(j).getContent_name().size(); n++) {
|
|
RightMenuItem tItem = new RightMenuItem();
|
|
tItem.setName(list.get(j).getContent_name().get(n).getServe_content_name());
|
|
rightItemMenu.add(tItem);
|
|
}
|
|
RightMenu menu = new RightMenu();
|
|
menu.setRightTitle(list.get(j).getServe_category_name());
|
|
menu.setRightMenuItem(rightItemMenu);
|
|
rightMenu.add(menu);
|
|
leftListView = mDataBinding.recyViewleft;
|
|
rightListView = mDataBinding.recyView;
|
|
rightAdapter = new RightAdapter(getContext(),rightMenu,list.get(j).getContent_name());
|
|
leftAdapter = new LeftAdapter(getContext(), leftMenu,rightListView,stringArrayList);
|
|
leftListView.setDividerHeight(1);
|
|
|
|
leftListView.setAdapter(leftAdapter);
|
|
rightListView.setAdapter(rightAdapter);
|
|
leftAdapter.setSelectID(0);
|
|
/* leftListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
// TODO Auto-generated method stub
|
|
leftAdapter.setSelectID(position);
|
|
rightListView.setSelection(position);
|
|
|
|
|
|
}
|
|
});*/
|
|
|
|
rightListView.setDividerHeight(0);
|
|
rightListView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
// TODO Auto-generated method stub
|
|
if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE){//如果停止滚动
|
|
|
|
leftAdapter.setSelectID(currentItem);
|
|
leftListView.setSelection(currentItem);
|
|
}
|
|
// if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
|
|
//
|
|
// leftAdapter.setSelectID(currentItem);
|
|
// leftListView.setSelection(currentItem);
|
|
//
|
|
// }
|
|
// if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING){
|
|
//
|
|
// leftAdapter.setSelectID(currentItem);
|
|
// leftListView.setSelection(currentItem);
|
|
//
|
|
// }
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
// TODO Auto-generated method stub
|
|
//currentItem = firstVisibleItem;
|
|
if(currentItem!=firstVisibleItem){
|
|
currentItem = firstVisibleItem;
|
|
leftAdapter.setSelectID(currentItem);
|
|
leftListView.setSelection(currentItem);
|
|
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
/*
|
|
FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(),3);
|
|
mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
|
mgr.setSmoothScrollbarEnabled(true);
|
|
mDataBinding.recyView.setLayoutManager(mgr);
|
|
|
|
BaseRecycleViewAdapter baseRecycleViewAdapter=new BaseRecycleViewAdapter(getActivity(),R.layout.f3_itemrightlayout);
|
|
final ArrayList<SimpleEntity> homegridentityvArrayList=getGridVorizationlist(i);
|
|
baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
|
@Override
|
|
public void onBindViewHolder(Object b, int position) {
|
|
if(!(position>=homegridentityvArrayList.size())) {
|
|
F3ItemrightlayoutBinding homeGridAdapterItemBinding = (F3ItemrightlayoutBinding) b;
|
|
homeGridAdapterItemBinding.setMyentity(homegridentityvArrayList.get(position));
|
|
|
|
Picasso.with(getActivity()).load(homegridentityvArrayList.get(position).getString3())
|
|
.placeholder(R.mipmap.error)
|
|
.transform(new PicassoRoundTransform())
|
|
.into(homeGridAdapterItemBinding.logotop);
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
|
|
mDataBinding.recyView.setAdapter(baseRecycleViewAdapter);
|
|
baseRecycleViewAdapter.setData(homegridentityvArrayList);
|
|
baseRecycleViewAdapter.setOnItemClickListener(new BaseRecycleViewAdapter.OnItemClickListener() {
|
|
@Override
|
|
public void onItemClick(View itemView, int position) {
|
|
if(itemView.getId()==R.id.f3_itemright){
|
|
Intent intent=new Intent(getActivity(), HousekeepingActivity.class);
|
|
intent.putExtra("titile",homegridentityvArrayList.get(position).getString1());
|
|
startActivity(intent);
|
|
|
|
}
|
|
}
|
|
});*/
|
|
}
|
|
}
|
|
private ArrayList<SimpleEntity> getGridVorizationlist(int j) {
|
|
ArrayList<SimpleEntity> homeHorizatationEntities=new ArrayList<>();
|
|
for (int i = 0; i <j ; i++) {
|
|
SimpleEntity homeHorizatationEntity=new SimpleEntity();
|
|
homeHorizatationEntity.setString3("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1539688818787&di=f9b7b54f45e987042db8beabadf8d830&imgtype=0&src=http%3A%2F%2Fpic15.nipic.com%2F20110630%2F6322714_105909244340_2.jpg");
|
|
homeHorizatationEntity.setString2("2018-10-16");
|
|
homeHorizatationEntity.setString1("比卡丘");
|
|
homeHorizatationEntities.add(homeHorizatationEntity);
|
|
|
|
}
|
|
return homeHorizatationEntities;
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|