diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt index fac50ca9..366fc803 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt @@ -19,7 +19,6 @@ package com.moez.QKSMS.feature.blocking import android.view.View -import androidx.core.view.isVisible import com.bluelinelabs.conductor.RouterTransaction import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.R @@ -28,6 +27,7 @@ import com.moez.QKSMS.common.base.QkController import com.moez.QKSMS.common.util.Colors import com.moez.QKSMS.common.util.extensions.animateLayoutChanges import com.moez.QKSMS.feature.blocking.manager.BlockingManagerController +import com.moez.QKSMS.feature.blocking.messages.BlockedMessagesController import com.moez.QKSMS.injection.appComponent import kotlinx.android.synthetic.main.blocking_controller.* import kotlinx.android.synthetic.main.settings_switch_widget.view.* @@ -36,10 +36,9 @@ import javax.inject.Inject class BlockingController : QkController(), BlockingView { override val blockingManagerIntent by lazy { blockingManager.clicks() } + override val blockedMessagesIntent by lazy { blockedNumbers.clicks() } override val dropClickedIntent by lazy { drop.clicks() } - override val conversationClicks by lazy { blockingAdapter.clicks } - @Inject lateinit var blockingAdapter: BlockingAdapter @Inject lateinit var colors: Colors @Inject override lateinit var presenter: BlockingPresenter @@ -51,10 +50,6 @@ class BlockingController : QkController(BlockingState()) { init { - val blockedConversations = conversationRepo.getBlockedConversations() - newState { copy(data = blockedConversations) } - disposables += prefs.blockingManager.asObservable() .map { client -> when (client) { @@ -54,14 +46,6 @@ class BlockingPresenter @Inject constructor( disposables += prefs.drop.asObservable() .subscribe { enabled -> newState { copy(dropEnabled = enabled) } } - - // Trigger a refresh if we go between having some/no blocked conversations, otherwise the header won't update - disposables += blockedConversations - .asObservable() - .filter { it.isValid && it.isLoaded } - .map { it.isEmpty() } - .distinctUntilChanged() - .subscribe { newState { copy() } } } override fun bindIntents(view: BlockingView) { @@ -71,13 +55,13 @@ class BlockingPresenter @Inject constructor( .autoDisposable(view.scope()) .subscribe { view.openBlockingManager() } + view.blockedMessagesIntent + .autoDisposable(view.scope()) + .subscribe { view.openBlockedMessages() } + view.dropClickedIntent .autoDisposable(view.scope()) .subscribe { prefs.drop.set(!prefs.drop.get()) } - - view.conversationClicks - .autoDisposable(view.scope()) - .subscribe { threadId -> navigator.showConversation(threadId) } } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingState.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingState.kt index c7f6b9c6..8f3e3125 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingState.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingState.kt @@ -18,11 +18,7 @@ */ package com.moez.QKSMS.feature.blocking -import com.moez.QKSMS.model.Conversation -import io.realm.RealmResults - data class BlockingState( val blockingManager: String = "", - val dropEnabled: Boolean = false, - val data: RealmResults? = null -) \ No newline at end of file + val dropEnabled: Boolean = false +) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt index 9af28686..08555d40 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt @@ -24,8 +24,9 @@ import io.reactivex.Observable interface BlockingView : QkViewContract { val blockingManagerIntent: Observable<*> + val blockedMessagesIntent: Observable<*> val dropClickedIntent: Observable<*> - val conversationClicks: Observable fun openBlockingManager() + fun openBlockedMessages() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesAdapter.kt similarity index 90% rename from presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingAdapter.kt rename to presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesAdapter.kt index c7e34377..61973f64 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Moez Bhatti + * Copyright (C) 2019 Moez Bhatti * * This file is part of QKSMS. * @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with QKSMS. If not, see . */ -package com.moez.QKSMS.feature.blocking +package com.moez.QKSMS.feature.blocking.messages import android.view.LayoutInflater import android.view.ViewGroup @@ -28,7 +28,7 @@ import io.reactivex.subjects.PublishSubject import kotlinx.android.synthetic.main.blocked_list_item.view.* import javax.inject.Inject -class BlockingAdapter @Inject constructor() : QkRealmAdapter() { +class BlockedMessagesAdapter @Inject constructor() : QkRealmAdapter() { val clicks: PublishSubject = PublishSubject.create() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesController.kt new file mode 100644 index 00000000..11272cd9 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesController.kt @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2019 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.messages + +import android.view.View +import com.moez.QKSMS.R +import com.moez.QKSMS.common.base.QkController +import com.moez.QKSMS.common.util.Colors +import com.moez.QKSMS.injection.appComponent +import kotlinx.android.synthetic.main.blocked_messages_controller.* +import javax.inject.Inject + +class BlockedMessagesController : QkController(), + BlockedMessagesView { + + override val conversationClicks by lazy { blockedMessagesAdapter.clicks } + + @Inject lateinit var blockedMessagesAdapter: BlockedMessagesAdapter + @Inject lateinit var colors: Colors + @Inject override lateinit var presenter: BlockedMessagesPresenter + + init { + appComponent.inject(this) + retainViewMode = RetainViewMode.RETAIN_DETACH + layoutRes = R.layout.blocked_messages_controller + } + + override fun onViewCreated() { + super.onViewCreated() + + blockedMessagesAdapter.emptyView = empty + conversations.adapter = blockedMessagesAdapter + } + + override fun onAttach(view: View) { + super.onAttach(view) + presenter.bindIntents(this) + setTitle(R.string.blocked_messages_title) + showBackButton(true) + } + + override fun render(state: BlockedMessagesState) { + blockedMessagesAdapter.updateData(state.data) + } + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesPresenter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesPresenter.kt new file mode 100644 index 00000000..c9e43f04 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesPresenter.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.messages + +import com.moez.QKSMS.common.Navigator +import com.moez.QKSMS.common.base.QkPresenter +import com.moez.QKSMS.repository.ConversationRepository +import com.uber.autodispose.android.lifecycle.scope +import com.uber.autodispose.autoDisposable +import javax.inject.Inject + +class BlockedMessagesPresenter @Inject constructor( + conversationRepo: ConversationRepository, + private val navigator: Navigator +) : QkPresenter(BlockedMessagesState( + data = conversationRepo.getBlockedConversations() +)) { + + override fun bindIntents(view: BlockedMessagesView) { + super.bindIntents(view) + + view.conversationClicks + .autoDisposable(view.scope()) + .subscribe { threadId -> navigator.showConversation(threadId) } + } + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesState.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesState.kt new file mode 100644 index 00000000..6f645b14 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesState.kt @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.messages + +import com.moez.QKSMS.model.Conversation +import io.realm.RealmResults + +data class BlockedMessagesState( + val data: RealmResults? = null +) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesView.kt new file mode 100644 index 00000000..6ddeeedf --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/messages/BlockedMessagesView.kt @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.messages + +import com.moez.QKSMS.common.base.QkViewContract +import io.reactivex.Observable + +interface BlockedMessagesView : QkViewContract { + val conversationClicks: Observable +} diff --git a/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt b/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt index 8ca92a31..75515214 100644 --- a/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt +++ b/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt @@ -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.messages.BlockedMessagesController import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController import com.moez.QKSMS.feature.compose.DetailedChipView import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoComponent @@ -63,6 +64,7 @@ interface AppComponent { fun inject(controller: AboutController) fun inject(controller: BackupController) + fun inject(controller: BlockedMessagesController) fun inject(controller: BlockedNumbersController) fun inject(controller: BlockingController) fun inject(controller: BlockingManagerController) diff --git a/presentation/src/main/res/layout/blocked_messages_controller.xml b/presentation/src/main/res/layout/blocked_messages_controller.xml new file mode 100644 index 00000000..4979bcc0 --- /dev/null +++ b/presentation/src/main/res/layout/blocked_messages_controller.xml @@ -0,0 +1,45 @@ + + + + + + + + + diff --git a/presentation/src/main/res/layout/blocking_controller.xml b/presentation/src/main/res/layout/blocking_controller.xml index 7d5506de..f2162309 100644 --- a/presentation/src/main/res/layout/blocking_controller.xml +++ b/presentation/src/main/res/layout/blocking_controller.xml @@ -17,7 +17,7 @@ ~ You should have received a copy of the GNU General Public License ~ along with QKSMS. If not, see . --> - - + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingTop="16dp" + android:paddingBottom="16dp"> + + - + - - - - - - - - - + diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 9bc48258..ef3289e6 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -255,7 +255,6 @@ Drop messages Drop incoming messages from blocked senders instead of hiding them Blocked conversations - Your blocked conversations will appear here Blocking Manager QKSMS @@ -274,6 +273,9 @@ Phone number Block + Blocked messages + Your blocked messages will appear here + Block Unblock