Skip to content

Commit

Permalink
implement long click and short click on hangup button
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
  • Loading branch information
sowjanyakch committed Oct 25, 2024
1 parent af6ebaa commit bab1393
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 24 deletions.
57 changes: 39 additions & 18 deletions app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ class CallActivity : CallBaseActivity() {

override fun onCallEndedForAll() {
Log.d(TAG, "A moderator ended the call for all.")
hangup(true)
hangup(true, false)
}
}
private var callParticipantList: CallParticipantList? = null
private var switchToRoomToken = ""
private var isBreakoutRoom = false
private val localParticipantMessageListener = LocalParticipantMessageListener { token ->
switchToRoomToken = token
hangup(true)
hangup(true,false)
}
private val offerMessageListener = OfferMessageListener { sessionId, roomType, sdp, nick ->
getOrCreatePeerConnectionWrapperForSessionIdAndType(
Expand Down Expand Up @@ -470,7 +470,7 @@ class CallActivity : CallBaseActivity() {
binding!!.callRecordingIndicator.visibility = View.GONE
}
}
initClickListeners()
initClickListeners(isModerator)
binding!!.microphoneButton.setOnTouchListener(MicrophoneButtonTouchListener())
pulseAnimation = PulseAnimation.create().with(binding!!.microphoneButton)
.setDuration(310)
Expand Down Expand Up @@ -498,7 +498,7 @@ class CallActivity : CallBaseActivity() {
}
.setNegativeButton(R.string.nc_no) { _, _ ->
recordingConsentGiven = false
hangup(true)
hangup(true,false)
}

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, materialAlertDialogBuilder)
Expand Down Expand Up @@ -613,7 +613,8 @@ class CallActivity : CallBaseActivity() {
}
}

private fun initClickListeners() {
@SuppressLint("ClickableViewAccessibility")
private fun initClickListeners(isModerator:Boolean) {
binding!!.pictureInPictureButton.setOnClickListener { enterPipMode() }

binding!!.audioOutputButton.setOnClickListener {
Expand Down Expand Up @@ -663,7 +664,22 @@ class CallActivity : CallBaseActivity() {
).show()
}
}
binding!!.hangupButton.setOnClickListener { hangup(true) }

binding!!.hangupButton.setOnClickListener {
hangup(true, false)
}

if (isModerator) {
binding!!. hangupButton.setOnLongClickListener {
showPopupMenu()
true
}
}

binding!!.popupMenu.setOnClickListener {
hangup(true, true)
binding!!.popupMenu.visibility = View.GONE
}
binding!!.switchSelfVideoButton.setOnClickListener { switchCamera() }
binding!!.gridview.onItemClickListener =
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, _: Int, _: Long ->
Expand All @@ -675,7 +691,7 @@ class CallActivity : CallBaseActivity() {
binding!!.callStates.callStateRelativeLayout.setOnClickListener {
if (currentCallStatus === CallStatus.CALLING_TIMEOUT) {
setCallState(CallStatus.RECONNECTING)
hangupNetworkCalls(false)
hangupNetworkCalls(false, false)
}
}
binding!!.callRecordingIndicator.setOnClickListener {
Expand All @@ -699,6 +715,11 @@ class CallActivity : CallBaseActivity() {
binding!!.lowerHandButton.setOnClickListener { l: View? -> raiseHandViewModel!!.lowerHand() }
}

private fun showPopupMenu() {
binding!!.popupMenu.visibility = View.VISIBLE

}

private fun createCameraEnumerator() {
var camera2EnumeratorIsSupported = false
try {
Expand Down Expand Up @@ -1442,7 +1463,7 @@ class CallActivity : CallBaseActivity() {
Log.d(TAG, "localStream is null")
}
if (currentCallStatus !== CallStatus.LEAVING) {
hangup(true)
hangup(true, false)
}
powerManagerUtils!!.updatePhoneState(PowerManagerUtils.PhoneState.IDLE)
super.onDestroy()
Expand Down Expand Up @@ -1726,7 +1747,7 @@ class CallActivity : CallBaseActivity() {
override fun onError(e: Throwable) {
Log.e(TAG, "Failed to join call", e)
Snackbar.make(binding!!.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
hangup(true)
hangup(true, false)
}

override fun onComplete() {
Expand Down Expand Up @@ -1877,7 +1898,7 @@ class CallActivity : CallBaseActivity() {
Log.d(TAG, "onMessageEvent 'hello'")
if (!webSocketCommunicationEvent.getHashMap()!!.containsKey("oldResumeId")) {
if (currentCallStatus === CallStatus.RECONNECTING) {
hangup(false)
hangup(false, false)
} else {
setCallState(CallStatus.RECONNECTING)
runOnUiThread { initiateCall() }
Expand Down Expand Up @@ -1953,7 +1974,7 @@ class CallActivity : CallBaseActivity() {
}
}

private fun hangup(shutDownView: Boolean) {
private fun hangup(shutDownView: Boolean, endCallForAll:Boolean) {
Log.d(TAG, "hangup! shutDownView=$shutDownView")
if (shutDownView) {
setCallState(CallStatus.LEAVING)
Expand Down Expand Up @@ -2018,17 +2039,17 @@ class CallActivity : CallBaseActivity() {

ApplicationWideCurrentRoomHolder.getInstance().isInCall = false
ApplicationWideCurrentRoomHolder.getInstance().isDialing = false
hangupNetworkCalls(shutDownView)
hangupNetworkCalls(shutDownView,endCallForAll)
}

private fun hangupNetworkCalls(shutDownView: Boolean) {
private fun hangupNetworkCalls(shutDownView: Boolean, endCallForAll: Boolean) {
Log.d(TAG, "hangupNetworkCalls. shutDownView=$shutDownView")
val apiVersion = ApiUtils.getCallApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1))
if (callParticipantList != null) {
callParticipantList!!.removeObserver(callParticipantListObserver)
callParticipantList!!.destroy()
}
ncApi!!.leaveCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken!!), false)
ncApi!!.leaveCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken!!), endCallForAll)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> {
Expand Down Expand Up @@ -2122,7 +2143,7 @@ class CallActivity : CallBaseActivity() {
ApplicationWideCurrentRoomHolder.getInstance().isInCall
) {
Log.d(TAG, "Most probably a moderator ended the call for all.")
hangup(true)
hangup(true, true)
return
}

Expand Down Expand Up @@ -2249,7 +2270,7 @@ class CallActivity : CallBaseActivity() {
context.resources.getString(R.string.nc_common_error_sorry),
Snackbar.LENGTH_LONG
).show()
hangup(true)
hangup(true,false)
return null
}
peerConnectionWrapper = if (hasMCU && publisher) {
Expand Down Expand Up @@ -2565,7 +2586,7 @@ class CallActivity : CallBaseActivity() {
}

CallStatus.CALLING_TIMEOUT -> handler!!.post {
hangup(false)
hangup(false, false)
binding!!.callStates.callStateTextView.setText(R.string.nc_call_timeout)
binding!!.callModeTextView.text = descriptionForCallType
if (binding!!.callStates.callStateRelativeLayout.visibility != View.VISIBLE) {
Expand Down Expand Up @@ -2835,7 +2856,7 @@ class CallActivity : CallBaseActivity() {
if (iceConnectionState == IceConnectionState.FAILED) {
setCallState(CallStatus.PUBLISHER_FAILED)
webSocketClient!!.clearResumeId()
hangup(false)
hangup(false, false)
}
}
}
Expand Down
34 changes: 28 additions & 6 deletions app/src/main/res/layout/call_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
android:src="@drawable/record_stop"
android:translationZ="2dp"
android:visibility="gone"
tools:visibility="visible"></ImageView>
tools:visibility="visible">
</ImageView>
</LinearLayout>

<LinearLayout
Expand Down Expand Up @@ -182,14 +183,31 @@
android:layout_marginBottom="50dp">
</RelativeLayout>


<com.google.android.flexbox.FlexboxLayout
android:id="@+id/flexboxLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_half_margin"
app:flexDirection="row"
android:layout_alignParentBottom="true"
app:justifyContent="flex_end"
app:alignItems="center">

<Button
android:id="@+id/popup_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/end_call_for_everyone"
android:layout_marginEnd="8dp"
android:visibility="gone"
tools:visibility ="visible"/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/lower_hand_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_half_margin"
android:contentDescription="@string/lower_hand"
android:visibility="gone"
app:backgroundTint="@color/call_buttons_background"
Expand All @@ -198,7 +216,11 @@
app:shapeAppearance="@style/fab_3_rounded"
app:srcCompat="@drawable/ic_baseline_do_not_touch_24"
app:tint="@color/white"
tools:visibility="visible" />
tools:visibility = "visible"/>

</com.google.android.flexbox.FlexboxLayout>



</RelativeLayout>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ How to translate with transifex:
<string name="lower_hand">Lower hand</string>
<string name="restrict_join_other_room_while_call">It\'s not possible to join other rooms while being in a call</string>
<string name="call_running_since_one_hour">The call has been running for one hour.</string>
<string name="end_call_for_everyone">End Call for Everyone</string>

<!-- Picture in Picture -->
<string name="nc_pip_microphone_mute">Mute microphone</string>
Expand Down

0 comments on commit bab1393

Please sign in to comment.