Commit edddc76b authored by aniket's avatar aniket

makes requested changes

parent c7dfe315
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.members.viewmodel.MemberViewModelMapper
import chat.rocket.android.server.domain.GetCurrentServerInteractor
......@@ -19,11 +18,9 @@ class AddMembersPresenter @Inject constructor(
private val mapper: MemberViewModelMapper,
factory: RocketChatClientFactory
) {
val serverUrl: String? = serverInteractor.get()
private val client = if (serverUrl != null) factory.create(serverUrl) else null
private val client = factory.create(serverInteractor.get()!!)
fun queryUsersFromRegex(queryParam: String, offset: Long = 0) {
if (client != null) {
view.showLoading()
launchUI(strategy) {
try {
......@@ -43,5 +40,4 @@ class AddMembersPresenter @Inject constructor(
}
}
}
}
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ import com.jakewharton.rxbinding2.widget.RxTextView
import dagger.android.AndroidInjection
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.subjects.BehaviorSubject
import kotlinx.android.synthetic.main.activity_add_members.*
import kotlinx.android.synthetic.main.layout_toolbar.*
......@@ -46,7 +47,9 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
.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?) {
AndroidInjection.inject(this)
......@@ -56,17 +59,14 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
setUpRecyclerView()
setOnClickListeners()
setInitialChips()
observableFromSearchView(search_view)
.debounce(300, TimeUnit.MILLISECONDS)
.filter { item -> item.isNotEmpty() }
.observeOn(AndroidSchedulers.mainThread())
.subscribe { query ->
queryParam = query
run {
adapter.reAllocateArrayList()
presenter.queryUsersFromRegex(query)
}
setUpObservableForSearchView()
}
override fun onDestroy() {
super.onDestroy()
//dispose off the rx disposables
observableForToolbarAction.dispose()
observableForSearchView.dispose()
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
......@@ -129,6 +129,20 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
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) {
memberViewModel.username?.let {
buildNewChip(it)
......@@ -156,7 +170,8 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
} else {
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() {
......@@ -186,7 +201,7 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
private fun observableFromSearchView(searchView: EditText): Observable<String> {
val observableSubject: BehaviorSubject<String> = BehaviorSubject.create()
RxTextView.textChanges(searchView).subscribe { text ->
observableForToolbarAction = RxTextView.textChanges(searchView).subscribe { text ->
if (text.isNotBlank()) {
observableSubject.onNext(text.toString())
}
......
package chat.rocket.android.createChannel.presentation
import android.widget.Toast
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
......@@ -10,7 +9,6 @@ import chat.rocket.common.model.RoomType
import chat.rocket.common.util.ifNull
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.createChannel
import chat.rocket.core.model.Room
import javax.inject.Inject
......@@ -31,14 +29,13 @@ class CreateNewChannelPresenter @Inject constructor(
launchUI(strategy) {
view.showLoading()
try {
val channelCreated: Room? =
client.createChannel(roomType, channelName, usersList, readOnly)
view.showChannelCreatedSuccessfullyMessage()
} catch (exception: RocketChatException) {
exception.message?.let {
view.showMessage(it)
view.showMessageAndClearText(it)
}.ifNull {
view.showGenericErrorMessage()
view.showErrorMessage()
}
} finally {
view.hideLoading()
......
package chat.rocket.android.createChannel.presentation
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
*/
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
import chat.rocket.android.createChannel.presentation.CreateNewChannelView
import chat.rocket.android.util.extensions.setVisible
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 dagger.android.AndroidInjection
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.activity_create_new_channel.*
import kotlinx.android.synthetic.main.layout_toolbar.*
import javax.inject.Inject
......@@ -25,8 +26,9 @@ internal const val ADD_MEMBERS_ACTIVITY_REQUEST_CODE = 1
class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
@Inject
lateinit var presenter: CreateNewChannelPresenter
private var channelType: String = "public"
private var channelType: RoomType = RoomType.CHANNEL
private var listOfUsers: ArrayList<String> = ArrayList()
private lateinit var observableForToolbarAction: Disposable
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
......@@ -36,6 +38,11 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
setUpOnClickListeners()
}
override fun onDestroy() {
super.onDestroy()
observableForToolbarAction.dispose()
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
android.R.id.home -> {
......@@ -75,19 +82,18 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
finish()
}
override fun showMessage(resId: Int) {
override fun showMessageAndClearText(resId: Int) {
channel_name_edit_text.setText("")
showToast(getString(resId))
}
override fun showMessage(message: String) {
override fun showMessageAndClearText(message: String) {
channel_name_edit_text.setText("")
showToast(message)
}
override fun showGenericErrorMessage() {
channel_name_edit_text.setText("")
showMessage(getString(R.string.msg_generic_error))
override fun showErrorMessage() {
showMessageAndClearText(getString(R.string.msg_generic_error))
}
......@@ -108,6 +114,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
toolbar_action_text.text = getString(R.string.action_create_new_channel)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
observableForToolbarAction =
RxTextView.textChanges(channel_name_edit_text).subscribe { text ->
toolbar_action_text.isEnabled = (text.isNotEmpty() && listOfUsers.isNotEmpty())
if (text.isEmpty()) {
......@@ -120,7 +127,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
private fun setUpOnClickListeners() {
public_channel.setOnClickListener {
channelType = "c"
channelType = RoomType.CHANNEL
channel_type.text = getString(R.string.public_channel_type)
channel_description.text = getString(R.string.public_channel_description)
......@@ -142,7 +149,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
}
private_channel.setOnClickListener {
channelType = "p"
channelType = RoomType.PRIVATE_GROUP
channel_type.text = getString(R.string.private_channel_type)
channel_description.text = getString(R.string.private_channel_type_description)
......@@ -150,11 +157,11 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
placeholder.setImageDrawable(getDrawable(R.drawable.ic_lock_black_12_dp))
(getDrawable(R.drawable.button_border) as GradientDrawable).setColor(
resources.getColor(
R.color.colorRed
resources.getColor(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(
1,
resources.getColor(R.color.colorRed)
......@@ -170,7 +177,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
toolbar_action_text.setOnClickListener {
if (toolbar_action_text.isEnabled) {
presenter.createNewChannel(
roomTypeOf(channelType),
channelType,
channel_name_edit_text.text.toString(),
listOfUsers,
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