Skip to content

Commit

Permalink
2012-9-10 V1.7.1 Beta2
Browse files Browse the repository at this point in the history
1.修复首页部分列表出现空数据的问题;
2.修复收藏失败老弹出用户登录框的问题;
  • Loading branch information
jxsmallmouse committed Sep 10, 2012
1 parent da75e47 commit 9e03d52
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 26 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.oschina.app"
android:versionCode="14"
android:versionName="1.7.1 Beta1">
android:versionCode="15"
android:versionName="1.7.1 Beta2">
<uses-sdk android:minSdkVersion="4" />

<application android:name=".AppContext" android:icon="@drawable/icon" android:label="@string/app_name" >
Expand Down
76 changes: 57 additions & 19 deletions src/net/oschina/app/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
Expand Down Expand Up @@ -242,12 +243,13 @@ public User loginVerify(String account, String pwd) throws AppException {
public MyInformation getMyInformation(boolean isRefresh) throws AppException {
MyInformation myinfo = null;
String key = "myinfo_"+loginUid;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
myinfo = ApiClient.myInformation(this, loginUid);
if(myinfo != null && myinfo.getName().length() > 0){
Notice notice = myinfo.getNotice();
myinfo.setNotice(null);
myinfo.setCacheKey(key);
saveObject(myinfo, key);
myinfo.setNotice(notice);
}
Expand Down Expand Up @@ -280,12 +282,13 @@ public UserInformation getInformation(int uid, int hisuid, String hisname, int p
}
UserInformation userinfo = null;
String key = "userinfo_"+uid+"_"+hisuid+"_"+(URLEncoder.encode(hisname))+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
userinfo = ApiClient.information(this, uid, hisuid, _hisname, pageIndex, PAGE_SIZE);
if(userinfo != null && pageIndex == 0){
Notice notice = userinfo.getNotice();
userinfo.setNotice(null);
userinfo.setCacheKey(key);
saveObject(userinfo, key);
userinfo.setNotice(notice);
}
Expand Down Expand Up @@ -355,12 +358,13 @@ public Notice getUserNotice(int uid) throws AppException {
public FavoriteList getFavoriteList(int type, int pageIndex, boolean isRefresh) throws AppException {
FavoriteList list = null;
String key = "favoritelist_"+loginUid+"_"+type+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getFavoriteList(this, loginUid, type, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -387,12 +391,13 @@ public FavoriteList getFavoriteList(int type, int pageIndex, boolean isRefresh)
public FriendList getFriendList(int relation, int pageIndex, boolean isRefresh) throws AppException {
FriendList list = null;
String key = "friendlist_"+loginUid+"_"+relation+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getFriendList(this, loginUid, relation, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand Down Expand Up @@ -420,12 +425,13 @@ public FriendList getFriendList(int relation, int pageIndex, boolean isRefresh)
public NewsList getNewsList(int catalog, int pageIndex, boolean isRefresh) throws AppException {
NewsList list = null;
String key = "newslist_"+catalog+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getNewsList(this, catalog, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -451,12 +457,13 @@ public NewsList getNewsList(int catalog, int pageIndex, boolean isRefresh) throw
public News getNews(int news_id, boolean isRefresh) throws AppException {
News news = null;
String key = "news_"+news_id;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
news = ApiClient.getNewsDetail(this, news_id);
if(news != null){
Notice notice = news.getNotice();
news.setNotice(null);
news.setCacheKey(key);
saveObject(news, key);
news.setNotice(notice);
}
Expand All @@ -483,12 +490,13 @@ public News getNews(int news_id, boolean isRefresh) throws AppException {
public BlogList getUserBlogList(int authoruid, String authorname, int pageIndex, boolean isRefresh) throws AppException {
BlogList list = null;
String key = "userbloglist_"+authoruid+"_"+(URLEncoder.encode(authorname))+"_"+loginUid+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getUserBlogList(this, authoruid, authorname, loginUid, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -515,12 +523,13 @@ public BlogList getUserBlogList(int authoruid, String authorname, int pageIndex,
public BlogList getBlogList(String type, int pageIndex, boolean isRefresh) throws AppException {
BlogList list = null;
String key = "bloglist_"+type+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getBlogList(this, type, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -546,12 +555,13 @@ public BlogList getBlogList(String type, int pageIndex, boolean isRefresh) throw
public Blog getBlog(int blog_id, boolean isRefresh) throws AppException {
Blog blog = null;
String key = "blog_"+blog_id;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
blog = ApiClient.getBlogDetail(this, blog_id);
if(blog != null){
Notice notice = blog.getNotice();
blog.setNotice(null);
blog.setCacheKey(key);
saveObject(blog, key);
blog.setNotice(notice);
}
Expand All @@ -578,12 +588,13 @@ public Blog getBlog(int blog_id, boolean isRefresh) throws AppException {
public SoftwareList getSoftwareList(String searchTag, int pageIndex, boolean isRefresh) throws AppException {
SoftwareList list = null;
String key = "softwarelist_"+searchTag+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getSoftwareList(this, searchTag, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand Down Expand Up @@ -616,6 +627,7 @@ public SoftwareList getSoftwareTagList(int searchTag, int pageIndex, boolean isR
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand Down Expand Up @@ -647,6 +659,7 @@ public SoftwareCatalogList getSoftwareCatalogList(int tag) throws AppException {
if(list != null){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand Down Expand Up @@ -678,6 +691,7 @@ public Software getSoftware(String ident, boolean isRefresh) throws AppException
if(soft != null){
Notice notice = soft.getNotice();
soft.setNotice(null);
soft.setCacheKey(key);
saveObject(soft, key);
soft.setNotice(notice);
}
Expand All @@ -704,12 +718,13 @@ public Software getSoftware(String ident, boolean isRefresh) throws AppException
public PostList getPostList(int catalog, int pageIndex, boolean isRefresh) throws AppException {
PostList list = null;
String key = "postlist_"+catalog+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getPostList(this, catalog, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -736,12 +751,13 @@ public PostList getPostList(int catalog, int pageIndex, boolean isRefresh) throw
public PostList getPostListByTag(String tag, int pageIndex, boolean isRefresh) throws AppException {
PostList list = null;
String key = "postlist_"+(URLEncoder.encode(tag))+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getPostListByTag(this, tag, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -767,12 +783,13 @@ public PostList getPostListByTag(String tag, int pageIndex, boolean isRefresh) t
public Post getPost(int post_id, boolean isRefresh) throws AppException {
Post post = null;
String key = "post_"+post_id;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
post = ApiClient.getPostDetail(this, post_id);
if(post != null){
Notice notice = post.getNotice();
post.setNotice(null);
post.setCacheKey(key);
saveObject(post, key);
post.setNotice(notice);
}
Expand All @@ -799,12 +816,13 @@ public Post getPost(int post_id, boolean isRefresh) throws AppException {
public TweetList getTweetList(int catalog, int pageIndex, boolean isRefresh) throws AppException {
TweetList list = null;
String key = "tweetlist_"+catalog+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getTweetList(this, catalog, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -830,12 +848,13 @@ public TweetList getTweetList(int catalog, int pageIndex, boolean isRefresh) thr
public Tweet getTweet(int tweet_id, boolean isRefresh) throws AppException {
Tweet tweet = null;
String key = "tweet_"+tweet_id;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
tweet = ApiClient.getTweetDetail(this, tweet_id);
if(tweet != null){
Notice notice = tweet.getNotice();
tweet.setNotice(null);
tweet.setCacheKey(key);
saveObject(tweet, key);
tweet.setNotice(notice);
}
Expand Down Expand Up @@ -863,12 +882,13 @@ public Tweet getTweet(int tweet_id, boolean isRefresh) throws AppException {
public ActiveList getActiveList(int catalog, int pageIndex, boolean isRefresh) throws AppException {
ActiveList list = null;
String key = "activelist_"+loginUid+"_"+catalog+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getActiveList(this, loginUid, catalog, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -894,12 +914,13 @@ public ActiveList getActiveList(int catalog, int pageIndex, boolean isRefresh) t
public MessageList getMessageList(int pageIndex, boolean isRefresh) throws AppException {
MessageList list = null;
String key = "messagelist_"+loginUid+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getMessageList(this, loginUid, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand All @@ -926,12 +947,13 @@ public MessageList getMessageList(int pageIndex, boolean isRefresh) throws AppEx
public BlogCommentList getBlogCommentList(int id, int pageIndex, boolean isRefresh) throws AppException {
BlogCommentList list = null;
String key = "blogcommentlist_"+id+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getBlogCommentList(this, id, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand Down Expand Up @@ -959,12 +981,13 @@ public BlogCommentList getBlogCommentList(int id, int pageIndex, boolean isRefre
public CommentList getCommentList(int catalog, int id, int pageIndex, boolean isRefresh) throws AppException {
CommentList list = null;
String key = "commentlist_"+catalog+"_"+id+"_"+pageIndex+"_"+PAGE_SIZE;
if(isNetworkConnected() && (!isExistDataCache(key) || isRefresh)) {
if(isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
try{
list = ApiClient.getCommentList(this, catalog, id, pageIndex, PAGE_SIZE);
if(list != null && pageIndex == 0){
Notice notice = list.getNotice();
list.setNotice(null);
list.setCacheKey(key);
saveObject(list, key);
list.setNotice(notice);
}
Expand Down Expand Up @@ -1362,6 +1385,16 @@ public void cleanCookie()
removeProperty(AppConfig.CONF_COOKIE);
}

/**
* 判断缓存数据是否可读
* @param cachefile
* @return
*/
private boolean isReadDataCache(String cachefile)
{
return readObject(cachefile) != null;
}

/**
* 判断缓存是否存在
* @param cachefile
Expand Down Expand Up @@ -1557,6 +1590,11 @@ public Serializable readObject(String file){
}catch(FileNotFoundException e){
}catch(Exception e){
e.printStackTrace();
//反序列化失败 - 删除缓存文件
if(e instanceof InvalidClassException){
File data = getFileStreamPath(file);
data.delete();
}
}finally{
try {
ois.close();
Expand Down
9 changes: 9 additions & 0 deletions src/net/oschina/app/bean/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ public int getId() {
return id;
}

protected String cacheKey;

public String getCacheKey() {
return cacheKey;
}

public void setCacheKey(String cacheKey) {
this.cacheKey = cacheKey;
}
}
4 changes: 3 additions & 1 deletion src/net/oschina/app/ui/BlogDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ public void handleMessage(Message msg) {
}else{
blogDetail.setFavorite(1);
mFavorite.setImageResource(R.drawable.widget_bar_favorite2);
}
}
//重新保存缓存
ac.saveObject(blogDetail, blogDetail.getCacheKey());
}
UIHelper.ToastMessage(BlogDetail.this, res.getErrorMessage());
}else{
Expand Down
1 change: 0 additions & 1 deletion src/net/oschina/app/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,6 @@ public void onClick(View v) {
break;
}
}
setCurPoint(pos);
mScrollLayout.snapToScreen(pos);
}
});
Expand Down
Loading

0 comments on commit 9e03d52

Please sign in to comment.