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