aboutsummaryrefslogtreecommitdiff
path: root/src/org/happysanta/gd/Menu/LevelsAdapter.java
blob: 9f7ddc9c535802afc222e01c39c33f2def36654b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.happysanta.gd.Menu;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import org.happysanta.gd.Global;
import org.happysanta.gd.R;
import org.happysanta.gd.Storage.Level;

import java.util.ArrayList;

import static org.happysanta.gd.Helpers.getString;

public class LevelsAdapter extends ArrayAdapter<Level> {

	private ArrayList<Level> levels;

	public LevelsAdapter(Context context, ArrayList<Level> levels) {
		super(context, R.layout.levels_list_item, levels);
		this.levels = levels;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.levels_list_item, null);
		}

		Level level = levels.get(position);
		if (level != null) {
			TextView name = (TextView) v.findViewById(R.id.level_name);
			TextView count = (TextView) v.findViewById(R.id.level_count);

			name.setTypeface(Global.robotoCondensedTypeface);
			count.setTypeface(Global.robotoCondensedTypeface);

			name.setText(level.getName());
			count.setText(Html.fromHtml(String.format(getString(R.string.levels_count_tpl),
					level.getCountEasy() + " - " + level.getCountMedium() + " - " + level.getCountHard(), level.getShortAddedDate())));
		}

		return v;
	}

}