use of com.owncloud.android.datamodel.SyncedFolder in project android by nextcloud.
the class FilesSyncHelper method insertAllDBEntries.
public static void insertAllDBEntries(boolean skipCustom) {
final Context context = MainApp.getAppContext();
final ContentResolver contentResolver = context.getContentResolver();
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
if ((syncedFolder.isEnabled()) && ((MediaFolderType.CUSTOM != syncedFolder.getType()) || !skipCustom)) {
insertAllDBEntriesForSyncedFolder(syncedFolder);
}
}
}
use of com.owncloud.android.datamodel.SyncedFolder in project android by nextcloud.
the class MainApp method cleanOldEntries.
private static void cleanOldEntries() {
// previous versions of application created broken entries in the SyncedFolderProvider
// database, and this cleans all that and leaves 1 (newest) entry per synced folder
Context context = getAppContext();
if (!PreferenceManager.getLegacyClean(context)) {
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
List<SyncedFolder> syncedFolderList = syncedFolderProvider.getSyncedFolders();
Map<Pair<String, String>, Long> syncedFolders = new HashMap<>();
ArrayList<Long> ids = new ArrayList<>();
for (SyncedFolder syncedFolder : syncedFolderList) {
Pair<String, String> checkPair = new Pair<>(syncedFolder.getAccount(), syncedFolder.getLocalPath());
if (syncedFolders.containsKey(checkPair)) {
if (syncedFolder.getId() > syncedFolders.get(checkPair)) {
syncedFolders.put(checkPair, syncedFolder.getId());
}
} else {
syncedFolders.put(checkPair, syncedFolder.getId());
}
}
ids.addAll(syncedFolders.values());
if (ids.size() > 0) {
syncedFolderProvider.deleteSyncedFoldersNotInList(mContext, ids);
} else {
PreferenceManager.setLegacyClean(context, true);
}
}
}
use of com.owncloud.android.datamodel.SyncedFolder in project android by nextcloud.
the class FilesSyncHelper method scheduleNJobs.
public static void scheduleNJobs(boolean force, Context context) {
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
boolean hasVideoFolders = false;
boolean hasImageFolders = false;
if (syncedFolderProvider.getSyncedFolders() != null) {
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
if (MediaFolderType.VIDEO == syncedFolder.getType()) {
hasVideoFolders = true;
} else if (MediaFolderType.IMAGE == syncedFolder.getType()) {
hasImageFolders = true;
}
}
}
if (hasImageFolders || hasVideoFolders) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
scheduleJobOnN(hasImageFolders, hasVideoFolders, force);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
cancelJobOnN();
}
}
}
use of com.owncloud.android.datamodel.SyncedFolder 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.SyncedFolder 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