#1010 - Message content search

This commit is contained in:
Moez Bhatti
2018-05-17 15:31:34 -04:00
parent 8374386734
commit e3307bf3dc
31 changed files with 540 additions and 91 deletions
@@ -84,9 +84,10 @@ class Navigator @Inject constructor(private val context: Context, private val no
startActivity(intent)
}
fun showConversation(threadId: Long) {
fun showConversation(threadId: Long, query: String? = null) {
val intent = Intent(context, ComposeActivity::class.java)
intent.putExtra("threadId", threadId)
.putExtra("threadId", threadId)
.putExtra("query", query)
startActivity(intent)
}
@@ -20,8 +20,6 @@ package common.base
import android.support.annotation.CallSuper
import android.support.v7.widget.RecyclerView
import android.view.View
import common.util.extensions.setVisible
import io.reactivex.Flowable
import io.reactivex.disposables.Disposable
@@ -31,16 +29,6 @@ import io.reactivex.disposables.Disposable
*/
abstract class FlowableAdapter<T> : QkAdapter<T>() {
/**
* This view can be set, and the adapter will automatically control the visibility of this view
* based on the data
*/
var emptyView: View? = null
set(value) {
field = value
value?.setVisible(false)
}
var flowable: Flowable<List<T>>? = null
set(value) {
if (field === value) return
@@ -83,7 +71,6 @@ abstract class FlowableAdapter<T> : QkAdapter<T>() {
private fun subscribe() {
disposable = flowable?.subscribe {
data = it
emptyView?.setVisible(data.isEmpty())
}
}
@@ -20,6 +20,8 @@ package common.base
import android.support.v7.util.DiffUtil
import android.support.v7.widget.RecyclerView
import android.view.View
import common.util.extensions.setVisible
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
@@ -36,7 +38,18 @@ abstract class QkAdapter<T> : RecyclerView.Adapter<QkViewHolder>() {
val diff = DiffUtil.calculateDiff(getDiffUtilCallback(field, value))
field = value
diff.dispatchUpdatesTo(this)
onDatasetChanged()
emptyView?.setVisible(value.isEmpty())
}
/**
* This view can be set, and the adapter will automatically control the visibility of this view
* based on the data
*/
var emptyView: View? = null
set(value) {
field = value
value?.setVisible(false)
}
val selectionChanges: Subject<List<Long>> = BehaviorSubject.create()
@@ -56,6 +56,8 @@ abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkVi
}
override fun updateData(data: OrderedRealmCollection<T>?) {
if (getData() === data) return
removeListener(getData())
addListener(data)
@@ -82,14 +82,14 @@ abstract class QkThemedActivity : QkActivity() {
super.onPostCreate(savedInstanceState)
// Update the colours of the menu items
Observables.combineLatest(menu, theme, colors.textTertiary, { menu, theme, textTertiary ->
Observables.combineLatest(menu, theme, colors.textSecondary, { menu, theme, text ->
(0 until menu.size())
.map { position -> menu.getItem(position) }
.forEach { menuItem ->
menuItem?.icon?.run {
setTint(when (menuItem.itemId) {
R.id.info -> textTertiary
else -> theme
in getColoredMenuItems() -> theme
else -> text
})
menuItem.icon = this
@@ -119,6 +119,10 @@ abstract class QkThemedActivity : QkActivity() {
.subscribe { color -> toolbar?.setBackgroundTint(color) }
}
open fun getColoredMenuItems(): List<Int> {
return listOf()
}
/**
* This can be overridden in case an activity does not want to use the default themes
*/
@@ -204,6 +204,11 @@ class Colors @Inject constructor(private val context: Context, private val prefs
.map { res -> getColor(res) }
.distinctUntilChanged()
val highlightColor: Observable<Int> = theme
.map { theme -> FloatArray(3).apply { Color.colorToHSV(theme, this) } }
.map { hsv -> hsv.apply { set(2, 0.75f) } } // 75% value
.map { hsv -> Color.HSVToColor(85, hsv) } // 33% alpha
val textPrimaryOnTheme = textPrimaryOnThemeForConversation()
val textSecondaryOnTheme = textSecondaryOnThemeForConversation()
@@ -1,32 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.filter
import model.Contact
import util.extensions.removeAccents
import javax.inject.Inject
class ContactFilter @Inject constructor(private val phoneNumberFilter: PhoneNumberFilter) : Filter<Contact>() {
override fun filter(item: Contact, query: CharSequence): Boolean {
return item.name.removeAccents().contains(query, true) || // Name
item.numbers.map { it.address }.any { address -> phoneNumberFilter.filter(address, query) } // Number
}
}
@@ -1,30 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.filter
import model.Conversation
import javax.inject.Inject
class ConversationFilter @Inject constructor(private val recipientFilter: RecipientFilter) : Filter<Conversation>() {
override fun filter(item: Conversation, query: CharSequence): Boolean {
return item.recipients.any { recipient -> recipientFilter.filter(recipient, query) }
}
}
@@ -1,25 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.filter
abstract class Filter<in T> {
abstract fun filter(item: T, query: CharSequence): Boolean
}
@@ -1,33 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.filter
import android.telephony.PhoneNumberUtils
import javax.inject.Inject
class PhoneNumberFilter @Inject constructor() : Filter<String>() {
override fun filter(item: String, query: CharSequence): Boolean {
val allCharactersDialable = query.all { PhoneNumberUtils.isReallyDialable(it) }
return allCharactersDialable && (PhoneNumberUtils.compare(item, query.toString()) ||
PhoneNumberUtils.stripSeparators(item).contains(PhoneNumberUtils.stripSeparators(query.toString())))
}
}
@@ -1,35 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.filter
import model.Recipient
import javax.inject.Inject
class RecipientFilter @Inject constructor(
private val contactFilter: ContactFilter,
private val phoneNumberFilter: PhoneNumberFilter)
: Filter<Recipient>() {
override fun filter(item: Recipient, query: CharSequence) = when {
item.contact?.let { contactFilter.filter(it, query) } == true -> true
phoneNumberFilter.filter(item.address, query) -> true
else -> false
}
}