Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b56111ab authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Allow sharing vCard from other apps

parent 057806e9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -90,6 +90,11 @@
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/x-vcard" />
            </intent-filter>

            <meta-data
                android:name="android.service.chooser.chooser_target_service"
+23 −5
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ package com.moez.QKSMS.feature.compose

import android.content.Intent
import android.net.Uri
import androidx.core.net.toFile
import androidx.lifecycle.ViewModel
import com.google.android.mms.ContentType
import com.moez.QKSMS.injection.ViewModelKey
import com.moez.QKSMS.model.Attachment
import com.moez.QKSMS.model.Attachments
@@ -28,6 +30,7 @@ import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import java.net.URLDecoder
import java.nio.charset.Charset
import javax.inject.Named

@Module
@@ -73,10 +76,25 @@ class ComposeActivityModule {
    @Provides
    @Named("attachments")
    fun provideSharedAttachments(activity: ComposeActivity): Attachments {
        val sharedImages = mutableListOf<Uri>()
        activity.intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)?.run(sharedImages::add)
        activity.intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)?.run(sharedImages::addAll)
        return Attachments(sharedImages.map { Attachment.Image(it) })
        val uris = mutableListOf<Uri>()
        activity.intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)?.run(uris::add)
        activity.intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)?.run(uris::addAll)
        return Attachments(uris.mapNotNull { uri ->
            val mimeType = activity.contentResolver.getType(uri)
            when {
                ContentType.isImageType(mimeType) -> {
                    Attachment.Image(uri)
                }

                ContentType.TEXT_VCARD.equals(mimeType, true) -> {
                    val inputStream = activity.contentResolver.openInputStream(uri)
                    val text = inputStream?.reader(Charset.forName("utf-8"))?.readText()
                    text?.let(Attachment::Contact)
                }

                else -> null
            }
        })
    }

    @Provides