From c1fa728c24d740e58c18a100beb20e9e9584287f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 3 Jun 2019 16:04:22 +0200 Subject: [PATCH] Public rooms little rework --- matrix-sdk-android/build.gradle | 4 +- vector/sampledata/matrix.json | 6 + .../features/roomdirectory/PublicRoomItem.kt | 11 ++ .../roomdirectory/PublicRoomsController.kt | 2 + .../roomdirectory/PublicRoomsFragment.kt | 40 ++++-- .../picker/RoomDirectoryPickerFragment.kt | 2 +- .../main/res/layout/fragment_public_rooms.xml | 116 ++++++------------ .../src/main/res/layout/item_public_room.xml | 70 ++++++++--- .../src/main/res/menu/menu_room_directory.xml | 10 ++ vector/src/main/res/values/strings_riotX.xml | 1 + 10 files changed, 155 insertions(+), 107 deletions(-) create mode 100644 vector/src/main/res/menu/menu_room_directory.xml diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index c04907ab..8fcc1a25 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -45,10 +45,10 @@ android { debug { // Set to true to log privacy or sensible data, such as token - buildConfigField "boolean", "LOG_PRIVATE_DATA", "false" + buildConfigField "boolean", "LOG_PRIVATE_DATA", "true" // Set to BODY instead of NONE to enable logging - buildConfigField "okhttp3.logging.HttpLoggingInterceptor.Level", "OKHTTP_LOGGING_LEVEL", "okhttp3.logging.HttpLoggingInterceptor.Level.NONE" + buildConfigField "okhttp3.logging.HttpLoggingInterceptor.Level", "OKHTTP_LOGGING_LEVEL", "okhttp3.logging.HttpLoggingInterceptor.Level.BODY" } release { diff --git a/vector/sampledata/matrix.json b/vector/sampledata/matrix.json index e8bd85d1..b9c55b91 100644 --- a/vector/sampledata/matrix.json +++ b/vector/sampledata/matrix.json @@ -5,6 +5,7 @@ "mxid": "@longmatrixidbecausesometimesuserschooselongmxid:matrix.org", "message": "William Shakespeare (bapt. 26 April 1564 – 23 April 1616) was an English poet, playwright and actor, widely regarded as the greatest writer in the English language and the world's greatest dramatist. He is often called England's national poet and the \"Bard of Avon\". His extant works, including collaborations, consist of approximately 39 plays, 154 sonnets, two long narrative poems, and a few other verses, some of uncertain authorship. His plays have been translated into every major living language and are performed more often than those of any other playwright.\n\nShakespeare was born and raised in Stratford-upon-Avon, Warwickshire. At the age of 18, he married Anne Hathaway, with whom he had three children: Susanna and twins Hamnet and Judith. Sometime between 1585 and 1592, he began a successful career in London as an actor, writer, and part-owner of a playing company called the Lord Chamberlain's Men, later known as the King's Men. At age 49 (around 1613), he appears to have retired to Stratford, where he died three years later. Few records of Shakespeare's private life survive; this has stimulated considerable speculation about such matters as his physical appearance, his sexuality, his religious beliefs, and whether the works attributed to him were written by others. Such theories are often criticised for failing to adequately note that few records survive of most commoners of the period.\n\nShakespeare produced most of his known works between 1589 and 1613. His early plays were primarily comedies and histories and are regarded as some of the best work produced in these genres. Until about 1608, he wrote mainly tragedies, among them Hamlet, Othello, King Lear, and Macbeth, all considered to be among the finest works in the English language. In the last phase of his life, he wrote tragicomedies (also known as romances) and collaborated with other playwrights.\n\nMany of Shakespeare's plays were published in editions of varying quality and accuracy in his lifetime. However, in 1623, two fellow actors and friends of Shakespeare's, John Heminges and Henry Condell, published a more definitive text known as the First Folio, a posthumous collected edition of Shakespeare's dramatic works that included all but two of his plays. The volume was prefaced with a poem by Ben Jonson, in which Jonson presciently hails Shakespeare in a now-famous quote as \"not of an age, but for all time\".\n\nThroughout the 20th and 21st centuries, Shakespeare's works have been continually adapted and rediscovered by new movements in scholarship and performance. His plays remain popular and are studied, performed, and reinterpreted through various cultural and political contexts around the world.", "roomName": "Matrix HQ", + "roomAlias": "#matrix:matrix.org", "roomTopic": "Welcome to Matrix HQ! Here is the rest of the room topic…" }, { @@ -12,6 +13,7 @@ "mxid": "@benoit:matrix.org", "message": "Hello!", "roomName": "Room name very loooooooong with some details", + "roomAlias": "#matrix:matrix.org", "roomTopic": "Room topic very loooooooong with some details" }, { @@ -19,6 +21,7 @@ "mxid": "@ganfra:matrix.org", "message": "How are you?", "roomName": "Room name very loooooooong with some details", + "roomAlias": "#matrix:matrix.org", "roomTopic": "Room topic very loooooooong with some details" }, { @@ -26,6 +29,7 @@ "mxid": "@manu:matrix.org", "message": "Great weather today!", "roomName": "Room name very loooooooong with some details", + "roomAlias": "#matrix:matrix.org", "roomTopic": "Room topic very loooooooong with some details" }, { @@ -33,6 +37,7 @@ "mxid": "@giom:matrix.org", "message": "Let's do a picnic", "roomName": "Room name very loooooooong with some details", + "roomAlias": "#matrix:matrix.org", "roomTopic": "Room topic very loooooooong with some details" }, { @@ -40,6 +45,7 @@ "mxid": "@nadonomy:matrix.org", "message": "Yes, great idea", "roomName": "Room name very loooooooong with some details", + "roomAlias": "#matrix:matrix.org", "roomTopic": "Room topic very loooooooong with some details" } ] diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomItem.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomItem.kt index 2825c09f..8e30809f 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomItem.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomItem.kt @@ -24,6 +24,7 @@ import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotredesign.R import im.vector.riotredesign.core.epoxy.VectorEpoxyHolder import im.vector.riotredesign.core.epoxy.VectorEpoxyModel +import im.vector.riotredesign.core.extensions.setTextOrHide import im.vector.riotredesign.core.platform.ButtonStateView import im.vector.riotredesign.features.home.AvatarRenderer @@ -39,6 +40,12 @@ abstract class PublicRoomItem : VectorEpoxyModel() { @EpoxyAttribute var roomName: String? = null + @EpoxyAttribute + var roomAlias: String? = null + + @EpoxyAttribute + var roomTopic: String? = null + @EpoxyAttribute var nbOfMembers: Int = 0 @@ -56,6 +63,8 @@ abstract class PublicRoomItem : VectorEpoxyModel() { AvatarRenderer.render(avatarUrl, roomId!!, roomName, holder.avatarView) holder.nameView.text = roomName + holder.aliasView.setTextOrHide(roomAlias) + holder.topicView.setTextOrHide(roomTopic) // TODO Use formatter for big numbers? holder.counterView.text = nbOfMembers.toString() @@ -85,6 +94,8 @@ abstract class PublicRoomItem : VectorEpoxyModel() { val avatarView by bind(R.id.itemPublicRoomAvatar) val nameView by bind(R.id.itemPublicRoomName) + val aliasView by bind(R.id.itemPublicRoomAlias) + val topicView by bind(R.id.itemPublicRoomTopic) val counterView by bind(R.id.itemPublicRoomMembersCount) val buttonState by bind(R.id.itemPublicRoomButtonState) diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt index 50b1d3cd..01309e9e 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt @@ -82,6 +82,8 @@ class PublicRoomsController(private val stringProvider: StringProvider, roomId(publicRoom.roomId) avatarUrl(publicRoom.avatarUrl) roomName(publicRoom.name) + roomAlias(publicRoom.canonicalAlias) + roomTopic(publicRoom.topic) nbOfMembers(publicRoom.numJoinedMembers) val joinState = when { diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt index fea9a5a5..7c269f3d 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt @@ -17,6 +17,7 @@ package im.vector.riotredesign.features.roomdirectory import android.os.Bundle +import android.view.MenuItem import android.view.View import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager @@ -31,7 +32,6 @@ import im.vector.riotredesign.core.error.ErrorFormatter import im.vector.riotredesign.core.extensions.addFragmentToBackstack import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerFragment -import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewActivity import io.reactivex.rxkotlin.subscribeBy import kotlinx.android.synthetic.main.fragment_public_rooms.* import org.koin.android.ext.android.inject @@ -46,12 +46,20 @@ import java.util.concurrent.TimeUnit * - When filtering more (when entering new chars), we could filter on result we already have, during the new server request, to avoid empty screen effect * * TODO For Nad: - * Display number of rooms? - * Picto size are not correct - * Where I put the room directory picker? - * World Readable badge - * Guest can join badge + * Display number of rooms? -> Not displayed + * Picto size are not correct -> Fixed + * Where I put the room directory picker? -> Menu + * World Readable badge -> not displayed + * Guest can join badge -> not displayed + * Create Room -> Wait for screen * + * + * Home + * -> FAB on first screen + * -> Counter -> Ok + * + * + * @Benoit: Provide list for event type in last message on home */ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback { @@ -61,6 +69,8 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback override fun getLayoutResId() = R.layout.fragment_public_rooms + override fun getMenuRes() = R.menu.menu_room_directory + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -84,10 +94,6 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback vectorBaseActivity.notImplemented() } - publicRoomsChangeDirectory.setOnClickListener { - vectorBaseActivity.addFragmentToBackstack(RoomDirectoryPickerFragment(), R.id.simpleFragmentContainer) - } - viewModel.joinRoomErrorLiveData.observe(this, Observer { it.getContentIfNotHandled()?.let { throwable -> Snackbar.make(publicRoomsCoordinator, errorFormatter.toHumanReadable(throwable), Snackbar.LENGTH_SHORT) @@ -96,6 +102,17 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback }) } + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + R.id.menu_room_directory_change_protocol -> { + vectorBaseActivity.addFragmentToBackstack(RoomDirectoryPickerFragment(), R.id.simpleFragmentContainer) + true + } + else -> + super.onOptionsItemSelected(item) + } + } + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) bindScope(getOrCreateScope(RoomDirectoryModule.ROOM_DIRECTORY_SCOPE)) @@ -146,8 +163,5 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback override fun invalidate() = withState(viewModel) { state -> // Populate list with Epoxy publicRoomsController.setData(state) - - // Directory name - publicRoomsDirectoryName.text = state.roomDirectoryDisplayName } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt index 6ac80106..6365d39a 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt @@ -61,7 +61,7 @@ class RoomDirectoryPickerFragment : VectorBaseFragment(), RoomDirectoryPickerCon override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == R.id.action_add_custom_hs) { // TODO - vectorBaseActivity.notImplemented() + vectorBaseActivity.notImplemented("Entering custom homeserver") return true } diff --git a/vector/src/main/res/layout/fragment_public_rooms.xml b/vector/src/main/res/layout/fragment_public_rooms.xml index a369496d..6db130e8 100644 --- a/vector/src/main/res/layout/fragment_public_rooms.xml +++ b/vector/src/main/res/layout/fragment_public_rooms.xml @@ -19,88 +19,52 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:background="?attr/colorPrimary" + app:contentInsetStartWithNavigation="0dp" + app:layout_scrollFlags="noScroll" + app:popupTheme="@style/ThemeOverlay.AppCompat.Light" + app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> - + android:layout_height="32dp" + android:layout_marginStart="8dp" + android:layout_marginLeft="8dp" + android:layout_marginTop="8dp" + android:layout_marginEnd="@dimen/layout_horizontal_margin" + android:layout_marginRight="@dimen/layout_horizontal_margin" + android:layout_marginBottom="8dp" + android:background="@drawable/bg_search_edit_text" + android:drawableStart="@drawable/ic_search_white" + android:drawableLeft="@drawable/ic_search_white" + android:drawablePadding="8dp" + android:drawableTint="#9fa9ba" + android:hint="@string/home_filter_placeholder_rooms" + android:lines="1" + android:paddingLeft="8dp" + android:paddingRight="8dp" /> - + - - - - -