project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java
branchhedgeroid
changeset 5603 4e4a579a60af
parent 5542 141c12a23787
child 5621 ea796c83ea47
equal deleted inserted replaced
5601:92a7336043d6 5603:4e4a579a60af
    29 
    29 
    30 	private static final int ACTIVITY_TEAMCREATION = 0;
    30 	private static final int ACTIVITY_TEAMCREATION = 0;
    31 	
    31 	
    32 	private ImageButton addTeam, back;
    32 	private ImageButton addTeam, back;
    33 	private ListView availableTeams, selectedTeams;
    33 	private ListView availableTeams, selectedTeams;
    34 	private ArrayList<HashMap<String, ?>> availableTeamsList, selectedTeamsList;
    34 	private ArrayList<HashMap<String, Object>> availableTeamsList, selectedTeamsList;
    35 	private int minTeams = 2;
    35 	private int minTeams = 2;
    36 
    36 
    37 	public void onCreate(Bundle savedInstanceState){
    37 	public void onCreate(Bundle savedInstanceState){
    38 		super.onCreate(savedInstanceState);
    38 		super.onCreate(savedInstanceState);
    39 
    39 
    51 		availableTeams.setAdapter(adapter);
    51 		availableTeams.setAdapter(adapter);
    52 		registerForContextMenu(availableTeams);
    52 		registerForContextMenu(availableTeams);
    53 		availableTeams.setOnItemClickListener(availableClicker);
    53 		availableTeams.setOnItemClickListener(availableClicker);
    54 
    54 
    55 		selectedTeams = (ListView) findViewById(R.id.selectedTeams);
    55 		selectedTeams = (ListView) findViewById(R.id.selectedTeams);
    56 		selectedTeamsList = new ArrayList<HashMap<String, ?>>();
    56 		selectedTeamsList = new ArrayList<HashMap<String, Object>>();
    57 		ArrayList<HashMap<String, ?>> toBeRemoved = new ArrayList<HashMap<String, ?>>();
    57 		ArrayList<HashMap<String, ?>> toBeRemoved = new ArrayList<HashMap<String, ?>>();
    58 		ArrayList<Team> teamsStartGame = getIntent().getParcelableArrayListExtra("teams");
    58 		ArrayList<Team> teamsStartGame = getIntent().getParcelableArrayListExtra("teams");
    59 		for(HashMap<String, ?> hashmap : availableTeamsList){
    59 		for(HashMap<String, Object> hashmap : availableTeamsList){
    60 			for(Team t : teamsStartGame){
    60 			for(Team t : teamsStartGame){
    61 				if(((Team)hashmap.get("team")).equals(t)){
    61 				if(((Team)hashmap.get("team")).equals(t)){
    62 					toBeRemoved.add(hashmap);
    62 					toBeRemoved.add(hashmap);
    63 					selectedTeamsList.add(hashmap);
    63 					selectedTeamsList.add(FrontendDataUtils.teamToHashMap(t));//create a new hashmap to ensure all variables are entered into the map
    64 				}
    64 				}
    65 			}
    65 			}
    66 		}
    66 		}
    67 		for(HashMap<String, ?> hashmap : toBeRemoved) availableTeamsList.remove(hashmap);
    67 		for(HashMap<String, ?> hashmap : toBeRemoved) availableTeamsList.remove(hashmap);
    68 
    68 
    99 	}
    99 	}
   100 	
   100 	
   101 	private void updateListViews(){
   101 	private void updateListViews(){
   102 		unregisterForContextMenu(availableTeams);
   102 		unregisterForContextMenu(availableTeams);
   103 		availableTeamsList = FrontendDataUtils.getTeams(this);
   103 		availableTeamsList = FrontendDataUtils.getTeams(this);
   104 		for(HashMap<String, ?> hashmap : selectedTeamsList){
   104 		ArrayList<HashMap<String, Object>> toBeRemoved = new ArrayList<HashMap<String, Object>>();
       
   105 		for(HashMap<String, Object> hashmap : selectedTeamsList){
   105 			String name = (String)hashmap.get("txt");
   106 			String name = (String)hashmap.get("txt");
   106 			for(HashMap<String, ?> hash : availableTeamsList){
   107 			
       
   108 			for(HashMap<String, Object> hash : availableTeamsList){
   107 				if(name.equals((String)hash.get("txt"))){
   109 				if(name.equals((String)hash.get("txt"))){
   108 					availableTeamsList.remove(hash);
   110 					toBeRemoved.add(hash);
   109 				}
   111 				}
   110 			}
   112 			}
   111 		}
   113 		}
       
   114 		for(HashMap<String, Object> hash: toBeRemoved) availableTeamsList.remove(hash);
       
   115 		
   112 		SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty});
   116 		SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty});
   113 		availableTeams.setAdapter(adapter);
   117 		availableTeams.setAdapter(adapter);
   114 		registerForContextMenu(availableTeams);
   118 		registerForContextMenu(availableTeams);
   115 		availableTeams.setOnItemClickListener(availableClicker);
   119 		availableTeams.setOnItemClickListener(availableClicker);
   116 		
   120 		
   189 			selectAvailableTeamsItem(position);
   193 			selectAvailableTeamsItem(position);
   190 		}
   194 		}
   191 	};
   195 	};
   192 	private OnItemClickListener selectedClicker = new OnItemClickListener(){
   196 	private OnItemClickListener selectedClicker = new OnItemClickListener(){
   193 		public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) {
   197 		public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) {
   194 			availableTeamsList.add((HashMap<String, ?>) selectedTeamsList.get(position));
   198 			availableTeamsList.add((HashMap<String, Object>) selectedTeamsList.get(position));
   195 			selectedTeamsList.remove(position);
   199 			selectedTeamsList.remove(position);
   196 			((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged();
   200 			((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged();
   197 			((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged();
   201 			((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged();
   198 		}
   202 		}
   199 
   203