project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomListAdapter.java
changeset 7349 12fdfd2038d4
parent 7342 0e29eec2df5c
child 7352 641f11cdd319
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomListAdapter.java	Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomListAdapter.java	Sat Jul 21 14:56:52 2012 +0200
@@ -11,10 +11,6 @@
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.text.Layout.Alignment;
-import android.text.SpannableStringBuilder;
-import android.text.Spanned;
-import android.text.style.AlignmentSpan;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -51,38 +47,56 @@
 		notifyDataSetChanged();
 	}
 	
-	private static Spanned formatExtra(Resources res, Room room) {
+	private static CharSequence formatExtra(Resources res, Room room) {
 		String ownermsg = res.getString(R.string.roomlist_owner, room.owner);
 		String mapmsg = res.getString(R.string.roomlist_map, Room.formatMapName(res, room.map));
-		String schememsg = res.getString(R.string.roomlist_scheme, room.scheme);
-		String weaponsmsg = res.getString(R.string.roomlist_weapons,  room.weapons);
-		SpannableStringBuilder ssb = new SpannableStringBuilder();
-		ssb.append(ownermsg).append(" ").append(mapmsg).append("\n").append(schememsg).append(" ").append(weaponsmsg);
-		
-		int weaponOffset = ownermsg.length()+1+mapmsg.length()+1+schememsg.length()+1;
-		ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), ownermsg.length(), ownermsg.length()+mapmsg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-		ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), weaponOffset, weaponOffset+weaponsmsg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-		return ssb;
+		String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons;
+		String schememsg = res.getString(R.string.roomlist_scheme, scheme);
+		return ownermsg + ". " + mapmsg + ", " + schememsg;
 	}
 	
 	public View getView(int position, View convertView, ViewGroup parent) {
 		View v = convertView;
-		TextView tv1;
 		if (v == null) {
 			LayoutInflater vi = LayoutInflater.from(context);
-			v = vi.inflate(android.R.layout.simple_list_item_2, null);
-			tv1 = (TextView)v.findViewById(android.R.id.text1);
-			tv1.setCompoundDrawablePadding(5);
-		} else {
-			tv1 = (TextView)v.findViewById(android.R.id.text1);
+			v = vi.inflate(R.layout.listview_room, null);
 		}
 		
 		Room room = rooms.get(position);
 		int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing;
-		TextView tv2 = (TextView)v.findViewById(android.R.id.text2);
-		tv1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
-		tv1.setText(room.name);
-		tv2.setText(formatExtra(context.getResources(), room));
+		
+		if(v.findViewById(android.R.id.text1) == null) {
+			// Tabular room list
+			TextView roomnameView = (TextView)v.findViewById(R.id.roomname);
+			TextView playerCountView = (TextView)v.findViewById(R.id.playercount);
+			TextView teamCountView = (TextView)v.findViewById(R.id.teamcount);
+			TextView ownerView = (TextView)v.findViewById(R.id.owner);
+			TextView mapView = (TextView)v.findViewById(R.id.map);
+			TextView schemeView = (TextView)v.findViewById(R.id.scheme);
+			TextView weaponView = (TextView)v.findViewById(R.id.weapons);
+			
+			roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
+			roomnameView.setText(room.name);
+			if(playerCountView != null) {
+				playerCountView.setText(String.valueOf(room.playerCount));
+			}
+			if(teamCountView != null) {
+				teamCountView.setText(String.valueOf(room.teamCount));
+			}
+			ownerView.setText(room.owner);
+			mapView.setText(Room.formatMapName(context.getResources(), room.map));
+			schemeView.setText(room.scheme);
+			weaponView.setText(room.weapons);
+		} else {
+			// Small room list
+			TextView v1 = (TextView)v.findViewById(android.R.id.text1);
+			TextView v2 = (TextView)v.findViewById(android.R.id.text2);
+			
+			v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
+			v1.setText(room.name);
+			v2.setText(formatExtra(context.getResources(), room));
+		}
+		
 		return v;
 	}