Android: use GET /tag/list instead of /tag/stats

This commit is contained in:
jendib 2016-05-11 00:55:27 +02:00
parent e181b7d24b
commit a13174ac4d
No known key found for this signature in database
GPG Key ID: 06EE7F699579166F
4 changed files with 8 additions and 24 deletions

View File

@ -87,13 +87,13 @@ public class MainActivity extends AppCompatActivity {
tagListView.setEmptyView(tagProgressView);
JSONObject cacheTags = PreferenceUtil.getCachedJson(this, PreferenceUtil.PREF_CACHED_TAGS_JSON);
if (cacheTags != null) {
tagListView.setAdapter(new TagListAdapter(cacheTags.optJSONArray("stats")));
tagListView.setAdapter(new TagListAdapter(cacheTags.optJSONArray("tags")));
}
TagResource.stats(this, new HttpCallback() {
TagResource.list(this, new HttpCallback() {
@Override
public void onSuccess(JSONObject response) {
PreferenceUtil.setCachedJson(MainActivity.this, PreferenceUtil.PREF_CACHED_TAGS_JSON, response);
tagListView.setAdapter(new TagListAdapter(response.optJSONArray("stats")));
tagListView.setAdapter(new TagListAdapter(response.optJSONArray("tags")));
tagProgressView.setVisibility(View.GONE);
tagListView.setEmptyView(tagEmptyView);
}

View File

@ -46,7 +46,7 @@ public class TagListAdapter extends BaseAdapter {
// Reorder tags by parent/child relation and compute depth
int depth = 0;
initTags(tags, JSONObject.NULL.toString(), depth);
initTags(tags, "", depth);
}
/**
@ -60,11 +60,10 @@ public class TagListAdapter extends BaseAdapter {
// Get all tags with this parent
for (JSONObject tag : tags) {
String tagParentId = tag.optString("parent");
if (tagParentId.equals(parentId)) {
if (parentId.equals(tagParentId)) {
TagItem tagItem = new TagItem();
tagItem.id = tag.optString("id");
tagItem.name = tag.optString("name");
tagItem.count = tag.optInt("count");
tagItem.color = tag.optString("color");
tagItem.depth = depth;
tagItemList.add(tagItem);
@ -99,8 +98,6 @@ public class TagListAdapter extends BaseAdapter {
TagItem tagItem = getItem(position);
TextView tagTextView = (TextView) view.findViewById(R.id.tagTextView);
tagTextView.setText(tagItem.name);
TextView tagCountTextView = (TextView) view.findViewById(R.id.tagCountTextView);
tagCountTextView.setText(String.format(Locale.ENGLISH, "%d", tagItem.count));
// Label color filtering
ImageView labelImageView = (ImageView) view.findViewById(R.id.labelImageView);
@ -125,7 +122,6 @@ public class TagListAdapter extends BaseAdapter {
public static class TagItem {
private String id;
private String name;
private int count;
private String color;
private int depth;

View File

@ -16,14 +16,14 @@ import okhttp3.Request;
*/
public class TagResource extends BaseResource {
/**
* GET /tag/stats.
* GET /tag/list.
*
* @param context Context
* @param callback Callback
*/
public static void stats(Context context, HttpCallback callback) {
public static void list(Context context, HttpCallback callback) {
Request request = new Request.Builder()
.url(HttpUrl.parse(getApiUrl(context) + "/tag/stats"))
.url(HttpUrl.parse(getApiUrl(context) + "/tag/list"))
.get()
.build();
OkHttpUtil.buildClient(context)

View File

@ -28,17 +28,5 @@
android:textColor="#212121"
android:text="Appartement"
android:textSize="14sp"/>
<TextView
android:id="@+id/tagCountTextView"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textColor="#888"
android:text="5"
android:textSize="14sp"/>
</RelativeLayout>