package cn.flightfeather.thirdappmodule.module.inspection
|
|
import android.app.Dialog
|
import android.arch.lifecycle.Observer
|
import android.arch.lifecycle.ViewModelProviders
|
import android.content.Intent
|
import android.os.Bundle
|
import android.os.Environment
|
import android.support.design.widget.FloatingActionButton
|
import android.support.v7.widget.LinearLayoutManager
|
import android.util.Log
|
import android.view.View
|
import android.widget.*
|
import cn.flightfeather.thirdappmodule.R
|
import cn.flightfeather.thirdappmodule.activity.GitDetailActivity
|
import cn.flightfeather.thirdappmodule.adapter.GitListAdapter
|
import cn.flightfeather.thirdappmodule.adapter.GitTypeListAdapter
|
import cn.flightfeather.thirdappmodule.adapter.RecyclerItemClickListener
|
import cn.flightfeather.thirdappmodule.bean.entity.*
|
import cn.flightfeather.thirdappmodule.common.database.DbFactory
|
import cn.flightfeather.thirdappmodule.common.net.RetrofitFactory
|
import cn.flightfeather.thirdappmodule.httpservice.InspectionService
|
import cn.flightfeather.thirdappmodule.module.base.BaseTakePicActivity
|
import cn.flightfeather.thirdappmodule.util.DateFormatter
|
import cn.flightfeather.thirdappmodule.util.ScreenUtils
|
import cn.flightfeather.thirdappmodule.util.UUIDGenerator
|
import cn.flightfeather.thirdappmodule.util.file.FileUtil
|
import com.ping.greendao.gen.GittypeDao
|
import kotlinx.android.synthetic.main.dialog_camera.fab_problem_list_close
|
import kotlinx.android.synthetic.main.dialog_camera.iv_new_photo
|
import kotlinx.android.synthetic.main.dialog_camera.tv_title
|
import kotlinx.android.synthetic.main.dialog_camera_2.*
|
import okhttp3.ResponseBody
|
import retrofit2.Call
|
import retrofit2.Callback
|
import retrofit2.Response
|
import java.io.File
|
import java.io.IOException
|
import java.util.*
|
import kotlin.collections.ArrayList
|
|
/**
|
* @author riku
|
* Date: 2019/8/1
|
* 技防措施
|
*/
|
class MenuNewGitActivity : BaseTakePicActivity() {
|
|
override val picDeletable: Boolean = true
|
|
override fun getImageViews(): MutableList<ImageView> = mutableListOf()
|
|
override fun getLayoutId(): Int = R.layout.dialog_camera_2
|
|
lateinit var viewModel: MenuNewGitViewModel
|
|
var subTask: Subtask? = null
|
var inspection: Inspection? = null
|
var scene: Scense? = null
|
var lat = 0.0
|
var lng = 0.0
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
viewModel = ViewModelProviders.of(this).get(MenuNewGitViewModel::class.java)
|
|
subTask = intent.getSerializableExtra("subTask") as Subtask?
|
inspection = intent.getSerializableExtra("inspection") as Inspection?
|
scene = intent.getSerializableExtra("scene") as Scense?
|
lat = intent.getDoubleExtra("lat", 0.0)
|
lng = intent.getDoubleExtra("lng", 0.0)
|
|
initUI()
|
|
viewModel.gitList.observe(this, Observer {
|
it?.let {
|
rv_photo_list.adapter?.notifyDataSetChanged()
|
|
val t = "共${it.size}条技防措施"
|
tv_count.text = t
|
}
|
})
|
|
inspection?.guid?.let { viewModel.getGitList(it) }
|
}
|
|
private fun initUI() {
|
tv_title.text = "技防措施"
|
|
rv_photo_list.run {
|
layoutManager = LinearLayoutManager(this@MenuNewGitActivity)
|
adapter = GitListAdapter(this@MenuNewGitActivity, viewModel.gitList.value)
|
addOnItemTouchListener(RecyclerItemClickListener(this@MenuNewGitActivity, this, object : RecyclerItemClickListener.OnItemClickListener {
|
override fun onItemClick(view: View?, position: Int) {
|
val intent = Intent(this@MenuNewGitActivity, GitDetailActivity::class.java)
|
intent.putExtra("gitlistVo", viewModel.gitList.value?.get(position))
|
intent.putExtra("subTask", subTask)
|
intent.putExtra("inspectionGuid", inspection?.guid)
|
intent.putExtra("scenseAddress", "${scene?.cityname ?: ""}${scene?.districtname?:""}${scene?.townname?:""}${scene?.location?:""}")
|
startActivity(intent)
|
}
|
|
override fun onItemLongClick(view: View?, position: Int) {
|
}
|
|
}))
|
}
|
|
iv_new_photo.setOnClickListener{
|
showNewGitDialog()
|
}
|
|
fab_problem_list_close.setOnClickListener {
|
finish()
|
}
|
}
|
|
//新增一条技防措施的dialog
|
private fun showNewGitDialog() {
|
val dialog = Dialog(this)
|
dialog.setContentView(R.layout.dialog_take_evidence)
|
//设置dialog宽度
|
val dialogWindow = dialog.window
|
dialogWindow!!.setBackgroundDrawableResource(android.R.color.transparent)
|
val p = dialogWindow.attributes
|
p.width = ScreenUtils.getScreenWidth(this) * 1
|
|
dialog.setCancelable(false)
|
//初始化控件
|
val tv_title = dialog.findViewById(R.id.tv_dialog_take_evidence_title) as TextView
|
val tv_type = dialog.findViewById(R.id.tv_type) as TextView
|
val tv_chose = dialog.findViewById(R.id.tv_chose) as TextView
|
val tv_location = dialog.findViewById(R.id.tv_location) as TextView
|
val fab_ok = dialog.findViewById(R.id.fab_take_evidence_ok) as FloatingActionButton
|
val fab_Close = dialog.findViewById(R.id.fab_take_evidence_close) as FloatingActionButton
|
val iv_gitPhoto1 = dialog.findViewById(R.id.iv_take_evidence_add_photo1) as ImageView
|
val iv_gitPhoto2 = dialog.findViewById(R.id.iv_take_evidence_add_photo2) as ImageView
|
val iv_gitPhoto3 = dialog.findViewById(R.id.iv_take_evidence_add_photo3) as ImageView
|
val sp_gitType = dialog.findViewById(R.id.sp_take_evidence_select_problem_type) as Spinner
|
val sp_git = dialog.findViewById(R.id.sp_take_evidence_select_problem) as Spinner
|
val sp_location = dialog.findViewById(R.id.sp_take_evidence_select_location) as Spinner
|
val et_locationRemark = dialog.findViewById(R.id.et_take_evidence_location) as EditText
|
val et_problemDes = dialog.findViewById(R.id.et_take_evidence_problem_des) as EditText
|
val ll_change_suggestion = dialog.findViewById<LinearLayout>(R.id.ll_change_suggestion)
|
|
imageViewList.apply {
|
pathTempList.clear()
|
clear()
|
add(iv_gitPhoto1)
|
add(iv_gitPhoto2)
|
add(iv_gitPhoto3)
|
refreshImageView()
|
}
|
|
//设置界面
|
tv_title.text = "新增技防措施"
|
tv_type.text = "措施类型"
|
tv_chose.text = "选择一个技防措施"
|
tv_location.visibility = View.GONE
|
sp_location.visibility = View.GONE
|
et_locationRemark.visibility = View.GONE
|
et_problemDes.visibility = View.GONE
|
ll_change_suggestion.visibility = View.GONE
|
//加载预置数据
|
val gittypeList = DbFactory.getInstance().gittypeDao.queryBuilder()
|
.where(
|
GittypeDao.Properties.Tasktype.eq(subTask?.type ?: ""),
|
GittypeDao.Properties.Scensetype.eq(scene?.type ?: ""),
|
GittypeDao.Properties.Districtname.eq(subTask?.districtname ?: "")
|
).orderAsc(GittypeDao.Properties.Typeid).list()
|
if (gittypeList.size == 0) {
|
val gittype1 = Gittype()
|
gittype1.guid = "00"
|
gittype1.name = "无"
|
gittype1.type = "无"
|
gittype1.desc = "无"
|
gittypeList.add(gittype1)
|
}
|
|
val gitTypeStringList = ArrayList<String>()
|
val gitTypeMap = HashMap<String, ArrayList<Gittype>>()
|
for (gittype in gittypeList) {
|
if (gitTypeMap.containsKey(gittype.getType())) {
|
gitTypeMap[gittype.type]!!.add(gittype)
|
} else {
|
gitTypeStringList.add(gittype.type)
|
val gittypeList1 = ArrayList<Gittype>()
|
gittypeList1.add(gittype)
|
gitTypeMap[gittype.type] = gittypeList1
|
}
|
}
|
val gittypeAdapter = ArrayAdapter(this, R.layout.item_spinner_drop_down, gitTypeStringList)
|
sp_gitType.adapter = gittypeAdapter
|
val gittypeList1 = ArrayList<Gittype>()
|
val gitTypeListAdapter = GitTypeListAdapter(gittypeList1, this)
|
sp_git.adapter = gitTypeListAdapter
|
sp_gitType.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
override fun onItemSelected(adapterView: AdapterView<*>, view: View, i: Int, l: Long) {
|
//当选中一个分类时,从map加载问题列表,填充数据
|
gittypeList1.removeAll(gittypeList1)
|
gittypeList1.addAll(gitTypeMap[gitTypeStringList[i]]!!)
|
gitTypeListAdapter.notifyDataSetChanged()
|
}
|
|
override fun onNothingSelected(adapterView: AdapterView<*>) {
|
|
}
|
}
|
|
|
fab_ok.setOnClickListener {
|
if (pathTempList.size > 0) {
|
//准备gitlist
|
val gitlist = Gitlist()
|
gitlist.guid = UUIDGenerator.generate16ShortUUID()
|
gitlist.iguid = inspection?.guid
|
gitlist.stguid = subTask?.stguid
|
gitlist.sguid = scene?.guid
|
gitlist.scensename = scene?.name
|
gitlist.scenseaddress = "${scene?.cityname ?: ""} + ${scene?.districtname?:""} + ${scene?.townname?:""} + ${scene?.location?:""}"
|
val gitSelected = sp_git.selectedItem as Gittype
|
gitlist.gtguid = gitSelected.guid
|
gitlist.name = gitSelected.name
|
gitlist.type = gitSelected.type
|
gitlist.desc = gitSelected.desc
|
gitlist.createdate = Date()
|
gitlist.updatedate = Date()
|
//准备mediaFIle
|
val calendar = java.util.Calendar.getInstance()
|
calendar.time = subTask?.executionstarttime
|
val path = "FlightFeather/Photo/" + scene?.districtname + "/" + calendar.get(Calendar.YEAR) + "年" + (calendar.get(Calendar.MONTH) + 1) + "月/" + (calendar.get(Calendar.MONTH) + 1) + "月" + calendar.get(Calendar.DAY_OF_MONTH) + "日/" + scene?.name + "/技防措施/"
|
|
val putGit = RetrofitFactory.instance.retrofit.create(InspectionService::class.java).putGitList(gitlist)
|
putGit.enqueue(object : Callback<ResponseBody> {
|
override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
|
if (response.body() != null) {
|
Toast.makeText(application, "提交成功", Toast.LENGTH_SHORT).show()
|
for (l in pathTempList) {
|
val oldfile = l.first
|
val fileName = gitSelected.name + " " + UUIDGenerator.generateUUID(4) + ".jpg"
|
val mediafile = Mediafile()
|
mediafile.guid = UUIDGenerator.generate16ShortUUID()
|
mediafile.businessguid = gitlist.guid
|
mediafile.iguid = inspection?.guid
|
mediafile.longitude = lng
|
mediafile.latitude = lat
|
mediafile.address = "${scene?.cityname ?: ""} + ${scene?.districtname?:""} + ${scene?.townname?:""} + ${scene?.location?:""}"
|
mediafile.filetype = 1
|
mediafile.businesstype = "2"
|
mediafile.businesstype = "技防措施"
|
mediafile.path = path
|
mediafile.description = fileName
|
mediafile.savetime = Date()
|
val exetension1 = scene?.getCitycode() + "/" + scene?.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.time) + "/" + scene?.getGuid() + "/"
|
mediafile.extension1 = exetension1
|
mediafile.remark = "未上传"
|
try {
|
val newfile = File(Environment.getExternalStorageDirectory(), path + fileName)
|
newfile.parentFile.mkdirs()
|
FileUtil.copyFile(oldfile, newfile)
|
|
viewModel.putMediaFile(mediafile)
|
} catch (e: IOException) {
|
e.printStackTrace()
|
}
|
|
}
|
dialog.dismiss()
|
inspection?.guid?.let { viewModel.getGitList(it) }
|
} else if (response.errorBody() != null) {
|
Log.e("putGit:", response.errorBody()!!.toString())
|
Toast.makeText(application, "提交失败", Toast.LENGTH_SHORT).show()
|
}
|
}
|
|
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
|
Log.e("putGit:", t.toString())
|
Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show()
|
}
|
})
|
|
} else {
|
Toast.makeText(application, "至少拍一张照片", Toast.LENGTH_SHORT).show()
|
}
|
}
|
fab_Close.setOnClickListener { dialog.dismiss() }
|
dialog.show()
|
}
|
}
|