mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-22 21:58:53 +01:00
Show button to add new contact
This commit is contained in:
@@ -41,6 +41,7 @@ import androidx.lifecycle.ViewModelProviders
|
|||||||
import com.google.android.flexbox.FlexboxLayoutManager
|
import com.google.android.flexbox.FlexboxLayoutManager
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.jakewharton.rxbinding2.view.clicks
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
|
import com.jakewharton.rxbinding2.widget.editorActions
|
||||||
import com.jakewharton.rxbinding2.widget.textChanges
|
import com.jakewharton.rxbinding2.widget.textChanges
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.Navigator
|
import com.moez.QKSMS.common.Navigator
|
||||||
@@ -86,9 +87,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||||
|
|
||||||
override val activityVisibleIntent: Subject<Boolean> = PublishSubject.create()
|
override val activityVisibleIntent: Subject<Boolean> = PublishSubject.create()
|
||||||
override val queryChangedIntent: Observable<CharSequence> by lazy { chipsAdapter.textChanges }
|
override val queryChangedIntent: Observable<CharSequence> by lazy { search.textChanges() }
|
||||||
override val queryBackspaceIntent: Observable<*> by lazy { chipsAdapter.backspaces }
|
override val queryBackspaceIntent: Observable<*> by lazy { search.backspaces }
|
||||||
override val queryEditorActionIntent: Observable<Int> by lazy { chipsAdapter.actions }
|
override val queryEditorActionIntent: Observable<Int> by lazy { search.editorActions() }
|
||||||
override val chipSelectedIntent: Subject<ComposeItem> by lazy { contactsAdapter.itemSelected }
|
override val chipSelectedIntent: Subject<ComposeItem> by lazy { contactsAdapter.itemSelected }
|
||||||
override val chipDeletedIntent: Subject<Contact> by lazy { chipsAdapter.chipDeleted }
|
override val chipDeletedIntent: Subject<Contact> by lazy { chipsAdapter.chipDeleted }
|
||||||
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
|
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
|
||||||
@@ -191,14 +192,16 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
toolbarSubtitle.text = getString(R.string.compose_subtitle_results, state.searchSelectionPosition, state.searchResults)
|
toolbarSubtitle.text = getString(R.string.compose_subtitle_results, state.searchSelectionPosition, state.searchResults)
|
||||||
|
|
||||||
toolbarTitle.setVisible(!state.editingMode)
|
toolbarTitle.setVisible(!state.editingMode)
|
||||||
chips.setVisible(state.editingMode)
|
chips.setVisible(state.editingMode && !state.searching)
|
||||||
contacts.setVisible(state.contactsVisible)
|
search.setVisible(state.editingMode && state.searching)
|
||||||
composeBar.setVisible(!state.contactsVisible && !state.loading)
|
contacts.setVisible(state.editingMode && state.searching)
|
||||||
|
composeBar.setVisible(!state.searching && !state.loading)
|
||||||
|
|
||||||
// Don't set the adapters unless needed
|
// Don't set the adapters unless needed
|
||||||
if (state.editingMode && chips.adapter == null) chips.adapter = chipsAdapter
|
if (state.editingMode && chips.adapter == null) chips.adapter = chipsAdapter
|
||||||
if (state.editingMode && contacts.adapter == null) contacts.adapter = contactsAdapter
|
if (state.editingMode && contacts.adapter == null) contacts.adapter = contactsAdapter
|
||||||
|
|
||||||
|
toolbar.menu.findItem(R.id.add)?.isVisible = state.editingMode && !state.searching
|
||||||
toolbar.menu.findItem(R.id.call)?.isVisible = !state.editingMode && state.selectedMessages == 0 && state.query.isEmpty()
|
toolbar.menu.findItem(R.id.call)?.isVisible = !state.editingMode && state.selectedMessages == 0 && state.query.isEmpty()
|
||||||
toolbar.menu.findItem(R.id.info)?.isVisible = !state.editingMode && state.selectedMessages == 0 && state.query.isEmpty()
|
toolbar.menu.findItem(R.id.info)?.isVisible = !state.editingMode && state.selectedMessages == 0 && state.query.isEmpty()
|
||||||
toolbar.menu.findItem(R.id.copy)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
toolbar.menu.findItem(R.id.copy)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ import io.realm.RealmResults
|
|||||||
data class ComposeState(
|
data class ComposeState(
|
||||||
val hasError: Boolean = false,
|
val hasError: Boolean = false,
|
||||||
val editingMode: Boolean = false,
|
val editingMode: Boolean = false,
|
||||||
|
val searching: Boolean = false,
|
||||||
val composeItems: List<ComposeItem> = ArrayList(),
|
val composeItems: List<ComposeItem> = ArrayList(),
|
||||||
val contactsVisible: Boolean = false,
|
|
||||||
val selectedConversation: Long = 0,
|
val selectedConversation: Long = 0,
|
||||||
val selectedContacts: List<Contact> = ArrayList(),
|
val selectedContacts: List<Contact> = ArrayList(),
|
||||||
val sendAsGroup: Boolean = true,
|
val sendAsGroup: Boolean = true,
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
private val syncContacts: ContactSync
|
private val syncContacts: ContactSync
|
||||||
) : QkViewModel<ComposeView, ComposeState>(ComposeState(
|
) : QkViewModel<ComposeView, ComposeState>(ComposeState(
|
||||||
editingMode = threadId == 0L && address.isBlank(),
|
editingMode = threadId == 0L && address.isBlank(),
|
||||||
|
searching = threadId == 0L && address.isBlank(),
|
||||||
selectedConversation = threadId,
|
selectedConversation = threadId,
|
||||||
query = query)
|
query = query)
|
||||||
) {
|
) {
|
||||||
@@ -243,17 +244,13 @@ class ComposeViewModel @Inject constructor(
|
|||||||
override fun bindView(view: ComposeView) {
|
override fun bindView(view: ComposeView) {
|
||||||
super.bindView(view)
|
super.bindView(view)
|
||||||
|
|
||||||
// Set the contact suggestions list to visible at all times when in editing mode and there are no contacts
|
// Set the contact suggestions list to visible when the add button is pressed
|
||||||
// selected yet, and also visible while in editing mode and there is text entered in the query field
|
view.optionsItemIntent
|
||||||
Observables
|
.filter { it == R.id.add }
|
||||||
.combineLatest(view.queryChangedIntent, selectedContacts) { query, selectedContacts ->
|
|
||||||
selectedContacts.isEmpty() || query.isNotEmpty()
|
|
||||||
}
|
|
||||||
.skipUntil(state.filter { state -> state.editingMode })
|
.skipUntil(state.filter { state -> state.editingMode })
|
||||||
.takeUntil(state.filter { state -> !state.editingMode })
|
.takeUntil(state.filter { state -> !state.editingMode })
|
||||||
.distinctUntilChanged()
|
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { contactsVisible -> newState { copy(contactsVisible = contactsVisible && editingMode) } }
|
.subscribe { newState { copy(searching = true) } }
|
||||||
|
|
||||||
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
||||||
// that have already been selected
|
// that have already been selected
|
||||||
@@ -318,6 +315,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
.withLatestFrom(state) { _, state -> state }
|
.withLatestFrom(state) { _, state -> state }
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { state ->
|
.subscribe { state ->
|
||||||
|
newState { copy(searching = false) }
|
||||||
state.composeItems.firstOrNull()?.let { composeItem ->
|
state.composeItems.firstOrNull()?.let { composeItem ->
|
||||||
contactsReducer.onNext { contacts -> contacts + composeItem.getContacts() }
|
contactsReducer.onNext { contacts -> contacts + composeItem.getContacts() }
|
||||||
}
|
}
|
||||||
@@ -329,6 +327,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
contactsReducer.onNext { contacts -> contacts.filterNot { it == contact } }
|
contactsReducer.onNext { contacts -> contacts.filterNot { it == contact } }
|
||||||
},
|
},
|
||||||
view.chipSelectedIntent.doOnNext { composeItem ->
|
view.chipSelectedIntent.doOnNext { composeItem ->
|
||||||
|
newState { copy(searching = false) }
|
||||||
contactsReducer.onNext { contacts ->
|
contactsReducer.onNext { contacts ->
|
||||||
contacts.toMutableList().apply { addAll(composeItem.getContacts()) }
|
contacts.toMutableList().apply { addAll(composeItem.getContacts()) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,103 +20,49 @@ package com.moez.QKSMS.feature.compose.editing
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.flexbox.FlexboxLayoutManager
|
|
||||||
import com.jakewharton.rxbinding2.widget.editorActions
|
|
||||||
import com.jakewharton.rxbinding2.widget.textChanges
|
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.base.QkAdapter
|
import com.moez.QKSMS.common.base.QkAdapter
|
||||||
import com.moez.QKSMS.common.base.QkViewHolder
|
import com.moez.QKSMS.common.base.QkViewHolder
|
||||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
|
||||||
import com.moez.QKSMS.common.util.extensions.showKeyboard
|
|
||||||
import com.moez.QKSMS.common.widget.QkEditText
|
|
||||||
import com.moez.QKSMS.model.Contact
|
import com.moez.QKSMS.model.Contact
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import kotlinx.android.synthetic.main.contact_chip.view.*
|
import kotlinx.android.synthetic.main.contact_chip.view.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ChipsAdapter @Inject constructor(private val context: Context) : QkAdapter<Contact>() {
|
class ChipsAdapter @Inject constructor() : QkAdapter<Contact>() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TYPE_EDIT_TEXT = 0
|
|
||||||
private const val TYPE_ITEM = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
private val hint: String = context.getString(R.string.title_compose)
|
|
||||||
private val editText = View.inflate(context, R.layout.chip_input_list_item, null) as QkEditText
|
|
||||||
|
|
||||||
var view: RecyclerView? = null
|
var view: RecyclerView? = null
|
||||||
val chipDeleted: PublishSubject<Contact> = PublishSubject.create<Contact>()
|
val chipDeleted: PublishSubject<Contact> = PublishSubject.create<Contact>()
|
||||||
val textChanges = editText.textChanges()
|
|
||||||
val actions = editText.editorActions()
|
|
||||||
val backspaces = editText.backspaces
|
|
||||||
|
|
||||||
init {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||||
val wrap = ViewGroup.LayoutParams.WRAP_CONTENT
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
editText.layoutParams = FlexboxLayoutManager.LayoutParams(wrap, wrap).apply {
|
val view = inflater.inflate(R.layout.contact_chip, parent, false)
|
||||||
minHeight = 36.dpToPx(context)
|
return QkViewHolder(view).apply {
|
||||||
minWidth = 56.dpToPx(context)
|
view.setOnClickListener {
|
||||||
flexGrow = 8f
|
val contact = getItem(adapterPosition)
|
||||||
}
|
showDetailedChip(view.context, contact)
|
||||||
|
|
||||||
editText.hint = hint
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDatasetChanged() {
|
|
||||||
editText.text = null
|
|
||||||
editText.hint = if (itemCount == 1) hint else null
|
|
||||||
|
|
||||||
if (itemCount != 2) {
|
|
||||||
editText.showKeyboard()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
|
|
||||||
TYPE_EDIT_TEXT -> {
|
|
||||||
editText.setTextColor(parent.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
|
||||||
editText.setHintTextColor(parent.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
|
||||||
QkViewHolder(editText)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
val inflater = LayoutInflater.from(parent.context)
|
|
||||||
val view = inflater.inflate(R.layout.contact_chip, parent, false)
|
|
||||||
QkViewHolder(view).apply {
|
|
||||||
view.setOnClickListener {
|
|
||||||
val contact = getItem(adapterPosition)
|
|
||||||
showDetailedChip(view.context, contact)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
when (getItemViewType(position)) {
|
val contact = getItem(position)
|
||||||
TYPE_ITEM -> {
|
val view = holder.containerView
|
||||||
val contact = getItem(position)
|
|
||||||
val view = holder.containerView
|
|
||||||
|
|
||||||
view.avatar.setContact(contact)
|
view.avatar.setContact(contact)
|
||||||
|
|
||||||
// If the contact's name is empty, try to display a phone number instead
|
// If the contact's name is empty, try to display a phone number instead
|
||||||
// The contacts provided here should only have one number
|
// The contacts provided here should only have one number
|
||||||
view.name.text = if (contact.name.isNotBlank()) {
|
view.name.text = if (contact.name.isNotBlank()) {
|
||||||
contact.name
|
contact.name
|
||||||
} else {
|
} else {
|
||||||
contact.numbers.firstOrNull { it.address.isNotBlank() }?.address ?: ""
|
contact.numbers.firstOrNull { it.address.isNotBlank() }?.address ?: ""
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount() = super.getItemCount() + 1
|
|
||||||
|
|
||||||
override fun getItemViewType(position: Int) = if (position == itemCount - 1) TYPE_EDIT_TEXT else TYPE_ITEM
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The [context] has to come from a view, because we're inflating a view that used themed attrs
|
* The [context] has to come from a view, because we're inflating a view that used themed attrs
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -376,6 +376,20 @@
|
|||||||
android:scrollbars="vertical"
|
android:scrollbars="vertical"
|
||||||
tools:visibility="gone" />
|
tools:visibility="gone" />
|
||||||
|
|
||||||
|
<com.moez.QKSMS.common.widget.QkEditText
|
||||||
|
android:id="@+id/search"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@null"
|
||||||
|
android:hint="@string/title_compose"
|
||||||
|
android:imeOptions="flagNoExtractUi"
|
||||||
|
android:inputType="textFilter|textNoSuggestions"
|
||||||
|
android:privateImeOptions="nm"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textColorHint="?android:attr/textColorTertiary"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:textSize="primary" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.appcompat.widget.Toolbar>
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|||||||
@@ -20,6 +20,13 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/add"
|
||||||
|
android:icon="@drawable/ic_person_add_black_24dp"
|
||||||
|
android:title="@string/menu_add_person"
|
||||||
|
android:visible="false"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/call"
|
android:id="@+id/call"
|
||||||
android:icon="@drawable/ic_call_white_24dp"
|
android:icon="@drawable/ic_call_white_24dp"
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
<string name="setup_skip">Skip</string>
|
<string name="setup_skip">Skip</string>
|
||||||
<string name="setup_next">Continue</string>
|
<string name="setup_next">Continue</string>
|
||||||
|
|
||||||
|
<string name="menu_add_person">Add person</string>
|
||||||
<string name="menu_call">Call</string>
|
<string name="menu_call">Call</string>
|
||||||
<string name="menu_info">Details</string>
|
<string name="menu_info">Details</string>
|
||||||
<string name="menu_save">Save to gallery</string>
|
<string name="menu_save">Save to gallery</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user