diff options
Diffstat (limited to 'src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java')
-rw-r--r-- | src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java | 227 |
1 files changed, 114 insertions, 113 deletions
diff --git a/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java index 2d73525c0..99da9944f 100644 --- a/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java +++ b/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; 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.util.Log; import android.view.Menu; @@ -24,126 +25,126 @@ import de.danoeh.antennapod.preferences.UserPreferences; * Shows a list of available categories and offers a search button. If the user * selects a category, the MiroGuideCategoryActivity is started. */ -public class MiroGuideMainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener{ - private static final String TAG = "MiroGuideMainActivity"; +public class MiroGuideMainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener { + private static final String TAG = "MiroGuideMainActivity"; - private static String[] categories; - private ArrayAdapter<String> listAdapter; + private static String[] categories; + private ArrayAdapter<String> listAdapter; - private TextView txtvStatus; + private TextView txtvStatus; private ListView listView; - @Override - protected void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getTheme()); - super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setContentView(R.layout.miroguide_categorylist); + @Override + protected void onCreate(Bundle savedInstanceState) { + setTheme(UserPreferences.getTheme()); + super.onCreate(savedInstanceState); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + setContentView(R.layout.miroguide_categorylist); - txtvStatus = (TextView) findViewById(android.R.id.empty); + txtvStatus = (TextView) findViewById(android.R.id.empty); listView = (ListView) findViewById(android.R.id.list); listView.setOnItemClickListener(this); - } - - @Override - protected void onPause() { - super.onPause(); - } - - @Override - protected void onResume() { - super.onResume(); - if (categories != null) { - createAdapter(); - } else { - loadCategories(); - } - } - - private void createAdapter() { - if (categories != null) { - listAdapter = new ArrayAdapter<String>(this, - android.R.layout.simple_list_item_1, categories); - txtvStatus.setText(R.string.no_items_label); - listView.setAdapter(listAdapter); - } - } - - /** - * Launches an AsyncTask to load the available categories in the background. - */ - @SuppressLint("NewApi") - private void loadCategories() { - AsyncTask<Void, Void, Void> listLoader = new AsyncTask<Void, Void, Void>() { - - private String[] c; - private MiroGuideException exception; - - @Override - protected void onPostExecute(Void result) { - if (exception == null) { - if (AppConfig.DEBUG) - Log.d(TAG, "Successfully loaded categories"); - categories = c; - createAdapter(); - } else { - Log.e(TAG, "Error happened while trying to load categories"); - txtvStatus.setText(exception.getMessage()); - } - } - - @Override - protected void onPreExecute() { - txtvStatus.setText(R.string.loading_categories_label); - } - - @Override - protected Void doInBackground(Void... params) { - MiroGuideService service = new MiroGuideService(); - try { - c = service.getCategories(); - } catch (MiroGuideException e) { - e.printStackTrace(); - exception = e; - } finally { - service.close(); - } - return null; - } - - }; - - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - listLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - listLoader.execute(); - } - } - - @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; - } - } + } + + @Override + protected void onPause() { + super.onPause(); + } + + @Override + protected void onResume() { + super.onResume(); + if (categories != null) { + createAdapter(); + } else { + loadCategories(); + } + } + + private void createAdapter() { + if (categories != null) { + listAdapter = new ArrayAdapter<String>(this, + android.R.layout.simple_list_item_1, categories); + txtvStatus.setText(R.string.no_items_label); + listView.setAdapter(listAdapter); + } + } + + /** + * Launches an AsyncTask to load the available categories in the background. + */ + @SuppressLint("NewApi") + private void loadCategories() { + AsyncTask<Void, Void, Void> listLoader = new AsyncTask<Void, Void, Void>() { + + private String[] c; + private MiroGuideException exception; + + @Override + protected void onPostExecute(Void result) { + if (exception == null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Successfully loaded categories"); + categories = c; + createAdapter(); + } else { + Log.e(TAG, "Error happened while trying to load categories"); + txtvStatus.setText(exception.getMessage()); + } + } + + @Override + protected void onPreExecute() { + txtvStatus.setText(R.string.loading_categories_label); + } + + @Override + protected Void doInBackground(Void... params) { + MiroGuideService service = new MiroGuideService(); + try { + c = service.getCategories(); + } catch (MiroGuideException e) { + e.printStackTrace(); + exception = e; + } finally { + service.close(); + } + return null; + } + + }; + + if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { + listLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + listLoader.execute(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) + .setIcon( + obtainStyledAttributes( + new int[]{R.attr.action_search}) + .getDrawable(0)), + 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; + } + } @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { |