Start introducing theme on app + branch toolbar to drawer, still requires refinements

This commit is contained in:
ganfra
2018-10-29 14:57:36 +01:00
parent e5fc1e3412
commit cc29a387c7
32 changed files with 315 additions and 74 deletions

View File

@ -12,7 +12,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/Theme.Riot">
<activity android:name=".features.login.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -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
}

View File

@ -0,0 +1,9 @@
package im.vector.riotredesign.core.platform
import android.support.v7.widget.Toolbar
interface ToolbarConfigurable {
fun configure(toolbar: Toolbar)
}

View File

@ -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)

View File

@ -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<EnrichedEvent>?) {
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<EnrichedEvent>?, newList: List<EnrichedEvent>?) {
private fun renderRoomSummary(roomSummary: RoomSummary?) {
roomSummary?.let {
toolbar.title = it.displayName
}
}
private fun renderEvents(events: PagedList<EnrichedEvent>?) {
timelineAdapter.submitList(events)
}
override
fun onEventsListChanged(oldList: List<EnrichedEvent>?, newList: List<EnrichedEvent>?) {
if (oldList == null && newList != null) {
recyclerView.scrollToPosition(0)
}

View File

@ -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)
}

View File

@ -11,6 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/homeDrawerFragmentContainer"
android:layout_width="match_parent"

View File

@ -1,11 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?actionBarSize"
android:background="@color/dark"
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" />
<com.airbnb.epoxy.EpoxyRecyclerView
android:id="@+id/recyclerView"
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" />
</android.support.constraint.ConstraintLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.V21.Theme.Riot" parent="Base.V1.Theme.Riot"></style>
<style name="Base.Theme.Riot" parent="Base.V21.Theme.Riot" />
</resources>

View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="pale_grey">#f2f5f8</color>
<color name="dark">#2e3649</color>
<color name="pale_teal">#7ac9a1</color>

View File

@ -1,11 +1,4 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Riot" parent="Base.Theme.Riot">
</style>
</resources>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.V1.Theme.Riot" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/dark</item>
<item name="colorPrimaryDark">@color/dark</item>
<item name="colorAccent">@color/pale_teal</item>
</style>
<style name="Base.Theme.Riot" parent="Base.V1.Theme.Riot" />
</resources>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>