Commits

Ville Saalo committed 7de99f4

#2: Display Events

The first working version of the user's RSS newsfeed! For now you cannot actually access this feature anywhere from within the app, and the URL to the feed is hardcoded.

Also introduced a new library, SimpleRssParser.jar, by yours truly. ;)

Comments (0)

Files changed (9)

AndroidManifest.xml

         </activity>
         <activity android:name=".activities.UserProfileActivity"></activity>
         <activity android:name=".activities.SettingsActivity"></activity>
-    <uses-library android:name="android.test.runner"/>
-    <activity android:name=".activities.RepositoryFollowersActivity"></activity>
+    	<activity android:name=".activities.RepositoryFollowersActivity"></activity>
+    	<activity android:name=".activities.NewsfeedActivity"></activity>
+    	
+    	<uses-library android:name="android.test.runner"/>
     </application>
     
     <instrumentation android:label="All tests" 
 - [Sample codes from The Busy Coder's Guide to Android Development!](https://github.com/commonsguy/cw-omnibus)
 - [Android SeekBar preference](http://robobunny.com/wp/2011/08/13/android-seekbar-preference/)
 - [Universal Image Loader](https://github.com/nostra13/Android-Universal-Image-Loader)
+- [Simple RSS parser](https://bitbucket.org/ZeroOne3010/simple-rss-parser)
 
 
 # BUGS AND FEATURES
Add a comment to this file

libs/SimpleRssParser.jar

Binary file added.

res/layout/newsfeed.xml

+<?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/newsfeed_items"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent" >
+    </ListView>
+
+</LinearLayout>

res/values-fi/strings.xml

     <string name="about_issues">
         Löysitkö bugin tai onko sinulla jokin parannusehdotus? Kerro se meille osoitteessa %1$s.
         Voit myös selata lähdekoodia osoitteessa %2$s ja tehdä muutosehdotuksia tavallisella fork / pull request -menettelyllä.</string>
+        
+    <!--  NewsfeedActivity -->
+    <string name="user_newsfeed">Tapahtumavirtasi</string>
+    <string name="rss_loading_failed">Syötteen lataaminen epäonnistui.</string>
 </resources>

res/values/strings.xml

     <string name="about_issues">
         Found a bug? Have a feature request? Let us know by reporting it to our issue tracker at %1$s.
         You can also browse source code at %2$s and make changes by forking the project and sending a pull request.</string>
+    
+    <!--  NewsfeedActivity -->
+    <string name="user_newsfeed">Your newsfeed</string>
+    <string name="rss_loading_failed">Loading the RSS feed failed.</string>
 </resources>

src/com/saibotd/bitbeaker/activities/NewsfeedActivity.java

+package com.saibotd.bitbeaker.activities;
+
+import java.io.ByteArrayInputStream;
+
+import org.xml.sax.InputSource;
+
+import zeroone.rss.Channel;
+import zeroone.rss.RssParser;
+import android.os.Bundle;
+import android.widget.ListView;
+
+import com.saibotd.bitbeaker.R;
+import com.saibotd.bitbeaker.adapters.NewsfeedAdapter;
+
+/**
+ * This activity displays the user's main newsfeed using the RSS stream.
+ */
+public class NewsfeedActivity extends MyActivity {
+
+	@Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        
+        setContentView(R.layout.newsfeed);
+        
+        setTitle(getString(R.string.user_newsfeed));
+        
+        String rssUrl = "https://bitbucket.org/INSERT_USERNAME_HERE/rss/feed?token=INSERT_TOKEN_HERE"; // TODO
+        executeAsyncLoader(rssUrl);
+    }
+    
+	@Override
+	public void asyncLoaderDone(String result) {
+		Channel news = null;
+		try {
+			news = RssParser.parseFeed(new InputSource(new ByteArrayInputStream(result.getBytes())));
+		} catch (Exception e) {
+			makeToast(R.string.rss_loading_failed);
+			e.printStackTrace();
+			return;
+		}
+		
+		ListView listView = (ListView) findViewById(R.id.newsfeed_items);
+		listView.setAdapter(new NewsfeedAdapter(this, news));
+	}
+}

src/com/saibotd/bitbeaker/activities/RepositoriesActivity.java

 import com.saibotd.bitbeaker.FavoritesService;
 import com.saibotd.bitbeaker.Helper;
 import com.saibotd.bitbeaker.R;
-import com.saibotd.bitbeaker.R.id;
-import com.saibotd.bitbeaker.R.layout;
-import com.saibotd.bitbeaker.R.menu;
-import com.saibotd.bitbeaker.R.string;
 import com.saibotd.bitbeaker.adapters.RepositoriesAdapter;
 
 public class RepositoriesActivity extends MyTabbedActivity {

src/com/saibotd/bitbeaker/adapters/NewsfeedAdapter.java

+package com.saibotd.bitbeaker.adapters;
+
+import zeroone.rss.Channel;
+import zeroone.rss.Item;
+import android.content.Context;
+import android.text.Html;
+import android.text.method.LinkMovementMethod;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.saibotd.bitbeaker.R;
+
+public class NewsfeedAdapter extends BaseAdapter {
+	private final Context context;
+	private final Channel news;
+	
+	public NewsfeedAdapter(Context context, Channel news) {
+		this.context = context;
+		this.news = news;
+	}
+	
+	@Override
+	public int getCount() {
+		return news.getItems().size();
+	}
+
+	@Override
+	public Item getItem(int position) {
+		return news.getItems().get(position);
+	}
+
+	@Override
+	public long getItemId(int position) {
+		return position;
+	}
+
+	@Override
+	public View getView(int position, View convertView, ViewGroup parent) {
+		View view;
+		if (convertView == null) {
+			view = LayoutInflater.from(context).inflate(R.layout.listitem_two_rows, null);
+		} else {
+			view = (View) convertView;
+		}
+		view.setId(position);
+		TextView title = (TextView) view.findViewById(R.id.title);
+		TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
+		final Item item = getItem(position);
+		try {
+			title.setText(item.getTitle());
+			subtitle.setText(Html.fromHtml(item.getDescription()));
+			subtitle.setMovementMethod(LinkMovementMethod.getInstance());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		//view.setOnClickListener(clickListener);
+		
+		return view;
+	}
+
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.