Commit 866ff324 authored by aniket's avatar aniket

deals with more cases

parent 7435abb5
package chat.rocket.android.createChannel.addMembers.ui
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.design.chip.Chip
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.view.MenuItem
import android.widget.EditText
import android.widget.Toast
import chat.rocket.android.R
......@@ -29,11 +32,15 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
@Inject
lateinit var presenter: AddMembersPresenter
private var membersToAdd: ArrayList<String> = ArrayList()
private val adapter: MembersAdapter = MembersAdapter { memberViewModel ->
addNewChip(memberViewModel)
updateToolBar()
search_view.setText("")
if (!membersToAdd.contains(memberViewModel.username)) {
addNewChip(memberViewModel)
updateToolBar()
search_view.setText("")
}
else {
Toast.makeText(this, getString(R.string.msg_member_already_added), Toast.LENGTH_LONG).show()
}
}
private var linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
......@@ -43,6 +50,7 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
setContentView(R.layout.activity_add_members)
setUpToolBar()
setUpRecyclerView()
setOnClickListeners()
observableFromSearchView(search_view)
.debounce(300, TimeUnit.MILLISECONDS)
.filter { item -> item.length > 1 }
......@@ -55,6 +63,17 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
}
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
android.R.id.home -> {
finish()
return true
}
}
return super.onOptionsItemSelected(item)
}
private fun addNewChip(memberViewModel: MemberViewModel) {
val memberChip = Chip(this)
memberChip.chipText = memberViewModel.username
......@@ -67,10 +86,15 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
}
members_chips.addView(memberChip)
memberViewModel.username?.let { membersToAdd.add(it) }
Toast.makeText(this, membersToAdd.size.toString(), Toast.LENGTH_SHORT).show()
}
private fun updateToolBar() {
toolbar_action_text.isEnabled = membersToAdd.isNotEmpty()
if (membersToAdd.size == 0) {
toolbar_action_text.alpha = 0.8f
} else {
toolbar_action_text.alpha = 1.0f
}
toolbar_title.text = getString(R.string.title_add_members, membersToAdd.size)
}
......@@ -131,6 +155,17 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
}
private fun setOnClickListeners() {
toolbar_action_text.setOnClickListener { view ->
if (view.isEnabled) {
val intent = Intent()
intent.putExtra("members", membersToAdd)
setResult(Activity.RESULT_OK, intent)
finish()
}
}
}
private fun observableFromSearchView(searchView: EditText): Observable<String> {
val observableSubject: BehaviorSubject<String> = BehaviorSubject.create()
RxTextView.textChanges(searchView).subscribe { text ->
......
package chat.rocket.android.createChannel.ui
import android.app.Activity
import android.content.Intent
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.addMembers.ui.AddMembersActivity
import chat.rocket.android.createChannel.presentation.CreateNewChannelPresenter
......@@ -18,11 +20,13 @@ import kotlinx.android.synthetic.main.activity_create_new_channel.*
import kotlinx.android.synthetic.main.layout_toolbar.*
import javax.inject.Inject
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 listOfUsers: ArrayList<String> = ArrayList()
override fun showLoading() {
view_loading.setVisible(true)
......@@ -71,6 +75,16 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
setUpOnClickListeners()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
if (requestCode == ADD_MEMBERS_ACTIVITY_REQUEST_CODE && data != null) {
listOfUsers = data.getStringArrayListExtra("members")
Toast.makeText(this, listOfUsers.size.toString(), Toast.LENGTH_SHORT).show()
}
}
}
private fun setUpToolBar() {
setSupportActionBar(toolbar)
toolbar_title.text = getString(R.string.title_create_new_channel)
......@@ -78,7 +92,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
RxTextView.textChanges(channel_name_edit_text).subscribe { text ->
toolbar_action_text.isEnabled = text.isNotEmpty()
toolbar_action_text.isEnabled = (text.isNotEmpty() && listOfUsers.isNotEmpty())
if (text.isEmpty()) {
toolbar_action_text.alpha = 0.8f
} else {
......@@ -141,14 +155,15 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
presenter.createNewChannel(
roomTypeOf(channelType),
channel_name_edit_text.text.toString(),
listOf("aniket03"),
listOfUsers,
false
)
}
}
add_members_view.setOnClickListener {
startActivity(Intent(this, AddMembersActivity::class.java))
val intent = Intent(this, AddMembersActivity::class.java)
startActivityForResult(intent, ADD_MEMBERS_ACTIVITY_REQUEST_CODE)
}
}
}
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/white"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
......@@ -22,13 +22,13 @@
<android.support.design.chip.ChipGroup
android:id="@+id/members_chips"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="8dp"
app:chipSpacing="3dp"
style="@style/Widget.MaterialComponents.Chip.Entry">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.design.chip.ChipGroup>
......@@ -48,12 +48,11 @@
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:backgroundTint="@color/default_background"
android:backgroundTint="@android:color/transparent"
android:hint="@string/msg_search"
android:paddingBottom="8dp"
android:paddingEnd="8dp"
android:paddingStart="8dp"
app:layout_constraintTop_toBottomOf="@id/members_chips" />
<View
......
......@@ -64,7 +64,7 @@
android:layout_alignParentRight="true"
app:useCompatPadding="true"
android:layout_alignParentBottom="true"
android:src="@drawable/ic_add_24dp"
android:src="@drawable/ic_add_white_24dp"
app:backgroundTint="@color/black"
/>
</RelativeLayout>
\ No newline at end of file
......@@ -15,6 +15,10 @@
<string name="title_password">Cambia la contraseña</string>
<string name="title_update_profile">Actualización del perfil</string>
<string name="title_about">Acerca de</string>
// TODO: Add proper translation.
<string name="title_create_new_channel">Create New Channel</string>
// TODO: Add proper translation.
<string name="title_add_members">Invite Members (%d)</string>
<!-- Actions -->
<string name="action_connect">Conectar</string>"'
......@@ -120,6 +124,8 @@
// TODO: Add proper translation.
<string name="msg_several_users_are_typing">Several users are typing…</string>
<string name="msg_no_search_found">No se han encontrado resultados</string>
// TODO: Add proper translation.
<string name="msg_member_already_added">You have already selected this user</string>
<!-- System messages -->
<string name="message_room_name_changed">Nombre de la sala cambiado para: %1$s por %2$s</string>
......
......@@ -15,6 +15,10 @@
<string name="title_password">Changer le mot de passe</string>
<string name="title_update_profile">Update profile</string>
<string name="title_about">Sur</string>
// TODO: Add proper translation.
<string name="title_create_new_channel">Create New Channel</string>
// TODO: Add proper translation.
<string name="title_add_members">Invite Members (%d)</string>
<!-- Actions -->
<string name="action_connect">Se connecter</string>
......@@ -120,6 +124,8 @@
// TODO: Add proper translation.
<string name="msg_several_users_are_typing">Several users are typing…</string>
<string name="msg_no_search_found">Aucun résultat trouvé</string>
// TODO: Add proper translation.
<string name="msg_member_already_added">You have already selected this user</string>
<!-- System messages -->
<string name="message_room_name_changed">Le nom de le salle a changé à: %1$s par %2$s</string>
......
......@@ -16,6 +16,10 @@
<string name="title_password">पासवर्ड बदलें</string>
<string name="title_update_profile">प्रोफ़ाइल अपडेट करें</string>
<string name="title_about">परिचय</string>
// TODO: Add proper translation.
<string name="title_create_new_channel">Create New Channel</string>
// TODO: Add proper translation.
<string name="title_add_members">Invite Members (%d)</string>
<!-- Actions -->
<string name="action_connect">जुडिये</string>
......@@ -122,6 +126,8 @@
// TODO: Add proper translation.
<string name="msg_several_users_are_typing">Several users are typing…</string>
<string name="msg_no_search_found">कोई परिणाम नहीं मिला</string>
// TODO: Add proper translation.
<string name="msg_member_already_added">You have already selected this user</string>
<!-- System messages -->
<string name="message_room_name_changed">%2$s ने रूम का नाम बदलकर %1$s किया</string>
......
......@@ -15,6 +15,10 @@
<string name="title_password">Alterar senha</string>
<string name="title_update_profile">Editar perfil</string>
<string name="title_about">Sobre</string>
// TODO: Add proper translation.
<string name="title_create_new_channel">Create New Channel</string>
// TODO: Add proper translation.
<string name="title_add_members">Invite Members (%d)</string>
<!-- Actions -->
<string name="action_connect">Conectar</string>
......@@ -112,6 +116,8 @@
<string name="msg_are_typing">\u0020estão digitando…</string>
<string name="msg_several_users_are_typing">Vários usuários estão digitando…</string>
<string name="msg_no_search_found">nenhum resultado encontrado</string>
// TODO: Add proper translation.
<string name="msg_member_already_added">You have already selected this user</string>
<!-- System messages -->
<string name="message_room_name_changed">Nome da sala alterado para: %1$s por %2$s</string>
......
......@@ -31,8 +31,8 @@
<string name="action_logout">Logout</string>
<string name="action_files">Files</string>
<string name="action_confirm_password">Confirm Password Change</string>
<string name="action_create_new_channel">Create</string>
<string name="action_select_members">Done</string>
<string name="action_create_new_channel">CREATE</string>
<string name="action_select_members">DONE</string>
<string name="action_join_chat">Join Chat</string>
<string name="action_add_account">Add account</string>
<string name="action_online">Online</string>
......@@ -121,6 +121,7 @@
<string name="msg_are_typing">\u0020are typing…</string>
<string name="msg_several_users_are_typing">Several users are typing…</string>
<string name="msg_no_search_found">No result found</string>
<string name="msg_member_already_added">You have already selected this user</string>
<!--info for creating a channel-->
<string name="private_channel_type">Private</string>
......
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