add the action in the context menu

This commit is contained in:
purigarcia 2015-07-08 10:17:27 +02:00
parent 684104ccb8
commit f226b5f93a
3 changed files with 32 additions and 3 deletions

View file

@ -40,6 +40,7 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.dialog.ShareLinkToDialog;
@ -223,6 +224,25 @@ public class FileOperationsHelper {
mFileActivity.startService(intent);
}
}
public void toggleKeepInSync(OCFile file, boolean isFavorite) {
Log_OC.e(TAG, "KeepInSync");
file.setKeepInSync(isFavorite);
mFileActivity.getStorageManager().saveFile(file);
/// register the OCFile instance in the observer service to monitor local updates
Intent observedFileIntent = FileObserverService.makeObservedFileIntent(
mFileActivity,
file,
mFileActivity.getAccount(),
isFavorite);
mFileActivity.startService(observedFileIntent);
/// immediate content synchronization
if (file.keepInSync()) {
syncFile(file);
}
}
public void renameFile(OCFile file, String newFilename) {
// RenameFile

View file

@ -282,6 +282,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
private void toggleKeepInSync() {
Log_OC.e(TAG, "toggleKeepInSync");
CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
OCFile file = getFile();
file.setKeepInSync(cb.isChecked());

View file

@ -42,6 +42,7 @@ import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.FolderPickerActivity;
@ -341,6 +342,14 @@ public class OCFileListFragment extends ExtendedListFragment {
getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_MOVE_FILES);
return true;
}
case R.id.action_favorite_file:{
mContainerActivity.getFileOperationsHelper().toggleKeepInSync(mTargetFile, true);
return true;
}
case R.id.action_unfavorite_file:{
mContainerActivity.getFileOperationsHelper().toggleKeepInSync(mTargetFile, false);
return true;
}
default:
return super.onContextItemSelected(item);
}
@ -492,8 +501,7 @@ public class OCFileListFragment extends ExtendedListFragment {
public void sortBySize(boolean descending) {
mAdapter.setSortOrder(FileStorageUtils.SORT_SIZE, descending);
}
}
}