Removed some unneeded code in MotorListFragment. Use startActivityForResult when starting the TCQueryAction so the MotorBrowserActivity knows when it is finished. The MotorBrowserActivity uses the onActivityResult to refresh the data in the fragment.

This commit is contained in:
Kevin Ruland 2012-02-10 02:46:11 +00:00
parent 40c6999bb0
commit 737ede90a7
3 changed files with 27 additions and 27 deletions

View File

@ -18,9 +18,9 @@ public abstract class ActivityHelpers {
parent.startActivity(intent);
}
public static void downloadFromThrustcurve( Activity parent ) {
public static void downloadFromThrustcurve( Activity parent, int requestCode ) {
Intent i = new Intent(parent, TCQueryActivity.class);
parent.startActivity(i);
parent.startActivityForResult(i, requestCode);
}
}

View File

@ -19,6 +19,8 @@ implements MotorListFragment.OnMotorSelectedListener
{
MotorListFragment motorList;
private final static int DOWNLOAD_REQUEST_CODE = 1;
/** Called when the activity is first created. */
@Override
@ -40,7 +42,7 @@ implements MotorListFragment.OnMotorSelectedListener
AndroidLogWrapper.d(MotorBrowserActivity.class,"onMenuItemSelected" + item.getItemId());
switch(item.getItemId()) {
case R.id.download_from_thrustcurve_menu_option:
ActivityHelpers.downloadFromThrustcurve(this);
ActivityHelpers.downloadFromThrustcurve(this,DOWNLOAD_REQUEST_CODE);
return true;
case R.id.preference_menu_option:
Intent intent = new Intent().setClass(this, PreferencesActivity.class);
@ -50,6 +52,14 @@ implements MotorListFragment.OnMotorSelectedListener
return super.onMenuItemSelected(featureId, item);
}
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if ( requestCode == DOWNLOAD_REQUEST_CODE ) {
MotorListFragment frag = (MotorListFragment) getSupportFragmentManager().findFragmentById(R.id.motorBrowserList);
frag.refreshData();
}
}
@Override
public void onMotorSelected(long motorId) {

View File

@ -20,7 +20,6 @@ import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CursorTreeAdapter;
import android.widget.ExpandableListView;
import android.widget.ResourceCursorTreeAdapter;
import android.widget.TextView;
@ -55,8 +54,6 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
MotorDao.MANUFACTURER
};
private CursorTreeAdapter mAdapter;
private DbAdapter mDbHelper;
private OnMotorSelectedListener motorSelectedListener;
@ -138,6 +135,10 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// TODO - need some error text but unfortunately doing this, makes the layout funky
// on ICS.
//setEmptyText("No motors in database - download them from Thrustcurve using the Option Menu");
refreshData();
registerForContextMenu(getExpandableListView());
@ -204,7 +205,6 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
super.onChildClick(parent, v, groupPosition, childPosition, id);
//Intent i = new Intent(this, BurnPlotActivity.class);
if( motorSelectedListener != null ) {
motorSelectedListener.onMotorSelected(id);
}
@ -217,11 +217,6 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
pref.unregisterOnSharedPreferenceChangeListener(this);
// Null out the group cursor. This will cause the group cursor and all of the child cursors
// to be closed.
mAdapter.changeCursor(null);
mAdapter = null;
mDbHelper.close();
}
@ -240,20 +235,15 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
groupColumn = groupColumns[index];
}
private void refreshData() {
Cursor motorCursor = mDbHelper.getMotorDao().fetchGroups(groupColumn);
if (mAdapter != null ) {
mAdapter.changeCursor(motorCursor);
}
else {
// Set up our adapter
mAdapter = new MotorHierarchicalListAdapter(
getActivity(),
motorCursor,
R.layout.motor_list_group,
R.layout.motor_list_child);
setListAdapter(mAdapter);
}
}
public void refreshData() {
Cursor motorCursor = mDbHelper.getMotorDao().fetchGroups(groupColumn);
MotorHierarchicalListAdapter mAdapter = new MotorHierarchicalListAdapter(
getActivity(),
motorCursor,
R.layout.motor_list_group,
R.layout.motor_list_child);
setListAdapter(mAdapter);
onContentChanged();
}
}