PocActivity.kt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package com.sybotan.android.demo.activities
  2. import android.Manifest
  3. import android.content.SharedPreferences
  4. import android.content.pm.PackageManager
  5. import android.os.Bundle
  6. import android.widget.Button
  7. import androidx.appcompat.app.AppCompatActivity
  8. import androidx.constraintlayout.widget.ConstraintLayout
  9. import androidx.core.app.ActivityCompat
  10. import androidx.core.content.edit
  11. import com.framework.app.tools.MacUtil
  12. import com.framework.mvvm.model.vo.AdmRequest
  13. import com.framework.mvvm.mv.AdmViewModel
  14. import com.sybotan.android.demo.R
  15. import com.sybotan.android.demo.activities.poc.SceneActivity
  16. import com.sybotan.android.demo.activities.poc.SpaceActivity
  17. import com.sybotan.android.demo.tools.ToastUtils
  18. import com.sybotan.android.demo.tools.LocalDataOperation
  19. import org.jetbrains.anko.startActivity
  20. import org.kodein.di.DI
  21. import org.kodein.di.DIAware
  22. import org.kodein.di.android.closestDI
  23. import org.kodein.di.android.x.viewmodel.viewModel
  24. import org.kodein.di.instance
  25. class PocActivity : AppCompatActivity(), DIAware {
  26. override val di: DI by closestDI()
  27. private val mVm: AdmViewModel by viewModel()
  28. private val sp: SharedPreferences by instance()
  29. private val REQUEST_EXTERNAL_STORAGE = 1 // 不可改
  30. private lateinit var downloadBtn: Button
  31. private lateinit var uploadBtn: Button
  32. override fun onCreate(savedInstanceState: Bundle?) {
  33. super.onCreate(savedInstanceState)
  34. setContentView(R.layout.activity_poc)
  35. checkStoragePermission()
  36. LocalDataOperation.getInstance().offlineSendRequest.uploadImageNew(this)
  37. downloadBtn = findViewById(R.id.downloadBtn)
  38. uploadBtn = findViewById(R.id.uploadBtn)
  39. downloadBtn.setOnClickListener {
  40. mVm.downloadBuilding(sp) {
  41. ToastUtils.showMyToast("下载建筑数据完成")
  42. }
  43. }
  44. uploadBtn.setOnClickListener {
  45. mVm.uploadBuilding {
  46. ToastUtils.showMyToast("建筑数据上传成功")
  47. }
  48. }
  49. val spaceCL = findViewById<ConstraintLayout>(R.id.spaceCL)
  50. spaceCL.setOnClickListener {
  51. startActivity<SpaceActivity>()
  52. }
  53. val sceneCL = findViewById<ConstraintLayout>(R.id.sceneCL)
  54. sceneCL.setOnClickListener {
  55. startActivity<SceneActivity>()
  56. }
  57. mVm.requestFrame(
  58. AdmRequest(
  59. userId = "bdtp",
  60. projectId = "Pj0002220011",
  61. groupCode = "BR"
  62. )
  63. )
  64. mVm.requestDict(
  65. AdmRequest(
  66. userId = "bdtp",
  67. projectId = "Pj000222001",
  68. groupCode = "BR"
  69. )
  70. )
  71. // mVm.requestBuilding(
  72. // AdmRequest(
  73. // userId = "bdtp",
  74. // projectId = "Pj0002220011",
  75. // groupCode = "BR",
  76. // buildingId = "Bd0002220002bcaa181bd406439c9ecaddac13b0d543"
  77. // )
  78. // )
  79. }
  80. private fun checkStoragePermission() {
  81. // ActivityCompat.requestPermissions(
  82. // this, arrayOf(
  83. // Manifest.permission.READ_EXTERNAL_STORAGE,
  84. // Manifest.permission.WRITE_EXTERNAL_STORAGE
  85. // ),
  86. // REQUEST_EXTERNAL_STORAGE
  87. // )
  88. if (ActivityCompat.checkSelfPermission(
  89. this,
  90. Manifest.permission.WRITE_EXTERNAL_STORAGE
  91. ) != PackageManager.PERMISSION_GRANTED
  92. ) {
  93. ActivityCompat.requestPermissions(
  94. this,
  95. arrayOf(
  96. Manifest.permission.WRITE_EXTERNAL_STORAGE,
  97. Manifest.permission.READ_PHONE_STATE
  98. ),
  99. 1
  100. )
  101. }
  102. }
  103. override fun onRequestPermissionsResult(
  104. requestCode: Int,
  105. permissions: Array<out String>,
  106. grantResults: IntArray
  107. ) {
  108. super.onRequestPermissionsResult(requestCode, permissions, grantResults)
  109. if (requestCode == 1) {
  110. val mac = MacUtil.getMacAddress(this)!!
  111. println("deviceId: $mac")
  112. sp.edit {
  113. putString("deviceId", mac)
  114. }
  115. }
  116. }
  117. }