Search in sources :

Example 16 with File_POJO

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

the class NestedRecyclerViewAlbumHolder method deleteItems.

private void deleteItems(String[] paths) {
    File_POJO[] filesToDelete = new File_POJO[paths.length];
    for (int i = 0; i < filesToDelete.length; i++) {
        filesToDelete[i] = new File_POJO(paths[i], true);
    }
    getContext().startService(FileOperation.getDefaultIntent(getContext(), FileOperation.DELETE, filesToDelete));
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO)

Example 17 with File_POJO

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

the class FileExplorerActivity method loadDirectory.

public void loadDirectory(final String path) {
    Log.d("FileExplorerActivity", "loadDirectory(): " + path);
    final Snackbar snackbar = Snackbar.make(findViewById(R.id.root_view), getString(R.string.loading), Snackbar.LENGTH_INDEFINITE);
    Util.showSnackbar(snackbar);
    final FilesProvider.Callback callback = new FilesProvider.Callback() {

        @Override
        public void onDirLoaded(final File_POJO dir) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    filesProvider.onDestroy();
                    filesProvider = null;
                    if (dir != null) {
                        FileExplorerActivity.this.currentDir = dir;
                        if (recyclerViewAdapter != null) {
                            recyclerViewAdapter.setFiles(currentDir);
                            recyclerViewAdapter.notifyDataSetChanged();
                            onDataChanged();
                        }
                    }
                    snackbar.dismiss();
                }
            });
        }

        @Override
        public void timeout() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    snackbar.dismiss();
                    final Snackbar 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) {
                            loadDirectory(path);
                        }
                    });
                    Util.showSnackbar(snackbar);
                }
            });
        }

        @Override
        public void needPermission() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    snackbar.dismiss();
                }
            });
        }
    };
    filesProvider = new FilesProvider(this);
    filesProvider.loadDir(this, path, callback);
}
Also used : FilesProvider(us.koller.cameraroll.data.provider.FilesProvider) File_POJO(us.koller.cameraroll.data.models.File_POJO) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 18 with File_POJO

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

the class FileExplorerActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            if (recyclerViewAdapter.isModeActive() || recyclerViewAdapter.getMode() == FileExplorerAdapter.PICK_TARGET_MODE) {
                recyclerViewAdapter.cancelMode();
            } else {
                onBackPressed();
            }
            break;
        case R.id.exclude:
            currentDir.excluded = !currentDir.excluded;
            item.setChecked(currentDir.excluded);
            if (currentDir.excluded) {
                FilesProvider.addExcludedPath(this, currentDir.getPath());
            } else {
                FilesProvider.removeExcludedPath(this, currentDir.getPath());
            }
            break;
        case R.id.scan:
            AsyncTask.execute(new Runnable() {

                @Override
                public void run() {
                    ArrayList<String> paths = FileOperation.Util.getAllChildPaths(new ArrayList<String>(), currentDir.getPath());
                    String[] pathsArray = new String[paths.size()];
                    paths.toArray(pathsArray);
                    FileOperation.Util.scanPathsWithNotification(FileExplorerActivity.this, pathsArray);
                }
            });
            break;
        case R.id.add_to_virtual_album:
            String path = currentDir.getPath();
            AlertDialog dialog = VirtualAlbum.Util.getAddToVirtualAlbumDialog(this, path);
            dialog.show();
            break;
        case R.id.paste:
            if (!currentDir.getPath().equals(STORAGE_ROOTS)) {
                recyclerViewAdapter.cancelMode();
                if (fileOpIntent != null) {
                    File_POJO target = recyclerViewAdapter.getFiles();
                    fileOpIntent.putExtra(FileOperation.TARGET, target);
                    startService(fileOpIntent);
                    fileOpIntent = null;
                }
            } else {
                Toast.makeText(this, R.string.paste_error, Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.copy:
            fileOpIntent = new Intent(this, Copy.class).setAction(FileOperation.Util.getActionString(this, FileOperation.COPY));
            recyclerViewAdapter.cancelMode();
            break;
        case R.id.move:
            fileOpIntent = new Intent(this, Move.class).setAction(FileOperation.Util.getActionString(this, FileOperation.MOVE));
            recyclerViewAdapter.cancelMode();
            break;
        case R.id.delete:
            fileOpIntent = new Intent(this, Delete.class).setAction(FileOperation.Util.getActionString(this, FileOperation.DELETE));
            recyclerViewAdapter.cancelMode();
            break;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ArrayList(java.util.ArrayList) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO)

Example 19 with File_POJO

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

the class FileOperationDialogActivity method executeAction.

public void executeAction(File_POJO[] files, String target) {
    int action = this.action.equals(ACTION_COPY) ? FileOperation.COPY : FileOperation.MOVE;
    final Intent workIntent = FileOperation.getDefaultIntent(this, action, files);
    workIntent.putExtra(FileOperation.TARGET, new File_POJO(target, false));
    startService(workIntent);
}
Also used : Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) SuppressLint(android.annotation.SuppressLint)

Example 20 with File_POJO

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

the class ItemActivity method deletePhoto.

public void deletePhoto() {
    if (!MediaProvider.checkPermission(this)) {
        return;
    }
    if (albumItem == null) {
        return;
    }
    final File_POJO[] files = new File_POJO[] { new File_POJO(albumItem.getPath(), true) };
    registerLocalBroadcastReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            unregisterLocalBroadcastReceiver(this);
            switch(intent.getAction()) {
                case FileOperation.RESULT_DONE:
                    String path = albumItem.getPath();
                    Intent i = new Intent(AlbumActivity.ALBUM_ITEM_REMOVED).putExtra(ALBUM_ITEM_PATH, path);
                    // notify AlbumActivity
                    LocalBroadcastManager.getInstance(ItemActivity.this).sendBroadcast(i);
                    /*ItemActivity.this.setResult(RESULT_OK);
                        finish();*/
                    album.getAlbumItems().remove(albumItem);
                    viewPager.getAdapter().notifyDataSetChanged();
                    if (album.getAlbumItems().size() == 0) {
                        ItemActivity.this.setResult(RESULT_OK);
                        finish();
                        return;
                    }
                    albumItem = album.getAlbumItems().get(viewPager.getCurrentItem());
                    ItemAdapter adapter = (ItemAdapter) viewPager.getAdapter();
                    ViewHolder viewHolder = adapter.findViewHolderByTag(albumItem.getPath());
                    onShowViewHolder(viewHolder);
                    break;
                case FileOperation.FAILED:
                    // onBackPressed();
                    break;
                default:
                    break;
            }
        }
    });
    startService(FileOperation.getDefaultIntent(this, FileOperation.DELETE, files));
}
Also used : Context(android.content.Context) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) SpannableString(android.text.SpannableString) BroadcastReceiver(android.content.BroadcastReceiver) ItemAdapter(us.koller.cameraroll.adapter.item.ItemAdapter)

Aggregations

File_POJO (us.koller.cameraroll.data.models.File_POJO)22 Intent (android.content.Intent)10 Uri (android.net.Uri)6 RecyclerView (android.support.v7.widget.RecyclerView)6 View (android.view.View)6 BroadcastReceiver (android.content.BroadcastReceiver)5 Context (android.content.Context)5 TextView (android.widget.TextView)5 SuppressLint (android.annotation.SuppressLint)3 AlertDialog (android.support.v7.app.AlertDialog)3 Album (us.koller.cameraroll.data.models.Album)3 Activity (android.app.Activity)2 DialogInterface (android.content.DialogInterface)2 Handler (android.os.Handler)2 RequiresApi (android.support.annotation.RequiresApi)2 Snackbar (android.support.design.widget.Snackbar)2 ActionBar (android.support.v7.app.ActionBar)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 Toolbar (android.support.v7.widget.Toolbar)2 SpannableString (android.text.SpannableString)2