-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3032 from vector-im/feature/bca/spaces_context_menu
Feature/bca/spaces context menu
- Loading branch information
Showing
16 changed files
with
317 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
vector/src/main/java/im/vector/app/features/spaces/SpaceSettingsMenuBottomSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* 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.features.spaces | ||
|
||
import android.os.Bundle | ||
import android.os.Parcelable | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.core.view.isVisible | ||
import com.airbnb.mvrx.args | ||
import im.vector.app.R | ||
import im.vector.app.core.di.ActiveSessionHolder | ||
import im.vector.app.core.di.ScreenComponent | ||
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment | ||
import im.vector.app.databinding.BottomSheetSpaceSettingsBinding | ||
import im.vector.app.features.home.AvatarRenderer | ||
import im.vector.app.features.navigation.Navigator | ||
import im.vector.app.features.powerlevel.PowerLevelsObservableFactory | ||
import im.vector.app.features.roomprofile.RoomProfileActivity | ||
import im.vector.app.features.settings.VectorPreferences | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import kotlinx.parcelize.Parcelize | ||
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper | ||
import org.matrix.android.sdk.api.util.toMatrixItem | ||
import org.matrix.android.sdk.internal.util.awaitCallback | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@Parcelize | ||
data class SpaceBottomSheetSettingsArgs( | ||
val spaceId: String | ||
) : Parcelable | ||
|
||
class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetSpaceSettingsBinding>() { | ||
|
||
@Inject lateinit var navigator: Navigator | ||
@Inject lateinit var activeSessionHolder: ActiveSessionHolder | ||
@Inject lateinit var avatarRenderer: AvatarRenderer | ||
@Inject lateinit var vectorPreferences: VectorPreferences | ||
|
||
private val spaceArgs: SpaceBottomSheetSettingsArgs by args() | ||
|
||
override fun injectWith(injector: ScreenComponent) { | ||
injector.inject(this) | ||
} | ||
|
||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetSpaceSettingsBinding { | ||
return BottomSheetSpaceSettingsBinding.inflate(inflater, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val session = activeSessionHolder.getSafeActiveSession() ?: return | ||
val roomSummary = session.getRoomSummary(spaceArgs.spaceId) | ||
roomSummary?.toMatrixItem()?.let { | ||
avatarRenderer.renderSpace(it, views.roomAvatarImageView) | ||
} | ||
views.roomNameView.text = roomSummary?.displayName | ||
views.roomDescription.text = roomSummary?.topic | ||
|
||
val room = session.getRoom(spaceArgs.spaceId) ?: return | ||
|
||
PowerLevelsObservableFactory(room) | ||
.createObservable() | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe { powerLevelContent -> | ||
val powerLevelsHelper = PowerLevelsHelper(powerLevelContent) | ||
val canInvite = powerLevelsHelper.isUserAbleToInvite(session.myUserId) | ||
views.invitePeople.isVisible = canInvite | ||
}.disposeOnDestroyView() | ||
|
||
views.invitePeople.views.bottomSheetActionClickableZone.debouncedClicks { | ||
navigator.openInviteUsersToRoom(requireContext(), spaceArgs.spaceId) | ||
} | ||
|
||
views.showMemberList.views.bottomSheetActionClickableZone.debouncedClicks { | ||
navigator.openRoomProfile(requireContext(), spaceArgs.spaceId, RoomProfileActivity.EXTRA_DIRECT_ACCESS_ROOM_MEMBERS) | ||
} | ||
|
||
views.spaceSettings.isVisible = vectorPreferences.developerMode() | ||
views.spaceSettings.views.bottomSheetActionClickableZone.debouncedClicks { | ||
navigator.openRoomProfile(requireContext(), spaceArgs.spaceId) | ||
} | ||
|
||
views.exploreRooms.views.bottomSheetActionClickableZone.debouncedClicks { | ||
startActivity(SpaceExploreActivity.newIntent(requireContext(), spaceArgs.spaceId)) | ||
} | ||
|
||
views.leaveSpace.views.bottomSheetActionClickableZone.debouncedClicks { | ||
AlertDialog.Builder(requireContext()) | ||
.setMessage(getString(R.string.space_leave_prompt_msg)) | ||
.setPositiveButton(R.string.leave) { _, _ -> | ||
GlobalScope.launch { | ||
try { | ||
awaitCallback { | ||
session.getRoom(spaceArgs.spaceId)?.leave(null, it) | ||
} | ||
} catch (failure: Throwable) { | ||
Timber.e(failure, "Failed to leave space") | ||
} | ||
} | ||
dismiss() | ||
} | ||
.setNegativeButton(R.string.cancel, null) | ||
.show() | ||
} | ||
} | ||
|
||
companion object { | ||
fun newInstance(spaceId: String): SpaceSettingsMenuBottomSheet { | ||
return SpaceSettingsMenuBottomSheet().apply { | ||
setArguments(SpaceBottomSheetSettingsArgs(spaceId)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M22.6667,12C22.6667,17.8911 17.8911,22.6667 12,22.6667C6.109,22.6667 1.3333,17.8911 1.3333,12C1.3333,6.109 6.109,1.3334 12,1.3334C17.8911,1.3334 22.6667,6.109 22.6667,12ZM17.8333,7.1022C18.0778,6.5711 17.4288,5.9221 16.8977,6.1666L10.2263,9.238C9.7853,9.4411 9.4402,9.7861 9.2372,10.2271L6.1657,16.8986C5.9212,17.4297 6.5702,18.0787 7.1013,17.8341L13.7727,14.7627C14.2137,14.5597 14.5588,14.2146 14.7618,13.7736L17.8333,7.1022Z" | ||
android:fillColor="#737D8C" | ||
android:fillType="evenOdd"/> | ||
<path | ||
android:pathData="M13.178,13.1789C12.5271,13.8298 11.4719,13.8298 10.821,13.1789C10.1701,12.528 10.1701,11.4727 10.821,10.8219C11.4719,10.171 12.5271,10.171 13.178,10.8219C13.8289,11.4727 13.8289,12.528 13.178,13.1789Z" | ||
android:fillColor="#737D8C"/> | ||
</vector> |
Oops, something went wrong.