forked from upstream-mirrors/quik
Flatten hierarchy in presentation module
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 presentation.feature.blocked
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.os.Bundle
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import injection.appComponent
|
||||
import common.util.extensions.setVisible
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.blocked_activity.*
|
||||
import presentation.common.base.QkThemedActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedActivity : QkThemedActivity<BlockedViewModel>(), BlockedView {
|
||||
|
||||
@Inject lateinit var blockedAdapter: BlockedAdapter
|
||||
|
||||
override val viewModelClass = BlockedViewModel::class
|
||||
override val unblockIntent by lazy { blockedAdapter.unblock }
|
||||
override val confirmUnblockIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.blocked_activity)
|
||||
setTitle(R.string.blocked_title)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
colors.background
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
|
||||
conversations.adapter = blockedAdapter
|
||||
}
|
||||
|
||||
override fun render(state: BlockedState) {
|
||||
blockedAdapter.flowable = state.data
|
||||
empty.setVisible(state.empty)
|
||||
}
|
||||
|
||||
override fun showUnblockDialog() {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.blocked_unblock_dialog_title)
|
||||
.setMessage(R.string.blocked_unblock_dialog_message)
|
||||
.setPositiveButton(R.string.button_unblock, { _, _ -> confirmUnblockIntent.onNext(Unit) })
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.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 presentation.feature.blocked
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.blocked_list_item.view.*
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.PhoneNumber
|
||||
import presentation.common.base.FlowableAdapter
|
||||
import presentation.common.base.QkViewHolder
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedAdapter @Inject constructor(private val context: Context) : FlowableAdapter<Conversation>() {
|
||||
|
||||
val unblock: PublishSubject<Long> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
return QkViewHolder(LayoutInflater.from(context).inflate(R.layout.blocked_list_item, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val conversation = getItem(position)
|
||||
val view = holder.itemView
|
||||
|
||||
view.setOnClickListener { unblock.onNext(conversation.id) }
|
||||
|
||||
view.avatars.contacts = conversation.recipients.map { recipient ->
|
||||
recipient.contact ?: Contact().apply { numbers.add(PhoneNumber().apply { address = recipient.address }) }
|
||||
}
|
||||
|
||||
view.title.text = conversation.getTitle()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 presentation.feature.blocked
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import model.Conversation
|
||||
|
||||
data class BlockedState(
|
||||
val data: Flowable<List<Conversation>>? = null,
|
||||
val empty: Boolean = false
|
||||
)
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 presentation.feature.blocked
|
||||
|
||||
import io.reactivex.Observable
|
||||
import presentation.common.base.QkView
|
||||
|
||||
interface BlockedView : QkView<BlockedState> {
|
||||
|
||||
val unblockIntent: Observable<Long>
|
||||
val confirmUnblockIntent: Observable<Unit>
|
||||
|
||||
fun showUnblockDialog()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 presentation.feature.blocked
|
||||
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import injection.appComponent
|
||||
import interactor.MarkUnblocked
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import presentation.common.base.QkViewModel
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedViewModel : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
|
||||
|
||||
@Inject lateinit var markUnblocked: MarkUnblocked
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
val conversations = messageRepo.getBlockedConversations()
|
||||
.doOnNext { conversations -> newState { it.copy(empty = conversations.isEmpty()) } }
|
||||
|
||||
newState { it.copy(data = conversations) }
|
||||
}
|
||||
|
||||
override fun bindView(view: BlockedView) {
|
||||
super.bindView(view)
|
||||
|
||||
// Show confirm unblock conversation dialog
|
||||
view.unblockIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showUnblockDialog() }
|
||||
|
||||
// Unblock conversation
|
||||
view.confirmUnblockIntent
|
||||
.withLatestFrom(view.unblockIntent, { _, threadId -> threadId })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> markUnblocked.execute(threadId) }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user