mGradeFlowTagLayout.setOnTagSelectListener(new OnTagSelectListener() {
@Override
public void onItemSelect (FlowTagLayout parent, List<Integer> selectedList) {
if (selectedList != null && selectedList.size() > 0 ) {
for (int i : selectedList) {
switch (i) {
case 0 :
PadGrade(index_0+ "" , true );
mStartStatus=index_0;
break ;
case 1 :
PadGrade(index_1+ "" , true );
mStartStatus=index_1;
break ;
case 2 :
PadGrade(index_2+ "" , true );
mStartStatus=index_2;
break ;
case 3 :
PadGrade(index_3+ "" , true );
mStartStatus=index_3;
break ;
case 4 :
PadGrade(index_4+ "" , true );
mStartStatus=index_4;
break ;
}
}
} else {
Toast.makeText(getActivity(), "没有选择标签" , Toast.LENGTH_SHORT).show();
PadGrade(null , true );
}
}
});
netWorkHelper.obtainStoreScoreInfoComment(mContext, new NetWorkListener.ObtainStoreScoreInfoCommentListener() {
@Override
public void onFinish (int score, int pointCount, int starFive, int starFour, int starThree, int starTwo, int starOne) {
star1 = starOne;
star2 = starTwo;
star3 = starThree;
star4 = starFour;
star5 = starFive;
List<String> dataSource1 = new ArrayList<>();
int i = 0 ;
if (star5 != 0 ) {
dataSource1.add("5星评价" + "\n" + " " + star5);
i++;
index_0 = 5 ;
}
if (star4 != 0 ) {
dataSource1.add("4星评价" + "\n" + " " + star4);
if (i == 0 ) {
index_0 = 4 ;
}else {
index_1 = 4 ;
}
i++;
}
if (star3 != 0 ) {
dataSource1.add("3星评价" + "\n" + " " + star3);
switch (i) {
case 0 :
index_0 = 3 ;
break ;
case 1 :
index_1 = 3 ;
break ;
case 2 :
index_2 = 3 ;
break ;
}
i++;
}
if (star2 != 0 ) {
dataSource1.add("2星评价" + "\n" + " " + star2);
switch (i) {
case 0 :
index_0 = 2 ;
break ;
case 1 :
index_1 = 2 ;
break ;
case 2 :
index_2 = 2 ;
break ;
case 3 :
index_3 = 2 ;
break ;
}
i++;
}
if (star1 != 0 ) {
dataSource1.add("1星评价" + "\n" + " " + star1);
switch (i) {
case 0 :
index_0 = 1 ;
break ;
case 1 :
index_1 = 1 ;
break ;
case 2 :
index_2 = 1 ;
break ;
case 3 :
index_3 = 1 ;
break ;
case 4 :
index_4 = 1 ;
break ;
}
i++;
}
mGradeTagAdapter.onlyAddAll(dataSource1);
}
@Override
public void onError (String errorDesc) {
Toast.makeText(mContext, "网络错误" , Toast.LENGTH_SHORT).show();
}
});
package com.mine.project.function.home;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.mine.project.R;
import com.mine.project.flowlibrary.FlowTagLayout;
import com.mine.project.flowlibrary.OnTagSelectListener;
import com.mine.project.function.activity.UserComplainActivity;
import com.mine.project.function.adapter.PadComplainAdapter;
import com.mine.project.function.adapter.PadGradeAdpter;
import com.mine.project.function.adapter.TagAdapter;
import com.mine.project.function.domain.CommentInfo;
import com.mine.project.function.domain.ComplainInfo;
import com.mine.project.function.domain.PageInfo;
import com.mine.project.home.ui.BaseFragment;
import com.mine.project.network.control.NetWorkListener;
import java.util.ArrayList;
import java.util.List;
/**
* A simple {@link Fragment} subclass.
*/
public class TabLayoutFragment extends BaseFragment {
public static String TABLAYOUT_FRAGMENT = "tab_fragment" ;
private TextView mTextView;
private int type;
private ListView mLvShopGrade;
private LinearLayout mLlShapgrade;
private ListView mLvShopgrade;
private RecyclerView mRv;
List<String> mData;
private FlowTagLayout mGradeFlowTagLayout;
private CheckBox mChCommentShopgrade;
private TagAdapter<String> mGradeTagAdapter;
private FragmentManager manager;
private FragmentTransaction transaction;
private String padGradeTime;
private int star1;
private int star2;
private int star3;
private int star4;
private int star5;
private int index_0;
private int index_1;
private int index_2;
private int index_3;
private int index_4;
private int mStartStatus;
private boolean mIsChecked=true ;
private PadComplainAdapter mPadComplainAdapter;
public static TabLayoutFragment newInstance (int type) {
TabLayoutFragment fragment = new TabLayoutFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(TABLAYOUT_FRAGMENT, type);
fragment.setArguments(bundle);
return fragment;
}
@Override
public void onCreate (Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
if (getArguments() != null ) {
type = (int ) getArguments().getSerializable(TABLAYOUT_FRAGMENT);
}
}
@Nullable
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab_layout, container, false );
initView(view);
initData();
initSizeData();
return view;
}
private void initData () {
mChCommentShopgrade.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged (CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
PadGrade(mStartStatus+"" , true );
Toast.makeText(getActivity(), "只看有内容评论" , Toast.LENGTH_SHORT).show();
} else {
PadGrade(mStartStatus+"" , false );
Toast.makeText(getActivity(), "查看全部评论" , Toast.LENGTH_SHORT).show();
}
}
});
}
protected void initView (View view) {
mChCommentShopgrade = (CheckBox) view.findViewById(R.id.ch_comment_shopgrade);
mGradeFlowTagLayout = (FlowTagLayout) view.findViewById(R.id.size_flow_layout);
mRv = (RecyclerView) view.findViewById(R.id.rv);
mLlShapgrade = (LinearLayout) view.findViewById(R.id.ll_shapgrade);
switch (type) {
case 1 :
PadGrade(null , true );
break ;
case 2 :
PadComplain(1 );
mLlShapgrade.setVisibility(View.GONE);
break ;
}
}
private void initSizeData () {
mGradeTagAdapter = new TagAdapter<>(getActivity());
mGradeFlowTagLayout.setTagCheckedMode(FlowTagLayout.FLOW_TAG_CHECKED_SINGLE);
mGradeFlowTagLayout.setAdapter(mGradeTagAdapter);
mGradeFlowTagLayout.setOnTagSelectListener(new OnTagSelectListener() {
@Override
public void onItemSelect (FlowTagLayout parent, List<Integer> selectedList) {
if (selectedList != null && selectedList.size() > 0 ) {
for (int i : selectedList) {
switch (i) {
case 0 :
PadGrade(index_0+ "" , true );
mStartStatus=index_0;
break ;
case 1 :
PadGrade(index_1+ "" , true );
mStartStatus=index_1;
break ;
case 2 :
PadGrade(index_2+ "" , true );
mStartStatus=index_2;
break ;
case 3 :
PadGrade(index_3+ "" , true );
mStartStatus=index_3;
break ;
case 4 :
PadGrade(index_4+ "" , true );
mStartStatus=index_4;
break ;
}
}
} else {
Toast.makeText(getActivity(), "没有选择标签" , Toast.LENGTH_SHORT).show();
PadGrade(null , true );
}
}
});
netWorkHelper.obtainStoreScoreInfoComment(mContext, new NetWorkListener.ObtainStoreScoreInfoCommentListener() {
@Override
public void onFinish (int score, int pointCount, int starFive, int starFour, int starThree, int starTwo, int starOne) {
star1 = starOne;
star2 = starTwo;
star3 = starThree;
star4 = starFour;
star5 = starFive;
List<String> dataSource1 = new ArrayList<>();
int i = 0 ;
if (star5 != 0 ) {
dataSource1.add("5星评价" + "\n" + " " + star5);
i++;
index_0 = 5 ;
}
if (star4 != 0 ) {
dataSource1.add("4星评价" + "\n" + " " + star4);
if (i == 0 ) {
index_0 = 4 ;
}else {
index_1 = 4 ;
}
i++;
}
if (star3 != 0 ) {
dataSource1.add("3星评价" + "\n" + " " + star3);
switch (i) {
case 0 :
index_0 = 3 ;
break ;
case 1 :
index_1 = 3 ;
break ;
case 2 :
index_2 = 3 ;
break ;
}
i++;
}
if (star2 != 0 ) {
dataSource1.add("2星评价" + "\n" + " " + star2);
switch (i) {
case 0 :
index_0 = 2 ;
break ;
case 1 :
index_1 = 2 ;
break ;
case 2 :
index_2 = 2 ;
break ;
case 3 :
index_3 = 2 ;
break ;
}
i++;
}
if (star1 != 0 ) {
dataSource1.add("1星评价" + "\n" + " " + star1);
switch (i) {
case 0 :
index_0 = 1 ;
break ;
case 1 :
index_1 = 1 ;
break ;
case 2 :
index_2 = 1 ;
break ;
case 3 :
index_3 = 1 ;
break ;
case 4 :
index_4 = 1 ;
break ;
}
i++;
}
mGradeTagAdapter.onlyAddAll(dataSource1);
}
@Override
public void onError (String errorDesc) {
Toast.makeText(mContext, "网络错误" , Toast.LENGTH_SHORT).show();
}
});
}
private void PadGrade (String mLevel, boolean isShowNoComment) {
netWorkHelper.obtainStoreScoreComment(mContext, mLevel, 1 , isShowNoComment, new NetWorkListener.ObtainStoreScoreCommentListener() {
@Override
public void onFinish (ArrayList<CommentInfo> list, PageInfo pageInfo) {
mRv.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false ));
mRv.setItemAnimator(new DefaultItemAnimator());
mRv.setAdapter(new PadGradeAdpter(mContext, list));
}
@Override
public void onError (String errorDesc) {
Toast.makeText(mContext, "网络错误" , Toast.LENGTH_SHORT).show();
}
});
}
private void PadComplain (int mCurPage) {
netWorkHelper.obtainStoreScoreComplain(mContext, mCurPage, new NetWorkListener.ObtainStoreScoreComplainListener() {
@Override
public void onFinish (ArrayList<ComplainInfo> list, PageInfo pageInfo) {
mRv.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false ));
mRv.setItemAnimator(new DefaultItemAnimator());
mPadComplainAdapter = new PadComplainAdapter(mContext, list);
mRv.setAdapter(mPadComplainAdapter);
mPadComplainAdapter.setOnItemClickListener(new PadComplainAdapter.OnItemClickListener() {
@Override
public void onClick (PadComplainAdapter.ViewHolder holder, View view, int position) {
switch (position) {
case 1 :
startActvity(UserComplainActivity.class);
break ;
default :
startActvity(UserComplainActivity.class);
break ;
}
}
});
}
@Override
public void onError (String errorDesc) {
Toast.makeText(mContext, "联网失败" , Toast.LENGTH_SHORT).show();
}
});
}
}