Browse Source

feat 上传图片

lihao1 3 years ago
parent
commit
7f413a59b9

+ 2 - 0
demo/src/main/java/com/framework/app/Constants.kt

@@ -13,6 +13,8 @@ const val JdIP = "http://www.ysbdtp.com/adm-poc-backend/"
 
 const val IP = JdIP
 
+const val REVIT_IP = "http://www.ysbdtp.com/image-service/common/file_get?systemId=revit&key="
+
 const val devFileServiceUrl = "http://develop.persagy.com/image-service/"
 
 const val fileServiceUrl = devFileServiceUrl

+ 2 - 1
demo/src/main/java/com/framework/app/http/FileUpload.kt

@@ -7,7 +7,8 @@ data class FileInfo(
     val fileMd5: String,            // 文件MD5
     val fileName: String,           // 文件名
     val fileBucket: String = "adm", // 目前固定"adm"
-    val fileSize: Int               // 文件大小
+    val fileSize: Int,              // 文件大小
+    val fileId: String               // 文件key
 )
 
 /**

+ 6 - 6
demo/src/main/java/com/framework/mvvm/mv/AdmViewModel.kt

@@ -176,7 +176,7 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
                         val json = it.infos?.asJsonObject
                         val floorMap = json?.get("floorMap")?.asString ?: ""
                         if (floorMap.isNotEmpty()) {
-                            val mapString = OkhttpUtil.getGzipMap("$IP$pathDownloadMap${floorMap}")
+                            val mapString = OkhttpUtil.getGzipMap("$REVIT_IP${floorMap}")
                             val mapFile =
                                 File(DemoApp.getInstance()?.getExternalFilesDir("floorMap"), it.id)
                             FileOutputStream(mapFile).use { output -> output.write(mapString.toByteArray()) }
@@ -239,7 +239,8 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
         val info = FileInfo(
             fileMd5 = md5,
             fileName = file.name,
-            fileSize = bytes.size
+            fileSize = bytes.size,
+            fileId = file.name,
         )
 
         viewModelScope.launch(Dispatchers.IO) {
@@ -252,10 +253,9 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
                     val result = uploadFile(url, body)
 
                     Log.d("fileUpload", "success: $result")
-                    if ("success" == result) {
-                        //不管是那种情况,只要成功都需要从本地删除该图片¬
-                        file.renameTo(File(LocalDataOperation.getInstance().getOfflineImageFilePath(DemoApp.mContext) + File.separator + "uploaded" + file.name))
-                    }
+
+                    //不管是那种情况,只要成功都需要从本地删除该图片¬
+                    file.renameTo(File(LocalDataOperation.getInstance().getOfflineImageFilePath(DemoApp.mContext) + File.separator + "uploaded" + file.name))
                 }
             } else {
                 Log.d("fileUpload", "upload file has something error:$response")

+ 18 - 51
demo/src/main/java/com/sybotan/android/demo/activities/EquipDetailActivity.kt

@@ -710,60 +710,27 @@ class EquipDetailActivity : BaseActivity(), View.OnTouchListener {
                         val picFile = File(path)
                         if (picFile.exists()) {
                             val key = picFile.name
-                            if (isHaveInternet()) {
-                                val url: String = Constant.ServerImgIPUp + key
-                                val str = UploadImage.uploadFiles(picFile, url)
-                                if (!TextUtils.isEmpty(str)) {
-                                    var resultString: String? = null
-                                    try {
-                                        val `object` = JSONObject(str)
-                                        resultString = `object`.getString("Result")
-                                    } catch (e: JSONException) {
-                                        e.printStackTrace()
-                                    }
-                                    if ("success" == resultString) {
-                                        val photos = Photos()
-                                        photos.itemType = 0
-                                        photos.path = path
-                                        photos.key = key
-                                        if (info == null) {
-                                            beans.add(photos)
-                                        } else {
-                                            val photosList = ArrayList<Photos>()
-                                            if (staticInfoAdapter.hashMap[info!!.code] != null) {
-                                                val value = Gson().fromJson<ArrayList<Photos>>(
-                                                    Gson().toJson(staticInfoAdapter.hashMap[info!!.code]), object : TypeToken<List<Photos?>?>() {}.type
-                                                )
-                                                photosList.addAll(value)
-                                            }
-                                            photosList.add(photos)
-                                            staticInfoAdapter.hashMap.put(info!!.code, photosList)
-                                            staticInfoAdapter.valueList.remove(info?.code)
-                                            runOnUiThread { staticInfoAdapter.notifyItemChanged(currentPosition!!) }
-                                        }
-                                    }
-                                }
+
+                            val photos = Photos()
+                            photos.itemType = 0
+                            photos.path = path
+                            photos.key = key
+                            if (info == null) {
+                                beans.add(photos)
                             } else {
-                                val photos = Photos()
-                                photos.itemType = 0
-                                photos.path = path
-                                photos.key = key
-                                if (info == null) {
-                                    beans.add(photos)
-                                } else {
-                                    val photosList = ArrayList<Photos>()
-                                    if (staticInfoAdapter.hashMap[info!!.code] != null) {
-                                        val value = Gson().fromJson<ArrayList<Photos>>(
-                                            staticInfoAdapter.hashMap[info!!.code] as String, object : TypeToken<List<Photos?>?>() {}.type
-                                        )
-                                        photosList.addAll(value)
-                                    }
-                                    photosList.add(photos)
-                                    staticInfoAdapter.hashMap.put(info!!.code, photosList)
-                                    staticInfoAdapter.valueList.remove(info?.code)
-                                    runOnUiThread { staticInfoAdapter.notifyItemChanged(currentPosition!!) }
+                                val photosList = ArrayList<Photos>()
+                                if (staticInfoAdapter.hashMap[info!!.code] != null) {
+                                    val value = Gson().fromJson<ArrayList<Photos>>(
+                                        staticInfoAdapter.hashMap[info!!.code] as String, object : TypeToken<List<Photos?>?>() {}.type
+                                    )
+                                    photosList.addAll(value)
                                 }
+                                photosList.add(photos)
+                                staticInfoAdapter.hashMap.put(info!!.code, photosList)
+                                staticInfoAdapter.valueList.remove(info?.code)
+                                runOnUiThread { staticInfoAdapter.notifyItemChanged(currentPosition!!) }
                             }
+
                         }
                     }
                     emitter.onNext("")