Fix loader init

This commit is contained in:
Dominik Schürmann 2014-02-01 20:11:17 +01:00
parent 750aaead8e
commit 17f63e0716
2 changed files with 42 additions and 25 deletions

View File

@ -39,6 +39,7 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockListFragment; import com.actionbarsherlock.app.SherlockListFragment;
@ -100,12 +101,6 @@ public class ImportKeysListFragment extends SherlockListFragment implements
mActivity = getActivity(); mActivity = getActivity();
if (getArguments() != null) {
mDataUri = getArguments().getParcelable(ARG_DATA_URI);
mKeyBytes = getArguments().getByteArray(ARG_BYTES);
mServerQuery = getArguments().getString(ARG_SERVER_QUERY);
}
// Give some text to display if there is no data. In a real // Give some text to display if there is no data. In a real
// application this would come from a resource. // application this would come from a resource.
setEmptyText(mActivity.getString(R.string.error_nothing_import)); setEmptyText(mActivity.getString(R.string.error_nothing_import));
@ -114,14 +109,29 @@ public class ImportKeysListFragment extends SherlockListFragment implements
mAdapter = new ImportKeysAdapter(mActivity); mAdapter = new ImportKeysAdapter(mActivity);
setListAdapter(mAdapter); setListAdapter(mAdapter);
// Start out with a progress indicator. mDataUri = getArguments().getParcelable(ARG_DATA_URI);
setListShown(false); mKeyBytes = getArguments().getByteArray(ARG_BYTES);
mServerQuery = getArguments().getString(ARG_SERVER_QUERY);
// Prepare the loader. Either re-connect with an existing one, if (mDataUri != null || mKeyBytes != null) {
// or start a new one. // Start out with a progress indicator.
// give arguments to onCreateLoader() setListShown(false);
getLoaderManager().initLoader(LOADER_ID_BYTES, null, this);
getLoaderManager().initLoader(LOADER_ID_SERVER_QUERY, null, this); // Prepare the loader. Either re-connect with an existing one,
// or start a new one.
// give arguments to onCreateLoader()
getLoaderManager().initLoader(LOADER_ID_BYTES, null, this);
}
if (mServerQuery != null) {
// Start out with a progress indicator.
setListShown(false);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
// give arguments to onCreateLoader()
getLoaderManager().initLoader(LOADER_ID_SERVER_QUERY, null, this);
}
} }
@Override @Override
@ -142,6 +152,9 @@ public class ImportKeysListFragment extends SherlockListFragment implements
mServerQuery = serverQuery; mServerQuery = serverQuery;
mKeyServer = keyServer; mKeyServer = keyServer;
// Start out with a progress indicator.
setListShown(false);
if (mKeyBytes != null || mDataUri != null) if (mKeyBytes != null || mDataUri != null)
getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this); getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this);
@ -186,17 +199,21 @@ public class ImportKeysListFragment extends SherlockListFragment implements
} else { } else {
setListShownNoAnimation(true); setListShownNoAnimation(true);
} }
// switch (loader.getId()) { switch (loader.getId()) {
// case LOADER_ID_BYTES: case LOADER_ID_BYTES:
// break;
// break;
// case LOADER_ID_SERVER_QUERY:
// case LOADER_ID_SERVER_QUERY: Toast.makeText(
// break; getActivity(), getResources().getQuantityString(R.plurals.keys_found,
// mAdapter.getCount(), mAdapter.getCount()),
// default: Toast.LENGTH_SHORT
// break; ).show();
// } break;
default:
break;
}
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012-2013 Dominik Schürmann <dominik@dominikschuermann.de> * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by