Search in sources :

Example 1 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class MainApp method updateAutoUploadEntries.

private static void updateAutoUploadEntries(Clock clock) {
    // updates entries to reflect their true paths
    Context context = getAppContext();
    AppPreferences preferences = AppPreferencesImpl.fromContext(context);
    if (!preferences.isAutoUploadPathsUpdateEnabled()) {
        SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(MainApp.getAppContext().getContentResolver(), preferences, clock);
        syncedFolderProvider.updateAutoUploadPaths(mContext);
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(android.content.Context) AppPreferences(com.nextcloud.client.preferences.AppPreferences) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider)

Example 2 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class MainApp method splitOutAutoUploadEntries.

private static void splitOutAutoUploadEntries(Clock clock) {
    Context context = getAppContext();
    AppPreferences preferences = AppPreferencesImpl.fromContext(context);
    if (!preferences.isAutoUploadSplitEntriesEnabled()) {
        // magic to split out existing synced folders in two when needed
        // otherwise, we migrate them to their proper type (image or video)
        Log_OC.i(TAG, "Migrate synced_folders records for image/video split");
        ContentResolver contentResolver = context.getContentResolver();
        SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver, preferences, clock);
        final List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1, null, true);
        final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1, null, true);
        ArrayList<Long> idsToDelete = new ArrayList<>();
        List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
        long primaryKey;
        SyncedFolder newSyncedFolder;
        for (SyncedFolder syncedFolder : syncedFolders) {
            idsToDelete.add(syncedFolder.getId());
            Log_OC.i(TAG, "Migration check for synced_folders record: " + syncedFolder.getId() + " - " + syncedFolder.getLocalPath());
            for (MediaFolder imageMediaFolder : imageMediaFolders) {
                if (imageMediaFolder.absolutePath.equals(syncedFolder.getLocalPath())) {
                    newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                    newSyncedFolder.setType(MediaFolderType.IMAGE);
                    primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                    Log_OC.i(TAG, "Migrated image synced_folders record: " + primaryKey + " - " + newSyncedFolder.getLocalPath());
                    break;
                }
            }
            for (MediaFolder videoMediaFolder : videoMediaFolders) {
                if (videoMediaFolder.absolutePath.equals(syncedFolder.getLocalPath())) {
                    newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                    newSyncedFolder.setType(MediaFolderType.VIDEO);
                    primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                    Log_OC.i(TAG, "Migrated video synced_folders record: " + primaryKey + " - " + newSyncedFolder.getLocalPath());
                    break;
                }
            }
        }
        for (long id : idsToDelete) {
            Log_OC.i(TAG, "Removing legacy synced_folders record: " + id);
            syncedFolderProvider.deleteSyncedFolder(id);
        }
        preferences.setAutoUploadSplitEntriesEnabled(true);
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(android.content.Context) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) AppPreferences(com.nextcloud.client.preferences.AppPreferences) ArrayList(java.util.ArrayList) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) MediaFolder(com.owncloud.android.datamodel.MediaFolder) ContentResolver(android.content.ContentResolver)

Example 3 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class DocumentsStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) {
    // always recreate storage manager collection, as it will change after account creation/removal
    // and we need to serve document(tree)s with persist permissions
    initiateStorageMap();
    Context context = MainApp.getAppContext();
    AppPreferences preferences = AppPreferencesImpl.fromContext(context);
    if (SettingsActivity.LOCK_PASSCODE.equals(preferences.getLockPreference()) || SettingsActivity.LOCK_DEVICE_CREDENTIALS.equals(preferences.getLockPreference())) {
        return new FileCursor();
    }
    final RootCursor result = new RootCursor(projection);
    for (int i = 0; i < rootIdToStorageManager.size(); i++) {
        result.addRoot(new Document(rootIdToStorageManager.valueAt(i), ROOT_PATH), getContext());
    }
    return result;
}
Also used : Context(android.content.Context) FileCursor(org.nextcloud.providers.cursors.FileCursor) AppPreferences(com.nextcloud.client.preferences.AppPreferences) RootCursor(org.nextcloud.providers.cursors.RootCursor) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 4 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class SyncedFolderProvider method updateAutoUploadPaths.

/**
 * Try to figure out if a path exists for synced folder, and if not, go one folder back
 * Otherwise, delete the entry
 *
 * @param context the context.
 */
public void updateAutoUploadPaths(Context context) {
    List<SyncedFolder> syncedFolders = getSyncedFolders();
    for (SyncedFolder syncedFolder : syncedFolders) {
        if (!new File(syncedFolder.getLocalPath()).exists()) {
            String localPath = syncedFolder.getLocalPath();
            if (localPath.endsWith(PATH_SEPARATOR)) {
                localPath = localPath.substring(0, localPath.lastIndexOf('/'));
            }
            localPath = localPath.substring(0, localPath.lastIndexOf('/'));
            if (new File(localPath).exists()) {
                syncedFolder.setLocalPath(localPath);
                updateSyncFolder(syncedFolder);
            } else {
                deleteSyncFolderWithId(syncedFolder.getId());
            }
        }
    }
    if (context != null) {
        AppPreferences preferences = AppPreferencesImpl.fromContext(context);
        preferences.setAutoUploadPathsUpdateEnabled(true);
    }
}
Also used : AppPreferences(com.nextcloud.client.preferences.AppPreferences) File(java.io.File)

Example 5 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class UserAccountManagerImplTest method updateOneAccount.

@Test
public void updateOneAccount() {
    AppPreferences appPreferences = AppPreferencesImpl.fromContext(targetContext);
    UserAccountManagerImpl sut = new UserAccountManagerImpl(targetContext, accountManager);
    assertEquals(1, sut.getAccounts().length);
    assertFalse(appPreferences.isUserIdMigrated());
    Account account = sut.getAccounts()[0];
    // for testing remove userId
    accountManager.setUserData(account, AccountUtils.Constants.KEY_USER_ID, null);
    assertNull(accountManager.getUserData(account, AccountUtils.Constants.KEY_USER_ID));
    boolean success = sut.migrateUserId();
    assertTrue(success);
    Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
    String userId = arguments.getString("TEST_SERVER_USERNAME");
    // assume that userId == loginname (as we manually set it)
    assertEquals(userId, accountManager.getUserData(account, AccountUtils.Constants.KEY_USER_ID));
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) AppPreferences(com.nextcloud.client.preferences.AppPreferences) Test(org.junit.Test)

Aggregations

AppPreferences (com.nextcloud.client.preferences.AppPreferences)8 Context (android.content.Context)6 SyncedFolderProvider (com.owncloud.android.datamodel.SyncedFolderProvider)4 SSLContext (javax.net.ssl.SSLContext)4 SuppressLint (android.annotation.SuppressLint)3 SyncedFolder (com.owncloud.android.datamodel.SyncedFolder)3 ArrayList (java.util.ArrayList)3 ContentResolver (android.content.ContentResolver)2 Bundle (android.os.Bundle)2 Pair (androidx.core.util.Pair)2 StoragePoint (com.owncloud.android.datastorage.StoragePoint)2 HashMap (java.util.HashMap)2 Account (android.accounts.Account)1 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 Application (android.app.Application)1 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1