Skip to content
Snippets Groups Projects
Commit f8d4d7e2 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

sort models by name

parent 05772ac1
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package org.geuz.onelab; ...@@ -2,6 +2,7 @@ package org.geuz.onelab;
import java.io.File; import java.io.File;
import android.net.Uri; import android.net.Uri;
import java.util.Comparator;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
...@@ -32,3 +33,10 @@ class Model { ...@@ -32,3 +33,10 @@ class Model {
} }
public void setUrl(Uri url) { _url = url; } public void setUrl(Uri url) { _url = url; }
} }
class ModelComp implements Comparator<Model>{
@Override
public int compare(Model e1, Model e2) {
return e1.getName().compareTo(e2.getName());
}
}
...@@ -2,6 +2,7 @@ package org.geuz.onelab; ...@@ -2,6 +2,7 @@ package org.geuz.onelab;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -27,7 +28,15 @@ public class ModelArrayAdapter extends ArrayAdapter<Model> { ...@@ -27,7 +28,15 @@ public class ModelArrayAdapter extends ArrayAdapter<Model> {
_models.add(model); _models.add(model);
} }
public Model getModel(int pos) { return _models.get(pos); } public void sortByName()
{
Collections.sort(_models, new ModelComp());
}
public Model getModel(int pos)
{
return _models.get(pos);
}
@Override @Override
public View getView(int position, View convertView, final ViewGroup parent) public View getView(int position, View convertView, final ViewGroup parent)
......
...@@ -65,12 +65,13 @@ public class ModelList extends Activity { ...@@ -65,12 +65,13 @@ public class ModelList extends Activity {
CharSequence[] actions; CharSequence[] actions;
if(m.getUrl() != null) { if(m.getUrl() != null) {
actions = new CharSequence[2]; actions = new CharSequence[2];
actions[0] = "Open this model"; actions[0] = "Open model";
actions[1] = "More information"; actions[1] = "View model website";
// FIXME: add "Remove model" as in iOS
} }
else { else {
actions = new CharSequence[1]; actions = new CharSequence[1];
actions[0] = "Open this model"; actions[0] = "Open model";
} }
AlertDialog.Builder builder = new AlertDialog.Builder(parent.getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(parent.getContext());
builder.setTitle(m.getName()); builder.setTitle(m.getName());
...@@ -182,6 +183,7 @@ public class ModelList extends Activity { ...@@ -182,6 +183,7 @@ public class ModelList extends Activity {
} }
} }
} }
_modelArrayAdapter.sortByName();
} }
private void readModel(XmlPullParser parser, String dir) throws XmlPullParserException, IOException private void readModel(XmlPullParser parser, String dir) throws XmlPullParserException, IOException
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment