Exemplo n.º 1
0
  @Override
  public void unbind() {
    super.unbind();

    // Unbinding model
    if (downloadFileVM != null) {
      downloadFileVM.detach();
      downloadFileVM = null;
    }
    if (uploadFileVM != null) {
      uploadFileVM.detach();
      uploadFileVM = null;
    }
  }
Exemplo n.º 2
0
  @Override
  protected void bindData(Message message, boolean isUpdated) {
    document = (DocumentContent) message.getContent();

    // Content data
    fileName.setText(document.getName());
    fileSize.setText(
        messenger().getFormatter().formatFileSize(document.getSource().getSize())
            + " "
            + document.getExt().toUpperCase());

    // region File icon
    if (isUpdated) {
      boolean isAppliedThumb = false;
      if (document.getFastThumb() != null) {
        try {
          Bitmap img = ImageLoading.loadBitmap(document.getFastThumb().getImage());
          fileIcon.setImageBitmap(img);
          fileIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
          isAppliedThumb = true;
        } catch (ImageLoadException e) {
          e.printStackTrace();
        }
      }
      if (!isAppliedThumb) {
        int type = FileTypes.getType(document.getExt());
        switch (type) {
          default:
          case FileTypes.TYPE_UNKNOWN:
            fileIcon.setImageResource(R.drawable.picker_unknown);
            break;
          case FileTypes.TYPE_APK:
            fileIcon.setImageResource(R.drawable.picker_apk);
            break;
          case FileTypes.TYPE_MUSIC:
            fileIcon.setImageResource(R.drawable.picker_music);
            break;
          case FileTypes.TYPE_PICTURE:
            fileIcon.setImageResource(R.drawable.picker_unknown);
            break;
          case FileTypes.TYPE_DOC:
            fileIcon.setImageResource(R.drawable.picker_doc);
            break;
          case FileTypes.TYPE_RAR:
            fileIcon.setImageResource(R.drawable.picker_rar);
            break;
          case FileTypes.TYPE_VIDEO:
            fileIcon.setImageResource(R.drawable.picker_video);
            break;
          case FileTypes.TYPE_ZIP:
            fileIcon.setImageResource(R.drawable.picker_zip);
            break;
          case FileTypes.TYPE_XLS:
            fileIcon.setImageResource(R.drawable.picker_xls);
            break;
          case FileTypes.TYPE_PPT:
            fileIcon.setImageResource(R.drawable.picker_ppt);
            break;
          case FileTypes.TYPE_CSV:
            fileIcon.setImageResource(R.drawable.picker_csv);
            break;
          case FileTypes.TYPE_HTM:
            fileIcon.setImageResource(R.drawable.picker_htm);
            break;
          case FileTypes.TYPE_HTML:
            fileIcon.setImageResource(R.drawable.picker_html);
            break;
          case FileTypes.TYPE_PDF:
            fileIcon.setImageResource(R.drawable.picker_pdf);
            break;
        }
        fileIcon.setScaleType(ImageView.ScaleType.CENTER);
      }
    }
    // endregion

    // Update view
    boolean needRebind = false;
    if (isUpdated) {
      // Resetting binding
      if (downloadFileVM != null) {
        downloadFileVM.detach();
        downloadFileVM = null;
      }
      if (uploadFileVM != null) {
        uploadFileVM.detach();
        uploadFileVM = null;
      }
      needRebind = true;
    } else {
      if (document.getSource() instanceof FileLocalSource) {
        if (uploadFileVM == null && downloadFileVM != null) {
          downloadFileVM.detach();
          downloadFileVM = null;
          needRebind = true;
        }
      } else if (document.getSource() instanceof FileRemoteSource) {
        if (uploadFileVM != null && downloadFileVM == null) {
          uploadFileVM.detach();
          uploadFileVM = null;
          needRebind = true;
        }
      }
    }

    if (downloadFileVM == null && uploadFileVM == null) {
      needRebind = true;
    }

    if (needRebind) {
      downloadIcon.setVisibility(View.GONE);
      progressView.setVisibility(View.GONE);
      progressValue.setVisibility(View.GONE);
      fileIcon.setVisibility(View.GONE);
      menu.setVisibility(View.GONE);
      status.setVisibility(View.GONE);

      if (document.getSource() instanceof FileRemoteSource) {
        FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
        boolean autoDownload =
            remoteSource.getFileReference().getFileSize() <= 1024 * 1024; // < 1MB
        downloadFileVM =
            messenger()
                .bindFile(remoteSource.getFileReference(), autoDownload, new DownloadVMCallback());
      } else if (document.getSource() instanceof FileLocalSource) {
        uploadFileVM = messenger().bindUpload(message.getRid(), new UploadVMCallback());
      }
    }
  }