X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/51a04aa54111ce3c7b45c5ab6f073a25b3b4d985..4e66d6acd88fbfce9601b646a564d5291e5a16d5:/src/com/owncloud/android/ui/fragment/FileDetailFragment.java diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index fa78039c..94723721 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -68,7 +68,28 @@ public class FileDetailFragment extends FileFragment implements OnClickListener private static final String TAG = FileDetailFragment.class.getSimpleName(); public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT"; public static final String FTAG_RENAME_FILE = "RENAME_FILE_FRAGMENT"; - + + private static final String ARG_FILE = "FILE"; + private static final String ARG_ACCOUNT = "ACCOUNT"; + + + /** + * Public factory method to create new FileDetailFragment instances. + * + * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before). + * + * @param fileToDetail An {@link OCFile} to show in the fragment + * @param account An ownCloud account; needed to start downloads + * @return New fragment with arguments set + */ + public static FileDetailFragment newInstance(OCFile fileToDetail, Account account) { + FileDetailFragment frag = new FileDetailFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARG_FILE, fileToDetail); + args.putParcelable(ARG_ACCOUNT, account); + frag.setArguments(args); + return frag; + } /** * Creates an empty details fragment. @@ -83,22 +104,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener mProgressListener = null; } - /** - * Creates a details fragment. - * - * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before). - * - * @param fileToDetail An {@link OCFile} to show in the fragment - * @param ocAccount An ownCloud account; needed to start downloads - */ - public FileDetailFragment(OCFile fileToDetail, Account ocAccount) { - super(fileToDetail); - mAccount = ocAccount; - mLayout = R.layout.file_details_empty; - mProgressListener = null; - } - - + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -109,7 +115,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - + + setFile((OCFile) getArguments().getParcelable(ARG_FILE)); + mAccount = getArguments().getParcelable(ARG_ACCOUNT); + if (savedInstanceState != null) { setFile((OCFile)savedInstanceState.getParcelable(FileActivity.EXTRA_FILE)); mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT); @@ -250,6 +259,14 @@ public class FileDetailFragment extends FileFragment implements OnClickListener } return true; } + case R.id.action_favorite_file:{ + mContainerActivity.getFileOperationsHelper().toggleKeepInSync(getFile(), true); + return true; + } + case R.id.action_unfavorite_file:{ + mContainerActivity.getFileOperationsHelper().toggleKeepInSync(getFile(), false); + return true; + } default: return false; } @@ -259,7 +276,8 @@ public class FileDetailFragment extends FileFragment implements OnClickListener public void onClick(View v) { switch (v.getId()) { case R.id.fdKeepInSync: { - toggleKeepInSync(); + CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); + mContainerActivity.getFileOperationsHelper().toggleKeepInSync(getFile(),cb.isChecked()); break; } case R.id.fdCancelBtn: { @@ -270,27 +288,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener Log_OC.e(TAG, "Incorrect view clicked!"); } } - - - private void toggleKeepInSync() { - CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); - OCFile file = getFile(); - file.setKeepInSync(cb.isChecked()); - mContainerActivity.getStorageManager().saveFile(file); - - /// register the OCFile instance in the observer service to monitor local updates - Intent observedFileIntent = FileObserverService.makeObservedFileIntent( - getActivity(), - file, - mAccount, - cb.isChecked()); - getActivity().startService(observedFileIntent); - - /// immediate content synchronization - if (file.keepInSync()) { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); - } - } + /** * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced. @@ -392,7 +390,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener private void setFiletype(String mimetype, String filename) { TextView tv = (TextView) getView().findViewById(R.id.fdType); if (tv != null) { - String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);; + String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype); tv.setText(printableMimetype); } ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon);