<commit_before>package de.danoeh.antennapod.fragment;

import de.danoeh.antennapod.activity.*;
import de.danoeh.antennapod.adapter.FeedlistAdapter;
import de.danoeh.antennapod.asynctask.FeedRemover;
import de.danoeh.antennapod.dialog.ConfirmationDialog;
import de.danoeh.antennapod.feed.*;
import de.danoeh.antennapod.service.download.DownloadService;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import android.os.AsyncTask;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import android.util.Log;

public class FeedlistFragment extends SherlockFragment implements
		ActionMode.Callback, AdapterView.OnItemClickListener,
		AdapterView.OnItemLongClickListener {
	private static final String TAG = "FeedlistFragment";
	public static final String EXTRA_SELECTED_FEED = "extra.de.danoeh.antennapod.activity.selected_feed";

	private FeedManager manager;
	private FeedlistAdapter fla;
	private SherlockFragmentActivity pActivity;

	private Feed selectedFeed;
	private ActionMode mActionMode;

	private GridView gridView;
	private ListView listView;
	private TextView txtvEmpty;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		pActivity = (SherlockFragmentActivity) activity;
	}

	@Override
	public void onDetach() {
		super.onDetach();
		pActivity = null;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (AppConfig.DEBUG)
			Log.d(TAG, "Creating");
		manager = FeedManager.getInstance();
		fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds());

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View result = inflater.inflate(R.layout.feedlist, container, false);
		listView = (ListView) result.findViewById(android.R.id.list);
		gridView = (GridView) result.findViewById(R.id.grid);
		txtvEmpty = (TextView) result.findViewById(android.R.id.empty);

		return result;

	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		if (listView != null) {
			listView.setOnItemClickListener(this);
			listView.setOnItemLongClickListener(this);
			listView.setAdapter(fla);
			listView.setEmptyView(txtvEmpty);
			if (AppConfig.DEBUG)
				Log.d(TAG, "Using ListView");
		} else {
			gridView.setOnItemClickListener(this);
			gridView.setOnItemLongClickListener(this);
			gridView.setAdapter(fla);
			gridView.setEmptyView(txtvEmpty);
			if (AppConfig.DEBUG)
				Log.d(TAG, "Using GridView");
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		if (AppConfig.DEBUG)
			Log.d(TAG, "Resuming");
		IntentFilter filter = new IntentFilter();
		filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED);
		filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE);
		filter.addAction(FeedManager.ACITON_FEED_LIST_UPDATE);
		filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED);
		pActivity.registerReceiver(contentUpdate, filter);
		fla.notifyDataSetChanged();
	}

	@Override
	public void onPause() {
		super.onPause();
		pActivity.unregisterReceiver(contentUpdate);
		if (mActionMode != null) {
			mActionMode.finish();
		}
	}

	private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, final Intent intent) {
			if (AppConfig.DEBUG)
				Log.d(TAG, "Received contentUpdate Intent.");
			getActivity().runOnUiThread(new Runnable() {

				@Override
				public void run() {
					if (intent.getAction().equals(
							DownloadService.ACTION_DOWNLOAD_HANDLED)) {
						int type = intent.getIntExtra(DownloadService.EXTRA_DOWNLOAD_TYPE, 0);
						if (type == DownloadService.DOWNLOAD_TYPE_IMAGE) {
							fla.notifyDataSetChanged();
						}
					} else {
						fla.notifyDataSetChanged();
					}
				}
			});
		}
	};

	@Override
	public boolean onCreateActionMode(ActionMode mode, Menu menu) {
		FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu);
		mode.setTitle(selectedFeed.getTitle());
		return true;
	}

	@Override
	public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
		return FeedMenuHandler.onPrepareOptionsMenu(menu, selectedFeed);
	}

	@SuppressLint("NewApi")<commit_msg>FeedlistFragment now refreshes more frequently<commit_after>package de.danoeh.antennapod.fragment;

import de.danoeh.antennapod.activity.*;
import de.danoeh.antennapod.adapter.FeedlistAdapter;
import de.danoeh.antennapod.asynctask.FeedRemover;
import de.danoeh.antennapod.dialog.ConfirmationDialog;
import de.danoeh.antennapod.feed.*;
import de.danoeh.antennapod.service.download.DownloadService;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import android.os.AsyncTask;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import android.util.Log;

public class FeedlistFragment extends SherlockFragment implements
		ActionMode.Callback, AdapterView.OnItemClickListener,
		AdapterView.OnItemLongClickListener {
	private static final String TAG = "FeedlistFragment";
	public static final String EXTRA_SELECTED_FEED = "extra.de.danoeh.antennapod.activity.selected_feed";

	private FeedManager manager;
	private FeedlistAdapter fla;
	private SherlockFragmentActivity pActivity;

	private Feed selectedFeed;
	private ActionMode mActionMode;

	private GridView gridView;
	private ListView listView;
	private TextView txtvEmpty;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		pActivity = (SherlockFragmentActivity) activity;
	}

	@Override
	public void onDetach() {
		super.onDetach();
		pActivity = null;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (AppConfig.DEBUG)
			Log.d(TAG, "Creating");
		manager = FeedManager.getInstance();
		fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds());

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View result = inflater.inflate(R.layout.feedlist, container, false);
		listView = (ListView) result.findViewById(android.R.id.list);
		gridView = (GridView) result.findViewById(R.id.grid);
		txtvEmpty = (TextView) result.findViewById(android.R.id.empty);

		return result;

	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		if (listView != null) {
			listView.setOnItemClickListener(this);
			listView.setOnItemLongClickListener(this);
			listView.setAdapter(fla);
			listView.setEmptyView(txtvEmpty);
			if (AppConfig.DEBUG)
				Log.d(TAG, "Using ListView");
		} else {
			gridView.setOnItemClickListener(this);
			gridView.setOnItemLongClickListener(this);
			gridView.setAdapter(fla);
			gridView.setEmptyView(txtvEmpty);
			if (AppConfig.DEBUG)
				Log.d(TAG, "Using GridView");
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		if (AppConfig.DEBUG)
			Log.d(TAG, "Resuming");
		IntentFilter filter = new IntentFilter();
		filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED);
		filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE);
		filter.addAction(FeedManager.ACITON_FEED_LIST_UPDATE);
		filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED);
		pActivity.registerReceiver(contentUpdate, filter);
		fla.notifyDataSetChanged();
	}

	@Override
	public void onPause() {
		super.onPause();
		pActivity.unregisterReceiver(contentUpdate);
		if (mActionMode != null) {
			mActionMode.finish();
		}
	}

	private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, final Intent intent) {
			if (AppConfig.DEBUG)
				Log.d(TAG, "Received contentUpdate Intent.");
			getActivity().runOnUiThread(new Runnable() {

				@Override
				public void run() {
					fla.notifyDataSetChanged();
				}
			});
		}
	};

	@Override
	public boolean onCreateActionMode(ActionMode mode, Menu menu) {
		FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu);
		mode.setTitle(selectedFeed.getTitle());
		return true;
	}

	@Override
	public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
		return FeedMenuHandler.onPrepareOptionsMenu(menu, selectedFeed);
	}

	@SuppressLint("NewApi")
{'fraction_non_alphanumeric': 0.10085436511833448, 'fraction_numerical': 0.0002946086614946479, 'mean_word_length': 5.708827404479578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3431726', 'n_tokens_mistral': 3464, 'n_tokens_neox': 3132, 'n_words': 585}