Search in sources :

Example 1 with MediaProvider

use of us.koller.cameraroll.data.provider.MediaProvider in project Camera-Roll-Android-App by kollerlukas.

the class AlbumActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final String[] selected_items_paths;
    Intent intent;
    switch(item.getItemId()) {
        case R.id.select_all:
            SelectorModeManager manager = recyclerViewAdapter.getSelectorManager();
            String[] paths = new String[album.getAlbumItems().size()];
            for (int i = 0; i < album.getAlbumItems().size(); i++) {
                paths[i] = album.getAlbumItems().get(i).getPath();
            }
            manager.selectAll(paths);
            recyclerViewAdapter.notifyItemRangeChanged(0, paths.length);
            break;
        case R.id.share:
            // share multiple items
            selected_items_paths = recyclerViewAdapter.cancelSelectorMode(this);
            ArrayList<Uri> uris = new ArrayList<>();
            for (int i = 0; i < selected_items_paths.length; i++) {
                uris.add(StorageUtil.getContentUri(this, selected_items_paths[i]));
            }
            intent = new Intent().setAction(Intent.ACTION_SEND_MULTIPLE).setType(MediaType.getMimeType(this, uris.get(0))).putExtra(Intent.EXTRA_STREAM, uris);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(Intent.createChooser(intent, getString(R.string.share)));
            }
            break;
        case R.id.copy:
        case R.id.move:
            selected_items_paths = recyclerViewAdapter.cancelSelectorMode(this);
            intent = new Intent(this, FileOperationDialogActivity.class);
            intent.setAction(item.getItemId() == R.id.copy ? FileOperationDialogActivity.ACTION_COPY : FileOperationDialogActivity.ACTION_MOVE);
            intent.putExtra(FileOperationDialogActivity.FILES, selected_items_paths);
            startActivityForResult(intent, FILE_OP_DIALOG_REQUEST);
            break;
        case R.id.exclude:
            Provider.loadExcludedPaths(this);
            if (!album.excluded) {
                Provider.addExcludedPath(this, album.getPath());
                album.excluded = true;
            } else {
                Provider.removeExcludedPath(this, album.getPath());
                album.excluded = false;
            }
            item.setChecked(album.excluded);
            break;
        case R.id.pin:
            Provider.loadPinnedPaths(this);
            if (!album.pinned) {
                Provider.pinPath(this, album.getPath());
                album.pinned = true;
            } else {
                Provider.unpinPath(this, album.getPath());
                album.pinned = false;
            }
            item.setChecked(album.pinned);
            break;
        case R.id.rename:
            File_POJO file = new File_POJO(album.getPath(), false).setName(album.getName());
            Rename.Util.getRenameDialog(this, file, new BroadcastReceiver() {

                @Override
                public void onReceive(Context context, Intent intent) {
                    final Activity activity = AlbumActivity.this;
                    final String newFilePath = intent.getStringExtra(Rename.NEW_FILE_PATH);
                    getIntent().putExtra(ALBUM_PATH, newFilePath);
                    boolean hiddenFolders = Settings.getInstance(activity).getHiddenFolders();
                    new MediaProvider(activity).loadAlbums(activity, hiddenFolders, new MediaProvider.OnMediaLoadedCallback() {

                        @Override
                        public void onMediaLoaded(ArrayList<Album> albums) {
                            // reload activity
                            MediaProvider.loadAlbum(activity, newFilePath, new MediaProvider.OnAlbumLoadedCallback() {

                                @Override
                                public void onAlbumLoaded(Album album) {
                                    AlbumActivity.this.album = album;
                                    AlbumActivity.this.onAlbumLoaded(null);
                                }
                            });
                        }

                        @Override
                        public void timeout() {
                            finish();
                        }

                        @Override
                        public void needPermission() {
                            finish();
                        }
                    });
                }
            }).show();
            break;
        case R.id.sort_by_date:
        case R.id.sort_by_name:
            item.setChecked(true);
            int sort_by = item.getItemId() == R.id.sort_by_date ? SortUtil.BY_DATE : SortUtil.BY_NAME;
            Settings.getInstance(this).sortAlbumBy(this, sort_by);
            SortUtil.sort(album.getAlbumItems(), sort_by);
            recyclerViewAdapter.notifyDataSetChanged();
            break;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) Activity(android.app.Activity) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) BroadcastReceiver(android.content.BroadcastReceiver) Uri(android.net.Uri) MediaProvider(us.koller.cameraroll.data.provider.MediaProvider) SelectorModeManager(us.koller.cameraroll.adapter.SelectorModeManager)

Example 2 with MediaProvider

use of us.koller.cameraroll.data.provider.MediaProvider in project Camera-Roll-Android-App by kollerlukas.

the class ItemActivity method renameAlbumItem.

public void renameAlbumItem() {
    File_POJO file = new File_POJO(albumItem.getPath(), true).setName(albumItem.getName());
    Rename.Util.getRenameDialog(this, file, new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            switch(intent.getAction()) {
                case FileOperation.RESULT_DONE:
                    // refresh data
                    final Activity activity = ItemActivity.this;
                    String newFilePath = intent.getStringExtra(Rename.NEW_FILE_PATH);
                    if (newFilePath == null) {
                        return;
                    }
                    int index = newFilePath.lastIndexOf("/");
                    final String albumPath = newFilePath.substring(0, index);
                    getIntent().putExtra(ALBUM_PATH, albumPath);
                    getIntent().putExtra(ITEM_POSITION, album.getAlbumItems().indexOf(albumItem));
                    boolean hiddenFolders = Settings.getInstance(activity).getHiddenFolders();
                    new MediaProvider(activity).loadAlbums(activity, hiddenFolders, new MediaProvider.OnMediaLoadedCallback() {

                        @Override
                        public void onMediaLoaded(ArrayList<Album> albums) {
                            // reload activity
                            MediaProvider.loadAlbum(activity, albumPath, new MediaProvider.OnAlbumLoadedCallback() {

                                @Override
                                public void onAlbumLoaded(Album album) {
                                    ItemActivity.this.albumItem = null;
                                    ItemActivity.this.album = album;
                                    ItemActivity.this.onAlbumLoaded(null);
                                    // notify AlbumActivity
                                    LocalBroadcastManager.getInstance(ItemActivity.this).sendBroadcast(new Intent(AlbumActivity.ALBUM_ITEM_RENAMED));
                                }
                            });
                        }

                        @Override
                        public void timeout() {
                            finish();
                        }

                        @Override
                        public void needPermission() {
                            finish();
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    }).show();
}
Also used : Context(android.content.Context) Activity(android.app.Activity) Album(us.koller.cameraroll.data.models.Album) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) SpannableString(android.text.SpannableString) BroadcastReceiver(android.content.BroadcastReceiver) MediaProvider(us.koller.cameraroll.data.provider.MediaProvider)

Example 3 with MediaProvider

use of us.koller.cameraroll.data.provider.MediaProvider in project Camera-Roll-Android-App by kollerlukas.

the class MainActivity method refreshPhotos.

public void refreshPhotos() {
    if (mediaProvider != null) {
        mediaProvider.onDestroy();
        mediaProvider = null;
    }
    snackbar = Snackbar.make(findViewById(R.id.root_view), R.string.loading, Snackbar.LENGTH_INDEFINITE);
    Util.showSnackbar(snackbar);
    final MediaProvider.OnMediaLoadedCallback callback = new MediaProvider.OnMediaLoadedCallback() {

        @Override
        public void onMediaLoaded(final ArrayList<Album> albums) {
            final ArrayList<Album> albumsWithVirtualDirs = MediaProvider.getAlbumsWithVirtualDirectories(MainActivity.this);
            if (albums != null) {
                MainActivity.this.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        MainActivity.this.albums = albumsWithVirtualDirs;
                        recyclerViewAdapter.setData(albumsWithVirtualDirs);
                        snackbar.dismiss();
                        if (mediaProvider != null) {
                            mediaProvider.onDestroy();
                        }
                        mediaProvider = null;
                    }
                });
            }
        }

        @Override
        public void timeout() {
            // handle timeout
            snackbar.dismiss();
            snackbar = Snackbar.make(findViewById(R.id.root_view), R.string.loading_failed, Snackbar.LENGTH_INDEFINITE);
            snackbar.setAction(getString(R.string.retry), new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (mediaProvider != null) {
                        mediaProvider.onDestroy();
                    }
                    refreshPhotos();
                    snackbar.dismiss();
                }
            });
            Util.showSnackbar(snackbar);
            if (mediaProvider != null) {
                mediaProvider.onDestroy();
            }
            mediaProvider = null;
        }

        @Override
        public void needPermission() {
            snackbar.dismiss();
        }
    };
    mediaProvider = new MediaProvider(this);
    mediaProvider.loadAlbums(MainActivity.this, hiddenFolders, callback);
}
Also used : MediaProvider(us.koller.cameraroll.data.provider.MediaProvider) ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) View(android.view.View) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView)

Example 4 with MediaProvider

use of us.koller.cameraroll.data.provider.MediaProvider in project Camera-Roll-Android-App by kollerlukas.

the class BaseActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    // registering RemovableStorage...Receiver here so only the visible activity receives the broadcast
    removableStoragePermissionRequestBroadcastReceiver = getRemovableStoragePermissionRequestBroadcastReceiver();
    if (removableStoragePermissionRequestBroadcastReceiver != null) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(FileOperation.NEED_REMOVABLE_STORAGE_PERMISSION);
        broadcastReceivers.add(removableStoragePermissionRequestBroadcastReceiver);
        LocalBroadcastManager.getInstance(this).registerReceiver(removableStoragePermissionRequestBroadcastReceiver, filter);
    }
    if (MediaProvider.dataChanged) {
        MediaProvider.dataChanged = false;
        Settings s = Settings.getInstance(this);
        boolean hiddenFolders = s.getHiddenFolders();
        MediaProvider provider = new MediaProvider(this);
        provider.loadAlbums(this, hiddenFolders, new MediaProvider.OnMediaLoadedCallback() {

            @Override
            public void onMediaLoaded(ArrayList<Album> albums) {
                LocalBroadcastManager manager = LocalBroadcastManager.getInstance(BaseActivity.this);
                manager.sendBroadcast(new Intent().setAction(DATA_CHANGED));
            }

            @Override
            public void timeout() {
            }

            @Override
            public void needPermission() {
                MediaProvider.checkPermission(BaseActivity.this);
            }
        });
    }
}
Also used : IntentFilter(android.content.IntentFilter) MediaProvider(us.koller.cameraroll.data.provider.MediaProvider) Album(us.koller.cameraroll.data.models.Album) Intent(android.content.Intent) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Settings(us.koller.cameraroll.data.Settings)

Aggregations

Album (us.koller.cameraroll.data.models.Album)4 MediaProvider (us.koller.cameraroll.data.provider.MediaProvider)4 Intent (android.content.Intent)3 Activity (android.app.Activity)2 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 ArrayList (java.util.ArrayList)2 File_POJO (us.koller.cameraroll.data.models.File_POJO)2 IntentFilter (android.content.IntentFilter)1 Uri (android.net.Uri)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 SelectorModeManager (us.koller.cameraroll.adapter.SelectorModeManager)1 Settings (us.koller.cameraroll.data.Settings)1 VirtualAlbum (us.koller.cameraroll.data.models.VirtualAlbum)1 FastScrollerRecyclerView (us.koller.cameraroll.ui.widget.FastScrollerRecyclerView)1 ParallaxImageView (us.koller.cameraroll.ui.widget.ParallaxImageView)1