Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP Stories integration - implement StoryNotificationTrackerProvider interface #12068

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions WordPress/src/main/java/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.firebase.iid.FirebaseInstanceId;
import com.wordpress.rest.RestClient;
import com.wordpress.stories.compose.NotificationTrackerProvider;
import com.wordpress.stories.compose.frame.StoryNotificationType;
import com.yarolegovich.wellsql.WellSql;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.analytics.AnalyticsTracker.Stat;
import org.wordpress.android.analytics.Tracker;
Expand Down Expand Up @@ -76,6 +79,7 @@
import org.wordpress.android.networking.OAuthAuthenticator;
import org.wordpress.android.networking.RestClientUtils;
import org.wordpress.android.push.GCMRegistrationIntentService;
import org.wordpress.android.push.NotificationType;
import org.wordpress.android.support.ZendeskHelper;
import org.wordpress.android.ui.ActivityId;
import org.wordpress.android.ui.notifications.SystemNotificationsTracker;
Expand Down Expand Up @@ -147,6 +151,7 @@ public class WordPress extends MultiDexApplication implements HasServiceInjector
private static Context mContext;
private static BitmapLruCache mBitmapCache;
private static ApplicationLifecycleMonitor mApplicationLifecycleMonitor;
private static StoryNotificationTrackerProvider mStoryNotificationTrackerProvider;

private static GoogleApiClient mCredentialsClient;

Expand Down Expand Up @@ -338,6 +343,7 @@ public void onConnectionSuspended(int i) {
ImageEditorInitializer.Companion.init(mImageManager, mImageEditorTracker);

initEmojiCompat();
mStoryNotificationTrackerProvider = new StoryNotificationTrackerProvider();
ProcessLifecycleOwner.get().getLifecycle().addObserver(mStoryMediaSaveUploadBridge);
}

Expand Down Expand Up @@ -816,6 +822,10 @@ private void initEmojiCompat() {
EmojiCompat.init(config);
}

public StoryNotificationTrackerProvider getStoryNotificationTrackerProvider() {
return mStoryNotificationTrackerProvider;
}

@Override
public AndroidInjector<Service> serviceInjector() {
return mServiceDispatchingAndroidInjector;
Expand Down Expand Up @@ -995,4 +1005,32 @@ public void onTrimMemory(final int level) {
}
}
}

private class StoryNotificationTrackerProvider implements NotificationTrackerProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mzorz what do you think about putting this class into another file? Just checking because this class is getting a bit big. Let me know though because it's also a really small class 🙏

private NotificationType translateNotificationTypes(StoryNotificationType storyNotificationType) {
switch (storyNotificationType) {
case STORY_SAVE_SUCCESS:
return NotificationType.STORY_SAVE_SUCCESS;
case STORY_SAVE_ERROR:
return NotificationType.STORY_SAVE_ERROR;
case STORY_FRAME_SAVE_SUCCESS:
return NotificationType.STORY_FRAME_SAVE_SUCCESS;
case STORY_FRAME_SAVE_ERROR:
return NotificationType.STORY_FRAME_SAVE_ERROR;
}
return NotificationType.STORY_FRAME_SAVE_ERROR; // shouldn't reach this
}

@Override public void trackShownNotification(@NotNull StoryNotificationType storyNotificationType) {
mSystemNotificationsTracker.trackShownNotification(translateNotificationTypes(storyNotificationType));
}

@Override public void trackTappedNotification(@NotNull StoryNotificationType storyNotificationType) {
mSystemNotificationsTracker.trackTappedNotification(translateNotificationTypes(storyNotificationType));
}

@Override public void trackDismissedNotification(@NotNull StoryNotificationType storyNotificationType) {
mSystemNotificationsTracker.trackDismissedNotification(translateNotificationTypes(storyNotificationType));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import org.wordpress.android.fluxc.model.post.PostStatus.PUBLISHED
import org.wordpress.android.fluxc.store.PostStore
import org.wordpress.android.push.NotificationType
import org.wordpress.android.push.NotificationsProcessingService
import org.wordpress.android.push.NotificationsProcessingService.ARG_NOTIFICATION_TYPE
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.RequestCodes
import org.wordpress.android.ui.media.MediaBrowserActivity
import org.wordpress.android.ui.media.MediaBrowserType
import org.wordpress.android.ui.notifications.SystemNotificationsTracker
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.photopicker.PhotoPickerActivity
import org.wordpress.android.ui.posts.EditPostActivity.OnPostUpdatedFromUIListener
Expand Down Expand Up @@ -76,6 +78,7 @@ class StoryComposerActivity : ComposeLoopFrameActivity(),
@Inject lateinit var editPostRepository: EditPostRepository
@Inject lateinit var savePostToDbUseCase: SavePostToDbUseCase
@Inject lateinit var dispatcher: Dispatcher
@Inject lateinit var systemNotificationsTracker: SystemNotificationsTracker

private var addingMediaToEditorProgressDialog: ProgressDialog? = null

Expand All @@ -97,6 +100,7 @@ class StoryComposerActivity : ComposeLoopFrameActivity(),
setNotificationExtrasLoader(this)
setMetadataProvider(this)
setStoryDiscardListener(this)
setNotificationTrackerProvider((application as WordPress).getStoryNotificationTrackerProvider())

if (savedInstanceState == null) {
site = intent.getSerializableExtra(WordPress.SITE) as SiteModel
Expand All @@ -107,6 +111,11 @@ class StoryComposerActivity : ComposeLoopFrameActivity(),
} else {
editPostRepository.loadPostByLocalPostId(localPostId)
}

if (intent.hasExtra(ARG_NOTIFICATION_TYPE)) {
val notificationType = intent.getSerializableExtra(ARG_NOTIFICATION_TYPE) as NotificationType
systemNotificationsTracker.trackTappedNotification(notificationType)
}
} else {
site = savedInstanceState.getSerializable(WordPress.SITE) as SiteModel
if (savedInstanceState.containsKey(STATE_KEY_POST_LOCAL_ID)) {
Expand Down Expand Up @@ -296,16 +305,15 @@ class StoryComposerActivity : ComposeLoopFrameActivity(),
return authenticationUtils.getAuthHeaders(url)
}

// NotificationIntentLoader
// region NotificationIntentLoader
override fun loadIntentForErrorNotification(): Intent {
val notificationIntent = Intent(applicationContext, StoryComposerActivity::class.java)
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
notificationIntent.putExtra(WordPress.SITE, site)
// TODO WPSTORIES add TRACKS
// add NotificationType.MEDIA_SAVE_ERROR param later when integrating with WPAndroid
// val notificationType = NotificationType.MEDIA_SAVE_ERROR
// notificationIntent.putExtra(ARG_NOTIFICATION_TYPE, notificationType)
// setup tracks NotificationType for Notification tracking. Note this doesn't use our interface.
val notificationType = NotificationType.STORY_FRAME_SAVE_ERROR
notificationIntent.putExtra(ARG_NOTIFICATION_TYPE, notificationType)
return notificationIntent
}

Expand All @@ -321,6 +329,7 @@ class StoryComposerActivity : ComposeLoopFrameActivity(),
override fun setupErrorNotificationBaseId(): Int {
return BASE_FRAME_MEDIA_ERROR_NOTIFICATION_ID
}
// endregion

override fun loadMetadataForStory(index: StoryIndex): Bundle? {
val bundle = Bundle()
Expand Down
2 changes: 1 addition & 1 deletion libs/portkey-android