| | |
| | | import android.os.Bundle |
| | | import android.os.Environment |
| | | import android.support.v7.widget.GridLayoutManager |
| | | import android.support.v7.widget.RecyclerView |
| | | import android.view.View |
| | | import cn.flightfeather.thirdapp.R |
| | | import cn.flightfeather.thirdapp.activity.PhotoViewerActivity |
| | |
| | | import cn.flightfeather.thirdapp.bean.Mediafile |
| | | import cn.flightfeather.thirdapp.bean.Scense |
| | | import cn.flightfeather.thirdapp.bean.Subtask |
| | | import cn.flightfeather.thirdapp.fragment.InspectionFragment.intToByte |
| | | import cn.flightfeather.thirdapp.model.enumreation.MediaFileType |
| | | import cn.flightfeather.thirdapp.module.base.BaseActivity |
| | | import cn.flightfeather.thirdapp.module.base.BaseTakePicActivity |
| | | import cn.flightfeather.thirdapp.module.base.TAKE_PHOTO |
| | |
| | | import java.io.IOException |
| | | import java.io.Serializable |
| | | import java.util.* |
| | | import kotlin.collections.ArrayList |
| | | |
| | | const val BUSINESS_TYPE_CAMERA = 5 |
| | | |
| | | class MenuCameraActivity : BaseActivity() { |
| | | override fun getLayoutId(): Int = R.layout.dialog_camera |
| | | |
| | | //页面支持的拍摄图片类型 |
| | | private val typeList = listOf(MediaFileType.RoutineRecord, MediaFileType.Nameplate, MediaFileType.MonitorDevice) |
| | | |
| | | //当前选择的拍照类型 |
| | | private var currentType = MediaFileType.RoutineRecord |
| | | |
| | | lateinit var viewModel: MenuCameraViewModel |
| | | |
| | |
| | | lng = intent.getDoubleExtra("lng", 0.0) |
| | | |
| | | initUI() |
| | | |
| | | viewModel.mediaFileList.observe(this, Observer { |
| | | it?.let { |
| | | rv_photo_list.adapter?.notifyDataSetChanged() |
| | | |
| | | val t = "共${it.size}张照片" |
| | | tv_count.text = t |
| | | } |
| | | }) |
| | | initObserver() |
| | | |
| | | inspection?.guid?.let { viewModel.getMediaFile(it) } |
| | | } |
| | |
| | | } |
| | | try { |
| | | FileUtil.copyFile(oldFile, newFile) |
| | | putMediaFile(path, fileName, cal) |
| | | val mf = putMediaFile(path, fileName, cal) |
| | | addPhoto(mf) |
| | | } catch (e: IOException) { |
| | | e.printStackTrace() |
| | | application.toast("复制文件失败") |
| | | } |
| | | } |
| | | } |
| | | inspection?.guid?.let { viewModel.getMediaFile(it) } |
| | | } |
| | | VIEW_PHOTO -> { |
| | | //查看临时拍摄图片可以删除 |
| | | data?.getIntExtra("position", -1)?.let { |
| | | viewModel.mediaFileList.value?.removeAt(it) |
| | | rv_photo_list.adapter?.run { |
| | | notifyDataSetChanged() |
| | | } |
| | | deletePhoto(it) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun initUI() { |
| | | rv_photo_list.run { |
| | | typeList.forEach { |
| | | getDataSet(it).run { |
| | | initRecyclerView(first.value, second, it) |
| | | } |
| | | } |
| | | fab_problem_list_close.setOnClickListener { |
| | | finish() |
| | | } |
| | | } |
| | | |
| | | private fun initRecyclerView(dataList: MutableList<Mediafile>?, recyclerView: RecyclerView, type: MediaFileType) { |
| | | if (dataList==null) return |
| | | recyclerView.run { |
| | | layoutManager = GridLayoutManager(this@MenuCameraActivity, 4) |
| | | adapter = PhotoListAdapter(viewModel.mediaFileList.value, this@MenuCameraActivity) |
| | | adapter = PhotoListAdapter(dataList, this@MenuCameraActivity) |
| | | addOnItemTouchListener(RecyclerItemClickListener(this@MenuCameraActivity, this, object : RecyclerItemClickListener.OnItemClickListener { |
| | | override fun onItemClick(view: View?, position: Int) { |
| | | currentType = type |
| | | //拍照 |
| | | if (dataList[position].guid == null) { |
| | | PhotoUtil.pickPhoto2(this@MenuCameraActivity, TAKE_PHOTO, 9) |
| | | } |
| | | //查看图片 |
| | | else { |
| | | val files = ArrayList<File>() |
| | | for (m in viewModel.mediaFileList.value!!) { |
| | | val medias = ArrayList<Mediafile>() |
| | | for (m in dataList) { |
| | | if (m.guid != null) { |
| | | val f = File(Environment.getExternalStorageDirectory(), m.path + m.description) |
| | | files.add(f) |
| | | medias.add(m) |
| | | } |
| | | } |
| | | val intent = Intent(this@MenuCameraActivity, PhotoViewerActivity::class.java) |
| | | .putExtra(PhotoViewerActivity.PARA_FILES, files as Serializable) |
| | | .putExtra("type", PhotoViewerActivity.CAMERA_PHOTO) |
| | | .putExtra("deletable", true) |
| | | .putExtra("position", position) |
| | | .putExtra(PhotoViewerActivity.PARA_MEDIAS, viewModel.mediaFileList.value as Serializable) |
| | | .putExtra("position", position - 1) |
| | | .putExtra(PhotoViewerActivity.PARA_MEDIAS, medias as Serializable) |
| | | startActivityForResult(intent, VIEW_PHOTO) |
| | | } |
| | | } |
| | | |
| | | override fun onItemLongClick(view: View?, position: Int) { |
| | |
| | | |
| | | })) |
| | | } |
| | | |
| | | iv_new_photo.setOnClickListener { |
| | | PhotoUtil.pickPhoto2(this, TAKE_PHOTO, 9) |
| | | } |
| | | |
| | | fab_problem_list_close.setOnClickListener { |
| | | finish() |
| | | private fun initObserver() { |
| | | typeList.forEach { |
| | | getDataSet(it).run { |
| | | first.observe(this@MenuCameraActivity, Observer {list-> |
| | | list?.let { |
| | | second.adapter?.notifyDataSetChanged() |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun putMediaFile(path: String, fileName: String, calendar: Calendar) { |
| | | private fun putMediaFile(path: String, fileName: String, calendar: Calendar):Mediafile { |
| | | val mediaFile = Mediafile() |
| | | mediaFile.guid = UUIDGenerator.generate16ShortUUID() |
| | | mediaFile.iguid = inspection?.guid |
| | |
| | | mediaFile.address = "${scene?.cityname ?: ""} + ${scene?.districtname |
| | | ?: ""} + ${scene?.townname ?: ""} + ${scene?.location ?: ""}" |
| | | mediaFile.filetype = 1 |
| | | mediaFile.businesstype = "常规记录" |
| | | mediaFile.businesstypeid = intToByte(5) |
| | | mediaFile.businesstype = currentType.des |
| | | mediaFile.businesstypeid = currentType.value.toByte() |
| | | mediaFile.path = path |
| | | mediaFile.description = fileName |
| | | mediaFile.savetime = Date() |
| | |
| | | mediaFile.remark = "未上传" |
| | | |
| | | viewModel.putMediaFile(mediaFile) |
| | | |
| | | return mediaFile |
| | | } |
| | | |
| | | private fun addPhoto(mediaFile: Mediafile) { |
| | | getDataSet(currentType).run { |
| | | first.value?.add(mediaFile) |
| | | second.adapter?.run { |
| | | notifyDataSetChanged() |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun deletePhoto(pos: Int) { |
| | | getDataSet(currentType).run { |
| | | first.value?.removeAt(pos + 1)//第一个数据为拍照按钮 |
| | | second.adapter?.run { |
| | | notifyDataSetChanged() |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun getDataSet(type: MediaFileType) = when (type) { |
| | | MediaFileType.RoutineRecord -> Pair(viewModel.routineRecordList, rv_photo_list_1) |
| | | MediaFileType.Nameplate -> Pair(viewModel.nameplateList, rv_photo_list_2) |
| | | MediaFileType.MonitorDevice -> Pair(viewModel.monitorDeviceList, rv_photo_list_3) |
| | | else -> Pair(viewModel.routineRecordList, rv_photo_list_1) |
| | | } |
| | | } |