예제 #1
0
	// 长按菜单响应函数
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		int itemIndex = item.getItemId();
		AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
		View v = menuInfo.targetView;
		switch (itemIndex) {
			case R.id.menu_unrss://取消订阅
				default:
				//显示ProgressDialog  
	            progressDialog = ProgressDialog.show(MyFavActivity.this, "删除收藏", "正在删除收藏中,请稍候", true, false);
				TextView tvId=(TextView)v.findViewById(R.id.recommend_text_id);
				int contentId=Integer.valueOf(tvId.getText().toString());
				FavList.EnumContentType contentType=FavList.EnumContentType.Blog;
				
				try{
					FavListHelper.RemoveFav(contentId,contentType,getApplicationContext());
					Toast.makeText(getApplicationContext(), R.string.unfav_succ, Toast.LENGTH_SHORT).show();
				}catch(Exception ex){
					Toast.makeText(getApplicationContext(), R.string.unfav_fail, Toast.LENGTH_SHORT).show();
				}
				progressDialog.dismiss();
				// 广播
				Intent intent = new Intent();
				Bundle bundle = new Bundle();
				bundle.putInt("contentId",contentId);
				bundle.putInt("contentType", contentType.ordinal());
				bundle.putBoolean("isfav", false);
				intent.putExtras(bundle);
				intent.setAction("android.cnblogs.com.update_favlist");
				sendBroadcast(intent);
		}
		return super.onContextItemSelected(item);
	}
예제 #2
0
		protected List<Blog> doInBackground(String... params) {
			boolean isNetworkAvailable = NetHelper.networkIsAvailable(getApplicationContext());

			int _pageIndex = curPageIndex;
			if (_pageIndex <= 0) {
				_pageIndex = 1;
			}
			FavList.EnumContentType contentType=FavList.EnumContentType.Blog;
			if (isNetworkAvailable) {// 有网络情况				
				List<Blog> listBlogTmp=new ArrayList<Blog>();
				List<FavList> listFavNew = FavListHelper.GetFavListByPage(_pageIndex, contentType, getApplicationContext());
				switch (curPageIndex) {
					case -1 :// 上拉\
						List<FavList> listTmp = new ArrayList<FavList>();
						if (listBlog != null && listBlog.size() > 0) {// 避免首页无数据时
							if (listFavNew != null && listFavNew.size() > 0) {
								int size = listFavNew.size();
								for (int i = 0; i < size; i++) {
									if (!listBlog.contains(listFavNew.get(i))) {// 避免出现重复
										listTmp.add(listFavNew.get(i));
									}
								}
							}
						}
						listFav =listTmp;
					case 0 :// 首次加载
					case 1 :// 刷新
						if (listFavNew != null && listFavNew.size() > 0) {
							listFav= listFavNew;
						}
						break;
					default :// 下拉
						List<FavList> listT = new ArrayList<FavList>();
						if (listBlog != null && listBlog.size() > 0) {// 避免首页无数据时
							if (listFavNew != null && listFavNew.size() > 0) {
								int size = listFavNew.size();
								for (int i = 0; i < size; i++) {
									if (!listBlog.contains(listFavNew.get(i))) {// 避免出现重复
										listT.add(listFavNew.get(i));
									}
								}
							}
						}
						listFav= listT;
				}

				for(int i=0,len=listFav.size();i<len;i++){
					BlogDalHelper helper=new BlogDalHelper(getApplicationContext());
					Blog entity=helper.GetBlogEntity(listFav.get(i).GetContentId());
					listBlogTmp.add(entity);
				}
				return listBlogTmp;
			}

			return null;
		}
예제 #3
0
		@Override
		public void onReceive(Context content, Intent intent) {
			Bundle bundle=intent.getExtras();
			int contentId=bundle.getInt("contentId");
			FavList.EnumContentType contentType=FavList.EnumContentType.values()[bundle.getInt("contentType",0)];
			try{
				boolean isFav=bundle.getBoolean("isfav");
				
				Object obj=FavListHelper.GetFavRefEntity(contentId, contentType, getApplicationContext());

				if(isFav){
					List<Blog> list=new ArrayList<Blog>();
					list.add((Blog)obj);
					adapter.AddMoreData(list);
				}else{
					adapter.RemoveData((Blog)obj);
				}
			}catch(Exception ex){
				Log.e("favActivity", ex.getMessage());
			}
		}