X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/31827bce0c5e5d2d595610c08aad60ee3c2fe170..5b9935c849edbbfbaea563f95373f7f7dbe0fc59:/src/com/owncloud/android/ui/preview/FileDownloadFragment.java diff --git a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java index eea10cca..b11d341c 100644 --- a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java +++ b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java @@ -4,8 +4,7 @@ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, either version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -52,6 +51,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; + private static final String EXTRA_ERROR = "ERROR"; private FileFragment.ContainerActivity mContainerActivity; @@ -64,8 +64,9 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis private boolean mListening; private static final String TAG = FileDownloadFragment.class.getSimpleName(); - + private boolean mIgnoreFirstSavedState; + private boolean mError; /** @@ -80,6 +81,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis mProgressListener = null; mListening = false; mIgnoreFirstSavedState = false; + mError = false; } @@ -99,6 +101,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis mProgressListener = null; mListening = false; mIgnoreFirstSavedState = ignoreFirstSavedState; + mError = false; } @@ -117,6 +120,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis if (!mIgnoreFirstSavedState) { mFile = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE); mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT); + mError = savedInstanceState.getBoolean(FileDownloadFragment.EXTRA_ERROR); } else { mIgnoreFirstSavedState = false; } @@ -131,6 +135,12 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis ((Button)mView.findViewById(R.id.cancelBtn)).setOnClickListener(this); + if (mError) { + setButtonsForRemote(); + } else { + setButtonsForTransferring(); + } + return view; } @@ -167,6 +177,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis super.onSaveInstanceState(outState); outState.putParcelable(FileDownloadFragment.EXTRA_FILE, mFile); outState.putParcelable(FileDownloadFragment.EXTRA_ACCOUNT, mAccount); + outState.putBoolean(FileDownloadFragment.EXTRA_ERROR, mError); } @Override @@ -249,7 +260,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis */ public void updateView(boolean transferring) { // configure UI for depending upon local state of the file - FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); + FileDownloaderBinder downloaderBinder = (mContainerActivity == null) ? null : mContainerActivity.getFileDownloaderBinder(); if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile))) { setButtonsForTransferring(); @@ -261,6 +272,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis setButtonsForRemote(); } getView().invalidate(); + } @@ -268,14 +280,17 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis * Enables or disables buttons for a file being downloaded */ private void setButtonsForTransferring() { - Button downloadButton = (Button) getView().findViewById(R.id.cancelBtn); - downloadButton.setText(R.string.common_cancel); + getView().findViewById(R.id.cancelBtn).setVisibility(View.VISIBLE); // show the progress bar for the transfer - ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.progressBar); - progressBar.setVisibility(View.VISIBLE); + getView().findViewById(R.id.progressBar).setVisibility(View.VISIBLE); TextView progressText = (TextView)getView().findViewById(R.id.progressText); progressText.setText(R.string.downloader_download_in_progress_ticker); + progressText.setVisibility(View.VISIBLE); + + // hides the error icon + getView().findViewById(R.id.errorText).setVisibility(View.GONE); + getView().findViewById(R.id.error_image).setVisibility(View.GONE); } @@ -283,34 +298,37 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis * Enables or disables buttons for a file locally available */ private void setButtonsForDown() { - Button downloadButton = (Button) getView().findViewById(R.id.cancelBtn); - downloadButton.setVisibility(View.GONE); + getView().findViewById(R.id.cancelBtn).setVisibility(View.GONE); // hides the progress bar - ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.progressBar); - progressBar.setVisibility(View.GONE); + getView().findViewById(R.id.progressBar).setVisibility(View.GONE); // updates the text message TextView progressText = (TextView)getView().findViewById(R.id.progressText); progressText.setText(R.string.common_loading); + progressText.setVisibility(View.VISIBLE); + + // hides the error icon + getView().findViewById(R.id.errorText).setVisibility(View.GONE); + getView().findViewById(R.id.error_image).setVisibility(View.GONE); } /** * Enables or disables buttons for a file not locally available + * + * Currently, this is only used when a download was failed */ private void setButtonsForRemote() { - Button downloadButton = (Button) getView().findViewById(R.id.cancelBtn); - downloadButton.setVisibility(View.GONE); - //downloadButton.setText(R.string.filedetails_download); - - // hides the progress bar - ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.progressBar); - progressBar.setVisibility(View.GONE); + getView().findViewById(R.id.cancelBtn).setVisibility(View.GONE); - // updates the text message - TextView progressText = (TextView)getView().findViewById(R.id.progressText); - progressText.setText(R.string.downloader_not_downloaded_yet); + // hides the progress bar and message + getView().findViewById(R.id.progressBar).setVisibility(View.GONE); + getView().findViewById(R.id.progressText).setVisibility(View.GONE); + + // shows the error icon and message + getView().findViewById(R.id.errorText).setVisibility(View.VISIBLE); + getView().findViewById(R.id.error_image).setVisibility(View.VISIBLE); } @@ -366,6 +384,11 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis mLastPercent = percent; } + } + + + public void setError(boolean error) { + mError = error; };