|
@@ -48,6 +48,7 @@ import com.google.android.material.appbar.AppBarLayout;
|
|
|
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
+import com.nextcloud.android.lib.resources.files.ToggleFileLockRemoteOperation;
|
|
|
import com.nextcloud.android.lib.richWorkspace.RichWorkspaceDirectEditingRemoteOperation;
|
|
|
import com.nextcloud.client.account.User;
|
|
|
import com.nextcloud.client.account.UserAccountManager;
|
|
@@ -56,6 +57,7 @@ import com.nextcloud.client.di.Injectable;
|
|
|
import com.nextcloud.client.network.ClientFactory;
|
|
|
import com.nextcloud.client.preferences.AppPreferences;
|
|
|
import com.nextcloud.client.utils.Throttler;
|
|
|
+import com.nextcloud.common.NextcloudClient;
|
|
|
import com.owncloud.android.MainApp;
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
|
@@ -92,6 +94,7 @@ import com.owncloud.android.ui.events.ChangeMenuEvent;
|
|
|
import com.owncloud.android.ui.events.CommentsEvent;
|
|
|
import com.owncloud.android.ui.events.EncryptionEvent;
|
|
|
import com.owncloud.android.ui.events.FavoriteEvent;
|
|
|
+import com.owncloud.android.ui.events.FileLockEvent;
|
|
|
import com.owncloud.android.ui.events.SearchEvent;
|
|
|
import com.owncloud.android.ui.helpers.FileOperationsHelper;
|
|
|
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface;
|
|
@@ -1146,6 +1149,10 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|
|
} else if (itemId == R.id.action_unset_encrypted) {
|
|
|
mContainerActivity.getFileOperationsHelper().toggleEncryption(singleFile, false);
|
|
|
return true;
|
|
|
+ } else if (itemId == R.id.action_lock_file) {
|
|
|
+ mContainerActivity.getFileOperationsHelper().toggleFileLock(singleFile, true);
|
|
|
+ } else if (itemId == R.id.action_unlock_file) {
|
|
|
+ mContainerActivity.getFileOperationsHelper().toggleFileLock(singleFile, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1192,6 +1199,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|
|
} else if (itemId == R.id.action_send_file) {
|
|
|
mContainerActivity.getFileOperationsHelper().sendFiles(checkedFiles);
|
|
|
return true;
|
|
|
+ } else if (itemId == R.id.action_lock_file) {
|
|
|
+ // TODO call lock API
|
|
|
}
|
|
|
|
|
|
return false;
|
|
@@ -1642,6 +1651,35 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Subscribe(threadMode = ThreadMode.BACKGROUND)
|
|
|
+ public void onMessageEvent(FileLockEvent event) {
|
|
|
+ final User user = accountManager.getUser();
|
|
|
+
|
|
|
+ try {
|
|
|
+ new Handler(Looper.getMainLooper()).post(() -> setLoading(true));
|
|
|
+ NextcloudClient client = clientFactory.createNextcloudClient(user);
|
|
|
+ ToggleFileLockRemoteOperation operation = new ToggleFileLockRemoteOperation(event.getShouldLock(), event.getFilePath());
|
|
|
+ RemoteOperationResult<Void> result = operation.execute(client);
|
|
|
+
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ // TODO only refresh the modified file?
|
|
|
+ new Handler(Looper.getMainLooper()).post(this::onRefresh);
|
|
|
+ } else {
|
|
|
+ Snackbar.make(getRecyclerView(),
|
|
|
+ R.string.error_file_lock,
|
|
|
+ Snackbar.LENGTH_LONG).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (ClientFactory.CreationException e) {
|
|
|
+ Log_OC.e(TAG, "Cannot create client", e);
|
|
|
+ Snackbar.make(getRecyclerView(),
|
|
|
+ R.string.error_file_lock,
|
|
|
+ Snackbar.LENGTH_LONG).show();
|
|
|
+ } finally {
|
|
|
+ new Handler(Looper.getMainLooper()).post(() -> setLoading(false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
protected void setTitle(@StringRes final int title) {
|
|
|
setTitle(getContext().getString(title));
|
|
|
}
|