From 33711e1657546f5478d94d5f191d958011611f74 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Thu, 13 Sep 2012 13:15:30 +0200 Subject: [PATCH] Fix orientation change bug in ItemDescriptionFragment --- AndroidManifest.xml | 3 +- .../antennapod/activity/ItemviewActivity.java | 2 +- .../fragment/ItemDescriptionFragment.java | 44 +++++++++++++------ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 07e71ef9d..67e50cf33 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -60,8 +60,7 @@ android:value=".activity.SearchActivity" /> + android:name="de.danoeh.antennapod.activity.ItemviewActivity" android:configChanges="keyboard|orientation"/> diff --git a/src/de/danoeh/antennapod/activity/ItemviewActivity.java b/src/de/danoeh/antennapod/activity/ItemviewActivity.java index c31cc7c77..dbcb86656 100644 --- a/src/de/danoeh/antennapod/activity/ItemviewActivity.java +++ b/src/de/danoeh/antennapod/activity/ItemviewActivity.java @@ -94,7 +94,7 @@ public class ItemviewActivity extends SherlockFragmentActivity { .beginTransaction(); ItemDescriptionFragment fragment = ItemDescriptionFragment.newInstance( item); - fragmentTransaction.add(R.id.description_fragment, fragment); + fragmentTransaction.replace(R.id.description_fragment, fragment); fragmentTransaction.commit(); } diff --git a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index 4d4f2ff40..ed10195d7 100644 --- a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -48,29 +48,30 @@ public class ItemDescriptionFragment extends SherlockFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + if (AppConfig.DEBUG) + Log.d(TAG, "Creating view"); webvDescription = new WebView(getActivity()); webvDescription.getSettings().setUseWideViewPort(false); - return webvDescription; } - @SuppressLint("NewApi") + @Override + public void onDestroyView() { + super.onDestroyView(); + } + @Override public void onAttach(Activity activity) { super.onAttach(activity); - if (webViewLoader == null && 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(); - } - } + if (AppConfig.DEBUG) + Log.d(TAG, "Fragment attached"); } @Override public void onDetach() { super.onDetach(); + if (AppConfig.DEBUG) + Log.d(TAG, "Fragment detached"); if (webViewLoader != null) { webViewLoader.cancel(true); } @@ -79,6 +80,8 @@ public class ItemDescriptionFragment extends SherlockFragment { @Override public void onDestroy() { super.onDestroy(); + if (AppConfig.DEBUG) + Log.d(TAG, "Fragment destroyed"); if (webViewLoader != null) { webViewLoader.cancel(true); } @@ -88,6 +91,8 @@ public class ItemDescriptionFragment extends SherlockFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (AppConfig.DEBUG) + Log.d(TAG, "Creating fragment"); setRetainInstance(true); FeedManager manager = FeedManager.getInstance(); Bundle args = getArguments(); @@ -96,6 +101,17 @@ public class ItemDescriptionFragment extends SherlockFragment { if (feedId != -1 && itemId != -1) { Feed feed = manager.getFeed(feedId); item = manager.getFeedItem(itemId, feed); + + } else { + Log.e(TAG, TAG + " was called with invalid arguments"); + } + } + + @SuppressLint("NewApi") + @Override + 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); @@ -103,9 +119,13 @@ public class ItemDescriptionFragment extends SherlockFragment { webViewLoader.execute(); } } else { - Log.e(TAG, TAG + " was called with invalid arguments"); + Log.e(TAG, "Error in onViewCreated: Item was null"); } + } + @Override + public void onResume() { + super.onResume(); } private AsyncTask createLoader() { @@ -159,8 +179,6 @@ public class ItemDescriptionFragment extends SherlockFragment { return null; } - - }; } }