Browse Source

2024-09-02 新增 / 修改

修改:
1. 公务出访 优化图片选择逻辑 不再打开系统文件管理器而是系统相册
2. 邀请资料 界面修改
3. Android 权限修改
zhaiy 7 months ago
parent
commit
a0b6452d73

+ 3 - 3
app/src/main/AndroidManifest.xml

@@ -14,11 +14,11 @@
     <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
     <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
     <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
+
+    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:ignore="ScopedStorage"/>
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
     <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
     <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
     <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
     <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
-    <uses-permission
-        android:name="android.permission.READ_EXTERNAL_STORAGE"
-        android:maxSdkVersion="32" />
 
 
     <application
     <application
         android:name=".OASystem"
         android:name=".OASystem"

+ 85 - 63
app/src/main/java/com/pan_american/android/ui/group_invite_official/official_visits/AddOfficialVisitsActivity.kt

@@ -1,13 +1,11 @@
 package com.pan_american.android.ui.group_invite_official.official_visits
 package com.pan_american.android.ui.group_invite_official.official_visits
 
 
 import android.Manifest
 import android.Manifest
-import android.content.ContentResolver
+import android.content.Intent
 import android.content.pm.PackageManager
 import android.content.pm.PackageManager
 import android.net.Uri
 import android.net.Uri
 import android.os.Build
 import android.os.Build
 import android.os.Bundle
 import android.os.Bundle
-import android.os.Environment
-import android.provider.DocumentsContract
 import android.provider.MediaStore
 import android.provider.MediaStore
 import android.text.Editable
 import android.text.Editable
 import android.text.TextWatcher
 import android.text.TextWatcher
@@ -18,6 +16,7 @@ import android.widget.EditText
 import android.widget.LinearLayout
 import android.widget.LinearLayout
 import android.widget.PopupWindow
 import android.widget.PopupWindow
 import android.widget.TextView
 import android.widget.TextView
+import androidx.activity.result.ActivityResultCallback
 import androidx.activity.result.ActivityResultLauncher
 import androidx.activity.result.ActivityResultLauncher
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.appcompat.widget.AppCompatImageView
 import androidx.appcompat.widget.AppCompatImageView
@@ -61,6 +60,7 @@ import retrofit2.Callback
 import retrofit2.Response
 import retrofit2.Response
 import java.io.File
 import java.io.File
 
 
+
 class AddOfficialVisitsActivity : BaseActivity<ActivityAddOfficialVisitsBinding>() {
 class AddOfficialVisitsActivity : BaseActivity<ActivityAddOfficialVisitsBinding>() {
 
 
     private var fromList = false
     private var fromList = false
@@ -81,7 +81,7 @@ class AddOfficialVisitsActivity : BaseActivity<ActivityAddOfficialVisitsBinding>
 
 
     private val officialTypeList = ArrayList<Selector>()
     private val officialTypeList = ArrayList<Selector>()
 
 
-    private val officialAttributeList = ArrayList<Selector>()
+//    private val officialAttributeList = ArrayList<Selector>()
 
 
     private val photoList = ArrayList<PictureListItem>()
     private val photoList = ArrayList<PictureListItem>()
 
 
@@ -89,14 +89,14 @@ class AddOfficialVisitsActivity : BaseActivity<ActivityAddOfficialVisitsBinding>
 
 
     private var officialTypeId = 0
     private var officialTypeId = 0
 
 
-    private var officialAttributeId = 0
+//    private var officialAttributeId = 0
 
 
     private var checkCommitType = 0
     private var checkCommitType = 0
 
 
     private val updateOfficialVisitRequest = UpdateOfficialVisitRequest()
     private val updateOfficialVisitRequest = UpdateOfficialVisitRequest()
 
 
     //监听相册事件回调
     //监听相册事件回调
-    private lateinit var result: ActivityResultLauncher<String>
+    private lateinit var result: ActivityResultLauncher<Intent>
 
 
     override fun getViewBinding() = ActivityAddOfficialVisitsBinding.inflate(layoutInflater)
     override fun getViewBinding() = ActivityAddOfficialVisitsBinding.inflate(layoutInflater)
 
 
@@ -119,23 +119,30 @@ class AddOfficialVisitsActivity : BaseActivity<ActivityAddOfficialVisitsBinding>
             pageSize = 10
             pageSize = 10
         }
         }
 
 
-        result = registerForActivityResult(ActivityResultContracts.GetContent()) {
-            if (it != null) {
+        result = registerForActivityResult(
+            ActivityResultContracts.StartActivityForResult(),
+            ActivityResultCallback { result ->
+                if (result.resultCode == RESULT_OK) {
+                    val data: Intent? = result.data
+                    if (data != null) {
+                        val selectedImageUri = data.data
+                        if (selectedImageUri != null) {
+                            photoList.add(PictureListItem().apply {
+                                picName = File(uri2Path(selectedImageUri)).name
+
+                                if (picName.isBlank()) {
+                                    showMessage(resources.getString(R.string.picture_select_error_hint))
+                                    return@ActivityResultCallback
+                                }
 
 
-                photoList.add(PictureListItem().apply {
-                    picName = uri2Path(it).substringAfterLast("/")
+                                uri = selectedImageUri
+                            })
 
 
-                    if (picName.isBlank()) {
-                        showMessage(resources.getString(R.string.picture_select_error_hint))
-                        return@registerForActivityResult
+                            initPictureList()
+                        }
                     }
                     }
-
-                    uri = it
-                })
-
-                initPictureList()
-            }
-        }
+                }
+            })
 
 
         initTitle()
         initTitle()
         getSelectDataSource()
         getSelectDataSource()
@@ -880,7 +887,9 @@ class AddOfficialVisitsActivity : BaseActivity<ActivityAddOfficialVisitsBinding>
     }
     }
 
 
     private fun openGallery() {
     private fun openGallery() {
-        result.launch("image/*")
+        val intent = Intent(Intent.ACTION_PICK)
+        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*")
+        result.launch(intent)
     }
     }
 
 
     private fun initPictureList() {
     private fun initPictureList() {
@@ -968,49 +977,62 @@ class AddOfficialVisitsActivity : BaseActivity<ActivityAddOfficialVisitsBinding>
         }
         }
     }
     }
 
 
-    private fun uri2Path(uri: Uri?): String {
-        if (uri == null) {
-            return ""
-        }
-        if (ContentResolver.SCHEME_FILE == uri.scheme) {
-            return uri.path.toString()
-        } else if (ContentResolver.SCHEME_CONTENT == uri.scheme) {
-            val authority = uri.authority
-            if (authority!!.startsWith("com.android.externalstorage")) {
-                return Environment.getExternalStorageDirectory()
-                    .toString() + "/" + uri.path!!.split(":".toRegex())
-                    .dropLastWhile { it.isEmpty() }
-                    .toTypedArray()[1]
-            } else {
-                var idStr = ""
-                if (authority == "media") {
-                    idStr = uri.toString().substring(uri.toString().lastIndexOf('/') + 1)
-                } else if (authority.startsWith("com.android.providers")) {
-                    idStr = DocumentsContract.getDocumentId(uri).split(":".toRegex())
-                        .dropLastWhile { it.isEmpty() }
-                        .toTypedArray()[1]
-                }
-                val contentResolver = OASystem.context.contentResolver
-                val cursor = contentResolver.query(
-                    MediaStore.Files.getContentUri("external"),
-                    arrayOf(MediaStore.Files.FileColumns.DATA),
-                    "_id=?",
-                    arrayOf(idStr),
-                    null
-                )
-                if (cursor != null) {
-                    cursor.moveToFirst()
-                    try {
-                        val idx = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)
-                        return cursor.getString(idx)
-                    } catch (_: Exception) {
-                    } finally {
-                        cursor.close()
-                    }
-                }
-            }
+//    private fun uri2Path(uri: Uri?): String {
+//        if (uri == null) {
+//            return ""
+//        }
+//        if (ContentResolver.SCHEME_FILE == uri.scheme) {
+//            return uri.path.toString()
+//        } else if (ContentResolver.SCHEME_CONTENT == uri.scheme) {
+//            val authority = uri.authority
+//            if (authority!!.startsWith("com.android.externalstorage")) {
+//                return Environment.getExternalStorageDirectory()
+//                    .toString() + "/" + uri.path!!.split(":".toRegex())
+//                    .dropLastWhile { it.isEmpty() }
+//                    .toTypedArray()[1]
+//            } else {
+//                var idStr = ""
+//                if (authority == "media") {
+//                    idStr = uri.toString().substring(uri.toString().lastIndexOf('/') + 1)
+//                } else if (authority.startsWith("com.android.providers")) {
+//                    idStr = DocumentsContract.getDocumentId(uri).split(":".toRegex())
+//                        .dropLastWhile { it.isEmpty() }
+//                        .toTypedArray()[1]
+//                }
+//                val contentResolver = OASystem.context.contentResolver
+//                val cursor = contentResolver.query(
+//                    MediaStore.Files.getContentUri("external"),
+//                    arrayOf(MediaStore.Files.FileColumns.DATA),
+//                    "_id=?",
+//                    arrayOf(idStr),
+//                    null
+//                )
+//                if (cursor != null) {
+//                    cursor.moveToFirst()
+//                    try {
+//                        val idx = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)
+//                        return cursor.getString(idx)
+//                    } catch (_: Exception) {
+//                    } finally {
+//                        cursor.close()
+//                    }
+//                }
+//            }
+//        }
+//        return ""
+//    }
+
+    private fun uri2Path(uri: Uri): String {
+        var filePath = ""
+        val projection = arrayOf(MediaStore.Images.Media.DATA)
+        val cursor = contentResolver.query(uri, projection, null, null, null)!!
+        if (cursor.moveToFirst()) {
+            val columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
+            filePath = cursor.getString(columnIndex)
+            cursor.close()
         }
         }
-        return ""
+
+        return filePath
     }
     }
 
 
     private fun updateOfficialVisitData() {
     private fun updateOfficialVisitData() {

+ 48 - 1
app/src/main/res/layout/activity_add_invite_data.xml

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
     android:orientation="vertical">
@@ -617,6 +616,54 @@
                 android:layout_width="match_parent"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content" />
                 android:layout_height="wrap_content" />
 
 
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/line"
+                android:layout_marginTop="@dimen/common_padding"
+                android:layout_marginBottom="@dimen/common_padding"
+                android:background="@color/line_color" />
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/common_padding"
+                android:layout_marginBottom="@dimen/common_padding"
+                android:orientation="horizontal">
+
+                <TextView
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:layout_weight="1"
+                    android:text="@string/invite_data_document"
+                    android:textSize="@dimen/text_size_medium" />
+
+                <TextView
+                    android:id="@+id/upload"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginStart="@dimen/common_padding"
+                    android:background="@drawable/shape_corner_solid_blue"
+                    android:gravity="end"
+                    android:padding="@dimen/common_padding_small"
+                    android:text="@string/select_annex"
+                    android:textColor="@color/white"
+                    android:textSize="@dimen/text_size_medium" />
+
+            </LinearLayout>
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/invite_data_file_list"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/line"
+                android:layout_marginTop="@dimen/common_padding"
+                android:layout_marginBottom="@dimen/common_padding"
+                android:background="@color/line_color" />
+
             <LinearLayout
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_height="wrap_content"

+ 5 - 1
app/src/main/res/values/strings.xml

@@ -902,7 +902,11 @@
     <string name="face_book">FaceBook</string>
     <string name="face_book">FaceBook</string>
     <string name="instagram">Instagram</string>
     <string name="instagram">Instagram</string>
     <string name="association_group">关联团组</string>
     <string name="association_group">关联团组</string>
-
+    
+    <string name="invite_data_document">邀请函文件</string>
+    <string name="download_original_invite_data">下载原版文件</string>
+    <string name="file_name">文件名称</string>
+    
     <string name="association_group_selected_hint">该团组已选择,请勿重复选择</string>
     <string name="association_group_selected_hint">该团组已选择,请勿重复选择</string>
     <string name="invitee_country_input_hint">请输入邀请方国家</string>
     <string name="invitee_country_input_hint">请输入邀请方国家</string>
     <string name="invitee_city_input_hint">请输入邀请方城市</string>
     <string name="invitee_city_input_hint">请输入邀请方城市</string>