mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-14 16:25:05 +01:00
Add default notification sounds
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
09dfd42bb7
commit
e3464b65b1
@ -20,11 +20,13 @@
|
||||
|
||||
package com.nextcloud.talk.controllers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -33,6 +35,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.bluelinelabs.conductor.RouterTransaction;
|
||||
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
import com.bumptech.glide.load.model.LazyHeaders;
|
||||
@ -42,6 +45,7 @@ import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.api.NcApi;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.models.RingtoneSettings;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.participants.Participant;
|
||||
import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
|
||||
@ -50,9 +54,11 @@ import com.nextcloud.talk.models.json.rooms.RoomsOverall;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
|
||||
import org.parceler.Parcels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -69,9 +75,14 @@ import io.reactivex.schedulers.Schedulers;
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class CallNotificationController extends BaseController {
|
||||
|
||||
private static final String TAG = "CallNotificationController";
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
@Inject
|
||||
AppPreferences appPreferences;
|
||||
|
||||
@BindView(R.id.conversationNameTextView)
|
||||
TextView conversationNameTextView;
|
||||
|
||||
@ -84,7 +95,6 @@ public class CallNotificationController extends BaseController {
|
||||
private String credentials;
|
||||
private Room currentRoom;
|
||||
private MediaPlayer mediaPlayer;
|
||||
private boolean participantsCheckIsRunning;
|
||||
private boolean leavingScreen = false;
|
||||
|
||||
public CallNotificationController(Bundle args) {
|
||||
@ -141,7 +151,6 @@ public class CallNotificationController extends BaseController {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
disposablesList.add(d);
|
||||
participantsCheckIsRunning = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -219,6 +228,7 @@ public class CallNotificationController extends BaseController {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
protected void onViewBound(@NonNull View view) {
|
||||
super.onViewBound(view);
|
||||
@ -227,12 +237,28 @@ public class CallNotificationController extends BaseController {
|
||||
|
||||
handleFromNotification();
|
||||
|
||||
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
String callRingtonePreferenceString = appPreferences.getCallRingtoneUri();
|
||||
Uri ringtoneUri = null;
|
||||
|
||||
if (TextUtils.isEmpty(callRingtonePreferenceString)) {
|
||||
// play default sound
|
||||
ringtoneUri = Uri.parse("android.resource://" + getApplicationContext().getPackageName()+
|
||||
"/raw/librem_by_feandesign_call");
|
||||
} else {
|
||||
try {
|
||||
RingtoneSettings ringtoneSettings = LoganSquare.parse(callRingtonePreferenceString, RingtoneSettings.class);
|
||||
ringtoneUri = ringtoneSettings.getRingtoneUri();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to parse ringtone settings");
|
||||
}
|
||||
}
|
||||
|
||||
if (ringtoneUri != null) {
|
||||
mediaPlayer = MediaPlayer.create(getApplicationContext(), ringtoneUri);
|
||||
mediaPlayer.setLooping(true);
|
||||
mediaPlayer.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadAvatar() {
|
||||
int avatarSize = Math.round(NextcloudTalkApplication
|
||||
|
@ -149,7 +149,24 @@ public class RingtoneSelectionController extends BaseController implements Flexi
|
||||
abstractFlexibleItemList = new ArrayList<>();
|
||||
abstractFlexibleItemList.add(new NotificationSoundItem("None", null));
|
||||
|
||||
int positionToToggle = -1;
|
||||
String ringtoneString;
|
||||
|
||||
if (callNotificationSounds) {
|
||||
ringtoneString = "android.resource://" + getApplicationContext().getPackageName() +
|
||||
"/raw/librem_by_feandesign_call";
|
||||
} else {
|
||||
ringtoneString = "android.resource://" + getApplicationContext().getPackageName() +
|
||||
"/raw/librem_by_feandesign_message";
|
||||
}
|
||||
|
||||
abstractFlexibleItemList.add(new NotificationSoundItem(getResources()
|
||||
.getString(R.string.nc_settings_default_ringtone), ringtoneString));
|
||||
|
||||
String preferencesString = null;
|
||||
if ((TextUtils.isEmpty((preferencesString = appPreferences.getCallRingtoneUri())))
|
||||
|| TextUtils.isEmpty((preferencesString = appPreferences.getMessageRingtoneUri()))) {
|
||||
((NotificationSoundItem) abstractFlexibleItemList.get(1)).setSelected(true);
|
||||
}
|
||||
|
||||
if (getActivity() != null) {
|
||||
RingtoneManager manager = new RingtoneManager(getActivity());
|
||||
@ -164,6 +181,7 @@ public class RingtoneSelectionController extends BaseController implements Flexi
|
||||
|
||||
NotificationSoundItem notificationSoundItem;
|
||||
|
||||
boolean foundDefault = false;
|
||||
while (cursor.moveToNext()) {
|
||||
String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
|
||||
String notificationUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
|
||||
@ -174,23 +192,23 @@ public class RingtoneSelectionController extends BaseController implements Flexi
|
||||
|
||||
abstractFlexibleItemList.add(notificationSoundItem);
|
||||
|
||||
String preferencesString;
|
||||
if (callNotificationSounds && !TextUtils.isEmpty(preferencesString = appPreferences
|
||||
.getCallRingtoneUri()) ||
|
||||
!callNotificationSounds && !TextUtils.isEmpty(preferencesString = appPreferences
|
||||
.getMessageRingtoneUri())) {
|
||||
if (!TextUtils.isEmpty(preferencesString) && !foundDefault) {
|
||||
try {
|
||||
RingtoneSettings ringtoneSettings = LoganSquare.parse(preferencesString, RingtoneSettings.class);
|
||||
if (ringtoneSettings.getRingtoneUri() == null) {
|
||||
((NotificationSoundItem)abstractFlexibleItemList.get(0)).setSelected(true);
|
||||
((NotificationSoundItem) abstractFlexibleItemList.get(0)).setSelected(true);
|
||||
foundDefault = true;
|
||||
} else if (completeNotificationUri.equals(ringtoneSettings.getRingtoneUri().toString())) {
|
||||
notificationSoundItem.setSelected(true);
|
||||
foundDefault = true;
|
||||
} else if (completeNotificationUri.equals(ringtoneString)) {
|
||||
((NotificationSoundItem) abstractFlexibleItemList.get(1)).setSelected(true);
|
||||
foundDefault = true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to parse ringtone settings");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
@ -320,6 +320,8 @@ public class SettingsController extends BaseController {
|
||||
Log.e(TAG, "Failed to parse ringtone name");
|
||||
}
|
||||
settingsCallSounds.setSummary(ringtoneName);
|
||||
} else {
|
||||
settingsMessageSound.setSummary(R.string.nc_settings_default_ringtone);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(appPreferences.getMessageRingtoneUri())) {
|
||||
@ -330,6 +332,8 @@ public class SettingsController extends BaseController {
|
||||
Log.e(TAG, "Failed to parse ringtone name");
|
||||
}
|
||||
settingsMessageSound.setSummary(ringtoneName);
|
||||
} else {
|
||||
settingsMessageSound.setSummary(R.string.nc_settings_default_ringtone);
|
||||
}
|
||||
|
||||
if ("No proxy".equals(appPreferences.getProxyType()) || appPreferences.getProxyType() == null) {
|
||||
|
BIN
app/src/main/res/raw/librem_by_feandesign_call.ogg
Normal file
BIN
app/src/main/res/raw/librem_by_feandesign_call.ogg
Normal file
Binary file not shown.
BIN
app/src/main/res/raw/librem_by_feandesign_message.ogg
Normal file
BIN
app/src/main/res/raw/librem_by_feandesign_message.ogg
Normal file
Binary file not shown.
@ -65,6 +65,7 @@
|
||||
<string name="nc_settings_call_ringtone_key">call_ringtone</string>
|
||||
<string name="nc_settings_message_ringtone">Messages</string>
|
||||
<string name="nc_settings_message_ringtone_key">message_ringtone</string>
|
||||
<string name="nc_settings_default_ringtone" translatable="false">Librem by feandesign</string>
|
||||
|
||||
<string name="nc_no_proxy">No proxy</string>
|
||||
<string name="nc_username">Username</string>
|
||||
|
Loading…
Reference in New Issue
Block a user