diff --git a/presentation/src/main/java/common/Navigator.kt b/presentation/src/main/java/common/Navigator.kt index 3c04d7c5..c2594f81 100644 --- a/presentation/src/main/java/common/Navigator.kt +++ b/presentation/src/main/java/common/Navigator.kt @@ -88,9 +88,14 @@ class Navigator @Inject constructor(private val context: Context, private val no startActivity(intent) } - fun showCompose(body: String? = null) { + fun showCompose(body: String? = null, images: List? = null) { val intent = Intent(context, ComposeActivity::class.java) intent.putExtra(Intent.EXTRA_TEXT, body) + + images?.takeIf { it.isNotEmpty() }?.let { + intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(images)) + } + startActivity(intent) } diff --git a/presentation/src/main/java/feature/compose/ComposeViewModel.kt b/presentation/src/main/java/feature/compose/ComposeViewModel.kt index 5af55169..a8502fe2 100644 --- a/presentation/src/main/java/feature/compose/ComposeViewModel.kt +++ b/presentation/src/main/java/feature/compose/ComposeViewModel.kt @@ -25,6 +25,7 @@ import android.telephony.PhoneNumberUtils import android.telephony.SmsMessage import android.view.KeyEvent import android.view.inputmethod.EditorInfo +import androidx.net.toUri import com.mlsdev.rximagepicker.RxImagePicker import com.mlsdev.rximagepicker.Sources import com.moez.QKSMS.R @@ -58,6 +59,7 @@ import model.PhoneNumber import repository.ContactRepository import repository.MessageRepository import util.extensions.asObservable +import util.extensions.isImage import java.net.URLDecoder import java.util.* import java.util.concurrent.TimeUnit @@ -210,7 +212,8 @@ class ComposeViewModel(intent: Intent) : QkViewModel( // If the entry is a valid destination, allow it as a recipient if (PhoneNumberUtils.isWellFormedSmsAddress(query.toString())) { val newAddress = PhoneNumberUtils.formatNumber(query.toString(), Locale.getDefault().country) - val newContact = Contact(numbers = RealmList(PhoneNumber(address = newAddress ?: query.toString()))) + val newContact = Contact(numbers = RealmList(PhoneNumber(address = newAddress + ?: query.toString()))) filteredContacts = listOf(newContact) + filteredContacts } @@ -398,7 +401,10 @@ class ComposeViewModel(intent: Intent) : QkViewModel( // Forward the message view.forwardMessageIntent .autoDisposable(view.scope()) - .subscribe { message -> navigator.showCompose(message.body) } + .subscribe { message -> + val images = message.parts.filter { it.isImage() }.mapNotNull { it.image?.toUri() } + navigator.showCompose(message.body, images) + } // Delete the selected message view.deleteMessageIntent