1 package org.hedgewars.hedgeroid.netplay; |
|
2 |
|
3 import java.util.Comparator; |
|
4 |
|
5 import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
|
6 |
|
7 import android.content.Context; |
|
8 import android.util.Pair; |
|
9 import android.view.LayoutInflater; |
|
10 import android.view.View; |
|
11 import android.view.ViewGroup; |
|
12 import android.widget.TextView; |
|
13 |
|
14 public class TeamlistAdapter extends ObservableTreeMapAdapter<String, Pair<TeamInGame, Long>> { |
|
15 private Context context; |
|
16 |
|
17 public TeamlistAdapter(Context context) { |
|
18 this.context = context; |
|
19 } |
|
20 |
|
21 @Override |
|
22 protected Comparator<Pair<TeamInGame, Long>> getEntryOrder() { |
|
23 return AlphabeticalOrderComparator.INSTANCE; |
|
24 } |
|
25 |
|
26 public TeamInGame getItem(int position) { |
|
27 return getEntries().get(position).first; |
|
28 } |
|
29 |
|
30 public long getItemId(int position) { |
|
31 return getEntries().get(position).second; |
|
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(android.R.layout.simple_list_item_2, null); |
|
43 } |
|
44 |
|
45 TeamInGame team = getItem(position); |
|
46 TextView tv1 = (TextView) v.findViewById(android.R.id.text1); |
|
47 TextView tv2 = (TextView) v.findViewById(android.R.id.text2); |
|
48 |
|
49 tv1.setText(team.team.name); |
|
50 tv2.setText("Hogs: "+team.ingameAttribs.hogCount); |
|
51 return v; |
|
52 } |
|
53 |
|
54 private static final class AlphabeticalOrderComparator implements Comparator<Pair<TeamInGame, Long>> { |
|
55 public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator(); |
|
56 public int compare(Pair<TeamInGame, Long> lhs, Pair<TeamInGame, Long> rhs) { |
|
57 return lhs.first.team.name.compareToIgnoreCase(rhs.first.team.name); |
|
58 }; |
|
59 } |
|
60 } |
|