project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomlistAdapter.java
changeset 10017 de822cd3df3a
parent 7584 7831c84cc644
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    35 
    35 
    36 /**
    36 /**
    37  * Displays the list of all rooms in the lobby
    37  * Displays the list of all rooms in the lobby
    38  */
    38  */
    39 public class RoomlistAdapter extends ObservableTreeMapAdapter<String, RoomWithId> {
    39 public class RoomlistAdapter extends ObservableTreeMapAdapter<String, RoomWithId> {
    40 	private Context context;
    40     private Context context;
    41 	
    41 
    42 	public RoomlistAdapter(Context context) {
    42     public RoomlistAdapter(Context context) {
    43 		this.context = context;
    43         this.context = context;
    44 	}
    44     }
    45 	
    45 
    46 	@Override
    46     @Override
    47 	protected Comparator<RoomWithId> getEntryOrder() {
    47     protected Comparator<RoomWithId> getEntryOrder() {
    48 		return RoomWithId.NEWEST_FIRST_ORDER;
    48         return RoomWithId.NEWEST_FIRST_ORDER;
    49 	}
    49     }
    50 	
    50 
    51 	@Override
    51     @Override
    52 	public long getItemId(int position) {
    52     public long getItemId(int position) {
    53 		return getItem(position).id;
    53         return getItem(position).id;
    54 	}
    54     }
    55 	
    55 
    56 	@Override
    56     @Override
    57 	public boolean hasStableIds() {
    57     public boolean hasStableIds() {
    58 		return true;
    58         return true;
    59 	}
    59     }
    60 	
    60 
    61 	private static CharSequence formatExtra(Resources res, Room room) {
    61     private static CharSequence formatExtra(Resources res, Room room) {
    62 		String ownermsg = res.getString(R.string.roomlist_owner, room.owner);
    62         String ownermsg = res.getString(R.string.roomlist_owner, room.owner);
    63 		String mapmsg = res.getString(R.string.roomlist_map, room.formatMapName(res));
    63         String mapmsg = res.getString(R.string.roomlist_map, room.formatMapName(res));
    64 		String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons;
    64         String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons;
    65 		String schememsg = res.getString(R.string.roomlist_scheme, scheme);
    65         String schememsg = res.getString(R.string.roomlist_scheme, scheme);
    66 		return ownermsg + ". " + mapmsg + ", " + schememsg;
    66         return ownermsg + ". " + mapmsg + ", " + schememsg;
    67 	}
    67     }
    68 	
    68 
    69 	public View getView(int position, View convertView, ViewGroup parent) {
    69     public View getView(int position, View convertView, ViewGroup parent) {
    70 		View v = convertView;
    70         View v = convertView;
    71 		if (v == null) {
    71         if (v == null) {
    72 			LayoutInflater vi = LayoutInflater.from(context);
    72             LayoutInflater vi = LayoutInflater.from(context);
    73 			v = vi.inflate(R.layout.listview_room, null);
    73             v = vi.inflate(R.layout.listview_room, null);
    74 		}
    74         }
    75 		
    75 
    76 		Room room = getItem(position).room;
    76         Room room = getItem(position).room;
    77 		int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing;
    77         int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing;
    78 		
    78 
    79 		if(v.findViewById(android.R.id.text1) == null) {
    79         if(v.findViewById(android.R.id.text1) == null) {
    80 			// Tabular room list
    80             // Tabular room list
    81 			TextView roomnameView = (TextView)v.findViewById(R.id.roomname);
    81             TextView roomnameView = (TextView)v.findViewById(R.id.roomname);
    82 			TextView playerCountView = (TextView)v.findViewById(R.id.playercount);
    82             TextView playerCountView = (TextView)v.findViewById(R.id.playercount);
    83 			TextView teamCountView = (TextView)v.findViewById(R.id.teamcount);
    83             TextView teamCountView = (TextView)v.findViewById(R.id.teamcount);
    84 			TextView ownerView = (TextView)v.findViewById(R.id.owner);
    84             TextView ownerView = (TextView)v.findViewById(R.id.owner);
    85 			TextView mapView = (TextView)v.findViewById(R.id.map);
    85             TextView mapView = (TextView)v.findViewById(R.id.map);
    86 			TextView schemeView = (TextView)v.findViewById(R.id.scheme);
    86             TextView schemeView = (TextView)v.findViewById(R.id.scheme);
    87 			TextView weaponView = (TextView)v.findViewById(R.id.weapons);
    87             TextView weaponView = (TextView)v.findViewById(R.id.weapons);
    88 			
    88 
    89 			roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
    89             roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
    90 			roomnameView.setText(room.name);
    90             roomnameView.setText(room.name);
    91 			if(playerCountView != null) {
    91             if(playerCountView != null) {
    92 				playerCountView.setText(String.valueOf(room.playerCount));
    92                 playerCountView.setText(String.valueOf(room.playerCount));
    93 			}
    93             }
    94 			if(teamCountView != null) {
    94             if(teamCountView != null) {
    95 				teamCountView.setText(String.valueOf(room.teamCount));
    95                 teamCountView.setText(String.valueOf(room.teamCount));
    96 			}
    96             }
    97 			ownerView.setText(room.owner);
    97             ownerView.setText(room.owner);
    98 			mapView.setText(room.formatMapName(context.getResources()));
    98             mapView.setText(room.formatMapName(context.getResources()));
    99 			schemeView.setText(room.scheme);
    99             schemeView.setText(room.scheme);
   100 			weaponView.setText(room.weapons);
   100             weaponView.setText(room.weapons);
   101 		} else {
   101         } else {
   102 			// Small room list
   102             // Small room list
   103 			TextView v1 = (TextView)v.findViewById(android.R.id.text1);
   103             TextView v1 = (TextView)v.findViewById(android.R.id.text1);
   104 			TextView v2 = (TextView)v.findViewById(android.R.id.text2);
   104             TextView v2 = (TextView)v.findViewById(android.R.id.text2);
   105 			
   105 
   106 			v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
   106             v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
   107 			v1.setText(room.name);
   107             v1.setText(room.name);
   108 			v2.setText(formatExtra(context.getResources(), room));
   108             v2.setText(formatExtra(context.getResources(), room));
   109 		}
   109         }
   110 		
   110 
   111 		return v;
   111         return v;
   112 	}
   112     }
   113 }
   113 }