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:configChanges="keyboardHidden|orientation"
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
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
android:name="de.danoeh.antennapod.activity.AddFeedActivity"
@ -99,7 +100,10 @@
android:configChanges="orientation|screenSize" >
<meta-data
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
android:name="de.danoeh.antennapod.activity.ItemviewActivity"
@ -256,16 +260,16 @@
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
<meta-data
android:name="android.app.default_searchable"
android:value=".activity.SearchActivity" />
</activity>
<activity
android:name=".activity.MiroGuideMainActivity"
android:label="@string/miro_guide_label" >
<meta-data
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
android:name=".activity.MiroGuideSearchActivity"
@ -278,9 +282,6 @@
<meta-data
android:name="android.app.searchable"
android:resource="@xml/miroguide_searchable" />
<meta-data
android:name="android.app.default_searchable"
android:value=".activity.MiroGuideSearchActivity" />
</activity>
<activity
android:name=".activity.MiroGuideCategoryActivity"

View File

@ -1,7 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<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:title="@string/add_feed_label"
android:icon="?attr/content_new"
@ -9,9 +14,32 @@
</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">
</item><item android:id="@+id/show_preferences" android:title="@string/settings_label" android:icon="?attr/action_settings" android:showAsAction="collapseActionView"></item>
<item
android:id="@id/search_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>

View File

@ -1,5 +1,4 @@
<?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>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_hint"
android:label="@string/app_name"/>

View File

@ -1,6 +1,9 @@
package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
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.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.util.Log;
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)
.setIcon(drawables.getDrawable(0)),
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
.onCreateOptionsMenu(new MenuInflater(this), menu);
} else {
@ -155,9 +168,6 @@ public class FeedItemlistActivity extends ActionBarActivity {
};
conDialog.createNewDialog().show();
break;
case R.id.search_item:
onSearchRequested();
break;
case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class);
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
public void onStop() {
super.onStop();
EventDistributor.getInstance().unregister(contentUpdate);
if (AppConfig.DEBUG)
Log.d(TAG, "Stopping Activity");
}

View File

@ -2,15 +2,19 @@ package de.danoeh.antennapod.activity;
import java.util.ArrayList;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Menu;
@ -150,9 +154,6 @@ public class MainActivity extends ActionBarActivity {
case R.id.show_player:
startActivity(PlaybackService.getPlayerActivityIntent(this));
return true;
case R.id.search_item:
onSearchRequested();
return true;
case R.id.show_playback_history:
startActivity(new Intent(this, PlaybackHistoryActivity.class));
return true;
@ -177,6 +178,17 @@ public class MainActivity extends ActionBarActivity {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.main, menu);
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;
}

View File

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

View File

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