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
25 changes: 23 additions & 2 deletions src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import android.view.WindowManager;

import com.evernote.android.job.JobManager;
import com.evernote.android.job.JobRequest;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.authentication.PassCodeManager;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
Expand All @@ -56,6 +57,7 @@
import com.owncloud.android.datastorage.DataStorageProvider;
import com.owncloud.android.datastorage.StoragePoint;
import com.owncloud.android.db.PreferenceManager;
import com.owncloud.android.jobs.MediaFoldersDetectionJob;
import com.owncloud.android.jobs.NCJobCreator;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
Expand All @@ -77,6 +79,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand Down Expand Up @@ -164,6 +167,20 @@ public void onCreate() {
initContactsBackup();
notificationChannels();


new JobRequest.Builder(MediaFoldersDetectionJob.TAG)
.setPeriodic(TimeUnit.MINUTES.toMillis(15), TimeUnit.MINUTES.toMillis(5))
.setUpdateCurrent(true)
.build()
.schedule();

new JobRequest.Builder(MediaFoldersDetectionJob.TAG)
.startNow()
.setUpdateCurrent(false)
.build()
.schedule();


// register global protection with pass code
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

Expand Down Expand Up @@ -336,6 +353,10 @@ public static void notificationChannels() {
createChannel(notificationManager, NotificationUtils.NOTIFICATION_CHANNEL_PUSH,
R.string.notification_channel_push_name, R.string
.notification_channel_push_description, context, NotificationManager.IMPORTANCE_DEFAULT);

createChannel(notificationManager, NotificationUtils.NOTIFICATION_CHANNEL_GENERAL, R.string
.notification_channel_general_name, R.string.notification_channel_general_description,
context, NotificationManager.IMPORTANCE_DEFAULT);
} else {
Log_OC.e(TAG, "Notification manager is null");
}
Expand Down Expand Up @@ -546,8 +567,8 @@ private static void splitOutAutoUploadEntries() {

SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);

final List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1, null);
final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1, null);
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Nextcloud Android client application
*
* @author Mario Danic
* Copyright (C) 2018 Mario Danic
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.datamodel;

import java.util.List;

public class MediaFoldersModel {
private List<String> imageMediaFolders;
private List<String> videoMediaFolders;

/**
* default constructor.
*/
public MediaFoldersModel() {
// keep default constructor for GSON
}

public MediaFoldersModel(List<String> imageMediaFolders, List<String> videoMediaFolders) {
this.imageMediaFolders = imageMediaFolders;
this.videoMediaFolders = videoMediaFolders;
}

public List<String> getImageMediaFolders() {
return imageMediaFolders;
}

public void setImageMediaFolders(List<String> imageMediaFolders) {
this.imageMediaFolders = imageMediaFolders;
}

public List<String> getVideoMediaFolders() {
return videoMediaFolders;
}

public void setVideoMediaFolders(List<String> videoMediaFolders) {
this.videoMediaFolders = videoMediaFolders;
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/owncloud/android/datamodel/MediaProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public class MediaProvider {
* @return list with media folders
*/
public static List<MediaFolder> getImageFolders(ContentResolver contentResolver, int itemLimit,
@Nullable final Activity activity) {
@Nullable final Activity activity, boolean getWithoutActivity) {
// check permissions
checkPermissions(activity);

// query media/image folders
Cursor cursorFolders = null;
if (activity != null && PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if ((activity != null && PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE)) || getWithoutActivity) {
cursorFolders = contentResolver.query(IMAGES_MEDIA_URI, IMAGES_FOLDER_PROJECTION, null, null,
IMAGES_FOLDER_SORT_ORDER);
}
Expand Down Expand Up @@ -171,14 +171,14 @@ private static void checkPermissions(@Nullable Activity activity) {
}

public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver, int itemLimit,
@Nullable final Activity activity) {
@Nullable final Activity activity, boolean getWithoutActivity) {
// check permissions
checkPermissions(activity);

// query media/image folders
Cursor cursorFolders = null;
if (activity != null && PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if ((activity != null && PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE)) || getWithoutActivity) {
cursorFolders = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, VIDEOS_FOLDER_PROJECTION,
null, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ public long storeSyncedFolder(SyncedFolder syncedFolder) {
}
}

public int countEnabledSyncedFolders() {
int count = 0;
Cursor cursor = mContentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
null,
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED + " = ?",
new String[]{"1"},
null
);

if (cursor != null) {
count = cursor.getCount();
cursor.close();
}

return count;
}

/**
* get all synced folder entries.
*
Expand Down Expand Up @@ -160,6 +178,37 @@ public int updateSyncedFolderEnabled(long id, Boolean enabled) {
return result;
}

public SyncedFolder findByLocalPathAndAccount(String localPath, Account account) {

SyncedFolder result = null;
Cursor cursor = mContentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
null,
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " == \"" + localPath + "\"" + " AND " +
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " == " + account.name,
null,
null
);

if (cursor != null && cursor.getCount() == 1) {
result = createSyncedFolderFromCursor(cursor);
} else {
if (cursor == null) {
Log_OC.e(TAG, "Sync folder db cursor for local path=" + localPath + " in NULL.");
} else {
Log_OC.e(TAG, cursor.getCount() + " items for local path=" + localPath
+ " available in sync folder db. Expected 1. Failed to update sync folder db.");
}
}

if (cursor != null) {
cursor.close();
}

return result;

}

/**
* find a synced folder by local path.
*
Expand All @@ -171,7 +220,7 @@ public SyncedFolder findByLocalPath(String localPath) {
Cursor cursor = mContentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
null,
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + "== \"" + localPath + "\"",
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " == \"" + localPath + "\"",
null,
null
);
Expand Down
Loading