// Path: src/fr/xtof54/jsgo/EventManager.java
// enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady,
// 	msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
// 
// Path: src/fr/xtof54/jsgo/GoJsActivity.java
// enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums};


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import fr.xtof54.jsgo.R;
import fr.xtof54.jsgo.EventManager.eventType;
import fr.xtof54.jsgo.GoJsActivity.guistate;
			}
		});
		if (savedGames!=null) {
			for (File f: savedGames) {
				int i=Integer.parseInt(f.getName().substring(6, f.getName().length()-4));
				games.add(i);
			}
		}
		int[] gs = new int[games.size()];
		int j=0; for (int i:games) gs[j++]=i;
		return gs;
	}

	public static void loadStatusGames(final ServerConnection server) {
		Thread push = new Thread(new Runnable() {
			@Override
			public void run() {
				final EventManager em = EventManager.getEventManager();
				if (GoJsActivity.main.getGamesFromDGS) {
					System.out.println("DGSAPP loadstatusgame DGS ");
					// this listener will be called when list if downloaded
					EventManager.EventListener f = new EventManager.EventListener() {
						@Override
						public synchronized void reactToEvent() {
							JSONObject o = server.o;
							parseJSONStatusGames(o);
							// also connects now to the client server to give it time to connect correctly
//							if (games2play.size() > 0) WSclient.init(games2play.get(0).myid);

							System.out.println("DGSAPP end of loadstatusgame, unregistering listener " + games2play.size());
// Path: src/fr/xtof54/jsgo/EventManager.java
// enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady,
// 	msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
// 
// Path: src/fr/xtof54/jsgo/GoJsActivity.java
// enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums};


// Path: src/fr/xtof54/jsgo/Game.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import fr.xtof54.jsgo.R;
import fr.xtof54.jsgo.EventManager.eventType;
import fr.xtof54.jsgo.GoJsActivity.guistate;

			}
		});
		if (savedGames!=null) {
			for (File f: savedGames) {
				int i=Integer.parseInt(f.getName().substring(6, f.getName().length()-4));
				games.add(i);
			}
		}
		int[] gs = new int[games.size()];
		int j=0; for (int i:games) gs[j++]=i;
		return gs;
	}

	public static void loadStatusGames(final ServerConnection server) {
		Thread push = new Thread(new Runnable() {
			@Override
			public void run() {
				final EventManager em = EventManager.getEventManager();
				if (GoJsActivity.main.getGamesFromDGS) {
					System.out.println("DGSAPP loadstatusgame DGS ");
					// this listener will be called when list if downloaded
					EventManager.EventListener f = new EventManager.EventListener() {
						@Override
						public synchronized void reactToEvent() {
							JSONObject o = server.o;
							parseJSONStatusGames(o);
							// also connects now to the client server to give it time to connect correctly
//							if (games2play.size() > 0) WSclient.init(games2play.get(0).myid);

							System.out.println("DGSAPP end of loadstatusgame, unregistering listener " + games2play.size());
							em.unregisterListener(eventType.downloadListEnd, this);