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

allow to remove models

parent 1f81238f
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,12 @@ public class ModelArrayAdapter extends ArrayAdapter<Model> { ...@@ -28,6 +28,12 @@ public class ModelArrayAdapter extends ArrayAdapter<Model> {
_models.add(model); _models.add(model);
} }
public void reset()
{
super.clear();
_models.clear();
}
public void sortByName() public void sortByName()
{ {
Collections.sort(_models, new ModelComp()); Collections.sort(_models, new ModelComp());
......
...@@ -32,6 +32,15 @@ public class ModelList extends Activity { ...@@ -32,6 +32,15 @@ public class ModelList extends Activity {
private ModelArrayAdapter _modelArrayAdapter; private ModelArrayAdapter _modelArrayAdapter;
private void deleteRecursive(File fileOrDirectory)
{
if (fileOrDirectory.isDirectory()){
for (File child : fileOrDirectory.listFiles())
deleteRecursive(child);
}
fileOrDirectory.delete();
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
...@@ -66,30 +75,42 @@ public class ModelList extends Activity { ...@@ -66,30 +75,42 @@ public class ModelList extends Activity {
final Model m = _modelArrayAdapter.getModel(position); final Model m = _modelArrayAdapter.getModel(position);
CharSequence[] actions; CharSequence[] actions;
if(m.getUrl() != null) { if(m.getUrl() != null) {
actions = new CharSequence[2]; actions = new CharSequence[3];
actions[0] = "Open model"; actions[0] = "Open model";
actions[1] = "View model website"; actions[1] = "Remove model";
// FIXME: add "Remove model" as in iOS actions[2] = "View model website";
} }
else { else {
actions = new CharSequence[1]; actions = new CharSequence[2];
actions[0] = "Open model"; actions[0] = "Open model";
actions[1] = "Remove 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());
builder.setItems(actions, new DialogInterface.OnClickListener() { builder.setItems(actions, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int position) { public void onClick(DialogInterface dialog, int position) {
switch (position) { switch (position) {
case 1: case 0:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, m.getUrl());
startActivity(browserIntent);
break;
default:
Intent intent = new Intent(ModelList.this, MainActivity.class); Intent intent = new Intent(ModelList.this, MainActivity.class);
intent.putExtra("file", m.getFile().toString()); intent.putExtra("file", m.getFile().toString());
intent.putExtra("name", m.getName()); intent.putExtra("name", m.getName());
startActivity(intent); startActivity(intent);
break; break;
case 1:
deleteRecursive(m.getFile().getParentFile());
_modelArrayAdapter.reset();
try {
getModels();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
case 2:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, m.getUrl());
startActivity(browserIntent);
break;
} }
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment