|
@@ -34,6 +34,8 @@ import eu.alefzero.webdav.OnDatatransferProgressListener;
|
|
|
import com.owncloud.android.network.OwnCloudClientUtils;
|
|
|
import com.owncloud.android.operations.DownloadFileOperation;
|
|
|
import com.owncloud.android.operations.RemoteOperationResult;
|
|
|
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
|
|
|
+import com.owncloud.android.ui.activity.AuthenticatorActivity;
|
|
|
import com.owncloud.android.ui.activity.FileDetailActivity;
|
|
|
import com.owncloud.android.ui.fragment.FileDetailFragment;
|
|
|
|
|
@@ -387,9 +389,27 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
|
|
|
int contentId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_content : R.string.downloader_download_failed_content;
|
|
|
Notification finalNotification = new Notification(R.drawable.icon, getString(tickerId), System.currentTimeMillis());
|
|
|
finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
- // TODO put something smart in the contentIntent below
|
|
|
- finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
|
|
|
- finalNotification.setLatestEventInfo(getApplicationContext(), getString(tickerId), String.format(getString(contentId), new File(download.getSavePath()).getName()), finalNotification.contentIntent);
|
|
|
+ boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED);
|
|
|
+ if (needsToUpdateCredentials) {
|
|
|
+ // let the user update credentials with one click
|
|
|
+ Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
|
|
|
+ updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount());
|
|
|
+ updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_TOKEN);
|
|
|
+ updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
|
|
+ updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
|
|
|
+ finalNotification.contentIntent = PendingIntent.getActivity(this, (int)System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT);
|
|
|
+ finalNotification.setLatestEventInfo( getApplicationContext(),
|
|
|
+ getString(tickerId),
|
|
|
+ String.format(getString(contentId), new File(download.getSavePath()).getName()),
|
|
|
+ finalNotification.contentIntent);
|
|
|
+ mDownloadClient = null; // grant that future retries on the same account will get the fresh credentials
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // TODO put something smart in the contentIntent below
|
|
|
+ finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
|
|
|
+ finalNotification.setLatestEventInfo(getApplicationContext(), getString(tickerId), String.format(getString(contentId), new File(download.getSavePath()).getName()), finalNotification.contentIntent);
|
|
|
+ }
|
|
|
mNotificationManager.notify(tickerId, finalNotification);
|
|
|
}
|
|
|
}
|