Skip to content

Commit

Permalink
filter top artists by gender
Browse files Browse the repository at this point in the history
  • Loading branch information
camillol committed Nov 20, 2011
1 parent 267c96e commit 3aac9e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Data.pde
Expand Up @@ -53,6 +53,16 @@ class UserFilter {
ageMax = DONTCARE;
country = null;
}

String queryString()
{
String genderQ = "";
if ((gender & MALE) != 0) genderQ += "m";
if ((gender & FEMALE) != 0) genderQ += "f";
if ((gender & UNKNOWN) != 0) genderQ += "u";
if (genderQ.length() < 3 && genderQ.length() > 0) return "?gender=" + genderQ;
else return "";
}
}

class Country {
Expand Down Expand Up @@ -100,7 +110,7 @@ class WebDataSource {
List<ArtistChartEntry> getTopArtists(UserFilter userFilter)
{
List<ArtistChartEntry> entries = new ArrayList<ArtistChartEntry>(10);
String request = baseURL + "top_artists";
String request = baseURL + "top_artists" + userFilter.queryString();
println(request);
try {
JSONArray result = new JSONArray(join(loadStrings(request), ""));
Expand Down
10 changes: 8 additions & 2 deletions TopArtistView.pde
Expand Up @@ -15,7 +15,7 @@ class TopArtistView extends View implements ListDataSource {
femaleCB = makeGenderCheckbox(FEMALE, "F", 1);
noGenderCB = makeGenderCheckbox(UNKNOWN, "?", 2);

artists = data.getTopArtists(userFilter);
reloadArtists();

artistListbox = new ListBox(0, 20, w, h-2, this); // new MissingListDataSource("no artists")
subviews.add(artistListbox);
Expand All @@ -24,18 +24,24 @@ class TopArtistView extends View implements ListDataSource {
GlyphCheckbox makeGenderCheckbox(final int flag, String letter, int idx)
{
GlyphCheckbox cb = new GlyphCheckbox(20*idx, 0, 20, 20, letter);
cb.checked = (userFilter.gender | flag) != 0;
cb.checked = (userFilter.gender & flag) != 0;
cb.setAction(new Action<Button>() {
public void respond(Button b) {
Checkbox cb = (Checkbox)b;
if (cb.checked) userFilter.gender |= flag;
else userFilter.gender &= ~flag;
reloadArtists();
}
});
subviews.add(cb);
return cb;
}

void reloadArtists()
{
artists = data.getTopArtists(userFilter);
}

void drawContent(float lx, float ly)
{
strokeWeight(1);
Expand Down

0 comments on commit 3aac9e9

Please sign in to comment.