forked from upstream-mirrors/quik
Launch ComposeActivity directly from other apps, load address from intent
This commit is contained in:
@@ -27,15 +27,16 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="presentation.feature.compose.ComposeActivity"
|
||||
android:parentActivityName="presentation.feature.main.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<action android:name="android.intent.action.SENDTO" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
<data android:scheme="sms" />
|
||||
<data android:scheme="smsto" />
|
||||
@@ -44,9 +45,6 @@
|
||||
<data android:scheme="sms_body" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="presentation.feature.compose.ComposeActivity"
|
||||
android:parentActivityName="presentation.feature.main.MainActivity" />
|
||||
<activity android:name="presentation.feature.settings.SettingsActivity" />
|
||||
<activity android:name="presentation.feature.setup.SetupActivity" />
|
||||
|
||||
|
||||
@@ -105,9 +105,7 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
}
|
||||
|
||||
ComposeViewModel::class.java -> {
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
val body = intent.getStringExtra("body") ?: ""
|
||||
ComposeViewModel(threadId, body)
|
||||
ComposeViewModel(intent)
|
||||
}
|
||||
|
||||
SettingsViewModel::class.java -> {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package presentation.feature.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.moez.QKSMS.R
|
||||
import common.di.appComponent
|
||||
import common.util.ClipboardUtils
|
||||
@@ -30,8 +31,6 @@ import data.model.Conversation
|
||||
import data.repository.ContactRepository
|
||||
import data.repository.MessageRepository
|
||||
import interactor.*
|
||||
import presentation.common.Navigator
|
||||
import presentation.common.base.QkViewModel
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
@@ -40,10 +39,13 @@ import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import presentation.common.Navigator
|
||||
import presentation.common.base.QkViewModel
|
||||
import timber.log.Timber
|
||||
import java.net.URLDecoder
|
||||
import javax.inject.Inject
|
||||
|
||||
class ComposeViewModel(threadId: Long, var draft: String)
|
||||
: QkViewModel<ComposeView, ComposeState>(ComposeState(editingMode = threadId == 0L)) {
|
||||
class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(ComposeState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var contactFilter: ContactFilter
|
||||
@@ -58,6 +60,7 @@ class ComposeViewModel(threadId: Long, var draft: String)
|
||||
@Inject lateinit var markRead: MarkRead
|
||||
@Inject lateinit var deleteMessage: DeleteMessage
|
||||
|
||||
private var draft: String = ""
|
||||
private val contacts: List<Contact> by lazy { contactsRepo.getContacts() }
|
||||
private val contactsReducer: Subject<(List<Contact>) -> List<Contact>> = PublishSubject.create()
|
||||
private val selectedContacts: Observable<List<Contact>>
|
||||
@@ -66,6 +69,24 @@ class ComposeViewModel(threadId: Long, var draft: String)
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
val threadId = intent.extras?.getLong("threadId") ?: 0L
|
||||
draft = intent.extras?.getString("draft") ?: ""
|
||||
|
||||
intent.data?.let {
|
||||
val data = URLDecoder.decode(it.toString(), "utf-8")
|
||||
val scheme = it.scheme
|
||||
val address = when {
|
||||
scheme.startsWith("smsto") -> data.replace("smsto:", "")
|
||||
scheme.startsWith("mmsto") -> data.replace("mmsto:", "")
|
||||
scheme.startsWith("sms") -> data.replace("sms:", "")
|
||||
scheme.startsWith("mms") -> data.replace("mms:", "")
|
||||
else -> ""
|
||||
}
|
||||
Timber.v("address: $address")
|
||||
}
|
||||
|
||||
newState { ComposeState(editingMode = threadId == 0L) }
|
||||
|
||||
selectedContacts = contactsReducer
|
||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
||||
@@ -213,7 +234,7 @@ class ComposeViewModel(threadId: Long, var draft: String)
|
||||
sendMessage.execute(SendMessage.Params(threadId, address, body))
|
||||
view.setDraft("")
|
||||
})
|
||||
.withLatestFrom(state, {_, state ->
|
||||
.withLatestFrom(state, { _, state ->
|
||||
if (state.editingMode) {
|
||||
newState { it.copy(editingMode = false) }
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package presentation.feature.main
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.StateListDrawable
|
||||
@@ -48,8 +47,8 @@ import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.drawer_view.*
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
import kotlinx.android.synthetic.main.toolbar_search.*
|
||||
import presentation.common.Navigator
|
||||
import presentation.common.MenuItemAdapter
|
||||
import presentation.common.Navigator
|
||||
import presentation.common.base.QkActivity
|
||||
import presentation.feature.conversations.ConversationItemTouchCallback
|
||||
import presentation.feature.conversations.ConversationsAdapter
|
||||
@@ -177,13 +176,6 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
})
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
intent?.getLongExtra("threadId", 0)
|
||||
?.takeIf { threadId -> threadId > 0 }
|
||||
?.let { threadId -> navigator.showConversation(threadId) }
|
||||
}
|
||||
|
||||
override fun render(state: MainState) {
|
||||
toolbarSearch.isEnabled = state.page is Inbox
|
||||
toolbarSearch.textSize = if (state.page is Inbox) 16f else 20f
|
||||
|
||||
Reference in New Issue
Block a user