project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyPlayerlistAdapter.java
author Medo <smaxein@googlemail.com>
Mon, 06 Aug 2012 22:39:36 +0200
changeset 7476 2fb781bbdd51
permissions -rw-r--r--
Hedgeroid: Start using the frontlib for more operations
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
package org.hedgewars.hedgeroid.netplay;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
import java.util.Comparator;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
import org.hedgewars.hedgeroid.R;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
import org.hedgewars.hedgeroid.Datastructures.Player;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
import android.content.Context;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
import android.util.Pair;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
import android.view.LayoutInflater;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
import android.view.View;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
import android.view.ViewGroup;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
import android.widget.TextView;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
public class LobbyPlayerlistAdapter extends ObservableTreeMapAdapter<String, Pair<Player, Long>> {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
	private Context context;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
	public LobbyPlayerlistAdapter(Context context) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
		this.context = context;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
	@Override
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
	protected Comparator<Pair<Player, Long>> getEntryOrder() {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
		return AlphabeticalOrderComparator.INSTANCE;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
	public Player getItem(int position) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
		return getEntries().get(position).first;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
	public long getItemId(int position) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
		return getEntries().get(position).second;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
	public boolean hasStableIds() {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
		return true;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
	public View getView(int position, View convertView, ViewGroup parent) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
		View v = convertView;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
		if (v == null) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
			LayoutInflater vi = LayoutInflater.from(context);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
			v = vi.inflate(R.layout.listview_player, null);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
		}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
		String player = getItem(position).name;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
		TextView username = (TextView) v.findViewById(android.R.id.text1);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
		username.setText(player);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
		return v;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
	private static final class AlphabeticalOrderComparator implements Comparator<Pair<Player, Long>> {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
		public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator();
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
		public int compare(Pair<Player, Long> lhs, Pair<Player, Long> rhs) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
			return lhs.first.name.compareToIgnoreCase(rhs.first.name);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
		};
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
}