private List<News.DataBean.ComicsBean>list;
private ListView listView;
private Button button;
private MyAdapter adapter;
private List<ChannelBean>channelBeanList;
private List<String>stringList;
private String json;
private SharedPreferences sp;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
String s = msg.obj.toString();
Gson gson=new Gson();
News news = gson.fromJson(s, News.class);
list.addAll(news.getData().getComics());
adapter.notifyDataSetChanged();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView= (ListView) findViewById(R.id.list);
list=new ArrayList<>();
button= (Button) findViewById(R.id.b1);
adapter=new MyAdapter();
listView.setAdapter(adapter);
loadDate();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("te",list.get(i).getTitle());
startActivity(intent);
}
});
sp=getSharedPreferences("set",MODE_PRIVATE);
stringList=new ArrayList<>();
stringList.add("推荐");stringList.add("娱乐");stringList.add("体育");
stringList.add("热点");stringList.add("金融");stringList.add("NBA");
stringList.add("汽车");stringList.add("时尚");stringList.add("股票");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
json=sp.getString("use",null);
if(json==null){
channelBeanList=new ArrayList<ChannelBean>();
for(int i=0;i<stringList.size();i++){
ChannelBean bean=null;
if(i<3){
bean=new ChannelBean(stringList.get(i),true);
}else {
bean=new ChannelBean(stringList.get(i),false);
}
channelBeanList.add(bean);
}
ChannelActivity.startChannelActivity(MainActivity.this,channelBeanList);
}else {
ChannelActivity.startChannelActivity(MainActivity.this,json);
}
}
});
}
private void loadDate() {
new Thread(){
@Override
public void run() {
String urlConnect = Net.getUrlConnect("http://api.kkmh.com/v1/daily/comic_lists/0?since=0&gender=0&sa_event=eyJwcm9qZWN0Ijoia3VhaWthbl9hcHAiLCJ0aW1lIjoxNDg3NzQyMjQwNjE1LCJwcm9wZXJ0aWVzIjp7IkhvbWVwYWdlVGFiTmFtZSI6IueDremXqCIsIlZDb21tdW5pdHlUYWJOYW1lIjoi54Ot6ZeoIiwiJG9zX3ZlcnNpb24iOiI0LjQuMiIsIkdlbmRlclR5cGUiOiLlpbPniYgiLCJGcm9tSG9tZXBhZ2VUYWJOYW1lIjoi54Ot6ZeoIiwiJGxpYl92ZXJzaW9uIjoiMS42LjEzIiwiJG5ldHdvcmtfdHlwZSI6IldJRkkiLCIkd2lmaSI6dHJ1ZSwiJG1hbnVmYWN0dXJlciI6ImJpZ25veCIsIkZyb21Ib21lcGFnZVVwZGF0ZURhdGUiOjAsIiRzY3JlZW5faGVpZ2h0IjoxMjgwLCJIb21lcGFnZVVwZGF0ZURhdGUiOjAsIlByb3BlcnR5RXZlbnQiOiJSZWFkSG9tZVBhZ2UiLCJGaW5kVGFiTmFtZSI6IuaOqOiNkCIsImFidGVzdF9ncm91cCI6MTEsIiRzY3JlZW5fd2lkdGgiOjcyMCwiJG9zIjoiQW5kcm9pZCIsIlRyaWdnZXJQYWdlIjoiSG9tZVBhZ2UiLCIkY2FycmllciI6IkNoaW5hIE1vYmlsZSIsIiRtb2RlbCI6IlZQaG9uZSIsIiRhcHBfdmVyc2lvbiI6IjMuNi4yIn0sInR5cGUiOiJ0cmFjayIsImRpc3RpbmN0X2lkIjoiQTo2YWRkYzdhZTQ1MjUwMzY1Iiwib3JpZ2luYWxfaWQiOiJBOjZhZGRjN2FlNDUyNTAzNjUiLCJldmVudCI6IlJlYWRIb21lUGFnZSJ9");
Message message=Message.obtain();
message.obj=urlConnect;
handler.sendMessage(message);
}
}.start();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode== ChannelActivity.REQUEST_CODE&&resultCode==ChannelActivity.RESULT_CODE){
json=data.getStringExtra(ChannelActivity.RESULT_JSON_KEY);
sp.edit().putString("use",json).commit();
}
}
class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder holder;
if(view==null){
holder=new ViewHolder();
view=View.inflate(MainActivity.this,R.layout.item, null);
holder.textView= (TextView) view.findViewById(R.id.t1);
holder.imageView= (ImageView) view.findViewById(R.id.i1);
view.setTag(holder);
}else {
holder= (ViewHolder) view.getTag();
}
News.DataBean.ComicsBean bean=list.get(i);
holder.textView.setText(bean.getTitle());
Glide.with(MainActivity.this).load(bean.getCover_image_url()).into(holder.imageView);
return view;
}
}
class ViewHolder{
TextView textView;
ImageView imageView;
}
}
xlistview
com.github.andyoom:xlistview:v1.0.1
citypicker 城市列表
com.github.andyoom:citypicker:v1.0.4
draggrid 频道管理
com.github.andyoom:draggrid:v1.0.1
com.github.andyoom:project-library:v1.0.0
以上全部都是在jitpack中
使用方式:
1.在项目目录下的build.gradle中添加
maven {url "https://jitpack.io"}
如图:
2.在相应Module中的build.gradle中导入所需包就可以