IBCActivity.java (5532B)
1 /* 2 * IBC-App for Android 3 * 4 * Copyright (C) 2011 Jan Dankert 5 * 6 * This program is free software: you can redistribute it and/or modify it under 7 * the terms of the GNU General Public License as published by the Free Software 8 * Foundation, either version 3 of the License, or (at your option) any later 9 * version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 * details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 package de.mtbnews.android; 20 21 import org.mcsoxford.rss.RSSFault; 22 import org.mcsoxford.rss.RSSFeed; 23 import org.mcsoxford.rss.RSSReader; 24 import org.mcsoxford.rss.RSSReaderException; 25 26 import android.app.ListActivity; 27 import android.content.Intent; 28 import android.net.Uri; 29 import android.os.Bundle; 30 import android.view.Menu; 31 import android.view.MenuInflater; 32 import android.view.MenuItem; 33 import android.view.View; 34 import android.view.View.OnClickListener; 35 import android.widget.AdapterView; 36 import android.widget.Button; 37 import android.widget.ListAdapter; 38 import android.widget.ListView; 39 import android.widget.AdapterView.OnItemClickListener; 40 import de.mtbnews.android.adapter.ListEntryContentAdapter; 41 import de.mtbnews.android.util.IBC; 42 import de.mtbnews.android.util.IBCException; 43 import de.mtbnews.android.util.ServerAsyncTask; 44 45 /** 46 * @author Jan Dankert 47 */ 48 public class IBCActivity extends ListActivity 49 { 50 /** Called when the activity is first created. */ 51 @Override 52 public void onCreate(Bundle savedInstanceState) 53 { 54 setTheme(((IBCApplication) getApplication()).themeResId); 55 56 super.onCreate(savedInstanceState); 57 setContentView(R.layout.start); 58 59 Button forumButton = (Button) findViewById(R.id.forum); 60 forumButton.setOnClickListener(new OnClickListener() 61 { 62 63 @Override 64 public void onClick(View v) 65 { 66 startActivity(new Intent(IBCActivity.this, ForumOverviewActivity.class)); 67 } 68 }); 69 70 reloadFeed(); 71 } 72 73 /** 74 * 75 */ 76 private void reloadFeed() 77 { 78 final ListView list = getListView(); 79 80 list.setOnItemClickListener(new OnItemClickListener() 81 { 82 83 @Override 84 public void onItemClick(AdapterView<?> parent, View view, int position, long id) 85 { 86 final Intent intent = new Intent(IBCActivity.this, NewsDetailActivity.class); 87 intent.putExtra("itemid", position); 88 startActivity(intent); 89 } 90 }); 91 92 new ServerAsyncTask(this, R.string.waitingfor_news) 93 { 94 private RSSFeed feed; 95 96 @Override 97 protected void callServer() throws IBCException 98 { 99 final RSSFeed oldFeed = ((IBCApplication) getApplication()).getNewsFeed(); 100 101 if (oldFeed != null) 102 { 103 feed = oldFeed; 104 } 105 else 106 { 107 108 RSSReader reader = new RSSReader(); 109 try 110 { 111 feed = reader.load(IBC.IBC_NEWS_RSS_URL); 112 ((IBCApplication) getApplication()).setNewsFeed(feed); 113 } 114 catch (RSSReaderException e) 115 { 116 throw new IBCException(R.string.error_io, e.getMessage(), e); 117 } 118 catch (RSSFault e) 119 { 120 throw new IBCException(R.string.error_io, e.getMessage(), e); 121 } 122 } 123 } 124 125 protected void doOnSuccess() 126 { 127 IBCActivity.this.setTitle(feed.getTitle()); 128 129 ListAdapter adapter = new ListEntryContentAdapter(IBCActivity.this, this.feed.getItems(), false, true); 130 setListAdapter(adapter); 131 } 132 }.execute(); 133 } 134 135 @Override 136 public boolean onCreateOptionsMenu(Menu menu) 137 { 138 super.onCreateOptionsMenu(menu); 139 MenuInflater mi = new MenuInflater(getApplication()); 140 mi.inflate(R.menu.main, menu); 141 142 return true; 143 } 144 145 public boolean onOptionsItemSelected(MenuItem item) 146 { 147 switch (item.getItemId()) 148 { 149 case R.id.menu_preferences: 150 startActivity(new Intent(this, Configuration.class)); 151 return true; 152 case R.id.menu_photo: 153 startActivity(new Intent(IBCActivity.this, PhotoActivity.class)); 154 return true; 155 case R.id.menu_mailbox: 156 startActivity(new Intent(IBCActivity.this, MailboxActivity.class)); 157 return true; 158 159 case R.id.www_bikemarkt: 160 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://bikemarkt.mtb-news.de/bikemarkt/"))); 161 return true; 162 case R.id.www_biketest: 163 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mtb-news.de/biketest/"))); 164 return true; 165 case R.id.www_blog: 166 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://schaltwerk.mtb-news.de/"))); 167 return true; 168 case R.id.www_forum: 169 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mtb-news.de/forum/"))); 170 return true; 171 case R.id.www_fotos: 172 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://fotos.mtb-news.de/"))); 173 return true; 174 case R.id.www_gewichte: 175 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://gewichte.mtb-news.de/"))); 176 return true; 177 case R.id.www_lmb: 178 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mtb-news.de/lmb/"))); 179 return true; 180 case R.id.www_news: 181 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mtb-news.de/"))); 182 return true; 183 case R.id.www_shop: 184 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://shop.mtb-news.de/"))); 185 return true; 186 case R.id.www_video: 187 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://videos.mtb-news.de/"))); 188 return true; 189 190 } 191 return false; 192 } 193 }