浏览代码

open file from notification

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 6 年之前
父节点
当前提交
22e605b584

+ 14 - 2
src/main/java/com/owncloud/android/jobs/NotificationJob.java

@@ -57,6 +57,8 @@ import com.owncloud.android.lib.resources.notifications.DeleteNotificationRemote
 import com.owncloud.android.lib.resources.notifications.GetNotificationRemoteOperation;
 import com.owncloud.android.lib.resources.notifications.GetNotificationRemoteOperation;
 import com.owncloud.android.lib.resources.notifications.models.Action;
 import com.owncloud.android.lib.resources.notifications.models.Action;
 import com.owncloud.android.lib.resources.notifications.models.Notification;
 import com.owncloud.android.lib.resources.notifications.models.Notification;
+import com.owncloud.android.lib.resources.notifications.models.RichObject;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.activity.NotificationsActivity;
 import com.owncloud.android.ui.activity.NotificationsActivity;
 import com.owncloud.android.ui.notifications.NotificationUtils;
 import com.owncloud.android.ui.notifications.NotificationUtils;
 import com.owncloud.android.utils.PushUtils;
 import com.owncloud.android.utils.PushUtils;
@@ -150,9 +152,19 @@ public class NotificationJob extends Job {
     }
     }
 
 
     private void sendNotification(Notification notification, Account account) {
     private void sendNotification(Notification notification, Account account) {
-        Intent intent = new Intent(context, NotificationsActivity.class);
-        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        RichObject file = notification.subjectRichParameters.get("file");
+
+        Intent intent;
+        if (file == null) {
+            intent = new Intent(context, NotificationsActivity.class);
+        } else {
+            intent = new Intent(context, FileDisplayActivity.class);
+            intent.setAction(Intent.ACTION_VIEW);
+            intent.putExtra(FileDisplayActivity.KEY_FILE_ID, file.id);
+        }
         intent.putExtra(KEY_NOTIFICATION_ACCOUNT, account.name);
         intent.putExtra(KEY_NOTIFICATION_ACCOUNT, account.name);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+
         PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
         PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
         int pushNotificationId = randomId.nextInt();
         int pushNotificationId = randomId.nextInt();
 
 

+ 14 - 8
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -176,6 +176,7 @@ public class FileDisplayActivity extends FileActivity
 
 
     public static final String TAG_PUBLIC_LINK = "PUBLIC_LINK";
     public static final String TAG_PUBLIC_LINK = "PUBLIC_LINK";
     public static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG";
     public static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG";
+    public static final String KEY_FILE_ID = "KEY_FILE_ID";
 
 
     private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
     private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
@@ -2622,17 +2623,22 @@ public class FileDisplayActivity extends FileActivity
 
 
         String accountName = intent.getStringExtra("KEY_ACCOUNT");
         String accountName = intent.getStringExtra("KEY_ACCOUNT");
 
 
-        Account newAccount = getUserAccountManager().getAccountByName(accountName);
+        Account newAccount;
+        if (accountName == null) {
+            newAccount = getAccount();
+        } else {
+            newAccount = getUserAccountManager().getAccountByName(accountName);
 
 
-        if (newAccount == null) {
-            dismissLoadingDialog();
-            DisplayUtils.showSnackMessage(this, "Associated account not found!");
-            return;
-        }
+            if (newAccount == null) {
+                dismissLoadingDialog();
+                DisplayUtils.showSnackMessage(this, "Associated account not found!");
+                return;
+            }
 
 
-        setAccount(newAccount);
+            setAccount(newAccount);
+        }
 
 
-        String fileId = String.valueOf(intent.getStringExtra("KEY_FILE_ID"));
+        String fileId = String.valueOf(intent.getStringExtra(KEY_FILE_ID));
 
 
         if ("null".equals(fileId)) {
         if ("null".equals(fileId)) {
             dismissLoadingDialog();
             dismissLoadingDialog();

+ 14 - 2
src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java

@@ -52,6 +52,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.resources.notifications.models.Action;
 import com.owncloud.android.lib.resources.notifications.models.Action;
 import com.owncloud.android.lib.resources.notifications.models.Notification;
 import com.owncloud.android.lib.resources.notifications.models.Notification;
 import com.owncloud.android.lib.resources.notifications.models.RichObject;
 import com.owncloud.android.lib.resources.notifications.models.RichObject;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.activity.NotificationsActivity;
 import com.owncloud.android.ui.activity.NotificationsActivity;
 import com.owncloud.android.ui.asynctasks.DeleteNotificationTask;
 import com.owncloud.android.ui.asynctasks.DeleteNotificationTask;
 import com.owncloud.android.ui.asynctasks.NotificationExecuteActionTask;
 import com.owncloud.android.ui.asynctasks.NotificationExecuteActionTask;
@@ -106,8 +107,9 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
         holder.dateTime.setText(DisplayUtils.getRelativeTimestamp(notificationsActivity,
         holder.dateTime.setText(DisplayUtils.getRelativeTimestamp(notificationsActivity,
                 notification.getDatetime().getTime()));
                 notification.getDatetime().getTime()));
 
 
+        RichObject file = notification.subjectRichParameters.get("file");
         String subject = notification.getSubject();
         String subject = notification.getSubject();
-        if (!TextUtils.isEmpty(notification.getLink())) {
+        if (file == null && !TextUtils.isEmpty(notification.getLink())) {
             subject = subject + " ↗";
             subject = subject + " ↗";
             holder.subject.setTypeface(holder.subject.getTypeface(), Typeface.BOLD);
             holder.subject.setTypeface(holder.subject.getTypeface(), Typeface.BOLD);
             holder.subject.setOnClickListener(v -> openLink(notification.getLink()));
             holder.subject.setOnClickListener(v -> openLink(notification.getLink()));
@@ -118,6 +120,16 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
             } else {
             } else {
                 holder.subject.setText(subject);
                 holder.subject.setText(subject);
             }
             }
+
+            if (file != null && !TextUtils.isEmpty(file.id)) {
+                holder.subject.setOnClickListener(v -> {
+                    Intent intent = new Intent(notificationsActivity, FileDisplayActivity.class);
+                    intent.setAction(Intent.ACTION_VIEW);
+                    intent.putExtra(FileDisplayActivity.KEY_FILE_ID, file.id);
+
+                    notificationsActivity.startActivity(intent);
+                });
+            }
         }
         }
 
 
         holder.message.setText(notification.getMessage());
         holder.message.setText(notification.getMessage());
@@ -136,7 +148,7 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
             ViewGroup.LayoutParams.WRAP_CONTENT);
             ViewGroup.LayoutParams.WRAP_CONTENT);
         params.setMargins(20, 0, 20, 0);
         params.setMargins(20, 0, 20, 0);
-        
+
         for (Action action : notification.getActions()) {
         for (Action action : notification.getActions()) {
             button = new MaterialButton(notificationsActivity);
             button = new MaterialButton(notificationsActivity);