implemented search for single feeds
This commit is contained in:
parent
bc089c9e64
commit
80a9100b8f
|
@ -8,18 +8,26 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14"/>
|
||||
<uses-sdk
|
||||
android:minSdkVersion="10"
|
||||
android:targetSdkVersion="14" />
|
||||
|
||||
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<supports-screens android:normalScreens="true" android:xlargeScreens="true" android:smallScreens="false" android:largeScreens="true"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<supports-screens
|
||||
android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:smallScreens="false"
|
||||
android:xlargeScreens="true" />
|
||||
|
||||
<application
|
||||
android:name="de.danoeh.antennapod.PodcastApp"
|
||||
android:debuggable="false"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:logo="@drawable/ic_launcher"
|
||||
android:theme="@style/Theme.Sherlock.Light.ForceOverflow" android:debuggable="false">
|
||||
android:theme="@style/Theme.Sherlock.Light.ForceOverflow" >
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
|
@ -29,20 +37,30 @@
|
|||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.default_searchable" android:value=".activity.SearchActivity"/>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.default_searchable"
|
||||
android:value=".activity.SearchActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name="de.danoeh.antennapod.activity.AddFeedActivity"
|
||||
android:label="@string/add_new_feed_label" android:configChanges="keyboardHidden|orientation">
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:label="@string/add_new_feed_label" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="de.danoeh.antennapod.activity.FeedItemlistActivity"
|
||||
android:configChanges="orientation|screenSize" />
|
||||
android:configChanges="orientation|screenSize" >
|
||||
<meta-data
|
||||
android:name="android.app.default_searchable"
|
||||
android:value=".activity.SearchActivity" />
|
||||
</activity>
|
||||
<activity android:name="de.danoeh.antennapod.activity.ItemviewActivity" />
|
||||
<activity
|
||||
android:name="de.danoeh.antennapod.activity.DownloadActivity"
|
||||
|
@ -63,7 +81,8 @@
|
|||
|
||||
<activity
|
||||
android:name=".activity.PreferenceActivity"
|
||||
android:label="@string/settings_label" android:configChanges="keyboardHidden|orientation">
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:label="@string/settings_label" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.DownloadLogActivity"
|
||||
|
@ -127,15 +146,32 @@
|
|||
android:scheme="flattr4j" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:label="@string/about_pref" android:name=".activity.AboutActivity" android:theme="@style/Theme.Sherlock.Light.NoActionBar"></activity>
|
||||
<activity android:label="@string/opml_import_label" android:name=".activity.OpmlImportActivity"></activity>
|
||||
<activity android:label="@string/opml_import_label" android:name=".activity.OpmlFeedChooserActivity"></activity>
|
||||
<activity android:name=".activity.SearchActivity" android:launchMode="singleTop" android:label="@string/search_results_label" android:configChanges="keyboardHidden|orientation">
|
||||
<activity
|
||||
android:name=".activity.AboutActivity"
|
||||
android:label="@string/about_pref"
|
||||
android:theme="@style/Theme.Sherlock.Light.NoActionBar" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.OpmlImportActivity"
|
||||
android:label="@string/opml_import_label" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.OpmlFeedChooserActivity"
|
||||
android:label="@string/opml_import_label" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.SearchActivity"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:label="@string/search_results_label"
|
||||
android:launchMode="singleTop" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH"/>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /></activity>
|
||||
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -70,6 +70,9 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
|||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
|
||||
.setIcon(R.drawable.action_search)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
||||
return FeedMenuHandler
|
||||
.onCreateOptionsMenu(new MenuInflater(this), menu);
|
||||
}
|
||||
|
@ -101,6 +104,9 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
|||
remover.execute(feed);
|
||||
}
|
||||
break;
|
||||
case R.id.search_item:
|
||||
onSearchRequested();
|
||||
break;
|
||||
case android.R.id.home:
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
break;
|
||||
|
@ -109,4 +115,14 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSearchRequested() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(SearchActivity.EXTRA_FEED_ID, feed.getId());
|
||||
startSearch(null, false, bundle, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import de.danoeh.antennapod.R;
|
|||
import de.danoeh.antennapod.adapter.SearchlistAdapter;
|
||||
import de.danoeh.antennapod.feed.Feed;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.feed.FeedSearcher;
|
||||
import de.danoeh.antennapod.feed.SearchResult;
|
||||
import de.danoeh.antennapod.fragment.FeedlistFragment;
|
||||
|
@ -29,9 +30,14 @@ import de.danoeh.antennapod.fragment.ItemlistFragment;
|
|||
public class SearchActivity extends SherlockListActivity {
|
||||
private static final String TAG = "SearchActivity";
|
||||
|
||||
public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.searchactivity.extra.feedId";
|
||||
|
||||
private SearchlistAdapter searchAdapter;
|
||||
private ArrayList<SearchResult> content;
|
||||
|
||||
/** Feed that is being searched or null if the search is global. */
|
||||
private Feed selectedFeed;
|
||||
|
||||
private TextView txtvStatus;
|
||||
|
||||
@Override
|
||||
|
@ -40,10 +46,17 @@ public class SearchActivity extends SherlockListActivity {
|
|||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
setContentView(R.layout.searchlist);
|
||||
txtvStatus = (TextView) findViewById(android.R.id.empty);
|
||||
if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
|
||||
Intent intent = getIntent();
|
||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
Bundle extra = intent.getBundleExtra(SearchManager.APP_DATA);
|
||||
if (extra != null) {
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Found bundle extra");
|
||||
long feedId = extra.getLong(EXTRA_FEED_ID);
|
||||
selectedFeed = FeedManager.getInstance().getFeed(feedId);
|
||||
}
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Starting search");
|
||||
String query = getIntent().getStringExtra(SearchManager.QUERY);
|
||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
||||
getSupportActionBar().setSubtitle(
|
||||
getString(R.string.search_term_label) + query);
|
||||
startSearch(query);
|
||||
|
@ -101,7 +114,7 @@ public class SearchActivity extends SherlockListActivity {
|
|||
protected ArrayList<SearchResult> doInBackground(String... params) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Starting background work");
|
||||
return FeedSearcher.performSearch(params[0]);
|
||||
return FeedSearcher.performSearch(params[0], selectedFeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,27 +12,36 @@ import de.danoeh.antennapod.R;
|
|||
public class FeedSearcher {
|
||||
private static final String TAG = "FeedSearcher";
|
||||
|
||||
public static ArrayList<SearchResult> performSearch(final String query) {
|
||||
/** Performs a search in all feeds or one specific feed. */
|
||||
public static ArrayList<SearchResult> performSearch(final String query,
|
||||
Feed selectedFeed) {
|
||||
String lcQuery = query.toLowerCase();
|
||||
ArrayList<SearchResult> result = new ArrayList<SearchResult>();
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Searching Feed titles");
|
||||
searchFeedtitles(lcQuery, result);
|
||||
if (selectedFeed == null) {
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Performing global search");
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Searching Feed titles");
|
||||
searchFeedtitles(lcQuery, result);
|
||||
} else if (AppConfig.DEBUG) {
|
||||
Log.d(TAG, "Performing search on specific feed");
|
||||
}
|
||||
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Searching Feeditem titles");
|
||||
searchFeedItemTitles(lcQuery, result);
|
||||
searchFeedItemTitles(lcQuery, result, selectedFeed);
|
||||
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Searching item-chaptertitles");
|
||||
searchFeedItemChapters(lcQuery, result, selectedFeed);
|
||||
|
||||
searchFeedItemChapters(lcQuery, result);
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Searching item descriptions");
|
||||
searchFeedItemDescription(lcQuery, result, selectedFeed);
|
||||
|
||||
searchFeedItemDescription(lcQuery, result);
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Searching item content encoded data");
|
||||
searchFeedItemContentEncoded(lcQuery, result, selectedFeed);
|
||||
|
||||
searchFeedItemContentEncoded(lcQuery, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -47,31 +56,49 @@ public class FeedSearcher {
|
|||
}
|
||||
|
||||
private static void searchFeedItemTitles(String query,
|
||||
ArrayList<SearchResult> destination) {
|
||||
ArrayList<SearchResult> destination, Feed selectedFeed) {
|
||||
FeedManager manager = FeedManager.getInstance();
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getTitle().toLowerCase().contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp
|
||||
.getInstance().getString(R.string.found_in_label)
|
||||
+ item.getFeed().getTitle()));
|
||||
}
|
||||
if (selectedFeed == null) {
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
searchFeedItemTitlesSingleFeed(query, destination, feed);
|
||||
}
|
||||
} else {
|
||||
searchFeedItemTitlesSingleFeed(query, destination, selectedFeed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchFeedItemTitlesSingleFeed(String query,
|
||||
ArrayList<SearchResult> destination, Feed feed) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getTitle().toLowerCase().contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp.getInstance()
|
||||
.getString(R.string.found_in_label)
|
||||
+ item.getFeed().getTitle()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchFeedItemChapters(String query,
|
||||
ArrayList<SearchResult> destination) {
|
||||
ArrayList<SearchResult> destination, Feed selectedFeed) {
|
||||
FeedManager manager = FeedManager.getInstance();
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getSimpleChapters() != null) {
|
||||
for (SimpleChapter sc : item.getSimpleChapters()) {
|
||||
if (sc.getTitle().toLowerCase().contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp
|
||||
.getInstance().getString(
|
||||
R.string.found_in_chapters_label)));
|
||||
}
|
||||
if (selectedFeed == null) {
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
searchFeedItemChaptersSingleFeed(query, destination, feed);
|
||||
}
|
||||
} else {
|
||||
searchFeedItemChaptersSingleFeed(query, destination, selectedFeed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchFeedItemChaptersSingleFeed(String query,
|
||||
ArrayList<SearchResult> destination, Feed feed) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getSimpleChapters() != null) {
|
||||
for (SimpleChapter sc : item.getSimpleChapters()) {
|
||||
if (sc.getTitle().toLowerCase().contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp
|
||||
.getInstance().getString(
|
||||
R.string.found_in_chapters_label)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,33 +106,48 @@ public class FeedSearcher {
|
|||
}
|
||||
|
||||
private static void searchFeedItemDescription(String query,
|
||||
ArrayList<SearchResult> destination) {
|
||||
ArrayList<SearchResult> destination, Feed selectedFeed) {
|
||||
FeedManager manager = FeedManager.getInstance();
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getDescription() != null
|
||||
&& item.getDescription().toLowerCase().contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp
|
||||
.getInstance().getString(
|
||||
R.string.found_in_shownotes_label)));
|
||||
}
|
||||
if (selectedFeed == null) {
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
searchFeedItemDescriptionSingleFeed(query, destination, feed);
|
||||
}
|
||||
} else {
|
||||
searchFeedItemDescriptionSingleFeed(query, destination,
|
||||
selectedFeed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchFeedItemDescriptionSingleFeed(String query,
|
||||
ArrayList<SearchResult> destination, Feed feed) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getDescription() != null
|
||||
&& item.getDescription().toLowerCase().contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp.getInstance()
|
||||
.getString(R.string.found_in_shownotes_label)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchFeedItemContentEncoded(String query,
|
||||
ArrayList<SearchResult> destination) {
|
||||
ArrayList<SearchResult> destination, Feed selectedFeed) {
|
||||
FeedManager manager = FeedManager.getInstance();
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (!destination.contains(item)
|
||||
&& item.getContentEncoded() != null
|
||||
&& item.getContentEncoded().toLowerCase()
|
||||
.contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp
|
||||
.getInstance().getString(
|
||||
R.string.found_in_shownotes_label)));
|
||||
}
|
||||
if (selectedFeed == null) {
|
||||
for (Feed feed : manager.getFeeds()) {
|
||||
searchFeedItemContentEncodedSingleFeed(query, destination, feed);
|
||||
}
|
||||
} else {
|
||||
searchFeedItemContentEncodedSingleFeed(query, destination, selectedFeed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchFeedItemContentEncodedSingleFeed(String query,
|
||||
ArrayList<SearchResult> destination, Feed feed) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (!destination.contains(item) && item.getContentEncoded() != null
|
||||
&& item.getContentEncoded().toLowerCase().contains(query)) {
|
||||
destination.add(new SearchResult(item, PodcastApp.getInstance()
|
||||
.getString(R.string.found_in_shownotes_label)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue