add header footer and fix toolbar

This commit is contained in:
David Langley 2021-07-23 22:37:36 +01:00
parent df7e6bd00d
commit 90e04d4358
11 changed files with 234 additions and 10 deletions

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2021 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.app.core.epoxy.profiles.notifications
import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.extensions.setTextWithColoredPart
@EpoxyModelClass(layout = R.layout.item_notifications_footer)
abstract class NotificationSettingsFooterItem : VectorEpoxyModel<NotificationSettingsFooterItem.Holder>() {
@EpoxyAttribute
var encrypted: Boolean = false
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var clickListener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
val accountSettingsString = holder.view.context.getString(R.string.room_settings_room_notifications_account_settings)
val manageNotificationsString = StringBuilder(holder.view.context.getString(R.string.room_settings_room_notifications_manage_notifications, accountSettingsString))
if (encrypted) {
val encryptionNotice = holder.view.context.getString(R.string.room_settings_room_notifications_encryption_notice)
manageNotificationsString.appendLine().append(encryptionNotice)
}
holder.textView.setTextWithColoredPart(
manageNotificationsString.toString(),
accountSettingsString,
underline = true
) {
clickListener?.invoke(holder.textView)
}
}
class Holder : VectorEpoxyHolder() {
val textView by bind<TextView>(R.id.footerText)
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package im.vector.app.core.epoxy
package im.vector.app.core.epoxy.profiles.notifications
import android.widget.ImageView
import android.widget.TextView
@ -23,10 +23,12 @@ import androidx.core.content.ContextCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
/**
* A action for bottom sheet.
*/
@EpoxyModelClass(layout = R.layout.item_radio)
abstract class RadioButtonItem : VectorEpoxyModel<RadioButtonItem.Holder>() {

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2021 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.app.core.epoxy.profiles.notifications
import android.widget.TextView
import androidx.annotation.StringRes
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
@EpoxyModelClass(layout = R.layout.item_text_header)
abstract class TextHeaderItem : VectorEpoxyModel<TextHeaderItem.Holder>() {
@EpoxyAttribute
var text: String? = null
@StringRes
@EpoxyAttribute
var textRes: Int? = null
override fun bind(holder: Holder) {
super.bind(holder)
if (textRes != null) {
holder.textView.setText(textRes!!)
} else {
holder.textView.text = text
}
}
class Holder : VectorEpoxyHolder() {
val textView by bind<TextView>(R.id.headerText)
}
}

View File

@ -65,6 +65,23 @@ fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int,
val coloredPart = resources.getString(coloredTextRes)
// Insert colored part into the full text
val fullText = resources.getString(fullTextRes, coloredPart)
setTextWithColoredPart(fullText, coloredPart, colorAttribute, underline, onClick)
}
/**
* Set text with a colored part
* @param fullText The full text.
* @param coloredPart The colored part of the text
* @param colorAttribute attribute of the color. Default to colorPrimary
* @param underline true to also underline the text. Default to false
* @param onClick attributes to handle click on the colored part if needed
*/
fun TextView.setTextWithColoredPart(fullText: String,
coloredPart: String,
@AttrRes colorAttribute: Int = R.attr.colorPrimary,
underline: Boolean = false,
onClick: (() -> Unit)? = null) {
val color = ThemeUtils.getColor(context, colorAttribute)
val foregroundSpan = ForegroundColorSpan(color)

View File

@ -19,7 +19,11 @@ package im.vector.app.features.roomprofile.notifications
import androidx.annotation.StringRes
import com.airbnb.epoxy.TypedEpoxyController
import im.vector.app.R
import im.vector.app.core.epoxy.radioButtonItem
import im.vector.app.core.epoxy.profiles.notifications.notificationSettingsFooterItem
import im.vector.app.core.epoxy.profiles.notifications.radioButtonItem
import im.vector.app.core.epoxy.profiles.notifications.textHeaderItem
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.genericHeaderItem
import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState
import javax.inject.Inject
@ -27,6 +31,7 @@ class RoomNotificationSettingsController @Inject constructor() : TypedEpoxyContr
interface Callback {
fun didSelectRoomNotificationState(roomNotificationState: RoomNotificationState)
fun didSelectAccountSettingsLink()
}
var callback: Callback? = null
@ -47,6 +52,10 @@ class RoomNotificationSettingsController @Inject constructor() : TypedEpoxyContr
val host = this
data ?: return
textHeaderItem {
id("roomNotificationSettingsHeader")
textRes(R.string.room_settings_room_notifications_notify_me)
}
data.notificationOptions.forEach { notificationState ->
val title = titleForNotificationState(notificationState)
radioButtonItem {
@ -58,5 +67,12 @@ class RoomNotificationSettingsController @Inject constructor() : TypedEpoxyContr
}
}
}
notificationSettingsFooterItem {
id("roomNotificationSettingsFooter")
encrypted(data.roomEncrypted)
clickListener {
host.callback?.didSelectAccountSettingsLink()
}
}
}
}

View File

@ -27,12 +27,15 @@ import im.vector.app.R
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentRoomSettingGenericBinding
import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState
import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject
class RoomNotificationSettingsFragment @Inject constructor(
val roomNotificationSettingsViewModel: RoomNotificationSettingsViewModel.Factory,
val roomNotificationSettingsController: RoomNotificationSettingsController
val viewModelFactory: RoomNotificationSettingsViewModel.Factory,
private val roomNotificationSettingsController: RoomNotificationSettingsController,
private val avatarRenderer: AvatarRenderer
) : VectorBaseFragment<FragmentRoomSettingGenericBinding>(),
RoomNotificationSettingsController.Callback {
@ -45,7 +48,6 @@ class RoomNotificationSettingsFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar(views.roomSettingsToolbar)
views.roomSettingsToolbarTitleView.setText(R.string.settings_notifications)
roomNotificationSettingsController.callback = this
views.roomSettingsRecyclerView.configureWith(roomNotificationSettingsController, hasFixedSize = true)
setupWaitingView()
@ -67,9 +69,22 @@ class RoomNotificationSettingsFragment @Inject constructor(
override fun invalidate() = withState(viewModel) { viewState ->
roomNotificationSettingsController.setData(viewState)
views.waitingView.root.isVisible = viewState.isLoading
renderRoomSummary(viewState)
}
override fun didSelectRoomNotificationState(roomNotificationState: RoomNotificationState) {
viewModel.handle(RoomNotificationSettingsAction.SelectNotificationState(roomNotificationState))
}
override fun didSelectAccountSettingsLink() {
navigator.openSettings(requireContext())
}
private fun renderRoomSummary(state: RoomNotificationSettingsViewState) {
state.roomSummary()?.let {
views.roomSettingsToolbarTitleView.text = it.displayName
avatarRenderer.render(it.toMatrixItem(), views.roomSettingsToolbarAvatarImageView)
views.roomSettingsDecorationToolbarAvatarImageView.render(it.roomEncryptionTrustLevel)
}
}
}

View File

@ -28,6 +28,7 @@ import im.vector.app.core.platform.VectorViewModel
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.rx.rx
import org.matrix.android.sdk.rx.unwrap
class RoomNotificationSettingsViewModel @AssistedInject constructor(
@Assisted initialState: RoomNotificationSettingsViewState,
@ -44,7 +45,7 @@ class RoomNotificationSettingsViewModel @AssistedInject constructor(
@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: RoomNotificationSettingsViewState): RoomNotificationSettingsViewModel {
val fragment: RoomNotificationSettingsFragment = (viewModelContext as FragmentViewModelContext).fragment()
return fragment.roomNotificationSettingsViewModel.create(state)
return fragment.viewModelFactory.create(state)
}
}
@ -52,6 +53,7 @@ class RoomNotificationSettingsViewModel @AssistedInject constructor(
init {
initEncrypted()
observeSummary()
observeNotificationState()
}
@ -61,6 +63,14 @@ class RoomNotificationSettingsViewModel @AssistedInject constructor(
}
}
private fun observeSummary() {
room.rx().liveRoomSummary()
.unwrap()
.execute { async ->
copy(roomSummary = async)
}
}
private fun observeNotificationState() {
room.rx()
.liveNotificationState()

View File

@ -20,14 +20,15 @@ import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MvRxState
import com.airbnb.mvrx.Uninitialized
import im.vector.app.features.roomprofile.RoomProfileArgs
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState
data class RoomNotificationSettingsViewState(
val roomId: String,
val roomSummary: Async<RoomSummary> = Uninitialized,
val isLoading: Boolean = false,
val roomEncrypted: Boolean = false,
val notificationState: Async<RoomNotificationState> = Uninitialized,
val avatarData: AvatarData? = null
) : MvRxState {
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingVertical="@dimen/layout_vertical_margin"
android:paddingHorizontal="@dimen/layout_horizontal_margin">
<TextView
android:id="@+id/footerText"
style="@style/Widget.Vector.TextView.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:textColor="?vctr_content_secondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0"
tools:text="@string/room_settings_room_notifications_encryption_notice" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingVertical="@dimen/layout_vertical_margin"
android:paddingHorizontal="@dimen/layout_horizontal_margin">
<TextView
android:id="@+id/headerText"
style="@style/Widget.Vector.TextView.Subtitle"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:textColor="?vctr_content_secondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0"
tools:text="@string/room_settings_room_notifications_notify_me" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1408,6 +1408,10 @@
<string name="room_settings_category_access_visibility_title">Access and visibility</string>
<string name="room_settings_directory_visibility">List this room in room directory</string>
<string name="room_settings_room_notifications_title">Notifications</string>
<string name="room_settings_room_notifications_notify_me">Notify me for</string>
<string name="room_settings_room_notifications_encryption_notice">Please note that mentions &amp; keyword notifications are not available in encrypted rooms on mobile.</string>
<string name="room_settings_room_notifications_manage_notifications">You can manage notifications in %1$s.</string>
<string name="room_settings_room_notifications_account_settings">Account settings</string>
<string name="room_settings_room_access_rules_pref_title">Room Access</string>
<string name="room_settings_room_read_history_rules_pref_title">Room History Readability</string>
<string name="room_settings_room_read_history_rules_pref_dialog_title">Who can read history?</string>