Fixed search

This commit is contained in:
daniel oeh 2013-08-14 17:22:13 +02:00
parent a1b0b5ac09
commit 6b69f7fe28
8 changed files with 128 additions and 49 deletions

View File

@ -40,15 +40,16 @@
android:name=".activity.MainActivity" android:name=".activity.MainActivity"
android:configChanges="keyboardHidden|orientation" android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name" > android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data <meta-data
android:name="android.app.default_searchable" android:name="android.app.default_searchable"
android:value=".activity.SearchActivity" /> android:value="de.danoeh.antennapod.activity.SearchActivity" />
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name="de.danoeh.antennapod.activity.AddFeedActivity" android:name="de.danoeh.antennapod.activity.AddFeedActivity"
@ -99,7 +100,10 @@
android:configChanges="orientation|screenSize" > android:configChanges="orientation|screenSize" >
<meta-data <meta-data
android:name="android.app.default_searchable" android:name="android.app.default_searchable"
android:value=".activity.SearchActivity" /> android:value="de.danoeh.antennapod.activity.SearchActivity" />
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity> </activity>
<activity <activity
android:name="de.danoeh.antennapod.activity.ItemviewActivity" android:name="de.danoeh.antennapod.activity.ItemviewActivity"
@ -256,16 +260,16 @@
<meta-data <meta-data
android:name="android.app.searchable" android:name="android.app.searchable"
android:resource="@xml/searchable" /> android:resource="@xml/searchable" />
<meta-data
android:name="android.app.default_searchable"
android:value=".activity.SearchActivity" />
</activity> </activity>
<activity <activity
android:name=".activity.MiroGuideMainActivity" android:name=".activity.MiroGuideMainActivity"
android:label="@string/miro_guide_label" > android:label="@string/miro_guide_label" >
<meta-data <meta-data
android:name="android.app.default_searchable" android:name="android.app.default_searchable"
android:value=".activity.MiroGuideSearchActivity" /> android:value="de.danoeh.antennapod.activity.MiroGuideSearchActivity" />
<meta-data
android:name="android.app.searchable"
android:resource="@xml/miroguide_searchable" />
</activity> </activity>
<activity <activity
android:name=".activity.MiroGuideSearchActivity" android:name=".activity.MiroGuideSearchActivity"
@ -278,9 +282,6 @@
<meta-data <meta-data
android:name="android.app.searchable" android:name="android.app.searchable"
android:resource="@xml/miroguide_searchable" /> android:resource="@xml/miroguide_searchable" />
<meta-data
android:name="android.app.default_searchable"
android:value=".activity.MiroGuideSearchActivity" />
</activity> </activity>
<activity <activity
android:name=".activity.MiroGuideCategoryActivity" android:name=".activity.MiroGuideCategoryActivity"

View File

@ -1,17 +1,45 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/all_feed_refresh" android:title="@string/refresh_label" android:icon="?attr/navigation_refresh" android:showAsAction="ifRoom|collapseActionView"> <item
</item><item android:id="@+id/all_feed_refresh"
android:title="@string/refresh_label"
android:icon="?attr/navigation_refresh"
android:showAsAction="ifRoom|collapseActionView">
</item>
<item
android:id="@+id/add_feed" android:id="@+id/add_feed"
android:title="@string/add_feed_label" android:title="@string/add_feed_label"
android:icon="?attr/content_new" android:icon="?attr/content_new"
android:showAsAction="ifRoom|collapseActionView"> android:showAsAction="ifRoom|collapseActionView">
</item> </item>
<item
<item android:id="@id/search_item" android:icon="?attr/action_search" android:title="@string/search_label" android:showAsAction="ifRoom|collapseActionView"></item><item android:id="@+id/show_player" android:title="@string/show_player_label" android:icon="@drawable/av_play" android:showAsAction="collapseActionView"></item><item android:id="@+id/show_playback_history" android:title="@string/playback_history_label" android:showAsAction="collapseActionView"></item><item android:id="@+id/show_downloads" android:title="@string/downloads_label" android:icon="@drawable/av_download" android:showAsAction="collapseActionView"> android:id="@id/search_item"
</item><item android:id="@+id/show_preferences" android:title="@string/settings_label" android:icon="?attr/action_settings" android:showAsAction="collapseActionView"></item> android:icon="?attr/action_search"
android:title="@string/search_label"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.support.v7.widget.SearchView"/>
<item
android:id="@+id/show_player"
android:title="@string/show_player_label"
android:icon="@drawable/av_play"
android:showAsAction="collapseActionView"/>
<item
android:id="@+id/show_playback_history"
android:title="@string/playback_history_label"
android:showAsAction="collapseActionView"/>
<item
android:id="@+id/show_downloads"
android:title="@string/downloads_label"
android:icon="@drawable/av_download"
android:showAsAction="collapseActionView">
</item>
<item
android:id="@+id/show_preferences"
android:title="@string/settings_label"
android:icon="?attr/action_settings"
android:showAsAction="collapseActionView"/>
</menu> </menu>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:hint="@string/search_hint" android:label="@string/app_name" android:icon="@drawable/ic_launcher"> <searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_hint"
android:label="@string/app_name"/>
</searchable>

View File

@ -1,6 +1,9 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@ -10,6 +13,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
@ -113,6 +117,15 @@ public class FeedItemlistActivity extends ActionBarActivity {
MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
.setIcon(drawables.getDrawable(0)), .setIcon(drawables.getDrawable(0)),
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
MenuItemCompat.setActionView(menu.findItem(R.id.search_item), new SearchView(this));
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_item));
searchView.setIconifiedByDefault(true);
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return FeedMenuHandler return FeedMenuHandler
.onCreateOptionsMenu(new MenuInflater(this), menu); .onCreateOptionsMenu(new MenuInflater(this), menu);
} else { } else {
@ -155,9 +168,6 @@ public class FeedItemlistActivity extends ActionBarActivity {
}; };
conDialog.createNewDialog().show(); conDialog.createNewDialog().show();
break; break;
case R.id.search_item:
onSearchRequested();
break;
case android.R.id.home: case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -185,4 +195,17 @@ public class FeedItemlistActivity extends ActionBarActivity {
} }
} }
@Override
public void startActivity(Intent intent) {
if (intent.getAction() != null &&
intent.getAction().equals(Intent.ACTION_SEARCH)) {
addSearchInformation(intent);
}
super.startActivity(intent);
}
private void addSearchInformation(Intent startIntent) {
startIntent.putExtra(SearchActivity.EXTRA_FEED_ID, feed.getId());
}
} }

View File

@ -65,6 +65,7 @@ public class ItemviewActivity extends ActionBarActivity {
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
EventDistributor.getInstance().unregister(contentUpdate);
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Stopping Activity"); Log.d(TAG, "Stopping Activity");
} }

View File

@ -2,15 +2,19 @@ package de.danoeh.antennapod.activity;
import java.util.ArrayList; import java.util.ArrayList;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
@ -150,9 +154,6 @@ public class MainActivity extends ActionBarActivity {
case R.id.show_player: case R.id.show_player:
startActivity(PlaybackService.getPlayerActivityIntent(this)); startActivity(PlaybackService.getPlayerActivityIntent(this));
return true; return true;
case R.id.search_item:
onSearchRequested();
return true;
case R.id.show_playback_history: case R.id.show_playback_history:
startActivity(new Intent(this, PlaybackHistoryActivity.class)); startActivity(new Intent(this, PlaybackHistoryActivity.class));
return true; return true;
@ -177,7 +178,18 @@ public class MainActivity extends ActionBarActivity {
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = new MenuInflater(this); MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.main, menu); inflater.inflate(R.menu.main, menu);
return true;
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_item));
searchView.setIconifiedByDefault(true);
SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
} }
public static class TabsAdapter extends FragmentPagerAdapter implements public static class TabsAdapter extends FragmentPagerAdapter implements

View File

@ -1,11 +1,15 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -44,6 +48,7 @@ public class MiroGuideMainActivity extends ActionBarActivity implements AdapterV
txtvStatus = (TextView) findViewById(android.R.id.empty); txtvStatus = (TextView) findViewById(android.R.id.empty);
listView = (ListView) findViewById(android.R.id.list); listView = (ListView) findViewById(android.R.id.list);
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
listView.setEmptyView(txtvStatus);
} }
@Override @Override
@ -129,6 +134,15 @@ public class MiroGuideMainActivity extends ActionBarActivity implements AdapterV
new int[]{R.attr.action_search}) new int[]{R.attr.action_search})
.getDrawable(0)), .getDrawable(0)),
MenuItem.SHOW_AS_ACTION_IF_ROOM); MenuItem.SHOW_AS_ACTION_IF_ROOM);
MenuItemCompat.setActionView(menu.findItem(R.id.search_item), new SearchView(this));
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_item));
searchView.setIconifiedByDefault(true);
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true; return true;
} }
@ -138,9 +152,6 @@ public class MiroGuideMainActivity extends ActionBarActivity implements AdapterV
case android.R.id.home: case android.R.id.home:
finish(); finish();
return true; return true;
case R.id.search_item:
onSearchRequested();
return true;
default: default:
return false; return false;
} }

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -36,7 +37,6 @@ public class SearchActivity extends ActionBarActivity implements AdapterView.OnI
public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.searchactivity.extra.feedId"; public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.searchactivity.extra.feedId";
private SearchlistAdapter searchAdapter; private SearchlistAdapter searchAdapter;
private List<SearchResult> content;
/** /**
* ID of the feed that is being searched or null if the search is global. * ID of the feed that is being searched or null if the search is global.
@ -46,6 +46,7 @@ public class SearchActivity extends ActionBarActivity implements AdapterView.OnI
private ListView listView; private ListView listView;
private TextView txtvStatus; private TextView txtvStatus;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme()); setTheme(UserPreferences.getTheme());
@ -57,6 +58,9 @@ public class SearchActivity extends ActionBarActivity implements AdapterView.OnI
txtvStatus = (TextView) findViewById(android.R.id.empty); txtvStatus = (TextView) findViewById(android.R.id.empty);
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
searchAdapter = new SearchlistAdapter(this, 0, new ArrayList<SearchResult>());
listView.setAdapter(searchAdapter);
listView.setEmptyView(txtvStatus);
} }
@Override @Override
@ -69,11 +73,10 @@ public class SearchActivity extends ActionBarActivity implements AdapterView.OnI
super.onResume(); super.onResume();
Intent intent = getIntent(); Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
Bundle extra = intent.getBundleExtra(SearchManager.APP_DATA); if (intent.hasExtra(SearchActivity.EXTRA_FEED_ID)) {
if (extra != null) {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Found bundle extra"); Log.d(TAG, "Found bundle extra");
feedID = extra.getLong(EXTRA_FEED_ID); feedID = intent.getLongExtra(SearchActivity.EXTRA_FEED_ID, 0);
} }
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Starting search"); Log.d(TAG, "Starting search");
@ -149,15 +152,16 @@ public class SearchActivity extends ActionBarActivity implements AdapterView.OnI
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Found " + result.size() Log.d(TAG, "Found " + result.size()
+ " results"); + " results");
content = result;
searchAdapter = new SearchlistAdapter( searchAdapter.clear();
SearchActivity.this, 0, content); searchAdapter.addAll(result);
listView.setAdapter(searchAdapter);
searchAdapter.notifyDataSetChanged(); searchAdapter.notifyDataSetChanged();
if (content.isEmpty()) { txtvStatus
txtvStatus .setText(R.string.search_status_no_results);
.setText(R.string.search_status_no_results); if (!searchAdapter.isEmpty()) {
txtvStatus.setVisibility(View.GONE);
} else {
txtvStatus.setVisibility(View.VISIBLE);
} }
} }
}); });