Skip to content
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
4 changes: 0 additions & 4 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<uses-sdk tools:overrideLibrary="org.m4m.android" />

<!-- Normal permissions, access automatically granted to app -->
<uses-permission
android:name="android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down Expand Up @@ -884,7 +881,6 @@
</intent-filter>
</receiver>

<receiver android:name=".ui.notifications.ShareAndDismissNotificationReceiver" />
<receiver
android:name=".ui.stats.refresh.lists.widget.views.StatsViewsWidget"
android:label="@string/stats_widget_weekly_views_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ private void buildAndShowNotificationFromNoteData(Context context, Bundle data)
// Try to build the note object from the PN payload, and save it to the DB.
NotificationsUtils.buildNoteObjectFromBundleAndSaveIt(data);
EventBus.getDefault().post(new NotificationEvents.NotificationsChanged(true));
// Always do this, since a note can be updated on the server after a PN is sent
NotificationsActions.downloadNoteAndUpdateDB(wpcomNoteID, null, null);

String noteType = StringUtils.notNullStr(data.getString(PUSH_ARG_TYPE));

Expand Down Expand Up @@ -388,23 +386,8 @@ private void buildAndShowNotificationFromNoteData(Context context, Bundle data)
AppPrefs.setLastPushNotificationWpcomNoteId(wpcomNoteID);

// Update notification content for the same noteId if it is already showing
int pushId = 0;
for (Integer id : mGCMMessageHandler.mActiveNotificationsMap.keySet()) {
if (id == null) {
continue;
}
Bundle noteBundle = mGCMMessageHandler.mActiveNotificationsMap.get(id);
if (noteBundle != null && noteBundle.getString(PUSH_ARG_NOTE_ID, "").equals(wpcomNoteID)) {
pushId = id;
mGCMMessageHandler.mActiveNotificationsMap.put(pushId, data);
break;
}
}

if (pushId == 0) {
pushId = PUSH_NOTIFICATION_ID + mGCMMessageHandler.mActiveNotificationsMap.size();
mGCMMessageHandler.mActiveNotificationsMap.put(pushId, data);
}
int pushId = getPushIdForWpcomeNoteID(wpcomNoteID);
mGCMMessageHandler.mActiveNotificationsMap.put(pushId, data);

// Bump Analytics for PNs if "Show notifications" setting is checked (default). Skip otherwise.
if (NotificationsUtils.isNotificationsEnabled(context)) {
Expand All @@ -430,13 +413,46 @@ private void buildAndShowNotificationFromNoteData(Context context, Bundle data)
builder.setLargeIcon(largeIconBitmap);
}

// Always do this, since a note can be updated on the server after a PN is sent
NotificationsActions.downloadNoteAndUpdateDB(
wpcomNoteID,
success -> showNotificationForNoteData(context, data, builder),
error -> showNotificationForNoteData(context, data, builder)
);
}

private void showNotificationForNoteData(Context context, Bundle noteData, NotificationCompat.Builder builder) {
String noteType = StringUtils.notNullStr(noteData.getString(PUSH_ARG_TYPE));
String wpcomNoteID = noteData.getString(PUSH_ARG_NOTE_ID, "");
String message = StringEscapeUtils.unescapeHtml4(noteData.getString(PUSH_ARG_MSG));
int pushId = getPushIdForWpcomeNoteID(wpcomNoteID);

showSingleNotificationForBuilder(context, builder, noteType, wpcomNoteID, pushId, true);

// Also add a group summary notification, which is required for non-wearable devices
// Do not need to play the sound again. We've already played it in the individual builder.
showGroupNotificationForBuilder(context, builder, wpcomNoteID, message);
}

private int getPushIdForWpcomeNoteID(String wpcomNoteID) {
int pushId = 0;
for (Integer id : mGCMMessageHandler.mActiveNotificationsMap.keySet()) {
if (id == null) {
continue;
}
Bundle noteBundle = mGCMMessageHandler.mActiveNotificationsMap.get(id);
if (noteBundle != null && noteBundle.getString(PUSH_ARG_NOTE_ID, "").equals(wpcomNoteID)) {
pushId = id;
break;
}
}

if (pushId == 0) {
pushId = PUSH_NOTIFICATION_ID + mGCMMessageHandler.mActiveNotificationsMap.size();
}
return pushId;
}

private void showSimpleNotification(Context context, String title, String message, Intent resultIntent,
int pushId, NotificationType notificationType) {
NotificationCompat.Builder builder = getNotificationBuilder(context, title, message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.push;

import android.content.Context;
import android.content.Intent;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
Expand Down Expand Up @@ -64,9 +63,4 @@ public static void dismissNotification(int pushId, Context context) {
notificationManager.cancel(pushId);
}
}

public static void hideStatusBar(Context context) {
Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.sendBroadcast(closeIntent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.models.Note;
import org.wordpress.android.ui.comments.unified.CommentsStoreAdapter;
import org.wordpress.android.ui.main.WPMainActivity;
import org.wordpress.android.ui.notifications.NotificationsListFragment;
import org.wordpress.android.ui.notifications.SystemNotificationsTracker;
import org.wordpress.android.ui.notifications.receivers.NotificationsPendingDraftsReceiver;
import org.wordpress.android.ui.notifications.utils.NotificationsActions;
Expand Down Expand Up @@ -612,49 +610,31 @@ private void replyToComment() {
return;
}

if (!TextUtils.isEmpty(mReplyText)) {
SiteModel site = mSiteStore.getSiteBySiteId(mNote.getSiteId());
if (site == null) {
AppLog.e(T.NOTIFS, "Impossible to reply to a comment on a site that is not in the App."
+ " SiteId: " + mNote.getSiteId());
requestFailed(ARG_ACTION_APPROVE);
return;
}
if (TextUtils.isEmpty(mReplyText)) return;

// Pseudo comment (built from the note)
CommentModel comment = mNote.buildComment();
SiteModel site = mSiteStore.getSiteBySiteId(mNote.getSiteId());
if (site == null) {
AppLog.e(T.NOTIFS, "Impossible to reply to a comment on a site that is not in the App."
+ " SiteId: " + mNote.getSiteId());
requestFailed(ARG_ACTION_APPROVE);
return;
}

// Pseudo comment reply
CommentModel reply = new CommentModel();
reply.setContent(mReplyText);
// Pseudo comment (built from the note)
CommentModel comment = mNote.buildComment();

// Push the reply
RemoteCreateCommentPayload payload = new RemoteCreateCommentPayload(site, comment, reply);
mCommentsStoreAdapter.dispatch(CommentActionBuilder.newCreateNewCommentAction(payload));
// Pseudo comment reply
CommentModel reply = new CommentModel();
reply.setContent(mReplyText);

// Bump analytics
AnalyticsUtils.trackCommentReplyWithDetails(true,
site, comment, AnalyticsCommentActionSource.NOTIFICATIONS);
AnalyticsUtils.trackQuickActionTouched(QuickActionTrackPropertyValue.REPLY_TO, site, comment);
} else {
// cancel the current notification
NativeNotificationsUtils.dismissNotification(mPushId, mContext);
NativeNotificationsUtils.hideStatusBar(mContext);
// and just trigger the Activity to allow the user to write a reply
startReplyToCommentActivity();
}
}
// Push the reply
RemoteCreateCommentPayload payload = new RemoteCreateCommentPayload(site, comment, reply);
mCommentsStoreAdapter.dispatch(CommentActionBuilder.newCreateNewCommentAction(payload));

private void startReplyToCommentActivity() {
Intent intent = new Intent(mContext, WPMainActivity.class);
intent.putExtra(WPMainActivity.ARG_OPENED_FROM_PUSH, true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.putExtra(NotificationsListFragment.NOTE_ID_EXTRA, mNoteId);
intent.putExtra(NotificationsListFragment.NOTE_INSTANT_REPLY_EXTRA, true);
startActivity(intent);
// Bump analytics
AnalyticsUtils.trackCommentReplyWithDetails(true,
site, comment, AnalyticsCommentActionSource.NOTIFICATIONS);
AnalyticsUtils.trackQuickActionTouched(QuickActionTrackPropertyValue.REPLY_TO, site, comment);
}

private void resetOriginalNotification() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.wordpress.android.ui.uploads;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -12,6 +11,7 @@
import androidx.annotation.Nullable;
import androidx.collection.SparseArrayCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.TaskStackBuilder;

import org.greenrobot.eventbus.EventBus;
import org.wordpress.android.R;
Expand All @@ -25,7 +25,6 @@
import org.wordpress.android.push.NotificationsProcessingService;
import org.wordpress.android.ui.RequestCodes;
import org.wordpress.android.ui.media.MediaBrowserActivity;
import org.wordpress.android.ui.notifications.ShareAndDismissNotificationReceiver;
import org.wordpress.android.ui.notifications.SystemNotificationsTracker;
import org.wordpress.android.ui.pages.PagesActivity;
import org.wordpress.android.ui.posts.EditPostActivity;
Expand Down Expand Up @@ -289,7 +288,6 @@ static void cancelFinalNotificationForMedia(Context context, @NonNull SiteModel
}
}

@SuppressLint("NotificationTrampoline")
void updateNotificationSuccessForPost(@NonNull PostImmutableModel post, @NonNull SiteModel site,
boolean isFirstTimePublish) {
if (!WordPress.Companion.getAppIsInTheBackground()) {
Expand Down Expand Up @@ -366,14 +364,8 @@ void updateNotificationSuccessForPost(@NonNull PostImmutableModel post, @NonNull

// Share intent - started if the user tap the share link button - only if the link exist
if (shareableUrl != null && PostStatus.fromPost(post) == PostStatus.PUBLISHED) {
Intent shareIntent = new Intent(mContext, ShareAndDismissNotificationReceiver.class);
shareIntent.putExtra(ShareAndDismissNotificationReceiver.NOTIFICATION_ID_KEY, notificationId);
shareIntent.putExtra(Intent.EXTRA_TEXT, shareableUrl);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, post.getTitle());
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, shareIntent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
notificationBuilder.addAction(R.drawable.ic_share_white_24dp, mContext.getString(R.string.share_action),
pendingIntent);
getSharePendingIntent(post, shareableUrl));
}

// add draft Publish action for drafts
Expand Down Expand Up @@ -570,6 +562,21 @@ private Intent getNotificationIntent(@NonNull PostImmutableModel post, @NonNull
return notificationIntent;
}

@Nullable
private PendingIntent getSharePendingIntent(@NonNull PostImmutableModel post, String shareableUrl) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, shareableUrl);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, post.getTitle());
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

TaskStackBuilder builder = TaskStackBuilder.create(mContext);
builder.addNextIntentWithParentStack(shareIntent);
PendingIntent pendingIntent = builder
.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
return pendingIntent;
}

void updateNotificationErrorForMedia(@NonNull List<MediaModel> mediaList, @NonNull SiteModel site,
String errorMessage) {
AppLog.d(AppLog.T.MEDIA, "updateNotificationErrorForMedia: " + errorMessage);
Expand Down