diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 7d78b399..da03d886 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 963750b8..1d462efa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,6 +54,11 @@ dependencies { implementation "com.airbnb.android:epoxy-paging:$epoxy_version" implementation 'com.airbnb.android:mvrx:0.6.0' + implementation 'com.github.bumptech.glide:glide:4.8.0' + kapt 'com.github.bumptech.glide:compiler:4.8.0' + //todo remove that + implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' + implementation "org.koin:koin-android:$koin_version" implementation "org.koin:koin-android-scope:$koin_version" diff --git a/app/src/main/java/im/vector/riotredesign/core/extensions/CharSequence.kt b/app/src/main/java/im/vector/riotredesign/core/extensions/CharSequence.kt new file mode 100644 index 00000000..f2e6f70b --- /dev/null +++ b/app/src/main/java/im/vector/riotredesign/core/extensions/CharSequence.kt @@ -0,0 +1,6 @@ +package im.vector.riotredesign.core.extensions + + +fun CharSequence.firstCharAsString(): String { + return this[0].toString() +} \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/RoomSummaryViewHelper.kt b/app/src/main/java/im/vector/riotredesign/features/home/RoomSummaryViewHelper.kt new file mode 100644 index 00000000..4f59f0d6 --- /dev/null +++ b/app/src/main/java/im/vector/riotredesign/features/home/RoomSummaryViewHelper.kt @@ -0,0 +1,19 @@ +package im.vector.riotredesign.features.home + +import android.content.Context +import android.graphics.drawable.Drawable +import android.support.v4.content.ContextCompat +import com.amulyakhare.textdrawable.TextDrawable +import im.vector.matrix.android.api.session.room.model.RoomSummary +import im.vector.riotredesign.R +import im.vector.riotredesign.core.extensions.firstCharAsString + +class RoomSummaryViewHelper(private val roomSummary: RoomSummary) { + + fun avatarDrawable(context: Context): Drawable { + val avatarColor = ContextCompat.getColor(context, R.color.pale_teal) + return TextDrawable.builder().buildRound(roomSummary.displayName.firstCharAsString().toUpperCase(), avatarColor) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/detail/RoomDetailFragment.kt b/app/src/main/java/im/vector/riotredesign/features/home/detail/RoomDetailFragment.kt index 7cf1f473..a06a69b0 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/detail/RoomDetailFragment.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/detail/RoomDetailFragment.kt @@ -16,6 +16,7 @@ import im.vector.riotredesign.R import im.vector.riotredesign.core.platform.RiotFragment import im.vector.riotredesign.core.platform.ToolbarConfigurable import im.vector.riotredesign.core.utils.FragmentArgumentDelegate +import im.vector.riotredesign.features.home.RoomSummaryViewHelper import kotlinx.android.synthetic.main.fragment_room_detail.* import org.koin.android.ext.android.inject @@ -76,7 +77,15 @@ class RoomDetailFragment : RiotFragment(), TimelineEventAdapter.Callback { private fun renderRoomSummary(roomSummary: RoomSummary?) { roomSummary?.let { - toolbar.title = it.displayName + val roomSummaryViewHelper = RoomSummaryViewHelper(it) + toolbarTitleView.text = it.displayName + toolbarAvatarImageView.setImageDrawable(roomSummaryViewHelper.avatarDrawable(riotActivity)) + if (it.topic.isNotEmpty()) { + toolbarSubtitleView.visibility = View.VISIBLE + toolbarSubtitleView.text = it.topic + } else { + toolbarSubtitleView.visibility = View.GONE + } } } diff --git a/app/src/main/java/im/vector/riotredesign/features/home/list/RoomListFragment.kt b/app/src/main/java/im/vector/riotredesign/features/home/list/RoomListFragment.kt index 20c58e4d..575db4e1 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/list/RoomListFragment.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/list/RoomListFragment.kt @@ -36,7 +36,7 @@ class RoomListFragment : RiotFragment(), RoomSummaryController.Callback { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - roomController = RoomSummaryController(this) + roomController = RoomSummaryController(riotActivity, this) stateView.contentView = epoxyRecyclerView epoxyRecyclerView.setController(roomController) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryController.kt b/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryController.kt index da2e3897..6b8d175b 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryController.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryController.kt @@ -1,16 +1,20 @@ package im.vector.riotredesign.features.home.list +import android.content.Context import com.airbnb.epoxy.Typed2EpoxyController import im.vector.matrix.android.api.session.room.model.RoomSummary +import im.vector.riotredesign.features.home.RoomSummaryViewHelper -class RoomSummaryController(private val callback: Callback? = null - +class RoomSummaryController(private val context: Context, + private val callback: Callback? = null ) : Typed2EpoxyController, RoomSummary>() { override fun buildModels(summaries: List?, selected: RoomSummary?) { summaries?.forEach { + val roomSummaryViewHelper = RoomSummaryViewHelper(it) RoomSummaryItem( - it.displayName, + title = it.displayName, + avatarDrawable = roomSummaryViewHelper.avatarDrawable(context), isSelected = it == selected, listener = { callback?.onRoomSelected(it) } ) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryItem.kt b/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryItem.kt index 718628dd..99393f21 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryItem.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/list/RoomSummaryItem.kt @@ -1,23 +1,28 @@ package im.vector.riotredesign.features.home.list -import android.support.v4.content.ContextCompat +import android.graphics.drawable.Drawable +import android.widget.ImageView import android.widget.TextView import im.vector.riotredesign.R import im.vector.riotredesign.core.epoxy.KotlinModel import im.vector.riotredesign.core.platform.CheckableConstraintLayout + data class RoomSummaryItem( val title: CharSequence, + val avatarDrawable: Drawable, val isSelected: Boolean, val listener: (() -> Unit)? = null ) : KotlinModel(R.layout.item_room) { - val titleView by bind(R.id.titleView) - val rootView by bind(R.id.itemRoomLayout) + private val titleView by bind(R.id.titleView) + private val avatarImageView by bind(R.id.toolbarAvatarImageView) + private val rootView by bind(R.id.itemRoomLayout) override fun bind() { rootView.isChecked = isSelected titleView.setOnClickListener { listener?.invoke() } titleView.text = title + avatarImageView.setImageDrawable(avatarDrawable) } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_room_detail.xml b/app/src/main/res/layout/fragment_room_detail.xml index 9b4f1019..3dff21eb 100644 --- a/app/src/main/res/layout/fragment_room_detail.xml +++ b/app/src/main/res/layout/fragment_room_detail.xml @@ -1,6 +1,7 @@ @@ -8,12 +9,65 @@ android:id="@+id/toolbar" android:layout_width="0dp" android:layout_height="?actionBarSize" - android:background="@color/dark" + android:background="?attr/colorPrimary" + app:contentInsetStartWithNavigation="0dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" - app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> + app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> + + + + + + + + + + + + + + android:minHeight="48dp"> + + + tools:text="@tools:sample/full_names" /> \ No newline at end of file