+
+ /**
+ * 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 isOffscreen = Math.abs((mViewPager.getCurrentItem() - position)) <= mViewPager.getOffscreenPageLimit();
+
+ if (position >= 0 && intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {
+ if (downloadWasFine) {
+ mPreviewImagePagerAdapter.updateFile(position, file);
+
+ } else {
+ mPreviewImagePagerAdapter.updateWithDownloadError(position);
+ }
+ mPreviewImagePagerAdapter.notifyDataSetChanged(); // will trigger the creation of new fragments
+
+ } else {
+ Log_OC.d(TAG, "Download finished, but the fragment is offscreen");
+ }
+
+ }
+ removeStickyBroadcast(intent);
+ }
+
+ }
+
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_UP) {
+ toggleFullScreen();
+ }
+ return true;
+ }
+
+
+ private void toggleFullScreen() {
+ ActionBar actionBar = getSupportActionBar();
+ if (mFullScreen) {
+ actionBar.show();
+
+ } else {
+ actionBar.hide();
+
+ }
+ mFullScreen = !mFullScreen;
+ }
+
+ @Override
+ protected void onAccountSet(boolean stateWasRecovered) {
+ // TODO
+ }
+
+