From 2c9dab04070e8fcd77a7d54c5f80ff2b804d39fe Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Fri, 29 Jul 2022 15:36:22 -0400 Subject: [PATCH 001/231] Create skeleton API and update app to (partially) integrate with it --- Examples/OneSignalDemo/app/build.gradle | 1 + .../sdktest/activity/MainActivity.java | 14 +- .../adapter/SingleRecyclerViewAdapter.java | 97 +++ .../sdktest/application/MainApplication.java | 82 +-- .../sdktest/callback/EmailUpdateCallback.java | 8 - .../sdktest/callback/SMSUpdateCallback.java | 8 - .../SendOutcomeAlertDialogCallback.java | 4 +- .../callback/SingleItemActionCallback.java | 7 + .../com/onesignal/sdktest/constant/Text.java | 15 +- .../sdktest/model/ActivityViewModel.java | 6 +- .../sdktest/model/MainActivityViewModel.java | 565 ++++++++++++------ .../model/SplashActivityViewModel.java | 92 ++- .../NotificationServiceExtension.java | 28 +- .../OneSignalNotificationSender.java | 30 +- .../onesignal/sdktest/user/CurrentUser.java | 102 ---- .../com/onesignal/sdktest/util/Dialog.java | 299 +-------- .../com/onesignal/sdktest/util/IntentTo.java | 29 +- .../onesignal/sdktest/util/ProfileUtil.java | 18 + .../sdktest/util/SharedPreferenceUtil.java | 18 - .../main/res/layout/activity_secondary.xml | 2 +- .../main/res/layout/main_activity_layout.xml | 240 +++++--- .../single_recycler_view_item_layout.xml | 35 ++ .../app/src/main/res/values/strings.xml | 24 +- OneSignalSDK/build.gradle | 2 +- OneSignalSDK/onesignal/build.gradle | 3 + .../com/onesignal/onesignal/core/Continue.kt | 84 +++ .../onesignal/onesignal/core/IDebugManager.kt | 6 + .../onesignal/onesignal/core/IOneSignal.kt | 124 ++++ .../com/onesignal/onesignal/core/LogLevel.kt | 11 + .../com/onesignal/onesignal/core/OneSignal.kt | 176 ++++++ .../onesignal/core/internal/AppEntryAction.kt | 41 ++ .../onesignal/core/internal/CoreModule.kt | 86 +++ .../onesignal/core/internal/OneSignalImp.kt | 230 +++++++ .../application/IActivityLifecycleHandler.kt | 8 + .../IApplicationLifecycleHandler.kt | 6 + .../application/IApplicationService.kt | 54 ++ .../application/impl/ApplicationService.kt | 319 ++++++++++ .../impl/ISystemConditionHandler.kt | 5 + .../core/internal/backend/api/ApiException.kt | 7 + .../core/internal/backend/api/ApiService.kt | 157 +++++ .../core/internal/backend/api/IApiService.kt | 98 +++ .../core/internal/backend/http/HttpClient.kt | 218 +++++++ .../internal/backend/http/HttpResponse.kt | 23 + .../core/internal/backend/http/IHttpClient.kt | 26 + .../internal/common/AndroidSupportV4Compat.kt | 97 +++ .../core/internal/common/AndroidUtils.kt | 164 +++++ .../core/internal/common/BundleCompat.kt | 179 ++++++ .../core/internal/common/DateUtils.kt | 36 ++ .../core/internal/common/DeviceUtils.kt | 60 ++ .../core/internal/common/JSONUtils.kt | 88 +++ .../core/internal/common/NetworkUtils.kt | 12 + .../core/internal/common/OneSignalUtils.kt | 6 + .../common/RootToolsInternalMethods.kt | 48 ++ .../core/internal/common/TimeUtils.kt | 24 + .../core/internal/common/ViewUtils.kt | 95 +++ .../common/events/CallbackProducer.kt | 31 + .../internal/common/events/EventProducer.kt | 24 + .../common/events/ICallbackNotifier.kt | 30 + .../internal/common/events/IEventNotifier.kt | 41 ++ .../common/exceptions/MainThreadException.kt | 3 + .../core/internal/common/time/ITime.kt | 6 + .../core/internal/common/time/Time.kt | 10 + .../core/internal/database/IDatabase.kt | 32 + .../internal/database/IDatabaseProvider.kt | 5 + .../database/impl/DatabaseProvider.kt | 15 + .../core/internal/database/impl/OSDatabase.kt | 406 +++++++++++++ .../database/impl/OneSignalDbContract.kt | 44 ++ .../core/internal/debug/DebugManager.kt | 15 + .../core/internal/device/IDeviceService.kt | 16 + .../internal/device/impl/DeviceService.kt | 204 +++++++ .../internal/influence/IChannelTracker.kt | 25 + .../internal/influence/IInfluenceManager.kt | 19 + .../core/internal/influence/Influence.kt | 73 +++ .../internal/influence/InfluenceChannel.kt | 18 + .../core/internal/influence/InfluenceType.kt | 26 + .../influence/OSInfluenceConstants.kt | 45 ++ .../internal/influence/impl/ChannelTracker.kt | 169 ++++++ .../impl/IInfluenceDataRepository.kt | 54 ++ .../influence/impl/InAppMessageTracker.kt | 77 +++ .../influence/impl/InfluenceDataRepository.kt | 206 +++++++ .../influence/impl/InfluenceManager.kt | 83 +++ .../influence/impl/NotificationTracker.kt | 65 ++ .../internal/language/ILanguageProvider.kt | 5 + .../internal/language/impl/LanguageContext.kt | 39 ++ .../impl/LanguageProviderAppDefined.kt | 21 + .../language/impl/LanguageProviderDevice.kt | 27 + .../listeners/IdentityModelStoreListener.kt | 23 + .../internal/listeners/ModelStoreListener.kt | 44 ++ .../listeners/PropertiesModelStoreListener.kt | 24 + .../SubscriptionModelStoreListener.kt | 24 + .../core/internal/logging/Logging.kt | 90 +++ .../internal/modeling/IModelChangedHandler.kt | 32 + .../core/internal/modeling/IModelStore.kt | 47 ++ .../modeling/IModelStoreChangeHandler.kt | 31 + .../internal/modeling/ISingletonModelStore.kt | 19 + .../ISingletonModelStoreChangeHandler.kt | 18 + .../onesignal/core/internal/modeling/Model.kt | 41 ++ .../core/internal/modeling/ModelStore.kt | 53 ++ .../internal/modeling/SingletonModelStore.kt | 37 ++ .../core/internal/models/ConfigModel.kt | 61 ++ .../core/internal/models/IdentityModel.kt | 22 + .../core/internal/models/ModelStoreDefs.kt | 10 + .../core/internal/models/PropertiesModel.kt | 29 + .../core/internal/models/SessionModel.kt | 14 + .../core/internal/models/SubscriptionModel.kt | 23 + .../internal/operations/BootstrapOperation.kt | 9 + .../operations/CreateSubscriptionOperation.kt | 12 + .../operations/CreateUserOperation.kt | 6 + .../operations/DeleteSubscriptionOperation.kt | 6 + .../operations/DeleteUserOperation.kt | 6 + .../internal/operations/IOperationRepo.kt | 5 + .../core/internal/operations/Operation.kt | 3 + .../operations/UpdatePropertyOperation.kt | 9 + .../operations/UpdateSubscriptionOperation.kt | 9 + .../operations/UpdateUserOperation.kt | 9 + .../internal/operations/impl/OperationRepo.kt | 65 ++ .../impl/executors/BootstrapExecutor.kt | 220 +++++++ .../impl/executors/IOperationExecutor.kt | 25 + .../executors/PropertyOperationExecutor.kt | 25 + .../SubscriptionOperationExecutor.kt | 118 ++++ .../impl/executors/UserOperationExecutor.kt | 33 + .../outcomes/IOutcomeEventsFactory.kt | 5 + .../outcomes/IOutcomeEventsRepository.kt | 21 + .../internal/outcomes/OutcomeConstants.kt | 26 + .../core/internal/outcomes/OutcomeEvent.kt | 95 +++ .../internal/outcomes/OutcomeEventParams.kt | 32 + .../core/internal/outcomes/OutcomeSource.kt | 34 ++ .../internal/outcomes/OutcomeSourceBody.kt | 21 + .../outcomes/impl/CachedUniqueOutcome.kt | 10 + .../outcomes/impl/IOutcomeEventsBackend.kt | 8 + .../outcomes/impl/IOutcomeEventsCache.kt | 56 ++ .../outcomes/impl/OSOutcomeEventsCache.kt | 332 ++++++++++ .../outcomes/impl/OSOutcomeEventsClient.kt | 9 + .../outcomes/impl/OSOutcomeEventsFactory.kt | 29 + .../impl/OSOutcomeEventsRepository.kt | 47 ++ .../impl/OSOutcomeEventsV1Repository.kt | 62 ++ .../outcomes/impl/OSOutcomeEventsV1Service.kt | 14 + .../impl/OSOutcomeEventsV2Repository.kt | 23 + .../outcomes/impl/OSOutcomeEventsV2Service.kt | 14 + .../outcomes/impl/OSOutcomeTableProvider.kt | 111 ++++ .../outcomes/impl/OSOutcomesDbContract.kt | 84 +++ .../core/internal/params/IParamsService.kt | 113 ++++ .../params/IWriteableParamsService.kt | 26 + .../internal/params/impl/ParamsService.kt | 26 + .../preferences/IPreferencesService.kt | 109 ++++ .../preferences/impl/PreferencesService.kt | 156 +++++ .../internal/service/IBootstrapService.kt | 10 + .../core/internal/service/IServiceBuilder.kt | 58 ++ .../core/internal/service/IServiceProvider.kt | 48 ++ .../internal/service/IStartableService.kt | 10 + .../core/internal/service/ServiceBuilder.kt | 31 + .../core/internal/service/ServiceProvider.kt | 84 +++ .../internal/service/ServiceRegistration.kt | 141 +++++ .../session/ISessionLifecycleHandler.kt | 5 + .../core/internal/session/ISessionService.kt | 7 + .../internal/session/impl/SessionService.kt | 72 +++ .../core/internal/user/UserManager.kt | 316 ++++++++++ .../core/internal/user/aliases/Alias.kt | 12 + .../user/subscriptions/EmailSubscription.kt | 13 + .../user/subscriptions/PushSubscription.kt | 22 + .../user/subscriptions/SmsSubscription.kt | 9 + .../user/subscriptions/Subscription.kt | 15 + .../onesignal/core/internal/user/tags/Tag.kt | 9 + .../core/internal/user/triggers/Trigger.kt | 9 + .../user/IUserIdentityConflictResolver.kt | 10 + .../onesignal/core/user/IUserManager.kt | 215 +++++++ .../user/subscriptions/IEmailSubscription.kt | 12 + .../user/subscriptions/IPushSubscription.kt | 19 + .../user/subscriptions/ISmsSubscription.kt | 14 + .../core/user/subscriptions/ISubscription.kt | 13 + .../user/subscriptions/SubscriptionList.kt | 41 ++ .../onesignal/onesignal/iam/IIAMManager.kt | 33 + .../onesignal/onesignal/iam/IInAppMessage.kt | 34 ++ .../onesignal/iam/IInAppMessageAction.kt | 39 ++ .../iam/IInAppMessageClickHandler.kt | 10 + .../iam/IInAppMessageLifecycleHandler.kt | 36 ++ .../iam/InAppMessageActionUrlType.kt | 28 + .../onesignal/iam/internal/IAMManager.kt | 19 + .../onesignal/iam/internal/IAMModule.kt | 12 + .../onesignal/location/ILocationManager.kt | 24 + .../location/internal/LocationManager.kt | 14 + .../location/internal/LocationModule.kt | 10 + .../notification/BackgroundImageLayout.kt | 7 + .../onesignal/notification/IActionButton.kt | 7 + .../notification/IMutableNotification.kt | 41 ++ .../onesignal/notification/INotification.kt | 51 ++ .../notification/INotificationAction.kt | 49 ++ .../INotificationOpenedHandler.kt | 18 + .../notification/INotificationOpenedResult.kt | 13 + .../INotificationReceivedEvent.kt | 14 + ...NotificationWillShowInForegroundHandler.kt | 15 + .../notification/INotificationsManager.kt | 120 ++++ .../notification/IPermissionChangedHandler.kt | 5 + .../notification/IPermissionState.kt | 5 + .../notification/IPermissionStateChanges.kt | 32 + .../IRemoteNotificationReceivedHandler.kt | 21 + .../internal/NotificationModule.kt | 11 + .../internal/NotificationsManager.kt | 139 +++++ .../notification/internal/PermissionState.kt | 7 + .../internal/common/NotificationConstants.kt | 24 + 200 files changed, 9890 insertions(+), 859 deletions(-) create mode 100644 Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/adapter/SingleRecyclerViewAdapter.java delete mode 100644 Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/EmailUpdateCallback.java delete mode 100644 Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SMSUpdateCallback.java create mode 100644 Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SingleItemActionCallback.java delete mode 100644 Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/user/CurrentUser.java create mode 100644 Examples/OneSignalDemo/app/src/main/res/layout/single_recycler_view_item_layout.xml create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/Continue.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/IDebugManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/IOneSignal.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/LogLevel.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/OneSignal.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/AppEntryAction.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/CoreModule.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/OneSignalImp.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/application/IActivityLifecycleHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/application/IApplicationLifecycleHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/application/IApplicationService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/application/impl/ApplicationService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/application/impl/ISystemConditionHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/backend/api/ApiException.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/backend/api/ApiService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/backend/api/IApiService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/backend/http/HttpClient.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/backend/http/HttpResponse.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/backend/http/IHttpClient.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/AndroidSupportV4Compat.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/AndroidUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/BundleCompat.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/DateUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/DeviceUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/JSONUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/NetworkUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/OneSignalUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/RootToolsInternalMethods.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/TimeUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/ViewUtils.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/events/CallbackProducer.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/events/EventProducer.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/events/ICallbackNotifier.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/events/IEventNotifier.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/exceptions/MainThreadException.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/time/ITime.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/common/time/Time.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/database/IDatabase.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/database/IDatabaseProvider.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/database/impl/DatabaseProvider.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/database/impl/OSDatabase.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/database/impl/OneSignalDbContract.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/debug/DebugManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/device/IDeviceService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/device/impl/DeviceService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/IChannelTracker.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/IInfluenceManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/Influence.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/InfluenceChannel.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/InfluenceType.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/OSInfluenceConstants.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/impl/ChannelTracker.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/impl/IInfluenceDataRepository.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/impl/InAppMessageTracker.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/impl/InfluenceDataRepository.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/impl/InfluenceManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/influence/impl/NotificationTracker.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/language/ILanguageProvider.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/language/impl/LanguageContext.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/language/impl/LanguageProviderAppDefined.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/language/impl/LanguageProviderDevice.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/listeners/IdentityModelStoreListener.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/listeners/ModelStoreListener.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/listeners/PropertiesModelStoreListener.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/listeners/SubscriptionModelStoreListener.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/logging/Logging.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/IModelChangedHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/IModelStore.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/IModelStoreChangeHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/ISingletonModelStore.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/ISingletonModelStoreChangeHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/Model.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/ModelStore.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/modeling/SingletonModelStore.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/models/ConfigModel.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/models/IdentityModel.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/models/ModelStoreDefs.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/models/PropertiesModel.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/models/SessionModel.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/models/SubscriptionModel.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/BootstrapOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/CreateSubscriptionOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/CreateUserOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/DeleteSubscriptionOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/DeleteUserOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/IOperationRepo.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/Operation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/UpdatePropertyOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/UpdateSubscriptionOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/UpdateUserOperation.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/impl/OperationRepo.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/impl/executors/BootstrapExecutor.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/impl/executors/IOperationExecutor.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/impl/executors/PropertyOperationExecutor.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/impl/executors/SubscriptionOperationExecutor.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/operations/impl/executors/UserOperationExecutor.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/IOutcomeEventsFactory.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/IOutcomeEventsRepository.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/OutcomeConstants.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/OutcomeEvent.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/OutcomeEventParams.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/OutcomeSource.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/OutcomeSourceBody.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/CachedUniqueOutcome.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/IOutcomeEventsBackend.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/IOutcomeEventsCache.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsCache.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsClient.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsFactory.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsRepository.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsV1Repository.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsV1Service.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsV2Repository.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeEventsV2Service.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomeTableProvider.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/outcomes/impl/OSOutcomesDbContract.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/params/IParamsService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/params/IWriteableParamsService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/params/impl/ParamsService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/preferences/IPreferencesService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/preferences/impl/PreferencesService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/service/IBootstrapService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/service/IServiceBuilder.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/service/IServiceProvider.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/service/IStartableService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/service/ServiceBuilder.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/service/ServiceProvider.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/service/ServiceRegistration.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/session/ISessionLifecycleHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/session/ISessionService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/session/impl/SessionService.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/UserManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/aliases/Alias.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/subscriptions/EmailSubscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/subscriptions/PushSubscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/subscriptions/SmsSubscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/subscriptions/Subscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/tags/Tag.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/internal/user/triggers/Trigger.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/user/IUserIdentityConflictResolver.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/user/IUserManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/user/subscriptions/IEmailSubscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/user/subscriptions/IPushSubscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/user/subscriptions/ISmsSubscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/user/subscriptions/ISubscription.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/core/user/subscriptions/SubscriptionList.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/IIAMManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/IInAppMessage.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/IInAppMessageAction.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/IInAppMessageClickHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/IInAppMessageLifecycleHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/InAppMessageActionUrlType.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/internal/IAMManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/iam/internal/IAMModule.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/location/ILocationManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/location/internal/LocationManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/location/internal/LocationModule.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/BackgroundImageLayout.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/IActionButton.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/IMutableNotification.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/INotification.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/INotificationAction.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/INotificationOpenedHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/INotificationOpenedResult.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/INotificationReceivedEvent.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/INotificationWillShowInForegroundHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/INotificationsManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/IPermissionChangedHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/IPermissionState.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/IPermissionStateChanges.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/IRemoteNotificationReceivedHandler.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/internal/NotificationModule.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/internal/NotificationsManager.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/internal/PermissionState.kt create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/onesignal/notification/internal/common/NotificationConstants.kt diff --git a/Examples/OneSignalDemo/app/build.gradle b/Examples/OneSignalDemo/app/build.gradle index 04a7bf98e..2cf76baad 100644 --- a/Examples/OneSignalDemo/app/build.gradle +++ b/Examples/OneSignalDemo/app/build.gradle @@ -53,6 +53,7 @@ android { } dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" implementation 'com.android.support:multidex:1.0.3' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.cardview:cardview:1.0.0' diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/activity/MainActivity.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/activity/MainActivity.java index 57794009c..46e48c32a 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/activity/MainActivity.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/activity/MainActivity.java @@ -1,13 +1,16 @@ package com.onesignal.sdktest.activity; +import android.os.Build; import android.os.Bundle; +import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; -import com.onesignal.OneSignal; +import com.onesignal.onesignal.core.OneSignal; import com.onesignal.sdktest.R; import com.onesignal.sdktest.model.MainActivityViewModel; +@RequiresApi(api = Build.VERSION_CODES.N) public class MainActivity extends AppCompatActivity { private MainActivityViewModel viewModel; @@ -18,9 +21,10 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.main_activity_layout); viewModel = new MainActivityViewModel(); - OneSignal.addPermissionObserver(viewModel); - OneSignal.addSubscriptionObserver(viewModel); - OneSignal.addEmailSubscriptionObserver(viewModel); + OneSignal.getNotifications().addPushPermissionHandler(viewModel); +// TODO("STILL SUPPORT?") +// OneSignal.addSubscriptionObserver(viewModel); +// OneSignal.addEmailSubscriptionObserver(viewModel); viewModel.onActivityCreated(this) .setupInterfaceElements(); } @@ -37,7 +41,7 @@ public void onBackPressed() { protected void onResume() { super.onResume(); - boolean hasConsent = OneSignal.userProvidedPrivacyConsent(); + boolean hasConsent = OneSignal.getRequiresPrivacyConsent(); if (hasConsent) viewModel.setupSettingsLayout(); } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/adapter/SingleRecyclerViewAdapter.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/adapter/SingleRecyclerViewAdapter.java new file mode 100644 index 000000000..401dbfe7d --- /dev/null +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/adapter/SingleRecyclerViewAdapter.java @@ -0,0 +1,97 @@ +package com.onesignal.sdktest.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.onesignal.sdktest.R; +import com.onesignal.sdktest.callback.SingleItemActionCallback; +import com.onesignal.sdktest.util.Util; + +import java.util.ArrayList; + +public class SingleRecyclerViewAdapter extends RecyclerView.Adapter { + + private LayoutInflater layoutInflater; + + private Context context; + + private ArrayList values; + private SingleItemActionCallback callback; + + public SingleRecyclerViewAdapter(Context context, ArrayList values, SingleItemActionCallback callback) { + this.context = context; + + this.values = values; + this.callback = callback; + + layoutInflater = LayoutInflater.from(context); + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) { + View view = layoutInflater.inflate(R.layout.single_recycler_view_item_layout, parent, false); + view.setHasTransientState(true); + return new SingleViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + ((SingleViewHolder) holder).setData(position, values.get(position)); + } + + @Override + public int getItemCount() { + return values.size(); + } + + public class SingleViewHolder extends RecyclerView.ViewHolder { + + private RelativeLayout singleRelativeLayout; + private TextView singleTextView; + + private Object item; + + SingleViewHolder(View itemView) { + super(itemView); + + singleRelativeLayout = itemView.findViewById(R.id.single_recycler_view_item_relative_layout); + singleTextView = itemView.findViewById(R.id.single_recycler_view_item_text_view); + } + + private void setData(int position, Object item) { + this.item = item; + populateInterfaceElements(position); + } + + private void populateInterfaceElements(final int position) { + String value = item.toString(); + + if (Util.isBoolean(value)) + value += " (bool)"; + else if (Util.isNumeric(value)) + value += " (num)"; + else + value += " (str)"; + singleTextView.setText(value); + + singleRelativeLayout.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + callback.onLongClick(item.toString()); + return false; + } + }); + + } + + } + +} diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/application/MainApplication.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/application/MainApplication.java index 3005e7e0e..4b7b064a3 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/application/MainApplication.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/application/MainApplication.java @@ -2,12 +2,15 @@ import android.util.Log; +import androidx.annotation.NonNull; import androidx.multidex.MultiDexApplication; -import com.onesignal.OSInAppMessage; -import com.onesignal.OSNotification; -import com.onesignal.OSInAppMessageLifecycleHandler; -import com.onesignal.OneSignal; +import com.onesignal.onesignal.core.OneSignal; +import com.onesignal.onesignal.iam.IInAppMessage; +import com.onesignal.onesignal.iam.IInAppMessageLifecycleHandler; +import com.onesignal.onesignal.core.LogLevel; +import com.onesignal.onesignal.core.internal.logging.Logging; +import com.onesignal.onesignal.notification.INotification; import com.onesignal.sdktest.R; import com.onesignal.sdktest.constant.Tag; import com.onesignal.sdktest.constant.Text; @@ -21,28 +24,7 @@ public class MainApplication extends MultiDexApplication { public void onCreate() { super.onCreate(); - OSInAppMessageLifecycleHandler handler = new OSInAppMessageLifecycleHandler() { - @Override - public void onWillDisplayInAppMessage(OSInAppMessage message) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "MainApplication onWillDisplayInAppMessage"); - } - @Override - public void onDidDisplayInAppMessage(OSInAppMessage message) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "MainApplication onDidDisplayInAppMessage"); - } - @Override - public void onWillDismissInAppMessage(OSInAppMessage message) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "MainApplication onWillDismissInAppMessage"); - } - @Override - public void onDidDismissInAppMessage(OSInAppMessage message) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "MainApplication onDidDismissInAppMessage"); - } - }; - - OneSignal.setInAppMessageLifecycleHandler(handler); - - OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE); + Logging.setLogLevel(LogLevel.DEBUG); // OneSignal Initialization String appId = SharedPreferenceUtil.getOneSignalAppId(this); @@ -51,25 +33,51 @@ public void onDidDismissInAppMessage(OSInAppMessage message) { appId = getString(R.string.onesignal_app_id); SharedPreferenceUtil.cacheOneSignalAppId(this, appId); } + OneSignal.setAppId(appId); OneSignal.initWithContext(this); - OneSignal.setNotificationOpenedHandler(result -> - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "OSNotificationOpenedResult result: " + result.toString())); + OneSignal.getIam().setInAppMessageLifecycleHandler(new IInAppMessageLifecycleHandler() { + @Override + public void onWillDisplayInAppMessage(@NonNull IInAppMessage message) { + Logging.log(LogLevel.VERBOSE, "MainApplication onWillDisplayInAppMessage"); + } - OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent -> { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "NotificationWillShowInForegroundHandler fired!" + - " with notification event: " + notificationReceivedEvent.toString()); + @Override + public void onDidDisplayInAppMessage(@NonNull IInAppMessage message) { + Logging.log(LogLevel.VERBOSE, "MainApplication onDidDisplayInAppMessage"); + } - OSNotification notification = notificationReceivedEvent.getNotification(); - JSONObject data = notification.getAdditionalData(); + @Override + public void onWillDismissInAppMessage(@NonNull IInAppMessage message) { + Logging.log(LogLevel.VERBOSE, "MainApplication onWillDismissInAppMessage"); + } - notificationReceivedEvent.complete(notification); + @Override + public void onDidDismissInAppMessage(@NonNull IInAppMessage message) { + Logging.log(LogLevel.VERBOSE, "MainApplication onDidDismissInAppMessage"); + } }); - OneSignal.unsubscribeWhenNotificationsAreDisabled(true); - OneSignal.pauseInAppMessages(true); - OneSignal.setLocationShared(false); + OneSignal.getNotifications().setNotificationOpenedHandler(result -> + { + Logging.log(LogLevel.VERBOSE, "INotificationOpenedResult: " + result.toString()); + }); + + OneSignal.getNotifications().setNotificationWillShowInForegroundHandler(notificationReceivedEvent -> + { + Logging.log(LogLevel.VERBOSE, "NotificationWillShowInForegroundHandler fired!" + + " with notification event: " + notificationReceivedEvent.toString()); + + INotification notification = notificationReceivedEvent.getNotification(); + JSONObject data = notification.getAdditionalData(); + + notificationReceivedEvent.complete(notification); + }); + + OneSignal.getNotifications().setUnsubscribeWhenNotificationsAreDisabled(true); + OneSignal.getIam().setPaused(true); + OneSignal.getLocation().setLocationShared(false); Log.d(Tag.DEBUG, Text.ONESIGNAL_SDK_INIT); } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/EmailUpdateCallback.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/EmailUpdateCallback.java deleted file mode 100644 index d26382e9a..000000000 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/EmailUpdateCallback.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.onesignal.sdktest.callback; - -public interface EmailUpdateCallback { - - void onSuccess(); - void onFailure(); - -} diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SMSUpdateCallback.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SMSUpdateCallback.java deleted file mode 100644 index f99dfe633..000000000 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SMSUpdateCallback.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.onesignal.sdktest.callback; - -public interface SMSUpdateCallback { - - void onSuccess(); - void onFailure(); - -} diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SendOutcomeAlertDialogCallback.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SendOutcomeAlertDialogCallback.java index 7fe4b5aa8..e66ef198e 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SendOutcomeAlertDialogCallback.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SendOutcomeAlertDialogCallback.java @@ -1,10 +1,10 @@ package com.onesignal.sdktest.callback; -import android.util.Pair; +import com.onesignal.sdktest.type.OutcomeEvent; public interface SendOutcomeAlertDialogCallback { - void onSuccess(); + boolean onSuccess(OutcomeEvent outcomeEvent, String name, String value); void onFailure(); } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SingleItemActionCallback.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SingleItemActionCallback.java new file mode 100644 index 000000000..ea38662ef --- /dev/null +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/callback/SingleItemActionCallback.java @@ -0,0 +1,7 @@ +package com.onesignal.sdktest.callback; + +public interface SingleItemActionCallback { + + void onLongClick(String value); + +} diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/constant/Text.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/constant/Text.java index 50e04d0b3..c42c9199d 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/constant/Text.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/constant/Text.java @@ -5,29 +5,19 @@ public class Text { public static final String EMPTY = ""; public static final String ONESIGNAL_SDK_INIT = "OneSignal SDK initialized"; - public static final String SUBSCRIPTION_STATUS_SET = "Subscription status set"; public static final String PRIVACY_CONSENT_REQUIRED_SET = "Privacy consent required set"; - public static final String EMAIL_SET_SUCCESSFULLY = "Email set successfully"; - public static final String EMAIL_SET_FAILURE = "Email set failure"; - - public static final String SMS_SET_SUCCESSFULLY = "SMS Number set successfully"; - public static final String SMS_SET_FAILURE = "SMS Number set failure"; - public static final String APP_ID_IS_REQUIRED = "App id is required"; public static final String INVALID_APP_ID = "Invalid app id"; + public static final String ALIAS_LABEL_IS_REQUIRED = "Alias label is required"; + public static final String EMAIL_IS_REQUIRED = "Email is required"; public static final String INVALID_EMAIL = "Invalid email"; public static final String SMS_IS_REQUIRED = "SMS number is required"; - public static final String EMAIL_NOT_SET = "Email not set"; - public static final String SMS_NOT_SET = "SMS Number not set"; - public static final String EXTERNAL_USER_ID_NOT_SET = "External user id not set"; - public static final String EXTERNAL_USER_ID_IS_REQUIRED = "External user id is required"; - public static final String INVALID_EXTERNAL_USER_ID = "Invalid external user id"; public static final String KEY_IS_REQUIRED = "Key is required"; @@ -36,6 +26,7 @@ public class Text { public static final String BUTTON_ADD = "ADD"; public static final String BUTTON_SEND = "SEND"; public static final String BUTTON_UPDATE = "UPDATE"; + public static final String BUTTON_SWITCH = "SWITCH"; public static final String BUTTON_CANCEL = "CANCEL"; } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/ActivityViewModel.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/ActivityViewModel.java index 8336cf2ff..052f01993 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/ActivityViewModel.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/ActivityViewModel.java @@ -4,15 +4,13 @@ import android.content.Context; import androidx.appcompat.app.AppCompatActivity; -import com.onesignal.OSEmailSubscriptionObserver; -import com.onesignal.OSPermissionObserver; -import com.onesignal.OSSubscriptionObserver; +import com.onesignal.onesignal.notification.IPermissionChangedHandler; /** * This is the interface created with a few generic methods for setting a ViewModel * as the responsible guardian of an Activity */ -public interface ActivityViewModel extends OSPermissionObserver, OSSubscriptionObserver, OSEmailSubscriptionObserver { +public interface ActivityViewModel extends IPermissionChangedHandler { // TODO() extends OSPermissionObserver, OSSubscriptionObserver, OSEmailSubscriptionObserver { /** * Casts Context of the given Activity to an Activity object diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java index b4e0721ec..4d781e431 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java @@ -3,6 +3,9 @@ import android.app.Activity; import android.content.Context; import com.google.android.material.appbar.AppBarLayout; + +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import androidx.core.widget.NestedScrollView; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.GridLayoutManager; @@ -11,6 +14,7 @@ import androidx.appcompat.widget.Toolbar; import android.content.Intent; +import android.os.Build; import android.util.Pair; import android.view.View; import android.view.ViewTreeObserver; @@ -21,25 +25,28 @@ import android.widget.Switch; import android.widget.TextView; -import com.onesignal.OSDeviceState; -import com.onesignal.OSEmailSubscriptionStateChanges; -import com.onesignal.OSPermissionStateChanges; -import com.onesignal.OSSubscriptionStateChanges; -import com.onesignal.OneSignal; +import com.onesignal.onesignal.core.Continue; +import com.onesignal.onesignal.core.OneSignal; +import com.onesignal.onesignal.notification.IPermissionStateChanges; +import com.onesignal.onesignal.core.user.subscriptions.IEmailSubscription; +import com.onesignal.onesignal.core.user.subscriptions.IPushSubscription; +import com.onesignal.onesignal.core.user.subscriptions.ISmsSubscription; import com.onesignal.sdktest.R; import com.onesignal.sdktest.activity.SecondaryActivity; import com.onesignal.sdktest.adapter.InAppMessageRecyclerViewAdapter; import com.onesignal.sdktest.adapter.NotificationRecyclerViewAdapter; import com.onesignal.sdktest.adapter.PairRecyclerViewAdapter; +import com.onesignal.sdktest.adapter.SingleRecyclerViewAdapter; import com.onesignal.sdktest.callback.AddPairAlertDialogCallback; import com.onesignal.sdktest.callback.PairItemActionCallback; +import com.onesignal.sdktest.callback.SendOutcomeAlertDialogCallback; import com.onesignal.sdktest.callback.UpdateAlertDialogCallback; import com.onesignal.sdktest.constant.Text; import com.onesignal.sdktest.type.InAppMessage; import com.onesignal.sdktest.type.Notification; +import com.onesignal.sdktest.type.OutcomeEvent; import com.onesignal.sdktest.type.ToastType; import com.onesignal.sdktest.ui.RecyclerViewBuilder; -import com.onesignal.sdktest.user.CurrentUser; import com.onesignal.sdktest.util.Animate; import com.onesignal.sdktest.util.Dialog; import com.onesignal.sdktest.util.Font; @@ -48,18 +55,15 @@ import com.onesignal.sdktest.util.ProfileUtil; import com.onesignal.sdktest.util.Toaster; -import org.json.JSONException; -import org.json.JSONObject; - import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Map; +@RequiresApi(api = Build.VERSION_CODES.N) public class MainActivityViewModel implements ActivityViewModel { private Animate animate; - private CurrentUser currentUser; private Dialog dialog; private Font font; private IntentTo intentTo; @@ -81,30 +85,39 @@ public class MainActivityViewModel implements ActivityViewModel { private RelativeLayout appIdRelativeLayout; private TextView appIdTitleTextView; private TextView appIdTextView; + private Button switchUserButton; + + // Alias + private TextView aliasTitleTextView; + private RelativeLayout externalUserIdRelativeLayout; + private TextView externalUserIdTitleTextView; + private TextView userExternalUserIdTextView; + private RecyclerView aliasesRecyclerView; + private PairRecyclerViewAdapter aliasesRecyclerViewAdapter; + private TextView noAliasesTextView; + private Button addAliasButton; + // Email - private RelativeLayout emailRelativeLayout; private TextView emailHeaderTextView; - private TextView emailTitleTextView; - private TextView userEmailTextView; - private Button logoutEmailButton; + private TextView noEmailsTextView; + private Button addEmailButton; // SMS - private RelativeLayout smsRelativeLayout; private TextView smsHeaderTextView; - private TextView smsTitleTextView; - private TextView userSMSTextView; - private Button logoutSMSButton; - - // External User Id - private RelativeLayout externalUserIdRelativeLayout; - private TextView externalUserIdTitleTextView; - private TextView userExternalUserIdTextView; + private TextView noSmssTextView; + private Button addSMSButton; // Tags private TextView tagsTitleTextView; private TextView noTagsTextView; private RecyclerView tagsRecyclerView; private PairRecyclerViewAdapter tagPairRecyclerViewAdapter; + + private RecyclerView emailsRecyclerView; + private SingleRecyclerViewAdapter emailsRecyclerViewAdapter; + private RecyclerView smssRecyclerView; + private SingleRecyclerViewAdapter smssRecyclerViewAdapter; + private Button addTagButton; // Notification Demo @@ -152,6 +165,11 @@ public class MainActivityViewModel implements ActivityViewModel { private Context context; + private HashMap aliasSet; + private ArrayList aliasArrayList; + private ArrayList emailArrayList; + private ArrayList smsArrayList; + private HashMap tagSet; private ArrayList tagArrayList; @@ -173,7 +191,6 @@ public ActivityViewModel onActivityCreated(Context context) { this.context = context; animate = new Animate(); - currentUser = CurrentUser.getInstance(); dialog = new Dialog(context); font = new Font(context); intentTo = new IntentTo(context); @@ -193,22 +210,25 @@ public ActivityViewModel onActivityCreated(Context context) { appIdRelativeLayout = getActivity().findViewById(R.id.main_activity_account_details_app_id_relative_layout); appIdTitleTextView = getActivity().findViewById(R.id.main_activity_account_details_app_id_title_text_view); appIdTextView = getActivity().findViewById(R.id.main_activity_account_details_app_id_text_view); + switchUserButton = getActivity().findViewById(R.id.main_activity_switch_user_button); - emailHeaderTextView = getActivity().findViewById(R.id.main_activity_email_title_text_view); - emailRelativeLayout = getActivity().findViewById(R.id.main_activity_account_details_email_relative_layout); - emailTitleTextView = getActivity().findViewById(R.id.main_activity_account_details_email_text_view); - userEmailTextView = getActivity().findViewById(R.id.main_activity_account_details_user_email_text_view); - logoutEmailButton = getActivity().findViewById(R.id.main_activity_email_logout_email_button); - - smsHeaderTextView = getActivity().findViewById(R.id.main_activity_sms_title_text_view); - smsRelativeLayout = getActivity().findViewById(R.id.main_activity_account_details_sms_relative_layout); - smsTitleTextView = getActivity().findViewById(R.id.main_activity_account_details_sms_text_view); - userSMSTextView = getActivity().findViewById(R.id.main_activity_account_details_user_sms_text_view); - logoutSMSButton = getActivity().findViewById(R.id.main_activity_sms_logout_sms_button); - + aliasTitleTextView = getActivity().findViewById(R.id.main_activity_aliases_title_text_view); externalUserIdRelativeLayout = getActivity().findViewById(R.id.main_activity_account_details_external_user_id_relative_layout); externalUserIdTitleTextView = getActivity().findViewById(R.id.main_activity_account_details_external_user_id_text_view); userExternalUserIdTextView = getActivity().findViewById(R.id.main_activity_account_details_user_external_user_id_text_view); + noAliasesTextView = getActivity().findViewById(R.id.main_activity_aliases_no_aliases_text_view); + addAliasButton = getActivity().findViewById(R.id.main_activity_add_alias_button); + aliasesRecyclerView = getActivity().findViewById(R.id.main_activity_aliases_recycler_view); + + emailHeaderTextView = getActivity().findViewById(R.id.main_activity_email_title_text_view); + noEmailsTextView = getActivity().findViewById(R.id.main_activity_emails_no_emails_text_view); + addEmailButton = getActivity().findViewById(R.id.main_activity_add_email_button); + emailsRecyclerView = getActivity().findViewById(R.id.main_activity_emails_recycler_view); + + smsHeaderTextView = getActivity().findViewById(R.id.main_activity_sms_title_text_view); + noSmssTextView = getActivity().findViewById(R.id.main_activity_smss_no_smss_text_view); + addSMSButton = getActivity().findViewById(R.id.main_activity_add_sms_button); + smssRecyclerView = getActivity().findViewById(R.id.main_activity_smss_recycler_view); tagsTitleTextView = getActivity().findViewById(R.id.main_activity_tags_title_text_view); noTagsTextView = getActivity().findViewById(R.id.main_activity_tags_no_tags_text_view); @@ -251,6 +271,13 @@ public ActivityViewModel onActivityCreated(Context context) { navigateNextActivity.setOnClickListener(v -> { getActivity().startActivity(new Intent(getActivity(), SecondaryActivity.class)); }); + + aliasSet = new HashMap<>(); + aliasArrayList = new ArrayList<>(); + + emailArrayList = new ArrayList<>(); + smsArrayList = new ArrayList<>(); + tagSet = new HashMap<>(); tagArrayList = new ArrayList<>(); @@ -268,12 +295,13 @@ public ActivityViewModel setupInterfaceElements() { font.applyFont(privacyConsentAllowButton, font.saralaBold); font.applyFont(appIdTitleTextView, font.saralaBold); font.applyFont(appIdTextView, font.saralaRegular); + font.applyFont(switchUserButton, font.saralaBold); + font.applyFont(aliasTitleTextView, font.saralaBold); + font.applyFont(noAliasesTextView, font.saralaBold); font.applyFont(emailHeaderTextView, font.saralaBold); - font.applyFont(emailTitleTextView, font.saralaBold); - font.applyFont(userEmailTextView, font.saralaRegular); + font.applyFont(noEmailsTextView, font.saralaBold); font.applyFont(smsHeaderTextView, font.saralaBold); - font.applyFont(smsTitleTextView, font.saralaBold); - font.applyFont(userSMSTextView, font.saralaRegular); + font.applyFont(noSmssTextView, font.saralaBold); font.applyFont(externalUserIdTitleTextView, font.saralaBold); font.applyFont(userExternalUserIdTextView, font.saralaRegular); font.applyFont(tagsTitleTextView, font.saralaBold); @@ -323,26 +351,22 @@ public void networkDisconnected() { } @Override - public void onOSEmailSubscriptionChanged(OSEmailSubscriptionStateChanges stateChanges) { - - } - - @Override - public void onOSPermissionChanged(OSPermissionStateChanges stateChanges) { - OSDeviceState deviceState = OneSignal.getDeviceState(); - final boolean isSubscribed = deviceState != null && deviceState.isSubscribed(); + public void onPermissionChanged(@Nullable IPermissionStateChanges stateChanges) { + boolean isSubscribed = OneSignal.getUser().getSubscriptions().getPush() != null; + boolean isPermissionEnabled = stateChanges.getTo().getNotificationsEnabled(); - boolean isPermissionEnabled = stateChanges.getTo().areNotificationsEnabled(); subscriptionSwitch.setEnabled(isPermissionEnabled); subscriptionSwitch.setChecked(isSubscribed); } - @Override - public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) { - boolean isSubscribed = stateChanges.getTo().isSubscribed(); - subscriptionSwitch.setChecked(isSubscribed); - SharedPreferenceUtil.cacheLocationSharedStatus(context, isSubscribed); - } + // TODO() +// +// @Override +// public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) { +// boolean isSubscribed = stateChanges.getTo().isSubscribed(); +// subscriptionSwitch.setChecked(isSubscribed); +// SharedPreferenceUtil.cacheLocationSharedStatus(context, isSubscribed); +// } private void setupConsentLayout(boolean hasConsent) { int consentVisibility = hasConsent ? View.GONE : View.VISIBLE; @@ -360,6 +384,9 @@ private void setupConsentLayout(boolean hasConsent) { private void postPrivacyConsentSetup() { setupScrollView(); setupAppLayout(); + setupAliasLayout(); + setupEmailLayout(); + setupSMSLayout(); setupTagsLayout(); setupPushNotificationLayout(); setupOutcomeLayout(); @@ -367,6 +394,8 @@ private void postPrivacyConsentSetup() { setupInAppMessagingLayout(); setupLocationLayout(); setupSettingsLayout(); + + refreshState(); } private void setupScrollView() { @@ -380,122 +409,162 @@ public void onScrollChanged() { } private void setupAppLayout() { - appIdTextView.setText(getOneSignalAppId()); - appIdRelativeLayout.setOnClickListener(new View.OnClickListener() { + appIdRelativeLayout.setOnClickListener(v -> dialog.createUpdateAlertDialog(getOneSignalAppId(), Dialog.DialogAction.UPDATE, ProfileUtil.FieldType.APP_ID, new UpdateAlertDialogCallback() { @Override - public void onClick(View v) { - dialog.createUpdateAlertDialog(getOneSignalAppId(), ProfileUtil.FieldType.APP_ID, new UpdateAlertDialogCallback() { - @Override - public void onSuccess(String update) { - appIdTextView.setText(update); - SharedPreferenceUtil.cacheOneSignalAppId(getActivity(), update); - intentTo.resetApplication(); - } + public void onSuccess(String update) { + OneSignal.setAppId(update); + appIdTextView.setText(update); + SharedPreferenceUtil.cacheOneSignalAppId(getActivity(), update); + // TODO: Shouldn't need to do this anymore intentTo.resetApplication(); + } - @Override - public void onFailure() { + @Override + public void onFailure() { - } - }); } - }); + })); - setupEmailButton(); - setupSMSButton(); - setupExternalUserIdButton(); + switchUserButton.setOnClickListener(v -> dialog.createUpdateAlertDialog(OneSignal.getUser().getExternalId(), Dialog.DialogAction.SWITCH, ProfileUtil.FieldType.EXTERNAL_USER_ID, new UpdateAlertDialogCallback() { + @Override + public void onSuccess(String update) { + if(update == null || update.isEmpty()) { + OneSignal.loginGuest(Continue.with(r -> refreshState())); + } + else { + OneSignal.login(update, Continue.with(r -> refreshState())); + } + } + + @Override + public void onFailure() { + + } + })); } - private void setupEmailButton() { - boolean isEmailSet = currentUser.isEmailSet(); - String email = isEmailSet ? currentUser.getEmail() : Text.EMAIL_NOT_SET; - userEmailTextView.setText(email); + private void setupAliasLayout() { + setupAliasesRecyclerView(); + addAliasButton.setOnClickListener(v -> dialog.createAddPairAlertDialog("Add Alias", ProfileUtil.FieldType.ALIAS, new AddPairAlertDialogCallback() { + @Override + public void onSuccess(Pair pair) { + if (pair.second == null || pair.second.toString().isEmpty()) { + OneSignal.getUser().removeAlias(pair.first); + aliasSet.remove(pair.first); + toaster.makeCustomViewToast("Deleted alias " + pair.first, ToastType.SUCCESS); + } else { + OneSignal.getUser().addAlias(pair.first, pair.second.toString()); + aliasSet.put(pair.first, pair.second); + toaster.makeCustomViewToast("Added alias " + pair.first, ToastType.SUCCESS); + } + + refreshAliasRecyclerView(); + } - emailRelativeLayout.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { - dialog.createUpdateAlertDialog(currentUser.getEmail(), ProfileUtil.FieldType.EMAIL, new UpdateAlertDialogCallback() { - @Override - public void onSuccess(String update) { - userEmailTextView.setText(update); - } + public void onFailure() { + refreshAliasRecyclerView(); + } + })); - @Override - public void onFailure() { + setupExternalUserIdButton(); + } - } - }); + private void setupAliasesRecyclerView() { + recyclerViewBuilder.setupRecyclerView(aliasesRecyclerView, 20, false, true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); + aliasesRecyclerView.setLayoutManager(linearLayoutManager); + aliasesRecyclerViewAdapter = new PairRecyclerViewAdapter(context, aliasArrayList, new PairItemActionCallback() { + @Override + public void onLongClick(String key) { + OneSignal.getUser().removeAlias(key); + aliasSet.remove(key); + refreshAliasRecyclerView(); + toaster.makeCustomViewToast("Deleted alias " + key, ToastType.SUCCESS); } }); + aliasesRecyclerView.setAdapter(aliasesRecyclerViewAdapter); + } - logoutEmailButton.setOnClickListener(new View.OnClickListener() { + private void refreshAliasRecyclerView() { + getActivity().runOnUiThread(new Runnable() { @Override - public void onClick(View v) { - OneSignal.logoutEmail(new OneSignal.EmailUpdateHandler() { - @Override - public void onSuccess() { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "Logout email ended successfully"); - MainActivityViewModel.this.getActivity().runOnUiThread(() -> userEmailTextView.setText("")); - } + public void run() { + aliasArrayList.clear(); + aliasArrayList.addAll(aliasSet.entrySet()); - @Override - public void onFailure(OneSignal.EmailUpdateError error) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "Logout email failed with error: " + error); - } - }); + if (aliasArrayList.size() > 0) { + animate.toggleAnimationView(false, View.GONE, aliasesRecyclerView, noAliasesTextView); + } else { + animate.toggleAnimationView(true, View.GONE, aliasesRecyclerView, noAliasesTextView); + } + + aliasesRecyclerViewAdapter.notifyDataSetChanged(); } }); } - private void setupSMSButton() { - boolean isSMSNumberSet = currentUser.isSMSNumberSet(); - String smsNumber = isSMSNumberSet ? currentUser.getSMSNumber() : Text.SMS_NOT_SET; - userSMSTextView.setText(smsNumber); - - smsRelativeLayout.setOnClickListener(v -> dialog.createUpdateAlertDialog(currentUser.getSMSNumber(), ProfileUtil.FieldType.SMS, new UpdateAlertDialogCallback() { + private void setupExternalUserIdButton() { + // TODO: Can no longer set external ID after the fact +// externalUserIdRelativeLayout.setOnClickListener(v -> { +// String externalUserId2 = getExternalUserIdFromOS(); +// userExternalUserIdTextView.setText(externalUserId2 == null ? "" : externalUserId2); +// +// dialog.createUpdateAlertDialog(externalUserId2, Dialog.DialogAction.UPDATE, ProfileUtil.FieldType.EXTERNAL_USER_ID, new UpdateAlertDialogCallback() { +// @Override +// public void onSuccess(String externalUserId) { +// OneSignal.getUser().setExternalId(externalUserId); +// userExternalUserIdTextView.setText(externalUserId); +// SharedPreferenceUtil.cacheUserExternalUserId(context, externalUserId); +// } +// +// @Override +// public void onFailure() { +// +// } +// }); +// }); + } + + private void setupEmailLayout() { + setupEmailRecyclerView(); + + addEmailButton.setOnClickListener(v -> dialog.createUpdateAlertDialog("", Dialog.DialogAction.ADD, ProfileUtil.FieldType.EMAIL, new UpdateAlertDialogCallback() { @Override - public void onSuccess(String update) { - userSMSTextView.setText(update); + public void onSuccess(String value) { + if (value != null && !value.isEmpty()) { + OneSignal.getUser().addEmailSubscription(value.toString()); + emailArrayList.add(value); + toaster.makeCustomViewToast("Added email " + value, ToastType.SUCCESS); + } + + refreshEmailRecyclerView(); } @Override public void onFailure() { - + refreshEmailRecyclerView(); } })); - - logoutSMSButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - OneSignal.logoutSMSNumber(new OneSignal.OSSMSUpdateHandler() { - @Override - public void onSuccess(JSONObject result) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "Logout SMS ended successfully, result: " + result); - MainActivityViewModel.this.getActivity().runOnUiThread(() -> userSMSTextView.setText("")); - } - - @Override - public void onFailure(OneSignal.OSSMSUpdateError error) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "Logout SMS failed with error: " + error); - } - }); - } - }); } - private void setupExternalUserIdButton() { - boolean isExternalUserSet = currentUser.isExternalUserIdSet(context); - String externalUserId = isExternalUserSet ? currentUser.getExternalUserId(context) : Text.EXTERNAL_USER_ID_NOT_SET; - userExternalUserIdTextView.setText(externalUserId); + private void setupSMSLayout() { + setupSMSRecyclerView(); - externalUserIdRelativeLayout.setOnClickListener(v -> dialog.createUpdateAlertDialog(currentUser.getExternalUserId(context), ProfileUtil.FieldType.EXTERNAL_USER_ID, new UpdateAlertDialogCallback() { + addSMSButton.setOnClickListener(v -> dialog.createUpdateAlertDialog("", Dialog.DialogAction.ADD, ProfileUtil.FieldType.SMS, new UpdateAlertDialogCallback() { @Override - public void onSuccess(String update) { - userExternalUserIdTextView.setText(update); + public void onSuccess(String value) { + if (value != null && !value.isEmpty()) { + OneSignal.getUser().addSmsSubscription(value); + smsArrayList.add(value); + toaster.makeCustomViewToast("Added SMS " + value, ToastType.SUCCESS); + } + + refreshSMSRecyclerView(); } @Override public void onFailure() { - + refreshSMSRecyclerView(); } })); } @@ -506,13 +575,10 @@ private void setupLocationLayout() { } private void setupLocationSharedSwitch() { - locationSharedRelativeLayout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - boolean isLocationShared = !locationSharedSwitch.isChecked(); - locationSharedSwitch.setChecked(isLocationShared); - SharedPreferenceUtil.cacheLocationSharedStatus(context, isLocationShared); - } + locationSharedRelativeLayout.setOnClickListener(v -> { + boolean isLocationShared = !locationSharedSwitch.isChecked(); + locationSharedSwitch.setChecked(isLocationShared); + SharedPreferenceUtil.cacheLocationSharedStatus(context, isLocationShared); }); boolean isLocationShared = SharedPreferenceUtil.getCachedLocationSharedStatus(context); @@ -521,17 +587,14 @@ public void onClick(View v) { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SharedPreferenceUtil.cacheLocationSharedStatus(context, isChecked); - OneSignal.setLocationShared(isChecked); + OneSignal.getLocation().setLocationShared(isChecked); } }); } private void setupPromptLocationButton() { - promptLocationButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - OneSignal.promptLocation(); - } + promptLocationButton.setOnClickListener(v -> { + OneSignal.getLocation().requestPermission(Continue.none()); }); } @@ -542,34 +605,32 @@ public void setupSettingsLayout() { } private void setupSubscriptionSwitch() { - OSDeviceState deviceState = OneSignal.getDeviceState(); - boolean isPermissionEnabled = deviceState != null && deviceState.areNotificationsEnabled(); - final boolean isSubscribed = deviceState != null && deviceState.isSubscribed(); + boolean isPermissionEnabled = OneSignal.getNotifications().getPermissionStatus().getNotificationsEnabled(); + boolean isSubscribed = OneSignal.getUser().getSubscriptions().getPush() != null; + subscriptionSwitch.setEnabled(isPermissionEnabled); subscriptionSwitch.setChecked(isSubscribed); - if (isPermissionEnabled) { - subscriptionRelativeLayout.setOnClickListener(v -> { - boolean isSubscribed1 = subscriptionSwitch.isChecked(); - subscriptionSwitch.setChecked(!isSubscribed1); - OneSignal.disablePush(isSubscribed1); - }); - } else { - subscriptionRelativeLayout.setOnClickListener(v -> intentTo.notificationPermissions()); - } + // Add a listener to try to enable push notifications if currently disabled. + subscriptionRelativeLayout.setOnClickListener(v -> { + boolean isPermissionEnabled1 = OneSignal.getNotifications().getPermissionStatus().getNotificationsEnabled(); + if(!isPermissionEnabled1) { + OneSignal.getNotifications().requestPermission(Continue.with(r -> { + // TODO: I think this will fire the change listener, which handles this code so might + // not need to do anything here? + if(r.isSuccess()) { + subscriptionSwitch.setEnabled(r.getData()); + } + })); + } + }); + // Add a listener to toggle the push notification enablement for the current user. The assumption is this + // can only fire if the subscription switch is enabled (push notifications are enabled). subscriptionSwitch.setOnClickListener(v -> { - OneSignal.disablePush(!subscriptionSwitch.isChecked()); - if (subscriptionSwitch.isChecked()) { - OneSignal.promptForPushNotifications( - true, - new OneSignal.PromptForPushNotificationPermissionResponseHandler() { - @Override - public void response(boolean accepted) { - System.out.println("APP promptForPushNotifications:" + this + ":accepted: " + accepted); - } - } - ); + IPushSubscription subscription = OneSignal.getUser().getSubscriptions().getPush(); + if (subscription != null) { + subscription.setEnabled(subscriptionSwitch.isChecked()); } }); } @@ -582,7 +643,7 @@ private void setupPauseInAppMessagesSwitch() { pauseInAppMessagesSwitch.setChecked(SharedPreferenceUtil.getCachedInAppMessagingPausedStatus(context)); pauseInAppMessagesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - OneSignal.pauseInAppMessages(isChecked); + OneSignal.getIam().setPaused(isChecked); SharedPreferenceUtil.cacheInAppMessagingPausedStatus(context, isChecked); }); } @@ -596,31 +657,15 @@ private void setupTagsLayout() { setupTagRecyclerView(); - OneSignal.getTags(tags -> { - if (tags == null || tags.toString().isEmpty()) - return; - - try { - for (Iterator it = tags.keys(); it.hasNext();) { - String key = it.next(); - tagSet.put(key, tags.get(key)); - } - - refreshTagRecyclerView(); - - } catch (JSONException e) { - e.printStackTrace(); - } - }); - addTagButton.setOnClickListener(v -> dialog.createAddPairAlertDialog("Add Tag", ProfileUtil.FieldType.TAG, new AddPairAlertDialogCallback() { @Override public void onSuccess(Pair pair) { if (pair.second == null || pair.second.toString().isEmpty()) { - OneSignal.deleteTag(pair.first); + OneSignal.getUser().removeTag(pair.first); tagSet.remove(pair.first); toaster.makeCustomViewToast("Deleted tag " + pair.first, ToastType.SUCCESS); } else { + OneSignal.getUser().setTag(pair.first, pair.second.toString()); tagSet.put(pair.first, pair.second); toaster.makeCustomViewToast("Added tag " + pair.first, ToastType.SUCCESS); } @@ -642,11 +687,9 @@ private void setupTagRecyclerView() { tagPairRecyclerViewAdapter = new PairRecyclerViewAdapter(context, tagArrayList, new PairItemActionCallback() { @Override public void onLongClick(String key) { - OneSignal.deleteTag(key); + OneSignal.getUser().removeTag(key); tagSet.remove(key); - refreshTagRecyclerView(); - toaster.makeCustomViewToast("Deleted tag " + key, ToastType.SUCCESS); } }); @@ -671,6 +714,56 @@ public void run() { }); } + private void setupEmailRecyclerView() { + recyclerViewBuilder.setupRecyclerView(emailsRecyclerView, 20, false, true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); + emailsRecyclerView.setLayoutManager(linearLayoutManager); + emailsRecyclerViewAdapter = new SingleRecyclerViewAdapter(context, emailArrayList, value -> { + OneSignal.getUser().removeEmailSubscription(value); + emailArrayList.remove(value); + refreshEmailRecyclerView(); + toaster.makeCustomViewToast("Deleted email " + value, ToastType.SUCCESS); + }); + emailsRecyclerView.setAdapter(emailsRecyclerViewAdapter); + } + + private void refreshEmailRecyclerView() { + getActivity().runOnUiThread(() -> { + if (emailArrayList.size() > 0) { + animate.toggleAnimationView(false, View.GONE, emailsRecyclerView, noEmailsTextView); + } else { + animate.toggleAnimationView(true, View.GONE, emailsRecyclerView, noEmailsTextView); + } + + emailsRecyclerViewAdapter.notifyDataSetChanged(); + }); + } + + private void setupSMSRecyclerView() { + recyclerViewBuilder.setupRecyclerView(smssRecyclerView, 20, false, true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); + smssRecyclerView.setLayoutManager(linearLayoutManager); + smssRecyclerViewAdapter = new SingleRecyclerViewAdapter(context, smsArrayList, value -> { + OneSignal.getUser().removeTrigger(value); + smsArrayList.remove(value); + refreshSMSRecyclerView(); + toaster.makeCustomViewToast("Deleted SMS " + value, ToastType.SUCCESS); + }); + smssRecyclerView.setAdapter(smssRecyclerViewAdapter); + } + + private void refreshSMSRecyclerView() { + getActivity().runOnUiThread(() -> { + if (smsArrayList.size() > 0) { + animate.toggleAnimationView(false, View.GONE, smssRecyclerView, noSmssTextView); + } else { + animate.toggleAnimationView(true, View.GONE, smssRecyclerView, noSmssTextView); + } + + smssRecyclerViewAdapter.notifyDataSetChanged(); + }); + } + private void setupPushNotificationLayout() { recyclerViewBuilder.setupRecyclerView(pushNotificationRecyclerView, 16, false, true); GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2); @@ -679,8 +772,36 @@ private void setupPushNotificationLayout() { pushNotificationRecyclerViewAdapter = new NotificationRecyclerViewAdapter(context, Notification.values()); pushNotificationRecyclerView.setAdapter(pushNotificationRecyclerViewAdapter); } + private void setupOutcomeLayout() { - sendOutcomeButton.setOnClickListener(v -> dialog.createSendOutcomeAlertDialog("Select an Outcome Type...")); + sendOutcomeButton.setOnClickListener(v -> dialog.createSendOutcomeAlertDialog("Select an Outcome Type...", new SendOutcomeAlertDialogCallback() { + @Override + public boolean onSuccess(OutcomeEvent outcomeEvent, String name, String value) { + switch (outcomeEvent) { + case OUTCOME: + OneSignal.getUser().sendOutcome(name); + break; + case UNIQUE_OUTCOME: + OneSignal.getUser().sendUniqueOutcome(name); + break; + case OUTCOME_WITH_VALUE: + if (value.isEmpty()) { + toaster.makeCustomViewToast("Please enter an outcome value!", ToastType.ERROR); + return false; + } + + OneSignal.getUser().sendOutcomeWithValue(name, Float.parseFloat(value)); + break; + } + + return true; + } + + @Override + public void onFailure() { + + } + })); } private void setupTriggersLayout() { @@ -691,10 +812,11 @@ private void setupTriggersLayout() { @Override public void onSuccess(Pair pair) { if (pair.second == null || pair.second.toString().isEmpty()) { - OneSignal.removeTriggerForKey(pair.first); + OneSignal.getUser().removeTrigger(pair.first); triggerSet.remove(pair.first); toaster.makeCustomViewToast("Deleted trigger " + pair.first, ToastType.SUCCESS); } else { + OneSignal.getUser().setTrigger(pair.first, pair.second); triggerSet.put(pair.first, pair.second); toaster.makeCustomViewToast("Added trigger " + pair.first, ToastType.SUCCESS); } @@ -714,7 +836,7 @@ private void setupTriggerRecyclerView() { LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); triggersRecyclerView.setLayoutManager(linearLayoutManager); triggerPairRecyclerViewAdapter = new PairRecyclerViewAdapter(context, triggerArrayList, key -> { - OneSignal.removeTriggerForKey(key); + OneSignal.getUser().removeTrigger(key); triggerSet.remove(key); refreshTriggerRecyclerView(); @@ -766,7 +888,7 @@ private String getOneSignalAppId() { } private void togglePrivacyConsent(boolean hasConsent) { - OneSignal.provideUserConsent(hasConsent); + OneSignal.setPrivacyConsent(hasConsent); SharedPreferenceUtil.cacheUserPrivacyConsent(context, hasConsent); shouldScrollTop = hasConsent; @@ -779,4 +901,49 @@ private void togglePrivacyConsent(boolean hasConsent) { appBarLayout.setExpanded(true); } + + + private void refreshState() { + // appId + appIdTextView.setText(getOneSignalAppId()); + + // externalId + String externalUserId = OneSignal.getUser().getExternalId(); + userExternalUserIdTextView.setText(externalUserId == null ? "" : externalUserId); + + // aliases + aliasSet.clear(); + for (Map.Entry aliasEntry :OneSignal.getUser().getAliases().entrySet()) { + aliasSet.put(aliasEntry.getKey(), aliasEntry.getValue()); + } + refreshAliasRecyclerView(); + + // email subscriptions + emailArrayList.clear(); + List emailSubs = OneSignal.getUser().getSubscriptions().getEmails(); + for (IEmailSubscription emailSub: emailSubs) { + emailArrayList.add(emailSub.getEmail()); + } + refreshEmailRecyclerView(); + + // sms subscriptions + smsArrayList.clear(); + List smsSubs = OneSignal.getUser().getSubscriptions().getSmss(); + for (ISmsSubscription smsSub: smsSubs) { + smsArrayList.add(smsSub.getNumber()); + } + refreshSMSRecyclerView(); + + // tags + tagSet.clear(); + for (Map.Entry tagEntry :OneSignal.getUser().getTags().entrySet()) { + tagSet.put(tagEntry.getKey(), tagEntry.getValue()); + } + refreshTagRecyclerView(); + + // triggers + triggerSet.clear(); + // triggers are not persisted, they are always "starting from scratch" + refreshTriggerRecyclerView(); + } } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/SplashActivityViewModel.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/SplashActivityViewModel.java index 03af86e43..aaa83b30d 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/SplashActivityViewModel.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/SplashActivityViewModel.java @@ -5,22 +5,18 @@ import android.os.Handler; import android.util.Log; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import com.onesignal.OSEmailSubscriptionStateChanges; -import com.onesignal.OSPermissionStateChanges; -import com.onesignal.OSSubscriptionStateChanges; -import com.onesignal.OneSignal; -import com.onesignal.sdktest.callback.EmailUpdateCallback; +import com.onesignal.onesignal.core.OneSignal; +import com.onesignal.onesignal.notification.IPermissionStateChanges; import com.onesignal.sdktest.constant.Tag; import com.onesignal.sdktest.constant.Text; -import com.onesignal.sdktest.user.CurrentUser; import com.onesignal.sdktest.util.IntentTo; import com.onesignal.sdktest.util.SharedPreferenceUtil; public class SplashActivityViewModel implements ActivityViewModel { - private CurrentUser currentUser; private IntentTo intentTo; private Context context; @@ -40,12 +36,8 @@ public AppCompatActivity getAppCompatActivity() { @Override public ActivityViewModel onActivityCreated(Context context) { this.context = context; - - currentUser = CurrentUser.getInstance(); intentTo = new IntentTo(context); - setupOneSignalSDK(); - return this; } @@ -69,50 +61,36 @@ public void networkDisconnected() { } - @Override - public void onOSEmailSubscriptionChanged(OSEmailSubscriptionStateChanges stateChanges) { - - } - - @Override - public void onOSPermissionChanged(OSPermissionStateChanges stateChanges) { - - } - - @Override - public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) { - - } - private void setupOneSignalSDK() { boolean privacyConsent = true; - OneSignal.setRequiresUserPrivacyConsent(privacyConsent); + + OneSignal.setRequiresPrivacyConsent(privacyConsent); boolean isLocationShared = SharedPreferenceUtil.getCachedLocationSharedStatus(context); - OneSignal.setLocationShared(isLocationShared); + OneSignal.getLocation().setLocationShared(isLocationShared); boolean isInAppMessagingPaused = SharedPreferenceUtil.getCachedInAppMessagingPausedStatus(context); - OneSignal.pauseInAppMessages(isInAppMessagingPaused); + OneSignal.getIam().setPaused(isInAppMessagingPaused); Log.d(Tag.DEBUG, Text.PRIVACY_CONSENT_REQUIRED_SET + ": " + privacyConsent); - boolean isEmailCached = attemptSignIn(new EmailUpdateCallback() { - @Override - public void onSuccess() { - tasks[0] = true; - attemptEnterApplication(); - } - - @Override - public void onFailure() { - tasks[0] = true; - attemptEnterApplication(); - } - }); - if (!isEmailCached) { +// boolean isEmailCached = attemptSignIn(new EmailUpdateCallback() { +// @Override +// public void onSuccess() { +// tasks[0] = true; +// attemptEnterApplication(); +// } +// +// @Override +// public void onFailure() { +// tasks[0] = true; +// attemptEnterApplication(); +// } +// }); +// if (!isEmailCached) { tasks[0] = true; attemptEnterApplication(); - } +// } new Thread() { public void run() { @@ -126,7 +104,8 @@ public void run() { new Thread() { public void run() { boolean hasConsent = SharedPreferenceUtil.getUserPrivacyConsent(context); - OneSignal.provideUserConsent(hasConsent); + // TODO() +// OneSignal.provideUserConsent(hasConsent); tasks[2] = true; attemptEnterApplication(); @@ -134,20 +113,21 @@ public void run() { }.start(); } - public boolean attemptSignIn(EmailUpdateCallback callback) { - boolean isEmailCached = SharedPreferenceUtil.exists(context, SharedPreferenceUtil.USER_EMAIL_SHARED_PREF); - if (isEmailCached) { - String email = SharedPreferenceUtil.getCachedUserEmail(context); - currentUser.setEmail(email, callback); - } - return isEmailCached; - } +// public boolean attemptSignIn(EmailUpdateCallback callback) { +// boolean isEmailCached = SharedPreferenceUtil.exists(context, SharedPreferenceUtil.USER_EMAIL_SHARED_PREF); +// if (isEmailCached) { +// String email = SharedPreferenceUtil.getCachedUserEmail(context); +// currentUser.setEmail(email, callback); +// } +// return isEmailCached; +// return false; +// } public boolean attemptExternalUserId() { boolean isExternalUserIdCached = SharedPreferenceUtil.exists(context, SharedPreferenceUtil.USER_EXTERNAL_USER_ID_SHARED_PREF); if (isExternalUserIdCached) { String externalUserId = SharedPreferenceUtil.getCachedUserExternalUserId(context); - currentUser.setExternalUserId(context, externalUserId); +// currentUser.setExternalUserId(context, externalUserId); } return isExternalUserIdCached; } @@ -161,4 +141,8 @@ private void attemptEnterApplication() { ((Activity) context).runOnUiThread(() -> new Handler().postDelayed(() -> intentTo.mainActivity(), 1000)); } + @Override + public void onPermissionChanged(@Nullable IPermissionStateChanges stateChanges) { + + } } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/NotificationServiceExtension.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/NotificationServiceExtension.java index 677f4c2ec..3a14d2d0c 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/NotificationServiceExtension.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/NotificationServiceExtension.java @@ -2,34 +2,34 @@ import android.content.Context; -import com.onesignal.OSMutableNotification; -import com.onesignal.OSNotification; -import com.onesignal.OSNotificationOpenedResult; -import com.onesignal.OSNotificationReceivedEvent; -import com.onesignal.OneSignal; +import com.onesignal.onesignal.core.LogLevel; +import com.onesignal.onesignal.core.internal.logging.Logging; +import com.onesignal.onesignal.notification.IActionButton; +import com.onesignal.onesignal.notification.IMutableNotification; +import com.onesignal.onesignal.notification.INotification; +import com.onesignal.onesignal.notification.INotificationReceivedEvent; +import com.onesignal.onesignal.notification.IRemoteNotificationReceivedHandler; import com.onesignal.sdktest.R; -public class NotificationServiceExtension implements - OneSignal.OSRemoteNotificationReceivedHandler { +public class NotificationServiceExtension implements IRemoteNotificationReceivedHandler { @Override - public void remoteNotificationReceived(Context context, OSNotificationReceivedEvent notificationReceivedEvent) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "OSRemoteNotificationReceivedHandler fired!" + + public void remoteNotificationReceived(Context context, INotificationReceivedEvent notificationReceivedEvent) { + Logging.log(LogLevel.VERBOSE, "OSRemoteNotificationReceivedHandler fired!" + " with OSNotificationReceived: " + notificationReceivedEvent.toString()); - OSNotification notification = notificationReceivedEvent.getNotification(); + INotification notification = notificationReceivedEvent.getNotification(); if (notification.getActionButtons() != null) { - for (OSNotification.ActionButton button : notification.getActionButtons()) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "ActionButton: " + button.toString()); + for (IActionButton button : notification.getActionButtons()) { + Logging.log(LogLevel.VERBOSE, "ActionButton: " + button.toString()); } } - OSMutableNotification mutableNotification = notification.mutableCopy(); + IMutableNotification mutableNotification = notification.mutableCopy(); mutableNotification.setExtender(builder -> builder.setColor(context.getResources().getColor(R.color.colorPrimary))); // If complete isn't call within a time period of 25 seconds, OneSignal internal logic will show the original notification notificationReceivedEvent.complete(mutableNotification); } - } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/OneSignalNotificationSender.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/OneSignalNotificationSender.java index 9e4ac4d51..b99916570 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/OneSignalNotificationSender.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/OneSignalNotificationSender.java @@ -2,8 +2,9 @@ import android.util.Log; -import com.onesignal.OSDeviceState; -import com.onesignal.OneSignal; +import com.onesignal.onesignal.core.Continue; +import com.onesignal.onesignal.core.OneSignal; +import com.onesignal.onesignal.core.user.subscriptions.IPushSubscription; import com.onesignal.sdktest.constant.Tag; import com.onesignal.sdktest.type.Notification; @@ -14,16 +15,14 @@ public class OneSignalNotificationSender { public static void sendDeviceNotification(final Notification notification) { new Thread(() -> { - OSDeviceState deviceState = OneSignal.getDeviceState(); - String userId = deviceState != null ? deviceState.getUserId() : null; - boolean isSubscribed = deviceState != null && deviceState.isSubscribed(); + IPushSubscription subscription = OneSignal.getUser().getSubscriptions().getPush(); - if (!isSubscribed) + if (subscription == null || !subscription.getEnabled()) return; int pos = notification.getTemplatePos(); try { - JSONObject notificationContent = new JSONObject("{'include_player_ids': ['" + userId + "']," + + JSONObject notificationContent = new JSONObject("{'include_player_ids': ['" + subscription.getId() + "']," + "'headings': {'en': '" + notification.getTitle(pos) + "'}," + "'contents': {'en': '" + notification.getMessage(pos) + "'}," + "'small_icon': '" + notification.getSmallIconRes() + "'," + @@ -35,17 +34,16 @@ public static void sendDeviceNotification(final Notification notification) { "'android_accent_color': 'FFE9444E'," + "'android_sound': 'nil'}"); - OneSignal.postNotification(notificationContent, new OneSignal.PostNotificationResponseHandler() { - @Override - public void onSuccess(JSONObject response) { - Log.d(Tag.DEBUG, "Success sending notification: " + response.toString()); + OneSignal.getNotifications().postNotification(notificationContent, Continue.with(r -> { + if(r.isSuccess()) + { + Log.d(Tag.DEBUG, "Success sending notification: " + r.getData().toString()); } - - @Override - public void onFailure(JSONObject response) { - Log.d(Tag.ERROR, "Failure sending notification: " + response.toString()); + else + { + Log.d(Tag.ERROR, "Failure sending notification: " + r.getData().toString()); } - }); + })); } catch (JSONException e) { e.printStackTrace(); } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/user/CurrentUser.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/user/CurrentUser.java deleted file mode 100644 index 769fb141d..000000000 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/user/CurrentUser.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.onesignal.sdktest.user; - -import android.content.Context; -import android.util.Log; - -import com.onesignal.OSDeviceState; -import com.onesignal.OneSignal; -import com.onesignal.sdktest.callback.EmailUpdateCallback; -import com.onesignal.sdktest.callback.SMSUpdateCallback; -import com.onesignal.sdktest.constant.Tag; -import com.onesignal.sdktest.util.SharedPreferenceUtil; - -import org.json.JSONObject; - -public class CurrentUser { - - private static CurrentUser currentUser; - - public String getEmail() { - OSDeviceState deviceState = OneSignal.getDeviceState(); - if (deviceState != null) - return deviceState.getEmailAddress(); - return null; - } - - public String getSMSNumber() { - OSDeviceState deviceState = OneSignal.getDeviceState(); - if (deviceState != null) - return deviceState.getSMSNumber(); - return null; - } - - public String getExternalUserId(Context context) { - return SharedPreferenceUtil.getCachedUserExternalUserId(context); - } - - public void setExternalUserId(Context context, String userId) { - OneSignal.setExternalUserId(userId); - SharedPreferenceUtil.cacheUserExternalUserId(context, userId); - } - - public void setEmail(String email, final EmailUpdateCallback callback) { - OneSignal.setEmail(email, new OneSignal.EmailUpdateHandler() { - @Override - public void onSuccess() { - callback.onSuccess(); - } - - @Override - public void onFailure(OneSignal.EmailUpdateError error) { - String errorMsg = error.getType() + ": " + error.getMessage(); - Log.e(Tag.ERROR, errorMsg); - - callback.onFailure(); - } - }); - } - - public void setSMSNumber(String smsNumber, final SMSUpdateCallback callback) { - OneSignal.setSMSNumber(smsNumber, new OneSignal.OSSMSUpdateHandler() { - @Override - public void onSuccess(JSONObject result) { - callback.onSuccess(); - } - - @Override - public void onFailure(OneSignal.OSSMSUpdateError error) { - String errorMsg = error.getType() + ": " + error.getMessage(); - Log.e(Tag.ERROR, errorMsg); - - callback.onFailure(); - } - }); - } - - public void removeEmail(final EmailUpdateCallback callback) { - OneSignal.logoutEmail(); - callback.onSuccess(); - } - - public boolean isEmailSet() { - OSDeviceState deviceState = OneSignal.getDeviceState(); - return deviceState != null && deviceState.getEmailAddress() != null; - } - - public boolean isSMSNumberSet() { - OSDeviceState deviceState = OneSignal.getDeviceState(); - return deviceState != null && deviceState.getSMSNumber() != null; - } - - public boolean isExternalUserIdSet(Context context) { - String userId = getExternalUserId(context); - return userId != null && !userId.isEmpty(); - } - - public static CurrentUser getInstance() { - if (currentUser == null) { - currentUser = new CurrentUser(); - } - return currentUser; - } -} diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/Dialog.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/Dialog.java index 579a9212a..c8fc37f1a 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/Dialog.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/Dialog.java @@ -1,15 +1,12 @@ package com.onesignal.sdktest.util; -import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.graphics.drawable.Drawable; -import androidx.annotation.Nullable; import com.google.android.material.textfield.TextInputLayout; import androidx.cardview.widget.CardView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import android.util.Log; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -20,29 +17,20 @@ import android.widget.RelativeLayout; import android.widget.TextView; -import com.onesignal.OSOutcomeEvent; -import com.onesignal.OneSignal; import com.onesignal.sdktest.R; import com.onesignal.sdktest.adapter.EnumSelectionRecyclerViewAdapter; import com.onesignal.sdktest.callback.AddPairAlertDialogCallback; -import com.onesignal.sdktest.callback.EmailUpdateCallback; import com.onesignal.sdktest.callback.EnumSelectionCallback; -import com.onesignal.sdktest.callback.SMSUpdateCallback; +import com.onesignal.sdktest.callback.SendOutcomeAlertDialogCallback; import com.onesignal.sdktest.callback.UpdateAlertDialogCallback; -import com.onesignal.sdktest.constant.Tag; import com.onesignal.sdktest.constant.Text; import com.onesignal.sdktest.type.OutcomeEvent; import com.onesignal.sdktest.type.ToastType; import com.onesignal.sdktest.ui.CustomAlertDialogBuilder; import com.onesignal.sdktest.ui.RecyclerViewBuilder; -import com.onesignal.sdktest.user.CurrentUser; - -import org.json.JSONException; -import org.json.JSONObject; public class Dialog { - private CurrentUser currentUser; private Font font; private LayoutInflater layoutInflater; private RecyclerViewBuilder recyclerViewBuilder; @@ -53,18 +41,23 @@ public class Dialog { public Dialog(Context context) { this.context = context; - currentUser = CurrentUser.getInstance(); font = new Font(context); layoutInflater = LayoutInflater.from(context); recyclerViewBuilder = new RecyclerViewBuilder(context); toaster = new Toaster(context); } + public enum DialogAction { + SWITCH, + ADD, + UPDATE + } + /** * Create an AlertDialog for when the user updates a single value field * Click OK to verify and update the field being updated */ - public void createUpdateAlertDialog(final String content, final ProfileUtil.FieldType field, final UpdateAlertDialogCallback callback) { + public void createUpdateAlertDialog(final String content, final DialogAction action, final ProfileUtil.FieldType field, final UpdateAlertDialogCallback callback) { View updateAlertDialogView = layoutInflater.inflate(R.layout.update_alert_dialog_layout, null, false); final TextInputLayout updateAlertDialogTextInputLayout = updateAlertDialogView.findViewById(R.id.update_alert_dialog_text_input_layout); @@ -82,7 +75,21 @@ public void createUpdateAlertDialog(final String content, final ProfileUtil.Fiel updateAlertDialog.setView(updateAlertDialogView); updateAlertDialog.setIsCancelable(true); updateAlertDialog.setCanceledOnTouchOutside(false); - updateAlertDialog.setPositiveButton(Text.BUTTON_UPDATE, new DialogInterface.OnClickListener() { + + String buttonText = Text.BUTTON_UPDATE; + + switch (action) { + case ADD: + buttonText = Text.BUTTON_ADD; + break; + case UPDATE: + buttonText = Text.BUTTON_UPDATE; + break; + case SWITCH: + buttonText = Text.BUTTON_SWITCH; + break; + } + updateAlertDialog.setPositiveButton(buttonText, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { toggleUpdateAlertDialogAttributes(true); @@ -96,24 +103,9 @@ public void onClick(final DialogInterface dialog, int which) { dialog.dismiss(); } else if (ProfileUtil.isContentValid(field, updateAlertDialogTextInputLayout)) { InterfaceUtil.hideKeyboardFrom(context, updateAlertDialogEditText); - - switch (field) { - case APP_ID: - updateAppId(dialog, newContent); - break; - - case EMAIL: - updateEmail(dialog, newContent); - break; - - case SMS: - updateSMsNumber(dialog, newContent); - break; - - case EXTERNAL_USER_ID: - updateExternalUserId(dialog, newContent); - break; - } + toggleUpdateAlertDialogAttributes(false); + dialog.dismiss(); + callback.onSuccess(newContent); } else { toggleUpdateAlertDialogAttributes(false); } @@ -131,177 +123,6 @@ private void toggleUpdateAlertDialogAttributes(boolean disableAttributes) { updateAlertDialog.getNegativeButtonElement().setEnabled(!disableAttributes); updateAlertDialog.setIsCancelable(!disableAttributes); } - - /** - * Handles changing the app id for the SDK by reinitializing and caching - */ - private void updateAppId(DialogInterface dialog, String appId) { - OneSignal.setAppId(appId); - SharedPreferenceUtil.cacheOneSignalAppId(context, appId); - - toggleUpdateAlertDialogAttributes(false); - dialog.dismiss(); - callback.onSuccess(appId); - } - - /** - * Updates the email attached to the device and caches - */ - private void updateEmail(final DialogInterface dialog, final String email) { - currentUser.setEmail(email, new EmailUpdateCallback() { - @Override - public void onSuccess() { - SharedPreferenceUtil.cacheUserEmail(context, email); - Log.d(Tag.DEBUG, Text.EMAIL_SET_SUCCESSFULLY); - - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - toggleUpdateAlertDialogAttributes(false); - - dialog.dismiss(); - callback.onSuccess(email); - } - }); - } - - @Override - public void onFailure() { - Log.d(Tag.ERROR, Text.EMAIL_SET_FAILURE); - - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - toggleUpdateAlertDialogAttributes(false); - - dialog.dismiss(); - callback.onFailure(); - } - }); - } - }); - } - - /** - * Updates the SMS number attached to the device and caches - */ - private void updateSMsNumber(final DialogInterface dialog, final String smsNumber) { - currentUser.setSMSNumber(smsNumber, new SMSUpdateCallback() { - @Override - public void onSuccess() { - SharedPreferenceUtil.cacheUserSMSNumber(context, smsNumber); - Log.d(Tag.DEBUG, Text.SMS_SET_SUCCESSFULLY); - - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - toggleUpdateAlertDialogAttributes(false); - - dialog.dismiss(); - callback.onSuccess(smsNumber); - } - }); - } - - @Override - public void onFailure() { - Log.d(Tag.ERROR, Text.SMS_SET_FAILURE); - - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - toggleUpdateAlertDialogAttributes(false); - - dialog.dismiss(); - callback.onFailure(); - } - }); - } - }); - } - - /** - * Set external id attached to the user/email of the device - */ - private void updateExternalUserId(final DialogInterface dialog, final String externalUserId) { - OneSignal.setExternalUserId(externalUserId, new OneSignal.OSExternalUserIdUpdateCompletionHandler() { - @Override - public void onSuccess(JSONObject results) { - // Default success to false until we know push came back successful - boolean successful = false; - - // Check push exists with success status and success status is true - if (isExternalUserIdPushSuccessful(results)) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "Push channel external user id set successfully"); - SharedPreferenceUtil.cacheUserExternalUserId(context, externalUserId); - successful = true; - } - - // Check email exists with success status and success status is true - if (isExternalUserIdEmailSuccessful(results)) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "Email channel external user id set successfully"); - } - - // We base success on the push success existing and being true, call success callback for AlertDialog callback - // We could eventually check email also but not important for now - if (successful) - callback.onSuccess(externalUserId); - else - callback.onFailure(); - - toggleUpdateAlertDialogAttributes(false); - dialog.dismiss(); - } - - @Override - public void onFailure(OneSignal.ExternalIdError error) { - OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "External user id set failed with error: " + error); - callback.onFailure(); - dialog.dismiss(); - } - - /** - * Parse the results of the external user id completion callback and make sure push.success = true - */ - private boolean isExternalUserIdPushSuccessful(JSONObject status) { - boolean successful = false; - try { - if (!status.has("push")) - return false; - - JSONObject pushStatus = status.getJSONObject("push"); - if (!pushStatus.has("success")) - return false; - - successful = pushStatus.getBoolean("success"); - } catch (JSONException e) { - e.printStackTrace(); - } - return successful; - } - - /** - * Parse the results of the external user id completion callback and make sure email.success = true - */ - private boolean isExternalUserIdEmailSuccessful(JSONObject status) { - boolean successful = false; - try { - if (!status.has("email")) - return false; - - JSONObject emailStatus = status.getJSONObject("email"); - if (!emailStatus.has("success")) - return false; - - successful = emailStatus.getBoolean("success"); - } catch (JSONException e) { - e.printStackTrace(); - } - return successful; - } - }); - } - }).setNegativeButton(Text.BUTTON_CANCEL, null); updateAlertDialog.show(); updateAlertDialogEditText.requestFocus(); @@ -352,17 +173,6 @@ public void onClick(final DialogInterface dialog, int which) { if (ProfileUtil.isContentValid(field, addPairAlertDialogKeyTextInputLayout)) { InterfaceUtil.hideKeyboardFrom(context, addPairAlertDialogView); - - switch (field) { - case TAG: - OneSignal.sendTag(pairKey, pairStringValue); - break; - - case TRIGGER: - OneSignal.addTrigger(pairKey, pairValue); - break; - } - dialog.dismiss(); callback.onSuccess(new Pair<>(pairKey, pairValue)); } else { @@ -388,7 +198,7 @@ private void toggleUpdateAlertDialogAttributes(boolean disableAttributes) { addPairAlertDialogKeyEditText.requestFocus(); } - public void createSendOutcomeAlertDialog(final String content) { + public void createSendOutcomeAlertDialog(final String content, final SendOutcomeAlertDialogCallback callback) { final View sendOutcomeAlertDialogView = layoutInflater.inflate(R.layout.send_outcome_alert_dialog_layout, null, false); final CardView sendOutcomeDialogTitleCardView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_card_view); @@ -535,58 +345,11 @@ public void onClick(final DialogInterface dialog, int which) { return; } - switch (outcomeEvent) { - case OUTCOME: - OneSignal.sendOutcome(name, new OneSignal.OutcomeCallback() { - @Override - public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) { - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - toggleUpdateAlertDialogAttributes(false); - dialog.dismiss(); - } - }); - } - }); - break; - case UNIQUE_OUTCOME: - OneSignal.sendUniqueOutcome(name, new OneSignal.OutcomeCallback() { - @Override - public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) { - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - toggleUpdateAlertDialogAttributes(false); - dialog.dismiss(); - } - }); - } - }); - break; - case OUTCOME_WITH_VALUE: - if (value.isEmpty()) { - toaster.makeCustomViewToast("Please enter an outcome value!", ToastType.ERROR); - toggleUpdateAlertDialogAttributes(false); - return; - } - - OneSignal.sendOutcomeWithValue(name, Float.parseFloat(value), new OneSignal.OutcomeCallback() { - @Override - public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) { - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - toggleUpdateAlertDialogAttributes(false); - dialog.dismiss(); - } - }); - } - }); - break; + if(callback.onSuccess(outcomeEvent, name, value)) { + toggleUpdateAlertDialogAttributes(false); + dialog.dismiss(); + InterfaceUtil.hideKeyboardFrom(context, sendOutcomeAlertDialogView); } - - InterfaceUtil.hideKeyboardFrom(context, sendOutcomeAlertDialogView); } private void toggleUpdateAlertDialogAttributes(boolean disableAttributes) { diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/IntentTo.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/IntentTo.java index d341ba7d1..d99f53b33 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/IntentTo.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/IntentTo.java @@ -6,6 +6,8 @@ import android.content.Intent; import android.os.Build; +import androidx.annotation.RequiresApi; + import com.onesignal.sdktest.R; import com.onesignal.sdktest.activity.MainActivity; @@ -13,11 +15,11 @@ public class IntentTo { private Context context; - public IntentTo(Context context) { this.context = context; } + @RequiresApi(api = Build.VERSION_CODES.N) public void mainActivity() { Intent mainActivityIntent = new Intent(context, MainActivity.class); ComponentName componentName = mainActivityIntent.getComponent(); @@ -25,29 +27,4 @@ public void mainActivity() { context.startActivity(mainActivityIntent); ((Activity) context).overridePendingTransition(R.anim.fade_in, R.anim.fade_out); } - - public void notificationPermissions() { - Intent notificationPermissionIntent = new Intent(); - notificationPermissionIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - // Android 8 and above - notificationPermissionIntent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName()); - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - // Android 5-7 - notificationPermissionIntent.putExtra("app_package", context.getPackageName()); - notificationPermissionIntent.putExtra("app_uid", context.getApplicationInfo().uid); - } - context.startActivity(notificationPermissionIntent); - ((Activity) context).overridePendingTransition(R.anim.fade_in, R.anim.fade_out); - } - - public void resetApplication() { - Intent resetApplicationIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); - if (resetApplicationIntent != null) { - resetApplicationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - } - context.startActivity(resetApplicationIntent); - ((Activity) context).overridePendingTransition(R.anim.fade_in, R.anim.fade_out); - } - } diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/ProfileUtil.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/ProfileUtil.java index de433876e..9a026c5f4 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/ProfileUtil.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/ProfileUtil.java @@ -10,6 +10,7 @@ public class ProfileUtil { public enum FieldType { APP_ID("App Id"), + ALIAS("Alias"), EMAIL("Email"), SMS("SMS"), EXTERNAL_USER_ID("External User Id"), @@ -47,6 +48,21 @@ private static boolean isAppIdValid(TextInputLayout appIdTextInputLayout) { return true; } + private static boolean isAliasValid(TextInputLayout appIdTextInputLayout) { + appIdTextInputLayout.setErrorEnabled(false); + if (appIdTextInputLayout.getEditText() != null) { + String aliasLabel = appIdTextInputLayout.getEditText().getText().toString().trim(); + if (aliasLabel.isEmpty()) { + appIdTextInputLayout.setError(Text.ALIAS_LABEL_IS_REQUIRED); + return false; + } + } else { + appIdTextInputLayout.setError(Text.ERROR); + return false; + } + return true; + } + public static boolean isEmailValid(TextInputLayout emailTextInputLayout) { emailTextInputLayout.setErrorEnabled(false); if (emailTextInputLayout.getEditText() != null) { @@ -115,6 +131,8 @@ static boolean isContentValid(FieldType field, TextInputLayout alertDialogTextIn switch (field) { case APP_ID: return isAppIdValid(alertDialogTextInputLayout); + case ALIAS: + return isAliasValid(alertDialogTextInputLayout); case EMAIL: return isEmailValid(alertDialogTextInputLayout); case SMS: diff --git a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/SharedPreferenceUtil.java b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/SharedPreferenceUtil.java index e8ef9ab75..5cb286d7b 100644 --- a/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/SharedPreferenceUtil.java +++ b/Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/util/SharedPreferenceUtil.java @@ -11,8 +11,6 @@ public class SharedPreferenceUtil { public static final String OS_APP_ID_SHARED_PREF = "OS_APP_ID_SHARED_PREF"; private static final String PRIVACY_CONSENT_SHARED_PREF = "PRIVACY_CONSENT_SHARED_PREF"; - public static final String USER_EMAIL_SHARED_PREF = "USER_EMAIL_SHARED_PREF"; - public static final String USER_SMS_NUMBER_SHARED_PREF = "USER_SMS_NUMBER_SHARED_PREF"; public static final String USER_EXTERNAL_USER_ID_SHARED_PREF = "USER_EXTERNAL_USER_ID_SHARED_PREF"; private static final String LOCATION_SHARED_PREF = "LOCATION_SHARED_PREF"; private static final String IN_APP_MESSAGING_PAUSED_PREF = "IN_APP_MESSAGING_PAUSED_PREF"; @@ -33,10 +31,6 @@ public static boolean getUserPrivacyConsent(Context context) { return getSharedPreference(context).getBoolean(PRIVACY_CONSENT_SHARED_PREF, false); } - public static String getCachedUserEmail(Context context) { - return getSharedPreference(context).getString(USER_EMAIL_SHARED_PREF, Text.EMPTY); - } - public static String getCachedUserExternalUserId(Context context) { return getSharedPreference(context).getString(USER_EXTERNAL_USER_ID_SHARED_PREF, Text.EMPTY); } @@ -57,14 +51,6 @@ public static void cacheUserPrivacyConsent(Context context, boolean privacyConse getSharedPreference(context).edit().putBoolean(PRIVACY_CONSENT_SHARED_PREF, privacyConsent).apply(); } - public static void cacheUserEmail(Context context, String email) { - getSharedPreference(context).edit().putString(USER_EMAIL_SHARED_PREF, email).apply(); - } - - public static void cacheUserSMSNumber(Context context, String smsNumber) { - getSharedPreference(context).edit().putString(USER_SMS_NUMBER_SHARED_PREF, smsNumber).apply(); - } - public static void cacheUserExternalUserId(Context context, String userId) { getSharedPreference(context).edit().putString(USER_EXTERNAL_USER_ID_SHARED_PREF, userId).apply(); } @@ -76,8 +62,4 @@ public static void cacheLocationSharedStatus(Context context, boolean subscribed public static void cacheInAppMessagingPausedStatus(Context context, boolean paused) { getSharedPreference(context).edit().putBoolean(IN_APP_MESSAGING_PAUSED_PREF, paused).apply(); } - - public static void clearCachedEmail(Context context) { - getSharedPreference(context).edit().remove(USER_EMAIL_SHARED_PREF).apply(); - } } diff --git a/Examples/OneSignalDemo/app/src/main/res/layout/activity_secondary.xml b/Examples/OneSignalDemo/app/src/main/res/layout/activity_secondary.xml index 025f78899..267817f25 100644 --- a/Examples/OneSignalDemo/app/src/main/res/layout/activity_secondary.xml +++ b/Examples/OneSignalDemo/app/src/main/res/layout/activity_secondary.xml @@ -3,6 +3,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".activity.SecondaryActivity"> + tools:context="com.onesignal.sdktest.activity.SecondaryActivity"> \ No newline at end of file diff --git a/Examples/OneSignalDemo/app/src/main/res/layout/main_activity_layout.xml b/Examples/OneSignalDemo/app/src/main/res/layout/main_activity_layout.xml index 4a9ae2f89..2b01b530c 100644 --- a/Examples/OneSignalDemo/app/src/main/res/layout/main_activity_layout.xml +++ b/Examples/OneSignalDemo/app/src/main/res/layout/main_activity_layout.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context=".activity.MainActivity"> + tools:context="com.onesignal.sdktest.activity.MainActivity"> + + + + + + + + + +