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.
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);
@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);
mView = inflater.inflate(mLayout, null);
if (mLayout == R.layout.file_details_fragment) {
- mView.findViewById(R.id.fdKeepInSync).setOnClickListener(this);
+ mView.findViewById(R.id.fdFavorite).setOnClickListener(this);
ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.fdProgressBar);
+ DisplayUtils.colorPreLollipopHorizontalProgressBar(progressBar);
mProgressListener = new ProgressListener(progressBar);
mView.findViewById(R.id.fdCancelBtn).setOnClickListener(this);
}
}
return true;
}
+ case R.id.action_favorite_file:{
+ mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), true);
+ return true;
+ }
+ case R.id.action_unfavorite_file:{
+ mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), false);
+ return true;
+ }
default:
return false;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
- case R.id.fdKeepInSync: {
- toggleKeepInSync();
+ case R.id.fdFavorite: {
+ CheckBox cb = (CheckBox) getView().findViewById(R.id.fdFavorite);
+ mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(),cb.isChecked());
break;
}
case R.id.fdCancelBtn: {
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.
setTimeModified(file.getModificationTimestamp());
- CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);
- cb.setChecked(file.keepInSync());
+ CheckBox cb = (CheckBox)getView().findViewById(R.id.fdFavorite);
+ cb.setChecked(file.isFavorite());
// configure UI for depending upon local state of the file
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
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);
private void setButtonsForTransferring() {
if (!isEmpty()) {
// let's protect the user from himself ;)
- getView().findViewById(R.id.fdKeepInSync).setEnabled(false);
+ getView().findViewById(R.id.fdFavorite).setEnabled(false);
// show the progress bar for the transfer
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE);
*/
private void setButtonsForDown() {
if (!isEmpty()) {
- getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
+ getView().findViewById(R.id.fdFavorite).setEnabled(true);
// hides the progress bar
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
*/
private void setButtonsForRemote() {
if (!isEmpty()) {
- getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
+ getView().findViewById(R.id.fdFavorite).setEnabled(true);
// hides the progress bar
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);