9 import org.hedgewars.hedgeroid.R; |
9 import org.hedgewars.hedgeroid.R; |
10 import org.hedgewars.hedgeroid.netplay.RoomList.Observer; |
10 import org.hedgewars.hedgeroid.netplay.RoomList.Observer; |
11 |
11 |
12 import android.content.Context; |
12 import android.content.Context; |
13 import android.content.res.Resources; |
13 import android.content.res.Resources; |
14 import android.text.Layout.Alignment; |
|
15 import android.text.SpannableStringBuilder; |
|
16 import android.text.Spanned; |
|
17 import android.text.style.AlignmentSpan; |
|
18 import android.view.LayoutInflater; |
14 import android.view.LayoutInflater; |
19 import android.view.View; |
15 import android.view.View; |
20 import android.view.ViewGroup; |
16 import android.view.ViewGroup; |
21 import android.widget.BaseAdapter; |
17 import android.widget.BaseAdapter; |
22 import android.widget.TextView; |
18 import android.widget.TextView; |
49 this.rooms = new ArrayList<Room>(rooms); |
45 this.rooms = new ArrayList<Room>(rooms); |
50 Collections.reverse(this.rooms); // We want to show the newest rooms first |
46 Collections.reverse(this.rooms); // We want to show the newest rooms first |
51 notifyDataSetChanged(); |
47 notifyDataSetChanged(); |
52 } |
48 } |
53 |
49 |
54 private static Spanned formatExtra(Resources res, Room room) { |
50 private static CharSequence formatExtra(Resources res, Room room) { |
55 String ownermsg = res.getString(R.string.roomlist_owner, room.owner); |
51 String ownermsg = res.getString(R.string.roomlist_owner, room.owner); |
56 String mapmsg = res.getString(R.string.roomlist_map, Room.formatMapName(res, room.map)); |
52 String mapmsg = res.getString(R.string.roomlist_map, Room.formatMapName(res, room.map)); |
57 String schememsg = res.getString(R.string.roomlist_scheme, room.scheme); |
53 String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons; |
58 String weaponsmsg = res.getString(R.string.roomlist_weapons, room.weapons); |
54 String schememsg = res.getString(R.string.roomlist_scheme, scheme); |
59 SpannableStringBuilder ssb = new SpannableStringBuilder(); |
55 return ownermsg + ". " + mapmsg + ", " + schememsg; |
60 ssb.append(ownermsg).append(" ").append(mapmsg).append("\n").append(schememsg).append(" ").append(weaponsmsg); |
|
61 |
|
62 int weaponOffset = ownermsg.length()+1+mapmsg.length()+1+schememsg.length()+1; |
|
63 ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), ownermsg.length(), ownermsg.length()+mapmsg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
|
64 ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), weaponOffset, weaponOffset+weaponsmsg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
|
65 return ssb; |
|
66 } |
56 } |
67 |
57 |
68 public View getView(int position, View convertView, ViewGroup parent) { |
58 public View getView(int position, View convertView, ViewGroup parent) { |
69 View v = convertView; |
59 View v = convertView; |
70 TextView tv1; |
|
71 if (v == null) { |
60 if (v == null) { |
72 LayoutInflater vi = LayoutInflater.from(context); |
61 LayoutInflater vi = LayoutInflater.from(context); |
73 v = vi.inflate(android.R.layout.simple_list_item_2, null); |
62 v = vi.inflate(R.layout.listview_room, null); |
74 tv1 = (TextView)v.findViewById(android.R.id.text1); |
|
75 tv1.setCompoundDrawablePadding(5); |
|
76 } else { |
|
77 tv1 = (TextView)v.findViewById(android.R.id.text1); |
|
78 } |
63 } |
79 |
64 |
80 Room room = rooms.get(position); |
65 Room room = rooms.get(position); |
81 int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing; |
66 int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing; |
82 TextView tv2 = (TextView)v.findViewById(android.R.id.text2); |
67 |
83 tv1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0); |
68 if(v.findViewById(android.R.id.text1) == null) { |
84 tv1.setText(room.name); |
69 // Tabular room list |
85 tv2.setText(formatExtra(context.getResources(), room)); |
70 TextView roomnameView = (TextView)v.findViewById(R.id.roomname); |
|
71 TextView playerCountView = (TextView)v.findViewById(R.id.playercount); |
|
72 TextView teamCountView = (TextView)v.findViewById(R.id.teamcount); |
|
73 TextView ownerView = (TextView)v.findViewById(R.id.owner); |
|
74 TextView mapView = (TextView)v.findViewById(R.id.map); |
|
75 TextView schemeView = (TextView)v.findViewById(R.id.scheme); |
|
76 TextView weaponView = (TextView)v.findViewById(R.id.weapons); |
|
77 |
|
78 roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0); |
|
79 roomnameView.setText(room.name); |
|
80 if(playerCountView != null) { |
|
81 playerCountView.setText(String.valueOf(room.playerCount)); |
|
82 } |
|
83 if(teamCountView != null) { |
|
84 teamCountView.setText(String.valueOf(room.teamCount)); |
|
85 } |
|
86 ownerView.setText(room.owner); |
|
87 mapView.setText(Room.formatMapName(context.getResources(), room.map)); |
|
88 schemeView.setText(room.scheme); |
|
89 weaponView.setText(room.weapons); |
|
90 } else { |
|
91 // Small room list |
|
92 TextView v1 = (TextView)v.findViewById(android.R.id.text1); |
|
93 TextView v2 = (TextView)v.findViewById(android.R.id.text2); |
|
94 |
|
95 v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0); |
|
96 v1.setText(room.name); |
|
97 v2.setText(formatExtra(context.getResources(), room)); |
|
98 } |
|
99 |
86 return v; |
100 return v; |
87 } |
101 } |
88 |
102 |
89 public void itemAdded(Map<String, Room> map, String key, Room value) { |
103 public void itemAdded(Map<String, Room> map, String key, Room value) { |
90 setList(map.values()); |
104 setList(map.values()); |