@@ -53,7 +53,7 @@ fun Uri.getFileSize(context: Context): Int {
5353 return fileSize?.toIntOrNull() ? : - 1
5454}
5555
56- fun Uri.getMimeType (context : Context ): String {
56+ fun Uri.getMimeType (context : Context ): String? {
5757 return if (scheme == ContentResolver .SCHEME_CONTENT ) {
5858 context.contentResolver?.getType(this ) ? : " "
5959 } else {
@@ -121,7 +121,7 @@ fun Uri.getDeepLinkInfo(context: Context): DeepLinkInfo? {
121121 return when {
122122 isAuthenticationDeepLink(context) -> {
123123 val host = getQueryParameter(" host" )
124- val url = if (host.startsWith(" http" )) host else " https://$host "
124+ val url = if (host? .startsWith(" http" ) == true ) host else " https://$host "
125125 val userId = getQueryParameter(" userId" )
126126 val token = getQueryParameter(" token" )
127127 try {
@@ -133,12 +133,12 @@ fun Uri.getDeepLinkInfo(context: Context): DeepLinkInfo? {
133133 }
134134 isCustomSchemeRoomLink() -> {
135135 val hostValue = getQueryParameter(" host" )
136- val url = if (hostValue.startsWith(" http" )) hostValue else " https://$hostValue "
136+ val url = if (hostValue? .startsWith(" http" ) == true ) hostValue else " https://$hostValue "
137137 val rid = getQueryParameter(" rid" )
138138 val pathValue = getQueryParameter(" path" )
139- val pathSplit = pathValue.split(" /" )
140- val roomType = pathSplit[ 0 ]
141- val roomName = pathSplit[ 1 ]
139+ val pathSplit = pathValue? .split(" /" )
140+ val roomType = pathSplit?.get( 0 )
141+ val roomName = pathSplit?.get( 1 )
142142 try {
143143 DeepLinkInfo (url, null , null , rid, roomType, roomName)
144144 } catch (ex: Exception ) {
@@ -148,9 +148,9 @@ fun Uri.getDeepLinkInfo(context: Context): DeepLinkInfo? {
148148 }
149149 isWebSchemeRoomLink() -> {
150150 val url = " https://$host "
151- val pathSplit = path.split(" /" )
152- val roomType = pathSplit[ 1 ]
153- val roomName = pathSplit[ 2 ]
151+ val pathSplit = path? .split(" /" )
152+ val roomType = pathSplit?.get( 1 )
153+ val roomName = pathSplit?.get( 2 )
154154 try {
155155 DeepLinkInfo (url, null , null , null , roomType, roomName)
156156 } catch (ex: Exception ) {
@@ -163,7 +163,7 @@ fun Uri.getDeepLinkInfo(context: Context): DeepLinkInfo? {
163163}
164164
165165fun Uri.isDynamicLink (activity : Activity ): Boolean {
166- return (host != null && host.contains(activity.getString(R .string.dynamic_link_host_url)))
166+ return (host != null && host? .contains(activity.getString(R .string.dynamic_link_host_url)) == true )
167167}
168168
169169// Authentication deep link defined here: https://rocket.chat/docs/developer-guides/deeplink/#authentication
@@ -177,17 +177,11 @@ fun Uri.isAuthenticationDeepLink(context: Context): Boolean {
177177
178178// Custom scheme room deep link defined here: https://rocket.chat/docs/developer-guides/deeplink/#channel--group--dm
179179fun Uri.isCustomSchemeRoomLink (): Boolean {
180- if (scheme.startsWith(" rocketchat" ) &&
181- host == " room" )
182- return true
183- return false
180+ return (scheme?.startsWith(" rocketchat" )) == true && host == " room"
184181}
185182
186183// http(s) scheme deep link not yet documented. Ex: https://open.rocket.chat/direct/testuser1
187184fun Uri.isWebSchemeRoomLink (): Boolean {
188- val roomType = path.split(" /" )[1 ]
189- if (scheme.startsWith(" http" ) &&
190- (roomType == " channel" || roomType == " group" || roomType == " direct" ))
191- return true
192- return false
185+ val roomType = path?.split(" /" )?.get(1 )
186+ return (scheme?.startsWith(" http" )) == true && (roomType == " channel" || roomType == " group" || roomType == " direct" )
193187}
0 commit comments