X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f2474ae28d3765968559d4eaa965a16e50981793..d7e0519294ca47e6d53dd29e7355d452890ffb24:/src/com/owncloud/android/ui/activity/FileDetailActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDetailActivity.java b/src/com/owncloud/android/ui/activity/FileDetailActivity.java index a36c9723..6994c093 100644 --- a/src/com/owncloud/android/ui/activity/FileDetailActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDetailActivity.java @@ -40,10 +40,8 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.ui.fragment.FileDetailFragment; -import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.FilePreviewFragment; -import com.owncloud.android.AccountUtils; import com.owncloud.android.R; /** @@ -51,7 +49,7 @@ import com.owncloud.android.R; * on. * * @author Bartek Przybylski - * + * @author David A. Velasco */ public class FileDetailActivity extends SherlockFragmentActivity implements FileDetailFragment.ContainerActivity { @@ -62,17 +60,26 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File public static final String EXTRA_MODE = "MODE"; public static final int MODE_DETAILS = 0; public static final int MODE_PREVIEW = 1; + + public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW"; private boolean mConfigurationChangedToLandscape = false; private FileDownloaderBinder mDownloaderBinder = null; private ServiceConnection mDownloadConnection, mUploadConnection = null; private FileUploaderBinder mUploaderBinder = null; + private boolean mWaitingToPreview; + + private OCFile mFile; + private Account mAccount; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mFile = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); + mAccount = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT); + // check if configuration changed to large-land ; for a tablet being changed from portrait to landscape when in FileDetailActivity Configuration conf = getResources().getConfiguration(); mConfigurationChangedToLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE && @@ -80,39 +87,50 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File ); if (!mConfigurationChangedToLandscape) { - mDownloadConnection = new DetailsServiceConnection(); - bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE); - mUploadConnection = new DetailsServiceConnection(); - bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE); - setContentView(R.layout.file_activity_details); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); if (savedInstanceState == null) { + mWaitingToPreview = false; createChildFragment(); + } else { + mWaitingToPreview = savedInstanceState.getBoolean(KEY_WAITING_TO_PREVIEW); } + mDownloadConnection = new DetailsServiceConnection(); + bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE); + mUploadConnection = new DetailsServiceConnection(); + bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE); + + } else { backToDisplayActivity(); // the 'back' won't be effective until this.onStart() and this.onResume() are completed; } } - - + + /** + * Creates the proper fragment depending upon the state of the handled {@link OCFile} and + * the requested {@link Intent}. + */ private void createChildFragment() { - OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); - Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT); int mode = getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW); Fragment newFragment = null; - if (FilePreviewFragment.canBePreviewed(file) && mode == MODE_PREVIEW) { - newFragment = new FilePreviewFragment(file, account); + if (FilePreviewFragment.canBePreviewed(mFile) && mode == MODE_PREVIEW) { + if (mFile.isDown()) { + newFragment = new FilePreviewFragment(mFile, mAccount); + + } else { + newFragment = new FileDetailFragment(mFile, mAccount); + mWaitingToPreview = true; + } } else { - newFragment = new FileDetailFragment(file, account); + newFragment = new FileDetailFragment(mFile, mAccount); } FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.fragment, newFragment, FileDetailFragment.FTAG); @@ -120,24 +138,38 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File } + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(KEY_WAITING_TO_PREVIEW, mWaitingToPreview); + } + /** Defines callbacks for service binding, passed to bindService() */ private class DetailsServiceConnection implements ServiceConnection { @Override public void onServiceConnected(ComponentName component, IBinder service) { + if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) { Log.d(TAG, "Download service connected"); mDownloaderBinder = (FileDownloaderBinder) service; + if (mWaitingToPreview) { + requestForDownload(); + } + } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) { Log.d(TAG, "Upload service connected"); mUploaderBinder = (FileUploaderBinder) service; } else { return; } + Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); - if (fragment != null && fragment instanceof FileDetailFragment) { - ((FileDetailFragment) fragment).updateFileDetails(false); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais()) + FileDetailFragment detailsFragment = (fragment instanceof FileDetailFragment) ? (FileDetailFragment) fragment : null; + if (detailsFragment != null) { + detailsFragment.listenForTransferProgress(); + detailsFragment.updateFileDetails(mWaitingToPreview); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais()) } } @@ -153,7 +185,7 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File } }; - + @Override public void onDestroy() { super.onDestroy(); @@ -202,8 +234,8 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File private void backToDisplayActivity() { Intent intent = new Intent(this, FileDisplayActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(FileDetailFragment.EXTRA_FILE, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE)); - intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT)); + intent.putExtra(FileDetailFragment.EXTRA_FILE, mFile); + intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, mAccount); startActivity(intent); finish(); } @@ -256,8 +288,30 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File @Override public void showFragmentWithDetails(OCFile file) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - transaction.replace(R.id.fragment, new FileDetailFragment(file, (Account) getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT)), FileDetailFragment.FTAG); + transaction.replace(R.id.fragment, new FileDetailFragment(file, mAccount), FileDetailFragment.FTAG); transaction.commit(); } + + + private void requestForDownload() { + if (!mDownloaderBinder.isDownloading(mAccount, mFile)) { + Intent i = new Intent(this, FileDownloader.class); + i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount); + i.putExtra(FileDownloader.EXTRA_FILE, mFile); + startService(i); + } + } + + @Override + public void notifySuccessfulDownload(OCFile file, Intent intent, boolean success) { + if (success) { + if (mWaitingToPreview) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.fragment, new FilePreviewFragment(file, mAccount), FileDetailFragment.FTAG); + transaction.commit(); + mWaitingToPreview = false; + } + } + } }