From 6a4abe1e854d17ea502349cb9d7e8b1f8fc737fc Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sat, 27 Oct 2012 21:51:29 +0200 Subject: [PATCH] Implemented Asynchronous description loading in Itemdescriptionfragment --- .../danoeh/antennapod/feed/FeedManager.java | 3 ++ .../fragment/ItemDescriptionFragment.java | 32 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index 5607bf48b..86ab31475 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -1320,6 +1320,9 @@ public class FeedManager { public void loadExtraInformationOfItem(final Context context, final FeedItem item, FeedManager.TaskCallback callback) { + if (AppConfig.DEBUG) + Log.d(TAG, + "Loading extra information of item with id " + item.getId()); dbExec.execute(new FeedManager.Task(new Handler(), callback) { @Override diff --git a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index b05df96b2..2322a4e3c 100644 --- a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -109,12 +109,20 @@ public class ItemDescriptionFragment extends SherlockFragment { public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (item != null) { - webViewLoader = createLoader(); - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - webViewLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - webViewLoader.execute(); - } + FeedManager.getInstance().loadExtraInformationOfItem(getActivity(), + item, new FeedManager.TaskCallback() { + + @Override + public void onCompletion() { + webViewLoader = createLoader(); + if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { + webViewLoader + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + webViewLoader.execute(); + } + } + }); } else { Log.e(TAG, "Error in onViewCreated: Item was null"); } @@ -145,8 +153,10 @@ public class ItemDescriptionFragment extends SherlockFragment { // /webvDescription.loadData(url, "text/html", "utf-8"); webvDescription.loadDataWithBaseURL(null, data, "text/html", "utf-8", "about:blank"); - getSherlockActivity() - .setSupportProgressBarIndeterminateVisibility(false); + if (getSherlockActivity() != null) { + getSherlockActivity() + .setSupportProgressBarIndeterminateVisibility(false); + } if (AppConfig.DEBUG) Log.d(TAG, "Webview loaded"); webViewLoader = null; @@ -155,8 +165,10 @@ public class ItemDescriptionFragment extends SherlockFragment { @Override protected void onPreExecute() { super.onPreExecute(); - getSherlockActivity() - .setSupportProgressBarIndeterminateVisibility(true); + if (getSherlockActivity() != null) { + getSherlockActivity() + .setSupportProgressBarIndeterminateVisibility(true); + } } @Override