Ejemplo n.º 1
0
 @Override
 public void onFilterChanged(int filterType, int position) {
   // TODO Auto-generated method stub
   int Type = filterInfos.get(position).getFilterType(); // 获取类型
   FilterLayoutUtils.this.position = position;
   mMagicDisplay.setFilter(filterType);
   if (position != 0) btn_Favourite.setVisibility(View.VISIBLE);
   else btn_Favourite.setVisibility(View.INVISIBLE);
   btn_Favourite.setSelected(filterInfos.get(position).isFavourite());
   if (position <= favouriteFilterInfos.size()) { // 点击Favourite列表
     for (int i = favouriteFilterInfos.size() + 2; i < filterInfos.size(); i++) {
       if (filterInfos.get(i).getFilterType() == Type) {
         filterInfos.get(i).setSelected(true);
         mAdapter.setLastSelected(i);
         FilterLayoutUtils.this.position = i;
         mAdapter.notifyItemChanged(i);
       } else if (filterInfos.get(i).isSelected()) {
         filterInfos.get(i).setSelected(false);
         mAdapter.notifyItemChanged(i);
       }
     }
   }
   for (int i = 1; i < favouriteFilterInfos.size() + 1; i++) {
     if (filterInfos.get(i).getFilterType() == Type) {
       filterInfos.get(i).setSelected(true);
       mAdapter.notifyItemChanged(i);
     } else if (filterInfos.get(i).isSelected()) {
       filterInfos.get(i).setSelected(false);
       mAdapter.notifyItemChanged(i);
     }
   }
 }
Ejemplo n.º 2
0
        @Override
        public void onClick(View v) {
          if (position != 0 && filterInfos.get(position).getFilterType() != -1) {
            int Type = filterInfos.get(position).getFilterType(); // 获取类型
            if (filterInfos.get(position).isFavourite()) {
              // 取消Favourite------------------------------------
              btn_Favourite.setSelected(false);
              filterInfos.get(position).setFavourite(false);
              mAdapter.notifyItemChanged(position);
              int i = 0;
              for (i = 0; i < favouriteFilterInfos.size(); i++) {
                if (Type == favouriteFilterInfos.get(i).getFilterType()) { // 取消对应Favourite列表中元素
                  favouriteFilterInfos.remove(i);
                  filterInfos.remove(i + 1); // 从filterInfos去除
                  mAdapter.notifyItemRemoved(i + 1);
                  mAdapter.setLastSelected(mAdapter.getLastSelected() - 1);
                  break;
                }
              }
              position--;
              mAdapter.notifyItemRangeChanged(i + 1, filterInfos.size() - i - 1);
            } else { // 增加favourite
              btn_Favourite.setSelected(true); // 更改状态
              filterInfos.get(position).setFavourite(true);
              mAdapter.notifyItemChanged(position);

              FilterInfo filterInfo = new FilterInfo();
              filterInfo.setFilterType(Type);
              filterInfo.setSelected(true);
              filterInfo.setFavourite(true);
              filterInfos.add(favouriteFilterInfos.size() + 1, filterInfo);
              position++;
              mAdapter.notifyItemInserted(favouriteFilterInfos.size() + 1);
              mAdapter.notifyItemRangeChanged(
                  favouriteFilterInfos.size() + 1,
                  filterInfos.size() - favouriteFilterInfos.size() - 1);
              favouriteFilterInfos.add(filterInfo);
              mAdapter.setLastSelected(mAdapter.getLastSelected() + 1);
            }
            saveFavourite();
          }
        }