<commit_before>package com.namelessdev.mpdroid;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.a0z.mpd.MPD;
import org.a0z.mpd.MPDServerException;
import org.a0z.mpd.Music;

import com.namelessdev.mpdroid.MPDAsyncHelper.AsyncExecListener;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SearchAlbumActivity extends ListActivity implements AsyncExecListener {
	private LinkedList<String> items;
	private List<String> itemsList = null;
	private int iJobID = -1;
	private ProgressDialog pd;
	String searchKeywords = "";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		final Intent queryIntent = getIntent();
		final String queryAction = queryIntent.getAction();
		
		if (Intent.ACTION_SEARCH.equals(queryAction)) {
			searchKeywords = queryIntent.getStringExtra(SearchManager.QUERY);
		} else {
			return; //Bye !
		}
		setContentView(R.layout.artists);
		setTitle(getTitle()+" : "+searchKeywords);
		pd = ProgressDialog.show(SearchAlbumActivity.this, getResources().getString(R.string.loading), getResources().getString(R.string.loadingArtists));		
		//setTitle(getResources().getString(R.string.albums));
		MPDApplication app = (MPDApplication)getApplication();
		// Loading Albums asynchronous...
		itemsList = new ArrayList<String>();
		app.oMPDAsyncHelper.addAsyncExecListener(this);
		iJobID = app.oMPDAsyncHelper.execAsync(new Runnable(){
			@Override
			public void run() 
			{
				try {
					MPDApplication app = (MPDApplication)getApplication();
					items = app.oMPDAsyncHelper.oMPD.listAlbums();
				} catch (MPDServerException e) {
					
				}
			}
		});
		
		
	}

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
            Intent intent = new Intent(this, SongsActivity.class);
            intent.putExtra("album", itemsList.get(position));
            startActivityForResult(intent, -1);
    }
	
	@Override
	public void asyncExecSucceeded(int jobID) {
		// TODO Auto-generated method stub
		if(iJobID == jobID)
		{
			searchKeywords = searchKeywords.toLowerCase().trim();
			for (String music : items) {
				if(music.toLowerCase().contains(searchKeywords))
					itemsList.add(music);
			}
			// Use the ListViewButtonAdapter class to show the albums
			ListViewButtonAdapter<String> almumsAdapter = new ListViewButtonAdapter<String>(SearchAlbumActivity.this, android.R.layout.simple_list_item_1, itemsList);
			
			PlusListener AddListener = new PlusListener() {
				@Override
				public void OnAdd(CharSequence sSelected, int iPosition)
				{
					try {
						MPDApplication app = (MPDApplication)getApplication();
						ArrayList<Music> songs = new ArrayList<Music>(app.oMPDAsyncHelper.oMPD.find(MPD.MPD_FIND_ALBUM, sSelected.toString()));
						app.oMPDAsyncHelper.oMPD.getPlaylist().add(songs);
						MainMenuActivity.notifyUser(String.format(getResources().getString(R.string.albumAdded),sSelected), SearchAlbumActivity.this);
					} catch (MPDServerException e) {
						e.printStackTrace();
					}
				}
			};
			getListView().setOnItemLongClickListener( new AdapterView.OnItemLongClickListener (){
                @Override
                public boolean onItemLongClick(AdapterView<?> av, View v, int position, long id) {
					try {
						MainMenuActivity.notifyUser(String.format(getResources().getString(R.string.albumAdded),itemsList.get(position)), SearchAlbumActivity.this);
						MPDApplication app = (MPDApplication)getApplication();<commit_msg>Not a stub anymore<commit_after>package com.namelessdev.mpdroid;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.a0z.mpd.MPD;
import org.a0z.mpd.MPDServerException;
import org.a0z.mpd.Music;

import com.namelessdev.mpdroid.MPDAsyncHelper.AsyncExecListener;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SearchAlbumActivity extends ListActivity implements AsyncExecListener {
	private LinkedList<String> items;
	private List<String> itemsList = null;
	private int iJobID = -1;
	private ProgressDialog pd;
	String searchKeywords = "";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		final Intent queryIntent = getIntent();
		final String queryAction = queryIntent.getAction();
		
		if (Intent.ACTION_SEARCH.equals(queryAction)) {
			searchKeywords = queryIntent.getStringExtra(SearchManager.QUERY);
		} else {
			return; //Bye !
		}
		setContentView(R.layout.artists);
		setTitle(getTitle()+" : "+searchKeywords);
		pd = ProgressDialog.show(SearchAlbumActivity.this, getResources().getString(R.string.loading), getResources().getString(R.string.loadingArtists));		
		//setTitle(getResources().getString(R.string.albums));
		MPDApplication app = (MPDApplication)getApplication();
		// Loading Albums asynchronous...
		itemsList = new ArrayList<String>();
		app.oMPDAsyncHelper.addAsyncExecListener(this);
		iJobID = app.oMPDAsyncHelper.execAsync(new Runnable(){
			@Override
			public void run() 
			{
				try {
					MPDApplication app = (MPDApplication)getApplication();
					items = app.oMPDAsyncHelper.oMPD.listAlbums();
				} catch (MPDServerException e) {
					
				}
			}
		});
		
		
	}

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
            Intent intent = new Intent(this, SongsActivity.class);
            intent.putExtra("album", itemsList.get(position));
            startActivityForResult(intent, -1);
    }
	
	@Override
	public void asyncExecSucceeded(int jobID) {
		if(iJobID == jobID)
		{
			searchKeywords = searchKeywords.toLowerCase().trim();
			for (String music : items) {
				if(music.toLowerCase().contains(searchKeywords))
					itemsList.add(music);
			}
			// Use the ListViewButtonAdapter class to show the albums
			ListViewButtonAdapter<String> almumsAdapter = new ListViewButtonAdapter<String>(SearchAlbumActivity.this, android.R.layout.simple_list_item_1, itemsList);
			
			PlusListener AddListener = new PlusListener() {
				@Override
				public void OnAdd(CharSequence sSelected, int iPosition)
				{
					try {
						MPDApplication app = (MPDApplication)getApplication();
						ArrayList<Music> songs = new ArrayList<Music>(app.oMPDAsyncHelper.oMPD.find(MPD.MPD_FIND_ALBUM, sSelected.toString()));
						app.oMPDAsyncHelper.oMPD.getPlaylist().add(songs);
						MainMenuActivity.notifyUser(String.format(getResources().getString(R.string.albumAdded),sSelected), SearchAlbumActivity.this);
					} catch (MPDServerException e) {
						e.printStackTrace();
					}
				}
			};
			getListView().setOnItemLongClickListener( new AdapterView.OnItemLongClickListener (){
                @Override
                public boolean onItemLongClick(AdapterView<?> av, View v, int position, long id) {
					try {
						MainMenuActivity.notifyUser(String.format(getResources().getString(R.string.albumAdded),itemsList.get(position)), SearchAlbumActivity.this);
						MPDApplication app = (MPDApplication)getApplication();
{'fraction_non_alphanumeric': 0.11051948051948052, 'fraction_numerical': 0.0015584415584415584, 'mean_word_length': 4.430888575458392, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5561556', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2256, 'n_words': 434}