Skip to content

Commit

Permalink
Trigger manager is now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
damonkohler committed Nov 19, 2010
1 parent 0a2769c commit b1079c7
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
Expand All @@ -47,15 +46,17 @@
import com.googlecode.android_scripting.trigger.ScriptTrigger;
import com.googlecode.android_scripting.trigger.Trigger;
import com.googlecode.android_scripting.trigger.TriggerRepository;
import com.googlecode.android_scripting.trigger.TriggerRepository.TriggerRepositoryObserver;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class TriggerManager extends ListActivity {
private final List<ScriptTrigger> mTriggers = Lists.newArrayList();

private ScriptTriggerAdapter mAdapter;
private List<ScriptTrigger> mTriggers;
private TriggerRepository mTriggerRepository;

private static enum ContextMenuId {
Expand All @@ -76,12 +77,12 @@ public int getId() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CustomizeWindow.requestCustomTitle(this, "Triggers", R.layout.trigger_manager);
mTriggers = Lists.newArrayList();
mTriggerRepository = ((BaseApplication) getApplication()).getTriggerRepository();
ScriptTriggerListObserver observer = new ScriptTriggerListObserver();
mAdapter = new ScriptTriggerAdapter();
mAdapter.registerDataSetObserver(new ScriptTriggerListObserver());
setListAdapter(mAdapter);
registerForContextMenu(getListView());
mTriggerRepository = ((BaseApplication) getApplication()).getTriggerRepository();
mTriggerRepository.bootstrapObserver(observer);
ActivityFlinger.attachView(getListView(), this);
ActivityFlinger.attachView(getWindow().getDecorView(), this);
Analytics.trackActivity(this);
Expand Down Expand Up @@ -137,7 +138,6 @@ public boolean onContextItemSelected(MenuItem item) {
if (item.getItemId() == ContextMenuId.REMOVE.getId()) {
mTriggerRepository.remove(trigger);
}
mAdapter.notifyDataSetInvalidated();
return true;
}

Expand All @@ -146,12 +146,18 @@ public void onListItemClick(ListView l, View v, int position, long id) {
mAdapter.notifyDataSetInvalidated();
}

private class ScriptTriggerListObserver extends DataSetObserver {
private class ScriptTriggerListObserver implements TriggerRepositoryObserver {

@Override
public void onPut(Trigger trigger) {
mTriggers.add((ScriptTrigger) trigger);
mAdapter.notifyDataSetInvalidated();
}

@Override
public void onInvalidated() {
mTriggers.clear();
// TODO(damonkohler): Bootstrap the TriggerRepositoryObserver.
public void onRemove(Trigger trigger) {
mTriggers.remove(trigger);
mAdapter.notifyDataSetInvalidated();
}
}

Expand Down Expand Up @@ -198,6 +204,7 @@ public void onClick(DialogInterface dialog, int position) {
mTriggerRepository.put(new ScriptTrigger(eventNames.get(position), script));
}
});
builder.show();
}
}
}
Expand Down

0 comments on commit b1079c7

Please sign in to comment.