Skip to content

Commit d1a9e9d

Browse files
committed
update taxonomy query
1 parent 9b78d7a commit d1a9e9d

File tree

7 files changed

+122
-6
lines changed

7 files changed

+122
-6
lines changed

.idea/dictionaries/abu.xml

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/github/kingaza/aspree/MainActivity.java

+31-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import retrofit.client.Response;
2121

2222
import com.github.kingaza.aspree.model.TaxonomyModel;
23-
23+
import com.github.kingaza.aspree.protocol.Taxonomies;
24+
import com.github.kingaza.aspree.protocol.Taxonomy;
2425

2526
public class MainActivity extends ActionBarActivity
2627
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
@@ -142,10 +143,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
142143

143144
final TextView textView = (TextView) rootView.findViewById(R.id.section_label);
144145

145-
Callback<TaxonomyModel.Taxonomy> taxonomyCallback = new Callback<TaxonomyModel.Taxonomy>() {
146+
Callback<Taxonomy> taxonomyCallback = new Callback<Taxonomy>() {
146147
@Override
147-
public void success(TaxonomyModel.Taxonomy taxonomy, Response response) {
148-
textView.setText(taxonomy.toString());
148+
public void success(Taxonomy taxonomy, Response response) {
149+
String text = "";
150+
for (String s : taxonomy.getTaxonNames() ) {
151+
text = text + "\n" + s;
152+
}
153+
textView.setText(text);
149154
Log.i(TAG, response.toString());
150155
}
151156

@@ -154,7 +159,28 @@ public void failure(RetrofitError error) {
154159
textView.setText("Spree access failure: " + error.getMessage());
155160
}
156161
};
157-
TaxonomyModel.getTaxonomy(1, taxonomyCallback);
162+
//TaxonomyModel.getTaxonomy(1, taxonomyCallback);
163+
164+
Callback<Taxonomies> taxonomiesCallback = new Callback<Taxonomies>() {
165+
@Override
166+
public void success(Taxonomies taxonomies, Response response) {
167+
String text = "";
168+
for (Taxonomy taxonomy : taxonomies.taxonomies) {
169+
text = text + taxonomy.name + "\n";
170+
for (String s : taxonomy.getTaxonNames()) {
171+
text = text + "\t" + s + ", ";
172+
}
173+
text = text + "\n";
174+
}
175+
textView.setText(text);
176+
}
177+
178+
@Override
179+
public void failure(RetrofitError error) {
180+
textView.setText("Spree access failure: " + error.getMessage());
181+
}
182+
};
183+
TaxonomyModel.getTaxonomies(taxonomiesCallback);
158184

159185
return rootView;
160186
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.kingaza.aspree;
2+
3+
import android.app.Fragment;
4+
5+
/**
6+
* Created by abu on 2015/4/28.
7+
*/
8+
9+
public class TaxonomyFragment extends Fragment{
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.kingaza.aspree.protocol;
2+
3+
/**
4+
* Created by abu on 2015/4/28.
5+
*/
6+
public class Taxon {
7+
8+
int id;
9+
String name;
10+
String pretty_name;
11+
String permalink;
12+
int parent_id;
13+
int taxonomy_id;
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.kingaza.aspree.protocol;
2+
3+
/**
4+
* Created by abu on 2015/4/28.
5+
*/
6+
7+
import java.util.List;
8+
9+
public class Taxonomies {
10+
11+
public int count;
12+
public int current_page;
13+
public int pages;
14+
15+
public List<Taxonomy> taxonomies;
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.kingaza.aspree.protocol;
2+
3+
/**
4+
* Created by abu on 2015/4/28.
5+
*/
6+
7+
import java.util.List;
8+
import java.util.ArrayList;
9+
10+
public class Taxonomy {
11+
12+
public int id;
13+
public String name;
14+
15+
16+
public class Root {
17+
public int id;
18+
public String name;
19+
public String pretty_name;
20+
public String permalink;
21+
public int parent_id;
22+
public int taxonomy_id;
23+
public List<Taxon> taxons;
24+
}
25+
26+
public Root root;
27+
28+
public List<String> getTaxonNames() {
29+
List<String> list = new ArrayList<String>();
30+
for (Taxon taxon : root.taxons) {
31+
list.add(taxon.name);
32+
}
33+
return list;
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
</LinearLayout>

0 commit comments

Comments
 (0)