use of com.owncloud.android.datamodel.SyncedFolderDisplayItem in project android by nextcloud.
the class SyncedFoldersActivity method onAddCustomFolderClick.
public void onAddCustomFolderClick(View view) {
Log.d(TAG, "Show custom folder dialog");
SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(SyncedFolder.UNPERSISTED_ID, null, null, true, false, false, AccountUtils.getCurrentOwnCloudAccount(this).name, FileUploader.LOCAL_BEHAVIOUR_FORGET, false, null, MediaFolderType.CUSTOM);
onSyncFolderSettingsClick(0, emptyCustomFolder);
}
use of com.owncloud.android.datamodel.SyncedFolderDisplayItem in project android by nextcloud.
the class SyncedFoldersActivity method onSaveSyncedFolderPreference.
@Override
public void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder) {
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
// so triggering a refresh
if (MediaFolderType.CUSTOM.equals(syncedFolder.getType()) && syncedFolder.getId() == UNPERSISTED_ID) {
SyncedFolderDisplayItem newCustomFolder = new SyncedFolderDisplayItem(SyncedFolder.UNPERSISTED_ID, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.getEnabled(), new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType());
long storedId = mSyncedFolderProvider.storeSyncedFolder(newCustomFolder);
if (storedId != -1) {
newCustomFolder.setId(storedId);
if (newCustomFolder.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(newCustomFolder);
} else {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + newCustomFolder.getId();
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
}
FilesSyncHelper.scheduleNJobs(false, getApplicationContext());
}
mAdapter.addSyncFolderItem(newCustomFolder);
} else {
SyncedFolderDisplayItem item = mAdapter.get(syncedFolder.getSection());
item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder.getUploadAction(), syncedFolder.getEnabled());
if (syncedFolder.getId() == UNPERSISTED_ID) {
// newly set up folder sync config
long storedId = mSyncedFolderProvider.storeSyncedFolder(item);
if (storedId != -1) {
item.setId(storedId);
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
} else {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
}
FilesSyncHelper.scheduleNJobs(false, getApplicationContext());
}
} else {
// existing synced folder setup to be updated
mSyncedFolderProvider.updateSyncFolder(item);
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
} else {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
}
FilesSyncHelper.scheduleNJobs(false, getApplicationContext());
}
mAdapter.setSyncFolderItem(syncedFolder.getSection(), item);
}
mSyncedFolderPreferencesDialogFragment = null;
}
use of com.owncloud.android.datamodel.SyncedFolderDisplayItem in project android by nextcloud.
the class SyncedFoldersActivity method createSyncedFolderWithoutMediaFolder.
@NonNull
private SyncedFolderDisplayItem createSyncedFolderWithoutMediaFolder(@NonNull SyncedFolder syncedFolder) {
File localFolder = new File(syncedFolder.getLocalPath());
File[] files = getFileList(localFolder);
List<String> filePaths = getDisplayFilePathList(files);
return new SyncedFolderDisplayItem(syncedFolder.getId(), syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.isEnabled(), filePaths, localFolder.getName(), files.length, syncedFolder.getType());
}
use of com.owncloud.android.datamodel.SyncedFolderDisplayItem in project android by nextcloud.
the class SyncedFoldersActivity method mergeFolderData.
/**
* merges two lists of {@link SyncedFolder} and {@link MediaFolder} items into one of SyncedFolderItems.
*
* @param syncedFolders the synced folders
* @param mediaFolders the media folders
* @return the merged list of SyncedFolderItems
*/
@NonNull
private List<SyncedFolderDisplayItem> mergeFolderData(List<SyncedFolder> syncedFolders, @NonNull List<MediaFolder> mediaFolders) {
Map<String, SyncedFolder> syncedFoldersMap = createSyncedFoldersMap(syncedFolders);
List<SyncedFolderDisplayItem> result = new ArrayList<>();
for (MediaFolder mediaFolder : mediaFolders) {
if (syncedFoldersMap.containsKey(mediaFolder.absolutePath + "-" + mediaFolder.type)) {
SyncedFolder syncedFolder = syncedFoldersMap.get(mediaFolder.absolutePath + "-" + mediaFolder.type);
syncedFoldersMap.remove(mediaFolder.absolutePath + "-" + mediaFolder.type);
if (MediaFolderType.CUSTOM == syncedFolder.getType()) {
result.add(createSyncedFolderWithoutMediaFolder(syncedFolder));
} else {
result.add(createSyncedFolder(syncedFolder, mediaFolder));
}
} else {
result.add(createSyncedFolderFromMediaFolder(mediaFolder));
}
}
for (SyncedFolder syncedFolder : syncedFoldersMap.values()) {
result.add(createSyncedFolderWithoutMediaFolder(syncedFolder));
}
return result;
}
use of com.owncloud.android.datamodel.SyncedFolderDisplayItem in project android by nextcloud.
the class SyncedFoldersActivity method load.
/**
* loads all media/synced folders, adds them to the recycler view adapter and shows the list.
*
* @param perFolderMediaItemLimit the amount of media items to be loaded/shown per media folder
*/
private void load(final int perFolderMediaItemLimit, boolean force) {
if (mAdapter.getItemCount() > 0 && !force) {
return;
}
setListShown(false);
final List<MediaFolder> mediaFolders = MediaProvider.getImageFolders(getContentResolver(), perFolderMediaItemLimit, SyncedFoldersActivity.this);
mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit, SyncedFoldersActivity.this));
List<SyncedFolder> syncedFolderArrayList = mSyncedFolderProvider.getSyncedFolders();
List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(SyncedFoldersActivity.this);
for (SyncedFolder syncedFolder : syncedFolderArrayList) {
if (currentAccount != null && syncedFolder.getAccount().equals(currentAccount.name)) {
currentAccountSyncedFoldersList.add(syncedFolder);
}
}
List<SyncedFolderDisplayItem> syncFolderItems = sortSyncedFolderItems(mergeFolderData(currentAccountSyncedFoldersList, mediaFolders));
mAdapter.setSyncFolderItems(syncFolderItems);
mAdapter.notifyDataSetChanged();
setListShown(true);
}
Aggregations