package net.oschina.app.ui;
import greendroid.widget.MyQuickAction;
import greendroid.widget.QuickActionGrid;
import greendroid.widget.QuickActionWidget;
import greendroid.widget.QuickActionWidget.OnQuickActionClickListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import net.oschina.app.AppConfig;
import net.oschina.app.AppContext;
import net.oschina.app.AppException;
import net.oschina.app.R;
import net.oschina.app.adapter.ListViewActiveAdapter;
import net.oschina.app.adapter.ListViewBlogAdapter;
import net.oschina.app.adapter.ListViewMessageAdapter;
import net.oschina.app.adapter.ListViewNewsAdapter;
import net.oschina.app.adapter.ListViewQuestionAdapter;
import net.oschina.app.adapter.ListViewTweetAdapter;
import net.oschina.app.bean.Active;
import net.oschina.app.bean.ActiveList;
import net.oschina.app.bean.Blog;
import net.oschina.app.bean.BlogList;
import net.oschina.app.bean.MessageList;
import net.oschina.app.bean.Messages;
import net.oschina.app.bean.News;
import net.oschina.app.bean.NewsList;
import net.oschina.app.bean.Notice;
import net.oschina.app.bean.Post;
import net.oschina.app.bean.PostList;
import net.oschina.app.bean.Result;
import net.oschina.app.bean.Tweet;
import net.oschina.app.bean.TweetList;
import net.oschina.app.common.StringUtils;
import net.oschina.app.common.UIHelper;
import net.oschina.app.common.UpdateManager;
import net.oschina.app.widget.BadgeView;
import net.oschina.app.widget.NewDataToast;
import net.oschina.app.widget.PullToRefreshListView;
import net.oschina.app.widget.ScrollLayout;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.TextView;
/**
* 应用程序首页
*
* @author liux (http://my.oschina.net/liux)
* @version 1.0
* @created 2012-3-21
*/
public class Main extends BaseActivity {
public static final int QUICKACTION_LOGIN_OR_LOGOUT = 0;
public static final int QUICKACTION_USERINFO = 1;
public static final int QUICKACTION_SOFTWARE = 2;
public static final int QUICKACTION_SEARCH = 3;
public static final int QUICKACTION_SETTING = 4;
public static final int QUICKACTION_EXIT = 5;
private ScrollLayout mScrollLayout;
private RadioButton[] mButtons;
private String[] mHeadTitles;
private int mViewCount;
private int mCurSel;
private ImageView mHeadLogo;
private TextView mHeadTitle;
private ProgressBar mHeadProgress;
private ImageButton mHead_search;
private ImageButton mHeadPub_post;
private ImageButton mHeadPub_tweet;
private int curNewsCatalog = NewsList.CATALOG_ALL;
private int curQuestionCatalog = PostList.CATALOG_ASK;
private int curTweetCatalog = TweetList.CATALOG_LASTEST;
private int curActiveCatalog = ActiveList.CATALOG_LASTEST;
private PullToRefreshListView lvNews;
private PullToRefreshListView lvBlog;
private PullToRefreshListView lvQuestion;
private PullToRefreshListView lvTweet;
private PullToRefreshListView lvActive;
private PullToRefreshListView lvMsg;
private ListViewNewsAdapter lvNewsAdapter;
private ListViewBlogAdapter lvBlogAdapter;
private ListViewQuestionAdapter lvQuestionAdapter;
private ListViewTweetAdapter lvTweetAdapter;
private ListViewActiveAdapter lvActiveAdapter;
private ListViewMessageAdapter lvMsgAdapter;
private List<News> lvNewsData = new ArrayList<News>();
private List<Blog> lvBlogData = new ArrayList<Blog>();
private List<Post> lvQuestionData = new ArrayList<Post>();
private List<Tweet> lvTweetData = new ArrayList<Tweet>();
private List<Active> lvActiveData = new ArrayList<Active>();
private List<Messages> lvMsgData = new ArrayList<Messages>();
private Handler lvNewsHandler;
private Handler lvBlogHandler;
private Handler lvQuestionHandler;
private Handler lvTweetHandler;
private Handler lvActiveHandler;
private Handler lvMsgHandler;
private int lvNewsSumData;
private int lvBlogSumData;
private int lvQuestionSumData;
private int lvTweetSumData;
private int lvActiveSumData;
private int lvMsgSumData;
private RadioButton fbNews;
private RadioButton fbQuestion;
private RadioButton fbTweet;
private RadioButton fbactive;
private ImageView fbSetting;
private Button framebtn_News_lastest;
private Button framebtn_News_blog;
private Button framebtn_News_recommend;
private Button framebtn_Question_ask;
private Button framebtn_Question_share;
private Button framebtn_Question_other;
private Button framebtn_Question_job;
private Button framebtn_Question_site;
private Button framebtn_Tweet_lastest;
private Button framebtn_Tweet_hot;
private Button framebtn_Tweet_my;
private Button framebtn_Active_lastest;
private Button framebtn_Active_atme;
private Button framebtn_Active_comment;
private Button framebtn_Active_myself;
private Button framebtn_Active_message;
private View lvNews_footer;
private View lvBlog_footer;
private View lvQuestion_footer;
private View lvTweet_footer;
private View lvActive_footer;
private View lvMsg_footer;
private TextView lvNews_foot_more;
private TextView lvBlog_foot_more;
private TextView lvQuestion_foot_more;
private TextView lvTweet_foot_more;
private TextView lvActive_foot_more;
private TextView lvMsg_foot_more;
private ProgressBar lvNews_foot_progress;
private ProgressBar lvBlog_foot_progress;
private ProgressBar lvQuestion_foot_progress;
private ProgressBar lvTweet_foot_progress;
private ProgressBar lvActive_foot_progress;
private ProgressBar lvMsg_foot_progress;
public static BadgeView bv_active;
public static BadgeView bv_message;
public static BadgeView bv_atme;
public static BadgeView bv_review;
private QuickActionWidget mGrid;// 快捷栏控件
private boolean isClearNotice = false;
private int curClearNoticeType = 0;
private TweetReceiver tweetReceiver;// 动弹发布接收器
private AppContext appContext;// 全局Context
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 注册广播接收器
tweetReceiver = new TweetReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("net.oschina.app.action.APP_TWEETPUB");
registerReceiver(tweetReceiver, filter);
appContext = (AppContext) getApplication();
// 网络连接判断
if (!appContext.isNetworkConnected())
UIHelper.ToastMessage(this, R.string.network_not_connected);
// 初始化登录
appContext.initLoginInfo();
this.initHeadView();
this.initFootBar();
this.initPageScroll();
this.initFrameButton();
this.initBadgeView();
this.initQuickActionGrid();
this.initFrameListView();
// 检查新版本
if (appContext.isCheckUp()) {
UpdateManager.getUpdateManager().checkAppUpdate(this, false);
}
// 启动轮询通知信息
this.foreachUserNotice();
}
@Override
protected void onResume() {
super.onResume();
if (mViewCount == 0)
mViewCount = 4;
if (mCurSel == 0 && !fbNews.isChecked()) {
fbNews.setChecked(true);
fbQuestion.setChecked(false);
fbTweet.setChecked(false);
fbactive.setChecked(false);
}
// 读取左右滑动配置
mScrollLayout.setIsScroll(appCont