From 7926494d7657482df83a898750f7cb33f517e041 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Thu, 5 Sep 2013 14:39:53 +0200 Subject: [PATCH] Added workarounds for ActionMode/Option menu bugs --- .../antennapod/activity/FeedInfoActivity.java | 185 +++++++++--------- .../antennapod/fragment/FeedlistFragment.java | 4 +- 2 files changed, 97 insertions(+), 92 deletions(-) diff --git a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java index 4a8a2f1f8..3cb46a4f8 100644 --- a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java +++ b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java @@ -9,7 +9,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.widget.ImageView; import android.widget.TextView; - import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.ImageLoader; @@ -21,80 +20,81 @@ import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.util.LangUtils; import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; -/** Displays information about a feed. */ +/** + * Displays information about a feed. + */ public class FeedInfoActivity extends ActionBarActivity { - private static final String TAG = "FeedInfoActivity"; + private static final String TAG = "FeedInfoActivity"; - public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId"; + public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId"; - private Feed feed; + private Feed feed; - private ImageView imgvCover; - private TextView txtvTitle; - private TextView txtvDescription; - private TextView txtvLanguage; - private TextView txtvAuthor; + private ImageView imgvCover; + private TextView txtvTitle; + private TextView txtvDescription; + private TextView txtvLanguage; + private TextView txtvAuthor; - @Override - protected void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getTheme()); - super.onCreate(savedInstanceState); - setContentView(R.layout.feedinfo); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1); - - AsyncTask loadTask = new AsyncTask() { + @Override + protected void onCreate(Bundle savedInstanceState) { + setTheme(UserPreferences.getTheme()); + super.onCreate(savedInstanceState); + setContentView(R.layout.feedinfo); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1); - @Override - protected Feed doInBackground(Long... params) { - return DBReader.getFeed(FeedInfoActivity.this, params[0]); - } + AsyncTask loadTask = new AsyncTask() { - @Override - protected void onPostExecute(Feed result) { - super.onPostExecute(result); - if (result != null) { - feed = result; - if (feed != null) { - if (AppConfig.DEBUG) - Log.d(TAG, "Language is " + feed.getLanguage()); - if (AppConfig.DEBUG) - Log.d(TAG, "Author is " + feed.getAuthor()); - imgvCover = (ImageView) findViewById(R.id.imgvCover); - txtvTitle = (TextView) findViewById(R.id.txtvTitle); - txtvDescription = (TextView) findViewById(R.id.txtvDescription); - txtvLanguage = (TextView) findViewById(R.id.txtvLanguage); - txtvAuthor = (TextView) findViewById(R.id.txtvAuthor); - imgvCover.post(new Runnable() { + @Override + protected Feed doInBackground(Long... params) { + return DBReader.getFeed(FeedInfoActivity.this, params[0]); + } - @Override - public void run() { - ImageLoader.getInstance().loadThumbnailBitmap( - feed.getImage(), imgvCover); - } - }); + @Override + protected void onPostExecute(Feed result) { + super.onPostExecute(result); + if (result != null) { + feed = result; + if (AppConfig.DEBUG) + Log.d(TAG, "Language is " + feed.getLanguage()); + if (AppConfig.DEBUG) + Log.d(TAG, "Author is " + feed.getAuthor()); + imgvCover = (ImageView) findViewById(R.id.imgvCover); + txtvTitle = (TextView) findViewById(R.id.txtvTitle); + txtvDescription = (TextView) findViewById(R.id.txtvDescription); + txtvLanguage = (TextView) findViewById(R.id.txtvLanguage); + txtvAuthor = (TextView) findViewById(R.id.txtvAuthor); + imgvCover.post(new Runnable() { - txtvTitle.setText(feed.getTitle()); - txtvDescription.setText(feed.getDescription()); - if (feed.getAuthor() != null) { - txtvAuthor.setText(feed.getAuthor()); - } - if (feed.getLanguage() != null) { - txtvLanguage.setText(LangUtils - .getLanguageString(feed.getLanguage())); - } - supportInvalidateOptionsMenu(); - } - } else { - Log.e(TAG, "Activity was started with invalid arguments"); - } - } - }; - loadTask.execute(feedId); - } + @Override + public void run() { + ImageLoader.getInstance().loadThumbnailBitmap( + feed.getImage(), imgvCover); + } + }); - @Override - public boolean onCreateOptionsMenu(Menu menu) { + txtvTitle.setText(feed.getTitle()); + txtvDescription.setText(feed.getDescription()); + if (feed.getAuthor() != null) { + txtvAuthor.setText(feed.getAuthor()); + } + if (feed.getLanguage() != null) { + txtvLanguage.setText(LangUtils + .getLanguageString(feed.getLanguage())); + } + supportInvalidateOptionsMenu(); + + } else { + Log.e(TAG, "Activity was started with invalid arguments"); + } + } + }; + loadTask.execute(feedId); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { if (feed != null) { MenuInflater inflater = new MenuInflater(this); inflater.inflate(R.menu.feedinfo, menu); @@ -102,32 +102,35 @@ public class FeedInfoActivity extends ActionBarActivity { } else { return false; } - } + } - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.support_item).setVisible( - feed.getPaymentLink() != null); - menu.findItem(R.id.share_link_item).setVisible(feed.getLink() != null); + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + if (feed != null) { + menu.findItem(R.id.support_item).setVisible( + feed.getPaymentLink() != null); + menu.findItem(R.id.share_link_item).setVisible(feed.getLink() != null); + return true; + } else { + return false; + } + } - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - default: - try { - return FeedMenuHandler.onOptionsItemClicked(this, item, feed); - } catch (DownloadRequestException e) { - e.printStackTrace(); - DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, - e.getMessage()); - } - return super.onOptionsItemSelected(item); - } - } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + try { + return FeedMenuHandler.onOptionsItemClicked(this, item, feed); + } catch (DownloadRequestException e) { + e.printStackTrace(); + DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, + e.getMessage()); + } + return super.onOptionsItemSelected(item); + } + } } diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java index 6283a4b7f..ed607b279 100644 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBarActivity; @@ -244,10 +245,11 @@ public class FeedlistFragment extends Fragment implements } private boolean actionModeDestroyWorkaround = false; // TODO remove this workaround + private boolean skipWorkAround = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH; @Override public void onDestroyActionMode(ActionMode mode) { - if (actionModeDestroyWorkaround) { + if (skipWorkAround || actionModeDestroyWorkaround) { mActionMode = null; selectedFeed = null; fla.setSelectedItemIndex(FeedlistAdapter.SELECTION_NONE);