private void bindView() { hideProgressDialog(); icon.setVisibility(View.VISIBLE); icon.setImageResource(mFileObject.getIconResourceId()); iconTxt.setVisibility(View.GONE); name.setText(mFileObject.getName()); content.setText(Global.HumanReadableFilesize(mFileObject.getSize())); tvDownload.setText( String.format( downloadFormat, Global.HumanReadableFilesize(0.0), Global.HumanReadableFilesize(mFileObject.getSize()))); progressBar.setMax(mFileObject.getSize()); mainLayout.setVisibility(View.VISIBLE); mFile = FileUtil.getDestinationInExternalPublicDir( getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId)); Log.d(TAG, "downloadId:" + downloadId); File file = FileUtil.getDestinationInExternalPublicDir( getFileDownloadPath(), mAttachmentFileObject.getSaveName(mProjectObjectId)); if (file.exists() && file.isFile()) { showState(STATE_FINISHDOWNLOAD); } else { showState(STATE_NEEDDOWNLOAD); } }
@OptionsItem void action_info() { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog dialog = builder .setTitle("文件信息") .setMessage( String.format( fileInfoFormat, mAttachmentFileObject.fileType, Global.HumanReadableFilesize(mAttachmentFileObject.getSize()), Global.dayToNow(mAttachmentFileObject.created_at), Global.dayToNow(mAttachmentFileObject.updated_at), mAttachmentFileObject.owner.name)) .setPositiveButton("确定", null) .show(); dialogTitleLineColor(dialog); }
@Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 0: int status = (Integer) msg.obj; if (isDownloading(status)) { showState(STATE_STARTDOWNLOAD); if (msg.arg2 < 0) { tvDownload.setText( String.format( downloadFormat, Global.HumanReadableFilesize(0.00), Global.HumanReadableFilesize(mFileObject.getSize()))); progressBar.setProgress(0); } else { tvDownload.setText( String.format( downloadFormat, Global.HumanReadableFilesize(msg.arg1), Global.HumanReadableFilesize(msg.arg2))); progressBar.setProgress(msg.arg1); } } else { if (status == DownloadManager.STATUS_FAILED) { // downloadButton.setText(getString(R.string.app_status_download_fail)); showButtomToast("下载失败,请重试"); showState(STATE_NEEDDOWNLOAD); } else if (status == DownloadManager.STATUS_SUCCESSFUL) { downloadListEditor.remove(mFileObject.file_id); downloadListEditor.commit(); showState(STATE_FINISHDOWNLOAD); downloadId = 0L; // jumpTextHtmlActivity(); // if (mAttachmentFileObject.isMd()) // finish(); Intent intent = new Intent(); mAttachmentFileObject.isDownload = true; intent.putExtra(AttachmentFileObject.RESULT, mAttachmentFileObject); if (mAttachmentFileObject.needJump()) { intent.putExtra( AttachmentsActivity.FileActions.ACTION_NAME, AttachmentsActivity.FileActions.ACTION_DOWNLOAD_OPEN); setResult(RESULT_OK, intent); finish(); } else { intent.putExtra( AttachmentsActivity.FileActions.ACTION_NAME, AttachmentsActivity.FileActions.ACTION_DOWNLOAD_OPEN); setResult(RESULT_OK, intent); } } else { showState(STATE_NEEDDOWNLOAD); } } break; } }