Search in sources :

Example 1 with NewsPresenter

use of cn.nicolite.palm300heroes.presenter.NewsPresenter in project Palm300Heroes by nicolite.

the class NewsFragment method doBusiness.

@Override
protected void doBusiness() {
    newsPresenter = new NewsPresenter(this, this);
    View headView = LayoutInflater.from(context).inflate(R.layout.news_headview, rootView, false);
    bgaBanner = headView.findViewById(R.id.banner_guide_content);
    bgaBanner.setAdapter(new BGABanner.Adapter() {

        @Override
        public void fillBannerItem(BGABanner banner, View itemView, Object model, int position) {
            if (itemView instanceof ImageView) {
                Glide.with(context).load((String) model).placeholder(R.drawable.img_loading).error(R.drawable.img_error).skipMemoryCache(true).centerCrop().dontAnimate().into((ImageView) itemView);
            }
        }
    });
    bgaBanner.setDelegate(new BGABanner.Delegate() {

        @Override
        public void onBannerItemClick(BGABanner banner, View itemView, Object model, int position) {
            if (itemView instanceof ImageView) {
                String url = bannerList.get(position).getUrl();
                if (url.contains("/details/")) {
                    Bundle bundle = new Bundle();
                    bundle.putInt("type", WebViewActivity.TYPE_NEWS);
                    bundle.putString("url", url);
                    bundle.putString("title", "资讯详情");
                    startActivity(WebViewActivity.class, bundle);
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putInt("type", WebViewActivity.TYPE_NEWS_BANNER);
                    bundle.putString("url", url);
                    bundle.putString("title", "资讯详情");
                    startActivity(WebViewActivity.class, bundle);
                }
            }
        }
    });
    View record = headView.findViewById(R.id.record);
    View equipment = headView.findViewById(R.id.equipment);
    View fightSkill = headView.findViewById(R.id.fightSkill);
    View talent = headView.findViewById(R.id.talent);
    record.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Bundle bundle = new Bundle();
            bundle.putInt("type", ContainerActivity.TYPE_NEWS_LIST);
            startActivity(ContainerActivity.class, bundle);
        }
    });
    equipment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Bundle bundle = new Bundle();
            bundle.putInt("type", ContainerActivity.TYPE_RECORD_RANK_TITLE);
            bundle.putString("title", "服务器排行榜");
            bundle.putInt("extra", HostRankFragment.TYPE_RANK_TITLE);
            startActivity(ContainerActivity.class, bundle);
        }
    });
    fightSkill.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startActivity(FightSkillActivity.class);
        }
    });
    talent.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startActivity(TalentActivity.class);
        }
    });
    List<View> viewList = new ArrayList<>();
    viewList.add(record);
    viewList.add(equipment);
    viewList.add(fightSkill);
    viewList.add(talent);
    for (int i = 0; i < viewList.size(); i++) {
        View itemView = viewList.get(i);
        ImageView menuImg = itemView.findViewById(R.id.menu_img);
        TextView menuText = itemView.findViewById(R.id.menu_text);
        menuImg.setImageResource(menuImgs[i]);
        menuText.setText(menuTexts[i]);
    }
    lRecyclerView.setLayoutManager(new LinearLayoutManager(context, OrientationHelper.VERTICAL, false));
    lRecyclerViewAdapter = new LRecyclerViewAdapter(new NewsAdapter(context, newsList));
    lRecyclerView.setAdapter(lRecyclerViewAdapter);
    lRecyclerViewAdapter.addHeaderView(headView);
    lRecyclerView.setLoadMoreEnabled(false);
    lRecyclerView.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            bannerViewList.clear();
            model.clear();
            tips.clear();
            newsPresenter.showBanner();
            newsPresenter.showNews();
        }
    });
    lRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            News news = newsList.get(position);
            if (!news.getNewsUrl().contains("/details/")) {
                Bundle bundle = new Bundle();
                bundle.putString("title", news.getNewsTitle());
                bundle.putString("url", news.getNewsUrl());
                bundle.putInt("type", WebViewActivity.TYPE_OTHERS);
                startActivity(WebViewActivity.class, bundle);
            } else {
                Bundle bundle = new Bundle();
                bundle.putString("url", news.getNewsUrl());
                bundle.putString("title", news.getNewsTitle());
                bundle.putInt("type", WebViewActivity.TYPE_NEWS);
                startActivity(WebViewActivity.class, bundle);
            }
        }
    });
    if (isFirstVisible && ListUtils.isEmpty(newsList)) {
        lRecyclerView.forceToRefresh();
    }
}
Also used : ArrayList(java.util.ArrayList) ContainerActivity(cn.nicolite.palm300heroes.view.activity.ContainerActivity) WebViewActivity(cn.nicolite.palm300heroes.view.activity.WebViewActivity) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) News(cn.nicolite.palm300heroes.model.bean.News) NewsAdapter(cn.nicolite.palm300heroes.view.oldAdapter.NewsAdapter) TextView(android.widget.TextView) ImageView(android.widget.ImageView) FightSkillActivity(cn.nicolite.palm300heroes.view.activity.FightSkillActivity) BGABanner(cn.bingoogolapple.bgabanner.BGABanner) OnItemClickListener(com.github.jdsjlzx.interfaces.OnItemClickListener) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) BindView(butterknife.BindView) LRecyclerView(com.github.jdsjlzx.recyclerview.LRecyclerView) NativeExpressADView(com.qq.e.ads.nativ.NativeExpressADView) View(android.view.View) INewsView(cn.nicolite.palm300heroes.view.iview.INewsView) TextView(android.widget.TextView) LRecyclerViewAdapter(com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter) TalentActivity(cn.nicolite.palm300heroes.view.activity.TalentActivity) NewsPresenter(cn.nicolite.palm300heroes.presenter.NewsPresenter) OnRefreshListener(com.github.jdsjlzx.interfaces.OnRefreshListener)

Aggregations

Bundle (android.os.Bundle)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 BGABanner (cn.bingoogolapple.bgabanner.BGABanner)1 News (cn.nicolite.palm300heroes.model.bean.News)1 NewsPresenter (cn.nicolite.palm300heroes.presenter.NewsPresenter)1 ContainerActivity (cn.nicolite.palm300heroes.view.activity.ContainerActivity)1 FightSkillActivity (cn.nicolite.palm300heroes.view.activity.FightSkillActivity)1 TalentActivity (cn.nicolite.palm300heroes.view.activity.TalentActivity)1 WebViewActivity (cn.nicolite.palm300heroes.view.activity.WebViewActivity)1 INewsView (cn.nicolite.palm300heroes.view.iview.INewsView)1 NewsAdapter (cn.nicolite.palm300heroes.view.oldAdapter.NewsAdapter)1 OnItemClickListener (com.github.jdsjlzx.interfaces.OnItemClickListener)1 OnRefreshListener (com.github.jdsjlzx.interfaces.OnRefreshListener)1 LRecyclerView (com.github.jdsjlzx.recyclerview.LRecyclerView)1 LRecyclerViewAdapter (com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter)1 NativeExpressADView (com.qq.e.ads.nativ.NativeExpressADView)1