Commit 89aad912 authored by aniket's avatar aniket

deals with many more cases

parent 2c4dffeb
...@@ -37,9 +37,9 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -37,9 +37,9 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
addNewChip(memberViewModel) addNewChip(memberViewModel)
updateToolBar() updateToolBar()
search_view.setText("") search_view.setText("")
} } else {
else { Toast.makeText(this, getString(R.string.msg_member_already_added), Toast.LENGTH_LONG)
Toast.makeText(this, getString(R.string.msg_member_already_added), Toast.LENGTH_LONG).show() .show()
} }
} }
private var linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) private var linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
...@@ -51,6 +51,7 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -51,6 +51,7 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
setUpToolBar() setUpToolBar()
setUpRecyclerView() setUpRecyclerView()
setOnClickListeners() setOnClickListeners()
setInitialChips()
observableFromSearchView(search_view) observableFromSearchView(search_view)
.debounce(300, TimeUnit.MILLISECONDS) .debounce(300, TimeUnit.MILLISECONDS)
.filter { item -> item.length > 1 } .filter { item -> item.length > 1 }
...@@ -74,33 +75,10 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -74,33 +75,10 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
private fun addNewChip(memberViewModel: MemberViewModel) {
val memberChip = Chip(this)
memberChip.chipText = memberViewModel.username
memberChip.isCloseIconEnabled = true
memberChip.setChipBackgroundColorResource(R.color.icon_grey)
memberChip.setOnCloseIconClickListener { view ->
members_chips.removeView(view)
membersToAdd.remove((view as Chip).chipText.toString())
updateToolBar()
}
members_chips.addView(memberChip)
memberViewModel.username?.let { membersToAdd.add(it) }
}
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)
}
override fun showMembers(dataSet: List<MemberViewModel>, total: Long) { override fun showMembers(dataSet: List<MemberViewModel>, total: Long) {
if (adapter.itemCount == 0) { if (adapter.itemCount == 0) {
adapter.prependData(dataSet) adapter.prependData(dataSet)
//TODO work on this part after adding support for count and offset in sdk
// if (dataSet.size >= 59) { // TODO Check why the API retorns the specified count -1 // if (dataSet.size >= 59) { // TODO Check why the API retorns the specified count -1
// search_results.addOnScrollListener(object : // search_results.addOnScrollListener(object :
// EndlessRecyclerViewScrollListener(linearLayoutManager) { // EndlessRecyclerViewScrollListener(linearLayoutManager) {
...@@ -139,6 +117,43 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -139,6 +117,43 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
showMessage(getString(R.string.msg_generic_error)) showMessage(getString(R.string.msg_generic_error))
} }
private fun setInitialChips() {
membersToAdd = intent.getStringArrayListExtra("chips")
for (element in membersToAdd) {
buildNewChip(element)
}
updateToolBar()
}
private fun addNewChip(memberViewModel: MemberViewModel) {
memberViewModel.username?.let {
buildNewChip(it)
membersToAdd.add(it)
}
}
private fun buildNewChip(chipText: String) {
val memberChip = Chip(this)
memberChip.chipText = chipText
memberChip.isCloseIconEnabled = true
memberChip.setChipBackgroundColorResource(R.color.icon_grey)
memberChip.setOnCloseIconClickListener { view ->
members_chips.removeView(view)
membersToAdd.remove((view as Chip).chipText.toString())
updateToolBar()
}
members_chips.addView(memberChip)
}
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)
}
private fun setUpToolBar() { private fun setUpToolBar() {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
...@@ -152,7 +167,6 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView { ...@@ -152,7 +167,6 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
search_results.layoutManager = linearLayoutManager search_results.layoutManager = linearLayoutManager
search_results.adapter = adapter search_results.adapter = adapter
search_results.addItemDecoration(DividerItemDecoration(this)) search_results.addItemDecoration(DividerItemDecoration(this))
} }
private fun setOnClickListeners() { private fun setOnClickListeners() {
......
...@@ -4,6 +4,7 @@ import android.app.Activity ...@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.os.Bundle import android.os.Bundle
import android.support.design.chip.Chip
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.view.MenuItem import android.view.MenuItem
import android.widget.Toast import android.widget.Toast
...@@ -28,6 +29,36 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -28,6 +29,36 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
private var channelType: String = "public" private var channelType: String = "public"
private var listOfUsers: ArrayList<String> = ArrayList() private var listOfUsers: ArrayList<String> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_create_new_channel)
setUpToolBar()
setUpOnClickListeners()
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
android.R.id.home -> {
finish()
return true
}
}
return super.onOptionsItemSelected(item)
}
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")
selected_members_chips.removeAllViews()
refreshMembersChips()
}
}
}
override fun showLoading() { override fun showLoading() {
view_loading.setVisible(true) view_loading.setVisible(true)
layout_container.alpha = 0.5f layout_container.alpha = 0.5f
...@@ -42,6 +73,8 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -42,6 +73,8 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
override fun showChannelCreatedSuccessfullyMessage() { override fun showChannelCreatedSuccessfullyMessage() {
showToast(getString(R.string.msg_channel_created_successfully)) showToast(getString(R.string.msg_channel_created_successfully))
finish()
//TODO check why the activity is not finishing
} }
override fun showMessage(resId: Int) { override fun showMessage(resId: Int) {
...@@ -56,32 +89,15 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -56,32 +89,15 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
showMessage(getString(R.string.msg_generic_error)) showMessage(getString(R.string.msg_generic_error))
} }
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
android.R.id.home -> {
finish()
return true
}
}
return super.onOptionsItemSelected(item)
}
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_create_new_channel)
setUpToolBar()
setUpOnClickListeners()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { private fun refreshMembersChips() {
super.onActivityResult(requestCode, resultCode, data) for (element in listOfUsers) {
if (resultCode == Activity.RESULT_OK) { val memberChip = Chip(this)
if (requestCode == ADD_MEMBERS_ACTIVITY_REQUEST_CODE && data != null) { memberChip.chipText = element
listOfUsers = data.getStringArrayListExtra("members") memberChip.isCloseIconEnabled = false
Toast.makeText(this, listOfUsers.size.toString(), Toast.LENGTH_SHORT).show() memberChip.isLongClickable = false
} memberChip.setChipBackgroundColorResource(R.color.icon_grey)
selected_members_chips.addView(memberChip)
} }
} }
...@@ -163,6 +179,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView { ...@@ -163,6 +179,7 @@ class CreateNewChannelActivity : AppCompatActivity(), CreateNewChannelView {
add_members_view.setOnClickListener { add_members_view.setOnClickListener {
val intent = Intent(this, AddMembersActivity::class.java) val intent = Intent(this, AddMembersActivity::class.java)
intent.putExtra("chips", listOfUsers)
startActivityForResult(intent, ADD_MEMBERS_ACTIVITY_REQUEST_CODE) startActivityForResult(intent, ADD_MEMBERS_ACTIVITY_REQUEST_CODE)
} }
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
android:id="@+id/layout_container" android:id="@+id/layout_container"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:padding="16dp" android:paddingTop="16dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
...@@ -80,20 +80,24 @@ ...@@ -80,20 +80,24 @@
android:id="@+id/channel_type" android:id="@+id/channel_type"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:text="@string/public_channel_type" android:text="@string/public_channel_type"
android:textColor="@color/colorPrimaryText" android:textColor="@color/colorPrimaryText"
android:textSize="16sp" android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/public_channel" /> app:layout_constraintTop_toBottomOf="@id/public_channel" />
<TextView <TextView
android:id="@+id/channel_description" android:id="@+id/channel_description"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:text="@string/public_channel_description" android:text="@string/public_channel_description"
android:textColor="@color/colorSecondaryText" android:textColor="@color/colorSecondaryText"
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/channel_type" /> app:layout_constraintTop_toBottomOf="@id/channel_type" />
<View <View
...@@ -108,6 +112,7 @@ ...@@ -108,6 +112,7 @@
android:id="@+id/placeholder" android:id="@+id/placeholder"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:src="@drawable/ic_hashtag_black" android:src="@drawable/ic_hashtag_black"
app:layout_constraintBottom_toBottomOf="@id/channel_name_text_input_layout" app:layout_constraintBottom_toBottomOf="@id/channel_name_text_input_layout"
...@@ -119,6 +124,7 @@ ...@@ -119,6 +124,7 @@
android:id="@+id/channel_name_text_input_layout" android:id="@+id/channel_name_text_input_layout"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:focusable="true" android:focusable="true"
...@@ -146,9 +152,9 @@ ...@@ -146,9 +152,9 @@
android:id="@+id/add_members_view" android:id="@+id/add_members_view"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/separator_2"> app:layout_constraintTop_toBottomOf="@id/separator_2">
...@@ -157,10 +163,11 @@ ...@@ -157,10 +163,11 @@
android:id="@+id/add_members_text" android:id="@+id/add_members_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="@string/msg_add_members" android:text="@string/msg_add_members"
android:textColor="@color/colorSecondaryText" android:textColor="@color/colorSecondaryText"
android:textSize="16sp" android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="spread" app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
...@@ -168,10 +175,27 @@ ...@@ -168,10 +175,27 @@
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_person_add_black_24dp" android:src="@drawable/ic_person_add_black_24dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1" app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toEndOf="@id/add_members_text" /> app:layout_constraintStart_toEndOf="@id/add_members_text"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.chip.ChipGroup
android:id="@+id/selected_members_chips"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:chipSpacing="3dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_members_text">
</android.support.design.chip.ChipGroup>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
<View <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