Fixed crash which occured when entering the teamselection menu for the second time hedgeroid
authorXeli
Fri, 19 Aug 2011 03:29:51 +0200
branchhedgeroid
changeset 5603 4e4a579a60af
parent 5601 92a7336043d6
child 5605 31bd6e30df02
Fixed crash which occured when entering the teamselection menu for the second time
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/FrontendDataUtils.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/FrontendDataUtils.java	Thu Aug 18 22:37:47 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/FrontendDataUtils.java	Fri Aug 19 03:29:51 2011 +0200
@@ -148,8 +148,8 @@
 		return data;
 	}
 
-	public static ArrayList<HashMap<String, ?>> getTeams(Context c){
-		ArrayList<HashMap<String, ?>> ret = new ArrayList<HashMap<String, ?>>();
+	public static ArrayList<HashMap<String, Object>> getTeams(Context c){
+		ArrayList<HashMap<String, Object>> ret = new ArrayList<HashMap<String, Object>>();
 
 		File teamsDir = new File(c.getFilesDir().getAbsolutePath() + '/' + Team.DIRECTORY_TEAMS);
 		File[] teamFileNames = teamsDir.listFiles();
@@ -168,6 +168,8 @@
 		HashMap<String, Object> hashmap = new HashMap<String, Object>();
 		hashmap.put("team", t);
 		hashmap.put("txt", t.name);
+		hashmap.put("color", t.color);
+		hashmap.put("count", t.hogCount);
 		switch(t.levels[0]){
 		case 0:
 			hashmap.put("img", R.drawable.human);
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java	Thu Aug 18 22:37:47 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java	Fri Aug 19 03:29:51 2011 +0200
@@ -31,7 +31,7 @@
 	
 	private ImageButton addTeam, back;
 	private ListView availableTeams, selectedTeams;
-	private ArrayList<HashMap<String, ?>> availableTeamsList, selectedTeamsList;
+	private ArrayList<HashMap<String, Object>> availableTeamsList, selectedTeamsList;
 	private int minTeams = 2;
 
 	public void onCreate(Bundle savedInstanceState){
@@ -53,14 +53,14 @@
 		availableTeams.setOnItemClickListener(availableClicker);
 
 		selectedTeams = (ListView) findViewById(R.id.selectedTeams);
-		selectedTeamsList = new ArrayList<HashMap<String, ?>>();
+		selectedTeamsList = new ArrayList<HashMap<String, Object>>();
 		ArrayList<HashMap<String, ?>> toBeRemoved = new ArrayList<HashMap<String, ?>>();
 		ArrayList<Team> teamsStartGame = getIntent().getParcelableArrayListExtra("teams");
-		for(HashMap<String, ?> hashmap : availableTeamsList){
+		for(HashMap<String, Object> hashmap : availableTeamsList){
 			for(Team t : teamsStartGame){
 				if(((Team)hashmap.get("team")).equals(t)){
 					toBeRemoved.add(hashmap);
-					selectedTeamsList.add(hashmap);
+					selectedTeamsList.add(FrontendDataUtils.teamToHashMap(t));//create a new hashmap to ensure all variables are entered into the map
 				}
 			}
 		}
@@ -101,14 +101,18 @@
 	private void updateListViews(){
 		unregisterForContextMenu(availableTeams);
 		availableTeamsList = FrontendDataUtils.getTeams(this);
-		for(HashMap<String, ?> hashmap : selectedTeamsList){
+		ArrayList<HashMap<String, Object>> toBeRemoved = new ArrayList<HashMap<String, Object>>();
+		for(HashMap<String, Object> hashmap : selectedTeamsList){
 			String name = (String)hashmap.get("txt");
-			for(HashMap<String, ?> hash : availableTeamsList){
+			
+			for(HashMap<String, Object> hash : availableTeamsList){
 				if(name.equals((String)hash.get("txt"))){
-					availableTeamsList.remove(hash);
+					toBeRemoved.add(hash);
 				}
 			}
 		}
+		for(HashMap<String, Object> hash: toBeRemoved) availableTeamsList.remove(hash);
+		
 		SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty});
 		availableTeams.setAdapter(adapter);
 		registerForContextMenu(availableTeams);
@@ -191,7 +195,7 @@
 	};
 	private OnItemClickListener selectedClicker = new OnItemClickListener(){
 		public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) {
-			availableTeamsList.add((HashMap<String, ?>) selectedTeamsList.get(position));
+			availableTeamsList.add((HashMap<String, Object>) selectedTeamsList.get(position));
 			selectedTeamsList.remove(position);
 			((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged();
 			((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged();