Эх сурвалжийг харах

Solve new lint warnings with AGP 7.3.0

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 жил өмнө
parent
commit
07aedfd888

+ 19 - 19
app/src/main/java/com/owncloud/android/utils/FileExportUtils.kt

@@ -22,6 +22,7 @@
 
 package com.owncloud.android.utils
 
+import android.annotation.SuppressLint
 import android.content.ContentResolver
 import android.content.ContentValues
 import android.os.Build
@@ -64,6 +65,7 @@ class FileExportUtils {
         }
     }
 
+    @SuppressLint("Recycle") // handled inside copy method
     @RequiresApi(Build.VERSION_CODES.Q)
     private fun exportFileAndroid10AndAbove(
         fileName: String,
@@ -139,30 +141,28 @@ class FileExportUtils {
 
     @Throws(IllegalStateException::class)
     private fun copy(ocFile: OCFile?, file: File?, contentResolver: ContentResolver, outputStream: FileOutputStream) {
-        try {
-            val inputStream = if (ocFile != null) {
-                contentResolver.openInputStream(ocFile.storageUri)
-            } else if (file != null) {
-                FileInputStream(file)
-            } else {
-                error("ocFile and file both may not be null")
+        outputStream.use { fos ->
+            try {
+                val inputStream = when {
+                    ocFile != null -> contentResolver.openInputStream(ocFile.storageUri)
+                    file != null -> FileInputStream(file)
+                    else -> error("ocFile and file both may not be null")
+                }!!
+
+                inputStream.use { fis ->
+                    copyStream(fis, fos)
+                }
+            } catch (e: IOException) {
+                Log_OC.e(this, "Cannot write file", e)
             }
-
-            copyStream(inputStream!!, outputStream)
-        } catch (e: IOException) {
-            Log_OC.e(this, "Cannot write file", e)
         }
     }
 
     private fun copyStream(inputStream: InputStream, outputStream: FileOutputStream) {
-        inputStream.use { input ->
-            outputStream.use { output ->
-                val buffer = ByteArray(COPY_BUFFER_SIZE)
-                var len: Int
-                while (input.read(buffer).also { len = it } != -1) {
-                    output.write(buffer, 0, len)
-                }
-            }
+        val buffer = ByteArray(COPY_BUFFER_SIZE)
+        var len: Int
+        while (inputStream.read(buffer).also { len = it } != -1) {
+            outputStream.write(buffer, 0, len)
         }
     }
 

+ 1 - 3
app/src/main/java/com/owncloud/android/utils/svg/SvgSoftwareLayerSetter.java

@@ -10,7 +10,6 @@
  */
 package com.owncloud.android.utils.svg;
 
-import android.annotation.TargetApi;
 import android.graphics.drawable.PictureDrawable;
 import android.os.Build;
 import android.widget.ImageView;
@@ -19,7 +18,6 @@ import com.bumptech.glide.request.RequestListener;
 import com.bumptech.glide.request.target.ImageViewTarget;
 import com.bumptech.glide.request.target.Target;
 
-@TargetApi(Build.VERSION_CODES.HONEYCOMB)
 public class SvgSoftwareLayerSetter<T> implements RequestListener<T, PictureDrawable> {
 
     @Override
@@ -40,4 +38,4 @@ public class SvgSoftwareLayerSetter<T> implements RequestListener<T, PictureDraw
         }
         return false;
     }
-}
+}