| | |
| | | package cn.flightfeather.thirdapp.module.inspection |
| | | |
| | | import android.annotation.SuppressLint |
| | | import android.app.Activity |
| | | import android.arch.lifecycle.Observer |
| | | import android.arch.lifecycle.ViewModelProviders |
| | |
| | | import android.os.Bundle |
| | | import android.os.Environment |
| | | import android.support.v7.widget.GridLayoutManager |
| | | import android.support.v7.widget.RecyclerView |
| | | import android.view.LayoutInflater |
| | | import android.view.View |
| | | import android.widget.ImageView |
| | | import android.widget.TextView |
| | | import cn.flightfeather.thirdapp.R |
| | | import cn.flightfeather.thirdapp.activity.PhotoViewerActivity |
| | | import cn.flightfeather.thirdapp.adapter.PhotoListAdapter |
| | | import cn.flightfeather.thirdapp.adapter.RecyclerItemClickListener |
| | | import cn.flightfeather.thirdapp.bean.Inspection |
| | | 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.bean.entity.Inspection |
| | | import cn.flightfeather.thirdapp.bean.entity.Mediafile |
| | | import cn.flightfeather.thirdapp.bean.entity.Scense |
| | | import cn.flightfeather.thirdapp.bean.entity.Subtask |
| | | 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 cn.flightfeather.thirdapp.util.UUIDGenerator |
| | | import cn.flightfeather.thirdapp.util.file.FileUtil |
| | | import cn.flightfeather.thirdapp.util.photo.PhotoUtil |
| | | import cn.flightfeather.thirdapp.view.SearchView |
| | | import kotlinx.android.synthetic.main.dialog_camera.* |
| | | import kotlinx.android.synthetic.main.dialog_camera.fab_problem_list_close |
| | | import kotlinx.android.synthetic.main.dialog_camera_3.* |
| | | import org.jetbrains.anko.toast |
| | | import java.io.File |
| | | 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 |
| | | override fun getLayoutId(): Int = R.layout.dialog_camera_3 |
| | | |
| | | //页面支持的拍摄图片类型 |
| | | private val typeList = listOf(MediaFileType.RoutineRecord, MediaFileType.Nameplate, MediaFileType.MonitorDevice) |
| | | |
| | | //当前选择的拍照类型 |
| | | private var currentType = MediaFileType.RoutineRecord |
| | | private var currentTypeName = currentType.des |
| | | |
| | | lateinit var viewModel: MenuCameraViewModel |
| | | |
| | | private val viewList = mutableListOf<View>() |
| | | |
| | | private val listMap = mutableMapOf<MediaFileType, RecyclerView>() |
| | | |
| | | var subTask: Subtask? = null |
| | | var inspection: Inspection? = null |
| | |
| | | lng = intent.getDoubleExtra("lng", 0.0) |
| | | |
| | | initUI() |
| | | initObserver() |
| | | |
| | | viewModel.mediaFileList.observe(this, Observer { |
| | | it?.let { |
| | | rv_photo_list.adapter?.notifyDataSetChanged() |
| | | |
| | | val t = "共${it.size}张照片" |
| | | tv_count.text = t |
| | | inspection?.guid?.let {guid -> |
| | | scene?.typeid?.let { typeId -> |
| | | viewModel.getMediaFile(guid, typeId.toInt()) |
| | | } |
| | | }) |
| | | |
| | | inspection?.guid?.let { viewModel.getMediaFile(it) } |
| | | } |
| | | } |
| | | |
| | | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
| | |
| | | val oldFile = File(it) |
| | | val cal = Calendar.getInstance().apply { time = subTask?.executionstarttime } |
| | | scene?.run { |
| | | val path = "FlightFeather/Photo/" + districtname + "/"+ cal.get(Calendar.YEAR) + "年" + (cal.get(Calendar.MONTH) + 1) + "月/"+ (cal.get(Calendar.MONTH) + 1) + "月" + cal.get(Calendar.DAY_OF_MONTH) + "日/"+ name + "/任意拍照/" |
| | | val path = "FlightFeather/Photo/" + districtname + "/" + cal.get(Calendar.YEAR) + "年" + (cal.get(Calendar.MONTH) + 1) + "月/" + |
| | | (cal.get(Calendar.MONTH) + 1) + "月" + cal.get(Calendar.DAY_OF_MONTH) + "日/" + name + "/任意拍照/" + currentTypeName + "/" |
| | | |
| | | val fileName = UUIDGenerator.generateUUID(4) + ".jpg" |
| | | val newFile = File(Environment.getExternalStorageDirectory(), path + fileName) |
| | | if (!newFile.parentFile.exists()) { |
| | |
| | | } |
| | | 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() |
| | | } |
| | | } |
| | | |
| | | @SuppressLint("SetTextI18n") |
| | | private fun initRecyclerView(dataList: List<Mediafile>?, type: MediaFileType, alias: String?) { |
| | | if (dataList == null) return |
| | | val view = LayoutInflater.from(this).inflate(R.layout.item_take_photo, null) |
| | | val searchView = view.findViewById<SearchView>(R.id.search_view) |
| | | val title = view.findViewById<TextView>(R.id.txt_title) |
| | | searchView.onConfirm = { str -> |
| | | scene?.typeid?.let { |
| | | viewModel.updateAlias(it.toInt(), type, str) { alias -> |
| | | title.text = if (alias.isBlank()) type.des else "${alias}(${type.des})" |
| | | } |
| | | } |
| | | } |
| | | title.text = if (alias.isNullOrBlank()) type.des else "${alias}(${type.des})" |
| | | view.findViewById<ImageView>(R.id.img_edit).setOnClickListener { |
| | | searchView.show(type.des, alias ?: "") |
| | | } |
| | | view.findViewById<RecyclerView>(R.id.rv_photo_list).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) { |
| | | val files = ArrayList<File>() |
| | | for (m in viewModel.mediaFileList.value!!) { |
| | | val f = File(Environment.getExternalStorageDirectory(), m.path + m.description) |
| | | files.add(f) |
| | | currentType = type |
| | | currentTypeName = title.text.toString() |
| | | //拍照 |
| | | if (dataList[position].guid == null) { |
| | | PhotoUtil.pickPhoto2(this@MenuCameraActivity, TAKE_PHOTO, 9) |
| | | } |
| | | 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) |
| | | startActivityForResult(intent, VIEW_PHOTO) |
| | | //查看图片 |
| | | else { |
| | | val files = ArrayList<File>() |
| | | 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 - 1) |
| | | .putExtra(PhotoViewerActivity.PARA_MEDIAS, medias as Serializable) |
| | | startActivityForResult(intent, VIEW_PHOTO) |
| | | } |
| | | } |
| | | |
| | | override fun onItemLongClick(view: View?, position: Int) { |
| | | } |
| | | |
| | | })) |
| | | |
| | | if (!listMap.containsKey(type)) { |
| | | listMap[type] = this |
| | | } |
| | | } |
| | | |
| | | iv_new_photo.setOnClickListener { |
| | | PhotoUtil.pickPhoto2(this, TAKE_PHOTO, 9) |
| | | } |
| | | |
| | | fab_problem_list_close.setOnClickListener { |
| | | finish() |
| | | } |
| | | viewList.add(view) |
| | | } |
| | | |
| | | private fun putMediaFile(path: String, fileName: String, calendar: Calendar) { |
| | | private fun initObserver() { |
| | | viewModel.fileList.observe(this, Observer { |
| | | it?.forEach { m -> |
| | | initRecyclerView(m.dataList, m.type ?: MediaFileType.Others, m.alias) |
| | | } |
| | | if (viewList.isNotEmpty()) { |
| | | banner.dataList = viewList |
| | | } |
| | | }) |
| | | // 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): Mediafile { |
| | | val mediaFile = Mediafile() |
| | | mediaFile.guid = UUIDGenerator.generate16ShortUUID() |
| | | mediaFile.iguid = inspection?.guid |
| | | mediaFile.longitude = lng |
| | | mediaFile.latitude = lat |
| | | mediaFile.address = "${scene?.cityname ?: ""} + ${scene?.districtname |
| | | ?: ""} + ${scene?.townname ?: ""} + ${scene?.location ?: ""}" |
| | | 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) { |
| | | if (listMap.containsKey(currentType)) { |
| | | viewModel.fileList.value?.forEach { |
| | | if (it.type == currentType) { |
| | | it.dataList.add(mediaFile)//第一个数据为拍照按钮 |
| | | listMap[currentType]?.adapter?.notifyDataSetChanged() |
| | | } |
| | | } |
| | | } |
| | | // getDataSet(currentType).run { |
| | | // first.value?.add(mediaFile) |
| | | // second.adapter?.run { |
| | | // notifyDataSetChanged() |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | private fun deletePhoto(pos: Int) { |
| | | if (listMap.containsKey(currentType)) { |
| | | viewModel.fileList.value?.forEach { |
| | | if (it.type == currentType) { |
| | | it.dataList.removeAt(pos + 1)//第一个数据为拍照按钮 |
| | | listMap[currentType]?.adapter?.notifyDataSetChanged() |
| | | } |
| | | } |
| | | } |
| | | // 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) |
| | | } |
| | | } |