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