Permalink
Browse files

Introduce the notion of a Stream

  • Loading branch information...
1 parent 6247ca0 commit ecd5df04ed30d4fb0a2e34762ff3d4cd9fbf791c @thomaslee committed Sep 3, 2012
View
16 res/layout/activity_posts.xml
@@ -38,15 +38,25 @@
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:dividerHeight="10dp"
- android:drawSelectorOnTop="true">
-
- </ListView>
+ android:drawSelectorOnTop="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/mentions_tab"
android:layout_width="match_parent"
android:layout_height="match_parent" >
+
+ <ListView
+ android:id="@+id/mentions_list_view"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:choiceMode="singleChoice"
+ android:divider="#00000000"
+ android:paddingLeft="20dp"
+ android:paddingRight="20dp"
+ android:dividerHeight="10dp"
+ android:drawSelectorOnTop="true" />
+
</LinearLayout>
<LinearLayout
View
10 src/co/tomlee/frapp/PostsActivity.java
@@ -62,7 +62,9 @@
private String accessToken;
private ListView myStreamListView;
+ private ListView mentionsListView;
private PostsAdapter myStreamPostsAdapter;
+ private PostsAdapter mentionsPostsAdapter;
private PostsAdapter postsAdapter;
private PollThread pollThread;
private TabHost tabHost;
@@ -85,8 +87,10 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_posts);
myStreamPostsAdapter = new PostsAdapter(this, R.layout.postlistitem, R.layout.waitlistitem);
+ mentionsPostsAdapter = new PostsAdapter(this, R.layout.postlistitem, R.layout.waitlistitem);
tabsPostsAdapters.put(TAB_MY_STREAM_TAG, myStreamPostsAdapter);
+ tabsPostsAdapters.put(TAB_MENTIONS_TAG, mentionsPostsAdapter);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec(TAB_MY_STREAM_TAG).setIndicator(TAB_MY_STREAM_TITLE).setContent(R.id.my_stream_tab));
@@ -104,6 +108,12 @@ public void onTabChanged(String tabId) {
myStreamListView.setOnScrollListener(this);
myStreamListView.setOnItemClickListener(this);
myStreamListView.setOnItemLongClickListener(this);
+
+ mentionsListView = (ListView) findViewById(R.id.mentions_list_view);
+ mentionsListView.setAdapter(mentionsPostsAdapter);
+ mentionsListView.setOnScrollListener(this);
+ mentionsListView.setOnItemClickListener(this);
+ mentionsListView.setOnItemLongClickListener(this);
}
/*
View
16 src/co/tomlee/frapp/appnet/AppNetClient.java
@@ -38,19 +38,19 @@ private AppNetClient(final String baseUrl, final String accessToken) {
this.accessToken = accessToken;
}
- public List<Post> getRecentPosts(final int count) throws AppNetException {
- return getPosts(null, null, count);
+ public List<Post> getRecentPosts(final Stream stream, final int count) throws AppNetException {
+ return getPosts(stream, null, null, count);
}
- public List<Post> getPostsSince(final String sinceId, final int count) throws AppNetException {
- return getPosts(null, sinceId, count);
+ public List<Post> getPostsSince(final Stream stream, final String sinceId, final int count) throws AppNetException {
+ return getPosts(stream, null, sinceId, count);
}
- public List<Post> getPostsBefore(final String beforeId, final int count) throws AppNetException {
- return getPosts(beforeId, null, count);
+ public List<Post> getPostsBefore(final Stream stream, final String beforeId, final int count) throws AppNetException {
+ return getPosts(stream, beforeId, null, count);
}
- private List<Post> getPosts(final String beforeId, final String sinceId, final int count) throws AppNetException {
+ private List<Post> getPosts(final Stream stream, final String beforeId, final String sinceId, final int count) throws AppNetException {
final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
if (beforeId != null) {
params.add(new BasicNameValuePair("before_id", beforeId));
@@ -64,7 +64,7 @@ private AppNetClient(final String baseUrl, final String accessToken) {
params.add(new BasicNameValuePair("include_deleted", "0"));
final StringBuilder sb = new StringBuilder();
- sb.append(baseUrl).append("/stream/0/posts/stream");
+ sb.append(baseUrl).append(stream.getPath());
if (params.size() > 0) {
sb.append("?").append(URLEncodedUtils.format(params, "utf-8"));
}
View
17 src/co/tomlee/frapp/appnet/Stream.java
@@ -0,0 +1,17 @@
+package co.tomlee.frapp.appnet;
+
+public final class Stream {
+ private final String path;
+
+ public Stream(final String path) {
+ this.path = path;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public static final Stream MY_STREAM = new Stream("/stream/0/posts/stream");
+ public static final Stream GLOBAL_STREAM = new Stream("/stream/0/posts/stream/global");
+ public static final Stream MENTIONS_STREAM = new Stream("/stream/0/users/me/mentions");
+}
View
3 src/co/tomlee/frapp/task/PostsBeforeTask.java
@@ -5,6 +5,7 @@
import co.tomlee.frapp.PostsAdapter;
import co.tomlee.frapp.appnet.AppNetClient;
import co.tomlee.frapp.appnet.AppNetException;
+import co.tomlee.frapp.appnet.Stream;
import co.tomlee.frapp.model.Post;
public final class PostsBeforeTask extends AbstractPostsTask {
@@ -19,7 +20,7 @@ public PostsBeforeTask(final PostsAdapter postsAdapter, final AppNetClient clien
@Override
protected List<Post> getPosts(final int batchSize) throws AppNetException {
- return client.getPostsBefore(id, batchSize);
+ return client.getPostsBefore(Stream.MY_STREAM, id, batchSize);
}
@Override
View
3 src/co/tomlee/frapp/task/PostsSinceTask.java
@@ -6,6 +6,7 @@
import co.tomlee.frapp.PostsAdapter;
import co.tomlee.frapp.appnet.AppNetClient;
import co.tomlee.frapp.appnet.AppNetException;
+import co.tomlee.frapp.appnet.Stream;
import co.tomlee.frapp.model.Post;
public class PostsSinceTask extends AbstractPostsTask {
@@ -20,7 +21,7 @@ public PostsSinceTask(final PostsAdapter postAdapter, final AppNetClient client,
@Override
protected List<Post> getPosts(final int batchSize) throws AppNetException {
- return client.getPostsSince(id, batchSize);
+ return client.getPostsSince(Stream.MY_STREAM, id, batchSize);
}
@Override
View
3 src/co/tomlee/frapp/task/RecentPostsTask.java
@@ -5,6 +5,7 @@
import co.tomlee.frapp.PostsAdapter;
import co.tomlee.frapp.appnet.AppNetClient;
import co.tomlee.frapp.appnet.AppNetException;
+import co.tomlee.frapp.appnet.Stream;
import co.tomlee.frapp.model.Post;
public final class RecentPostsTask extends AbstractPostsTask {
@@ -17,7 +18,7 @@ public RecentPostsTask(final PostsAdapter postsAdapter, final AppNetClient clien
@Override
protected List<Post> getPosts(final int batchSize) throws AppNetException {
- return client.getRecentPosts(batchSize);
+ return client.getRecentPosts(Stream.MY_STREAM, batchSize);
}
@Override

0 comments on commit ecd5df0

Please sign in to comment.