diff --git a/src/com/owncloud/android/datamodel/MediaFolder.java b/src/com/owncloud/android/datamodel/MediaFolder.java new file mode 100644 index 0000000000..be41d8f846 --- /dev/null +++ b/src/com/owncloud/android/datamodel/MediaFolder.java @@ -0,0 +1,14 @@ +package com.owncloud.android.datamodel; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Created by scherzia on 22.09.2016. + */ + +public class MediaFolder { + public String folder; + public String path; + public Collection filePaths = new ArrayList<>(); +} diff --git a/src/com/owncloud/android/datamodel/MediaProvider.java b/src/com/owncloud/android/datamodel/MediaProvider.java new file mode 100644 index 0000000000..bf1d66d396 --- /dev/null +++ b/src/com/owncloud/android/datamodel/MediaProvider.java @@ -0,0 +1,93 @@ +/** + * Nextcloud Android client application + * + * @author Andy Scherzinger + * Copyright (C) 2016 Andy Scherzinger + * Copyright (C) 2016 Nextcloud + *

+ * 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 . + */ + +package com.owncloud.android.datamodel; + +import android.app.Activity; +import android.database.Cursor; +import android.net.Uri; +import android.provider.MediaStore; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; + +/** + * media queries to gain access to media lists for the device. + */ +public class MediaProvider { + private static final Uri MEDIA_URI = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; + + /** + * TODO rewrite + * Getting All Images Path + * + * @param activity + * @return List with images folders + */ + public static List getAllShownImagesPath(Activity activity) { + Cursor cursor; + int column_index_data, column_index_folder_name, column_index_data_image; + ArrayList listOfAllImages = new ArrayList<>(); + String absolutePathOfImage = null; + String folderName = null; + + String[] projectionTest = {MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME}; + //String[] projection = {MediaStore.Images.Media.BUCKET_DISPLAY_NAME,MediaStore.Images.Media.BUCKET_ID}; + String[] folderProjection = new String[]{"Distinct " + MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore + .MediaColumns.DATA}; + String[] fileProjection = new String[]{MediaStore.MediaColumns.DATA}; + String folderSelection = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " IS NOT NULL) GROUP BY (" + MediaStore + .Images.Media + .BUCKET_DISPLAY_NAME; + String fileSelection = MediaStore.MediaColumns.DATA + " LIKE "; + String folderSortOrder = "MAX(" + MediaStore.Images.Media.DISPLAY_NAME + ") DESC"; + String fileSortOrder = MediaStore.MediaColumns.DATA + " DESC LIMIT 8"; // LIMIT 8 + + cursor = activity.getContentResolver().query(MEDIA_URI, folderProjection, folderSelection, null, folderSortOrder); + + column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); + column_index_folder_name = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); + + List mediaFolders = new ArrayList<>(); + while (cursor.moveToNext()) { + MediaFolder mediaFolder = new MediaFolder(); + absolutePathOfImage = cursor.getString(column_index_data); + folderName = cursor.getString(column_index_folder_name); + mediaFolder.path = folderName; + mediaFolder.folder = absolutePathOfImage.substring(0, absolutePathOfImage.lastIndexOf(folderName) + folderName.length()); + mediaFolder.filePaths = new ArrayList<>(); + + Cursor cursorImages = activity.getContentResolver().query(MEDIA_URI, fileProjection, fileSelection + "'" + + absolutePathOfImage.substring(0, absolutePathOfImage.lastIndexOf("/")) + "/%'", null, + fileSortOrder); + column_index_data_image = cursorImages.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); + Log.e("READ IMAGES", "Reading images for --> " + mediaFolder.folder); + while (cursorImages.moveToNext()) { + mediaFolder.filePaths.add(cursorImages.getString(column_index_data_image)); + } + + mediaFolders.add(mediaFolder); + } + + return mediaFolders; + } +} diff --git a/src/com/owncloud/android/ui/activity/FolderSyncActivity.java b/src/com/owncloud/android/ui/activity/FolderSyncActivity.java index 3cf1b29ec7..fe26e36d17 100644 --- a/src/com/owncloud/android/ui/activity/FolderSyncActivity.java +++ b/src/com/owncloud/android/ui/activity/FolderSyncActivity.java @@ -24,15 +24,24 @@ package com.owncloud.android.ui.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.os.Handler; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.MenuItem; import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; import com.owncloud.android.MainApp; import com.owncloud.android.R; +import com.owncloud.android.datamodel.MediaFolder; +import com.owncloud.android.datamodel.MediaProvider; import com.owncloud.android.ui.adapter.FolderSyncAdapter; +import java.util.List; +import java.util.TimerTask; + /** * Activity displaying all auto-synced folders and/or instant upload media folders. */ @@ -40,6 +49,8 @@ public class FolderSyncActivity extends DrawerActivity { private static final String TAG = FolderSyncActivity.class.getSimpleName(); private RecyclerView mRecyclerView; private FolderSyncAdapter mAdapter; + private ProgressBar mProgress; + private TextView mEmpty; @Override protected void onCreate(Bundle savedInstanceState) { @@ -57,6 +68,7 @@ public class FolderSyncActivity extends DrawerActivity { setupContent(); } + private void setupContent() { // TODO setup/initialize UI mRecyclerView = (RecyclerView) findViewById(android.R.id.list); @@ -73,12 +85,54 @@ public class FolderSyncActivity extends DrawerActivity { mAdapter.setLayoutManager(lm); mRecyclerView.setLayoutManager(lm); mRecyclerView.setAdapter(mAdapter); + + load(); } public static void selectItem(final Activity context) { + // TODO implement selectItem() return; } + private void load() { + if (mAdapter.getItemCount() > 0) return; + setListShown(false); + final Handler mHandler = new Handler(); + new Thread(new Runnable() { + @Override + public void run() { + final List mediaFolders = MediaProvider.getAllShownImagesPath(FolderSyncActivity.this); + + for (MediaFolder mediaFolder : mediaFolders) { + Log.d(TAG, mediaFolder.path); + } + + mHandler.post(new TimerTask() { + @Override + public void run() { + mAdapter.setMediaFolders(mediaFolders); + setListShown(true); + } + }); + } + }).start(); + } + + void setListShown(boolean shown) { + if (mRecyclerView != null) { + mRecyclerView.setVisibility(shown ? + View.VISIBLE : View.GONE); + + // TODO show/hide loading visuals + /** + mProgress.setVisibility(shown ? + View.GONE : View.VISIBLE); + mEmpty.setVisibility(shown && mAdapter.getItemCount() == 0 ? + View.VISIBLE : View.GONE); + **/ + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { boolean retval; diff --git a/src/com/owncloud/android/ui/adapter/FolderSyncAdapter.java b/src/com/owncloud/android/ui/adapter/FolderSyncAdapter.java index cde7473a15..b83c92bda1 100644 --- a/src/com/owncloud/android/ui/adapter/FolderSyncAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FolderSyncAdapter.java @@ -23,6 +23,8 @@ package com.owncloud.android.ui.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -32,8 +34,10 @@ import android.widget.TextView; import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter; import com.owncloud.android.R; +import com.owncloud.android.datamodel.MediaFolder; import java.util.ArrayList; +import java.util.List; /** * Adapter to display all auto-synced folders and/or instant upload media folders. @@ -46,20 +50,26 @@ public class FolderSyncAdapter extends SectionedRecyclerViewAdapter mCategories; + private final List mMediaFolders; private final RecyclerView mRecyclerView; public FolderSyncAdapter(Context context, int gridWidth, ClickListener listener, RecyclerView recyclerView) { mContext = context; mGridWidth = gridWidth * 2; mListener = listener; - mCategories = new ArrayList<>(); + mMediaFolders = new ArrayList<>(); mRecyclerView = recyclerView; } + public void setMediaFolders(List mediaFolders) { + mMediaFolders.clear(); + mMediaFolders.addAll(mediaFolders); + notifyDataSetChanged(); + } + @Override public void onClick(View v) { - + Log.d(TAG, v.getTag().toString()); } @Override @@ -69,46 +79,107 @@ public class FolderSyncAdapter extends SectionedRecyclerViewAdapter