mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
make auto upload safe with no storage permission
This commit is contained in:
parent
ec246eac59
commit
a6474c32aa
3 changed files with 34 additions and 37 deletions
|
@ -410,7 +410,7 @@ public class MainApp extends MultiDexApplication {
|
||||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
||||||
|
|
||||||
final List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1, null);
|
final List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1, null);
|
||||||
final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1);
|
final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1, null);
|
||||||
|
|
||||||
ArrayList<Long> idsToDelete = new ArrayList<>();
|
ArrayList<Long> idsToDelete = new ArrayList<>();
|
||||||
List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
|
List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
|
||||||
|
|
|
@ -71,27 +71,14 @@ public class MediaProvider {
|
||||||
// check permissions
|
// check permissions
|
||||||
checkPermissions(activity);
|
checkPermissions(activity);
|
||||||
|
|
||||||
|
|
||||||
// query media/image folders
|
// query media/image folders
|
||||||
Cursor cursorFolders;
|
Cursor cursorFolders = null;
|
||||||
if (activity != null && PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
|
if (activity != null && PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
cursorFolders = contentResolver.query(
|
cursorFolders = contentResolver.query(IMAGES_MEDIA_URI, IMAGES_FOLDER_PROJECTION, null, null,
|
||||||
IMAGES_MEDIA_URI,
|
IMAGES_FOLDER_SORT_ORDER);
|
||||||
IMAGES_FOLDER_PROJECTION,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
IMAGES_FOLDER_SORT_ORDER
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
cursorFolders = contentResolver.query(
|
|
||||||
IMAGES_MEDIA_URI,
|
|
||||||
IMAGES_FOLDER_PROJECTION,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
IMAGES_FOLDER_SORT_ORDER
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MediaFolder> mediaFolders = new ArrayList<>();
|
List<MediaFolder> mediaFolders = new ArrayList<>();
|
||||||
String dataPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder();
|
String dataPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder();
|
||||||
|
|
||||||
|
@ -189,16 +176,26 @@ public class MediaProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver, int itemLimit) {
|
public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver, int itemLimit,
|
||||||
Cursor cursorFolders = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
@Nullable final Activity activity) {
|
||||||
VIDEOS_FOLDER_PROJECTION, null, null, null);
|
// check permissions
|
||||||
|
checkPermissions(activity);
|
||||||
|
|
||||||
|
// query media/image folders
|
||||||
|
Cursor cursorFolders = null;
|
||||||
|
if (activity != null && PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
|
cursorFolders = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, VIDEOS_FOLDER_PROJECTION,
|
||||||
|
null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
List<MediaFolder> mediaFolders = new ArrayList<>();
|
List<MediaFolder> mediaFolders = new ArrayList<>();
|
||||||
String dataPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder();
|
String dataPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder();
|
||||||
|
|
||||||
if (cursorFolders != null) {
|
if (cursorFolders != null) {
|
||||||
String folderName;
|
String folderName;
|
||||||
String fileSortOrder = MediaStore.Video.Media.DATE_TAKEN + " DESC LIMIT " + itemLimit;
|
String fileSortOrder = MediaStore.Video.Media.DATE_TAKEN + " DESC LIMIT " + itemLimit;
|
||||||
Cursor cursorImages;
|
Cursor cursorVideos;
|
||||||
|
|
||||||
while (cursorFolders.moveToNext()) {
|
while (cursorFolders.moveToNext()) {
|
||||||
String folderId = cursorFolders.getString(cursorFolders.getColumnIndex(MediaStore.Video.Media
|
String folderId = cursorFolders.getString(cursorFolders.getColumnIndex(MediaStore.Video.Media
|
||||||
|
@ -211,8 +208,8 @@ public class MediaProvider {
|
||||||
mediaFolder.folderName = folderName;
|
mediaFolder.folderName = folderName;
|
||||||
mediaFolder.filePaths = new ArrayList<>();
|
mediaFolder.filePaths = new ArrayList<>();
|
||||||
|
|
||||||
// query images
|
// query videos
|
||||||
cursorImages = contentResolver.query(
|
cursorVideos = contentResolver.query(
|
||||||
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||||
FILE_PROJECTION,
|
FILE_PROJECTION,
|
||||||
MediaStore.Video.Media.BUCKET_ID + "=" + folderId,
|
MediaStore.Video.Media.BUCKET_ID + "=" + folderId,
|
||||||
|
@ -220,10 +217,10 @@ public class MediaProvider {
|
||||||
fileSortOrder);
|
fileSortOrder);
|
||||||
Log.d(TAG, "Reading videos for " + mediaFolder.folderName);
|
Log.d(TAG, "Reading videos for " + mediaFolder.folderName);
|
||||||
|
|
||||||
if (cursorImages != null) {
|
if (cursorVideos != null) {
|
||||||
String filePath;
|
String filePath;
|
||||||
while (cursorImages.moveToNext()) {
|
while (cursorVideos.moveToNext()) {
|
||||||
filePath = cursorImages.getString(cursorImages.getColumnIndexOrThrow(
|
filePath = cursorVideos.getString(cursorVideos.getColumnIndexOrThrow(
|
||||||
MediaStore.MediaColumns.DATA));
|
MediaStore.MediaColumns.DATA));
|
||||||
|
|
||||||
if (filePath != null) {
|
if (filePath != null) {
|
||||||
|
@ -231,7 +228,7 @@ public class MediaProvider {
|
||||||
mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf("/"));
|
mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf("/"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursorImages.close();
|
cursorVideos.close();
|
||||||
|
|
||||||
// only do further work if folder is not within the Nextcloud app itself
|
// only do further work if folder is not within the Nextcloud app itself
|
||||||
if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
|
if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
|
||||||
|
|
|
@ -114,11 +114,10 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||||
|
|
||||||
// setup toolbar
|
// setup toolbar
|
||||||
setupToolbar();
|
setupToolbar();
|
||||||
CollapsingToolbarLayout mCollapsingToolbarLayout = ((CollapsingToolbarLayout)
|
CollapsingToolbarLayout mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
|
||||||
findViewById(R.id.collapsing_toolbar));
|
|
||||||
mCollapsingToolbarLayout.setTitle(this.getString(R.string.drawer_synced_folders));
|
mCollapsingToolbarLayout.setTitle(this.getString(R.string.drawer_synced_folders));
|
||||||
|
|
||||||
mCustomFolderRelativeLayout = (RelativeLayout) findViewById(R.id.custom_folder_toolbar);
|
mCustomFolderRelativeLayout = findViewById(R.id.custom_folder_toolbar);
|
||||||
|
|
||||||
SharedPreferences appPrefs =
|
SharedPreferences appPrefs =
|
||||||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
|
@ -170,10 +169,10 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||||
* sets up the UI elements and loads all media/synced folders.
|
* sets up the UI elements and loads all media/synced folders.
|
||||||
*/
|
*/
|
||||||
private void setupContent() {
|
private void setupContent() {
|
||||||
mRecyclerView = (RecyclerView) findViewById(android.R.id.list);
|
mRecyclerView = findViewById(android.R.id.list);
|
||||||
|
|
||||||
mProgress = (LinearLayout) findViewById(android.R.id.progress);
|
mProgress = findViewById(android.R.id.progress);
|
||||||
mEmpty = (TextView) findViewById(android.R.id.empty);
|
mEmpty = findViewById(android.R.id.empty);
|
||||||
|
|
||||||
final int gridWidth = getResources().getInteger(R.integer.media_grid_width);
|
final int gridWidth = getResources().getInteger(R.integer.media_grid_width);
|
||||||
boolean lightVersion = getResources().getBoolean(R.bool.syncedFolder_light);
|
boolean lightVersion = getResources().getBoolean(R.bool.syncedFolder_light);
|
||||||
|
@ -187,7 +186,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||||
mRecyclerView.setLayoutManager(lm);
|
mRecyclerView.setLayoutManager(lm);
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_view);
|
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
|
||||||
|
|
||||||
if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
|
if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
|
||||||
bottomNavigationView.setVisibility(View.VISIBLE);
|
bottomNavigationView.setVisibility(View.VISIBLE);
|
||||||
|
@ -209,13 +208,14 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||||
setListShown(false);
|
setListShown(false);
|
||||||
final List<MediaFolder> mediaFolders = MediaProvider.getImageFolders(getContentResolver(),
|
final List<MediaFolder> mediaFolders = MediaProvider.getImageFolders(getContentResolver(),
|
||||||
perFolderMediaItemLimit, SyncedFoldersActivity.this);
|
perFolderMediaItemLimit, SyncedFoldersActivity.this);
|
||||||
mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit));
|
mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit,
|
||||||
|
SyncedFoldersActivity.this));
|
||||||
|
|
||||||
List<SyncedFolder> syncedFolderArrayList = mSyncedFolderProvider.getSyncedFolders();
|
List<SyncedFolder> syncedFolderArrayList = mSyncedFolderProvider.getSyncedFolders();
|
||||||
List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
|
List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
|
||||||
Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(SyncedFoldersActivity.this);
|
Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(SyncedFoldersActivity.this);
|
||||||
for (SyncedFolder syncedFolder : syncedFolderArrayList) {
|
for (SyncedFolder syncedFolder : syncedFolderArrayList) {
|
||||||
if (syncedFolder.getAccount().equals(currentAccount.name)) {
|
if (currentAccount != null && syncedFolder.getAccount().equals(currentAccount.name)) {
|
||||||
currentAccountSyncedFoldersList.add(syncedFolder);
|
currentAccountSyncedFoldersList.add(syncedFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue