RoomPreview when the room is not world readable

This commit is contained in:
Benoit Marty 2019-05-28 15:58:30 +02:00
parent 8f2754493c
commit 33fbcc8ba3
18 changed files with 270 additions and 35 deletions

View file

@ -44,6 +44,7 @@
android:label="@string/title_activity_emoji_reaction_picker" /> android:label="@string/title_activity_emoji_reaction_picker" />
<activity android:name=".features.roomdirectory.RoomDirectoryActivity" /> <activity android:name=".features.roomdirectory.RoomDirectoryActivity" />
<activity android:name=".features.roomdirectory.roompreview.RoomPreviewActivity" />
<activity android:name=".features.home.room.detail.RoomDetailActivity" /> <activity android:name=".features.home.room.detail.RoomDetailActivity" />
<service <service

View file

@ -49,11 +49,6 @@ abstract class VectorBaseActivity : BaseMvRxActivity() {
* UI * UI
* ========================================================================================== */ * ========================================================================================== */
@Nullable
@JvmField
@BindView(R.id.toolbar)
var toolbar: Toolbar? = null
@Nullable @Nullable
@JvmField @JvmField
@BindView(R.id.vector_coordinator_layout) @BindView(R.id.vector_coordinator_layout)
@ -244,16 +239,18 @@ abstract class VectorBaseActivity : BaseMvRxActivity() {
protected fun isFirstCreation() = savedInstanceState == null protected fun isFirstCreation() = savedInstanceState == null
/** /**
* Configure the Toolbar. It MUST be present in your layout with id "toolbar" * Configure the Toolbar, with default back button.
*/ */
protected fun configureToolbar() { protected fun configureToolbar(toolbar: Toolbar, displayBack: Boolean = true) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
if (displayBack) {
supportActionBar?.let { supportActionBar?.let {
it.setDisplayShowHomeEnabled(true) it.setDisplayShowHomeEnabled(true)
it.setDisplayHomeAsUpEnabled(true) it.setDisplayHomeAsUpEnabled(true)
} }
} }
}
/* ========================================================================================== /* ==========================================================================================
* OPEN METHODS * OPEN METHODS

View file

@ -22,6 +22,7 @@ import android.view.*
import androidx.annotation.CallSuper import androidx.annotation.CallSuper
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.annotation.MainThread import androidx.annotation.MainThread
import androidx.appcompat.widget.Toolbar
import butterknife.ButterKnife import butterknife.ButterKnife
import butterknife.Unbinder import butterknife.Unbinder
import com.airbnb.mvrx.BaseMvRxFragment import com.airbnb.mvrx.BaseMvRxFragment
@ -123,6 +124,20 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed {
return this return this
} }
/* ==========================================================================================
* Toolbar
* ========================================================================================== */
/**
* Configure the Toolbar.
*/
protected fun setupToolbar(toolbar: Toolbar) {
val parentActivity = vectorBaseActivity
if (parentActivity is ToolbarConfigurable) {
parentActivity.configure(toolbar)
}
}
/* ========================================================================================== /* ==========================================================================================
* Disposable * Disposable
* ========================================================================================== */ * ========================================================================================== */

View file

@ -37,8 +37,6 @@ import im.vector.riotredesign.core.platform.ToolbarConfigurable
import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.core.platform.VectorBaseActivity
import im.vector.riotredesign.features.rageshake.BugReporter import im.vector.riotredesign.features.rageshake.BugReporter
import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity
import im.vector.riotredesign.features.settings.VectorSettingsActivity
import im.vector.riotredesign.features.workers.signout.SignOutUiWorker import im.vector.riotredesign.features.workers.signout.SignOutUiWorker
import kotlinx.android.synthetic.main.activity_home.* import kotlinx.android.synthetic.main.activity_home.*
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
@ -108,7 +106,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
} }
override fun configure(toolbar: Toolbar) { override fun configure(toolbar: Toolbar) {
setSupportActionBar(toolbar) configureToolbar(toolbar, false)
} }
override fun getMenuRes() = R.menu.home override fun getMenuRes() = R.menu.home

View file

@ -44,11 +44,7 @@ class RoomDetailActivity : VectorBaseActivity(), ToolbarConfigurable {
} }
override fun configure(toolbar: Toolbar) { override fun configure(toolbar: Toolbar) {
setSupportActionBar(toolbar) configureToolbar(toolbar)
supportActionBar?.let {
it.setDisplayShowHomeEnabled(true)
it.setDisplayHomeAsUpEnabled(true)
}
} }
companion object { companion object {

View file

@ -169,7 +169,7 @@ class RoomDetailFragment :
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
actionViewModel = ViewModelProviders.of(requireActivity()).get(ActionsHandler::class.java) actionViewModel = ViewModelProviders.of(requireActivity()).get(ActionsHandler::class.java)
bindScope(getOrCreateScope(HomeModule.ROOM_DETAIL_SCOPE)) bindScope(getOrCreateScope(HomeModule.ROOM_DETAIL_SCOPE))
setupToolbar() setupToolbar(roomToolbar)
setupRecyclerView() setupRecyclerView()
setupComposer() setupComposer()
setupAttachmentButton() setupAttachmentButton()
@ -189,13 +189,6 @@ class RoomDetailFragment :
}) })
} }
private fun setupToolbar() {
val parentActivity = vectorBaseActivity
if (parentActivity is ToolbarConfigurable) {
parentActivity.configure(roomToolbar)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK && data != null) { if (resultCode == RESULT_OK && data != null) {

View file

@ -21,7 +21,6 @@ import android.graphics.Color
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.setPadding
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import im.vector.matrix.android.api.session.user.model.User import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotredesign.R import im.vector.riotredesign.R

View file

@ -27,6 +27,7 @@ import butterknife.OnCheckedChanged
import butterknife.OnTextChanged import butterknife.OnTextChanged
import im.vector.riotredesign.R import im.vector.riotredesign.R
import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.core.platform.VectorBaseActivity
import kotlinx.android.synthetic.main.activity_bug_report.*
import timber.log.Timber import timber.log.Timber
/** /**
@ -68,7 +69,7 @@ class BugReportActivity : VectorBaseActivity() {
override fun getLayoutRes() = R.layout.activity_bug_report override fun getLayoutRes() = R.layout.activity_bug_report
override fun initUiAndData() { override fun initUiAndData() {
configureToolbar() configureToolbar(bugReportToolbar)
if (BugReporter.screenshot != null) { if (BugReporter.screenshot != null) {
mScreenShotPreview.setImageBitmap(BugReporter.screenshot) mScreenShotPreview.setImageBitmap(BugReporter.screenshot)

View file

@ -34,6 +34,7 @@ import androidx.lifecycle.ViewModelProviders
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import im.vector.riotredesign.R import im.vector.riotredesign.R
import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.core.platform.VectorBaseActivity
import kotlinx.android.synthetic.main.activity_emoji_reaction_picker.*
import timber.log.Timber import timber.log.Timber
/** /**
@ -80,8 +81,7 @@ class EmojiReactionPickerActivity : VectorBaseActivity() {
} }
override fun initUiAndData() { override fun initUiAndData() {
configureToolbar(emojiPickerToolbar)
configureToolbar()
requestEmojivUnicode10CompatibleFont() requestEmojivUnicode10CompatibleFont()

View file

@ -33,6 +33,7 @@ import im.vector.riotredesign.core.platform.VectorBaseFragment
import im.vector.riotredesign.features.home.room.detail.RoomDetailActivity import im.vector.riotredesign.features.home.room.detail.RoomDetailActivity
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerFragment import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerFragment
import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewActivity
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import kotlinx.android.synthetic.main.fragment_public_rooms.* import kotlinx.android.synthetic.main.fragment_public_rooms.*
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
@ -128,7 +129,7 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback
PublicRoomItem.JoinState.NOT_JOINED, PublicRoomItem.JoinState.NOT_JOINED,
PublicRoomItem.JoinState.JOINING_ERROR -> { PublicRoomItem.JoinState.JOINING_ERROR -> {
// ROOM PREVIEW // ROOM PREVIEW
vectorBaseActivity.notImplemented("Opening room preview") requireActivity().startActivity(RoomPreviewActivity.getIntent(requireActivity(), publicRoom))
} }
else -> { else -> {
Snackbar.make(publicRoomsCoordinator, getString(R.string.please_wait), Snackbar.LENGTH_SHORT) Snackbar.make(publicRoomsCoordinator, getString(R.string.please_wait), Snackbar.LENGTH_SHORT)

View file

@ -0,0 +1,87 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.riotredesign.features.roomdirectory.roompreview
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Parcelable
import androidx.appcompat.widget.Toolbar
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
import im.vector.riotredesign.R
import im.vector.riotredesign.core.extensions.addFragment
import im.vector.riotredesign.core.platform.ToolbarConfigurable
import im.vector.riotredesign.core.platform.VectorBaseActivity
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule
import kotlinx.android.parcel.Parcelize
import org.koin.android.scope.ext.android.bindScope
import org.koin.android.scope.ext.android.getOrCreateScope
@Parcelize
data class RoomPreviewData(
val roomId: String,
val roomName: String?,
val topic: String?,
val worldReadable: Boolean,
val avatarUrl: String?
) : Parcelable
class RoomPreviewActivity : VectorBaseActivity(), ToolbarConfigurable {
companion object {
private const val ARG = "ARG"
fun getIntent(context: Context, publicRoom: PublicRoom): Intent {
return Intent(context, RoomPreviewActivity::class.java).apply {
putExtra(ARG, RoomPreviewData(
roomId = publicRoom.roomId,
roomName = publicRoom.name,
topic = publicRoom.topic,
worldReadable = publicRoom.worldReadable,
avatarUrl = publicRoom.avatarUrl
))
}
}
}
override fun getLayoutRes() = R.layout.activity_simple
override fun configure(toolbar: Toolbar) {
configureToolbar(toolbar)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bindScope(getOrCreateScope(RoomDirectoryModule.ROOM_DIRECTORY_SCOPE))
}
override fun initUiAndData() {
if (isFirstCreation()) {
val args = intent.getParcelableExtra<RoomPreviewData>(ARG)
if (args.worldReadable) {
// TODO Room preview
notImplemented("Room preview of world readable room")
} else {
addFragment(RoomPreviewNoPreviewFragment.newInstance(args), R.id.simpleFragmentContainer)
}
}
}
}

View file

@ -0,0 +1,61 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.riotredesign.features.roomdirectory.roompreview
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.args
import im.vector.riotredesign.R
import im.vector.riotredesign.core.extensions.setTextOrHide
import im.vector.riotredesign.core.platform.VectorBaseFragment
import im.vector.riotredesign.features.home.AvatarRenderer
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule
import kotlinx.android.synthetic.main.fragment_room_preview_no_preview.*
import org.koin.android.scope.ext.android.bindScope
import org.koin.android.scope.ext.android.getOrCreateScope
class RoomPreviewNoPreviewFragment : VectorBaseFragment() {
companion object {
fun newInstance(arg: RoomPreviewData): Fragment {
return RoomPreviewNoPreviewFragment().apply { setArguments(arg) }
}
}
private val roomPreviewData: RoomPreviewData by args()
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
bindScope(getOrCreateScope(RoomDirectoryModule.ROOM_DIRECTORY_SCOPE))
setupToolbar(roomPreviewNoPreviewToolbar)
}
override fun getLayoutResId() = R.layout.fragment_room_preview_no_preview
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AvatarRenderer.render(roomPreviewData.avatarUrl, roomPreviewData.roomId, roomPreviewData.roomName, roomPreviewNoPreviewAvatar)
roomPreviewNoPreviewName.text = roomPreviewData.roomName
roomPreviewNoPreviewTopic.setTextOrHide(roomPreviewData.topic)
roomPreviewNoPreviewJoin.setOnClickListener {
vectorBaseActivity.notImplemented("Join from preview")
}
}
}

View file

@ -24,6 +24,7 @@ import androidx.preference.PreferenceFragmentCompat
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.riotredesign.R import im.vector.riotredesign.R
import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.core.platform.VectorBaseActivity
import kotlinx.android.synthetic.main.activity_vector_settings.*
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
/** /**
@ -45,7 +46,7 @@ class VectorSettingsActivity : VectorBaseActivity(),
private val session by inject<Session>() private val session by inject<Session>()
override fun initUiAndData() { override fun initUiAndData() {
configureToolbar() configureToolbar(settingsToolbar)
if (isFirstCreation()) { if (isFirstCreation()) {
vectorSettingsPreferencesFragment = VectorSettingsPreferencesFragment.newInstance(session.sessionParams.credentials.userId) vectorSettingsPreferencesFragment = VectorSettingsPreferencesFragment.newInstance(session.sessionParams.credentials.userId)

View file

@ -6,7 +6,7 @@
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/bugReportToolbar"
style="@style/VectorToolbarStyle" style="@style/VectorToolbarStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />

View file

@ -19,7 +19,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/emojiPickerToolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"

View file

@ -10,7 +10,7 @@
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/settingsToolbar"
style="@style/VectorToolbarStyle" style="@style/VectorToolbarStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />

View file

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/roomPreviewNoPreviewToolbar"
style="@style/VectorToolbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/layout_horizontal_margin"
android:paddingRight="@dimen/layout_horizontal_margin">
<ImageView
android:id="@+id/roomPreviewNoPreviewAvatar"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_marginTop="123dp"
tools:src="@tools:sample/avatars" />
<TextView
android:id="@+id/roomPreviewNoPreviewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:gravity="center"
android:textAppearance="@style/TextAppearance.Vector.Title"
android:textSize="15sp"
android:textStyle="bold"
tools:text="Matrix HQ" />
<TextView
android:id="@+id/roomPreviewNoPreviewTopic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_vertical_margin"
android:gravity="center"
android:textAppearance="@style/TextAppearance.Vector.Subtitle"
android:textSize="15sp"
tools:text="Welcome to Matrix HQ! Here is the rest of the room topic…" />
<TextView
android:id="@+id/roomPreviewNoPreviewLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:text="@string/room_preview_no_preview"
android:textAppearance="@style/TextAppearance.Vector.Subtitle2"
android:textSize="14sp" />
<Button
android:id="@+id/roomPreviewNoPreviewJoin"
style="@style/VectorButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_vertical_margin"
android:layout_marginBottom="@dimen/layout_vertical_margin"
android:minWidth="120dp"
android:text="@string/join" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -30,4 +30,6 @@
<string name="please_wait">"Please wait…"</string> <string name="please_wait">"Please wait…"</string>
<string name="group_all_communities">"All Communities"</string> <string name="group_all_communities">"All Communities"</string>
<string name="room_preview_no_preview">"This room can't be previewed"</string>
</resources> </resources>