Commit 15b6c490 authored by Aniket Singh's avatar Aniket Singh

adds code to create channel

parent 1c9017ae
package chat.rocket.android.createChannel.presentation
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.extensions.launchUI
import chat.rocket.common.RocketChatException
import chat.rocket.common.model.RoomType
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.createChannel
import javax.inject.Inject
class CreateNewChannelPresenter @Inject constructor() {
class CreateNewChannelPresenter @Inject constructor(private val view: CreateNewChannelView,
private val strategy: CancelStrategy,
private val serverInteractor: GetCurrentServerInteractor,
factory: RocketChatClientFactory) {
private val client: RocketChatClient = factory.create(serverInteractor.get()!!)
fun createNewChannel(roomType: RoomType, channelName: String, usersList: List<String>, readOnly: Boolean) {
launchUI(strategy) {
view.showLoading()
try {
client.createChannel(roomType, channelName, usersList, readOnly)
view.showMessage("Channel Created successfully")
} catch (ex: RocketChatException) {
//TODO remove this and add Log message instead
ex.printStackTrace()
} finally {
view.hideLoading()
}
}
}
}
\ No newline at end of file
......@@ -4,9 +4,12 @@ import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.createChannel.presentation.CreateNewChannelPresenter
import chat.rocket.android.createChannel.presentation.CreateNewChannelView
import chat.rocket.android.util.extensions.setVisible
import chat.rocket.common.model.roomTypeOf
import com.jakewharton.rxbinding2.widget.RxTextView
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.activity_create_new_channel.*
......@@ -16,11 +19,15 @@ import javax.inject.Inject
class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
override fun showLoading() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
view_loading.setVisible(true)
layout_container.alpha = 0.5f
layout_container.isEnabled = false
}
override fun hideLoading() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
view_loading.setVisible(false)
layout_container.alpha = 1.0f
layout_container.isEnabled = true
}
override fun showMessage(resId: Int) {
......@@ -28,7 +35,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
}
override fun showMessage(message: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
}
override fun showGenericErrorMessage() {
......@@ -66,16 +73,17 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
RxTextView.textChanges(channel_name_edit_text).subscribe { text ->
toolbar_action_text.isEnabled = text.isNotEmpty()
if (text.isEmpty())
if (text.isEmpty()) {
toolbar_action_text.alpha = 0.8f
else
} else {
toolbar_action_text.alpha = 1.0f
}
}
}
private fun setUpOnClickListeners() {
public_channel.setOnClickListener {
channelType = "public"
channelType = "c"
channel_type.text = getString(R.string.public_channel_type)
channel_description.text = getString(R.string.private_channel_type_description)
......@@ -93,7 +101,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
}
private_channel.setOnClickListener {
channelType = "private"
channelType = "p"
channel_type.text = getString(R.string.private_channel_type)
channel_description.text = getString(R.string.public_channel_description)
......@@ -110,5 +118,11 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
private_channel.setTextColor(resources.getColor(R.color.colorLightTheme))
public_channel.setTextColor(resources.getColor(R.color.red))
}
toolbar_action_text.setOnClickListener {
if (toolbar_action_text.isEnabled) {
presenter.createNewChannel(roomTypeOf(channelType), channel_name_edit_text.text.toString(), listOf("aniket03"), false)
}
}
}
}
\ No newline at end of file
......@@ -7,6 +7,6 @@
android:pathData="M6.626,11.495L4.505,11.495L3.714,16L1.703,16L2.495,11.495L0,11.495L0,9.604L2.824,9.604L3.374,6.484L0.824,6.484L0.824,4.571L3.714,4.571L4.516,0L6.516,0L5.714,4.571L7.846,4.571L8.648,0L10.659,0L9.857,4.571L12.264,4.571L12.264,6.484L9.516,6.484L8.967,9.604L11.429,9.604L11.429,11.495L8.637,11.495L7.846,16L5.835,16L6.626,11.495ZM4.835,9.604L6.956,9.604L7.505,6.484L5.374,6.484L4.835,9.604Z"
android:strokeColor="#00000000"
android:fillType="evenOdd"
android:fillColor="#000000"
android:fillColor="@color/colorSecondaryText"
android:strokeWidth="1"/>
</vector>
......@@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="@color/colorSecondaryText"
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
......@@ -12,11 +13,24 @@
app:layout_constraintBottom_toTopOf="@+id/layout_container"
app:layout_constraintTop_toTopOf="parent" />
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/view_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:indicatorColor="@color/black"
app:indicatorName="BallPulseIndicator"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_layout"
tools:visibility="visible" />
<android.support.constraint.ConstraintLayout
android:id="@+id/layout_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
......@@ -67,8 +81,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/private_channel_type"
android:textColor="@color/black"
android:text="@string/public_channel_type"
android:textColor="@color/colorPrimaryText"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@id/public_channel" />
<TextView
......@@ -76,14 +91,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/private_channel_type_description"
android:textColor="@color/black"
android:text="@string/public_channel_description"
android:textColor="@color/colorSecondaryText"
android:textSize="12sp"
app:layout_constraintTop_toBottomOf="@id/channel_type" />
<View
android:id="@+id/separator_1"
android:layout_width="0dp"
android:layout_height="0.2dp"
android:layout_height="0.5dp"
android:layout_marginTop="8dp"
android:background="@color/colorDividerMessageComposer"
app:layout_constraintTop_toBottomOf="@id/channel_description" />
......@@ -114,13 +130,14 @@
<android.support.design.widget.TextInputEditText
android:id="@+id/channel_name_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
<View
android:id="@+id/separator_2"
android:layout_width="0dp"
android:layout_height="0.2dp"
android:layout_height="0.5dp"
android:layout_marginTop="8dp"
android:background="@color/colorDividerMessageComposer"
app:layout_constraintTop_toBottomOf="@id/channel_name_text_input_layout" />
......@@ -140,7 +157,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/msg_add_members"
android:textColor="@color/black"
android:textColor="@color/colorSecondaryText"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
......@@ -158,7 +176,7 @@
<View
android:id="@+id/separator_3"
android:layout_width="0dp"
android:layout_height="0.2dp"
android:layout_height="0.5dp"
android:layout_marginTop="8dp"
android:background="@color/colorDividerMessageComposer"
app:layout_constraintTop_toBottomOf="@id/add_members_view" />
......
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