<commit_before>package org.cnodejs.android.md.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
import com.melnykov.fab.FloatingActionButton;
import com.squareup.picasso.Picasso;

import org.cnodejs.android.md.R;
import org.cnodejs.android.md.adapter.MainAdapter;
import org.cnodejs.android.md.listener.NavigationOpenClickListener;
import org.cnodejs.android.md.listener.RecyclerViewLoadMoreListener;
import org.cnodejs.android.md.model.api.ApiClient;
import org.cnodejs.android.md.model.api.CallbackAdapter;
import org.cnodejs.android.md.model.entity.Result;
import org.cnodejs.android.md.model.entity.TabType;
import org.cnodejs.android.md.model.entity.Topic;
import org.cnodejs.android.md.model.entity.User;
import org.cnodejs.android.md.storage.LoginShared;
import org.cnodejs.android.md.util.HandlerUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener, RecyclerViewLoadMoreListener.OnLoadMoreListener {

    private static final int REQUEST_LOGIN = 1024;

    // 抽屉导航布局
    @Bind(R.id.main_drawer_layout)
    protected DrawerLayout drawerLayout;

    // 导航部分的个人信息
    @Bind(R.id.main_left_img_avatar)
    protected ImageView imgAvatar;

    @Bind(R.id.main_left_tv_login_name)
    protected TextView tvLoginName;

    @Bind(R.id.main_left_tv_score)
    protected TextView tvScore;

    @Bind(R.id.main_left_tv_badger_notification)
    protected TextView tvBadgerNotification;

    // 主要导航项
    @Bind({
            R.id.main_left_btn_all,
            R.id.main_left_btn_good,
            R.id.main_left_btn_share,
            R.id.main_left_btn_ask,
            R.id.main_left_btn_job
    })
    protected List<CheckedTextView> navMainItemList;

    // 内容部分
    @Bind(R.id.main_toolbar)
    protected Toolbar toolbar;

    @Bind(R.id.main_refresh_layout)
    protected SwipeRefreshLayout refreshLayout;

    @Bind(R.id.main_recycler_view)
    protected RecyclerView recyclerView;

    @Bind(R.id.main_fab_new_topic)
    protected FloatingActionButton fabNewTopic;

    @Bind(R.id.main_layout_no_data)
    protected ViewGroup layoutNoData;

    // 当前版块，默认为all
    private TabType currentTab = TabType.all;
    private int currentPage = 0; // 从未加载
    private List<Topic> topicList = new ArrayList<>();
    private MainAdapter adapter;

    // 首次按下返回键时间戳
    private long firstBackPressedTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        drawerLayout.setDrawerShadow(R.drawable.navigation_drawer_shadow, GravityCompat.START);
        drawerLayout.setDrawerListener(openDrawerListener);
        toolbar.setNavigationOnClickListener(new NavigationOpenClickListener(drawerLayout));

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        adapter = new MainAdapter(this, topicList);
        recyclerView.setAdapter(adapter);
        recyclerView.addOnScrollListener(new RecyclerViewLoadMoreListener(linearLayoutManager, this, 20));
        fabNewTopic.attachToRecyclerView(recyclerView);

        refreshLayout.setColorSchemeResources(R.color.red_light, R.color.green_light, R.color.blue_light, R.color.orange_light);
        refreshLayout.setOnRefreshListener(this);

        HandlerUtils.postDelayed(new Runnable() {

            @Override
            public void run() {
                refreshLayout.setRefreshing(true);
                onRefresh();
            }

        }, 100); // refreshLayout无法直接在onCreate中设置刷新状态

        updateUserInfoViews();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getMessageCountAsyncTask();
    }

    /**
     * 未读消息数目
     */
    private void getMessageCountAsyncTask() {
        if (!TextUtils.isEmpty(LoginShared.getAccessToken(this))) {
            ApiClient.service.getMessageCount(LoginShared.getAccessToken(this), new CallbackAdapter<Result<Integer>>() {

                @Override
                public void success(Result<Integer> result, Response response) {
                    if (result.getData() <= 0) {
                        tvBadgerNotification.setText(null);
                    } else if (result.getData() > 99) {
                        tvBadgerNotification.setText("99+");
                    } else {
                        tvBadgerNotification.setText(String.valueOf(result.getData()));
                    }
                }

            });
        }
    }

    /**
     * 用户信息更新逻辑
     */

    private DrawerLayout.DrawerListener openDrawerListener = new DrawerLayout.SimpleDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            updateUserInfoViews();
            getUserAsycnTask();
        }

    };
<commit_msg>添加首页获取消息数目策略<commit_after>package org.cnodejs.android.md.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
import com.melnykov.fab.FloatingActionButton;
import com.squareup.picasso.Picasso;

import org.cnodejs.android.md.R;
import org.cnodejs.android.md.adapter.MainAdapter;
import org.cnodejs.android.md.listener.NavigationOpenClickListener;
import org.cnodejs.android.md.listener.RecyclerViewLoadMoreListener;
import org.cnodejs.android.md.model.api.ApiClient;
import org.cnodejs.android.md.model.api.CallbackAdapter;
import org.cnodejs.android.md.model.entity.Result;
import org.cnodejs.android.md.model.entity.TabType;
import org.cnodejs.android.md.model.entity.Topic;
import org.cnodejs.android.md.model.entity.User;
import org.cnodejs.android.md.storage.LoginShared;
import org.cnodejs.android.md.util.HandlerUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener, RecyclerViewLoadMoreListener.OnLoadMoreListener {

    private static final int REQUEST_LOGIN = 1024;

    // 抽屉导航布局
    @Bind(R.id.main_drawer_layout)
    protected DrawerLayout drawerLayout;

    // 导航部分的个人信息
    @Bind(R.id.main_left_img_avatar)
    protected ImageView imgAvatar;

    @Bind(R.id.main_left_tv_login_name)
    protected TextView tvLoginName;

    @Bind(R.id.main_left_tv_score)
    protected TextView tvScore;

    @Bind(R.id.main_left_tv_badger_notification)
    protected TextView tvBadgerNotification;

    // 主要导航项
    @Bind({
            R.id.main_left_btn_all,
            R.id.main_left_btn_good,
            R.id.main_left_btn_share,
            R.id.main_left_btn_ask,
            R.id.main_left_btn_job
    })
    protected List<CheckedTextView> navMainItemList;

    // 内容部分
    @Bind(R.id.main_toolbar)
    protected Toolbar toolbar;

    @Bind(R.id.main_refresh_layout)
    protected SwipeRefreshLayout refreshLayout;

    @Bind(R.id.main_recycler_view)
    protected RecyclerView recyclerView;

    @Bind(R.id.main_fab_new_topic)
    protected FloatingActionButton fabNewTopic;

    @Bind(R.id.main_layout_no_data)
    protected ViewGroup layoutNoData;

    // 当前版块，默认为all
    private TabType currentTab = TabType.all;
    private int currentPage = 0; // 从未加载
    private List<Topic> topicList = new ArrayList<>();
    private MainAdapter adapter;

    // 首次按下返回键时间戳
    private long firstBackPressedTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        drawerLayout.setDrawerShadow(R.drawable.navigation_drawer_shadow, GravityCompat.START);
        drawerLayout.setDrawerListener(openDrawerListener);
        toolbar.setNavigationOnClickListener(new NavigationOpenClickListener(drawerLayout));

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        adapter = new MainAdapter(this, topicList);
        recyclerView.setAdapter(adapter);
        recyclerView.addOnScrollListener(new RecyclerViewLoadMoreListener(linearLayoutManager, this, 20));
        fabNewTopic.attachToRecyclerView(recyclerView);

        refreshLayout.setColorSchemeResources(R.color.red_light, R.color.green_light, R.color.blue_light, R.color.orange_light);
        refreshLayout.setOnRefreshListener(this);

        HandlerUtils.postDelayed(new Runnable() {

            @Override
            public void run() {
                refreshLayout.setRefreshing(true);
                onRefresh();
            }

        }, 100); // refreshLayout无法直接在onCreate中设置刷新状态

        updateUserInfoViews();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getMessageCountAsyncTask();
    }

    /**
     * 未读消息数目
     */
    private void getMessageCountAsyncTask() {
        if (!TextUtils.isEmpty(LoginShared.getAccessToken(this))) {
            ApiClient.service.getMessageCount(LoginShared.getAccessToken(this), new CallbackAdapter<Result<Integer>>() {

                @Override
                public void success(Result<Integer> result, Response response) {
                    if (result.getData() <= 0) {
                        tvBadgerNotification.setText(null);
                    } else if (result.getData() > 99) {
                        tvBadgerNotification.setText("99+");
                    } else {
                        tvBadgerNotification.setText(String.valueOf(result.getData()));
                    }
                }

            });
        }
    }

    /**
     * 用户信息更新逻辑
     */

    private DrawerLayout.DrawerListener openDrawerListener = new DrawerLayout.SimpleDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            updateUserInfoViews();
            getUserAsycnTask();
            getMessageCountAsyncTask();
        }

    };

{'fraction_non_alphanumeric': 0.09225856563390006, 'fraction_numerical': 0.003969966341589712, 'mean_word_length': 3.2478005865102637, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4670299', 'n_tokens_mistral': 3593, 'n_tokens_neox': 3512, 'n_words': 525}