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);
}
}
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);
}
}
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;
}
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);
}
}
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));
}
Aggregations