Commit a0058ba9 authored by Samer Alabi's avatar Samer Alabi

Added requested changes

parent a0b264a2
package chat.rocket.android.chatdetails.adapter
import chat.rocket.android.chatdetails.domain.Option
import chat.rocket.android.chatrooms.adapter.ItemHolder
data class OptionItemHolder(override val data: Option): ItemHolder<Option>
\ No newline at end of file
package chat.rocket.android.chatdetails.adapter
import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import chat.rocket.android.R
import chat.rocket.android.chatdetails.domain.Option
import chat.rocket.android.chatrooms.adapter.ViewHolder
import kotlinx.android.synthetic.main.item_detail_option.view.*
class OptionViewHolder(
itemView: View
): ViewHolder<OptionItemHolder>(itemView) {
override fun bindViews(data: OptionItemHolder) {
val option = data.data
bindName(option, itemView.name)
bindIcon(option, itemView.icon)
itemView.setOnClickListener { option.listener() }
}
private fun bindIcon(option: Option, view: ImageView) {
val drawable = DrawableHelper.getDrawableFromId(option.icon, itemView.context)
drawable.let { image ->
val mutateDrawable = DrawableHelper.wrapDrawable(image).mutate()
DrawableHelper.tintDrawable(mutateDrawable, itemView.context, R.color.colorPrimaryText)
view.setImageDrawable(mutateDrawable)
}
}
private fun bindName(option: Option, view: TextView) {
view.text = option.name
}
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ import kotlinx.coroutines.experimental.Job
@Module
class ChatDetailsFragmentModule {
@Provides
@PerFragment
fun provideJob() = Job()
......
......@@ -7,6 +7,7 @@ import dagger.android.ContributesAndroidInjector
@Module
abstract class ChatDetailsFragmentProvider {
@ContributesAndroidInjector(modules = [ChatDetailsFragmentModule::class])
@PerFragment
abstract fun providesChatDetailsFragment(): ChatDetailsFragment
......
......@@ -8,6 +8,7 @@ import dagger.Provides
@Module
class ChatDetailsModule {
@Provides
@PerActivity
fun providesNavigator(activity: ChatDetailsActivity) = ChatDetailsNavigator(activity)
......
package chat.rocket.android.chatdetails.domain
data class Option(
val name: String,
val icon: Int,
val listener: () -> Unit
)
\ No newline at end of file
......@@ -10,6 +10,7 @@ import chat.rocket.android.pinnedmessages.ui.TAG_PINNED_MESSAGES_FRAGMENT
import chat.rocket.android.util.extensions.addFragmentBackStack
class ChatDetailsNavigator(internal val activity: ChatDetailsActivity) {
fun toMembersList(chatRoomId: String) {
activity.addFragmentBackStack(TAG_MEMBERS_FRAGMENT, R.id.fragment_container) {
chat.rocket.android.members.ui.newInstance(chatRoomId)
......
......@@ -5,6 +5,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.retryIO
import chat.rocket.common.model.roomTypeOf
import chat.rocket.common.util.ifNull
import chat.rocket.core.internal.rest.getInfo
......@@ -25,7 +26,11 @@ class ChatDetailsPresenter @Inject constructor(
fun getDetails(chatRoomId: String, chatRoomType: String) {
launchUI(strategy) {
try {
view.displayDetails(roomToChatDetails(client.getInfo(chatRoomId, null, roomTypeOf(chatRoomType))))
val room = retryIO("getInfo($chatRoomId, null, $chatRoomType") {
client.getInfo(chatRoomId, null, roomTypeOf(chatRoomType))
}
view.displayDetails(roomToChatDetails(room))
} catch(e: Exception) {
e.message.let {
view.showMessage(it!!)
......
package chat.rocket.android.chatdetails.ui
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import chat.rocket.android.R
import chat.rocket.android.chatdetails.adapter.OptionItemHolder
import chat.rocket.android.chatdetails.adapter.OptionViewHolder
import chat.rocket.android.chatdetails.domain.Option
import chat.rocket.android.util.extensions.inflate
import kotlinx.android.synthetic.main.item_detail_option.view.*
class ChatDetailsAdapter(private val context: Context): RecyclerView.Adapter<ChatDetailsAdapter.ViewHolder>() {
class ChatDetailsAdapter: RecyclerView.Adapter<OptionViewHolder>() {
private val options: MutableList<Option> = ArrayList()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = ViewHolder(parent.inflate(R.layout.item_detail_option))
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OptionViewHolder = OptionViewHolder(parent.inflate(R.layout.item_detail_option))
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(options[position])
override fun onBindViewHolder(holder: OptionViewHolder, position: Int) = holder.bindViews(OptionItemHolder(options[position]))
override fun getItemCount(): Int = options.size
inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
fun bind(option: Option) {
bindName(option, itemView.name)
bindIcon(option, itemView.icon)
itemView.setOnClickListener { option.listener() }
}
}
inner class Option(val name: String, val icon: Int, val listener: () -> Unit)
fun addOption(name: String, icon: Int, listener: () -> Unit) {
options.add(Option(name, icon, listener))
notifyDataSetChanged()
}
private fun bindName(option: Option, view: TextView) {
view.text = option.name
}
private fun bindIcon(option: Option, view: ImageView) {
val drawable = DrawableHelper.getDrawableFromId(option.icon, context)
drawable.let { image ->
val mutateDrawable = DrawableHelper.wrapDrawable(image).mutate()
DrawableHelper.tintDrawable(mutateDrawable, context, R.color.colorPrimaryText)
view.setImageDrawable(mutateDrawable)
}
}
}
\ No newline at end of file
......@@ -114,27 +114,29 @@ class ChatDetailsFragment: Fragment(), ChatDetailsView {
}
}
private fun addOptions(adapter: ChatDetailsAdapter) {
if (!disableMenu) {
adapter.addOption(getString(R.string.title_files), R.drawable.ic_files_24dp) {
presenter.toFiles(chatRoomId!!)
private fun addOptions(adapter: ChatDetailsAdapter?) {
adapter?.let {
if (!disableMenu) {
it.addOption(getString(R.string.title_files), R.drawable.ic_files_24dp) {
presenter.toFiles(chatRoomId!!)
}
}
}
if (chatRoomType != RoomType.DIRECT_MESSAGE && !disableMenu) {
adapter.addOption(getString(R.string.msg_mentions), R.drawable.ic_at_black_20dp) {
presenter.toMentions(chatRoomId!!)
}
adapter.addOption(getString(R.string.title_members), R.drawable.ic_people_outline_black_24dp) {
presenter.toMembers(chatRoomId!!)
if (chatRoomType != RoomType.DIRECT_MESSAGE && !disableMenu) {
it.addOption(getString(R.string.msg_mentions), R.drawable.ic_at_black_20dp) {
presenter.toMentions(chatRoomId!!)
}
it.addOption(getString(R.string.title_members), R.drawable.ic_people_outline_black_24dp) {
presenter.toMembers(chatRoomId!!)
}
}
}
adapter.addOption(getString(R.string.title_favorite_messages), R.drawable.ic_star_border_white_24dp) {
presenter.toFavorites(chatRoomId!!)
}
adapter.addOption(getString(R.string.title_pinned_messages), R.drawable.ic_action_message_pin_24dp) {
presenter.toPinned(chatRoomId!!)
it.addOption(getString(R.string.title_favorite_messages), R.drawable.ic_star_border_white_24dp) {
presenter.toFavorites(chatRoomId!!)
}
it.addOption(getString(R.string.title_pinned_messages), R.drawable.ic_action_message_pin_24dp) {
presenter.toPinned(chatRoomId!!)
}
}
}
......@@ -169,7 +171,7 @@ class ChatDetailsFragment: Fragment(), ChatDetailsView {
private fun setupOptions() {
ui {
if (options.adapter == null) {
adapter = ChatDetailsAdapter(context!!)
adapter = ChatDetailsAdapter()
options.adapter = adapter
with(options) {
......@@ -185,7 +187,7 @@ class ChatDetailsFragment: Fragment(), ChatDetailsView {
isNestedScrollingEnabled = false
}
}
addOptions(adapter!!)
addOptions(adapter)
}
}
......
......@@ -8,6 +8,7 @@ import chat.rocket.android.chatdetails.domain.ChatDetails
import chat.rocket.android.db.ChatRoomDao
class ChatDetailsViewModel(private val chatRoomDao: ChatRoomDao): ViewModel() {
fun getDetails(chatRoomId: String): LiveData<ChatDetails> {
return Transformations.switchMap(chatRoomDao.get(chatRoomId)) { room ->
val entity = room.chatRoom
......
......@@ -6,6 +6,7 @@ import chat.rocket.android.db.ChatRoomDao
import javax.inject.Inject
class ChatDetailsViewModelFactory @Inject constructor(private val chatRoomDao: ChatRoomDao) : ViewModelProvider.NewInstanceFactory() {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>) =
ChatDetailsViewModel(chatRoomDao) as T
......
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