Merge pull request #3915 from jmue/cleanup/ocfile

use path separator constant
This commit is contained in:
Tobias Kaminsky 2019-04-18 07:54:56 +02:00 committed by GitHub
commit b22f517029
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 72 additions and 51 deletions

View file

@ -34,13 +34,14 @@ import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
import java.lang.ref.WeakReference;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
/**
* Async Task to verify the credentials of a user
*/
public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOperationResult> {
private static final String REMOTE_PATH = "/";
private static final boolean SUCCESS_IF_ABSENT = false;
private WeakReference<Context> mWeakContext;
@ -66,7 +67,7 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
client.setCredentials(credentials);
// Operation - try credentials
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(REMOTE_PATH, SUCCESS_IF_ABSENT);
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(ROOT_PATH, SUCCESS_IF_ABSENT);
result = operation.execute(client);
if (operation.wasRedirected()) {

View file

@ -67,6 +67,8 @@ import androidx.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
@Getter
public class FileDataStorageManager {
private static final String TAG = FileDataStorageManager.class.getSimpleName();
@ -264,7 +266,7 @@ public class FileDataStorageManager {
* @return the parent file
*/
public OCFile saveFileWithParent(OCFile file, Context context) {
if (file.getParentId() == 0 && !"/".equals(file.getRemotePath())) {
if (file.getParentId() == 0 && !ROOT_PATH.equals(file.getRemotePath())) {
String remotePath = file.getRemotePath();
String parentPath = remotePath.substring(0, remotePath.lastIndexOf(file.getFileName()));

View file

@ -199,17 +199,17 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
if (isEncrypted() && !isFolder()) {
String parentPath = new File(remotePath).getParent();
if (parentPath.endsWith("/")) {
if (parentPath.endsWith(PATH_SEPARATOR)) {
return parentPath + getEncryptedFileName();
} else {
return parentPath + "/" + getEncryptedFileName();
return parentPath + PATH_SEPARATOR + getEncryptedFileName();
}
} else {
if (isFolder()) {
if (remotePath.endsWith("/")) {
if (remotePath.endsWith(PATH_SEPARATOR)) {
return remotePath;
} else {
return remotePath + "/";
return remotePath + PATH_SEPARATOR;
}
} else {
return remotePath;
@ -412,7 +412,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
*/
public String getParentRemotePath() {
String parentPath = new File(this.getRemotePath()).getParent();
return parentPath.endsWith("/") ? parentPath : parentPath + "/";
return parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
}
@Override

View file

@ -39,6 +39,8 @@ import java.util.Observable;
import androidx.annotation.NonNull;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
/**
* Database provider for handling the persistence aspects of {@link SyncedFolder}s.
*/
@ -251,7 +253,7 @@ public class SyncedFolderProvider extends Observable {
for (SyncedFolder syncedFolder : syncedFolders) {
if (!new File(syncedFolder.getLocalPath()).exists()) {
String localPath = syncedFolder.getLocalPath();
if (localPath.endsWith("/")) {
if (localPath.endsWith(PATH_SEPARATOR)) {
localPath = localPath.substring(0, localPath.lastIndexOf('/'));
}
localPath = localPath.substring(0, localPath.lastIndexOf('/'));

View file

@ -64,6 +64,8 @@ import java.util.TimeZone;
import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
/*
Job that:
- restarts existing jobs if required
@ -190,7 +192,7 @@ public class FilesSyncJob extends Job {
if (!subfolderByDate) {
String adaptedPath = file.getAbsolutePath()
.replace(syncedFolder.getLocalPath(), "")
.replace("/" + file.getName(), "");
.replace(PATH_SEPARATOR + file.getName(), "");
remotePath += adaptedPath;
}

View file

@ -48,6 +48,9 @@ import java.util.Set;
import androidx.annotation.NonNull;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
public class OfflineSyncJob extends Job {
public static final String TAG = "OfflineSyncJob";
@ -90,7 +93,7 @@ public class OfflineSyncJob extends Job {
FileDataStorageManager storageManager = new FileDataStorageManager(account,
getContext().getContentResolver());
OCFile ocRoot = storageManager.getFileByPath("/");
OCFile ocRoot = storageManager.getFileByPath(ROOT_PATH);
if (ocRoot.getStoragePath() == null) {
break;
@ -109,7 +112,7 @@ public class OfflineSyncJob extends Job {
private void recursive(File folder, FileDataStorageManager storageManager, Account account) {
String downloadFolder = FileStorageUtils.getSavePath(account.name);
String folderName = folder.getAbsolutePath().replaceFirst(downloadFolder, "") + "/";
String folderName = folder.getAbsolutePath().replaceFirst(downloadFolder, "") + PATH_SEPARATOR;
Log_OC.d(TAG, folderName + ": enter");
// exit

View file

@ -34,6 +34,9 @@ import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeType;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
/**
* Access to remote operation performing the creation of a new folder in the ownCloud server.
@ -99,13 +102,13 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
getFileByPath(FileStorageUtils.getParentPath(mRemotePath)) == null){// When parent
// of remote path
// is not created
String[] subFolders = mRemotePath.split("/");
String composedRemotePath = "/";
String[] subFolders = mRemotePath.split(PATH_SEPARATOR);
String composedRemotePath = ROOT_PATH;
// For each ancestor folders create them recursively
for (String subFolder : subFolders) {
if (!subFolder.isEmpty()) {
composedRemotePath = composedRemotePath + subFolder + "/";
composedRemotePath = composedRemotePath + subFolder + PATH_SEPARATOR;
mRemotePath = composedRemotePath;
saveFolderInDB();
}

View file

@ -89,6 +89,9 @@ import javax.inject.Inject;
import dagger.android.AndroidInjection;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
@TargetApi(Build.VERSION_CODES.KITKAT)
public class DocumentsStorageProvider extends DocumentsProvider {
@ -396,7 +399,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
String newPath = targetFolder.getRemotePath() + file.getFileName();
if (file.isFolder()) {
newPath = newPath + "/";
newPath = newPath + PATH_SEPARATOR;
}
OCFile newFile = currentStorageManager.getFileByPath(newPath);
@ -438,7 +441,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
public Cursor querySearchDocuments(String rootId, String query, String[] projection) {
updateCurrentStorageManagerIfNeeded(rootId);
OCFile root = currentStorageManager.getFileByPath("/");
OCFile root = currentStorageManager.getFileByPath(ROOT_PATH);
FileCursor result = new FileCursor(projection);
for (OCFile f : findFiles(root, query)) {
@ -469,7 +472,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
private String createFolder(OCFile parent, String displayName, String documentId) throws FileNotFoundException {
CreateFolderOperation createFolderOperation = new CreateFolderOperation(parent.getRemotePath() + displayName
+ "/", true);
+ PATH_SEPARATOR, true);
RemoteOperationResult result = createFolderOperation.execute(client, currentStorageManager);
@ -479,7 +482,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
}
String newDirPath = parent.getRemotePath() + displayName + "/";
String newDirPath = parent.getRemotePath() + displayName + PATH_SEPARATOR;
OCFile newFolder = currentStorageManager.getFileByPath(newDirPath);
return String.valueOf(newFolder.getFileId());
@ -601,7 +604,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
for (Account account : accountManager.getAccounts()) {
final FileDataStorageManager storageManager = new FileDataStorageManager(account, contentResolver);
final OCFile rootDir = storageManager.getFileByPath("/");
final OCFile rootDir = storageManager.getFileByPath(ROOT_PATH);
rootIdToStorageManager.put(rootDir.getFileId(), storageManager);
}
}

View file

@ -148,6 +148,8 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
/**
* Displays, what files the user has available in his ownCloud. This is the main view.
*/
@ -983,7 +985,7 @@ public class FileDisplayActivity extends FileActivity
if (hasEnoughSpaceAvailable) {
File file = new File(filesToUpload[0]);
File renamedFile = new File(file.getParent() + "/" + FileOperationsHelper.getCapturedImageName());
File renamedFile = new File(file.getParent() + PATH_SEPARATOR + FileOperationsHelper.getCapturedImageName());
if (!file.renameTo(renamedFile)) {
DisplayUtils.showSnackMessage(getActivity(), "Fail to upload taken image!");

View file

@ -123,6 +123,9 @@ import java.util.Vector;
import javax.inject.Inject;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
/**
* This can be used to upload things to an ownCloud instance.
*/
@ -174,7 +177,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
String parentPath = savedInstanceState.getString(KEY_PARENTS);
if (parentPath != null) {
mParents.addAll(Arrays.asList(parentPath.split("/")));
mParents.addAll(Arrays.asList(parentPath.split(PATH_SEPARATOR)));
}
mFile = savedInstanceState.getParcelable(KEY_FILE);
@ -884,7 +887,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
String full_path = "";
for (String a : dirs) {
full_path += a + "/";
full_path += a + PATH_SEPARATOR;
}
return full_path;
}
@ -1034,10 +1037,10 @@ public class ReceiveExternalFilesActivity extends FileActivity
if (mParents.empty()) {
String lastPath = preferences.getLastUploadPath();
// "/" equals root-directory
if ("/".equals(lastPath)) {
if (ROOT_PATH.equals(lastPath)) {
mParents.add("");
} else {
String[] dir_names = lastPath.split("/");
String[] dir_names = lastPath.split(PATH_SEPARATOR);
mParents.clear();
mParents.addAll(Arrays.asList(dir_names));
}

View file

@ -51,6 +51,9 @@ import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
/**
* Adapter for the trashbin view
*/
@ -134,9 +137,9 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
String location;
int lastIndex = file.getOriginalLocation().lastIndexOf('/');
if (lastIndex != -1) {
location = "/" + file.getOriginalLocation().substring(0, lastIndex) + "/";
location = ROOT_PATH + file.getOriginalLocation().substring(0, lastIndex) + PATH_SEPARATOR;
} else {
location = "/";
location = ROOT_PATH;
}
trashbinFileViewHolder.originalLocation.setText(location);

View file

@ -30,6 +30,8 @@ import com.google.android.material.textfield.TextInputEditText;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
/**
* Custom edit text to support fixed suffix or prefix
*/
@ -45,7 +47,7 @@ public class CustomEditText extends TextInputEditText {
if (AuthenticatorActivity.DIRECTORY_SERVER_INPUT_TYPE.equals(serverInputType)) {
isPrefixFixed = true;
fixedText = getResources().getString(R.string.server_url) + "/";
fixedText = getResources().getString(R.string.server_url) + PATH_SEPARATOR;
} else if (AuthenticatorActivity.SUBDOMAIN_SERVER_INPUT_TYPE.equals(serverInputType)) {
isPrefixFixed = false;
fixedText = "." + getResources().getString(R.string.server_url);
@ -56,18 +58,6 @@ public class CustomEditText extends TextInputEditText {
}
}
public String getFullServerUrl() {
if (TextUtils.isEmpty(fixedText)
|| getText().toString().startsWith(AuthenticatorActivity.HTTP_PROTOCOL)
|| getText().toString().startsWith(AuthenticatorActivity.HTTPS_PROTOCOL)) {
return getText().toString();
} else if (isPrefixFixed) {
return getResources().getString(R.string.server_url) + "/" + getText().toString();
} else {
return getText().toString() + "." + getResources().getString(R.string.server_url);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (!TextUtils.isEmpty(fixedText)) {

View file

@ -129,6 +129,8 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
/**
* A Fragment that lists all files and folders in a given path.
* TODO refactor to get rid of direct dependency on FileDisplayActivity
@ -796,7 +798,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
parentDir = storageManager.getFileByPath(parentPath);
moveCount++;
} else {
parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH);
parentDir = storageManager.getFileByPath(ROOT_PATH);
}
while (parentDir == null) {
parentPath = new File(parentPath).getParent();
@ -1140,7 +1142,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
if (mFile != null) {
directory = mFile;
} else {
directory = storageManager.getFileByPath("/");
directory = storageManager.getFileByPath(ROOT_PATH);
if (directory == null) {
return; // no files, wait for sync
}

View file

@ -26,6 +26,8 @@ import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
import java.io.File;
import java.util.List;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
/**
* Coordinates between model and view: querying model, updating view, react to UI input
*/
@ -33,7 +35,7 @@ public class TrashbinPresenter implements TrashbinContract.Presenter {
private TrashbinContract.View trashbinView;
private TrashbinRepository trashbinRepository;
private String currentPath = "/";
private String currentPath = ROOT_PATH;
public TrashbinPresenter(TrashbinRepository trashbinRepository, TrashbinContract.View trashbinView) {
this.trashbinRepository = trashbinRepository;
@ -48,12 +50,12 @@ public class TrashbinPresenter implements TrashbinContract.Presenter {
@Override
public boolean isRoot() {
return !"/".equals(currentPath);
return !ROOT_PATH.equals(currentPath);
}
@Override
public void navigateUp() {
if ("/".equals(currentPath)) {
if (ROOT_PATH.equals(currentPath)) {
trashbinView.close();
} else {
currentPath = new File(currentPath).getParent();
@ -61,7 +63,7 @@ public class TrashbinPresenter implements TrashbinContract.Presenter {
loadFolder();
}
trashbinView.setDrawerIndicatorEnabled("/".equals(currentPath));
trashbinView.setDrawerIndicatorEnabled(ROOT_PATH.equals(currentPath));
}
@Override

View file

@ -68,6 +68,8 @@ import java.util.concurrent.TimeUnit;
import androidx.annotation.RequiresApi;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
/**
* Various utilities that make auto upload tick
*/
@ -188,11 +190,10 @@ public final class FilesSyncHelper {
String[] projection = {MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DATE_MODIFIED};
String path = syncedFolder.getLocalPath();
if (!path.endsWith("/")) {
path = path + "/%";
} else {
path = path + "%";
if (!path.endsWith(PATH_SEPARATOR)) {
path = path + PATH_SEPARATOR;
}
path = path + "%";
String syncedFolderInitiatedKey = SYNCEDFOLDERINITIATED + syncedFolder.getId();
String dateInitiated = arbitraryDataProvider.getValue(GLOBAL, syncedFolderInitiatedKey);

View file

@ -31,6 +31,8 @@ import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
@TargetApi(Build.VERSION_CODES.KITKAT)
public class RootCursor extends MatrixCursor {
@ -47,7 +49,7 @@ public class RootCursor extends MatrixCursor {
public void addRoot(Account account, Context context) {
final FileDataStorageManager manager = new FileDataStorageManager(account, context.getContentResolver());
final OCFile mainDir = manager.getFileByPath("/");
final OCFile mainDir = manager.getFileByPath(ROOT_PATH);
newRow().add(Root.COLUMN_ROOT_ID, account.name)
.add(Root.COLUMN_DOCUMENT_ID, mainDir.getFileId())