|
|
|
@ -12,12 +12,18 @@ import android.view.View; |
|
|
|
|
|
|
|
import com.qhclh.ytzh.R; |
|
|
|
import com.qhclh.ytzh.base.BaseActivity; |
|
|
|
import com.qhclh.ytzh.home.RpcUrl; |
|
|
|
import com.qhclh.ytzh.tasks.ViewOnClickTask; |
|
|
|
import com.qhclh.ytzh.work.tablepoultry.anqiu.AnqiuFragment; |
|
|
|
import com.qhclh.ytzh.work.tablepoultry.changle.ChangleFragment; |
|
|
|
import com.qhclh.ytzh.work.tablepoultry.qiuping.QiupingFragment; |
|
|
|
import com.qhclh.ytzh.work.tablepoultry.shouguangdong.ShouguangdFragment; |
|
|
|
import com.qhclh.ytzh.work.tablepoultry.shouguangxi.ShouguangxFragment; |
|
|
|
|
|
|
|
import org.forks.jsonrpc.JsonRpcResult; |
|
|
|
import org.forks.jsonrpc.RpcFacade; |
|
|
|
import org.forks.jsonrpc.RpcObject; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@ -55,7 +61,8 @@ public class TablepoultryActivity extends BaseActivity { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void initData() { |
|
|
|
|
|
|
|
areasList = new ArrayList<>(); |
|
|
|
itemIdList = new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -66,37 +73,56 @@ public class TablepoultryActivity extends BaseActivity { |
|
|
|
@Override |
|
|
|
protected void onResume() { |
|
|
|
super.onResume(); |
|
|
|
initTabLayout(); |
|
|
|
initViewPager(); |
|
|
|
GetAllWeatherAreas(); |
|
|
|
} |
|
|
|
|
|
|
|
private List<RpcObject> rpcList; |
|
|
|
private List<Long> itemIdList; |
|
|
|
private void GetAllWeatherAreas() { |
|
|
|
ViewOnClickTask GetAllWeatherAreasTask = new ViewOnClickTask(this,"加载中...") { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void successUI() { |
|
|
|
areasList.clear(); |
|
|
|
itemIdList.clear(); |
|
|
|
mTitleList.clear(); |
|
|
|
mFragmentList.clear(); |
|
|
|
for (int i=0;i<rpcList.size();i++){ |
|
|
|
areasList.add(rpcList.get(i).getString("Name")); |
|
|
|
itemIdList.add(rpcList.get(i).getLong("ID")); |
|
|
|
} |
|
|
|
initTabLayout(); |
|
|
|
initViewPager(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
JsonRpcResult result = RpcFacade.rpcCall(RpcUrl.GetAllWeatherAreas); |
|
|
|
rpcList = result.getRpcObjectList(RpcUrl.GetAllWeatherAreas_fanhui); |
|
|
|
return null; |
|
|
|
} |
|
|
|
}; |
|
|
|
GetAllWeatherAreasTask.execute(); |
|
|
|
} |
|
|
|
|
|
|
|
private List<String> areasList; |
|
|
|
private void initViewPager() { |
|
|
|
for (int i=0;i<areasList.size();i++) { |
|
|
|
mFragmentList.add(new ChangleFragment()); |
|
|
|
mFragmentList.add(new ShouguangdFragment()); |
|
|
|
mFragmentList.add(new ShouguangxFragment()); |
|
|
|
mFragmentList.add(new AnqiuFragment()); |
|
|
|
mFragmentList.add(new QiupingFragment()); |
|
|
|
|
|
|
|
} |
|
|
|
mViewPagerAdapter = new TabViewPagerAdapter(getSupportFragmentManager()); |
|
|
|
mViewPager.setAdapter(mViewPagerAdapter); |
|
|
|
mViewPager.setOffscreenPageLimit(2); |
|
|
|
mViewPager.setOffscreenPageLimit(1); |
|
|
|
mTabLayout.setupWithViewPager(mViewPager); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initTabLayout() { |
|
|
|
mTitleList.add(getString(R.string.changle)); |
|
|
|
mTitleList.add(getString(R.string.shouguangdong)); |
|
|
|
mTitleList.add(getString(R.string.shouguangxi)); |
|
|
|
mTitleList.add(getString(R.string.anqiu)); |
|
|
|
mTitleList.add(getString(R.string.qiuping)); |
|
|
|
|
|
|
|
|
|
|
|
// for (String title : mTitleList) { |
|
|
|
// mTabLayout.addTab(mTabLayout.newTab().setText(title)); |
|
|
|
// } |
|
|
|
for (int i=0;i<rpcList.size();i++) { |
|
|
|
mTitleList.add(rpcList.get(i).getString("Name")); |
|
|
|
} |
|
|
|
|
|
|
|
mTabLayout.setTabMode(TabLayout.MODE_FIXED); |
|
|
|
mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); |
|
|
|
} |
|
|
|
|
|
|
|
private class TabViewPagerAdapter extends FragmentPagerAdapter { |
|
|
|
@ -114,6 +140,11 @@ public class TablepoultryActivity extends BaseActivity { |
|
|
|
return mFragmentList.size(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public long getItemId(int position) { |
|
|
|
return itemIdList.get(position); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CharSequence getPageTitle(int position) { |
|
|
|
return mTitleList.get(position); |
|
|
|
|