mirror of
https://github.com/nextcloud/android.git
synced 2024-11-30 08:00:29 +03:00
get direct editing info from endpoint
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
b31cee531b
commit
994817ce97
8 changed files with 72 additions and 23 deletions
|
@ -37,6 +37,9 @@ import androidx.annotation.NonNull;
|
|||
* Database provider for handling the persistence aspects of arbitrary data table.
|
||||
*/
|
||||
public class ArbitraryDataProvider {
|
||||
public static final String DIRECT_EDITING = "DIRECT_EDITING";
|
||||
public static final String DIRECT_EDITING_ETAG = "DIRECT_EDITING_ETAG";
|
||||
|
||||
private static final String TAG = ArbitraryDataProvider.class.getSimpleName();
|
||||
private static final String TRUE = "true";
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.JsonSyntaxException;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
|
||||
import com.owncloud.android.lib.common.DirectEditing;
|
||||
import com.owncloud.android.lib.common.network.WebdavEntry;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
@ -2031,7 +2030,7 @@ public class FileDataStorageManager {
|
|||
cv.put(ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES, capability.getRichDocumentsTemplatesAvailable()
|
||||
.getValue());
|
||||
cv.put(ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME, capability.getRichDocumentsProductName());
|
||||
cv.put(ProviderTableMeta.CAPABILITIES_DIRECT_EDITING, new Gson().toJson(capability.getDirectEditing()));
|
||||
cv.put(ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG, capability.getDirectEditingEtag());
|
||||
|
||||
return cv;
|
||||
}
|
||||
|
@ -2151,8 +2150,7 @@ public class FileDataStorageManager {
|
|||
}
|
||||
capability.setRichDocumentsOptionalMimeTypeList(Arrays.asList(optionalMimetypes.split(",")));
|
||||
capability.setRichDocumentsProductName(getString(c, ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME));
|
||||
capability.setDirectEditing(new Gson().fromJson(getString(c, ProviderTableMeta.CAPABILITIES_DIRECT_EDITING),
|
||||
DirectEditing.class));
|
||||
capability.setDirectEditingEtag(getString(c, ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG));
|
||||
}
|
||||
return capability;
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ public class ProviderMeta {
|
|||
public static final String CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME = "richdocument_product_name";
|
||||
public static final String CAPABILITIES_DEFAULT_SORT_ORDER = CAPABILITIES_ACCOUNT_NAME
|
||||
+ " collate nocase asc";
|
||||
public static final String CAPABILITIES_DIRECT_EDITING = "direct_editing";
|
||||
public static final String CAPABILITIES_DIRECT_EDITING_ETAG = "direct_editing_etag";
|
||||
|
||||
//Columns of Uploads table
|
||||
public static final String UPLOADS_LOCAL_PATH = "local_path";
|
||||
|
|
|
@ -22,11 +22,14 @@
|
|||
package com.owncloud.android.files;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||
|
@ -261,15 +264,23 @@ public class FileMenuFilter {
|
|||
) {
|
||||
String mimeType = mFiles.iterator().next().getMimeType();
|
||||
|
||||
if (isRichDocumentEditingSupported(capability, mimeType) || isEditorAvailable(capability, mimeType)) {
|
||||
if (isRichDocumentEditingSupported(capability, mimeType) || isEditorAvailable(mContext.getContentResolver(),
|
||||
mAccount,
|
||||
mimeType)) {
|
||||
toShow.add(R.id.action_edit);
|
||||
} else {
|
||||
toHide.add(R.id.action_edit);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEditorAvailable(OCCapability capability, String mimeType) {
|
||||
DirectEditing directEditing = capability.getDirectEditing();
|
||||
public static boolean isEditorAvailable(ContentResolver contentResolver, Account account, String mimeType) {
|
||||
String json = new ArbitraryDataProvider(contentResolver).getValue(account, ArbitraryDataProvider.DIRECT_EDITING);
|
||||
|
||||
if (json.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DirectEditing directEditing = new Gson().fromJson(json, DirectEditing.class);
|
||||
|
||||
for (Editor editor : directEditing.editors.values()) {
|
||||
if (editor.mimetypes.contains(mimeType) || editor.optionalMimetypes.contains(mimeType)) {
|
||||
|
|
|
@ -24,9 +24,13 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.nextcloud.android.lib.resources.directediting.DirectEditingObtainRemoteOperation;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.DecryptedFolderMetadata;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.DirectEditing;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
|
@ -275,13 +279,39 @@ public class RefreshFolderOperation extends RemoteOperation {
|
|||
}
|
||||
|
||||
private void updateCapabilities() {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver());
|
||||
String oldDirectEditingEtag = arbitraryDataProvider.getValue(mAccount,
|
||||
ArbitraryDataProvider.DIRECT_EDITING_ETAG);
|
||||
|
||||
GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation();
|
||||
RemoteOperationResult result = getCapabilities.execute(mStorageManager, mContext);
|
||||
if (!result.isSuccess()) {
|
||||
if (result.isSuccess()) {
|
||||
String newDirectEditingEtag = mStorageManager.getCapability(mAccount.name).getDirectEditingEtag();
|
||||
|
||||
if (!oldDirectEditingEtag.equalsIgnoreCase(newDirectEditingEtag)) {
|
||||
updateDirectEditing(arbitraryDataProvider, newDirectEditingEtag);
|
||||
}
|
||||
} else {
|
||||
Log_OC.w(TAG, "Update Capabilities unsuccessfully");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDirectEditing(ArbitraryDataProvider arbitraryDataProvider, String newDirectEditingEtag) {
|
||||
RemoteOperationResult result = new DirectEditingObtainRemoteOperation().execute(mAccount, mContext);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
DirectEditing directEditing = (DirectEditing) result.getSingleData();
|
||||
String json = new Gson().toJson(directEditing);
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, ArbitraryDataProvider.DIRECT_EDITING, json);
|
||||
} else {
|
||||
arbitraryDataProvider.deleteKeyForAccount(mAccount.name, ArbitraryDataProvider.DIRECT_EDITING);
|
||||
}
|
||||
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name,
|
||||
ArbitraryDataProvider.DIRECT_EDITING_ETAG,
|
||||
newDirectEditingEtag);
|
||||
}
|
||||
|
||||
private RemoteOperationResult checkForChanges(OwnCloudClient client) {
|
||||
mRemoteFolderChanged = true;
|
||||
RemoteOperationResult result;
|
||||
|
|
|
@ -53,6 +53,7 @@ import com.nextcloud.client.preferences.AppPreferences;
|
|||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
|
@ -163,7 +164,11 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|||
|
||||
boolean isLoading = false;
|
||||
if (parentFolder.isExpired()) {
|
||||
final ReloadFolderDocumentTask task = new ReloadFolderDocumentTask(parentFolder, result -> {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
|
||||
|
||||
final ReloadFolderDocumentTask task = new ReloadFolderDocumentTask(arbitraryDataProvider,
|
||||
parentFolder,
|
||||
result -> {
|
||||
getContext().getContentResolver().notifyChange(toNotifyUri(parentFolder), null, false);
|
||||
});
|
||||
task.executeOnExecutor(executor);
|
||||
|
@ -309,7 +314,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|||
}
|
||||
|
||||
Document document = toDocument(documentId);
|
||||
|
||||
|
||||
boolean exists = ThumbnailsCacheManager.containsBitmap(ThumbnailsCacheManager.PREFIX_THUMBNAIL
|
||||
+ document.getFile().getRemoteId());
|
||||
|
||||
|
@ -692,10 +697,14 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|||
|
||||
private final Document folder;
|
||||
private final OnTaskFinishedCallback callback;
|
||||
private final ArbitraryDataProvider arbitraryDataProvider;
|
||||
|
||||
ReloadFolderDocumentTask(Document folder, OnTaskFinishedCallback callback) {
|
||||
ReloadFolderDocumentTask(ArbitraryDataProvider arbitraryDataProvider,
|
||||
Document folder,
|
||||
OnTaskFinishedCallback callback) {
|
||||
this.folder = folder;
|
||||
this.callback = callback;
|
||||
this.arbitraryDataProvider = arbitraryDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -790,7 +790,7 @@ public class FileContentProvider extends ContentProvider {
|
|||
+ ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + TEXT
|
||||
+ ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD + INTEGER
|
||||
+ ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME + TEXT
|
||||
+ ProviderTableMeta.CAPABILITIES_DIRECT_EDITING + " TEXT );");
|
||||
+ ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + " TEXT );");
|
||||
}
|
||||
|
||||
private void createUploadsTable(SQLiteDatabase db) {
|
||||
|
@ -2067,11 +2067,11 @@ public class FileContentProvider extends ContentProvider {
|
|||
}
|
||||
|
||||
if (oldVersion < 52 && newVersion >= 52) {
|
||||
Log_OC.i(SQL, "Entering in the #52 add directEditing to capability");
|
||||
Log_OC.i(SQL, "Entering in the #52 add etag for directEditing to capability");
|
||||
db.beginTransaction();
|
||||
try {
|
||||
db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
|
||||
ADD_COLUMN + ProviderTableMeta.CAPABILITIES_DIRECT_EDITING + " TEXT ");
|
||||
ADD_COLUMN + ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + " TEXT ");
|
||||
|
||||
upgraded = true;
|
||||
db.setTransactionSuccessful();
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -60,9 +58,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
|
|||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||
import com.owncloud.android.files.FileMenuFilter;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
@ -108,7 +104,6 @@ import org.greenrobot.eventbus.ThreadMode;
|
|||
import org.parceler.Parcels;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
@ -954,7 +949,9 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
.isMediaStreamingSupported()) {
|
||||
// stream media preview on >= NC14
|
||||
((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, true);
|
||||
} else if (FileMenuFilter.isEditorAvailable(capability, file.getMimeType())) {
|
||||
} else if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(),
|
||||
account.toPlatformAccount(),
|
||||
file.getMimeType())) {
|
||||
mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(file, getContext());
|
||||
} else if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) &&
|
||||
android.os.Build.VERSION.SDK_INT >= RichDocumentsEditorWebView.MINIMUM_API &&
|
||||
|
@ -1024,9 +1021,10 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
case R.id.action_edit: {
|
||||
Account account = ((FileActivity) mContainerActivity).getUserAccountManager()
|
||||
.getUser().toPlatformAccount();
|
||||
OCCapability ocCapability = mContainerActivity.getStorageManager().getCapability(account.name);
|
||||
|
||||
if (FileMenuFilter.isEditorAvailable(ocCapability, singleFile.getMimeType())) {
|
||||
if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(),
|
||||
account,
|
||||
singleFile.getMimeType())) {
|
||||
mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(singleFile, getContext());
|
||||
} else {
|
||||
mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(singleFile, getContext());
|
||||
|
|
Loading…
Reference in a new issue