示例#1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.fragment_sale_skidkaonline, container, false);
    setHasOptionsMenu(true);
    setRetainInstance(true);

    sale = getArguments().getParcelable(CURRENT_SALE_TAG);

    progressBar = (CircularProgressView) rootView.findViewById(R.id.fragment_sale_progressbar);
    imageView = (SubsamplingScaleImageView) rootView.findViewById(R.id.fragment_sale_imageview);
    imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM);
    imageView.setMaxScale(getResources().getDimension(R.dimen.image_maximum_scale));

    File smallFile = ImageLoader.getInstance().getDiskCache().get(sale.getSmallImageUrl());
    if (smallFile != null) {
      imageView.setImage(ImageSource.uri(smallFile.getAbsolutePath()));
      loadBigImage();
    } else {
      ImageLoader.getInstance()
          .loadImage(
              sale.getSmallImageUrl(),
              null,
              UIL.getScaleImageOptions(),
              new ImageLoadingListener() {
                @Override
                public void onLoadingStarted(String s, View view) {
                  progressBar.setVisibility(View.VISIBLE);
                }

                @Override
                public void onLoadingFailed(String s, View view, FailReason failReason) {
                  progressBar.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                  File smallFile =
                      ImageLoader.getInstance().getDiskCache().get(sale.getSmallImageUrl());
                  if (smallFile != null) {
                    imageView.setImage(ImageSource.uri(smallFile.getAbsolutePath()));
                  }
                  bitmap.recycle();
                  loadBigImage();
                }

                @Override
                public void onLoadingCancelled(String s, View view) {}
              },
              new ImageLoadingProgressListener() {
                @Override
                public void onProgressUpdate(String s, View view, int progress, int size) {
                  progressBar.setProgress(progress * 500 / size);
                }
              });
    }
    return rootView;
  }
  @Override
  public void onBindViewHolder(final ViewHolder holder, int position) {
    Category category = publishItems.get(position);

    ImageLoader.getInstance()
        .displayImage(category.getImageUrl(), holder.image, UIL.getImageOptions());

    holder.name.setText(category.getName());

    if (category.isFavorite()) {
      holder.favorite.setImageResource(R.mipmap.ic_star_amber_24dp);
    } else {
      holder.favorite.setImageResource(R.mipmap.ic_star_outline_amber_24dp);
    }
    holder.favorite.setTag(category);
    holder.favorite.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!(v.getTag() instanceof Category))
              throw new RuntimeException("Category in tag instanceof error");
            Category shop = (Category) v.getTag();
            shop.setFavorite(!shop.isFavorite());
            notifyItemChanged(publishItems.indexOf(shop));
            shop.updateOrAddToDB();
            callback.onFavoriteChanged(shop);
          }
        });

    holder.setClickListener(
        new ViewHolder.ClickListener() {
          @Override
          public void onClick(View v, int position) {
            callback.onItemClick(v, position);
          }
        });
  }
示例#3
0
  private void loadBigImage() {
    ImageLoader.getInstance()
        .loadImage(
            sale.getImageUrl(),
            null,
            UIL.getScaleImageOptions(),
            new ImageLoadingListener() {
              @Override
              public void onLoadingStarted(String s, View view) {
                progressBar.setVisibility(View.VISIBLE);
              }

              @Override
              public void onLoadingFailed(String s, View view, FailReason failReason) {
                progressBar.setVisibility(View.GONE);
              }

              @Override
              public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                File file = ImageLoader.getInstance().getDiskCache().get(sale.getImageUrl());
                if (file != null) {
                  imageView.setImage(ImageSource.uri(file.getAbsolutePath()));
                }
                progressBar.setVisibility(View.GONE);
              }

              @Override
              public void onLoadingCancelled(String s, View view) {}
            },
            new ImageLoadingProgressListener() {
              @Override
              public void onProgressUpdate(String s, View view, int progress, int size) {
                progressBar.setProgress(500 + progress * 500 / size);
              }
            });
  }