Fix sharing

This commit is contained in:
Mario Danic 2020-01-02 14:57:37 +01:00
parent 894bb174f2
commit 436bdeb49f
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
2 changed files with 30 additions and 19 deletions

View File

@ -86,6 +86,10 @@ import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
@ -728,13 +732,14 @@ class ConversationInfoController(args: Bundle) : BaseController(),
} }
shareAction.setOnClickListener { shareAction.setOnClickListener {
GlobalScope.launch {
val sendIntent: Intent = Intent().apply { val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND action = Intent.ACTION_SEND
putExtra( putExtra(
Intent.EXTRA_SUBJECT, Intent.EXTRA_SUBJECT,
String.format( String.format(
context.getString(R.string.nc_share_subject), context.getString(string.nc_share_subject),
context.getString(R.string.nc_app_name) context.getString(string.nc_app_name)
) )
) )
@ -747,10 +752,15 @@ class ConversationInfoController(args: Bundle) : BaseController(),
type = "text/plain" type = "text/plain"
} }
val intent = Intent.createChooser(sendIntent, context.getString(string.nc_share_link)) val intent = Intent.createChooser(sendIntent, context.getString(string.nc_share_link))
withContext(Dispatchers.Main) {
startActivity(intent) startActivity(intent)
} }
}
}
if (allowGuestsAction.value) { if (allowGuestsAction.value) {
passwordAction.visibility = View.VISIBLE passwordAction.visibility = View.VISIBLE
shareAction.visibility = View.VISIBLE shareAction.visibility = View.VISIBLE

View File

@ -34,8 +34,8 @@ object ShareUtils : KoinComponent {
@JvmStatic @JvmStatic
fun getStringForIntent(context: Context?, password: String?, conversation: Conversation): String { fun getStringForIntent(context: Context?, password: String?, conversation: Conversation): String {
val userEntity: UserNgEntity? = usersRepository.getActiveUser()
var shareString = "" var shareString = ""
val userEntity: UserNgEntity? = usersRepository.getActiveUser()
if (userEntity != null && context != null) { if (userEntity != null && context != null) {
shareString = java.lang.String.format(context.resources.getString(R.string.nc_share_text), shareString = java.lang.String.format(context.resources.getString(R.string.nc_share_text),
userEntity.baseUrl, conversation.token) userEntity.baseUrl, conversation.token)
@ -43,6 +43,7 @@ object ShareUtils : KoinComponent {
shareString += String.format(context.resources.getString(R.string.nc_share_text_pass), password) shareString += String.format(context.resources.getString(R.string.nc_share_text_pass), password)
} }
} }
return shareString return shareString
} }
} }