|
1 package org.hedgewars.hedgeroid; |
|
2 |
|
3 import java.util.Comparator; |
|
4 |
|
5 import org.hedgewars.hedgeroid.R; |
|
6 import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom; |
|
7 import org.hedgewars.hedgeroid.util.ObservableTreeMapAdapter; |
|
8 |
|
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 @Override |
|
16 protected Comparator<PlayerInRoom> getEntryOrder() { |
|
17 return AlphabeticalOrderComparator.INSTANCE; |
|
18 } |
|
19 |
|
20 public View getView(int position, View convertView, ViewGroup parent) { |
|
21 View v = convertView; |
|
22 if (v == null) { |
|
23 LayoutInflater vi = LayoutInflater.from(parent.getContext()); |
|
24 v = vi.inflate(R.layout.listview_player, null); |
|
25 } |
|
26 |
|
27 PlayerInRoom player = getItem(position); |
|
28 TextView username = (TextView) v.findViewById(android.R.id.text1); |
|
29 username.setText(player.player.name); |
|
30 int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off; |
|
31 username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0); |
|
32 return v; |
|
33 } |
|
34 |
|
35 private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> { |
|
36 public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator(); |
|
37 public int compare(PlayerInRoom lhs, PlayerInRoom rhs) { |
|
38 return lhs.player.name.compareToIgnoreCase(rhs.player.name); |
|
39 }; |
|
40 } |
|
41 } |