Skip to content

Commit bfa9db9

Browse files
committed
- refactoring
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
1 parent a324f56 commit bfa9db9

5 files changed

Lines changed: 25 additions & 41 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ freeline_project_description.json
8686

8787
# python
8888
**/__pycache__/
89+
.vscode/
8990

9091
/gradle/verification-keyring.gpg

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOveral
9494
import com.nextcloud.talk.raisehand.viewmodel.RaiseHandViewModel
9595
import com.nextcloud.talk.raisehand.viewmodel.RaiseHandViewModel.LoweredHandState
9696
import com.nextcloud.talk.raisehand.viewmodel.RaiseHandViewModel.RaisedHandState
97+
import com.nextcloud.talk.receivers.EndCallReceiver.Companion.END_CALL_FROM_NOTIFICATION
9798
import com.nextcloud.talk.services.CallForegroundService
9899
import com.nextcloud.talk.signaling.SignalingMessageReceiver
99100
import com.nextcloud.talk.signaling.SignalingMessageReceiver.CallParticipantMessageListener
@@ -185,7 +186,6 @@ import java.util.Objects
185186
import java.util.concurrent.TimeUnit
186187
import java.util.concurrent.atomic.AtomicInteger
187188
import javax.inject.Inject
188-
import kotlin.String
189189
import kotlin.math.abs
190190

191191
@AutoInjector(NextcloudTalkApplication::class)
@@ -267,6 +267,16 @@ class CallActivity : CallBaseActivity() {
267267
private val callParticipantMessageListeners: MutableMap<String?, CallParticipantMessageListener> = HashMap()
268268
private val selfPeerConnectionObserver: PeerConnectionObserver = CallActivitySelfPeerConnectionObserver()
269269

270+
private val endCallFromNotificationReceiver = object : BroadcastReceiver() {
271+
override fun onReceive(context: Context, intent: Intent) {
272+
if (intent.action == END_CALL_FROM_NOTIFICATION) {
273+
isIntentionallyLeavingCall = true
274+
powerManagerUtils?.updatePhoneState(PowerManagerUtils.PhoneState.IDLE)
275+
hangup(shutDownView = true, endCallForAll = false)
276+
}
277+
}
278+
}
279+
270280
private val callParticipantListObserver: CallParticipantList.Observer = object : CallParticipantList.Observer {
271281
override fun onCallParticipantsChanged(
272282
joined: Collection<Participant>,
@@ -408,7 +418,7 @@ class CallActivity : CallBaseActivity() {
408418
sharedApplication!!.componentApplication.inject(this)
409419

410420
// Register broadcast receiver for ending call from notification
411-
val endCallFilter = IntentFilter("com.nextcloud.talk.END_CALL_FROM_NOTIFICATION")
421+
val endCallFilter = IntentFilter(END_CALL_FROM_NOTIFICATION)
412422

413423
// Use the proper utility function with ReceiverFlag for Android 14+ compatibility
414424
// This receiver is for internal app use only (notification actions), so it should NOT be exported
@@ -3223,18 +3233,4 @@ class CallActivity : CallBaseActivity() {
32233233

32243234
private const val SESSION_ID_PREFFIX_END: Int = 4
32253235
}
3226-
3227-
// Broadcast receiver to handle end call from notification
3228-
private val endCallFromNotificationReceiver = object : BroadcastReceiver() {
3229-
override fun onReceive(context: Context, intent: Intent) {
3230-
if (intent.action == "com.nextcloud.talk.END_CALL_FROM_NOTIFICATION") {
3231-
Log.d(TAG, "Received end call from notification broadcast")
3232-
Log.d(TAG, "endCallFromNotificationReceiver: Setting isIntentionallyLeavingCall=true")
3233-
isIntentionallyLeavingCall = true
3234-
Log.d(TAG, "endCallFromNotificationReceiver: Releasing proximity sensor before hangup")
3235-
powerManagerUtils?.updatePhoneState(PowerManagerUtils.PhoneState.IDLE)
3236-
hangup(shutDownView = true, endCallForAll = false)
3237-
}
3238-
}
3239-
}
32403236
}

app/src/main/java/com/nextcloud/talk/receivers/EndCallReceiver.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@ import android.content.BroadcastReceiver
1010
import android.content.Context
1111
import android.content.Intent
1212
import android.util.Log
13-
import com.nextcloud.talk.activities.CallActivity
1413
import com.nextcloud.talk.services.CallForegroundService
1514

1615
class EndCallReceiver : BroadcastReceiver() {
1716
companion object {
18-
private const val TAG = "EndCallReceiver"
17+
private val TAG = EndCallReceiver::class.simpleName
18+
const val END_CALL_ACTION = "com.nextcloud.talk.END_CALL"
19+
const val END_CALL_FROM_NOTIFICATION = "com.nextcloud.talk.END_CALL_FROM_NOTIFICATION"
1920
}
2021

2122
override fun onReceive(context: Context?, intent: Intent?) {
22-
if (intent?.action == "com.nextcloud.talk.END_CALL") {
23-
Log.d(TAG, "Received end call broadcast")
23+
if (intent?.action == END_CALL_ACTION) {
24+
Log.i(TAG, "Received end call broadcast")
2425

2526
// Stop the foreground service
2627
context?.let {
2728
CallForegroundService.stop(it)
2829

2930
// Send broadcast to CallActivity to end the call
30-
val endCallIntent = Intent("com.nextcloud.talk.END_CALL_FROM_NOTIFICATION")
31+
val endCallIntent = Intent(END_CALL_FROM_NOTIFICATION)
3132
endCallIntent.setPackage(context.packageName)
3233
context.sendBroadcast(endCallIntent)
3334
}
3435
}
3536
}
36-
}
37+
}

app/src/main/java/com/nextcloud/talk/services/CallForegroundService.kt

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import android.content.pm.ServiceInfo
1616
import android.os.Build
1717
import android.os.Bundle
1818
import android.os.IBinder
19-
import android.util.Log
2019
import androidx.core.app.NotificationCompat
2120
import androidx.core.app.NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE
2221
import androidx.core.content.ContextCompat
2322
import com.nextcloud.talk.R
2423
import com.nextcloud.talk.activities.CallActivity
2524
import com.nextcloud.talk.application.NextcloudTalkApplication
2625
import com.nextcloud.talk.receivers.EndCallReceiver
26+
import com.nextcloud.talk.receivers.EndCallReceiver.Companion.END_CALL_ACTION
2727
import com.nextcloud.talk.utils.NotificationUtils
2828
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CALL_VOICE_ONLY
2929
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO
@@ -62,25 +62,19 @@ class CallForegroundService : Service() {
6262
?: getString(R.string.nc_call_ongoing_notification_default_title)
6363
val pendingIntent = createContentIntent(callExtras)
6464

65-
// Create action to return to call
6665
val returnToCallAction = NotificationCompat.Action.Builder(
6766
R.drawable.ic_call_white_24dp,
6867
getString(R.string.nc_call_ongoing_notification_return_action),
6968
pendingIntent
7069
).build()
7170

72-
// Create action to end call
7371
val endCallPendingIntent = createEndCallIntent(callExtras)
7472

75-
// DIAGNOSTIC: Logging icon resource availability
76-
Log.d("CallForegroundService", "Creating end call action - checking icon resources")
77-
Log.d("CallForegroundService", "Using ic_baseline_close_24 instead of non-existent ic_close_white_24px")
78-
7973
val endCallAction = NotificationCompat.Action.Builder(
80-
R.drawable.ic_baseline_close_24, // DIAGNOSTIC: Fixed - using existing icon
74+
R.drawable.ic_baseline_close_24,
8175
getString(R.string.nc_call_ongoing_notification_end_action),
8276
endCallPendingIntent
83-
).build() // Already has parentheses, good!
77+
).build()
8478

8579
return NotificationCompat.Builder(this, channelId)
8680
.setContentTitle(contentTitle)
@@ -115,16 +109,11 @@ class CallForegroundService : Service() {
115109
}
116110

117111
private fun createEndCallIntent(callExtras: Bundle?): PendingIntent {
118-
// DIAGNOSTIC: Logging intent creation
119-
Log.d("CallForegroundService", "Creating EndCallIntent with EndCallReceiver class")
120-
121112
val intent = Intent(this, EndCallReceiver::class.java).apply {
122-
action = "com.nextcloud.talk.END_CALL"
113+
action = END_CALL_ACTION
123114
callExtras?.let { putExtras(Bundle(it)) }
124115
}
125-
126-
Log.d("CallForegroundService", "EndCallIntent created successfully with action: ${intent.action}")
127-
116+
128117
val flags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
129118
return PendingIntent.getBroadcast(this, 1, intent, flags)
130119
}

0 commit comments

Comments
 (0)