private void init() { dbQuery = new DatabaseQuery(this); dbQuery.openDB(); rssFeed = new RssFeed(); rssProvider = dbQuery.getRssProviderList(null); rssList = new ArrayList<RssItem>(); rssAdapter = new RssItemAdapter(this, R.layout.rss_item_list, rssList); setListAdapter(rssAdapter); if (!isServiceRunning(RssNotificationService.class.getCanonicalName())) startService(new Intent(RssReaderActivity.this, RssNotificationService.class)); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQ_RSS_MANAGE: switch (resultCode) { case RES_RSS_ADD: String[] addProvider = data.getStringArrayExtra("add-provider"); loadData(addProvider[0], false, true, true); curProvider = dbQuery.getRssProviderList(null).length() - 1; break; case RES_RSS_DELETE: loadData(null, true, false, false); break; default: break; } break; default: break; } }
@Override public void onClick(View v) { TextView txtManageLabel, txtBrowseLabel, txtRefreshLabel, txtSearchLabel; txtManageLabel = (TextView) findViewById(R.id.txt_manage_label); txtBrowseLabel = (TextView) findViewById(R.id.txt_browse_label); txtRefreshLabel = (TextView) findViewById(R.id.txt_refresh_label); txtSearchLabel = (TextView) findViewById(R.id.txt_search_label); txtSearch.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { new AsyncTask<String, Void, ArrayList<RssItem>>() { @Override protected ArrayList<RssItem> doInBackground(String... params) { return dbQuery.searchRssItem(params[0]); } @Override protected void onPostExecute(ArrayList<RssItem> result) { rssList.clear(); rssList.addAll(result); rssAdapter.config().notifyDataSetChanged(); } }.execute(s.toString()); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) {} }); txtSearch.setOnKeyListener( new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) return true; return false; } }); switch (v.getId()) { case R.id.btn_manage: startActivityForResult( new Intent(RssReaderActivity.this, RssManageActivity.class), REQ_RSS_MANAGE); break; case R.id.btn_browse: rssProvider = dbQuery.getRssProviderList(null); int length = rssProvider.getProviderNames().length; if (length == 0) break; String[] providers = new String[length + 1]; providers[0] = "All"; for (int i = 0; i < length; i++) providers[i + 1] = rssProvider.getProviderNames()[i]; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder .setTitle(R.string.rss_choose_provider) .setItems( providers, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (item == 0) { loadData(null, true, false, false); return; } loadData(rssProvider.getProviderNames()[item - 1], false, false, false); curProvider = item - 1; updateListView(); } }); builder.create().show(); break; case R.id.btn_refresh: if (curProvider == -1) loadData(null, true, true, true); else loadData( dbQuery.getRssProviderList(null).getProviderNames()[curProvider], false, true, true); break; case R.id.btn_search: if (txtSearchLabel.getText().toString().equals(getString(R.string.btn_search_text))) { btnManage.setVisibility(View.GONE); txtManageLabel.setVisibility(View.GONE); btnBrowse.setVisibility(View.GONE); txtBrowseLabel.setVisibility(View.GONE); btnRefresh.setVisibility(View.GONE); txtRefreshLabel.setVisibility(View.GONE); btnSearch.setBackgroundResource(R.drawable.btn_done_background); txtSearchLabel.setText(R.string.btn_done_text); txtSearch.setVisibility(View.VISIBLE); txtSearch.requestFocus(); } else { btnManage.setVisibility(View.VISIBLE); txtManageLabel.setVisibility(View.VISIBLE); btnBrowse.setVisibility(View.VISIBLE); txtBrowseLabel.setVisibility(View.VISIBLE); btnRefresh.setVisibility(View.VISIBLE); txtRefreshLabel.setVisibility(View.VISIBLE); btnSearch.setBackgroundResource(R.drawable.btn_search_background); txtSearchLabel.setText(R.string.btn_search_text); txtSearch.setVisibility(View.GONE); txtSearch.setText(""); loadData(null, true, false, false); } break; default: break; } }