Skip to content

Commit 1c4ba6f

Browse files
committed
Fix issues and add support for ringtone
Signed-off-by: Mario Danic <[email protected]>
1 parent 717ec32 commit 1c4ba6f

File tree

3 files changed

+68
-10
lines changed

3 files changed

+68
-10
lines changed

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import android.content.IntentFilter;
3434
import android.content.res.Configuration;
3535
import android.os.Bundle;
36-
import android.os.Parcelable;
3736
import android.support.annotation.NonNull;
3837
import android.support.annotation.Nullable;
3938
import android.support.v7.app.AppCompatActivity;
@@ -56,6 +55,8 @@
5655
import com.nextcloud.talk.api.helpers.api.ApiHelper;
5756
import com.nextcloud.talk.api.models.json.call.CallOverall;
5857
import com.nextcloud.talk.api.models.json.generic.GenericOverall;
58+
import com.nextcloud.talk.api.models.json.rooms.Room;
59+
import com.nextcloud.talk.api.models.json.rooms.RoomsOverall;
5960
import com.nextcloud.talk.api.models.json.signaling.DataChannelMessage;
6061
import com.nextcloud.talk.api.models.json.signaling.NCIceCandidate;
6162
import com.nextcloud.talk.api.models.json.signaling.NCMessagePayload;
@@ -221,14 +222,14 @@ protected void onCreate(Bundle savedInstanceState) {
221222
ButterKnife.bind(this);
222223

223224
roomToken = getIntent().getExtras().getString("roomToken", "");
224-
userEntity = Parcels.unwrap((Parcelable) getIntent().getExtras().get("userEntity"));
225+
userEntity = Parcels.unwrap(getIntent().getExtras().getParcelable("userEntity"));
225226
callSession = "0";
226227
credentials = ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken());
227228

228229
callControls.setZ(100.0f);
229230
basicInitialization();
230231

231-
if (userUtils.getCurrentUser() != null && userUtils.getCurrentUser() != userEntity) {
232+
if (!userEntity.getCurrent()) {
232233
userUtils.createOrUpdateUser(userEntity.getUsername(),
233234
userEntity.getToken(), userEntity.getBaseUrl(), null,
234235
null, true)
@@ -242,8 +243,12 @@ public void onSubscribe(Disposable d) {
242243
public void onNext(UserEntity userEntity) {
243244
cookieManager.getCookieStore().removeAll();
244245
userUtils.disableAllUsersWithoutId(userEntity.getId());
245-
initViews();
246-
checkPermissions();
246+
if (getIntent().getExtras().containsKey("fromNotification")) {
247+
handleFromNotification();
248+
} else {
249+
initViews();
250+
checkPermissions();
251+
}
247252
}
248253

249254
@Override
@@ -257,13 +262,50 @@ public void onComplete() {
257262
}
258263
});
259264

265+
} else if (getIntent().getExtras().containsKey("fromNotification")) {
266+
handleFromNotification();
260267
} else {
261268
initViews();
262269
checkPermissions();
263270
}
271+
}
272+
273+
private void handleFromNotification() {
274+
ncApi.getRooms(credentials, ApiHelper.getUrlForGetRooms(userEntity.getBaseUrl()))
275+
.subscribeOn(Schedulers.newThread())
276+
.observeOn(AndroidSchedulers.mainThread())
277+
.subscribe(new Observer<RoomsOverall>() {
278+
@Override
279+
public void onSubscribe(Disposable d) {
280+
281+
}
282+
283+
@Override
284+
public void onNext(RoomsOverall roomsOverall) {
285+
for (Room room : roomsOverall.getOcs().getData()) {
286+
if (roomToken.equals(room.getRoomId())) {
287+
roomToken = room.getToken();
288+
break;
289+
}
290+
}
264291

292+
initViews();
293+
checkPermissions();
294+
}
295+
296+
@Override
297+
public void onError(Throwable e) {
298+
299+
}
300+
301+
@Override
302+
public void onComplete() {
303+
304+
}
305+
});
265306
}
266307

308+
267309
private void toggleMedia(boolean enable, boolean video) {
268310
String message;
269311
if (video) {
@@ -731,6 +773,7 @@ public void onNext(SignalingOverall signalingOverall) {
731773

732774
@Override
733775
public void onError(Throwable e) {
776+
Log.d("MARIO_DEBUG", e.getLocalizedMessage());
734777
dispose(signalingDisposable);
735778
}
736779

@@ -745,7 +788,7 @@ public void onComplete() {
745788

746789
@Override
747790
public void onError(Throwable e) {
748-
791+
Log.d("MARIO_DEBUG", e.getLocalizedMessage());
749792
}
750793

751794
@Override

app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import com.nextcloud.talk.utils.PushUtils;
4747
import com.nextcloud.talk.utils.bundle.BundleBuilder;
4848

49+
import org.parceler.Parcels;
50+
4951
import java.security.InvalidKeyException;
5052
import java.security.NoSuchAlgorithmException;
5153
import java.security.PrivateKey;
@@ -93,7 +95,9 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
9395
Intent intent = new Intent(this, CallActivity.class);
9496
BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
9597
bundleBuilder.putString("roomToken", decryptedPushMessage.getId());
96-
bundleBuilder.putParcelable("userEntity", signatureVerification.getUserEntity());
98+
bundleBuilder.putParcelable("userEntity", Parcels.wrap(signatureVerification
99+
.getUserEntity()));
100+
bundleBuilder.putBoolean("fromNotification", true);
97101
intent.putExtras(bundleBuilder.build());
98102

99103
PendingIntent pendingIntent = PendingIntent.getActivity(this,
@@ -155,15 +159,15 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
155159
NotificationUtils.NOTIFICATION_CHANNEL_CALLS, getResources().getString(R
156160
.string.nc_notification_channel_calls), getResources().getString
157161
(R.string.nc_notification_channel_calls_description), true,
158-
NotificationManager.IMPORTANCE_HIGH);
162+
NotificationManager.IMPORTANCE_HIGH, soundUri);
159163

160164
notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
161165
} else {
162166
NotificationUtils.createNotificationChannel(notificationManager,
163167
NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES, getResources().getString(R
164168
.string.nc_notification_channel_messages), getResources().getString
165169
(R.string.nc_notification_channel_messages_description), true,
166-
NotificationManager.IMPORTANCE_DEFAULT);
170+
NotificationManager.IMPORTANCE_DEFAULT, soundUri);
167171

168172
notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
169173
}

app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import android.app.NotificationChannelGroup;
2626
import android.app.NotificationManager;
2727
import android.graphics.Color;
28+
import android.media.AudioAttributes;
29+
import android.net.Uri;
2830
import android.os.Build;
2931

3032
public class NotificationUtils {
@@ -36,14 +38,23 @@ public class NotificationUtils {
3638
public static void createNotificationChannel(NotificationManager notificationManager,
3739
String channelId, String channelName,
3840
String channelDescription, boolean vibrate,
39-
int importance) {
41+
int importance, Uri soundUri) {
4042

4143
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O
4244
&& notificationManager.getNotificationChannel(channelId) == null) {
4345

4446
NotificationChannel channel = new NotificationChannel(channelId, channelName,
4547
importance);
4648

49+
int usage;
50+
51+
if (channelId.equals(NotificationUtils.NOTIFICATION_CHANNEL_CALLS)) {
52+
usage = AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST;
53+
} else {
54+
usage = AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT;
55+
}
56+
57+
channel.setSound(soundUri, new AudioAttributes.Builder().setUsage(usage).build());
4758
channel.setDescription(channelDescription);
4859
channel.enableLights(vibrate);
4960
channel.enableVibration(vibrate);

0 commit comments

Comments
 (0)