package com.ewei.demo.article;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.ewei.demo.R;
import com.ewei.demo.article.adatper.TopicListAdatper;
import com.ewei.sdk.base.BaseActivity;
import com.ewei.sdk.entity.Topic;
import java.util.List;


/**
 * 文章目录子级列表
 *
 * @author Jay
 * @date 2016/3/3
 */
public class ArticleTopicChildrenListActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    private ListView mLvTopicList;
    private TopicListAdatper topicListAdatper;

    private static final String TAG = ArticleTopicChildrenListActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_topic);

        List<Topic> topicChildren = (List<Topic>) getIntent().getSerializableExtra("topicChildren");
        if (topicChildren == null || topicChildren.size() == 0) {
            finish();
        }
        initControl(topicChildren);
    }

    /**
     * 初始化基本控件
     */
    private void initControl(List<Topic> topicChildren) {

        initTitle("文章目录");

        mLvTopicList = (ListView) findViewById(R.id.ptr_topic_list);
        topicListAdatper = new TopicListAdatper(this);
        mLvTopicList.setAdapter(topicListAdatper);
        mLvTopicList.setOnItemClickListener(this);
        topicListAdatper.appendList(topicChildren);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Topic topic = (Topic) parent.getAdapter().getItem(position);
        if (topic != null) {
            Intent intent = new Intent(ArticleTopicChildrenListActivity.this, ArticleForTopicListActivity.class);
            intent.putExtra("topicInfo", topic);
            startActivity(intent);
        }
    }
}
