29 import android.view.View; |
29 import android.view.View; |
30 import android.view.ViewGroup; |
30 import android.view.ViewGroup; |
31 import android.widget.TextView; |
31 import android.widget.TextView; |
32 |
32 |
33 public class RoomPlayerlistAdapter extends ObservableTreeMapAdapter<String, PlayerInRoom> { |
33 public class RoomPlayerlistAdapter extends ObservableTreeMapAdapter<String, PlayerInRoom> { |
34 @Override |
34 @Override |
35 protected Comparator<PlayerInRoom> getEntryOrder() { |
35 protected Comparator<PlayerInRoom> getEntryOrder() { |
36 return AlphabeticalOrderComparator.INSTANCE; |
36 return AlphabeticalOrderComparator.INSTANCE; |
37 } |
37 } |
38 |
38 |
39 public View getView(int position, View convertView, ViewGroup parent) { |
39 public View getView(int position, View convertView, ViewGroup parent) { |
40 View v = convertView; |
40 View v = convertView; |
41 if (v == null) { |
41 if (v == null) { |
42 LayoutInflater vi = LayoutInflater.from(parent.getContext()); |
42 LayoutInflater vi = LayoutInflater.from(parent.getContext()); |
43 v = vi.inflate(R.layout.listview_player, null); |
43 v = vi.inflate(R.layout.listview_player, null); |
44 } |
44 } |
45 |
45 |
46 PlayerInRoom player = getItem(position); |
46 PlayerInRoom player = getItem(position); |
47 TextView username = (TextView) v.findViewById(android.R.id.text1); |
47 TextView username = (TextView) v.findViewById(android.R.id.text1); |
48 username.setText(player.player.name); |
48 username.setText(player.player.name); |
49 int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off; |
49 int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off; |
50 username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0); |
50 username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0); |
51 return v; |
51 return v; |
52 } |
52 } |
53 |
53 |
54 private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> { |
54 private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> { |
55 public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator(); |
55 public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator(); |
56 public int compare(PlayerInRoom lhs, PlayerInRoom rhs) { |
56 public int compare(PlayerInRoom lhs, PlayerInRoom rhs) { |
57 return lhs.player.name.compareToIgnoreCase(rhs.player.name); |
57 return lhs.player.name.compareToIgnoreCase(rhs.player.name); |
58 }; |
58 }; |
59 } |
59 } |
60 } |
60 } |