Skip to content

Commit

Permalink
Call: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
ganfra committed Aug 18, 2021
1 parent 50a0426 commit 882188f
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package im.vector.app.core.ui.views

import androidx.core.view.isVisible
import im.vector.app.features.call.webrtc.WebRtcCall
import org.matrix.android.sdk.api.session.call.CallState
import timber.log.Timber

class CurrentCallsViewPresenter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.airbnb.mvrx.activityViewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetCallControlsBinding
import im.vector.app.features.call.audio.CallAudioManager

import me.gujun.android.span.span

class CallControlsBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetCallControlsBinding>() {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetCallControlsBinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.airbnb.epoxy.SimpleEpoxyController
import com.airbnb.mvrx.activityViewModel
import im.vector.app.core.epoxy.bottomsheet.bottomSheetActionItem
import im.vector.app.core.epoxy.bottomsheet.BottomSheetActionItem_
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetGenericListBinding
import im.vector.app.features.call.audio.CallAudioManager
Expand All @@ -33,9 +35,11 @@ class CallSoundDeviceChooserBottomSheet : VectorBaseBottomSheetDialogFragment<Bo
}

private val callViewModel: VectorCallViewModel by activityViewModel()
private val controller = SimpleEpoxyController()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
views.bottomSheetRecyclerView.configureWith(controller, hasFixedSize = false)
callViewModel.observeViewEvents {
when (it) {
is VectorCallViewEvents.ShowSoundDeviceChooser -> {
Expand All @@ -49,14 +53,12 @@ class CallSoundDeviceChooserBottomSheet : VectorBaseBottomSheetDialogFragment<Bo
}

private fun render(available: Set<CallAudioManager.Device>, current: CallAudioManager.Device) {
views.bottomSheetRecyclerView.withModels {
available.forEach { device ->
val title = when (device) {
is CallAudioManager.Device.WirelessHeadset -> device.name ?: getString(device.titleRes)
else -> getString(device.titleRes)
}

bottomSheetActionItem {
val models = available.map { device ->
val title = when (device) {
is CallAudioManager.Device.WirelessHeadset -> device.name ?: getString(device.titleRes)
else -> getString(device.titleRes)
}
BottomSheetActionItem_().apply {
id(device.titleRes)
text(title)
iconRes(device.drawableRes)
Expand All @@ -67,12 +69,12 @@ class CallSoundDeviceChooserBottomSheet : VectorBaseBottomSheetDialogFragment<Bo
}
}
}
controller.setModels(models)
}
}

companion object {
fun newInstance(): RoomListQuickActionsBottomSheet {
return RoomListQuickActionsBottomSheet()
companion object {
fun newInstance(): RoomListQuickActionsBottomSheet {
return RoomListQuickActionsBottomSheet()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.lifecycle.ViewModel
import im.vector.app.features.call.webrtc.WebRtcCall
import im.vector.app.features.call.webrtc.WebRtcCallManager
import org.matrix.android.sdk.api.session.call.MxCall
import timber.log.Timber
import javax.inject.Inject

class SharedKnownCallsViewModel @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
views.callInfoGroup.isVisible = false
}
} else {
//showLoading()
// showLoading()
}
}
is CallState.Ended -> {
Expand Down Expand Up @@ -412,7 +412,13 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
views.otherKnownCallLayout.setOnClickListener {
withState(callViewModel) {
val otherCall = callManager.getCallById(it.otherKnownCallInfo?.callId ?: "") ?: return@withState
val callArgs = CallArgs(otherCall.nativeRoomId, otherCall.callId, otherCall.mxCall.opponentUserId, !otherCall.mxCall.isOutgoing, otherCall.mxCall.isVideoCall)
val callArgs = CallArgs(
signalingRoomId = otherCall.nativeRoomId,
callId = otherCall.callId,
participantUserId = otherCall.mxCall.opponentUserId,
isIncomingCall = !otherCall.mxCall.isOutgoing,
isVideoCall = otherCall.mxCall.isVideoCall
)
callViewModel.handle(VectorCallViewActions.SwitchCall(callArgs))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.content.getSystemService
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
import org.matrix.android.sdk.api.extensions.orFalse
import timber.log.Timber
import java.util.HashSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.core.widget.ImageViewCompat
import im.vector.app.R
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.databinding.ViewRemoveJitsiWidgetBinding
import im.vector.app.features.home.room.detail.RoomDetailViewState
import org.matrix.android.sdk.api.session.room.model.Membership
Expand Down Expand Up @@ -88,10 +87,10 @@ import org.matrix.android.sdk.api.session.room.model.Membership

fun render(roomDetailViewState: RoomDetailViewState) {
val summary = roomDetailViewState.asyncRoomSummary()
val newState = if (summary?.membership != Membership.JOIN ||
roomDetailViewState.isWebRTCCallOptionAvailable() ||
!roomDetailViewState.isAllowedToManageWidgets ||
roomDetailViewState.jitsiState.widgetId == null) {
val newState = if (summary?.membership != Membership.JOIN
|| roomDetailViewState.isWebRTCCallOptionAvailable()
|| !roomDetailViewState.isAllowedToManageWidgets
|| roomDetailViewState.jitsiState.widgetId == null) {
State.Unmount
} else if (roomDetailViewState.jitsiState.deleteWidgetInProgress) {
State.Progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ class RoomDevToolActivity : SimpleFragmentActivity(), RoomDevToolViewModel.Facto
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
if (item.itemId == R.id.menuItemEdit) {
viewModel.handle(RoomDevToolAction.MenuEdit)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachme
import org.matrix.android.sdk.api.session.room.timeline.Timeline
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.widgets.model.Widget
import org.matrix.android.sdk.api.session.widgets.model.WidgetContent
import org.matrix.android.sdk.api.util.MatrixItem

sealed class RoomDetailAction : VectorViewModelAction {
Expand Down Expand Up @@ -108,7 +107,6 @@ sealed class RoomDetailAction : VectorViewModelAction {
object QuickActionSetTopic : RoomDetailAction()
data class ShowRoomAvatarFullScreen(val matrixItem: MatrixItem?, val transitionView: View?) : RoomDetailAction()


// Preview URL
data class DoNotShowPreviewUrlFor(val eventId: String, val url: String) : RoomDetailAction()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,6 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject
import android.animation.ValueAnimator




@Parcelize
data class RoomDetailArgs(
val roomId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ class RoomDetailViewModel @AssistedInject constructor(
widgets.filter { it.isActive }
}
.execute { widgets ->
copy(
activeRoomWidgets = widgets,
)
copy(activeRoomWidgets = widgets)
}

asyncSubscribe(RoomDetailViewState::activeRoomWidgets) { widgets ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package im.vector.app.features.home.room.detail

import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MvRxState
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized
import im.vector.app.core.platform.ButtonStateView
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
} else if (!event.canBeMerged() || (nextEvent?.root?.getClearType() == event.root.getClearType() && !addDaySeparator)) {
null
} else {
buildMembershipEventsMergedSummary(currentPosition, items,partialState, event, eventIdToHighlight, requestModelBuild, callback)
buildMembershipEventsMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import im.vector.app.core.resources.StringProvider
import me.gujun.android.span.span
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent
import org.matrix.android.sdk.api.session.room.model.message.MessageOptionsContent
import org.matrix.android.sdk.api.session.room.model.message.MessageType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class NoticeEventFormatter @Inject constructor(
}
EventType.CALL_REJECT ->
if (event.isSentByCurrentUser()) {
sp.getString(R.string.call_tile_you_declined,"")
sp.getString(R.string.call_tile_you_declined, "")
} else {
sp.getString(R.string.call_tile_other_declined, senderName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
}
}

private fun getE2EDecoration(roomSummary: RoomSummary? , event: TimelineEvent): E2EDecoration {
private fun getE2EDecoration(roomSummary: RoomSummary?, event: TimelineEvent): E2EDecoration {
return if (
event.root.sendState == SendState.SYNCED
&& roomSummary?.isEncrypted.orFalse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.widgets.model.WidgetContent
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
import org.threeten.bp.Duration

class TimelineEventsGroup(val groupId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package im.vector.app.features.home.room.detail.timeline.item

import android.content.res.Resources
import android.telecom.Call
import android.view.View
import android.view.ViewGroup
import android.widget.Button
Expand Down
2 changes: 1 addition & 1 deletion vector/src/main/res/layout/bottom_sheet_generic_list.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.airbnb.epoxy.EpoxyRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottomSheetRecyclerView"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion vector/src/main/res/layout/view_join_conference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:paddingStart="4dp"
android:layout_width="wrap_content">

<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/join_conference_button"
android:layout_width="56dp"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 882188f

Please sign in to comment.