+
+ private void updateCurrentDownloadFragment(boolean transferring) {
+ FileFragment fragment = mPreviewImagePagerAdapter.getFragmentAt(mViewPager.getCurrentItem());
+ if (fragment instanceof FileDownloadFragment) {
+ ((FileDownloadFragment) fragment).updateView(transferring);
+ //mViewPager.invalidate();
+ }
+ }
+
+
+ /**
+ * Class waiting for broadcast events from the {@link FielDownloader} service.
+ *
+ * Updates the UI when a download is started or finished, provided that it is relevant for the
+ * folder displayed in the gallery.
+ */
+ private class DownloadFinishReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
+ String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
+ if (mAccount.name.equals(accountName) &&
+ downloadedRemotePath != null) {
+
+ OCFile file = mStorageManager.getFileByPath(downloadedRemotePath);
+ int position = mPreviewImagePagerAdapter.getFilePosition(file);
+ boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
+ boolean isCurrent = (mViewPager.getCurrentItem() == position);
+
+ if (position >= 0) {
+ /// ITS MY BUSSINESS
+ Log.e(TAG, "downloaded file FOUND in adapter");
+ if (downloadWasFine) {
+ mPreviewImagePagerAdapter.updateFile(position, file);
+ //Log.e(TAG, "BEFORE NOTIFY DATA SET CHANGED");
+ mPreviewImagePagerAdapter.notifyDataSetChanged();
+ //Log.e(TAG, "AFTER NOTIFY DATA SET CHANGED");
+
+ } else if (isCurrent) {
+ updateCurrentDownloadFragment(false);
+ }
+
+ } else {
+ Log.e(TAG, "DOWNLOADED FILE NOT FOUND IN ADAPTER ");
+ }
+
+ }
+ removeStickyBroadcast(intent);
+ }
+
+ }
+
+