From cc29a387c710b4a9a851e3d1df9b02a5bc7847eb Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 29 Oct 2018 14:57:36 +0100 Subject: [PATCH] Start introducing theme on app + branch toolbar to drawer, still requires refinements --- .idea/caches/build_file_checksums.ser | Bin 661 -> 659 bytes app/src/main/AndroidManifest.xml | 2 +- .../core/platform/RiotFragment.kt | 5 ++ .../core/platform/ToolbarConfigurable.kt | 9 +++ .../features/home/HomeActivity.kt | 39 ++++++++++++- .../home/detail/RoomDetailFragment.kt | 27 +++++++-- .../features/home/list/RoomListFragment.kt | 17 ++++-- app/src/main/res/layout/activity_home.xml | 1 + .../main/res/layout/fragment_room_detail.xml | 20 ++++++- app/src/main/res/values-v21/themes_base.xml | 9 +++ app/src/main/res/values/colors.xml | 5 -- app/src/main/res/values/styles.xml | 7 --- app/src/main/res/values/styles_widget.xml | 5 ++ app/src/main/res/values/text_appearances.xml | 5 ++ app/src/main/res/values/themes.xml | 9 +++ app/src/main/res/values/themes_base.xml | 13 +++++ app/src/main/res/values/themes_overlay.xml | 2 + .../main/res/values/themes_overlay_base.xml | 2 + .../matrix/android/api/session/room/Room.kt | 7 ++- .../session/room/model/RoomAvatarContent.kt | 9 +++ .../api/session/room/model/RoomSummary.kt | 5 +- .../database/mapper/RoomSummaryMapper.kt | 6 +- .../database/model/RoomSummaryEntity.kt | 1 + .../database/query/EventEntityQueries.kt | 13 ----- .../android/internal/session/SessionModule.kt | 11 +++- .../internal/session/room/DefaultRoom.kt | 21 +++++-- .../session/room/RoomAvatarResolver.kt | 53 ++++++++++++++++++ .../session/room/RoomSummaryUpdater.kt | 10 ++-- .../room/members/LoadRoomMembersRequest.kt | 4 +- .../room/members/RoomDisplayNameResolver.kt | 19 +++---- .../session/room/members/RoomMembers.kt | 47 ++++++++++++++++ .../internal/session/sync/RoomSyncHandler.kt | 6 +- 32 files changed, 315 insertions(+), 74 deletions(-) create mode 100644 app/src/main/java/im/vector/riotredesign/core/platform/ToolbarConfigurable.kt create mode 100644 app/src/main/res/values-v21/themes_base.xml create mode 100644 app/src/main/res/values/styles_widget.xml create mode 100644 app/src/main/res/values/text_appearances.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/main/res/values/themes_base.xml create mode 100644 app/src/main/res/values/themes_overlay.xml create mode 100644 app/src/main/res/values/themes_overlay_base.xml create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomAvatarContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAvatarResolver.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/members/RoomMembers.kt diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 0636ad2de7b896dcead25548e7297e2f36426773..7d78b39972890635811eb82242fdf631e8d2e89f 100644 GIT binary patch delta 72 zcmV-O0Jr~@1(OAkm;=8j5RsdS4ks^Fb7gXKFK1zHW^!SZ1p+pcV*xyqBmqB@p8-S@ ef7Z;PlyyDK5#g+$el~%6bN~^P4gwpKR{}n+^%>3p delta 74 zcmV-Q0JZ;<1(gMmm;<}jNRgX~lcWJZlV|}vlj8wIBAqkc65@?7i4E+OV(}pfPILe% gFI978a&s?ca$#;`Z)tOrG66OL5tBOs8 + android:theme="@style/Theme.Riot"> diff --git a/app/src/main/java/im/vector/riotredesign/core/platform/RiotFragment.kt b/app/src/main/java/im/vector/riotredesign/core/platform/RiotFragment.kt index 3f5e3d86..88300a4e 100644 --- a/app/src/main/java/im/vector/riotredesign/core/platform/RiotFragment.kt +++ b/app/src/main/java/im/vector/riotredesign/core/platform/RiotFragment.kt @@ -4,6 +4,11 @@ import com.airbnb.mvrx.BaseMvRxFragment abstract class RiotFragment : BaseMvRxFragment() { + val riotActivity: RiotActivity by lazy { + activity as RiotActivity + } + + override fun invalidate() { //no-ops by default } diff --git a/app/src/main/java/im/vector/riotredesign/core/platform/ToolbarConfigurable.kt b/app/src/main/java/im/vector/riotredesign/core/platform/ToolbarConfigurable.kt new file mode 100644 index 00000000..acaece0b --- /dev/null +++ b/app/src/main/java/im/vector/riotredesign/core/platform/ToolbarConfigurable.kt @@ -0,0 +1,9 @@ +package im.vector.riotredesign.core.platform + +import android.support.v7.widget.Toolbar + +interface ToolbarConfigurable { + + fun configure(toolbar: Toolbar) + +} \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index 62abf6f2..847045cc 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -3,10 +3,15 @@ package im.vector.riotredesign.features.home import android.content.Context import android.content.Intent import android.os.Bundle +import android.support.v4.view.GravityCompat +import android.support.v7.app.ActionBarDrawerToggle +import android.support.v7.widget.Toolbar import android.view.Gravity +import android.view.MenuItem import im.vector.riotredesign.R import im.vector.riotredesign.core.extensions.replaceFragment import im.vector.riotredesign.core.platform.RiotActivity +import im.vector.riotredesign.core.platform.ToolbarConfigurable import im.vector.riotredesign.features.home.detail.LoadingRoomDetailFragment import im.vector.riotredesign.features.home.detail.RoomDetailFragment import im.vector.riotredesign.features.home.list.RoomListFragment @@ -14,12 +19,13 @@ import kotlinx.android.synthetic.main.activity_home.* import org.koin.standalone.StandAloneContext.loadKoinModules -class HomeActivity : RiotActivity(), HomeNavigator { +class HomeActivity : RiotActivity(), HomeNavigator, ToolbarConfigurable { + override fun onCreate(savedInstanceState: Bundle?) { + loadKoinModules(listOf(HomeModule(this))) super.onCreate(savedInstanceState) setContentView(R.layout.activity_home) - loadKoinModules(listOf(HomeModule(this))) if (savedInstanceState == null) { val roomListFragment = RoomListFragment.newInstance() val loadingDetail = LoadingRoomDetailFragment.newInstance() @@ -28,6 +34,35 @@ class HomeActivity : RiotActivity(), HomeNavigator { } } + override fun configure(toolbar: Toolbar) { + setSupportActionBar(toolbar) + supportActionBar?.setHomeButtonEnabled(true) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + val drawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0) + drawerLayout.addDrawerListener(drawerToggle) + drawerToggle.syncState() + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + // Android home + android.R.id.home -> { + drawerLayout.openDrawer(GravityCompat.START) + return true + } + } + + return true + } + + override fun onBackPressed() { + if (drawerLayout.isDrawerOpen(Gravity.LEFT)) { + drawerLayout.closeDrawer(Gravity.LEFT) + } else { + super.onBackPressed() + } + } + override fun openRoomDetail(roomId: String) { val roomDetailFragment = RoomDetailFragment.newInstance(roomId) replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer) 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 10dbcb38..7cf1f473 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 @@ -11,8 +11,10 @@ import android.view.ViewGroup import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.session.events.model.EnrichedEvent import im.vector.matrix.android.api.session.room.Room +import im.vector.matrix.android.api.session.room.model.RoomSummary 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 kotlinx.android.synthetic.main.fragment_room_detail.* import org.koin.android.ext.android.inject @@ -41,14 +43,19 @@ class RoomDetailFragment : RiotFragment(), TimelineEventAdapter.Callback { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - setupRecyclerView() room = currentSession.getRoom(roomId)!! + setupRecyclerView() + setupToolbar() room.loadRoomMembersIfNeeded() room.liveTimeline().observe(this, Observer { renderEvents(it) }) + room.roomSummary.observe(this, Observer { renderRoomSummary(it) }) } - private fun renderEvents(events: PagedList?) { - timelineAdapter.submitList(events) + private fun setupToolbar() { + val parentActivity = riotActivity + if (parentActivity is ToolbarConfigurable) { + parentActivity.configure(toolbar) + } } private fun setupRecyclerView() { @@ -67,7 +74,19 @@ class RoomDetailFragment : RiotFragment(), TimelineEventAdapter.Callback { //recyclerView.setController(timelineEventController) } - override fun onEventsListChanged(oldList: List?, newList: List?) { + private fun renderRoomSummary(roomSummary: RoomSummary?) { + roomSummary?.let { + toolbar.title = it.displayName + } + } + + private fun renderEvents(events: PagedList?) { + timelineAdapter.submitList(events) + } + + + override + fun onEventsListChanged(oldList: List?, newList: List?) { if (oldList == null && newList != null) { recyclerView.scrollToPosition(0) } 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 103b7cdf..20c58e4d 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 @@ -4,7 +4,11 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import com.airbnb.mvrx.* +import com.airbnb.mvrx.Fail +import com.airbnb.mvrx.Incomplete +import com.airbnb.mvrx.Success +import com.airbnb.mvrx.fragmentViewModel +import com.airbnb.mvrx.withState import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.riotredesign.R @@ -35,16 +39,19 @@ class RoomListFragment : RiotFragment(), RoomSummaryController.Callback { roomController = RoomSummaryController(this) stateView.contentView = epoxyRecyclerView epoxyRecyclerView.setController(roomController) + viewModel.subscribe { renderState(it) } } private fun renderState(state: RoomListViewState) { when (state.roomSummaries) { is Incomplete -> renderLoading() - is Success -> renderSuccess(state.roomSummaries(), state.selectedRoom) - is Fail -> renderFailure(state.roomSummaries.error) + is Success -> renderSuccess(state.roomSummaries(), state.selectedRoom) + is Fail -> renderFailure(state.roomSummaries.error) } - if (state.showLastSelectedRoom && state.selectedRoom != null) { + if (state.selectedRoom != null && state.showLastSelectedRoom) { + val position = state.roomSummaries()?.indexOf(state.selectedRoom) ?: 0 + epoxyRecyclerView.scrollToPosition(position) homeNavigator.openRoomDetail(state.selectedRoom.roomId) } } @@ -65,7 +72,7 @@ class RoomListFragment : RiotFragment(), RoomSummaryController.Callback { private fun renderFailure(error: Throwable) { val message = when (error) { is Failure.NetworkConnection -> "Pas de connexion internet" - else -> "Une erreur est survenue" + else -> "Une erreur est survenue" } stateView.state = StateView.State.Error(message) } diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 0905e995..f7e6940b 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -11,6 +11,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> + + + + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/toolbar" /> \ No newline at end of file diff --git a/app/src/main/res/values-v21/themes_base.xml b/app/src/main/res/values-v21/themes_base.xml new file mode 100644 index 00000000..41d96f4b --- /dev/null +++ b/app/src/main/res/values-v21/themes_base.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/app/src/main/res/values/styles_widget.xml b/app/src/main/res/values/styles_widget.xml new file mode 100644 index 00000000..78554f9e --- /dev/null +++ b/app/src/main/res/values/styles_widget.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/text_appearances.xml b/app/src/main/res/values/text_appearances.xml new file mode 100644 index 00000000..78554f9e --- /dev/null +++ b/app/src/main/res/values/text_appearances.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 00000000..f9f41d58 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/themes_base.xml b/app/src/main/res/values/themes_base.xml new file mode 100644 index 00000000..4363f207 --- /dev/null +++ b/app/src/main/res/values/themes_base.xml @@ -0,0 +1,13 @@ + + + + + +