Commit 5dc78f82 authored by Lucio Maciel's avatar Lucio Maciel

More idiomatic kotlin

when can return a value
parent 9ff47c86
...@@ -13,6 +13,7 @@ import chat.rocket.android.server.infraestructure.ConnectionManagerFactory ...@@ -13,6 +13,7 @@ import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.util.extensions.addFragment import chat.rocket.android.util.extensions.addFragment
import chat.rocket.android.util.extensions.textContent import chat.rocket.android.util.extensions.textContent
import chat.rocket.common.model.RoomType import chat.rocket.common.model.RoomType
import chat.rocket.common.model.roomTypeOf
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector import dagger.android.DispatchingAndroidInjector
...@@ -87,17 +88,18 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector { ...@@ -87,17 +88,18 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
supportActionBar?.setDisplayShowTitleEnabled(false) supportActionBar?.setDisplayShowTitleEnabled(false)
text_room_name.textContent = chatRoomName text_room_name.textContent = chatRoomName
var drawable: Drawable? = null val roomType = roomTypeOf(chatRoomType)
when (chatRoomType) { val drawable = when (roomType) {
RoomType.CHANNEL.toString() -> { is RoomType.Channel -> {
drawable = DrawableHelper.getDrawableFromId(R.drawable.ic_room_channel, this) DrawableHelper.getDrawableFromId(R.drawable.ic_room_channel, this)
} }
RoomType.PRIVATE_GROUP.toString() -> { is RoomType.PrivateGroup -> {
drawable = DrawableHelper.getDrawableFromId(R.drawable.ic_room_lock, this) DrawableHelper.getDrawableFromId(R.drawable.ic_room_lock, this)
} }
RoomType.DIRECT_MESSAGE.toString() -> { is RoomType.DirectMessage -> {
drawable = DrawableHelper.getDrawableFromId(R.drawable.ic_room_dm, this) DrawableHelper.getDrawableFromId(R.drawable.ic_room_dm, this)
} }
else -> null
} }
drawable?.let { drawable?.let {
......
...@@ -76,27 +76,27 @@ class ChatRoomsAdapter(private val context: Context, ...@@ -76,27 +76,27 @@ class ChatRoomsAdapter(private val context: Context,
private fun bindName(chatRoom: ChatRoom, textView: TextView) { private fun bindName(chatRoom: ChatRoom, textView: TextView) {
textView.textContent = chatRoom.name textView.textContent = chatRoom.name
var drawable: Drawable? = null var drawable = when (chatRoom.type) {
when (chatRoom.type) {
is RoomType.Channel -> { is RoomType.Channel -> {
drawable = DrawableHelper.getDrawableFromId(R.drawable.ic_room_channel, context) DrawableHelper.getDrawableFromId(R.drawable.ic_room_channel, context)
} }
is RoomType.PrivateGroup -> { is RoomType.PrivateGroup -> {
drawable = DrawableHelper.getDrawableFromId(R.drawable.ic_room_lock, context) DrawableHelper.getDrawableFromId(R.drawable.ic_room_lock, context)
} }
is RoomType.DirectMessage -> { is RoomType.DirectMessage -> {
drawable = DrawableHelper.getDrawableFromId(R.drawable.ic_room_dm, context) DrawableHelper.getDrawableFromId(R.drawable.ic_room_dm, context)
} }
else -> null
} }
drawable?.let { drawable?.let {
val wrappedDrawable = DrawableHelper.wrapDrawable(it) val wrappedDrawable = DrawableHelper.wrapDrawable(it)
val mutableDrawable = wrappedDrawable.mutate() val mutableDrawable = wrappedDrawable.mutate()
DrawableHelper.tintDrawable(mutableDrawable, context, val color = when (chatRoom.alert || chatRoom.unread > 0) {
when (chatRoom.alert || chatRoom.unread > 0) {
true -> R.color.colorPrimaryText true -> R.color.colorPrimaryText
false -> R.color.colorSecondaryText false -> R.color.colorSecondaryText
}) }
DrawableHelper.tintDrawable(mutableDrawable, context, color)
DrawableHelper.compoundDrawable(textView, mutableDrawable) DrawableHelper.compoundDrawable(textView, mutableDrawable)
} }
} }
......
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