summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java
blob: cada0e4efb2288cd8ad9040075d3723c215a6ce8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package de.danoeh.antennapod.activity;

import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import android.view.Menu;
import android.view.MenuItem;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.fragment.MiroGuideChannellistFragment;
import de.danoeh.antennapod.preferences.UserPreferences;

/**
 * Displays results when a search for miroguide channels has been performed. It
 * uses a MiroGuideChannelListFragment to display the results.
 */
public class MiroGuideSearchActivity extends ActionBarActivity {
	private static final String TAG = "MiroGuideSearchActivity";

	private MiroGuideChannellistFragment listFragment;

	@Override
	protected void onCreate(Bundle arg0) {
		setTheme(UserPreferences.getTheme());
		super.onCreate(arg0);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		setContentView(R.layout.miroguidesearch);
	}

	@Override
	protected void onResume() {
		super.onResume();
		Intent intent = getIntent();
		if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
			String query = intent.getStringExtra(SearchManager.QUERY);
			getSupportActionBar()
					.setSubtitle(
							getString(R.string.search_term_label) + "\""
									+ query + "\"");
			handleSearchRequest(query);
		}
	}

	private void handleSearchRequest(String query) {
		if (AppConfig.DEBUG)
			Log.d(TAG, "Performing search");
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		listFragment = MiroGuideChannellistFragment.newInstance("name", query,
				"name");
		ft.replace(R.id.channellistFragment, listFragment);
		ft.commit();
	}

	@Override
	protected void onNewIntent(Intent intent) {
		setIntent(intent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
				.setIcon(
						obtainStyledAttributes(
								new int[] { R.attr.action_search })
								.getDrawable(0))
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			return true;
		case R.id.search_item:
			onSearchRequested();
			return true;
		default:
			return false;
		}
	}

}