| | |
| | | const val EXTRA_SELECT_IMAGES = ImagePicker.EXTRA_SELECT_IMAGES |
| | | } |
| | | |
| | | //拍摄的待上传的图片文件列表 |
| | | val pathTempList = mutableListOf<File>() |
| | | //拍摄的待上传的图片文件列表, true: 代表需要上传;false: 代表不需要上传 |
| | | val pathTempList = mutableListOf<Pair<File, Boolean>>() |
| | | |
| | | // fixme: 2019/8/2 由于原代码中大部分图片拍摄固定死了最多3张,所以没有使用列表结构,而是手动设置了3个ImageView,此处暂时延用,不做修改 |
| | | var imageViewList = mutableListOf<ImageView>() |
| | |
| | | //查看临时拍摄图片可以删除 |
| | | data?.getIntExtra("position", -1)?.let { |
| | | if (it > -1) { |
| | | if (pathTempList[it].exists()) { |
| | | pathTempList[it].delete() |
| | | if (pathTempList[it].first.exists()) { |
| | | pathTempList[it].first.delete() |
| | | } |
| | | pathTempList.removeAt(it) |
| | | refreshImageView() |
| | |
| | | } |
| | | try { |
| | | FileUtil.copyFile(oldFile, newFile) |
| | | pathTempList.add(newFile) |
| | | pathTempList.add(Pair(newFile, true)) |
| | | } catch (e: IOException) { |
| | | e.printStackTrace() |
| | | application.toast("复制文件失败") |
| | |
| | | i < picSize -> { |
| | | imageViewList[i].setOnClickListener(viewPhotoClickListener(i)) |
| | | // fixme: 2019/8/2 此处给imageVIew设置图片在原代码中是自定义了一个AsyncTask,之后可以用Glide等第三方框架替代 |
| | | SetImageTask(pathTempList[i], imageViewList[i]).execute() |
| | | imageViewList[i].scaleType = ImageView.ScaleType.CENTER_CROP |
| | | SetImageTask(pathTempList[i].first, imageViewList[i]).execute() |
| | | } |
| | | i == picSize -> imageViewList[i].run { |
| | | setOnClickListener(takePhotoClickListener(i)) |
| | | scaleType = ImageView.ScaleType.FIT_CENTER |
| | | setImageResource(R.drawable.icon_add_photo) |
| | | } |
| | | else -> imageViewList[i].run { |
| | | setOnClickListener(null) |
| | | scaleType = ImageView.ScaleType.FIT_CENTER |
| | | setImageResource(R.drawable.icon_add_photo_blank) |
| | | } |
| | | } |
| | |
| | | //有图片时,查看图片的点击事件(temp) |
| | | fun viewPhotoClickListener(position: Int): View.OnClickListener { |
| | | return View.OnClickListener { |
| | | val fileList = mutableListOf<File>() |
| | | pathTempList.forEach { |
| | | fileList.add(it.first) |
| | | } |
| | | val intent = Intent(this, PhotoViewerActivity::class.java) |
| | | intent.putExtra("position", position) |
| | | intent.putExtra("type", PhotoViewerActivity.EVIDENCE_PHOTO_TEMP) |
| | | intent.putExtra("deletable", picDeletable) |
| | | intent.putExtra(PhotoViewerActivity.PARA_FILES, pathTempList as Serializable) |
| | | intent.putExtra(PhotoViewerActivity.PARA_FILES, fileList as Serializable) |
| | | startActivityForResult(intent, VIEW_PHOTO) |
| | | } |
| | | } |
| | |
| | | return View.OnClickListener { |
| | | val t = imageViewList.size - pathTempList.size |
| | | val picNum = if (t >= 0) t else 0 |
| | | PhotoUtil.pickPhoto2(this, TAKE_PHOTO, picNum) |
| | | PhotoUtil.pickPhoto(this, TAKE_PHOTO, picNum) |
| | | } |
| | | } |
| | | |