message content filter feature initial implementation

This commit is contained in:
peanut250
2025-07-07 15:30:12 -05:00
parent 4e9e382f69
commit 66f165cccf
23 changed files with 715 additions and 3 deletions
@@ -29,6 +29,7 @@ import dev.octoshrimpy.quik.common.util.extensions.animateLayoutChanges
import dev.octoshrimpy.quik.feature.blocking.manager.BlockingManagerController
import dev.octoshrimpy.quik.feature.blocking.messages.BlockedMessagesController
import dev.octoshrimpy.quik.feature.blocking.numbers.BlockedNumbersController
import dev.octoshrimpy.quik.feature.blocking.filters.MessageContentFiltersController
import dev.octoshrimpy.quik.injection.appComponent
import kotlinx.android.synthetic.main.blocking_controller.*
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
@@ -38,6 +39,7 @@ class BlockingController : QkController<BlockingView, BlockingState, BlockingPre
override val blockingManagerIntent by lazy { blockingManager.clicks() }
override val blockedNumbersIntent by lazy { blockedNumbers.clicks() }
override val messageContentFiltersIntent by lazy { messageContentFilters.clicks() }
override val blockedMessagesIntent by lazy { blockedMessages.clicks() }
override val dropClickedIntent by lazy { drop.clicks() }
@@ -74,6 +76,12 @@ class BlockingController : QkController<BlockingView, BlockingState, BlockingPre
.popChangeHandler(QkChangeHandler()))
}
override fun openMessageContentFilters() {
router.pushController(RouterTransaction.with(MessageContentFiltersController())
.pushChangeHandler(QkChangeHandler())
.popChangeHandler(QkChangeHandler()))
}
override fun openBlockedMessages() {
router.pushController(RouterTransaction.with(BlockedMessagesController())
.pushChangeHandler(QkChangeHandler())
@@ -69,6 +69,10 @@ class BlockingPresenter @Inject constructor(
}
}
view.messageContentFiltersIntent
.autoDisposable(view.scope())
.subscribe { view.openMessageContentFilters() }
view.blockedMessagesIntent
.autoDisposable(view.scope())
.subscribe { view.openBlockedMessages() }
@@ -25,10 +25,12 @@ interface BlockingView : QkViewContract<BlockingState> {
val blockingManagerIntent: Observable<*>
val blockedNumbersIntent: Observable<*>
val messageContentFiltersIntent: Observable<*>
val blockedMessagesIntent: Observable<*>
val dropClickedIntent: Observable<*>
fun openBlockingManager()
fun openBlockedNumbers()
fun openMessageContentFilters()
fun openBlockedMessages()
}
@@ -0,0 +1,55 @@
/*
* 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 dev.octoshrimpy.quik.feature.blocking.filters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.base.QkRealmAdapter
import dev.octoshrimpy.quik.common.base.QkViewHolder
import dev.octoshrimpy.quik.model.MessageContentFilter
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.message_content_filter_list_item.*
import kotlinx.android.synthetic.main.message_content_filter_list_item.view.*
class MessageContentFiltersAdapter : QkRealmAdapter<MessageContentFilter>() {
val removeMessageContentFilter: Subject<Long> = PublishSubject.create()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.message_content_filter_list_item, parent, false)
return QkViewHolder(view).apply {
containerView.removeFilter.setOnClickListener {
val filter = getItem(adapterPosition) ?: return@setOnClickListener
removeMessageContentFilter.onNext(filter.id)
}
}
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val item = getItem(position)!!
holder.caseIcon.visibility = if (item.caseSensitive) View.VISIBLE else View.GONE
holder.regexIcon.visibility = if (item.isRegex) View.VISIBLE else View.GONE
holder.contactsIcon.visibility = if (item.includeContacts) View.VISIBLE else View.GONE
holder.filter.text = item.value
}
}
@@ -0,0 +1,115 @@
/*
* 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 dev.octoshrimpy.quik.feature.blocking.filters
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.jakewharton.rxbinding2.view.clicks
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.base.QkController
import dev.octoshrimpy.quik.common.util.Colors
import dev.octoshrimpy.quik.common.util.extensions.setBackgroundTint
import dev.octoshrimpy.quik.common.util.extensions.setTint
import dev.octoshrimpy.quik.common.widget.PreferenceView
import dev.octoshrimpy.quik.injection.appComponent
import dev.octoshrimpy.quik.model.MessageContentFilterData
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.message_content_filters_add_dialog.view.*
import kotlinx.android.synthetic.main.message_content_filters_controller.*
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
import javax.inject.Inject
class MessageContentFiltersController : QkController<MessageContentFiltersView, MessageContentFiltersState,
MessageContentFiltersPresenter>(), MessageContentFiltersView {
@Inject override lateinit var presenter: MessageContentFiltersPresenter
@Inject lateinit var colors: Colors
private val adapter = MessageContentFiltersAdapter()
private val saveFilterSubject: Subject<MessageContentFilterData> = PublishSubject.create()
init {
appComponent.inject(this)
retainViewMode = RetainViewMode.RETAIN_DETACH
layoutRes = R.layout.message_content_filters_controller
}
override fun onAttach(view: View) {
super.onAttach(view)
presenter.bindIntents(this)
setTitle(R.string.message_content_filters_title)
showBackButton(true)
}
override fun onViewCreated() {
super.onViewCreated()
add.setBackgroundTint(colors.theme().theme)
add.setTint(colors.theme().textPrimary)
adapter.emptyView = empty
filters.adapter = adapter
}
override fun render(state: MessageContentFiltersState) {
adapter.updateData(state.filters)
}
override fun removeFilter(): Observable<Long> = adapter.removeMessageContentFilter
override fun addFilter(): Observable<*> = add.clicks()
override fun saveFilter(): Observable<MessageContentFilterData> = saveFilterSubject
override fun showAddDialog() {
val layout = LayoutInflater.from(activity).inflate(R.layout.message_content_filters_add_dialog, null)
(0 until layout.add_dialog.childCount)
.map { index -> layout.add_dialog.getChildAt(index) }
.mapNotNull { view -> view as? PreferenceView }
.map { preference -> preference.clicks().map { preference } }
.let { Observable.merge(it) }
.autoDisposable(scope())
.subscribe {
it.checkbox.isChecked = !it.checkbox.isChecked
layout.caseSensitivity.isEnabled = !layout.regexp.checkbox.isChecked
}
val dialog = AlertDialog.Builder(activity!!)
.setView(layout)
.setPositiveButton(R.string.message_content_filters_dialog_create) { _, _ ->
var text = layout.input.text.toString();
if (!text.isBlank()) {
if (!layout.regexp.checkbox.isChecked) text = text.trim()
saveFilterSubject.onNext(
MessageContentFilterData(
text,
layout.caseSensitivity.checkbox.isChecked && !layout.regexp.checkbox.isChecked,
layout.regexp.checkbox.isChecked,
layout.contacts.checkbox.isChecked
)
)
}
}
.setNegativeButton(R.string.button_cancel) { _, _ -> }
dialog.show()
}
}
@@ -0,0 +1,55 @@
/*
* 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 dev.octoshrimpy.quik.feature.blocking.filters
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
import dev.octoshrimpy.quik.common.base.QkPresenter
import dev.octoshrimpy.quik.repository.MessageContentFilterRepository
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
class MessageContentFiltersPresenter @Inject constructor(
private val filterRepo: MessageContentFilterRepository,
) : QkPresenter<MessageContentFiltersView, MessageContentFiltersState>(
MessageContentFiltersState(filters = filterRepo.getMessageContentFilters())
) {
override fun bindIntents(view: MessageContentFiltersView) {
super.bindIntents(view)
view.removeFilter()
.observeOn(Schedulers.io())
.doOnNext(filterRepo::removeFilter)
.subscribeOn(Schedulers.io())
.autoDisposable(view.scope())
.subscribe()
view.addFilter()
.autoDisposable(view.scope())
.subscribe { view.showAddDialog() }
view.saveFilter()
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.io())
.autoDisposable(view.scope())
.subscribe { filterData -> filterRepo.createFilter(filterData) }
}
}
@@ -0,0 +1,26 @@
/*
* 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 dev.octoshrimpy.quik.feature.blocking.filters
import dev.octoshrimpy.quik.model.MessageContentFilter
import io.realm.RealmResults
data class MessageContentFiltersState(
val filters: RealmResults<MessageContentFilter>? = null
)
@@ -0,0 +1,33 @@
/*
* 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 dev.octoshrimpy.quik.feature.blocking.filters
import dev.octoshrimpy.quik.common.base.QkViewContract
import dev.octoshrimpy.quik.model.MessageContentFilterData
import io.reactivex.Observable
interface MessageContentFiltersView : QkViewContract<MessageContentFiltersState> {
fun removeFilter(): Observable<Long>
fun addFilter(): Observable<*>
fun saveFilter(): Observable<MessageContentFilterData>
fun showAddDialog()
}