@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final Bundle args = getArguments(); bucket = args.getString(BUNDLE_ARGS_S3_BUCKET); prefix = args.getString(BUNDLE_ARGS_S3_PREFIX); final ProgressDialog dialog = getProgressDialog(R.string.content_progress_dialog_message_load_local_content); // Create the User File Manager AWSMobileClient.defaultMobileClient() .createUserFileManager( bucket, prefix, new UserFileManager.BuilderResultHandler() { @Override public void onComplete(final UserFileManager userFileManager) { if (isAdded()) { UserFilesBrowserFragment.this.userFileManager = userFileManager; createContentList(getView(), userFileManager); userFileManager.setContentRemovedListener(contentListItems); dialog.dismiss(); refreshContent(currentPath); } else { userFileManager.destroy(); } } }); }
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getActionView() == cacheLimitTextView) { final SpannableString itemTitle = (SpannableString) item.getTitle(); final int cacheSizeIndex = ContentUtils.cacheSizeStrings.indexOf(itemTitle); if (cacheSizeIndex > -1) { userFileManager.setContentCacheSize(ContentUtils.cacheSizeValues[cacheSizeIndex]); refreshCacheSummary(); } return true; } else if (item.getActionView() == listView) { final CharSequence itemTitle = item.getTitle(); final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); final ContentItem content = contentListItems.getItem(info.position).getContentItem(); if (itemTitle.equals(getString(R.string.content_context_menu_open))) { ContentHelper.openFileViewer(getActivity(), content.getFile()); } else if (itemTitle.equals(getString(R.string.content_context_menu_open_remote))) { // Open the object in a browser via a presigned URL. final AmazonS3 s3 = new AmazonS3Client( AWSMobileClient.defaultMobileClient() .getIdentityManager() .getCredentialsProvider()); final URL presignedUrl = s3.generatePresignedUrl( bucket, prefix + content.getFilePath(), new Date(new Date().getTime() + 60 * 60 * 1000)); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(presignedUrl.toString())); startActivity(intent); } else if (itemTitle.equals(getString(R.string.content_context_menu_download))) { // Download the content. userFileManager.getContent( content.getFilePath(), content.getSize(), ContentDownloadPolicy.DOWNLOAD_ALWAYS, false, contentListItems); } else if (itemTitle.equals(getString(R.string.content_context_menu_download_latest))) { // Download the content. userFileManager.getContent( content.getFilePath(), content.getSize(), ContentDownloadPolicy.DOWNLOAD_IF_NEWER_EXIST, false, contentListItems); } else if (itemTitle.equals(getString(R.string.content_context_menu_pin))) { userFileManager.pinContent(content.getFilePath(), contentListItems); } else if (itemTitle.equals(getString(R.string.content_context_menu_download_pin))) { userFileManager.getContent( content.getFilePath(), content.getSize(), ContentDownloadPolicy.DOWNLOAD_ALWAYS, true, contentListItems); } else if (itemTitle.equals(getString(R.string.content_context_menu_unpin))) { userFileManager.unPinContent( content.getFilePath(), new Runnable() { @Override public void run() { refreshCacheSummary(); contentListItems.notifyDataSetChanged(); } }); } else if (itemTitle.equals(getString(R.string.content_context_menu_delete_local))) { userFileManager.removeLocal(content.getFilePath()); } else if (itemTitle.equals(getString(R.string.user_files_browser_context_menu_delete))) { deleteItem(info.position); } return true; } return super.onContextItemSelected(item); }