mirror of
https://github.com/sismics/docs.git
synced 2024-11-14 18:27:58 +01:00
Android: sort tags by count desc
This commit is contained in:
parent
a0356845b1
commit
9ae8303b18
@ -45,6 +45,12 @@ public class FilePagerAdapter extends PagerAdapter {
|
||||
*/
|
||||
private String authToken;
|
||||
|
||||
/**
|
||||
* File pager adapter.
|
||||
*
|
||||
* @param context Context
|
||||
* @param filesArray Files
|
||||
*/
|
||||
public FilePagerAdapter(Context context, JSONArray filesArray) {
|
||||
this.files = new ArrayList<>();
|
||||
for (int i = 0; i < filesArray.length(); i++) {
|
||||
|
@ -16,6 +16,11 @@ import com.sismics.docs.R;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tag list adapter.
|
||||
*
|
||||
@ -25,25 +30,36 @@ public class TagListAdapter extends BaseAdapter {
|
||||
/**
|
||||
* Tags.
|
||||
*/
|
||||
private JSONArray tags;
|
||||
private List<JSONObject> tags;
|
||||
|
||||
/**
|
||||
* Tag list adapter.
|
||||
*
|
||||
* @param tags Tags
|
||||
* @param tagsArray Tags
|
||||
*/
|
||||
public TagListAdapter(JSONArray tags) {
|
||||
this.tags = tags;
|
||||
public TagListAdapter(JSONArray tagsArray) {
|
||||
this.tags = new ArrayList<>();
|
||||
for (int i = 0; i < tagsArray.length(); i++) {
|
||||
tags.add(tagsArray.optJSONObject(i));
|
||||
}
|
||||
|
||||
// Sort tags by count desc
|
||||
Collections.sort(tags, new Comparator<JSONObject>() {
|
||||
@Override
|
||||
public int compare(JSONObject lhs, JSONObject rhs) {
|
||||
return lhs.optInt("count") < rhs.optInt("count") ? 1 : -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return tags.length();
|
||||
return tags.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getItem(int position) {
|
||||
return tags.optJSONObject(position);
|
||||
return tags.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user