talk-android/app/src/main/java/com/nextcloud/talk/utils/ShareUtils.kt
sowjanyakch acd0b92b6c
Pretty URL for conversation link
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
2024-05-08 13:53:44 +02:00

59 lines
1.6 KiB
Kotlin

/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2017 Mario Danic <mario@lovelyhq.com>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.utils
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.net.Uri
import com.nextcloud.talk.R
object ShareUtils {
@SuppressLint("StringFormatMatches")
fun shareConversationLink(
context: Activity,
baseUrl: String?,
roomToken: String?,
conversationName: String?,
canGeneratePrettyURL: Boolean
) {
if (baseUrl.isNullOrBlank() || roomToken.isNullOrBlank() || conversationName.isNullOrBlank()) {
return
}
val uriBuilder = Uri.parse(baseUrl)
.buildUpon()
if (!canGeneratePrettyURL) {
uriBuilder.appendPath("index.php")
}
uriBuilder.appendPath("call")
uriBuilder.appendPath(roomToken)
val uriToShareConversation = uriBuilder.build()
val shareConversationLink = String.format(
context.getString(
R.string.share_link_to_conversation,
conversationName,
uriToShareConversation.toString()
)
)
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, shareConversationLink)
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, context.getString(R.string.nc_share_link))
context.startActivity(shareIntent)
}
}