diff --git a/core/res/layout-w600dp/activity_search.xml b/core/res/layout-w600dp/activity_search.xml index 6df18868..df073660 100644 --- a/core/res/layout-w600dp/activity_search.xml +++ b/core/res/layout-w600dp/activity_search.xml @@ -32,7 +32,7 @@ android:listSelector="?attr/selectable_background_transdroid" /> lastNavigationLabels; // Contained torrent and details fragments - @FragmentById(resName = "torrent_list") + @FragmentById(resName = "torrents_fragment") protected TorrentsFragment fragmentTorrents; - @FragmentById(resName = "torrent_details") + @FragmentById(resName = "torrentdetails_fragment") protected DetailsFragment fragmentDetails; // Auto refresh task @@ -368,42 +368,38 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, super.onDestroy(); } - @TargetApi(Build.VERSION_CODES.FROYO) @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); if (navigationHelper.enableSearchUi()) { - // For Android 2.1+, add an expandable SearchView to the action bar + // Add an expandable SearchView to the action bar MenuItem item = menu.findItem(R.id.action_search); - if (android.os.Build.VERSION.SDK_INT >= 8) { - SearchView searchView = new SearchView(this); - searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); - searchView.setQueryRefinementEnabled(true); - searchView.setOnSearchClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - // Pause autorefresh - stopRefresh = true; - stopAutoRefresh(); - } - }); - // NOTE ABS's OnCloseListener is not working, hence using an OnActionExpandListener - item.setOnActionExpandListener(new OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem item) { - return true; - } + SearchView searchView = new SearchView(this); + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + searchView.setQueryRefinementEnabled(true); + searchView.setOnSearchClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + // Pause autorefresh + stopRefresh = true; + stopAutoRefresh(); + } + }); + item.setOnActionExpandListener(new OnActionExpandListener() { + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return true; + } - @Override - public boolean onMenuItemActionCollapse(MenuItem item) { - stopRefresh = false; - startAutoRefresh(); - return true; - } - }); - item.setActionView(searchView); - searchMenu = item; - } + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + stopRefresh = false; + startAutoRefresh(); + return true; + } + }); + item.setActionView(searchView); + searchMenu = item; } return true; } @@ -510,7 +506,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, // Clear the currently shown list of torrents and perhaps the details fragmentTorrents.clear(true, true); - if (fragmentDetails != null && fragmentDetails.getActivity() != null) { + if (fragmentDetails != null && fragmentDetails.isAdded() && fragmentDetails.getActivity() != null) { fragmentDetails.updateIsLoading(false, null); fragmentDetails.clear(); fragmentDetails.setCurrentServerSettings(server); @@ -530,7 +526,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, // Remember that the user last selected this applicationSettings.setLastUsedNavigationFilter(currentFilter); // Clear the details view - if (fragmentDetails != null) { + if (fragmentDetails != null && fragmentDetails.isAdded()) { fragmentDetails.updateIsLoading(false, null); fragmentDetails.clear(); } @@ -545,7 +541,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, private void updateFragmentVisibility(boolean hasServerSettings) { if (filtersList != null) filtersList.setVisibility(hasServerSettings ? View.VISIBLE : View.GONE); - if (fragmentDetails != null) { + if (fragmentDetails != null && fragmentDetails.isAdded()) { if (hasServerSettings) getFragmentManager().beginTransaction().show(fragmentDetails).commit(); else @@ -818,7 +814,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, * @param torrent The torrent to show detailed statistics for */ public void openDetails(Torrent torrent) { - if (fragmentDetails != null) { + if (fragmentDetails != null && fragmentDetails.isAdded()) { fragmentDetails.updateTorrent(torrent); } else { DetailsActivity_.intent(this).torrent(torrent).currentLabels(lastNavigationLabels) @@ -1186,7 +1182,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, fragmentTorrents.updateIsLoading(false); if (isCritical) { fragmentTorrents.updateError(error); - if (fragmentDetails != null) + if (fragmentDetails != null && fragmentDetails.isAdded()) fragmentDetails.updateIsLoading(false, error); } } @@ -1202,7 +1198,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, fragmentTorrents.updateTorrents(new ArrayList(torrents), lastNavigationLabels); // Update the details fragment if the currently shown torrent is in the newly retrieved list - if (fragmentDetails != null) { + if (fragmentDetails != null && fragmentDetails.isAdded()) { fragmentDetails.perhapsUpdateTorrent(torrents); } @@ -1214,7 +1210,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, // Labels are shown in the action bar spinner navigationSpinnerAdapter.updateLabels(lastNavigationLabels); } - if (fragmentDetails != null) + if (fragmentDetails != null && fragmentDetails.isAdded()) fragmentDetails.updateLabels(lastNavigationLabels); // Perhaps we were still waiting to preselect the last used filter (on a fresh application start) @@ -1244,14 +1240,14 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, @UiThread protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) { // Update the details fragment with the new fine details for the shown torrent - if (fragmentDetails != null) + if (fragmentDetails != null && fragmentDetails.isAdded()) fragmentDetails.updateTorrentDetails(torrent, torrentDetails); } @UiThread protected void onTorrentFilesRetrieved(Torrent torrent, List torrentFiles) { // Update the details fragment with the newly retrieved list of files - if (fragmentDetails != null) + if (fragmentDetails != null && fragmentDetails.isAdded()) fragmentDetails.updateTorrentFiles(torrent, new ArrayList(torrentFiles)); } diff --git a/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java b/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java index 08666f71..15dd8112 100644 --- a/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -53,9 +53,9 @@ public class RssfeedsActivity extends Activity { protected List loaders; // Contained feeds and items fragments - @FragmentById(resName = "rssfeeds_list") + @FragmentById(resName = "rssfeeds_fragment") protected RssfeedsFragment fragmentFeeds; - @FragmentById(resName = "rssitems_list") + @FragmentById(resName = "rssitems_fragment") protected RssitemsFragment fragmentItems; @Override @@ -145,7 +145,7 @@ public class RssfeedsActivity extends Activity { public void openRssfeed(RssfeedLoader loader, boolean markAsViewedNow) { // The RSS feed content was loaded and can now be shown in the dedicated fragment or a new activity - if (fragmentItems != null) { + if (fragmentItems != null && fragmentItems.isAdded()) { // If desired, update the lastViewedDate and lastViewedItemUrl of this feed in the user setting; this won't // be loaded until the RSS feeds screen in opened again. diff --git a/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java b/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java index 7d36e69e..30125d7e 100644 --- a/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java +++ b/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java @@ -41,7 +41,7 @@ public class RssitemsActivity extends Activity { @Extra protected String rssfeedName; - @FragmentById(resName = "rssitems_list") + @FragmentById(resName = "rssitems_fragment") protected RssitemsFragment fragmentItems; @Override diff --git a/core/src/org/transdroid/core/gui/search/SearchActivity.java b/core/src/org/transdroid/core/gui/search/SearchActivity.java index 390fdf8e..b3ad5d2d 100644 --- a/core/src/org/transdroid/core/gui/search/SearchActivity.java +++ b/core/src/org/transdroid/core/gui/search/SearchActivity.java @@ -29,8 +29,10 @@ import org.androidannotations.annotations.ViewById; import org.transdroid.core.R; import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchSite; -import org.transdroid.core.app.settings.*; -import org.transdroid.core.gui.*; +import org.transdroid.core.app.settings.ApplicationSettings; +import org.transdroid.core.app.settings.SystemSettings_; +import org.transdroid.core.app.settings.WebsearchSetting; +import org.transdroid.core.gui.TorrentsActivity_; import org.transdroid.core.gui.navigation.NavigationHelper; import android.annotation.TargetApi; @@ -62,7 +64,7 @@ import android.widget.TextView; @OptionsMenu(resName = "activity_search") public class SearchActivity extends Activity implements OnNavigationListener { - @FragmentById(resName = "searchresults_list") + @FragmentById(resName = "searchresults_fragment") protected SearchResultsFragment fragmentResults; @ViewById protected ListView searchsitesList; @@ -141,20 +143,17 @@ public class SearchActivity extends Activity implements OnNavigationListener { } - @TargetApi(Build.VERSION_CODES.FROYO) @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); if (navigationHelper.enableSearchUi()) { - // For Android 2.1+, add an expandable SearchView to the action bar + // Add an expandable SearchView to the action bar MenuItem item = menu.findItem(R.id.action_search); - if (android.os.Build.VERSION.SDK_INT >= 8) { - final SearchView searchView = new SearchView(this); - searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); - searchView.setQueryRefinementEnabled(true); - item.setActionView(searchView); - searchMenu = item; - } + final SearchView searchView = new SearchView(this); + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + searchView.setQueryRefinementEnabled(true); + item.setActionView(searchView); + searchMenu = item; } return true; }