package com.tejia.lijin.app.ui.gmtemplate;
|
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.view.View;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.TextView;
|
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ui.BaseFragmentActivity;
|
import com.tejia.lijin.app.util.umengCustomEvent.GoodsCustomEvent;
|
import com.tejia.lijin.app.view.BaseFragment;
|
import com.viewpagerindicator.ImagePath;
|
import com.viewpagerindicator.TabPageIndicator_Gm;
|
import com.wpc.library.RetainViewFragment;
|
import com.wpc.library.okhttp.OkHttpUtils;
|
|
import org.apache.http.Header;
|
import org.json.JSONArray;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import androidx.fragment.app.FragmentManager;
|
import androidx.viewpager.widget.ViewPager;
|
|
/**
|
* 通用模版
|
*/
|
public class GmTemplateFragment extends RetainViewFragment implements View.OnClickListener {
|
private TabPageIndicator_Gm gmtemplate_indicator;//指示器
|
private ViewPager gmtemplate_Pager;
|
|
private String key;
|
private String from;
|
private int type = 0;//上级传过来的type 默认为0 表示未传递
|
private GmTemplateTabAdapter adapter;
|
/**
|
* 导航栏标题
|
*/
|
private ArrayList<Map<String, String>> navtitle = new ArrayList<>();
|
|
String tag = "commoncontent/getNavList";
|
|
@Override
|
public int getContentResource() {
|
return R.layout.activity_gmtemplate;
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
getActivity().setTheme(R.style.AppTabTheme5);
|
initView(contentView);
|
key = getArguments().getString("key");
|
from = getArguments().getString("from");
|
String types = getArguments().getString("type");
|
if (types != null && !types.equals("")) {//上级传过来的type
|
double aDouble = Double.valueOf(types);
|
type = (int) aDouble;//默认为0 表示未传递
|
}
|
GoodsCustomEvent.goodsListCommonTemplate(getContext(), types);
|
FragmentManager fm = getChildFragmentManager();
|
adapter = new GmTemplateTabAdapter(fm, navtitle, key, type + "", from);
|
gmtemplate_Pager.setAdapter(adapter);
|
gmtemplate_indicator.setImgList(imgList);
|
gmtemplate_indicator.setViewPager(gmtemplate_Pager);
|
getNavList(key);//获取 指示器数据
|
}
|
|
|
/**
|
* 控件初始化
|
*/
|
private void initView(View view) {
|
view.findViewById(R.id.ll_top).setVisibility(View.GONE);
|
gmtemplate_indicator = view.findViewById(R.id.gmtemplate_indicator);
|
gmtemplate_Pager = view.findViewById(R.id.gmtemplate_Pager);
|
}
|
|
/**
|
* 单击事件
|
*
|
* @param v
|
*/
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
default:
|
break;
|
}
|
}
|
|
List<ImagePath> imgList = new ArrayList<>();
|
|
/**
|
* 获取通用模板的导航栏
|
*
|
* @param title 上级传过来的关键词
|
*/
|
private void getNavList(String title) {
|
ShoppingApi.getNavList(getContext(), title, type + "", new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
if (navtitle != null && navtitle.size() > 0) {
|
navtitle.clear();
|
}
|
if (imgList != null && imgList.size() > 0) {
|
imgList.clear();
|
}
|
JSONArray json = jsonObject.optJSONArray("data");
|
//当data数组为0时表示没有导航栏
|
if (json == null || json.length() == 0) {
|
gmtemplate_indicator.setVisibility(View.GONE);
|
Map<String, String> map = new HashMap<>();
|
map.put("name", "");
|
map.put("cid", "");
|
navtitle.add(map);
|
} else {//有导航栏
|
gmtemplate_indicator.setVisibility(View.VISIBLE);
|
for (int i = 0; i < json.length(); i++) {
|
Map<String, String> map = new HashMap<>();
|
ImagePath info = new ImagePath();
|
map.put("name", ((JSONObject) json.get(i)).optString("name", ""));
|
map.put("cid", ((JSONObject) json.get(i)).optString("cid", ""));
|
navtitle.add(map);
|
info.setImgUrl(((JSONObject) json.get(i)).optString("picture", ""));
|
imgList.add(info);
|
}
|
}
|
adapter.notifyDataSetChanged();
|
gmtemplate_indicator.notifyDataSetChanged();
|
} else {
|
// Toast.makeText(GmTemplate.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
//不论请求是否在服务器存在 都会回调
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
}
|
|
});
|
}
|
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
gmtemplate_indicator = null;//指示器
|
gmtemplate_Pager = null;
|
key = null;
|
type = 0;//上级传过来的type 默认为0 表示未传递
|
adapter = null;
|
OkHttpUtils.getInstance().cancelTag(tag);
|
}
|
}
|