Build out blocking client for pre api 24 devices

This commit is contained in:
moezbhatti
2019-06-26 02:01:46 -04:00
parent c04a368cc8
commit 83090452b5
19 changed files with 624 additions and 38 deletions
@@ -1,3 +1,21 @@
/*
* 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 com.moez.QKSMS.feature.blocking
import android.view.View
@@ -10,6 +28,7 @@ import com.moez.QKSMS.common.base.QkController
import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.feature.blocking.manager.BlockingManagerController
import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController
import com.moez.QKSMS.injection.appComponent
import io.reactivex.Observable
import kotlinx.android.synthetic.main.blocking_controller.*
@@ -61,4 +80,10 @@ class BlockingController : QkController<BlockingView, BlockingState, BlockingPre
.popChangeHandler(QkChangeHandler()))
}
override fun openBlockedNumbers() {
router.pushController(RouterTransaction.with(BlockedNumbersController())
.pushChangeHandler(QkChangeHandler())
.popChangeHandler(QkChangeHandler()))
}
}
@@ -1,3 +1,21 @@
/*
* 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 com.moez.QKSMS.feature.blocking
import android.app.Activity
@@ -51,7 +69,7 @@ class BlockingDialog @Inject constructor(
val manager = context.getString(when (prefs.blockingManager.get()) {
Preferences.BLOCKING_MANAGER_SIA -> R.string.blocking_manager_sia_title
Preferences.BLOCKING_MANAGER_CC -> R.string.blocking_manager_call_control_title
else -> R.string.blocking_manager_android
else -> R.string.app_name
})
val message = context.resources.getQuantityString(res, addresses.size, manager)
@@ -1,6 +1,25 @@
/*
* 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 com.moez.QKSMS.feature.blocking
import android.content.Context
import android.os.Build
import com.moez.QKSMS.R
import com.moez.QKSMS.blocking.BlockingManager
import com.moez.QKSMS.common.Navigator
@@ -31,7 +50,7 @@ class BlockingPresenter @Inject constructor(
}
}
.map(context::getString)
.subscribe { manager -> newState { copy(blockingManager = manager) }}
.subscribe { manager -> newState { copy(blockingManager = manager) } }
disposables += prefs.drop.asObservable()
.subscribe { enabled -> newState { copy(dropEnabled = enabled) } }
@@ -46,7 +65,15 @@ class BlockingPresenter @Inject constructor(
view.settingsClicks
.autoDisposable(view.scope())
.subscribe { blockingManager.openSettings() }
.subscribe {
// TODO: This is a hack, get rid of it once we implement AndroidX navigation
val client = prefs.blockingManager.get()
if (client == Preferences.BLOCKING_MANAGER_QKSMS && Build.VERSION.SDK_INT < 24) {
view.openBlockedNumbers()
} else {
blockingManager.openSettings()
}
}
view.dropClickedIntent
.autoDisposable(view.scope())
@@ -29,4 +29,5 @@ interface BlockingView : QkViewContract<BlockingState> {
val conversationClicks: Observable<Long>
fun openBlockingManager()
fun openBlockedNumbers()
}
@@ -0,0 +1,52 @@
/*
* 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 com.moez.QKSMS.feature.blocking.numbers
import android.view.LayoutInflater
import android.view.ViewGroup
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkRealmAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.model.BlockedNumber
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.blocked_number_list_item.*
import kotlinx.android.synthetic.main.blocked_number_list_item.view.*
class BlockedNumbersAdapter : QkRealmAdapter<BlockedNumber>() {
val unblockAddress: Subject<Long> = PublishSubject.create()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_number_list_item, parent, false)
return QkViewHolder(view).apply {
containerView.unblock.setOnClickListener {
val number = getItem(adapterPosition) ?: return@setOnClickListener
unblockAddress.onNext(number.id)
}
}
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val item = getItem(position)!!
holder.number.text = item.address
}
}
@@ -0,0 +1,87 @@
/*
* 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 com.moez.QKSMS.feature.blocking.numbers
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkController
import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.injection.appComponent
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.blocked_numbers_add_dialog.view.*
import kotlinx.android.synthetic.main.blocked_numbers_controller.*
import javax.inject.Inject
class BlockedNumbersController : QkController<BlockedNumbersView, BlockedNumbersState, BlockedNumbersPresenter>(),
BlockedNumbersView {
@Inject override lateinit var presenter: BlockedNumbersPresenter
@Inject lateinit var colors: Colors
private val adapter = BlockedNumbersAdapter()
private val saveAddressSubject: Subject<String> = PublishSubject.create()
init {
appComponent.inject(this)
retainViewMode = RetainViewMode.RETAIN_DETACH
layoutRes = R.layout.blocked_numbers_controller
}
override fun onAttach(view: View) {
super.onAttach(view)
presenter.bindIntents(this)
setTitle(R.string.blocked_numbers_title)
showBackButton(true)
}
override fun onViewCreated() {
super.onViewCreated()
add.setBackgroundTint(colors.theme().theme)
add.setTint(colors.theme().textPrimary)
adapter.emptyView = empty
numbers.adapter = adapter
}
override fun render(state: BlockedNumbersState) {
adapter.updateData(state.numbers)
}
override fun unblockAddress(): Observable<Long> = adapter.unblockAddress
override fun addAddress(): Observable<*> = add.clicks()
override fun saveAddress(): Observable<String> = saveAddressSubject
override fun showAddDialog() {
val layout = LayoutInflater.from(activity).inflate(R.layout.blocked_numbers_add_dialog, null)
val dialog = AlertDialog.Builder(activity!!)
.setView(layout)
.setPositiveButton(R.string.blocked_numbers_dialog_block) { _, _ ->
saveAddressSubject.onNext(layout.input.text.toString())
}
.setNegativeButton(R.string.button_cancel) { _, _ -> }
dialog.show()
}
}
@@ -0,0 +1,49 @@
/*
* 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 com.moez.QKSMS.feature.blocking.numbers
import com.moez.QKSMS.common.base.QkPresenter
import com.moez.QKSMS.repository.BlockingRepository
import com.uber.autodispose.kotlin.autoDisposable
import javax.inject.Inject
class BlockedNumbersPresenter @Inject constructor(
private val blockingRepo: BlockingRepository
) : QkPresenter<BlockedNumbersView, BlockedNumbersState>(
BlockedNumbersState(numbers = blockingRepo.getBlockedNumbers())
) {
override fun bindIntents(view: BlockedNumbersView) {
super.bindIntents(view)
view.unblockAddress()
.doOnNext(blockingRepo::unblockNumber)
.autoDisposable(view.scope())
.subscribe()
view.addAddress()
.autoDisposable(view.scope())
.subscribe { view.showAddDialog() }
view.saveAddress()
.autoDisposable(view.scope())
.subscribe{ address -> blockingRepo.blockNumber(address) }
}
}
@@ -0,0 +1,27 @@
/*
* 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 com.moez.QKSMS.feature.blocking.numbers
import com.moez.QKSMS.model.BlockedNumber
import io.realm.RealmList
import io.realm.RealmResults
data class BlockedNumbersState(
val numbers: RealmResults<BlockedNumber>? = null
)
@@ -0,0 +1,32 @@
/*
* 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 com.moez.QKSMS.feature.blocking.numbers
import com.moez.QKSMS.common.base.QkViewContract
import io.reactivex.Observable
interface BlockedNumbersView : QkViewContract<BlockedNumbersState> {
fun unblockAddress(): Observable<Long>
fun addAddress(): Observable<*>
fun saveAddress(): Observable<String>
fun showAddDialog()
}
@@ -31,6 +31,7 @@ import com.moez.QKSMS.common.widget.RadioPreferenceView
import com.moez.QKSMS.feature.backup.BackupController
import com.moez.QKSMS.feature.blocking.BlockingController
import com.moez.QKSMS.feature.blocking.manager.BlockingManagerController
import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController
import com.moez.QKSMS.feature.compose.DetailedChipView
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoComponent
import com.moez.QKSMS.feature.settings.SettingsController
@@ -62,6 +63,7 @@ interface AppComponent {
fun inject(controller: AboutController)
fun inject(controller: BackupController)
fun inject(controller: BlockedNumbersController)
fun inject(controller: BlockingController)
fun inject(controller: BlockingManagerController)
fun inject(controller: SettingsController)
@@ -1,4 +1,3 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
@@ -64,6 +63,8 @@ import com.moez.QKSMS.mapper.CursorToRecipientImpl
import com.moez.QKSMS.mapper.RatingManagerImpl
import com.moez.QKSMS.repository.BackupRepository
import com.moez.QKSMS.repository.BackupRepositoryImpl
import com.moez.QKSMS.repository.BlockingRepository
import com.moez.QKSMS.repository.BlockingRepositoryImpl
import com.moez.QKSMS.repository.ContactRepository
import com.moez.QKSMS.repository.ContactRepositoryImpl
import com.moez.QKSMS.repository.ConversationRepository
@@ -174,6 +175,9 @@ class AppModule(private var application: Application) {
@Provides
fun provideBackupRepository(repository: BackupRepositoryImpl): BackupRepository = repository
@Provides
fun provideBlockingRepository(repository: BlockingRepositoryImpl): BlockingRepository = repository
@Provides
fun provideContactRepository(repository: ContactRepositoryImpl): ContactRepository = repository