diff --git a/app/src/main/assets/ringtones/aqua.mp3 b/app/src/main/assets/ringtones/aqua.mp3 deleted file mode 100644 index eade4b71712e5a37d8495678573152f2c9a66fe0..0000000000000000000000000000000000000000 Binary files a/app/src/main/assets/ringtones/aqua.mp3 and /dev/null differ diff --git a/app/src/main/assets/ringtones/cheerful.mp3 b/app/src/main/assets/ringtones/cheerful.mp3 deleted file mode 100644 index c9a66e24ceb6035638e2064c17de269f6166e206..0000000000000000000000000000000000000000 Binary files a/app/src/main/assets/ringtones/cheerful.mp3 and /dev/null differ diff --git a/app/src/main/assets/ringtones/discreet.mp3 b/app/src/main/assets/ringtones/discreet.mp3 deleted file mode 100644 index 9900d9b96539d026a5429312304a5417c701b161..0000000000000000000000000000000000000000 Binary files a/app/src/main/assets/ringtones/discreet.mp3 and /dev/null differ diff --git a/app/src/main/assets/ringtones/important_stuff.mp3 b/app/src/main/assets/ringtones/important_stuff.mp3 deleted file mode 100644 index 0db04b3ecf3f1b24429234a41fb39f1e5d0419e2..0000000000000000000000000000000000000000 Binary files a/app/src/main/assets/ringtones/important_stuff.mp3 and /dev/null differ diff --git a/app/src/main/assets/ringtones/nynja.mp3 b/app/src/main/assets/ringtones/nynja.mp3 deleted file mode 100644 index de5759baa950b38d87a9986a6bdf74336f62faef..0000000000000000000000000000000000000000 Binary files a/app/src/main/assets/ringtones/nynja.mp3 and /dev/null differ diff --git a/app/src/main/assets/ringtones/optimistic.mp3 b/app/src/main/assets/ringtones/optimistic.mp3 deleted file mode 100644 index f0d434ce223d79dbfd8be731348cfce8cf509a28..0000000000000000000000000000000000000000 Binary files a/app/src/main/assets/ringtones/optimistic.mp3 and /dev/null differ diff --git a/app/src/main/assets/ringtones/sunrise.mp3 b/app/src/main/assets/ringtones/sunrise.mp3 deleted file mode 100644 index 6e6baf0acf6175adbc79971be84bc5a56fee372e..0000000000000000000000000000000000000000 Binary files a/app/src/main/assets/ringtones/sunrise.mp3 and /dev/null differ diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java b/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java index 9b2d0ef5c5f6d110160884c0c91bc718c75170de..d4fd29b4e66de6a007007f192e9be61cfe31019b 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java @@ -4460,8 +4460,9 @@ public class DataManager { return FileUtils.getAlertSoundsList(mContext, getSettingNotifications().getAlertSound()); } - public List getRingtonesFileNamesFromAssetsSubfolder() { - return FileUtils.getFileNamesFromAssetsSubfolder(mContext, Consts.RINGER_SOUND_FOLDER_NAME); + public HashMap getRingtonesFileNamesFromAssetsSubfolder() { + return FileUtils.getFileRingtonesNamesFromRaw(mContext); + //return FileUtils.getFileNamesFromAssetsSubfolder(mContext, Consts.RINGER_SOUND_FOLDER_NAME); } public AuthCodeReceiverClient getAuthCodeReceiverClient() { @@ -5806,7 +5807,8 @@ public class DataManager { } public void playDemoRingerSound(@NotNull String ringerSound) { - mNynjaSoundManager.playSound(ringerSound, false, NynjaSoundManager.Stream.MUSIC); +// mNynjaSoundManager.playSound(ringerSound, false, NynjaSoundManager.Stream.MUSIC); + mNynjaSoundManager.playSound(Uri.parse(ringerSound), false, NynjaSoundManager.Stream.MUSIC); if (mNotificationHelper.ringerSoundChange(mSettingNotifications, ringerSound)) { mPreferenceHelper.setSettingNotifications(mSettingNotifications); } @@ -5896,7 +5898,15 @@ public class DataManager { } public void playCallRinging() { - mNynjaSoundManager.playCallRinging(mSettingNotifications.getRingerSound()); + Uri soundUri = null; + try { + soundUri = Uri.parse(mSettingNotifications.getRingerSound()); + } catch (Exception ex) { + Timber.e(ex); + } + if (soundUri != null) { + mNynjaSoundManager.playCallRinging(soundUri); + } } public NynjaSoundManager.Mode getNynjaSoundManagerRingerMode() { diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt b/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt index d33b077baf050ff9642e37bc0ff7d9b6dbe9b576..4b0b2dbcc419c906d0b33060bf6e98f4aead93a0 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt @@ -70,9 +70,10 @@ class DownloadFileService : Service() { val launchIntent = MainActivity.getLaunchIntent(mDataManager.context) val title = mDataManager.context.getString(R.string.notification_downloading) val text = mDataManager.context.getString(R.string.notification_file) - val notification = mNotificationHelper.buildNotification(Push.DOWNLOADING, null, launchIntent, - mDataManager.settingNotifications, 0, text, true, title, true, - true, mDataManager.conferenceSDK.hasCallInProgress(), false, null) + val notification = mNotificationHelper.buildNotification(NotificationHelper.DOWNLOADING, null, + launchIntent, mDataManager.settingNotifications, 0, + text, true, title, true, true, + mDataManager.conferenceSDK.hasCallInProgress(), false, null) startForeground(ONGOING_NOTIFICATION_ID, notification) // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java b/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java index e6b368ae55f35775c1e15870658805578693b5b3..2dea4d560a0e7aba9973286ed054b53ebe3f8ef3 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java @@ -108,8 +108,8 @@ public class FireBaseMessagingService extends FirebaseMessagingService { if(model == null) break; Timber.i(model.toString()); if (mDataManager.getSettingNotifications().isCallNotifications()) { -// boolean isMainActivityIsActive = mDataManager.isMainActivityIsActive(); - boolean isMainActivityIsActive = !mDataManager.isInBackground(); + boolean isMainActivityIsActive = mDataManager.isMainActivityIsActive(); +// boolean isMainActivityIsActive = !mDataManager.isInBackground(); if (!isMainActivityIsActive) { mDataManager.reconnectConference(); } @@ -270,9 +270,10 @@ public class FireBaseMessagingService extends FirebaseMessagingService { "; isDeviceLocked=" + (isDeviceLocked ? "true" : "false")); if (context instanceof FireBaseMessagingService) { mNotificationHelper.createCallPushNotification(context, from, callId, - !hasActiveCall, - mDataManager.getSettingNotifications(), - true); + isMainActivityIsActive, + !hasActiveCall, + mDataManager.getSettingNotifications(), + true); } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/UploadFileService.kt b/app/src/main/java/com/nynja/mobile/communicator/data/UploadFileService.kt index f7f5f4e9b6eb128c23c799bb4a63c9e9524ebf01..91bff93650be853dc968868884ca10a1661d1a07 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/UploadFileService.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/UploadFileService.kt @@ -63,9 +63,10 @@ class UploadFileService : Service() { val launchIntent = MainActivity.getLaunchIntent(mDataManager.context) val title = mDataManager.context.getString(R.string.notification_uploading) val text = mDataManager.context.getString(R.string.notification_file) - val notification = mNotificationHelper.buildNotification(Push.UPLOADING, null, launchIntent, - mDataManager.settingNotifications, 0, text, true, title, true, - true, mDataManager.conferenceSDK.hasCallInProgress(), false, null) + val notification = mNotificationHelper.buildNotification(NotificationHelper.UPLOADING, null, + launchIntent, mDataManager.settingNotifications, 0, + text, true, title, true, true, + mDataManager.conferenceSDK.hasCallInProgress(), false, null) startForeground(ONGOING_NOTIFICATION_ID, notification) } else if (intent != null && STOP_UPLOAD_FOREGROUND_ACTION == intent.action) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt b/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt index 31437a93cfcf5cc45a11e7defb351f8daf072b2b..b3a9ed2c02ef371419da755bbe62e3d73f4b0616 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt @@ -160,7 +160,7 @@ class NynjaSoundManager(context: Context) { playSound(SOUND_RING_BACK_FILE_NAME, true, NynjaSoundManager.Stream.VOICE_CALL) } - fun playCallRinging(@NotNull soundFileName: String) { + fun playCallRinging(@NotNull soundFileName: Uri) { playCallRinging(soundFileName, true) } @@ -172,7 +172,7 @@ class NynjaSoundManager(context: Context) { return (mAudioManager.ringerMode != AudioManager.RINGER_MODE_SILENT && mInAppVibrate); } - fun playCallRinging(@NotNull soundFileName: String, registerObserver: Boolean) { + fun playCallRinging(@NotNull soundFileName: Uri, registerObserver: Boolean) { if (canPlayRingingSound()) { playSound(soundFileName, true, NynjaSoundManager.Stream.RINGER) } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java b/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java index fc0218451e0c2e5e4d6474eb5c67bc58b8edde2c..3194807e6fba3757b7333d02b83bec99dc8c5302 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java @@ -160,19 +160,21 @@ public class PreferenceHelper { } public void setSettingNotifications(SettingNotifications sn) { - mSharedPreferences.edit().putBoolean(NOTIFICATION_IN_APP_VIBRATE, sn.isInAppVibrate()).apply(); - mSharedPreferences.edit().putString(NOTIFICATION_ALERT_SOUND, sn.getAlertSound()).apply(); - mSharedPreferences.edit().putBoolean(NOTIFICATION_SOUND, sn.isSound()).apply(); - mSharedPreferences.edit().putBoolean(NOTIFICATION_CALL_NOTIFICATION, sn.isCallNotifications()).apply(); - mSharedPreferences.edit().putBoolean(NOTIFICATION_NEW_MESSAGE_ALERTS, sn.isNewMessageAlerts()).apply(); - mSharedPreferences.edit().putBoolean(NOTIFICATIONS_MUTE_DURING_CALL, sn.isMutedDuringCall()).apply(); - mSharedPreferences.edit().putBoolean(NOTIFICATION_INCOMING_SOUND, sn.isIncomingSoundInMutedChat()).apply(); - mSharedPreferences.edit().putString(NOTIFICATION_RINGER_SOUND, sn.getRingerSound()).apply(); - mSharedPreferences.edit().putBoolean(NOTIFICATION_SENT_MESSAGE_SOUND, sn.isSentMessageSound()).apply(); - mSharedPreferences.edit().putString(NOTIFICATION_DEFAULT_SOUND, sn.getDefaultNotificationSound()).apply(); - mSharedPreferences.edit().putLong(NOTIFICATION_PREFERENCE_VERSION, sn.getVersion()).apply(); - mSharedPreferences.edit().putBoolean(NOTIFICATION_APP_ICON_BADGES_CLEARED, sn.isBadgesCleared()).apply(); - mSharedPreferences.edit().putLong(NOTIFICATION_RINGER_SOUND_INDEX, sn.getRingerSoundIndex()).apply(); + SharedPreferences.Editor editor = mSharedPreferences.edit(); + editor.putBoolean(NOTIFICATION_IN_APP_VIBRATE, sn.isInAppVibrate()).apply(); + editor.putString(NOTIFICATION_ALERT_SOUND, sn.getAlertSound()).apply(); + editor.putBoolean(NOTIFICATION_SOUND, sn.isSound()).apply(); + editor.putBoolean(NOTIFICATION_CALL_NOTIFICATION, sn.isCallNotifications()).apply(); + editor.putBoolean(NOTIFICATION_NEW_MESSAGE_ALERTS, sn.isNewMessageAlerts()).apply(); + editor.putBoolean(NOTIFICATIONS_MUTE_DURING_CALL, sn.isMutedDuringCall()).apply(); + editor.putBoolean(NOTIFICATION_INCOMING_SOUND, sn.isIncomingSoundInMutedChat()).apply(); + editor.putString(NOTIFICATION_RINGER_SOUND, sn.getRingerSound()).apply(); + editor.putBoolean(NOTIFICATION_SENT_MESSAGE_SOUND, sn.isSentMessageSound()).apply(); + editor.putString(NOTIFICATION_DEFAULT_SOUND, sn.getDefaultNotificationSound()).apply(); + editor.putLong(NOTIFICATION_PREFERENCE_VERSION, sn.getVersion()).apply(); + editor.putBoolean(NOTIFICATION_APP_ICON_BADGES_CLEARED, sn.isBadgesCleared()).apply(); + editor.putLong(NOTIFICATION_RINGER_SOUND_INDEX, sn.getRingerSoundIndex()).apply(); + editor.commit(); } public SettingNotifications getSettingNotifications() { @@ -190,7 +192,7 @@ public class PreferenceHelper { String defaultNotificationSound = mSharedPreferences.getString(NOTIFICATION_DEFAULT_SOUND, Consts.NotificationSounds.NYNJA.getDisplayName()); Long version = mSharedPreferences.getLong(NOTIFICATION_PREFERENCE_VERSION, 0L); boolean isBadgesCleared = mSharedPreferences.getBoolean(NOTIFICATION_APP_ICON_BADGES_CLEARED, false); - Long ringerSoundIndex = mSharedPreferences.getLong(NOTIFICATION_PREFERENCE_VERSION, 0L); + Long ringerSoundIndex = mSharedPreferences.getLong(NOTIFICATION_RINGER_SOUND_INDEX, 0L); mSettingNotifications = new SettingNotifications(newMessgeAlerts, callNotification, sound, alertSound, inAppVibrate, isMutedDuringCall, isIncomingSoundInMutedChat, ringerSound, isSentMessageSound, defaultNotificationSound, diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt b/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt index 8333e5aa82770a1ac0ab9c34382373f2f265b0a9..3fce7b160262de241ce320443030be4574b6b063 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt @@ -22,8 +22,8 @@ class SettingNotifications (var isNewMessageAlerts: Boolean, private var version: Long = 0L companion object { - const val VERSION = 5 - const val RESET_VERSION = 5 + const val VERSION: Long = 6 + const val RESET_VERSION: Long = 5 fun defaultVersion(): Long = VERSION.toLong() } @@ -40,4 +40,11 @@ class SettingNotifications (var isNewMessageAlerts: Boolean, return this.version == VERSION.toLong() } + fun isUpgradeVersion(): Boolean { + return this.version < VERSION.toLong() + } + + fun isDowngradeVersion(): Boolean { + return this.version > VERSION.toLong() + } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/models/mqtt/Push.java b/app/src/main/java/com/nynja/mobile/communicator/data/models/mqtt/Push.java index d5e4bbac6e748af569ccc03154c656ebc8b9c8b4..684cdf61c8b623111f10833a935d113387a6d90c 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/models/mqtt/Push.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/models/mqtt/Push.java @@ -21,22 +21,10 @@ public class Push extends BaseParcelMQTT { public final static String FRIEND = "friend"; public final static String MESSAGE = "message"; public final static String REQUEST_FRIEND = "request"; - public final static String CONFERENCE = "media_playback_channel"; - public final static String UPLOADING = "uploading"; - public final static String DOWNLOADING = "downloading"; - - public final static String DEFAULT_V_01 = "DEFAULT_v_01"; - public final static String FRIEND_V_01 = "friend_v_01"; - public final static String MESSAGE_V_01 = "message_v_01"; - public final static String REQUEST_FRIEND_V_01 = "request_v_01"; - public final static String CONFERENCE_V_01 = "media_playback_channel_v_01"; private static final String MESSAGE_DELETE = "message_delete"; private static final String HISTORY_DELETE = "history_delete"; - public final static int CHANNEL_VERSION = 4; - - @Either({Contact.class, Room.class, String.class}) @Order(1) public Object model; @Order(2) public String type; @@ -50,10 +38,6 @@ public class Push extends BaseParcelMQTT { public Push() { } - public static String getChannelId(String channelPrefix) { - return channelPrefix + CHANNEL_VERSION; - } - @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java index f45a7dde97b3ff02451dff5a36830502f4e99586..4e52d9cf1819fe69eefe3d2e281526a7525e3b5f 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java @@ -2897,7 +2897,7 @@ public class ConferenceSDKModule extends BaseSDKModule { "; delayed=" + (delayed?"true": "false")); final String name = mActiveConference.getCallerName(); new Handler(Looper.getMainLooper()).post(() -> { - mNotificationHelper.createCallPushNotification(getContext(), name, callId, true, + mNotificationHelper.createCallPushNotification(getContext(), name, callId, true, true, mSettingNotifications, false); }); return true; @@ -3039,7 +3039,7 @@ public class ConferenceSDKModule extends BaseSDKModule { if (startActivity) { if (Consts.SHOW_INCOMING_CALLS_AS_POPUP_NOTIFICATIONS) { new Handler(Looper.getMainLooper()).post(() -> { - mNotificationHelper.createCallPushNotification(getContext(), mActiveConference.getCallerName(), callId, true, + mNotificationHelper.createCallPushNotification(getContext(), mActiveConference.getCallerName(), callId, true, true, mSettingNotifications, false); }); } else if (!startIncommingConferenceActivity(delayed, callId, null)) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java index 3eb8178a7724c01d911f91dd2ca7e7c02e595f9a..90b7ab46dddfcd96c2564316a2c2252c95575afd 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java @@ -133,7 +133,6 @@ public class ConferenceService extends Service implements SensorEventListener { Intent launchIntent = MainActivity.getLaunchIntent(this, true); launchIntent.putExtra(IS_INTENT_FROM_CALL_SERVICE, true); - launchIntent.putExtra(IS_CALL_ACTIVE, true); Notification notification = mNotificationHelper.buildNotification(Push.CALLING, null, launchIntent, mDataManager.getSettingNotifications(), 0, contentText, true, title, true, diff --git a/app/src/main/java/com/nynja/mobile/communicator/injection/ApplicationComponent.java b/app/src/main/java/com/nynja/mobile/communicator/injection/ApplicationComponent.java index 3badf826f4c131e4002f9a40ebf14fa5888d1b8b..dd737951513b66b0b3b39049cb90f384305ea02b 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/injection/ApplicationComponent.java +++ b/app/src/main/java/com/nynja/mobile/communicator/injection/ApplicationComponent.java @@ -12,6 +12,7 @@ import com.nynja.mobile.communicator.data.FireBaseMessagingService; import com.nynja.mobile.communicator.data.GooglePlacesService; import com.nynja.mobile.communicator.data.NynjaKeyboardManager; import com.nynja.mobile.communicator.data.RxBus; +import com.nynja.mobile.communicator.data.db.PreferenceHelper; import com.nynja.mobile.communicator.data.sdk.NynjaSDKManager; import com.nynja.mobile.communicator.data.sdk.calls.ConferenceService; import com.nynja.mobile.communicator.data.db.DbHelper; @@ -74,6 +75,8 @@ public interface ApplicationComponent { NotificationHelper notificationHelper(); + PreferenceHelper preferenceHelper(); + void inject(FireBaseInstanceIDService fbInstanceIDService); void inject(FireBaseMessagingService fbMessagingService); diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt index 41003eb4563b7685581a8fd63a40492dd2fd6d25..dd825fc3032b504c22913656ae7b76eebdc641f2 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt @@ -4,6 +4,7 @@ import com.arellomobile.mvp.InjectViewState import com.nynja.mobile.communicator.R import com.nynja.mobile.communicator.data.models.mqtt.Push import com.nynja.mobile.communicator.mvp.view.NotificationChannelsView +import com.nynja.mobile.communicator.utils.NotificationHelper import com.nynja.mobile.communicator.utils.navigation.navigators.HomeNavigator import com.nynja.mobile.communicator.utils.navigation.navigators.NynjaNavigator @@ -27,24 +28,23 @@ class NotificationChannelsPresenter : BasePresenter() } fun navigateToMainChannelSettings() { - openChannelSettings(Push.getChannelId(Push.DEFAULT_V_01)) + openChannelSettings(NotificationHelper.getChannelId(NotificationHelper.DEFAULT_V_01)) } fun navigateToMessageChannelSettings() { - openChannelSettings(Push.getChannelId(Push.MESSAGE_V_01)) + openChannelSettings(NotificationHelper.getChannelId(NotificationHelper.MESSAGE_V_01)) } fun navigateToFriendsChannelSettings() { - openChannelSettings(Push.getChannelId(Push.FRIEND_V_01)) + openChannelSettings(NotificationHelper.getChannelId(NotificationHelper.FRIEND_V_01)) } fun navigateToRequestsChannelSettings() { - openChannelSettings(Push.getChannelId(Push.REQUEST_FRIEND_V_01)) + openChannelSettings(NotificationHelper.getChannelId(NotificationHelper.REQUEST_FRIEND_V_01)) } fun navigateToConferenceChannelSettings() { - openChannelSettings(Push.getChannelId(Push.CONFERENCE_V_01) + - mDataManager.settingNotifications.ringerSoundIndex) + openChannelSettings(NotificationHelper.getdRingingChannelId(mDataManager.settingNotifications)) } fun openChannelSettings(channel: String) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/RingtonesPresenter.java b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/RingtonesPresenter.java index 6a79312a2d5fcde5af7b3e049d06df7c438f7d51..69c727206b6dbbb18374768f86557f3a43da0386 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/RingtonesPresenter.java +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/RingtonesPresenter.java @@ -3,10 +3,12 @@ package com.nynja.mobile.communicator.mvp.presenters; import com.arellomobile.mvp.InjectViewState; import com.nynja.mobile.communicator.data.models.RingtoneSound; import com.nynja.mobile.communicator.mvp.view.RingtonesView; +import com.nynja.mobile.communicator.utils.FileUtils; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** @@ -18,10 +20,10 @@ public class RingtonesPresenter extends BasePresenter { public void loadRingtoneSounds() { List ringtoneSounds = new ArrayList<>(); String currentSound = mDataManager.getSettingNotifications().getRingerSound(); - - List fileNames = mDataManager.getRingtonesFileNamesFromAssetsSubfolder(); - for (int i = 0; i < fileNames.size(); i++) { - ringtoneSounds.add(new RingtoneSound(fileNames.get(i), getRingtoneDisplayName(fileNames.get(i)), fileNames.get(i).equals(currentSound))); + HashMap fileNames = mDataManager.getRingtonesFileNamesFromAssetsSubfolder(); + for (String key : fileNames.keySet()) { + ringtoneSounds.add(new RingtoneSound(fileNames.get(key), key, + (currentSound != null && currentSound.equals(fileNames.get(key))))); } getViewState().setItems(ringtoneSounds); @@ -34,7 +36,7 @@ public class RingtonesPresenter extends BasePresenter { private String getRingtoneDisplayName(@NotNull String fileName) { int start = fileName.lastIndexOf("/") + 1; - int end = fileName.indexOf("."); + int end = fileName.indexOf(".", start); String result = fileName.substring(start, end); result = result.replaceAll("_", " "); diff --git a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java index e2388cf0ea57037cea0b6cf631461d8fc42ba300..92a23114050d93a25b0fb0ddf82c0fbd01ac9e1b 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java +++ b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java @@ -317,6 +317,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, //TODO need refactoring private void handleIntent() { if (getIntent() == null || getIntent().getExtras() == null) { + Timber.d("MainActivity::handleIntent(): intent OR iontent Extras is NULL!!!"); mPresenter.isComingFromLink(); return; } @@ -324,6 +325,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, if (Intent.ACTION_SEND.equals(intent.getAction()) && intent.getType() != null) { if (!mPresenter.isLogIn()) { mPresenter.navigateToWelcome(); + Timber.d("MainActivity::handleIntent(): NOT logged-in!!!"); return; } if (intent.getType() != null) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/calls/IncomeCallActivity.java b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/calls/IncomeCallActivity.java index 4e1163dbd87b99f43427e85f2f8c76289b1f1cab..e9781ef2101b2b320ca35c6d31555f2a6dc75a17 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/calls/IncomeCallActivity.java +++ b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/calls/IncomeCallActivity.java @@ -73,6 +73,7 @@ public class IncomeCallActivity extends BaseActivity implements IncomeCallView { } @Override protected void onCreate(Bundle savedInstanceState) { + Timber.d("IncomeCallActivity::onCreate()"); getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY); super.onCreate(savedInstanceState); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); @@ -84,6 +85,7 @@ public class IncomeCallActivity extends BaseActivity implements IncomeCallView { @Override protected void onDestroy() { releaseWakeLockActivity(); + Timber.d("IncomeCallActivity::onDestroy()"); super.onDestroy(); } diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java b/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java index 8e208eef6ca97aec58df2b56077db59d195e56bc..f4a3e9eda834ac7a5a15c11df4e7781f947d85f1 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java @@ -69,15 +69,24 @@ public interface Consts { } } + public static String[] mRingingSounds = { + "aqua.mp3", + "cheerful.mp3", + "discreet.mp3", + "important_stuff.mp3", + "nynja_ringing.mp3", + "optimistic.mp3", + "sunrise.mp3" + }; public enum NotificationRingingSounds { - SUNRUSE("sunrise", R.raw.sunrise), - AQUA("aqua", R.raw.aqua), - CHEERFUL("cheerful", R.raw.cheerful), - DISCREET("discreet", R.raw.discreet), - IMPORTAN_STUFF("important_stuff", R.raw.important_stuff), - NYNJA("nynja", R.raw.nynja_ringing), - OPTIMISTIC("optimistic", R.raw.optimistic); + AQUA(mRingingSounds[0], R.raw.aqua), + CHEERFUL(mRingingSounds[1], R.raw.cheerful), + DISCREET(mRingingSounds[2], R.raw.discreet), + IMPORTAN_STUFF(mRingingSounds[3], R.raw.important_stuff), + NYNJA(mRingingSounds[4], R.raw.nynja_ringing), + OPTIMISTIC(mRingingSounds[5], R.raw.optimistic), + SUNRUSE(mRingingSounds[6], R.raw.sunrise); private String name; private int id; diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java b/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java index f2b0e2d2a7d23156868d8ac6083fc8fdcaa0df69..b8acaf60139f70496de02a24dbd873732aa9fcc6 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java @@ -33,6 +33,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URI; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -653,6 +654,26 @@ public class FileUtils { return list; } + public static HashMap getFileRingtonesNamesFromRaw(@NonNull Context context) { + String[] fileNames; + HashMap fileNamesWithFolderPrefix = new HashMap<>(); + String folder = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/"; + try { + fileNames = Consts.mRingingSounds; + if (fileNames.length > 0) { + for (String file : fileNames) { + String name = FileUtils.getFileName(file); + String path = folder + Consts.NotificationRingingSounds.getIdByName(name); + fileNamesWithFolderPrefix.put(name, path); + } + } + } catch (Exception e) { + Timber.e(e); + } + + return fileNamesWithFolderPrefix; + } + public static List getFileNamesFromAssetsSubfolder(@NonNull Context context, @NonNull String folder) { String[] fileNames; List fileNamesWithFolderPrefix = new ArrayList<>(); @@ -853,12 +874,12 @@ public class FileUtils { @NonNull public static String getFileName(String fullPath) { final int lastIndexOf = fullPath.lastIndexOf('/'); - return lastIndexOf > 0 ? fullPath.substring(lastIndexOf+1) : fullPath; + return lastIndexOf >= 0 ? fullPath.substring(lastIndexOf+1) : fullPath; } @NonNull public static String getFileNameWithoutExt(String fullPath) { final int lastIndexOf = fullPath.lastIndexOf('/'); - String name = lastIndexOf > 0 ? fullPath.substring(lastIndexOf+1) : fullPath;; + String name = lastIndexOf >= 0 ? fullPath.substring(lastIndexOf+1) : fullPath;; int pos = name.lastIndexOf("."); if (pos > 0) { name = name.substring(0, pos); diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java b/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java index 4a258b57111148fa5d2755e52171283832a7737a..29ef622f6e22b07f7ade6a66f0ae53e57de3d663 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java @@ -23,9 +23,9 @@ import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; +import com.nynja.mobile.communicator.NynjaApp; import com.nynja.mobile.communicator.R; import com.nynja.mobile.communicator.data.DescManager; -import com.nynja.mobile.communicator.data.FireBaseMessagingService; import com.nynja.mobile.communicator.data.NotificationDismissReceiver; import com.nynja.mobile.communicator.data.audio.NynjaSoundManager; import com.nynja.mobile.communicator.data.models.PushNotificationCounter; @@ -57,6 +57,19 @@ import timber.log.Timber; @Singleton public class NotificationHelper extends ContextWrapper { + public final static String CONFERENCE = "media_playback_channel"; + public final static String UPLOADING = "uploading"; + public final static String DOWNLOADING = "downloading"; + + public final static String DEFAULT_V_01 = "DEFAULT_v_01"; + public final static String FRIEND_V_01 = "friend_v_01"; + public final static String MESSAGE_V_01 = "message_v_01"; + public final static String REQUEST_FRIEND_V_01 = "request_v_01"; + public final static String CONFERENCE_V_01 = "media_playback_channel_v_01"; + + public final static int CHANNEL_VERSION = 4; + public final static int CALLS_CHANNEL_VERSION = 1; + private final static String STICKER = "Sticker"; private final static int SUMMARY_ID = 0; @@ -71,6 +84,15 @@ public class NotificationHelper extends ContextWrapper { private NotificationManager mManager; private NynjaSoundManager mNynjaSoundManager; + public static String getChannelId(String channelPrefix) { + return channelPrefix + CHANNEL_VERSION; + } + + @NonNull + public static String getdRingingChannelId(SettingNotifications settingNotifications) { + return (CONFERENCE_V_01 + CALLS_CHANNEL_VERSION + settingNotifications.getRingerSoundIndex()); + } + @Inject public NotificationHelper(@ApplicationContext Context base, NynjaSoundManager soundManager) { super(base); mNynjaSoundManager = soundManager; @@ -82,11 +104,45 @@ public class NotificationHelper extends ContextWrapper { deleteChannelsIfExist(settingNotifications); } else if (settingNotifications.isLatestVersion()) { return; + } else if (settingNotifications.isUpgradeVersion()) { + onUpgrade(settingNotifications, + settingNotifications.getVersion(), + SettingNotifications.VERSION); + } else if (settingNotifications.isDowngradeVersion()) { + deleteChannelsIfExist(settingNotifications); } initChannels(settingNotifications); } + private void onUpgrade(SettingNotifications settingNotifications, + long oldVersion, long newVersion) { + if (oldVersion == 0) { + initChannels(settingNotifications); + } else { + for (long i = oldVersion; i < newVersion; i++) { + if (i == 5) { + upgrade_to_6(settingNotifications); + } + } + } + } + + @TargetApi(Build.VERSION_CODES.O) + private void upgrade_to_6(SettingNotifications settingNotifications) { + getManager().deleteNotificationChannel(CONFERENCE_V_01); + getManager().deleteNotificationChannel(CONFERENCE_V_01); + getManager().deleteNotificationChannel(getChannelId(CONFERENCE_V_01)); + // delete current ringing sound channels + for (long i = settingNotifications.getRingerSoundIndex(); i > 0; i--) { + String id = getChannelId(CONFERENCE_V_01)+i; + getManager().deleteNotificationChannel(id); + } + settingNotifications.setRingerSoundIndex(0L); + updateRingerSoundAndCreateChannel(settingNotifications); + NynjaApp.getComponent().preferenceHelper().setSettingNotifications(settingNotifications); + } + private void initChannels(SettingNotifications settingNotifications) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; deleteChannelsIfExist(settingNotifications); @@ -95,36 +151,34 @@ public class NotificationHelper extends ContextWrapper { boolean isVibrationEnabled = settingNotifications.isInAppVibrate(); String alertSound = settingNotifications.getAlertSound(); - NotificationChannel channel = buildChannel(Push.getChannelId(Push.DEFAULT_V_01), + NotificationChannel channel = buildChannel(getChannelId(DEFAULT_V_01), NOTIFICATION_CHANNEL_DEFAULT, "Default channel", isSoundEnabled, isVibrationEnabled, null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); - channel = buildChannel(Push.getChannelId(Push.MESSAGE_V_01), + channel = buildChannel(getChannelId(MESSAGE_V_01), NOTIFICATION_CHANNEL_MESSAGE, "Message channel", isSoundEnabled, isVibrationEnabled, null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); - channel = buildChannel(Push.getChannelId(Push.FRIEND_V_01), + channel = buildChannel(getChannelId(FRIEND_V_01), NOTIFICATION_CHANNEL_FRIEND, "Friend channel", isSoundEnabled, isVibrationEnabled, null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); - channel = buildChannel(Push.getChannelId(Push.REQUEST_FRIEND_V_01), + channel = buildChannel(getChannelId(REQUEST_FRIEND_V_01), NOTIFICATION_CHANNEL_REQUEST, "Request channel", isSoundEnabled, isVibrationEnabled, null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); - buildRingingChannel(settingNotifications); - channel = buildChannel(Push.CALLING, NOTIFICATION_CHANNEL_CALLING, "Calling channel", false, false, @@ -133,14 +187,16 @@ public class NotificationHelper extends ContextWrapper { channel.setShowBadge(false); getManager().createNotificationChannel(channel); - channel = buildChannel(Push.getChannelId(Push.UPLOADING), + buildRingingChannel(settingNotifications); + + channel = buildChannel(getChannelId(UPLOADING), NOTIFICATION_CHANNEL_UPLOADING, "Uploding", false, false, null); channel.setShowBadge(false); getManager().createNotificationChannel(channel); - channel = buildChannel(Push.getChannelId(Push.DOWNLOADING), + channel = buildChannel(getChannelId(DOWNLOADING), NOTIFICATION_CHANNEL_DOWNLOADING, "Downloading", false, false, null); @@ -156,27 +212,27 @@ public class NotificationHelper extends ContextWrapper { getManager().deleteNotificationChannel(Push.MESSAGE); getManager().deleteNotificationChannel(Push.FRIEND); getManager().deleteNotificationChannel(Push.REQUEST_FRIEND); - getManager().deleteNotificationChannel(Push.CONFERENCE); getManager().deleteNotificationChannel(Push.CALLING); - getManager().deleteNotificationChannel(Push.UPLOADING); - getManager().deleteNotificationChannel(Push.DOWNLOADING); + getManager().deleteNotificationChannel(CONFERENCE); + getManager().deleteNotificationChannel(UPLOADING); + getManager().deleteNotificationChannel(DOWNLOADING); // channel version 1 ... - getManager().deleteNotificationChannel(Push.DEFAULT_V_01); - getManager().deleteNotificationChannel(Push.MESSAGE_V_01); - getManager().deleteNotificationChannel(Push.FRIEND_V_01); - getManager().deleteNotificationChannel(Push.REQUEST_FRIEND_V_01); - getManager().deleteNotificationChannel(Push.CONFERENCE_V_01); + getManager().deleteNotificationChannel(DEFAULT_V_01); + getManager().deleteNotificationChannel(MESSAGE_V_01); + getManager().deleteNotificationChannel(FRIEND_V_01); + getManager().deleteNotificationChannel(REQUEST_FRIEND_V_01); + getManager().deleteNotificationChannel(CONFERENCE_V_01); // latest channel version ... - getManager().deleteNotificationChannel(Push.getChannelId(Push.DEFAULT_V_01)); - getManager().deleteNotificationChannel(Push.getChannelId(Push.MESSAGE_V_01)); - getManager().deleteNotificationChannel(Push.getChannelId(Push.FRIEND_V_01)); - getManager().deleteNotificationChannel(Push.getChannelId(Push.REQUEST_FRIEND_V_01)); - getManager().deleteNotificationChannel(Push.getChannelId(Push.CONFERENCE_V_01)); - getManager().deleteNotificationChannel(Push.getChannelId(Push.UPLOADING)); - getManager().deleteNotificationChannel(Push.getChannelId(Push.DOWNLOADING)); + getManager().deleteNotificationChannel(getChannelId(DEFAULT_V_01)); + getManager().deleteNotificationChannel(getChannelId(MESSAGE_V_01)); + getManager().deleteNotificationChannel(getChannelId(FRIEND_V_01)); + getManager().deleteNotificationChannel(getChannelId(REQUEST_FRIEND_V_01)); + getManager().deleteNotificationChannel(getChannelId(CONFERENCE_V_01)); + getManager().deleteNotificationChannel(getChannelId(UPLOADING)); + getManager().deleteNotificationChannel(getChannelId(DOWNLOADING)); // delete current ringing sound channel deleteRingingChannel(settingNotifications); @@ -222,23 +278,27 @@ public class NotificationHelper extends ContextWrapper { return channel; } + public void updateRingerSoundAndCreateChannel(SettingNotifications settingNotifications) { + Timber.d("updateRingerSoundAndCreateChannel()"); + deleteRingingChannel(settingNotifications); + settingNotifications.setRingerSoundIndex(settingNotifications.getRingerSoundIndex() + 1); + buildRingingChannel(settingNotifications); + } + public synchronized boolean ringerSoundChange(SettingNotifications settingNotifications, @NotNull String ringerSound) { String rSound = settingNotifications.getRingerSound(); + Timber.d("ringerSoundChange(): check 1: channel old_name=%s, new_name=%s", + rSound, ringerSound); if (!StringUtils.isEqual(ringerSound, rSound)) { - deleteRingingChannel(settingNotifications); + Timber.d("ringerSoundChange(): check 2: channel old_id=%d", + settingNotifications.getRingerSoundIndex()); settingNotifications.setRingerSound(ringerSound); - settingNotifications.setRingerSoundIndex(settingNotifications.getRingerSoundIndex() + 1); - buildRingingChannel(settingNotifications); + updateRingerSoundAndCreateChannel(settingNotifications); return true; } return false; } - @NonNull - private String getdRingingChannelId(SettingNotifications settingNotifications) { - return Push.getChannelId(Push.CONFERENCE_V_01)+settingNotifications.getRingerSoundIndex(); - } - @TargetApi(Build.VERSION_CODES.O) @NonNull private void buildRingingChannel(SettingNotifications settingNotifications) { @@ -250,6 +310,8 @@ public class NotificationHelper extends ContextWrapper { settingNotifications.isSound(), settingNotifications.isInAppVibrate(), notificationSoundUri); channel.setShowBadge(false); + Timber.d("buildRingingChannel(): new channel: channel id=%s, sound=%s", + id, notificationSoundUri.toString()); getManager().createNotificationChannel(channel); } @@ -272,13 +334,14 @@ public class NotificationHelper extends ContextWrapper { PendingIntent answerPendingIntent, PendingIntent rejectPendingIntent, boolean isMainActivityIsActive, + boolean sendNotification, SettingNotifications settingNotifications) { Uri notificationSoundUri = getCallNotificationSoundUri(settingNotifications.getRingerSound()); Timber.i("Push.CALLING: createCallPushNotification(): check XXX1"); Notification notification = buildCallNotification(context, intent, answerPendingIntent, rejectPendingIntent, - settingNotifications, from, notificationSoundUri); - if (isMainActivityIsActive) { + settingNotifications, from, isMainActivityIsActive, notificationSoundUri); + if (sendNotification) { Timber.i("Push.CALLING: createCallPushNotification(): check XXX2"); sendRingingNotify(notification, ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID); Timber.i("Push.CALLING: createCallPushNotification(): check XXX3"); @@ -300,11 +363,12 @@ public class NotificationHelper extends ContextWrapper { public synchronized Notification createCallPushNotification(Context context, String from, String callId, boolean isMainActivityIsActive, + boolean sendNotification, SettingNotifications settingNotifications, boolean isPush) { Timber.i((isPush?"Push.CALLING": "Grpc.CALLING")+": createCallPushNotification() isMainActivityIsActive=" + (isMainActivityIsActive?"true": "false")); if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) { - Timber.i((isPush?"Push.CALLING": "Grpc.CALLING")+": createCallPushNotification() Notifications are not enabledby the System !!!"); + Timber.i((isPush?"Push.CALLING": "Grpc.CALLING")+": createCallPushNotification() Notifications are not enabled by the System !!!"); return null; } Intent fullScreenIntent = MainActivity.getLaunchIntent(context, false, true); @@ -335,6 +399,7 @@ public class NotificationHelper extends ContextWrapper { answerPendingIntent, rejectPendingIntent, isMainActivityIsActive, + sendNotification, settingNotifications); } @@ -441,7 +506,7 @@ public class NotificationHelper extends ContextWrapper { if (Push.MESSAGE.equalsIgnoreCase(type)) { builder.setCategory(Notification.CATEGORY_MESSAGE); } - if (type != null && (type.contentEquals(Push.DOWNLOADING) || type.contentEquals(Push.UPLOADING))) { + if (type != null && (type.contentEquals(DOWNLOADING) || type.contentEquals(UPLOADING))) { builder.setProgress(10, 1, true); } } @@ -487,16 +552,17 @@ public class NotificationHelper extends ContextWrapper { @NonNull public synchronized Notification buildCallNotification(Context context, - Intent fullScreenIntent, - PendingIntent answerPendingIntent, - PendingIntent rejectPendingIntent, - SettingNotifications settingNotifications, - String from, - Uri notificationSoundUri) { + Intent fullScreenIntent, + PendingIntent answerPendingIntent, + PendingIntent rejectPendingIntent, + SettingNotifications settingNotifications, + String from, + boolean isMainActivityIsActive, + Uri notificationSoundUri) { String type = getdRingingChannelId(settingNotifications); boolean notificationsEnabled = areNotificationsEnabled(context, getManager(), type); if (!notificationsEnabled) { - Timber.w("buildCallNotification(): 'Calls' Notifications are DISABLED!!!!"); + Timber.w("buildCallNotification(): 'Calls' Notifications are DISABLED! Should be created later."); return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -523,6 +589,7 @@ public class NotificationHelper extends ContextWrapper { .setCategory(NotificationCompat.CATEGORY_CALL) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setOngoing(true) + .setGroupAlertBehavior(Notification.GROUP_ALERT_ALL) .addExtras(args); @@ -540,37 +607,52 @@ public class NotificationHelper extends ContextWrapper { notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true); - notificationBuilder.setPriority(NotificationManager.IMPORTANCE_MAX); - //notificationBuilder.setPriority(NotificationManager.IMPORTANCE_HIGH); } else { notificationBuilder.setContentIntent(fullScreenPendingIntent); } Notification notification = notificationBuilder.build(); - + Timber.d("ZZZZZZ 1"); if (!(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)) { + Timber.d("ZZZZZZ 2"); if (settingNotifications.isSound() && mNynjaSoundManager.canPlayRingingSound()) { + Timber.d("ZZZZZZ 3"); notification.sound = notificationSoundUri; notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR); } else { + Timber.d("ZZZZZZ 4"); notification.sound = null; notification.defaults = 0; notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_NO_CLEAR); } + Timber.d("ZZZZZZ 5"); if (settingNotifications.isInAppVibrate() && mNynjaSoundManager.canVibrateWhenRingingSound()) { + Timber.d("ZZZZZZ 6"); notification.defaults |= Notification.DEFAULT_VIBRATE; } } else { if (settingNotifications.isSound() && mNynjaSoundManager.canPlayRingingSound()) { + Timber.d("ZZZZZZ 7: ntfn flag=%d, isSound=%s, canPlayRingingSound=%s", + notification.flags, settingNotifications.isSound()?"true":"false", + mNynjaSoundManager.canPlayRingingSound()?"true":"false"); notification.sound = notificationSoundUri; - notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_NO_CLEAR); + if (isMainActivityIsActive) { + notification.flags |= (Notification.FLAG_INSISTENT); + } + } else { + notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR); + } } else { + Timber.d("ZZZZZZ 8"); notification.sound = null; notification.defaults = 0; notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_NO_CLEAR); notification.defaults &= Notification.DEFAULT_VIBRATE; } } + Timber.d("ZZZZZZ 9"); notification.ledARGB = Color.RED; notification.ledOnMS = 300; notification.ledOffMS = 1000; @@ -659,22 +741,22 @@ public class NotificationHelper extends ContextWrapper { // method to handle the old clients with old setup for the notification channels private String handleChannelIdToLatestOne(String id) { - if (id == null) id = Push.getChannelId(Push.DEFAULT_V_01); + if (id == null) id = getChannelId(DEFAULT_V_01); switch (id) { case Push.MESSAGE: - return Push.getChannelId(Push.MESSAGE_V_01); + return getChannelId(MESSAGE_V_01); case Push.DEFAULT: - return Push.getChannelId(Push.DEFAULT_V_01); + return getChannelId(DEFAULT_V_01); case Push.FRIEND: - return Push.getChannelId(Push.FRIEND_V_01); + return getChannelId(FRIEND_V_01); case Push.REQUEST_FRIEND: - return Push.getChannelId(Push.REQUEST_FRIEND_V_01); - case Push.CONFERENCE: - return Push.getChannelId(Push.CONFERENCE_V_01); - case Push.DOWNLOADING: - return Push.getChannelId(Push.DOWNLOADING); - case Push.UPLOADING: - return Push.getChannelId(Push.UPLOADING); + return getChannelId(REQUEST_FRIEND_V_01); + case CONFERENCE: + return getChannelId(CONFERENCE_V_01); + case DOWNLOADING: + return getChannelId(DOWNLOADING); + case UPLOADING: + return getChannelId(UPLOADING); } return id; @@ -706,19 +788,11 @@ public class NotificationHelper extends ContextWrapper { } private String getCallNotificationSoundName( String soundName) { - soundName = soundName == null ? "" : soundName; - if (Consts.NOTIFICATION_SOUND_NO_SOUND.equalsIgnoreCase(soundName)) { - return null; + if (StringUtils.isEmpty(soundName)) { + String basePath = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/"; + return (basePath + R.raw.nynja_ringing); } - - String basePath = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/"; - String name = FileUtils.getFileNameWithoutExt(soundName); - String path = basePath + Consts.NotificationRingingSounds.getIdByName(name); - if (path == null) { - path = basePath + R.raw.nynja_ringing; - } - - return path; + return soundName; } public Uri getCallNotificationSoundUri( String soundName) { @@ -733,14 +807,15 @@ public class NotificationHelper extends ContextWrapper { } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (!manager.areNotificationsEnabled()) { - Timber.i("Push.CALLING: areNotificationsEnabled(): check 2"); + Timber.i("Push.CALLING: areNotificationsEnabled(): check 2: Notifications are NOT enabled!"); return false; } if(StringUtils.isNotEmpty(channelId)) { - Timber.i("Push.CALLING: areNotificationsEnabled(): check 3"); + Timber.i("Push.CALLING: areNotificationsEnabled(): check 3: channelId=%s", channelId); NotificationChannel channel = manager.getNotificationChannel(channelId); if (channel != null) { - Timber.i("Push.CALLING: areNotificationsEnabled(): check 4"); + Timber.i("Push.CALLING: areNotificationsEnabled(): check 4: channel name=%s, id=%s, sound=%s ", + channel.getName(), channel.getId(), channel.getSound().toString()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { Timber.i("Push.CALLING: areNotificationsEnabled(): Importance=" + channel.getImportance()); //return channel.getImportance() >= NotificationManager.IMPORTANCE_HIGH; @@ -749,6 +824,7 @@ public class NotificationHelper extends ContextWrapper { } return channel.getImportance() != NotificationManager.IMPORTANCE_NONE; } + Timber.w("Push.CALLING: areNotificationsEnabled(): channel NOT FOUND OR NOT CREATEDT YET !!!!"); return true; } return false;