|
1 package org.hedgewars.hedgeroid.netplay; |
|
2 |
|
3 import java.util.Comparator; |
|
4 |
|
5 import org.hedgewars.hedgeroid.R; |
|
6 import org.hedgewars.hedgeroid.netplay.RoomPlayerlist.PlayerInRoom; |
|
7 |
|
8 import android.content.Context; |
|
9 import android.view.LayoutInflater; |
|
10 import android.view.View; |
|
11 import android.view.ViewGroup; |
|
12 import android.widget.TextView; |
|
13 |
|
14 public class RoomPlayerlistAdapter extends ObservableTreeMapAdapter<String, PlayerInRoom> { |
|
15 private Context context; |
|
16 |
|
17 public RoomPlayerlistAdapter(Context context) { |
|
18 this.context = context; |
|
19 } |
|
20 |
|
21 @Override |
|
22 protected Comparator<PlayerInRoom> getEntryOrder() { |
|
23 return AlphabeticalOrderComparator.INSTANCE; |
|
24 } |
|
25 |
|
26 public PlayerInRoom getItem(int position) { |
|
27 return getEntries().get(position); |
|
28 } |
|
29 |
|
30 public long getItemId(int position) { |
|
31 return getEntries().get(position).id; |
|
32 } |
|
33 |
|
34 public boolean hasStableIds() { |
|
35 return true; |
|
36 } |
|
37 |
|
38 public View getView(int position, View convertView, ViewGroup parent) { |
|
39 View v = convertView; |
|
40 if (v == null) { |
|
41 LayoutInflater vi = LayoutInflater.from(context); |
|
42 v = vi.inflate(R.layout.listview_player, null); |
|
43 } |
|
44 |
|
45 PlayerInRoom player = getItem(position); |
|
46 TextView username = (TextView) v.findViewById(android.R.id.text1); |
|
47 username.setText(player.player.name); |
|
48 int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off; |
|
49 username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0); |
|
50 return v; |
|
51 } |
|
52 |
|
53 private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> { |
|
54 public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator(); |
|
55 public int compare(PlayerInRoom lhs, PlayerInRoom rhs) { |
|
56 return lhs.player.name.compareToIgnoreCase(rhs.player.name); |
|
57 }; |
|
58 } |
|
59 } |