Started working on displaying user avatars

Currently the downloading and displaying of avatar images is working,
however we now need to fetch the author avatar url from the forum.

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-10-14 09:37:05 -04:00
parent 8f9abdec26
commit 73a98c05a3
17 changed files with 284 additions and 9 deletions

View File

@@ -0,0 +1,54 @@
cleanup.add_default_serial_version_id=false
cleanup.add_generated_serial_version_id=true
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=true
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=true
cleanup.always_use_blocks=false
cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=false
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_to_enhanced_for_loop=true
cleanup.correct_indentation=true
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=true
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=true
cleanup.never_use_blocks=true
cleanup.never_use_parentheses_in_expressions=true
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=true
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=true
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=true
cleanup.sort_members_all=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_parentheses_in_expressions=true
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup_profile=_Ricky
cleanup_settings_version=2
eclipse.preferences.version=1

View File

@@ -1,5 +1,5 @@
<manifest package="org.RickBarrette.osj.forum" <manifest package="org.RickBarrette.osj.forum"
android:versionCode="1344" android:versionCode="8134"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"> android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-sdk <uses-sdk

View File

@@ -38,7 +38,12 @@
<ul> <ul>
<li> <a href="http://code.google.com/p/android-xmlrpc/">android-xmlrpc</a> - Very thin xmlrpc client library for Android platform</li> <li> <a href="http://code.google.com/p/android-xmlrpc/">android-xmlrpc</a> - Very thin xmlrpc client library for Android platform</li>
<li> <a href="https://github.com/chrisbanes/Android-PullToRefresh"/>Android-PullToRefresh</a> - A project to provide a reusable Pull to Refresh widget for Android.</li> <li> <a href="https://github.com/chrisbanes/Android-PullToRefresh"/>Android-PullToRefresh</a> - A project to provide a reusable Pull to Refresh widget for Android</li>
<li> <a href="https://github.com/commonsguy/cwac-thumbnai"/>CWAC Thumbnail</a> - Images in Lists, Without the Wait</li>
<li> <a href="https://github.com/commonsguy/cwac-adapter"/>CWAC AdapterWrapper</a> - Adding Bits o' Functionality</li>
<li> <a href="https://github.com/commonsguy/cwac-bus"/>CWAC Bus</a> - Services And Activities, Communicating</li>
<li> <a href="https://github.com/commonsguy/cwac-cache"/>CWAC Cache</a> - Dealing With Pesky Download Times</li>
<li> <a href="https://github.com/commonsguy/cwac-task"/>CWAC Task</a> - A Bit More Background Task Goodness</li>
</ul> </ul>
<hr/> <hr/>

Binary file not shown.

BIN
OSJ Forum/libs/CWAC-Bus.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent"
android:padding="5dip"
>
<TextView <TextView
android:id="@+id/textView1" android:id="@+id/textView1"
@@ -20,7 +22,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher"
/> />
<TextView <TextView

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" > android:layout_height="wrap_content"
android:padding="5dip" >
<QuickContactBadge <QuickContactBadge
android:id="@+id/quickContactBadge1" android:id="@+id/quickContactBadge1"
@@ -9,7 +10,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" /> />
<TextView <TextView
android:id="@+id/textView1" android:id="@+id/textView1"

View File

@@ -0,0 +1,111 @@
/***
Copyright (c) 2008-2009 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.commonsware.cwac.thumbnail;
import org.RickBarrette.osj.forum.Log;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListAdapter;
import com.commonsware.cwac.adapter.AdapterWrapper;
import com.commonsware.cwac.cache.SimpleWebImageCache;
public class ThumbnailAdapter extends AdapterWrapper {
private static final String TAG = "ThumbnailAdapter";
private final int[] imageIds;
private SimpleWebImageCache<ThumbnailBus, ThumbnailMessage> cache = null;
private Activity host = null;
private final ThumbnailBus.Receiver<ThumbnailMessage> onCache = new ThumbnailBus.Receiver<ThumbnailMessage>() {
@Override
public void onReceive(final ThumbnailMessage message) {
final ImageView image = message.getImageView();
host.runOnUiThread(new Runnable() {
@Override
public void run() {
if (image.getTag() != null && image.getTag().toString().equals(message.getUrl()))
image.setImageDrawable(cache.get(message.getUrl()));
}
});
}
};
/**
* Constructor wrapping a supplied ListAdapter
*/
public ThumbnailAdapter(final Activity host, final ListAdapter wrapped, final SimpleWebImageCache<ThumbnailBus, ThumbnailMessage> cache, final int[] imageIds) {
super(wrapped);
this.host = host;
this.imageIds = imageIds;
this.cache = cache;
cache.getBus().register(getBusKey(), onCache);
}
public void close() {
cache.getBus().unregister(onCache);
}
private String getBusKey() {
return toString();
}
/**
* Get a View that displays the data at the specified position in the data
* set. In this case, if we are at the end of the list and we are still in
* append mode, we ask for a pending view and return it, plus kick off the
* background task to append more data to the wrapped adapter.
*
* @param position
* Position of the item whose data we want
* @param convertView
* View to recycle, if not null
* @param parent
* ViewGroup containing the returned View
*/
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
final View result = super.getView(position, convertView, parent);
processView(result);
return result;
}
public void processView(final View row) {
Log.v(TAG, "Processing View");
for (final int imageId : imageIds) {
final ImageView image = (ImageView) row.findViewById(imageId);
if (image != null && image.getTag() != null) {
final ThumbnailMessage msg = cache.getBus().createMessage(getBusKey());
msg.setImageView(image);
msg.setUrl(image.getTag().toString());
try {
cache.notify(msg.getUrl(), msg);
} catch (final Throwable t) {
Log.e(TAG, "Exception trying to fetch image", t);
}
}
}
}
}

View File

@@ -0,0 +1,36 @@
/***
Copyright (c) 2008-2009 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.commonsware.cwac.thumbnail;
import com.commonsware.cwac.bus.AbstractBus;
public class ThumbnailBus extends AbstractBus<ThumbnailMessage, String, ThumbnailBus.MatchStrategy> {
class MatchStrategy implements AbstractBus.Strategy<ThumbnailMessage, String> {
@Override
public boolean isMatch(final ThumbnailMessage message, final String filter) {
return filter != null && message != null && filter.equals(message.getKey());
}
}
public ThumbnailBus() {
super();
setStrategy(new MatchStrategy());
}
public ThumbnailMessage createMessage(final String key) {
return new ThumbnailMessage(key);
}
}

View File

@@ -0,0 +1,47 @@
/***
Copyright (c) 2008-2009 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.commonsware.cwac.thumbnail;
import android.widget.ImageView;
public class ThumbnailMessage {
private final String key;
private ImageView image;
private String url;
public ThumbnailMessage(final String key) {
this.key = key;
}
public ImageView getImageView() {
return image;
}
public String getKey() {
return key;
}
public String getUrl() {
return url;
}
public void setImageView(final ImageView image) {
this.image = image;
}
public void setUrl(final String url) {
this.url = url;
}
}

View File

@@ -35,6 +35,10 @@ import android.widget.AbsListView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import com.commonsware.cwac.cache.SimpleWebImageCache;
import com.commonsware.cwac.thumbnail.ThumbnailAdapter;
import com.commonsware.cwac.thumbnail.ThumbnailBus;
import com.commonsware.cwac.thumbnail.ThumbnailMessage;
import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment; import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment;
import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase;
@@ -173,7 +177,8 @@ public class ForumDetailFragment extends PullToRefreshListFragment implements Da
@Override @Override
public void run() { public void run() {
TopicContent.getTopics((String) mItem.content.get("forum_id"), mDb); TopicContent.getTopics((String) mItem.content.get("forum_id"), mDb);
setListAdapter(new TopicAdapter(getActivity())); setListAdapter(new ThumbnailAdapter(getActivity(), new TopicAdapter(getActivity()), new SimpleWebImageCache<ThumbnailBus, ThumbnailMessage>(null, null,
101, new ThumbnailBus()), new int[] { R.id.quickContactBadge1 }));
getPullToRefreshListView().onRefreshComplete(); getPullToRefreshListView().onRefreshComplete();
} }
}); });

View File

@@ -35,6 +35,10 @@ import android.widget.AbsListView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import com.commonsware.cwac.cache.SimpleWebImageCache;
import com.commonsware.cwac.thumbnail.ThumbnailAdapter;
import com.commonsware.cwac.thumbnail.ThumbnailBus;
import com.commonsware.cwac.thumbnail.ThumbnailMessage;
import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment; import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment;
import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase;
@@ -171,7 +175,8 @@ public class TopicDetailFragment extends PullToRefreshListFragment implements Da
@Override @Override
public void run() { public void run() {
ThreadContent.getThread((String) mItem.content.get("topic_id"), mDb); ThreadContent.getThread((String) mItem.content.get("topic_id"), mDb);
setListAdapter(new ThreadAdapter(getActivity())); setListAdapter(new ThumbnailAdapter(getActivity(), new ThreadAdapter(getActivity()), new SimpleWebImageCache<ThumbnailBus, ThumbnailMessage>(null, null,
101, new ThumbnailBus()), new int[] { R.id.quickContactBadge1 }));
getPullToRefreshListView().onRefreshComplete(); getPullToRefreshListView().onRefreshComplete();
} }
}); });

View File

@@ -32,6 +32,11 @@ import android.widget.AbsListView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import com.commonsware.cwac.cache.SimpleWebImageCache;
import com.commonsware.cwac.thumbnail.ThumbnailAdapter;
import com.commonsware.cwac.thumbnail.ThumbnailBus;
import com.commonsware.cwac.thumbnail.ThumbnailMessage;
public class TopicListFragment extends ListFragment { public class TopicListFragment extends ListFragment {
private static final String STATE_ACTIVATED_POSITION = "activated_position"; private static final String STATE_ACTIVATED_POSITION = "activated_position";
@@ -61,7 +66,8 @@ public class TopicListFragment extends ListFragment {
@Override @Override
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setListAdapter(new TopicAdapter(getActivity())); setListAdapter(new ThumbnailAdapter(getActivity(), new TopicAdapter(getActivity()), new SimpleWebImageCache<ThumbnailBus, ThumbnailMessage>(null, null, 101,
new ThumbnailBus()), new int[] { R.id.quickContactBadge1 }));
} }
@Override @Override

View File

@@ -129,6 +129,8 @@ public class ThreadAdapter extends BaseAdapter {
holder.title.setText((String) getItem(position).get("post_title")); holder.title.setText((String) getItem(position).get("post_title"));
holder.user.setText((String) getItem(position).get("post_author_name")); holder.user.setText((String) getItem(position).get("post_author_name"));
holder.post.setText((String) getItem(position).get("post_content")); holder.post.setText((String) getItem(position).get("post_content"));
holder.badage.setImageResource(R.drawable.ic_launcher);
holder.badage.setTag("http://www.gravatar.com/avatar/9b4f3d34ca3ce31198efac149c3a1ca2?s=300&d=identicon&r=PG");
return convertView; return convertView;
} }

View File

@@ -131,6 +131,8 @@ public class TopicAdapter extends BaseAdapter {
holder.user.setText((String) getItem(position).get("topic_author_name")); holder.user.setText((String) getItem(position).get("topic_author_name"));
holder.lastestPost.setText((String) getItem(position).get("short_content")); holder.lastestPost.setText((String) getItem(position).get("short_content"));
holder.newPosts.setVisibility(Boolean.parseBoolean((String) getItem(position).get("new_post")) ? View.VISIBLE : View.GONE); holder.newPosts.setVisibility(Boolean.parseBoolean((String) getItem(position).get("new_post")) ? View.VISIBLE : View.GONE);
holder.badage.setImageResource(R.drawable.ic_launcher);
holder.badage.setTag("http://www.gravatar.com/avatar/9b4f3d34ca3ce31198efac149c3a1ca2?s=300&d=identicon&r=PG");
return convertView; return convertView;
} }