Commit edddc76b authored by aniket's avatar aniket

makes requested changes

parent c7dfe315
package chat.rocket.android.createChannel.addMembers.presentation package chat.rocket.android.createChannel.addMembers.presentation
import chat.rocket.android.core.behaviours.showMessage
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.members.viewmodel.MemberViewModelMapper import chat.rocket.android.members.viewmodel.MemberViewModelMapper
import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.server.domain.GetCurrentServerInteractor
...@@ -19,28 +18,25 @@ class AddMembersPresenter @Inject constructor( ...@@ -19,28 +18,25 @@ class AddMembersPresenter @Inject constructor(
private val mapper: MemberViewModelMapper, private val mapper: MemberViewModelMapper,
factory: RocketChatClientFactory factory: RocketChatClientFactory
) { ) {
val serverUrl: String? = serverInteractor.get() private val client = factory.create(serverInteractor.get()!!)
private val client = if (serverUrl != null) factory.create(serverUrl) else null
fun queryUsersFromRegex(queryParam: String, offset: Long = 0) { fun queryUsersFromRegex(queryParam: String, offset: Long = 0) {
if (client != null) { view.showLoading()
view.showLoading() launchUI(strategy) {
launchUI(strategy) { try {
try { val allMembers = retryIO("queryUsers($queryParam)") {
val allMembers = retryIO("queryUsers($queryParam)") { client.queryUsers(queryParam, 60, offset)
client.queryUsers(queryParam, 60, offset)
}
val memberViewModelMapper = mapper.mapToViewModelList(allMembers.result)
view.showMembers(memberViewModelMapper, allMembers.total)
} catch (ex: RocketChatException) {
ex.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
} finally {
view.hideLoading()
} }
val memberViewModelMapper = mapper.mapToViewModelList(allMembers.result)
view.showMembers(memberViewModelMapper, allMembers.total)
} catch (ex: RocketChatException) {
ex.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
} finally {
view.hideLoading()
} }
} }
} }
......
...@@ -24,6 +24,7 @@ import com.jakewharton.rxbinding2.widget.RxTextView ...@@ -24,6 +24,7 @@ import com.jakewharton.rxbinding2.widget.RxTextView
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.BehaviorSubject
import kotlinx.android.synthetic.main.activity_add_members.* import kotlinx.android.synthetic.main.activity_add_members.*
import kotlinx.android.synthetic.main.layout_toolbar.* import kotlinx.android.synthetic.main.layout_toolbar.*
...@@ -46,7 +47,9 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -46,7 +47,9 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
.show() .show()
} }
} }
private var linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) private lateinit var observableForSearchView: Disposable
private lateinit var observableForToolbarAction: Disposable
private val linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) AndroidInjection.inject(this)
...@@ -56,17 +59,14 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -56,17 +59,14 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
setUpRecyclerView() setUpRecyclerView()
setOnClickListeners() setOnClickListeners()
setInitialChips() setInitialChips()
observableFromSearchView(search_view) setUpObservableForSearchView()
.debounce(300, TimeUnit.MILLISECONDS) }
.filter { item -> item.isNotEmpty() }
.observeOn(AndroidSchedulers.mainThread()) override fun onDestroy() {
.subscribe { query -> super.onDestroy()
queryParam = query //dispose off the rx disposables
run { observableForToolbarAction.dispose()
adapter.reAllocateArrayList() observableForSearchView.dispose()
presenter.queryUsersFromRegex(query)
}
}
} }
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onOptionsItemSelected(item: MenuItem?): Boolean {
...@@ -129,6 +129,20 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -129,6 +129,20 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
updateToolBar() updateToolBar()
} }
private fun setUpObservableForSearchView() {
observableForSearchView = observableFromSearchView(search_view)
.debounce(300, TimeUnit.MILLISECONDS)
.filter { item -> item.isNotEmpty() }
.observeOn(AndroidSchedulers.mainThread())
.subscribe { query ->
queryParam = query
run {
adapter.reAllocateArrayList()
presenter.queryUsersFromRegex(query)
}
}
}
private fun addNewChip(memberViewModel: MemberViewModel) { private fun addNewChip(memberViewModel: MemberViewModel) {
memberViewModel.username?.let { memberViewModel.username?.let {
buildNewChip(it) buildNewChip(it)
...@@ -156,7 +170,8 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -156,7 +170,8 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
} else { } else {
toolbar_action_text.alpha = 1.0f toolbar_action_text.alpha = 1.0f
} }
toolbar_title.textContent = getString(R.string.title_add_members, membersToAdd.size.toString()) toolbar_title.textContent =
getString(R.string.title_add_members, membersToAdd.size.toString())
} }
private fun setUpToolBar() { private fun setUpToolBar() {
...@@ -186,7 +201,7 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -186,7 +201,7 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
private fun observableFromSearchView(searchView: EditText): Observable<String> { private fun observableFromSearchView(searchView: EditText): Observable<String> {
val observableSubject: BehaviorSubject<String> = BehaviorSubject.create() val observableSubject: BehaviorSubject<String> = BehaviorSubject.create()
RxTextView.textChanges(searchView).subscribe { text -> observableForToolbarAction = RxTextView.textChanges(searchView).subscribe { text ->
if (text.isNotBlank()) { if (text.isNotBlank()) {
observableSubject.onNext(text.toString()) observableSubject.onNext(text.toString())
} }
......
package chat.rocket.android.createChannel.presentation package chat.rocket.android.createChannel.presentation
import android.widget.Toast
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
...@@ -10,7 +9,6 @@ import chat.rocket.common.model.RoomType ...@@ -10,7 +9,6 @@ import chat.rocket.common.model.RoomType
import chat.rocket.common.util.ifNull import chat.rocket.common.util.ifNull
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.createChannel import chat.rocket.core.internal.rest.createChannel
import chat.rocket.core.model.Room
import javax.inject.Inject import javax.inject.Inject
...@@ -31,14 +29,13 @@ class CreateNewChannelPresenter @Inject constructor( ...@@ -31,14 +29,13 @@ class CreateNewChannelPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
view.showLoading() view.showLoading()
try { try {
val channelCreated: Room? = client.createChannel(roomType, channelName, usersList, readOnly)
client.createChannel(roomType, channelName, usersList, readOnly)
view.showChannelCreatedSuccessfullyMessage() view.showChannelCreatedSuccessfullyMessage()
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
exception.message?.let { exception.message?.let {
view.showMessage(it) view.showMessageAndClearText(it)
}.ifNull { }.ifNull {
view.showGenericErrorMessage() view.showErrorMessage()
} }
} finally { } finally {
view.hideLoading() view.hideLoading()
......
package chat.rocket.android.createChannel.presentation package chat.rocket.android.createChannel.presentation
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView
interface CreateNewChannelView : LoadingView, MessageView { interface CreateNewChannelView : LoadingView {
/* /*
Show a message that a channel was successfully created Show a message that a channel was successfully created
*/ */
fun showChannelCreatedSuccessfullyMessage() fun showChannelCreatedSuccessfullyMessage()
/*
Show message and clear text in edit text
*/
fun showMessageAndClearText(resId: Int)
fun showMessageAndClearText(message: String)
/*
Show error message
*/
fun showErrorMessage()
} }
\ No newline at end of file
...@@ -13,9 +13,10 @@ import chat.rocket.android.createChannel.presentation.CreateNewChannelPresenter ...@@ -13,9 +13,10 @@ import chat.rocket.android.createChannel.presentation.CreateNewChannelPresenter
import chat.rocket.android.createChannel.presentation.CreateNewChannelView import chat.rocket.android.createChannel.presentation.CreateNewChannelView
import chat.rocket.android.util.extensions.setVisible import chat.rocket.android.util.extensions.setVisible
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.common.model.roomTypeOf import chat.rocket.common.model.RoomType
import com.jakewharton.rxbinding2.widget.RxTextView import com.jakewharton.rxbinding2.widget.RxTextView
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.activity_create_new_channel.* import kotlinx.android.synthetic.main.activity_create_new_channel.*
import kotlinx.android.synthetic.main.layout_toolbar.* import kotlinx.android.synthetic.main.layout_toolbar.*
import javax.inject.Inject import javax.inject.Inject
...@@ -25,8 +26,9 @@ internal const val ADD_MEMBERS_ACTIVITY_REQUEST_CODE = 1 ...@@ -25,8 +26,9 @@ internal const val ADD_MEMBERS_ACTIVITY_REQUEST_CODE = 1
class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
@Inject @Inject
lateinit var presenter: CreateNewChannelPresenter lateinit var presenter: CreateNewChannelPresenter
private var channelType: String = "public" private var channelType: RoomType = RoomType.CHANNEL
private var listOfUsers: ArrayList<String> = ArrayList() private var listOfUsers: ArrayList<String> = ArrayList()
private lateinit var observableForToolbarAction: Disposable
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) AndroidInjection.inject(this)
...@@ -36,6 +38,11 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -36,6 +38,11 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
setUpOnClickListeners() setUpOnClickListeners()
} }
override fun onDestroy() {
super.onDestroy()
observableForToolbarAction.dispose()
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
android.R.id.home -> { android.R.id.home -> {
...@@ -75,19 +82,18 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -75,19 +82,18 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
finish() finish()
} }
override fun showMessage(resId: Int) { override fun showMessageAndClearText(resId: Int) {
channel_name_edit_text.setText("") channel_name_edit_text.setText("")
showToast(getString(resId)) showToast(getString(resId))
} }
override fun showMessage(message: String) { override fun showMessageAndClearText(message: String) {
channel_name_edit_text.setText("") channel_name_edit_text.setText("")
showToast(message) showToast(message)
} }
override fun showGenericErrorMessage() { override fun showErrorMessage() {
channel_name_edit_text.setText("") showMessageAndClearText(getString(R.string.msg_generic_error))
showMessage(getString(R.string.msg_generic_error))
} }
...@@ -108,19 +114,20 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -108,19 +114,20 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
toolbar_action_text.text = getString(R.string.action_create_new_channel) toolbar_action_text.text = getString(R.string.action_create_new_channel)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
RxTextView.textChanges(channel_name_edit_text).subscribe { text -> observableForToolbarAction =
toolbar_action_text.isEnabled = (text.isNotEmpty() && listOfUsers.isNotEmpty()) RxTextView.textChanges(channel_name_edit_text).subscribe { text ->
if (text.isEmpty()) { toolbar_action_text.isEnabled = (text.isNotEmpty() && listOfUsers.isNotEmpty())
toolbar_action_text.alpha = 0.8f if (text.isEmpty()) {
} else { toolbar_action_text.alpha = 0.8f
toolbar_action_text.alpha = 1.0f } else {
} toolbar_action_text.alpha = 1.0f
} }
}
} }
private fun setUpOnClickListeners() { private fun setUpOnClickListeners() {
public_channel.setOnClickListener { public_channel.setOnClickListener {
channelType = "c" channelType = RoomType.CHANNEL
channel_type.text = getString(R.string.public_channel_type) channel_type.text = getString(R.string.public_channel_type)
channel_description.text = getString(R.string.public_channel_description) channel_description.text = getString(R.string.public_channel_description)
...@@ -142,7 +149,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -142,7 +149,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
} }
private_channel.setOnClickListener { private_channel.setOnClickListener {
channelType = "p" channelType = RoomType.PRIVATE_GROUP
channel_type.text = getString(R.string.private_channel_type) channel_type.text = getString(R.string.private_channel_type)
channel_description.text = getString(R.string.private_channel_type_description) channel_description.text = getString(R.string.private_channel_type_description)
...@@ -150,11 +157,11 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -150,11 +157,11 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
placeholder.setImageDrawable(getDrawable(R.drawable.ic_lock_black_12_dp)) placeholder.setImageDrawable(getDrawable(R.drawable.ic_lock_black_12_dp))
(getDrawable(R.drawable.button_border) as GradientDrawable).setColor( (getDrawable(R.drawable.button_border) as GradientDrawable).setColor(
resources.getColor( resources.getColor(R.color.colorRed)
R.color.colorRed )
) (getDrawable(R.drawable.button_solid) as GradientDrawable).setColor(
resources.getColor(R.color.default_background)
) )
(getDrawable(R.drawable.button_solid) as GradientDrawable).setColor(resources.getColor(R.color.default_background))
(getDrawable(R.drawable.button_solid) as GradientDrawable).setStroke( (getDrawable(R.drawable.button_solid) as GradientDrawable).setStroke(
1, 1,
resources.getColor(R.color.colorRed) resources.getColor(R.color.colorRed)
...@@ -170,7 +177,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -170,7 +177,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
toolbar_action_text.setOnClickListener { toolbar_action_text.setOnClickListener {
if (toolbar_action_text.isEnabled) { if (toolbar_action_text.isEnabled) {
presenter.createNewChannel( presenter.createNewChannel(
roomTypeOf(channelType), channelType,
channel_name_edit_text.text.toString(), channel_name_edit_text.text.toString(),
listOfUsers, listOfUsers,
false false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment