implemented search button

This commit is contained in:
daniel oeh 2012-07-24 14:37:34 +02:00
parent dc02bff7c6
commit 8243d0dde6
10 changed files with 94 additions and 2 deletions

View File

@ -130,7 +130,7 @@
<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:theme="@style/Theme.Sherlock.Light.NoActionBar">
<activity android:name=".activity.SearchActivity" android:launchMode="singleTop" android:label="@string/search_results_label" android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

20
res/layout/searchlist.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center" />
</LinearLayout>

View File

@ -21,4 +21,5 @@
<item android:id="@+id/show_preferences" android:title="@string/settings_label" android:icon="@drawable/action_settings" android:showAsAction="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/opml_import" android:title="@string/opml_import_label" android:showAsAction="collapseActionView"></item>
<item android:id="@id/search_item" android:icon="@drawable/action_search" android:title="@string/search_label" android:showAsAction="collapseActionView"></item>
</menu>

View File

@ -7,5 +7,6 @@
<item type="id" name="clear_queue_item"/>
<item type="id" name="select_all_item"/>
<item type="id" name="deselect_all_item"/>
<item type="id" name="search_item"/>
</resources>

View File

@ -140,6 +140,11 @@
<string name="found_in_label">Found in:\u0020</string>
<string name="found_in_shownotes_label">Found in shownotes</string>
<string name="found_in_chapters_label">Found in chapters</string>
<string name="search_status_searching">Searching...</string>
<string name="search_status_no_results">No results were found</string>
<string name="search_results_label">Search results</string>
<string name="search_term_label">You searched:\u0020</string>
<string name="search_label">Search</string>
</resources>

View File

@ -108,6 +108,9 @@ public class MainActivity extends SherlockFragmentActivity {
case R.id.opml_import:
startActivity(new Intent(this, OpmlImportActivity.class));
return true;
case R.id.search_item:
onSearchRequested();
return true;
default:
return super.onOptionsItemSelected(item);
}

View File

@ -8,14 +8,23 @@ import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.SearchlistAdapter;
import de.danoeh.antennapod.feed.FeedComponent;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedSearcher;
import de.danoeh.antennapod.feed.SearchResult;
import de.danoeh.antennapod.fragment.FeedlistFragment;
import de.danoeh.antennapod.fragment.ItemlistFragment;
public class SearchActivity extends SherlockListActivity {
private static final String TAG = "SearchActivity";
@ -23,21 +32,71 @@ public class SearchActivity extends SherlockListActivity {
private SearchlistAdapter searchAdapter;
private ArrayList<SearchResult> content;
private TextView txtvStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.searchlist);
txtvStatus = (TextView) findViewById(android.R.id.empty);
if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
if (AppConfig.DEBUG)
Log.d(TAG, "Starting search");
String query = getIntent().getStringExtra(SearchManager.QUERY);
getSupportActionBar().setSubtitle(
getString(R.string.search_term_label) + query);
startSearch(query);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
startActivity(new Intent(this, MainActivity.class));
return true;
default:
return false;
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
SearchResult selection = searchAdapter.getItem(position);
if (selection.getComponent().getClass() == Feed.class) {
Feed feed = (Feed) selection.getComponent();
Intent launchIntent = new Intent(this, FeedItemlistActivity.class);
launchIntent.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED,
feed.getId());
startActivity(launchIntent);
} else if (selection.getComponent().getClass() == FeedItem.class) {
FeedItem item = (FeedItem) selection.getComponent();
Intent launchIntent = new Intent(this, ItemviewActivity.class);
launchIntent.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED, item
.getFeed().getId());
launchIntent.putExtra(ItemlistFragment.EXTRA_SELECTED_FEEDITEM,
item.getId());
startActivity(launchIntent);
}
}
@SuppressLint({ "NewApi", "NewApi" })
private void startSearch(String query) {
AsyncTask<String, Void, ArrayList<SearchResult>> executor = new AsyncTask<String, Void, ArrayList<SearchResult>>() {
@Override
protected void onPreExecute() {
txtvStatus.setText(R.string.search_status_searching);
}
@Override
protected ArrayList<SearchResult> doInBackground(String... params) {
if (AppConfig.DEBUG)
@ -57,6 +116,9 @@ public class SearchActivity extends SherlockListActivity {
content);
getListView().setAdapter(searchAdapter);
searchAdapter.notifyDataSetChanged();
if (content.isEmpty()) {
txtvStatus.setText(R.string.search_status_no_results);
}
}