<commit_before>package com.comic.chhreader;

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

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.ActionBar;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.DateUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Toast;

import com.comic.chhreader.clean.CleanService;
import com.comic.chhreader.content.PullContentActivity;
import com.comic.chhreader.data.ContentData;
import com.comic.chhreader.data.RssNews;
import com.comic.chhreader.data.SubItemData;
import com.comic.chhreader.data.TopicData;
import com.comic.chhreader.gallery.GalleryRootView;
import com.comic.chhreader.provider.DataProvider;
import com.comic.chhreader.utils.CHHNetUtils;
import com.comic.chhreader.utils.DataBaseUtils;
import com.comic.chhreader.utils.FileOperation;
import com.comic.chhreader.utils.SharedPreferencesUtils;
import com.comic.chhreader.utils.Utils;
import com.comic.chhreader.view.NetworkDialog;

public class MainActivity extends Activity implements OnItemClickListener, LoaderCallbacks<Cursor> {

	private static final int LOADER_ID_LOACL = 103;

	private static final long UPGRADE_GAP = DateUtils.DAY_IN_MILLIS;

	private ScrollView mScrollView;
	private GalleryRootView mGalleryRootView;

	private GridView mGrid;
	private MainGridAdapter mGirdAdapter;

	private ProgressBar mLoadingProgress;

	private Context mContext = this;
	private NetworkDialog mNetworkDialog = null;

	private boolean updating = false;
	private boolean mNoImage = true;

	private List<RssNews> mENews = new ArrayList<RssNews>();

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

		Intent cleanService = new Intent();
		cleanService.setClass(MainActivity.this, CleanService.class);
		startService(cleanService);

		mScrollView = (ScrollView) findViewById(R.id.scroll_view);
		mScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
		mScrollView.setVerticalScrollBarEnabled(false);
		mScrollView.setHorizontalScrollBarEnabled(false);

		mGalleryRootView = (GalleryRootView) findViewById(R.id.news);

		mGrid = (GridView) findViewById(R.id.main_gird);
		mGrid.setOnItemClickListener(this);

		mGirdAdapter = new MainGridAdapter(this, null);

		if (SharedPreferencesUtils.getNoImageMode(mContext) && !Utils.isWifiAvailable(mContext)) {
			mNoImage = true;
		} else {
			mNoImage = false;
		}

		mGirdAdapter.setNoImage(mNoImage);

		mGrid.setAdapter(mGirdAdapter);

		initActionBar();

		mScrollView.scrollTo(0, 0);

		mScrollView.setAlpha(0f);
		mScrollView.animate().alpha(1f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
			@Override
			public void onAnimationEnd(Animator animation) {
				mScrollView.setVisibility(View.VISIBLE);
			}
		});
		new FetchNewsTaskLocal().execute();
		getLoaderManager().initLoader(LOADER_ID_LOACL, null, this);

		if (Utils.isWifiAvailable(mContext) && !updating) {
			new FetchDataTaskNet().execute();
		}
	}

	void initActionBar() {
		ActionBar actionBar = getActionBar();
		if (actionBar != null) {
			actionBar.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.action_bar_bg));
			// actionBar.setIcon(R.drawable.title_icon);

			Loge.i("action bar setCustomView");
			LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View actionbarView = inflator.inflate(R.layout.main_activity_actionbar, null);
			LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
					Gravity.RIGHT | Gravity.CENTER_VERTICAL);
			actionBar.setCustomView(actionbarView, lp);
			actionBar.setDisplayShowCustomEnabled(true);
			actionBar.setDisplayUseLogoEnabled(false);
			actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

			mLoadingProgress = (ProgressBar) actionbarView.findViewById(R.id.action_loading);
			mLoadingProgress.setVisibility(View.GONE);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		MenuItem no_image = menu.findItem(R.id.action_no_image);
		no_image.setChecked(SharedPreferencesUtils.getNoImageMode(mContext));
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.action_do_refresh: {
				Loge.i("Options Selected = do_refresh");
				if (!updating)
					new FetchDataTaskNet().execute();
			}
				break;
			case R.id.action_no_image: {
				Loge.i("Options Selected = no_image");
				boolean state = SharedPreferencesUtils.getNoImageMode(mContext);
				item.setChecked(!state);
				SharedPreferencesUtils.saveNoImageMode(mContext, !state);
			}
				break;
			default:
				break;
		}
		return super.onOptionsItemSelected(item);<commit_msg>add refreh item<commit_after>package com.comic.chhreader;

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

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.ActionBar;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.DateUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Toast;

import com.comic.chhreader.clean.CleanService;
import com.comic.chhreader.content.PullContentActivity;
import com.comic.chhreader.data.ContentData;
import com.comic.chhreader.data.RssNews;
import com.comic.chhreader.data.SubItemData;
import com.comic.chhreader.data.TopicData;
import com.comic.chhreader.gallery.GalleryRootView;
import com.comic.chhreader.provider.DataProvider;
import com.comic.chhreader.utils.CHHNetUtils;
import com.comic.chhreader.utils.DataBaseUtils;
import com.comic.chhreader.utils.FileOperation;
import com.comic.chhreader.utils.SharedPreferencesUtils;
import com.comic.chhreader.utils.Utils;
import com.comic.chhreader.view.NetworkDialog;

public class MainActivity extends Activity implements OnItemClickListener, LoaderCallbacks<Cursor> {

	private static final int LOADER_ID_LOACL = 103;

	private static final long UPGRADE_GAP = DateUtils.DAY_IN_MILLIS;

	private ScrollView mScrollView;
	private GalleryRootView mGalleryRootView;

	private GridView mGrid;
	private MainGridAdapter mGirdAdapter;

	private ProgressBar mLoadingProgress;

	private Context mContext = this;
	private NetworkDialog mNetworkDialog = null;

	private boolean updating = false;
	private boolean mNoImage = true;

	private List<RssNews> mENews = new ArrayList<RssNews>();

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

		Intent cleanService = new Intent();
		cleanService.setClass(MainActivity.this, CleanService.class);
		startService(cleanService);

		mScrollView = (ScrollView) findViewById(R.id.scroll_view);
		mScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
		mScrollView.setVerticalScrollBarEnabled(false);
		mScrollView.setHorizontalScrollBarEnabled(false);

		mGalleryRootView = (GalleryRootView) findViewById(R.id.news);

		mGrid = (GridView) findViewById(R.id.main_gird);
		mGrid.setOnItemClickListener(this);

		mGirdAdapter = new MainGridAdapter(this, null);

		if (SharedPreferencesUtils.getNoImageMode(mContext) && !Utils.isWifiAvailable(mContext)) {
			mNoImage = true;
		} else {
			mNoImage = false;
		}

		mGirdAdapter.setNoImage(mNoImage);

		mGrid.setAdapter(mGirdAdapter);

		initActionBar();

		mScrollView.scrollTo(0, 0);

		mScrollView.setAlpha(0f);
		mScrollView.animate().alpha(1f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
			@Override
			public void onAnimationEnd(Animator animation) {
				mScrollView.setVisibility(View.VISIBLE);
			}
		});
		new FetchNewsTaskLocal().execute();
		getLoaderManager().initLoader(LOADER_ID_LOACL, null, this);

		if (Utils.isWifiAvailable(mContext) && !updating) {
			new FetchDataTaskNet().execute();
		}
	}

	void initActionBar() {
		ActionBar actionBar = getActionBar();
		if (actionBar != null) {
			actionBar.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.action_bar_bg));
			// actionBar.setIcon(R.drawable.title_icon);

			Loge.i("action bar setCustomView");
			LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View actionbarView = inflator.inflate(R.layout.main_activity_actionbar, null);
			LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
					Gravity.RIGHT | Gravity.CENTER_VERTICAL);
			actionBar.setCustomView(actionbarView, lp);
			actionBar.setDisplayShowCustomEnabled(true);
			actionBar.setDisplayUseLogoEnabled(false);
			actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

			mLoadingProgress = (ProgressBar) actionbarView.findViewById(R.id.action_loading);
			mLoadingProgress.setVisibility(View.GONE);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		MenuItem no_image = menu.findItem(R.id.action_no_image);
		no_image.setChecked(SharedPreferencesUtils.getNoImageMode(mContext));
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.action_do_refresh: {
				Loge.i("Options Selected = do_refresh");
				if (!updating){
					new FetchDataTaskNet().execute();
					new FetchNewsTaskNet().execute();
				}

			}
				break;
			case R.id.action_no_image: {
				Loge.i("Options Selected = no_image");
				boolean state = SharedPreferencesUtils.getNoImageMode(mContext);
				item.setChecked(!state);
				SharedPreferencesUtils.saveNoImageMode(mContext, !state);
			}
				break;
			default:
				break;
		}
		return super.onOptionsItemSelected(item);
{'fraction_non_alphanumeric': 0.1026854802002731, 'fraction_numerical': 0.002002730996813837, 'mean_word_length': 5.8964218455743875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '964698', 'n_tokens_mistral': 3789, 'n_tokens_neox': 3418, 'n_words': 579}