Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,23 @@ The app is currently equipped to be built with three flavours:
[6]: https://developer.android.com/sdk/installing/index.html?pkg=studio
[7]: https://gradle.org/
[8]: https://docs.gradle.org/current/userguide/gradle_wrapper.html

### 5. How-To

#### 1. Direct usage of library project

This is handy if one wants to make changes both to files app and library:
- in files app root: ln -s $pathToLibraryProject nextcloud-android-library
- uncomment in build.gradle:
- `// implementation project('nextcloud-android-library')`
- comment in build.gradle:
- `genericImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'`
- `gplayImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'`
- `versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'`
- comment in settings.gradle:
- `include ':'`
- uncomment in settings.gradle:
- `//include 'nextcloud-android-library'`
- sync project with gradle files

Now every change in library can be directly used in files app.
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
435
434
2 changes: 1 addition & 1 deletion src/androidTest/java/com/owncloud/android/UploadIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class UploadIT extends AbstractIT {
public void setUp() {
final ContentResolver contentResolver = targetContext.getContentResolver();
final CurrentAccountProvider currentAccountProvider = () -> AccountUtils.getCurrentOwnCloudAccount(targetContext);
storageManager = new UploadsStorageManager(currentAccountProvider, contentResolver, targetContext);
storageManager = new UploadsStorageManager(currentAccountProvider, contentResolver);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.io.File;

import androidx.annotation.Nullable;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
Expand All @@ -36,7 +35,7 @@ public class UploadStorageManagerTest {
public void setUp() {
Context instrumentationCtx = InstrumentationRegistry.getTargetContext();
ContentResolver contentResolver = instrumentationCtx.getContentResolver();
uploadsStorageManager = new UploadsStorageManager(currentAccountProvider, contentResolver, instrumentationCtx);
uploadsStorageManager = new UploadsStorageManager(currentAccountProvider, contentResolver);
Accounts = new Account[]{new Account("A", "A"), new Account("B", "B")};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
public class UserAccountManagerImpl implements UserAccountManager {

private static final String TAG = AccountUtils.class.getSimpleName();
private static final String PREF_SELECT_OC_ACCOUNT = "select_oc_account";

private Context context;
private AccountManager accountManager;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/nextcloud/client/di/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ FilesRepository filesRepository(UserAccountManager accountManager) {
return new RemoteFilesRepository(new FilesServiceApiImpl(accountManager));
}

@Provides UploadsStorageManager uploadsStorageManager(Context context, CurrentAccountProvider currentAccountProvider) {
return new UploadsStorageManager(currentAccountProvider, context.getContentResolver(), context);
@Provides
UploadsStorageManager uploadsStorageManager(Context context,
CurrentAccountProvider currentAccountProvider) {
return new UploadsStorageManager(currentAccountProvider, context.getContentResolver());
}

@Provides CurrentAccountProvider currentAccountProvider(UserAccountManager accountManager) {
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ public class MainApp extends MultiDexApplication implements

private static final String TAG = MainApp.class.getSimpleName();

private static final String AUTH_ON = "on";

@SuppressWarnings("unused")
private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account";
@SuppressWarnings("unused")
private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client";

private static Context mContext;

private static String storagePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,14 @@
import android.accounts.AccountManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.OCFile;
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.UserInfo;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
import com.owncloud.android.ui.activity.ManageAccountsActivity;

import androidx.annotation.NonNull;
Expand All @@ -48,7 +40,6 @@
* Helper class for dealing with accounts.
*/
public final class AccountUtils {
private static final String TAG = AccountUtils.class.getSimpleName();
private static final String PREF_SELECT_OC_ACCOUNT = "select_oc_account";

public static final int ACCOUNT_VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1859,19 +1859,6 @@ public boolean onTouch(View view, MotionEvent event) {
public abstract boolean onDrawableTouch(final MotionEvent event);
}


private void getRemoteUserNameOperation(String sessionCookie) {

Intent getUserNameIntent = new Intent();
getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME);
getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);
getUserNameIntent.putExtra(OperationsService.EXTRA_COOKIE, sessionCookie);

if (mOperationsServiceBinder != null) {
mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getUserNameIntent);
}
}

/**
* Show untrusted cert dialog
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@

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;
Expand All @@ -66,7 +67,7 @@ protected RemoteOperationResult doInBackground(Object... params) {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
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();
Expand Down Expand Up @@ -264,7 +266,7 @@ public boolean saveFile(OCFile file) {
* @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()));

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ public String getRemotePath() {
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;
Expand Down Expand Up @@ -412,7 +412,7 @@ private void resetData() {
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

import androidx.annotation.NonNull;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;

/**
* Database provider for handling the persistence aspects of {@link SyncedFolder}s.
*/
Expand Down Expand Up @@ -251,7 +253,7 @@ public void updateAutoUploadPaths(Context context) {
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('/'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.accounts.Account;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

Expand Down Expand Up @@ -55,19 +54,16 @@ public class UploadsStorageManager extends Observable {
private static final int SINGLE_RESULT = 1;

private ContentResolver mContentResolver;
private Context mContext;
private CurrentAccountProvider currentAccountProvider;

public UploadsStorageManager(
CurrentAccountProvider currentAccountProvider,
ContentResolver contentResolver,
Context context
ContentResolver contentResolver
) {
if (contentResolver == null) {
throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
}
mContentResolver = contentResolver;
mContext = context;
this.currentAccountProvider = currentAccountProvider;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/owncloud/android/jobs/FilesSyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
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
Expand Down Expand Up @@ -190,7 +192,7 @@ private void syncFolder(Context context, Resources resources, boolean lightVersi
if (!subfolderByDate) {
String adaptedPath = file.getAbsolutePath()
.replace(syncedFolder.getLocalPath(), "")
.replace("/" + file.getName(), "");
.replace(PATH_SEPARATOR + file.getName(), "");
remotePath += adaptedPath;
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/owncloud/android/jobs/OfflineSyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.evernote.android.job.util.Device;
import com.nextcloud.client.account.UserAccountManager;
import com.owncloud.android.MainApp;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand All @@ -48,6 +47,9 @@

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";

Expand Down Expand Up @@ -90,7 +92,7 @@ protected Result onRunJob(@NonNull Params params) {
FileDataStorageManager storageManager = new FileDataStorageManager(account,
getContext().getContentResolver());

OCFile ocRoot = storageManager.getFileByPath("/");
OCFile ocRoot = storageManager.getFileByPath(ROOT_PATH);

if (ocRoot.getStoragePath() == null) {
break;
Expand All @@ -109,7 +111,7 @@ protected Result onRunJob(@NonNull Params params) {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
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.
Expand Down Expand Up @@ -99,13 +102,13 @@ private void saveFolderInDB() {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import com.nextcloud.client.account.UserAccountManager;
import com.owncloud.android.MainApp;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
Expand Down
Loading