From 17f63e071616bae0dbd01014d28781ed22e5234d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 1 Feb 2014 20:11:17 +0100 Subject: Fix loader init --- .../keychain/ui/ImportKeysListFragment.java | 65 ++++++++++++++-------- .../ui/adapter/ImportKeysListServerLoader.java | 2 +- 2 files changed, 42 insertions(+), 25 deletions(-) (limited to 'OpenPGP-Keychain/src/main') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index d33a20cc5..9c9dda0b4 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -39,6 +39,7 @@ import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.view.View; import android.widget.ListView; +import android.widget.Toast; import com.actionbarsherlock.app.SherlockListFragment; @@ -100,12 +101,6 @@ public class ImportKeysListFragment extends SherlockListFragment implements 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 // application this would come from a resource. setEmptyText(mActivity.getString(R.string.error_nothing_import)); @@ -114,14 +109,29 @@ public class ImportKeysListFragment extends SherlockListFragment implements mAdapter = new ImportKeysAdapter(mActivity); setListAdapter(mAdapter); - // Start out with a progress indicator. - setListShown(false); + mDataUri = getArguments().getParcelable(ARG_DATA_URI); + mKeyBytes = getArguments().getByteArray(ARG_BYTES); + mServerQuery = getArguments().getString(ARG_SERVER_QUERY); + + if (mDataUri != null || mKeyBytes != 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_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 @@ -142,6 +152,9 @@ public class ImportKeysListFragment extends SherlockListFragment implements mServerQuery = serverQuery; mKeyServer = keyServer; + // Start out with a progress indicator. + setListShown(false); + if (mKeyBytes != null || mDataUri != null) getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this); @@ -186,17 +199,21 @@ public class ImportKeysListFragment extends SherlockListFragment implements } else { setListShownNoAnimation(true); } -// switch (loader.getId()) { -// case LOADER_ID_BYTES: -// -// break; -// -// case LOADER_ID_SERVER_QUERY: -// break; -// -// default: -// break; -// } + switch (loader.getId()) { + case LOADER_ID_BYTES: + break; + + case LOADER_ID_SERVER_QUERY: + Toast.makeText( + getActivity(), getResources().getQuantityString(R.plurals.keys_found, + mAdapter.getCount(), mAdapter.getCount()), + Toast.LENGTH_SHORT + ).show(); + break; + + default: + break; + } } @Override diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java index 22d92c10b..753994450 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013 Dominik Schürmann + * Copyright (C) 2014 Dominik Schürmann * * 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 -- cgit v1.2.3