From 8196b06b34d9fd6817ea0521ac8a78a55fcf5288 Mon Sep 17 00:00:00 2001 From: Jerry Jeon Date: Fri, 8 Sep 2023 16:27:46 +0900 Subject: [PATCH] Updated SDK version to 33 --- build.gradle | 6 +- commonmodule/build.gradle | 3 +- .../chat/module/ui/base/BaseSplashActivity.kt | 15 ++-- .../module/ui/base/BaseUserInfoActivity.kt | 41 ++--------- .../sendbird/chat/module/utils/Constants.kt | 5 -- .../sendbird/chat/module/utils/FileUtils.kt | 59 ---------------- gradle/wrapper/gradle-wrapper.properties | 4 +- .../build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-admin-message/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 43 +++--------- groupchannel-ban-unban-user/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- .../build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-basic/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-categorize-channels/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-categorize-message/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-dnd-snooze/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-encryptedfiles/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- .../build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-freeze-unfreeze/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-friends/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-hide-archive/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-local-caching/build.gradle | 4 +- .../groupchannel/GroupChannelChatActivity.kt | 69 +++++-------------- .../groupchannel/GroupChannelChatAdapter.kt | 11 ++- groupchannel-mark-message-read/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-membersandoperators/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-mention-members/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-mute-user/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-nickname/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-ogt/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-onlinemembers/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-operators/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-pinnedmessage/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-polls/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-profile-image/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-push-notifications/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-push-translations/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-reactions/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-readmessage/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- .../build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-scheduled-message/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-threading/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-type/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-typingindicator/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-unreadmessages/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-unreceivedmessage/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- .../build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- groupchannel-user-online/build.gradle | 2 +- .../groupchannel/GroupChannelChatActivity.kt | 47 ++----------- openchannel-admin-message/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-basic/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-categorize-channels/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-categorize-messages/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-copy-message/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-delete-message/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-dnd-snooze/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-extra-data/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-freeze-unfreeze/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-friends/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-mention-user/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-metadata-metacounter/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-nickname/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-ogt/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-profile-image/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- .../build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-send-receive-files/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-structured-data/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-threading/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-thumbnails/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-update-message/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- openchannel-user-online/build.gradle | 2 +- .../ui/openchannel/OpenChannelChatActivity.kt | 48 ++----------- 128 files changed, 443 insertions(+), 2683 deletions(-) diff --git a/build.gradle b/build.gradle index 7c93b42a..2d91bbca 100644 --- a/build.gradle +++ b/build.gradle @@ -22,9 +22,9 @@ buildscript { } plugins { - id 'com.android.application' version '4.2.0' apply false - id 'com.android.library' version '4.2.0' apply false - id 'org.jetbrains.kotlin.android' version '1.6.21' apply false + id 'com.android.application' version '7.4.2' apply false + id 'com.android.library' version '7.4.2' apply false + id 'org.jetbrains.kotlin.android' version '1.8.10' apply false } task clean(type: Delete) { delete rootProject.buildDir diff --git a/commonmodule/build.gradle b/commonmodule/build.gradle index d651e9a6..e2423348 100644 --- a/commonmodule/build.gradle +++ b/commonmodule/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { minSdk 26 @@ -42,6 +42,7 @@ dependencies { implementation "androidx.appcompat:appcompat:$androidxAppcompatVersion" implementation "com.google.android.material:material:$googleMaterialVersion" implementation "androidx.constraintlayout:constraintlayout:$constraintlayoutVersion" + implementation "androidx.activity:activity:$androidxCoreKtxVersion" //sendbird implementation "com.sendbird.sdk:sendbird-chat:$sendbirdVersion" diff --git a/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseSplashActivity.kt b/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseSplashActivity.kt index ae4ee502..19fda689 100644 --- a/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseSplashActivity.kt +++ b/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseSplashActivity.kt @@ -33,15 +33,16 @@ class BaseSplashActivity : AppCompatActivity() { startActivity(intent) finish() } else { - SendbirdChat.connect(userId) { _, e -> - if (e != null) { - showToast("$e") + SendbirdChat.connect(userId) { user, e -> + if (user != null) { + val intent = Intent("$packageName.MAIN") + startActivity(intent) + } else { + if (e != null) { + showToast("$e") + } finish() - return@connect } - val intent = Intent("$packageName.MAIN") - startActivity(intent) - finish() } } } diff --git a/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseUserInfoActivity.kt b/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseUserInfoActivity.kt index f245f00b..fe56a580 100644 --- a/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseUserInfoActivity.kt +++ b/commonmodule/src/main/java/com/sendbird/chat/module/ui/base/BaseUserInfoActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.module.ui.base -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import com.sendbird.android.SendbirdChat @@ -20,14 +19,11 @@ class BaseUserInfoActivity : AppCompatActivity() { private var userNickname: String? = null private var profileUri: Uri? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - profileUri = uri - binding.circularImageviewProfile.setImageUri(uri) - } + profileUri = uri + binding.circularImageviewProfile.setImageUri(uri) } override fun onCreate(savedInstanceState: Bundle?) { @@ -47,7 +43,7 @@ class BaseUserInfoActivity : AppCompatActivity() { binding.circularImageviewEditProfile.setOnClickListener { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile(Constants.DATA_TYPE_ONLY_IMAGE, startForResult, this) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } binding.purpleButtonSave.setOnClickListener { val nickname = binding.tagEdittextNickname.getText() @@ -133,29 +129,4 @@ class BaseUserInfoActivity : AppCompatActivity() { else -> super.onOptionsItemSelected(item) } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile(Constants.DATA_TYPE_ONLY_IMAGE, startForResult, this) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } \ No newline at end of file diff --git a/commonmodule/src/main/java/com/sendbird/chat/module/utils/Constants.kt b/commonmodule/src/main/java/com/sendbird/chat/module/utils/Constants.kt index d8512523..816ba12f 100644 --- a/commonmodule/src/main/java/com/sendbird/chat/module/utils/Constants.kt +++ b/commonmodule/src/main/java/com/sendbird/chat/module/utils/Constants.kt @@ -12,9 +12,4 @@ object Constants { const val CHANNEL_HANDLER_ID = "channel_handler_id" const val CONNECTION_HANDLER_ID = "connection_handler_id" - - const val PERMISSION_REQUEST_CODE = 10001 - - const val DATA_TYPE_ONLY_IMAGE = "image/*" - const val DATA_TYPE_IMAGE_AND_VIDEO = "image/* video/*" } \ No newline at end of file diff --git a/commonmodule/src/main/java/com/sendbird/chat/module/utils/FileUtils.kt b/commonmodule/src/main/java/com/sendbird/chat/module/utils/FileUtils.kt index 709aa862..bdca8478 100644 --- a/commonmodule/src/main/java/com/sendbird/chat/module/utils/FileUtils.kt +++ b/commonmodule/src/main/java/com/sendbird/chat/module/utils/FileUtils.kt @@ -1,19 +1,11 @@ package com.sendbird.chat.module.utils -import android.Manifest -import android.app.Activity import android.content.ContentResolver import android.content.Context -import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri -import android.provider.MediaStore import android.provider.OpenableColumns import android.util.Log import android.webkit.MimeTypeMap -import androidx.activity.result.ActivityResultLauncher -import androidx.core.app.ActivityCompat.requestPermissions -import androidx.core.content.ContextCompat import java.io.File import java.io.FileDescriptor import java.io.FileInputStream @@ -22,57 +14,6 @@ import java.io.FileOutputStream object FileUtils { - fun selectFile( - type: String, - startForResult: ActivityResultLauncher, - context: Context - ) { - if (ContextCompat.checkSelfPermission( - context, - Manifest.permission.WRITE_EXTERNAL_STORAGE - ) != PackageManager.PERMISSION_GRANTED - ) { - requestStoragePermission(context) - } else { - val intent = Intent(Intent.ACTION_PICK) - intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, type) - startForResult.launch(intent) - } - } - - fun selectFile(startForResult: ActivityResultLauncher, context: Context) { - if (ContextCompat.checkSelfPermission( - context, - Manifest.permission.WRITE_EXTERNAL_STORAGE - ) != PackageManager.PERMISSION_GRANTED - ) { - requestStoragePermission(context) - } else { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.type = "*/*" - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true) - startForResult.launch(intent) - } - } - - private fun requestStoragePermission(context: Context) { - context.showAlertDialog( - "Permission", - "Storage access permissions are required to upload/download files.", - "Accept", - "Cancel", - { - requestPermissions( - context as Activity, - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - 10001 - ) - }, - {} - ) - } - data class FileResult(val file: File, val size: Int, val mime: String?, val name: String) fun getFileInfo(uri: Uri, context: Context): FileResult? { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7b74e622..15ced4b5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Feb 17 09:30:44 KST 2022 +#Thu Sep 07 16:17:09 KST 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/groupchannel-add-remove-operators/build.gradle b/groupchannel-add-remove-operators/build.gradle index 96e7e7f2..56c3e093 100644 --- a/groupchannel-add-remove-operators/build.gradle +++ b/groupchannel-add-remove-operators/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.addremoveoperators" diff --git a/groupchannel-add-remove-operators/src/main/java/com/sendbird/chat/sample/groupchannel/addremoveoperators/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-add-remove-operators/src/main/java/com/sendbird/chat/sample/groupchannel/addremoveoperators/ui/groupchannel/GroupChannelChatActivity.kt index ee694f5b..d5593696 100644 --- a/groupchannel-add-remove-operators/src/main/java/com/sendbird/chat/sample/groupchannel/addremoveoperators/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-add-remove-operators/src/main/java/com/sendbird/chat/sample/groupchannel/addremoveoperators/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.addremoveoperators.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-admin-message/build.gradle b/groupchannel-admin-message/build.gradle index c94c71d3..564feae7 100644 --- a/groupchannel-admin-message/build.gradle +++ b/groupchannel-admin-message/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.admin" diff --git a/groupchannel-admin-message/src/main/java/com/sendbird/chat/sample/groupchannel/admin/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-admin-message/src/main/java/com/sendbird/chat/sample/groupchannel/admin/ui/groupchannel/GroupChannelChatActivity.kt index b2aa5f13..a00eccaf 100644 --- a/groupchannel-admin-message/src/main/java/com/sendbird/chat/sample/groupchannel/admin/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-admin-message/src/main/java/com/sendbird/chat/sample/groupchannel/admin/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.admin.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,6 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> + SendbirdChat.autoBackgroundDetection = true + uri?.let { sendFileMessage(it) } + } + private val startForResultFile = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> SendbirdChat.autoBackgroundDetection = true @@ -86,11 +91,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +599,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-ban-unban-user/build.gradle b/groupchannel-ban-unban-user/build.gradle index f31b8ba0..3986f023 100644 --- a/groupchannel-ban-unban-user/build.gradle +++ b/groupchannel-ban-unban-user/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.ban" diff --git a/groupchannel-ban-unban-user/src/main/java/com/sendbird/chat/sample/groupchannel/ban/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-ban-unban-user/src/main/java/com/sendbird/chat/sample/groupchannel/ban/ui/groupchannel/GroupChannelChatActivity.kt index 202bfb4f..874470de 100644 --- a/groupchannel-ban-unban-user/src/main/java/com/sendbird/chat/sample/groupchannel/ban/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-ban-unban-user/src/main/java/com/sendbird/chat/sample/groupchannel/ban/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.ban.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-banned-and-muted-users/build.gradle b/groupchannel-banned-and-muted-users/build.gradle index 294d99ac..9f0e2cd6 100644 --- a/groupchannel-banned-and-muted-users/build.gradle +++ b/groupchannel-banned-and-muted-users/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.bannedandmutedusers" diff --git a/groupchannel-banned-and-muted-users/src/main/java/com/sendbird/chat/sample/groupchannel/bannedandmutedusers/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-banned-and-muted-users/src/main/java/com/sendbird/chat/sample/groupchannel/bannedandmutedusers/ui/groupchannel/GroupChannelChatActivity.kt index fb1fa69d..fc872e86 100644 --- a/groupchannel-banned-and-muted-users/src/main/java/com/sendbird/chat/sample/groupchannel/bannedandmutedusers/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-banned-and-muted-users/src/main/java/com/sendbird/chat/sample/groupchannel/bannedandmutedusers/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.bannedandmutedusers.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-basic/build.gradle b/groupchannel-basic/build.gradle index 3daac97a..8d6cdf9a 100644 --- a/groupchannel-basic/build.gradle +++ b/groupchannel-basic/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel" diff --git a/groupchannel-basic/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-basic/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt index d7c38003..96c60154 100644 --- a/groupchannel-basic/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-basic/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-categorize-channels/build.gradle b/groupchannel-categorize-channels/build.gradle index 48aec7c9..590927dc 100644 --- a/groupchannel-categorize-channels/build.gradle +++ b/groupchannel-categorize-channels/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.categorizechannels" diff --git a/groupchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/groupchannel/categorizechannels/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/groupchannel/categorizechannels/ui/groupchannel/GroupChannelChatActivity.kt index bae0a105..9b705a37 100644 --- a/groupchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/groupchannel/categorizechannels/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/groupchannel/categorizechannels/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.categorizechannels.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -602,32 +595,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-categorize-message/build.gradle b/groupchannel-categorize-message/build.gradle index b4d9d6fb..90abb26f 100644 --- a/groupchannel-categorize-message/build.gradle +++ b/groupchannel-categorize-message/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.categorizemessage" diff --git a/groupchannel-categorize-message/src/main/java/com/sendbird/chat/sample/groupchannel/categorizemessage/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-categorize-message/src/main/java/com/sendbird/chat/sample/groupchannel/categorizemessage/ui/groupchannel/GroupChannelChatActivity.kt index bb526821..69b04518 100644 --- a/groupchannel-categorize-message/src/main/java/com/sendbird/chat/sample/groupchannel/categorizemessage/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-categorize-message/src/main/java/com/sendbird/chat/sample/groupchannel/categorizemessage/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.categorizemessage.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -42,14 +41,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -87,11 +84,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -643,34 +636,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { const val PINNED = "pinned_message" } diff --git a/groupchannel-dnd-snooze/build.gradle b/groupchannel-dnd-snooze/build.gradle index 3daac97a..8d6cdf9a 100644 --- a/groupchannel-dnd-snooze/build.gradle +++ b/groupchannel-dnd-snooze/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel" diff --git a/groupchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt index d7c38003..96c60154 100644 --- a/groupchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-encryptedfiles/build.gradle b/groupchannel-encryptedfiles/build.gradle index 13279acb..ccdf4903 100644 --- a/groupchannel-encryptedfiles/build.gradle +++ b/groupchannel-encryptedfiles/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.encryptedfiles" diff --git a/groupchannel-encryptedfiles/src/main/java/com/sendbird/chat/sample/groupchannel/encryptedfiles/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-encryptedfiles/src/main/java/com/sendbird/chat/sample/groupchannel/encryptedfiles/ui/groupchannel/GroupChannelChatActivity.kt index a7671d70..6b2ab1e7 100644 --- a/groupchannel-encryptedfiles/src/main/java/com/sendbird/chat/sample/groupchannel/encryptedfiles/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-encryptedfiles/src/main/java/com/sendbird/chat/sample/groupchannel/encryptedfiles/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.encryptedfiles.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-file-progress-cancel/build.gradle b/groupchannel-file-progress-cancel/build.gradle index d100fb16..fe1778a2 100644 --- a/groupchannel-file-progress-cancel/build.gradle +++ b/groupchannel-file-progress-cancel/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.file" diff --git a/groupchannel-file-progress-cancel/src/main/java/com/sendbird/chat/sample/groupchannel/file/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-file-progress-cancel/src/main/java/com/sendbird/chat/sample/groupchannel/file/ui/groupchannel/GroupChannelChatActivity.kt index 9778eb90..7c1716f0 100644 --- a/groupchannel-file-progress-cancel/src/main/java/com/sendbird/chat/sample/groupchannel/file/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-file-progress-cancel/src/main/java/com/sendbird/chat/sample/groupchannel/file/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.file.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -44,14 +43,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var fileMessage: FileMessage? = null - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -89,11 +86,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -627,32 +620,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-freeze-unfreeze/build.gradle b/groupchannel-freeze-unfreeze/build.gradle index c50fe3e6..65d2375d 100644 --- a/groupchannel-freeze-unfreeze/build.gradle +++ b/groupchannel-freeze-unfreeze/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.freeze" diff --git a/groupchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/groupchannel/freeze/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/groupchannel/freeze/ui/groupchannel/GroupChannelChatActivity.kt index fb312a3e..962142f5 100644 --- a/groupchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/groupchannel/freeze/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/groupchannel/freeze/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.freeze.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -43,14 +42,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -88,11 +85,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -665,34 +658,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { private const val FrozenChannelHandlerIdentifier = "FreezeStatusHandler" } diff --git a/groupchannel-friends/build.gradle b/groupchannel-friends/build.gradle index 3daac97a..8d6cdf9a 100644 --- a/groupchannel-friends/build.gradle +++ b/groupchannel-friends/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel" diff --git a/groupchannel-friends/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-friends/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt index d7c38003..96c60154 100644 --- a/groupchannel-friends/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-friends/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-hide-archive/build.gradle b/groupchannel-hide-archive/build.gradle index c4c31c07..6db0ed43 100644 --- a/groupchannel-hide-archive/build.gradle +++ b/groupchannel-hide-archive/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.hide_archive" diff --git a/groupchannel-hide-archive/src/main/java/com/sendbird/chat/sample/groupchannel/hide_archive/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-hide-archive/src/main/java/com/sendbird/chat/sample/groupchannel/hide_archive/ui/groupchannel/GroupChannelChatActivity.kt index a5d774d5..85534aa3 100644 --- a/groupchannel-hide-archive/src/main/java/com/sendbird/chat/sample/groupchannel/hide_archive/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-hide-archive/src/main/java/com/sendbird/chat/sample/groupchannel/hide_archive/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.hide_archive.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-local-caching/build.gradle b/groupchannel-local-caching/build.gradle index 19ceda79..7c147885 100644 --- a/groupchannel-local-caching/build.gradle +++ b/groupchannel-local-caching/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.localcaching" @@ -63,4 +63,4 @@ dependencies { testImplementation "junit:junit:$junitVersion" androidTestImplementation "androidx.test.ext:junit:$androidxTestExtJunitVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$androidxTestEspressoCoreVersion" -} \ No newline at end of file +} diff --git a/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatActivity.kt index 1d8f0260..e8cc7c26 100644 --- a/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.localcaching.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -164,14 +157,14 @@ class GroupChannelChatActivity : AppCompatActivity() { GroupChannel.getChannel( channelUrl ) getChannelLabel@{ groupChannel, e -> - if (e != null) { - showToast("${e.message}") - return@getChannelLabel - } if (groupChannel != null) { currentGroupChannel = groupChannel setChannelTitle() createMessageCollection(channelTSHashMap[channelUrl] ?: Long.MAX_VALUE) + } else { + if (e != null) { + showToast("${e.message}") + } } } } @@ -215,9 +208,6 @@ class GroupChannelChatActivity : AppCompatActivity() { cachedList: List?, e: SendbirdException? ) { - if (e != null) { - showToast("${e.message}") - } adapter.changeMessages(cachedList) adapter.addPendingMessages(this@apply.pendingMessages) } @@ -226,11 +216,14 @@ class GroupChannelChatActivity : AppCompatActivity() { apiResultList: List?, e: SendbirdException? ) { - if (e != null) { - showToast("${e.message}") + if (apiResultList != null) { + adapter.changeMessages(apiResultList, false) + markAsRead() + } else { + if (e != null) { + showToast("${e.message}") + } } - adapter.changeMessages(apiResultList, false) - markAsRead() isCollectionInitialized = true } } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatAdapter.kt b/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatAdapter.kt index cb463344..d227f870 100644 --- a/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatAdapter.kt +++ b/groupchannel-local-caching/src/main/java/com/sendbird/chat/sample/groupchannel/localcaching/ui/groupchannel/GroupChannelChatAdapter.kt @@ -1,5 +1,6 @@ package com.sendbird.chat.sample.groupchannel.localcaching.ui.groupchannel +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -17,6 +18,7 @@ import com.sendbird.chat.module.utils.equalDate import com.sendbird.chat.module.utils.equalTime import com.sendbird.chat.module.utils.toTime import com.sendbird.chat.sample.groupchannel.localcaching.databinding.* +import java.util.logging.Logger class GroupChannelChatAdapter( private val longClickListener: OnItemLongClickListener, @@ -395,6 +397,7 @@ class GroupChannelChatAdapter( showTime: Boolean ) { if (message.sendingStatus == SendingStatus.SUCCEEDED) { + Log.e("==", "url: ${message.url}, mime type: ${message.type}") binding.chatBubbleImageSend.setImageUrl(message.url, message.plainUrl) binding.progressImageSend.visibility = View.GONE binding.chatImageErrorButton.visibility = View.GONE @@ -411,7 +414,13 @@ class GroupChannelChatAdapter( binding.textviewTime.visibility = View.GONE } } else { - binding.chatBubbleImageSend.setImageFile(message.messageCreateParams?.file) + Log.e("==", "file: ${message.messageCreateParams?.file}, file url: ${message.messageCreateParams?.fileUrl}") + message.messageCreateParams?.file?.let { + binding.chatBubbleImageSend.setImageFile(it) + } ?: message.messageCreateParams?.fileUrl?.let { + binding.chatBubbleImageSend.setImageUrl(it, it) + } + binding.dateTagView.visibility = View.GONE binding.textviewTime.visibility = View.GONE if (message.sendingStatus == SendingStatus.PENDING) { diff --git a/groupchannel-mark-message-read/build.gradle b/groupchannel-mark-message-read/build.gradle index 49d727b8..3d3d8978 100644 --- a/groupchannel-mark-message-read/build.gradle +++ b/groupchannel-mark-message-read/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.markmessage" diff --git a/groupchannel-mark-message-read/src/main/java/com/sendbird/chat/sample/groupchannel/markmessage/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-mark-message-read/src/main/java/com/sendbird/chat/sample/groupchannel/markmessage/ui/groupchannel/GroupChannelChatActivity.kt index 212b821e..c27b2167 100644 --- a/groupchannel-mark-message-read/src/main/java/com/sendbird/chat/sample/groupchannel/markmessage/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-mark-message-read/src/main/java/com/sendbird/chat/sample/groupchannel/markmessage/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.markmessage.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -43,14 +42,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -88,11 +85,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -618,34 +611,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { private const val ChatReadHandler = "chat_read_handler" } diff --git a/groupchannel-membersandoperators/build.gradle b/groupchannel-membersandoperators/build.gradle index a07ad46b..c54e6396 100644 --- a/groupchannel-membersandoperators/build.gradle +++ b/groupchannel-membersandoperators/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.membersandoperators" diff --git a/groupchannel-membersandoperators/src/main/java/com/sendbird/chat/sample/groupchannel/membersandoperators/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-membersandoperators/src/main/java/com/sendbird/chat/sample/groupchannel/membersandoperators/ui/groupchannel/GroupChannelChatActivity.kt index cf8cd4ae..37ceca2b 100644 --- a/groupchannel-membersandoperators/src/main/java/com/sendbird/chat/sample/groupchannel/membersandoperators/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-membersandoperators/src/main/java/com/sendbird/chat/sample/groupchannel/membersandoperators/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.membersandoperators.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-mention-members/build.gradle b/groupchannel-mention-members/build.gradle index 33753f88..14f6ed4c 100644 --- a/groupchannel-mention-members/build.gradle +++ b/groupchannel-mention-members/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.mentionmembers" diff --git a/groupchannel-mention-members/src/main/java/com/sendbird/chat/sample/groupchannel/mentionmembers/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-mention-members/src/main/java/com/sendbird/chat/sample/groupchannel/mentionmembers/ui/groupchannel/GroupChannelChatActivity.kt index 5a39c384..aa219ff7 100644 --- a/groupchannel-mention-members/src/main/java/com/sendbird/chat/sample/groupchannel/mentionmembers/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-mention-members/src/main/java/com/sendbird/chat/sample/groupchannel/mentionmembers/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.mentionmembers.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -43,14 +42,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -88,11 +85,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -633,34 +626,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { private const val MentionHandlerId = "MentionHandlerId" } diff --git a/groupchannel-mute-user/build.gradle b/groupchannel-mute-user/build.gradle index cc5ecc96..143619ee 100644 --- a/groupchannel-mute-user/build.gradle +++ b/groupchannel-mute-user/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.mute" diff --git a/groupchannel-mute-user/src/main/java/com/sendbird/chat/sample/groupchannel/mute/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-mute-user/src/main/java/com/sendbird/chat/sample/groupchannel/mute/ui/groupchannel/GroupChannelChatActivity.kt index 8bd6d7dd..7ade038c 100644 --- a/groupchannel-mute-user/src/main/java/com/sendbird/chat/sample/groupchannel/mute/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-mute-user/src/main/java/com/sendbird/chat/sample/groupchannel/mute/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.mute.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-nickname/build.gradle b/groupchannel-nickname/build.gradle index fa66f36c..c11c0d22 100644 --- a/groupchannel-nickname/build.gradle +++ b/groupchannel-nickname/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.nickname" diff --git a/groupchannel-nickname/src/main/java/com/sendbird/chat/sample/groupchannel/nickname/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-nickname/src/main/java/com/sendbird/chat/sample/groupchannel/nickname/ui/groupchannel/GroupChannelChatActivity.kt index d7bd7649..fcccece3 100644 --- a/groupchannel-nickname/src/main/java/com/sendbird/chat/sample/groupchannel/nickname/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-nickname/src/main/java/com/sendbird/chat/sample/groupchannel/nickname/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.nickname.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-ogt/build.gradle b/groupchannel-ogt/build.gradle index ed5cf3fb..a55c7117 100644 --- a/groupchannel-ogt/build.gradle +++ b/groupchannel-ogt/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.ogt" diff --git a/groupchannel-ogt/src/main/java/com/sendbird/chat/sample/groupchannel/ogt/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-ogt/src/main/java/com/sendbird/chat/sample/groupchannel/ogt/ui/groupchannel/GroupChannelChatActivity.kt index bb4a6896..6ab01775 100644 --- a/groupchannel-ogt/src/main/java/com/sendbird/chat/sample/groupchannel/ogt/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-ogt/src/main/java/com/sendbird/chat/sample/groupchannel/ogt/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.ogt.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-onlinemembers/build.gradle b/groupchannel-onlinemembers/build.gradle index dd4354fd..087842da 100644 --- a/groupchannel-onlinemembers/build.gradle +++ b/groupchannel-onlinemembers/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.onlinemembers" diff --git a/groupchannel-onlinemembers/src/main/java/com/sendbird/chat/sample/groupchannel/onlinemembers/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-onlinemembers/src/main/java/com/sendbird/chat/sample/groupchannel/onlinemembers/ui/groupchannel/GroupChannelChatActivity.kt index 34c6fbb1..f0f8e022 100644 --- a/groupchannel-onlinemembers/src/main/java/com/sendbird/chat/sample/groupchannel/onlinemembers/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-onlinemembers/src/main/java/com/sendbird/chat/sample/groupchannel/onlinemembers/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.onlinemembers.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-operators/build.gradle b/groupchannel-operators/build.gradle index e959f2bd..711baf76 100644 --- a/groupchannel-operators/build.gradle +++ b/groupchannel-operators/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.operators" diff --git a/groupchannel-operators/src/main/java/com/sendbird/chat/sample/groupchannel/operators/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-operators/src/main/java/com/sendbird/chat/sample/groupchannel/operators/ui/groupchannel/GroupChannelChatActivity.kt index ef7b687d..83083f04 100644 --- a/groupchannel-operators/src/main/java/com/sendbird/chat/sample/groupchannel/operators/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-operators/src/main/java/com/sendbird/chat/sample/groupchannel/operators/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.operators.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-pinnedmessage/build.gradle b/groupchannel-pinnedmessage/build.gradle index 9285c6d1..c4f5da0b 100644 --- a/groupchannel-pinnedmessage/build.gradle +++ b/groupchannel-pinnedmessage/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.pinnedmessage" diff --git a/groupchannel-pinnedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/pinnedmessage/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-pinnedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/pinnedmessage/ui/groupchannel/GroupChannelChatActivity.kt index 8ad2f439..d93ab77d 100644 --- a/groupchannel-pinnedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/pinnedmessage/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-pinnedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/pinnedmessage/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.pinnedmessage.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.view.isVisible @@ -45,14 +44,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -90,11 +87,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -667,34 +660,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - private fun drawLastPinnedMessage() { val channel = currentGroupChannel ?: return binding.lastPinnedMessageLayout.isVisible = channel.lastPinnedMessage != null diff --git a/groupchannel-polls/build.gradle b/groupchannel-polls/build.gradle index 3daac97a..8d6cdf9a 100644 --- a/groupchannel-polls/build.gradle +++ b/groupchannel-polls/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel" diff --git a/groupchannel-polls/src/main/java/com/sendbird/chat/sample/groupchannel/polls/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-polls/src/main/java/com/sendbird/chat/sample/groupchannel/polls/ui/groupchannel/GroupChannelChatActivity.kt index 9b45a7b5..2b2aa579 100644 --- a/groupchannel-polls/src/main/java/com/sendbird/chat/sample/groupchannel/polls/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-polls/src/main/java/com/sendbird/chat/sample/groupchannel/polls/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,13 +1,12 @@ package com.sendbird.chat.sample.groupchannel.polls.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.util.Log import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -49,14 +48,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -94,11 +91,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -711,34 +704,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { private const val GroupChannelPollHandler = "chat_poll_handler" } diff --git a/groupchannel-profile-image/build.gradle b/groupchannel-profile-image/build.gradle index fa617e1a..dbd9ceea 100644 --- a/groupchannel-profile-image/build.gradle +++ b/groupchannel-profile-image/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.profileimage" diff --git a/groupchannel-profile-image/src/main/java/com/sendbird/chat/sample/groupchannel/profileimage/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-profile-image/src/main/java/com/sendbird/chat/sample/groupchannel/profileimage/ui/groupchannel/GroupChannelChatActivity.kt index 729e3c77..f8ab0976 100644 --- a/groupchannel-profile-image/src/main/java/com/sendbird/chat/sample/groupchannel/profileimage/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-profile-image/src/main/java/com/sendbird/chat/sample/groupchannel/profileimage/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.profileimage.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-push-notifications/build.gradle b/groupchannel-push-notifications/build.gradle index 404a419a..24427c4d 100644 --- a/groupchannel-push-notifications/build.gradle +++ b/groupchannel-push-notifications/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.push" diff --git a/groupchannel-push-notifications/src/main/java/com/sendbird/chat/sample/groupchannel/push/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-push-notifications/src/main/java/com/sendbird/chat/sample/groupchannel/push/ui/groupchannel/GroupChannelChatActivity.kt index d5dd2ade..14635cd2 100644 --- a/groupchannel-push-notifications/src/main/java/com/sendbird/chat/sample/groupchannel/push/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-push-notifications/src/main/java/com/sendbird/chat/sample/groupchannel/push/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.push.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-push-translations/build.gradle b/groupchannel-push-translations/build.gradle index ddb0f58d..d52dfe1b 100644 --- a/groupchannel-push-translations/build.gradle +++ b/groupchannel-push-translations/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.pushtranslations" diff --git a/groupchannel-push-translations/src/main/java/com/sendbird/chat/sample/groupchannel/pushtranslations/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-push-translations/src/main/java/com/sendbird/chat/sample/groupchannel/pushtranslations/ui/groupchannel/GroupChannelChatActivity.kt index 24ef4518..b746a9a8 100644 --- a/groupchannel-push-translations/src/main/java/com/sendbird/chat/sample/groupchannel/pushtranslations/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-push-translations/src/main/java/com/sendbird/chat/sample/groupchannel/pushtranslations/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.pushtranslations.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-reactions/build.gradle b/groupchannel-reactions/build.gradle index 40c363d8..fe8b7384 100644 --- a/groupchannel-reactions/build.gradle +++ b/groupchannel-reactions/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.reactions" diff --git a/groupchannel-reactions/src/main/java/com/sendbird/chat/sample/groupchannel/reactions/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-reactions/src/main/java/com/sendbird/chat/sample/groupchannel/reactions/ui/groupchannel/GroupChannelChatActivity.kt index 448058be..221686fa 100644 --- a/groupchannel-reactions/src/main/java/com/sendbird/chat/sample/groupchannel/reactions/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-reactions/src/main/java/com/sendbird/chat/sample/groupchannel/reactions/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.reactions.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -44,14 +43,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -89,11 +86,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -645,34 +638,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { private const val ReactionHandlerKey = "ReactionHandler" } diff --git a/groupchannel-readmessage/build.gradle b/groupchannel-readmessage/build.gradle index 450e128e..95571d11 100644 --- a/groupchannel-readmessage/build.gradle +++ b/groupchannel-readmessage/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.readmessage" diff --git a/groupchannel-readmessage/src/main/java/com/sendbird/chat/sample/groupchannel/readmessage/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-readmessage/src/main/java/com/sendbird/chat/sample/groupchannel/readmessage/ui/groupchannel/GroupChannelChatActivity.kt index 53bbe52f..cfd8c350 100644 --- a/groupchannel-readmessage/src/main/java/com/sendbird/chat/sample/groupchannel/readmessage/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-readmessage/src/main/java/com/sendbird/chat/sample/groupchannel/readmessage/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.readmessage.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -613,32 +606,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-report-user-message-channel/build.gradle b/groupchannel-report-user-message-channel/build.gradle index 3affe591..e76195ca 100644 --- a/groupchannel-report-user-message-channel/build.gradle +++ b/groupchannel-report-user-message-channel/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.report" diff --git a/groupchannel-report-user-message-channel/src/main/java/com/sendbird/chat/sample/groupchannel/report/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-report-user-message-channel/src/main/java/com/sendbird/chat/sample/groupchannel/report/ui/groupchannel/GroupChannelChatActivity.kt index ce5cbb8c..2a08b531 100644 --- a/groupchannel-report-user-message-channel/src/main/java/com/sendbird/chat/sample/groupchannel/report/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-report-user-message-channel/src/main/java/com/sendbird/chat/sample/groupchannel/report/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.report.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -43,14 +42,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -88,11 +85,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -655,32 +648,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-scheduled-message/build.gradle b/groupchannel-scheduled-message/build.gradle index 3daac97a..8d6cdf9a 100644 --- a/groupchannel-scheduled-message/build.gradle +++ b/groupchannel-scheduled-message/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel" diff --git a/groupchannel-scheduled-message/src/main/java/com/sendbird/chat/sample/groupchannel/scheduled/message/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-scheduled-message/src/main/java/com/sendbird/chat/sample/groupchannel/scheduled/message/ui/groupchannel/GroupChannelChatActivity.kt index 03d93d80..87f5120b 100644 --- a/groupchannel-scheduled-message/src/main/java/com/sendbird/chat/sample/groupchannel/scheduled/message/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-scheduled-message/src/main/java/com/sendbird/chat/sample/groupchannel/scheduled/message/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,8 +1,6 @@ package com.sendbird.chat.sample.groupchannel.scheduled.message.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.util.Log @@ -10,6 +8,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.TextView +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.PopupMenu @@ -51,14 +50,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var scheduledTime: Long = 0L - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -96,11 +93,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) @@ -682,34 +675,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - private fun openScheduleMessageMenu(anchor: View) { if (scheduledTime == 0L) { createSelectScheduledMenu(anchor) diff --git a/groupchannel-threading/build.gradle b/groupchannel-threading/build.gradle index 3daac97a..8d6cdf9a 100644 --- a/groupchannel-threading/build.gradle +++ b/groupchannel-threading/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel" diff --git a/groupchannel-threading/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-threading/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt index 3741b0d0..30c9334c 100644 --- a/groupchannel-threading/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-threading/src/main/java/com/sendbird/chat/sample/groupchannel/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -43,14 +42,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var replayMessageId: Long = -1L - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -88,11 +85,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -606,32 +599,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-type/build.gradle b/groupchannel-type/build.gradle index e3bad34c..056de376 100644 --- a/groupchannel-type/build.gradle +++ b/groupchannel-type/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.type" diff --git a/groupchannel-type/src/main/java/com/sendbird/chat/sample/groupchannel/type/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-type/src/main/java/com/sendbird/chat/sample/groupchannel/type/ui/groupchannel/GroupChannelChatActivity.kt index 08829ba1..4af82662 100644 --- a/groupchannel-type/src/main/java/com/sendbird/chat/sample/groupchannel/type/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-type/src/main/java/com/sendbird/chat/sample/groupchannel/type/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.type.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-typingindicator/build.gradle b/groupchannel-typingindicator/build.gradle index c9de0315..f61ad7ab 100644 --- a/groupchannel-typingindicator/build.gradle +++ b/groupchannel-typingindicator/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.typingindicator" diff --git a/groupchannel-typingindicator/src/main/java/com/sendbird/chat/sample/typingindicator/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-typingindicator/src/main/java/com/sendbird/chat/sample/typingindicator/ui/groupchannel/GroupChannelChatActivity.kt index cd26bf7e..3e4109b7 100644 --- a/groupchannel-typingindicator/src/main/java/com/sendbird/chat/sample/typingindicator/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-typingindicator/src/main/java/com/sendbird/chat/sample/typingindicator/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.typingindicator.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -42,14 +41,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -89,11 +86,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) @@ -645,32 +638,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-unreadmessages/build.gradle b/groupchannel-unreadmessages/build.gradle index 2578aa6c..7f114902 100644 --- a/groupchannel-unreadmessages/build.gradle +++ b/groupchannel-unreadmessages/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.unreadmessages" diff --git a/groupchannel-unreadmessages/src/main/java/com/sendbird/chat/sample/groupchannel/unreadmessages/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-unreadmessages/src/main/java/com/sendbird/chat/sample/groupchannel/unreadmessages/ui/groupchannel/GroupChannelChatActivity.kt index a49d634d..2008e6a7 100644 --- a/groupchannel-unreadmessages/src/main/java/com/sendbird/chat/sample/groupchannel/unreadmessages/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-unreadmessages/src/main/java/com/sendbird/chat/sample/groupchannel/unreadmessages/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.unreadmessages.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -42,14 +41,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -87,11 +84,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -614,34 +607,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { private val UnReadMessageHandlerId = UUID.randomUUID().toString() } diff --git a/groupchannel-unreceivedmessage/build.gradle b/groupchannel-unreceivedmessage/build.gradle index 85bff4ae..f0339b8b 100644 --- a/groupchannel-unreceivedmessage/build.gradle +++ b/groupchannel-unreceivedmessage/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.unreceivedmessage" diff --git a/groupchannel-unreceivedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/unreceivedmessage/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-unreceivedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/unreceivedmessage/ui/groupchannel/GroupChannelChatActivity.kt index c4fa7cd8..281d3356 100644 --- a/groupchannel-unreceivedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/unreceivedmessage/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-unreceivedmessage/src/main/java/com/sendbird/chat/sample/groupchannel/unreceivedmessage/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.unreceivedmessage.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -43,14 +42,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -88,11 +85,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -627,34 +620,6 @@ class GroupChannelChatActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - companion object { private val UndeliveredMessageHandlerId = UUID.randomUUID().toString() } diff --git a/groupchannel-update-message-operator/build.gradle b/groupchannel-update-message-operator/build.gradle index f25f5c93..9b769441 100644 --- a/groupchannel-update-message-operator/build.gradle +++ b/groupchannel-update-message-operator/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.updateoperator" diff --git a/groupchannel-update-message-operator/src/main/java/com/sendbird/chat/sample/groupchannel/updateoperator/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-update-message-operator/src/main/java/com/sendbird/chat/sample/groupchannel/updateoperator/ui/groupchannel/GroupChannelChatActivity.kt index b7ca587b..698ae263 100644 --- a/groupchannel-update-message-operator/src/main/java/com/sendbird/chat/sample/groupchannel/updateoperator/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-update-message-operator/src/main/java/com/sendbird/chat/sample/groupchannel/updateoperator/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.updateoperator.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -45,14 +44,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private val operators = mutableListOf() - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -90,11 +87,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -651,32 +644,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/groupchannel-user-online/build.gradle b/groupchannel-user-online/build.gradle index 9caf6f7c..76783818 100644 --- a/groupchannel-user-online/build.gradle +++ b/groupchannel-user-online/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.groupchannel.useronline" diff --git a/groupchannel-user-online/src/main/java/com/sendbird/chat/sample/groupchannel/useronline/ui/groupchannel/GroupChannelChatActivity.kt b/groupchannel-user-online/src/main/java/com/sendbird/chat/sample/groupchannel/useronline/ui/groupchannel/GroupChannelChatActivity.kt index 05ccb6c2..404fedf6 100644 --- a/groupchannel-user-online/src/main/java/com/sendbird/chat/sample/groupchannel/useronline/ui/groupchannel/GroupChannelChatActivity.kt +++ b/groupchannel-user-online/src/main/java/com/sendbird/chat/sample/groupchannel/useronline/ui/groupchannel/GroupChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.groupchannel.useronline.ui.groupchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -41,14 +40,12 @@ class GroupChannelChatActivity : AppCompatActivity() { private var channelTSHashMap = ConcurrentHashMap() private var isCollectionInitialized = false - private val startForResultFile = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } + private val startForResultInvite = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> if (data.resultCode == RESULT_OK) { @@ -86,11 +83,7 @@ class GroupChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this@GroupChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -598,32 +591,4 @@ class GroupChannelChatActivity : AppCompatActivity() { } } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResultFile, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-admin-message/build.gradle b/openchannel-admin-message/build.gradle index 9ac85589..94a6d5a6 100644 --- a/openchannel-admin-message/build.gradle +++ b/openchannel-admin-message/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.adminmessasge" diff --git a/openchannel-admin-message/src/main/java/com/sendbird/chat/sample/openchannel/adminmessasge/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-admin-message/src/main/java/com/sendbird/chat/sample/openchannel/adminmessasge/ui/openchannel/OpenChannelChatActivity.kt index 769630c6..8c950536 100644 --- a/openchannel-admin-message/src/main/java/com/sendbird/chat/sample/openchannel/adminmessasge/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-admin-message/src/main/java/com/sendbird/chat/sample/openchannel/adminmessasge/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.adminmessasge.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -514,34 +506,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-basic/build.gradle b/openchannel-basic/build.gradle index 3bc6c123..11121bbd 100644 --- a/openchannel-basic/build.gradle +++ b/openchannel-basic/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel" diff --git a/openchannel-basic/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-basic/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt index 700569cc..291b9797 100644 --- a/openchannel-basic/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-basic/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -514,34 +506,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-categorize-channels/build.gradle b/openchannel-categorize-channels/build.gradle index 2c665742..4eb20e4a 100644 --- a/openchannel-categorize-channels/build.gradle +++ b/openchannel-categorize-channels/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.categorizechannels" diff --git a/openchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/openchannel/categorizechannels/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/openchannel/categorizechannels/ui/openchannel/OpenChannelChatActivity.kt index 410b738d..ef2b21e3 100644 --- a/openchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/openchannel/categorizechannels/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-categorize-channels/src/main/java/com/sendbird/chat/sample/openchannel/categorizechannels/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.categorizechannels.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -517,34 +509,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-categorize-messages/build.gradle b/openchannel-categorize-messages/build.gradle index 6585cab9..bb04cdc3 100644 --- a/openchannel-categorize-messages/build.gradle +++ b/openchannel-categorize-messages/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.categorizemessages" diff --git a/openchannel-categorize-messages/src/main/java/com/sendbird/chat/sample/openchannel/categorizemessages/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-categorize-messages/src/main/java/com/sendbird/chat/sample/openchannel/categorizemessages/ui/openchannel/OpenChannelChatActivity.kt index 6c72edf6..036c0372 100644 --- a/openchannel-categorize-messages/src/main/java/com/sendbird/chat/sample/openchannel/categorizemessages/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-categorize-messages/src/main/java/com/sendbird/chat/sample/openchannel/categorizemessages/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.categorizemessages.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -37,13 +36,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -76,11 +72,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -569,36 +561,6 @@ class OpenChannelChatActivity : AppCompatActivity() { currentOpenChannel?.exit {} } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } - companion object { const val PinnedMessage = "pinned_message" } diff --git a/openchannel-copy-message/build.gradle b/openchannel-copy-message/build.gradle index 2d84b302..86a64f5a 100644 --- a/openchannel-copy-message/build.gradle +++ b/openchannel-copy-message/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.copymessage" diff --git a/openchannel-copy-message/src/main/java/com/sendbird/chat/sample/openchannel/copymessage/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-copy-message/src/main/java/com/sendbird/chat/sample/openchannel/copymessage/ui/openchannel/OpenChannelChatActivity.kt index 3d9da932..4d25da00 100644 --- a/openchannel-copy-message/src/main/java/com/sendbird/chat/sample/openchannel/copymessage/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-copy-message/src/main/java/com/sendbird/chat/sample/openchannel/copymessage/ui/openchannel/OpenChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.openchannel.copymessage.ui.openchannel -import android.Manifest import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -38,13 +37,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } private val startChannelForResult = @@ -88,11 +84,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -592,34 +584,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-delete-message/build.gradle b/openchannel-delete-message/build.gradle index 2c7c2556..02173161 100644 --- a/openchannel-delete-message/build.gradle +++ b/openchannel-delete-message/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.deletemessage" diff --git a/openchannel-delete-message/src/main/java/com/sendbird/chat/sample/openchannel/deletemessage/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-delete-message/src/main/java/com/sendbird/chat/sample/openchannel/deletemessage/ui/openchannel/OpenChannelChatActivity.kt index 8b72440d..69441a5f 100644 --- a/openchannel-delete-message/src/main/java/com/sendbird/chat/sample/openchannel/deletemessage/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-delete-message/src/main/java/com/sendbird/chat/sample/openchannel/deletemessage/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.deletemessage.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -515,34 +507,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-dnd-snooze/build.gradle b/openchannel-dnd-snooze/build.gradle index 3bc6c123..11121bbd 100644 --- a/openchannel-dnd-snooze/build.gradle +++ b/openchannel-dnd-snooze/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel" diff --git a/openchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt index 1f59c121..1d72825c 100644 --- a/openchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-dnd-snooze/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -513,34 +505,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-extra-data/build.gradle b/openchannel-extra-data/build.gradle index 458f13e6..e89c349a 100644 --- a/openchannel-extra-data/build.gradle +++ b/openchannel-extra-data/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.extradata" diff --git a/openchannel-extra-data/src/main/java/com/sendbird/chat/sample/openchannel/extradata/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-extra-data/src/main/java/com/sendbird/chat/sample/openchannel/extradata/ui/openchannel/OpenChannelChatActivity.kt index 958e6d38..10796864 100644 --- a/openchannel-extra-data/src/main/java/com/sendbird/chat/sample/openchannel/extradata/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-extra-data/src/main/java/com/sendbird/chat/sample/openchannel/extradata/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.extradata.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -33,13 +32,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -72,11 +68,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -556,36 +548,6 @@ class OpenChannelChatActivity : AppCompatActivity() { currentOpenChannel?.exit {} } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } - companion object { private const val PeopleKey = "people" } diff --git a/openchannel-freeze-unfreeze/build.gradle b/openchannel-freeze-unfreeze/build.gradle index 1fdee965..377e37ca 100644 --- a/openchannel-freeze-unfreeze/build.gradle +++ b/openchannel-freeze-unfreeze/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.freeze" diff --git a/openchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/openchannel/freeze/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/openchannel/freeze/ui/openchannel/OpenChannelChatActivity.kt index 64f7ffec..ded497fc 100644 --- a/openchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/openchannel/freeze/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-freeze-unfreeze/src/main/java/com/sendbird/chat/sample/openchannel/freeze/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.freeze.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -511,34 +503,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-friends/build.gradle b/openchannel-friends/build.gradle index b0fb9931..b86c3e26 100644 --- a/openchannel-friends/build.gradle +++ b/openchannel-friends/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.friends" diff --git a/openchannel-friends/src/main/java/com/sendbird/chat/sample/openchannel/friends/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-friends/src/main/java/com/sendbird/chat/sample/openchannel/friends/ui/openchannel/OpenChannelChatActivity.kt index c36f86f9..0be004fa 100644 --- a/openchannel-friends/src/main/java/com/sendbird/chat/sample/openchannel/friends/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-friends/src/main/java/com/sendbird/chat/sample/openchannel/friends/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.friends.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -514,34 +506,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-mention-user/build.gradle b/openchannel-mention-user/build.gradle index 99402698..91ff1df3 100644 --- a/openchannel-mention-user/build.gradle +++ b/openchannel-mention-user/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.mentionuser" diff --git a/openchannel-mention-user/src/main/java/com/sendbird/chat/sample/openchannel/mentionuser/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-mention-user/src/main/java/com/sendbird/chat/sample/openchannel/mentionuser/ui/openchannel/OpenChannelChatActivity.kt index d1b05b47..f5756a2e 100644 --- a/openchannel-mention-user/src/main/java/com/sendbird/chat/sample/openchannel/mentionuser/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-mention-user/src/main/java/com/sendbird/chat/sample/openchannel/mentionuser/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.mentionuser.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope @@ -40,13 +39,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -79,11 +75,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -579,34 +571,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-metadata-metacounter/build.gradle b/openchannel-metadata-metacounter/build.gradle index 3bc6c123..11121bbd 100644 --- a/openchannel-metadata-metacounter/build.gradle +++ b/openchannel-metadata-metacounter/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel" diff --git a/openchannel-metadata-metacounter/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-metadata-metacounter/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt index 1f4db15c..be396bf1 100644 --- a/openchannel-metadata-metacounter/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-metadata-metacounter/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt @@ -1,13 +1,12 @@ package com.sendbird.chat.sample.openchannel.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.graphics.Color import android.net.Uri import android.os.Bundle import android.util.Log import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -38,13 +37,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -77,11 +73,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -623,34 +615,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-nickname/build.gradle b/openchannel-nickname/build.gradle index 0c4d5a83..4989a42b 100644 --- a/openchannel-nickname/build.gradle +++ b/openchannel-nickname/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.nickname" diff --git a/openchannel-nickname/src/main/java/com/sendbird/chat/sample/openchannel/nickname/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-nickname/src/main/java/com/sendbird/chat/sample/openchannel/nickname/ui/openchannel/OpenChannelChatActivity.kt index 4d0bbeca..0a0c4ee0 100644 --- a/openchannel-nickname/src/main/java/com/sendbird/chat/sample/openchannel/nickname/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-nickname/src/main/java/com/sendbird/chat/sample/openchannel/nickname/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.nickname.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -514,34 +506,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-ogt/build.gradle b/openchannel-ogt/build.gradle index 22f3827d..7196c938 100644 --- a/openchannel-ogt/build.gradle +++ b/openchannel-ogt/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.ogt" diff --git a/openchannel-ogt/src/main/java/com/sendbird/chat/sample/openchannel/ogt/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-ogt/src/main/java/com/sendbird/chat/sample/openchannel/ogt/ui/openchannel/OpenChannelChatActivity.kt index 1b312b9c..72e8fdb7 100644 --- a/openchannel-ogt/src/main/java/com/sendbird/chat/sample/openchannel/ogt/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-ogt/src/main/java/com/sendbird/chat/sample/openchannel/ogt/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.ogt.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -513,34 +505,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-profile-image/build.gradle b/openchannel-profile-image/build.gradle index 49b7aaed..de1b46b8 100644 --- a/openchannel-profile-image/build.gradle +++ b/openchannel-profile-image/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.profileimage" diff --git a/openchannel-profile-image/src/main/java/com/sendbird/chat/sample/openchannel/profileimage/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-profile-image/src/main/java/com/sendbird/chat/sample/openchannel/profileimage/ui/openchannel/OpenChannelChatActivity.kt index 6d192cc3..83fe9e48 100644 --- a/openchannel-profile-image/src/main/java/com/sendbird/chat/sample/openchannel/profileimage/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-profile-image/src/main/java/com/sendbird/chat/sample/openchannel/profileimage/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.profileimage.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -514,34 +506,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-report-message-user-channel/build.gradle b/openchannel-report-message-user-channel/build.gradle index 36e1aead..29d3c7ad 100644 --- a/openchannel-report-message-user-channel/build.gradle +++ b/openchannel-report-message-user-channel/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.report" diff --git a/openchannel-report-message-user-channel/src/main/java/com/sendbird/chat/sample/openchannel/report/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-report-message-user-channel/src/main/java/com/sendbird/chat/sample/openchannel/report/ui/openchannel/OpenChannelChatActivity.kt index 17237d39..e6eb4dbb 100644 --- a/openchannel-report-message-user-channel/src/main/java/com/sendbird/chat/sample/openchannel/report/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-report-message-user-channel/src/main/java/com/sendbird/chat/sample/openchannel/report/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.report.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -38,13 +37,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -77,11 +73,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -572,34 +564,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-send-receive-files/build.gradle b/openchannel-send-receive-files/build.gradle index db36bd7f..2003c085 100644 --- a/openchannel-send-receive-files/build.gradle +++ b/openchannel-send-receive-files/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.sendreceivefiles" diff --git a/openchannel-send-receive-files/src/main/java/com/sendbird/chat/sample/openchannel/sendreceivefiles/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-send-receive-files/src/main/java/com/sendbird/chat/sample/openchannel/sendreceivefiles/ui/openchannel/OpenChannelChatActivity.kt index 2fc362db..be898054 100644 --- a/openchannel-send-receive-files/src/main/java/com/sendbird/chat/sample/openchannel/sendreceivefiles/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-send-receive-files/src/main/java/com/sendbird/chat/sample/openchannel/sendreceivefiles/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.sendreceivefiles.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - - FileUtils.selectFile( - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -514,34 +506,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-structured-data/build.gradle b/openchannel-structured-data/build.gradle index 3bc6c123..11121bbd 100644 --- a/openchannel-structured-data/build.gradle +++ b/openchannel-structured-data/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel" diff --git a/openchannel-structured-data/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-structured-data/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt index d3bd4309..97a0842e 100644 --- a/openchannel-structured-data/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-structured-data/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt @@ -1,12 +1,11 @@ package com.sendbird.chat.sample.openchannel.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.graphics.Color import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -39,13 +38,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -78,11 +74,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -525,36 +517,6 @@ class OpenChannelChatActivity : AppCompatActivity() { currentOpenChannel?.exit {} } - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } - companion object { fun getRandomColor(): Int { return Color.argb(255, Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)) diff --git a/openchannel-threading/build.gradle b/openchannel-threading/build.gradle index 3bc6c123..11121bbd 100644 --- a/openchannel-threading/build.gradle +++ b/openchannel-threading/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel" diff --git a/openchannel-threading/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-threading/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt index 0317a27e..85a42eca 100644 --- a/openchannel-threading/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-threading/src/main/java/com/sendbird/chat/sample/openchannel/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -38,13 +37,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var replayMessageId: Long = -1L - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -77,11 +73,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -528,34 +520,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-thumbnails/build.gradle b/openchannel-thumbnails/build.gradle index 96d95390..0636a431 100644 --- a/openchannel-thumbnails/build.gradle +++ b/openchannel-thumbnails/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.thumbnails" diff --git a/openchannel-thumbnails/src/main/java/com/sendbird/chat/sample/openchannel/thumbnails/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-thumbnails/src/main/java/com/sendbird/chat/sample/openchannel/thumbnails/ui/openchannel/OpenChannelChatActivity.kt index ec11e2fd..383c27ef 100644 --- a/openchannel-thumbnails/src/main/java/com/sendbird/chat/sample/openchannel/thumbnails/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-thumbnails/src/main/java/com/sendbird/chat/sample/openchannel/thumbnails/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.thumbnails.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -513,34 +505,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-update-message/build.gradle b/openchannel-update-message/build.gradle index 2ac66ad5..0b8d5b52 100644 --- a/openchannel-update-message/build.gradle +++ b/openchannel-update-message/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.updatemessage" diff --git a/openchannel-update-message/src/main/java/com/sendbird/chat/sample/openchannel/updatemessage/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-update-message/src/main/java/com/sendbird/chat/sample/openchannel/updatemessage/ui/openchannel/OpenChannelChatActivity.kt index c223eee3..d3b6e331 100644 --- a/openchannel-update-message/src/main/java/com/sendbird/chat/sample/openchannel/updatemessage/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-update-message/src/main/java/com/sendbird/chat/sample/openchannel/updatemessage/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.updatemessage.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -515,34 +507,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file diff --git a/openchannel-user-online/build.gradle b/openchannel-user-online/build.gradle index 55f2a8d6..75467c9b 100644 --- a/openchannel-user-online/build.gradle +++ b/openchannel-user-online/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.sendbird.chat.sample.openchannel.useronline" diff --git a/openchannel-user-online/src/main/java/com/sendbird/chat/sample/openchannel/useronline/ui/openchannel/OpenChannelChatActivity.kt b/openchannel-user-online/src/main/java/com/sendbird/chat/sample/openchannel/useronline/ui/openchannel/OpenChannelChatActivity.kt index 2c1d8ae1..03633d08 100644 --- a/openchannel-user-online/src/main/java/com/sendbird/chat/sample/openchannel/useronline/ui/openchannel/OpenChannelChatActivity.kt +++ b/openchannel-user-online/src/main/java/com/sendbird/chat/sample/openchannel/useronline/ui/openchannel/OpenChannelChatActivity.kt @@ -1,11 +1,10 @@ package com.sendbird.chat.sample.openchannel.useronline.ui.openchannel -import android.Manifest -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView @@ -36,13 +35,10 @@ class OpenChannelChatActivity : AppCompatActivity() { private var isMessageLoading: Boolean = false private var changelogToken: String? = null - private val startForResult = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { data -> + private val pickMedia = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> SendbirdChat.autoBackgroundDetection = true - if (data.resultCode == RESULT_OK) { - val uri = data.data?.data - sendFileMessage(uri) - } + uri?.let { sendFileMessage(it) } } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,11 +71,7 @@ class OpenChannelChatActivity : AppCompatActivity() { override fun onFileMessageSend() { SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this@OpenChannelChatActivity - ) + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } }) } @@ -512,34 +504,4 @@ class OpenChannelChatActivity : AppCompatActivity() { SendbirdChat.autoBackgroundDetection = true currentOpenChannel?.exit {} } - - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - when (requestCode) { - Constants.PERMISSION_REQUEST_CODE -> { - if (grantResults.isNotEmpty()) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showToast(getString(R.string.permission_granted)) - SendbirdChat.autoBackgroundDetection = false - FileUtils.selectFile( - Constants.DATA_TYPE_IMAGE_AND_VIDEO, - startForResult, - this - ) - } else { - if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - Constants.PERMISSION_REQUEST_CODE - ) - } else { - showToast(getString(R.string.permission_denied)) - } - } - } - } - } - } } \ No newline at end of file