Skip to content

Commit

Permalink
Merge pull request #7189 from vector-im/feature/mna/device-manager-re…
Browse files Browse the repository at this point in the history
…name-session

[Device management] Rename a session (PSG-747)
  • Loading branch information
mnaturel authored Sep 26, 2022
2 parents a83be29 + 7a4bf83 commit 2231498
Show file tree
Hide file tree
Showing 25 changed files with 1,026 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/7158.wip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Device management] Rename a session
4 changes: 4 additions & 0 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3295,6 +3295,10 @@
<string name="device_manager_session_details_session_id">Session ID</string>
<string name="device_manager_session_details_session_last_activity">Last activity</string>
<string name="device_manager_session_details_device_ip_address">IP address</string>
<string name="device_manager_session_rename">Rename session</string>
<string name="device_manager_session_rename_edit_hint">Session name</string>
<string name="device_manager_session_rename_description">Custom session names can help you recognize your devices more easily.</string>
<string name="device_manager_session_rename_warning">Please be aware that session names are also visible to people you communicate with.</string>

<!-- Note to translators: %s will be replaces with selected space name -->
<string name="home_empty_space_no_rooms_title">%s\nis looking a little empty.</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<declare-styleable name="SessionWarningInfoView">
<attr name="sessionsWarningInfoDescription" format="string" />
<attr name="sessionsWarningInfoHasLearnMore" format="boolean" />
</declare-styleable>

</resources>
1 change: 1 addition & 0 deletions vector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
<activity android:name=".features.settings.devices.v2.overview.SessionOverviewActivity" />
<activity android:name=".features.settings.devices.v2.othersessions.OtherSessionsActivity" />
<activity android:name=".features.settings.devices.v2.details.SessionDetailsActivity" />
<activity android:name=".features.settings.devices.v2.rename.RenameSessionActivity" />

<!-- Services -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import im.vector.app.features.settings.devices.DevicesViewModel
import im.vector.app.features.settings.devices.v2.details.SessionDetailsViewModel
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsViewModel
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewViewModel
import im.vector.app.features.settings.devices.v2.rename.RenameSessionViewModel
import im.vector.app.features.settings.devtools.AccountDataViewModel
import im.vector.app.features.settings.devtools.GossipingEventsPaperTrailViewModel
import im.vector.app.features.settings.devtools.KeyRequestListViewModel
Expand Down Expand Up @@ -653,4 +654,9 @@ interface MavericksViewModelModule {
@IntoMap
@MavericksViewModelKey(SessionDetailsViewModel::class)
fun sessionDetailsViewModelFactory(factory: SessionDetailsViewModel.Factory): MavericksAssistedViewModelFactory<*, *>

@Binds
@IntoMap
@MavericksViewModelKey(RenameSessionViewModel::class)
fun renameSessionViewModelFactory(factory: RenameSessionViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2022 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.features.settings.devices.v2

import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.res.use
import im.vector.app.R
import im.vector.app.core.extensions.setTextWithColoredPart
import im.vector.app.databinding.ViewSessionWarningInfoBinding

class SessionWarningInfoView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {

private val binding = ViewSessionWarningInfoBinding.inflate(
LayoutInflater.from(context),
this
)

var onLearnMoreClickListener: (() -> Unit)? = null

init {
context.obtainStyledAttributes(
attrs,
R.styleable.SessionWarningInfoView,
0,
0
).use {
setDescription(it)
}
}

private fun setDescription(typedArray: TypedArray) {
val description = typedArray.getString(R.styleable.SessionWarningInfoView_sessionsWarningInfoDescription)
val hasLearnMore = typedArray.getBoolean(R.styleable.SessionWarningInfoView_sessionsWarningInfoHasLearnMore, false)
if (hasLearnMore) {
val learnMore = context.getString(R.string.action_learn_more)
val fullDescription = buildString {
append(description)
append(" ")
append(learnMore)
}

binding.sessionWarningInfoDescription.setTextWithColoredPart(
fullText = fullDescription,
coloredPart = learnMore,
underline = false
) {
onLearnMoreClickListener?.invoke()
}
} else {
binding.sessionWarningInfoDescription.text = description
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package im.vector.app.features.settings.devices.v2.overview

import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.fragmentViewModel
Expand All @@ -31,6 +31,7 @@ import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.databinding.FragmentSessionOverviewBinding
Expand All @@ -43,7 +44,8 @@ import javax.inject.Inject
*/
@AndroidEntryPoint
class SessionOverviewFragment :
VectorBaseFragment<FragmentSessionOverviewBinding>() {
VectorBaseFragment<FragmentSessionOverviewBinding>(),
VectorMenuProvider {

@Inject lateinit var viewNavigator: SessionOverviewViewNavigator

Expand Down Expand Up @@ -103,6 +105,22 @@ class SessionOverviewFragment :
views.sessionOverviewInfo.onLearnMoreClickListener = null
}

override fun getMenuRes() = R.menu.menu_session_overview

override fun handleMenuItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.sessionOverviewRename -> {
goToRenameSession()
true
}
else -> false
}
}

private fun goToRenameSession() = withState(viewModel) { state ->
viewNavigator.goToRenameSession(requireContext(), state.deviceId)
}

override fun invalidate() = withState(viewModel) { state ->
updateToolbar(state.isCurrentSession)
updateEntryDetails(state.deviceId)
Expand All @@ -118,7 +136,7 @@ class SessionOverviewFragment :

private fun updateEntryDetails(deviceId: String) {
views.sessionOverviewEntryDetails.setOnClickListener {
viewNavigator.navigateToSessionDetails(requireContext(), deviceId)
viewNavigator.goToSessionDetails(requireContext(), deviceId)
}
}

Expand All @@ -136,11 +154,7 @@ class SessionOverviewFragment :
)
views.sessionOverviewInfo.render(infoViewState, dateFormatter, drawableProvider, colorProvider)
} else {
hideSessionInfo()
views.sessionOverviewInfo.isVisible = false
}
}

private fun hideSessionInfo() {
views.sessionOverviewInfo.isGone = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ package im.vector.app.features.settings.devices.v2.overview

import android.content.Context
import im.vector.app.features.settings.devices.v2.details.SessionDetailsActivity
import im.vector.app.features.settings.devices.v2.rename.RenameSessionActivity
import javax.inject.Inject

class SessionOverviewViewNavigator @Inject constructor() {

fun navigateToSessionDetails(context: Context, deviceId: String) {
fun goToSessionDetails(context: Context, deviceId: String) {
context.startActivity(SessionDetailsActivity.newIntent(context, deviceId))
}

fun goToRenameSession(context: Context, deviceId: String) {
context.startActivity(RenameSessionActivity.newIntent(context, deviceId))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2020 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.features.settings.devices.v2.rename

import im.vector.app.core.platform.VectorViewModelAction

sealed class RenameSessionAction : VectorViewModelAction {
object InitWithLastEditedName : RenameSessionAction()
object SaveModifications : RenameSessionAction()
data class EditLocally(val editedName: String) : RenameSessionAction()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2022 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.features.settings.devices.v2.rename

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import com.airbnb.mvrx.Mavericks
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleBinding

/**
* Display the screen to rename a Session.
*/
@AndroidEntryPoint
class RenameSessionActivity : VectorBaseActivity<ActivitySimpleBinding>() {

override fun getBinding() = ActivitySimpleBinding.inflate(layoutInflater)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (isFirstCreation()) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
addFragment(
container = views.simpleFragmentContainer,
fragmentClass = RenameSessionFragment::class.java,
params = intent.getParcelableExtra(Mavericks.KEY_ARG)
)
}
}

companion object {
fun newIntent(context: Context, deviceId: String): Intent {
return Intent(context, RenameSessionActivity::class.java).apply {
putExtra(Mavericks.KEY_ARG, RenameSessionArgs(deviceId))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 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.features.settings.devices.v2.rename

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class RenameSessionArgs(
val deviceId: String
) : Parcelable
Loading

0 comments on commit 2231498

Please sign in to comment.