Search in sources :

Example 6 with File_POJO

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

the class AlbumActivity method deleteAlbumItems.

public void deleteAlbumItems(final AlbumItem[] selected_items, final int[] indices) {
    File_POJO[] filesToDelete = new File_POJO[selected_items.length];
    for (int i = 0; i < filesToDelete.length; i++) {
        filesToDelete[i] = new File_POJO(selected_items[i].getPath(), true);
    }
    registerLocalBroadcastReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            switch(intent.getAction()) {
                case FileOperation.RESULT_DONE:
                    unregisterLocalBroadcastReceiver(this);
                    break;
                case FileOperation.FAILED:
                    String path = intent.getStringExtra(FileOperation.FILES);
                    for (int i = 0; i < selected_items.length; i++) {
                        if (selected_items[i].getPath().equals(path)) {
                            int index = indices[i];
                            if (index < album.getAlbumItems().size()) {
                                album.getAlbumItems().add(index, selected_items[i]);
                            } else {
                                album.getAlbumItems().add(selected_items[i]);
                            }
                            recyclerViewAdapter.notifyItemInserted(indices[i]);
                            break;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    });
    startService(FileOperation.getDefaultIntent(this, FileOperation.DELETE, filesToDelete));
}
Also used : Context(android.content.Context) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) BroadcastReceiver(android.content.BroadcastReceiver)

Example 7 with File_POJO

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

the class ExcludePathsActivity method loadDirectory.

public void loadDirectory(final String path) {
    final Snackbar snackbar = Snackbar.make(findViewById(R.id.root_view), getString(R.string.loading), Snackbar.LENGTH_INDEFINITE);
    Util.showSnackbar(snackbar);
    filesProvider = new FilesProvider(this);
    final FilesProvider.Callback callback = new FilesProvider.Callback() {

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

                @Override
                public void run() {
                    filesProvider.onDestroy();
                    snackbar.dismiss();
                    if (dir == null) {
                        return;
                    }
                    File_POJO currentDir = removeFiles(dir);
                    if (currentDir == null) {
                        return;
                    }
                    ExcludePathsActivity.this.currentDir = currentDir;
                    if (recyclerViewAdapter != null) {
                        recyclerViewAdapter.setFiles(currentDir);
                        recyclerViewAdapter.notifyDataSetChanged();
                        onPathChanged();
                    }
                }
            });
        }

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

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

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

                @Override
                public void run() {
                    finish();
                }
            });
        }
    };
    filesProvider.loadDir(this, path, callback);
}
Also used : FilesProvider(us.koller.cameraroll.data.provider.FilesProvider) File_POJO(us.koller.cameraroll.data.models.File_POJO) Snackbar(android.support.design.widget.Snackbar)

Example 8 with File_POJO

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

the class FileExplorerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    final File_POJO file = files.getChildren().get(position);
    ((FileHolder) holder).setFile(file);
    ((FileHolder) holder).setSelected(selected_items[position]);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mode == SELECTOR_MODE) {
                onItemSelect(file);
            } else if (file.isMedia) {
                int index = file.getPath().lastIndexOf("/");
                String path = file.getPath().substring(0, index);
                // load Album
                final Album album = new Album().setPath(path);
                AlbumItem albumItem = AlbumItem.getInstance(file.getPath());
                if (albumItem != null) {
                    album.getAlbumItems().add(albumItem);
                }
                if (albumItem != null) {
                    // create intent
                    Intent intent = new Intent(holder.itemView.getContext(), IntentReceiver.class).setAction(Intent.ACTION_VIEW).setData(albumItem.getUri(holder.itemView.getContext()));
                    holder.itemView.getContext().startActivity(intent);
                }
            } else {
                // to keep the ripple animation
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        directoryChangeCallback.changeDir(file.getPath());
                    }
                }, 300);
            }
        }
    });
    holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            onItemSelect(file);
            return true;
        }
    });
    // clicking on folder icons also selects this item
    holder.itemView.findViewById(R.id.folder_indicator).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onItemSelect(file);
        }
    });
}
Also used : Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Handler(android.os.Handler) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) FileHolder(us.koller.cameraroll.adapter.fileExplorer.viewHolder.FileHolder)

Example 9 with File_POJO

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

the class FileLoader method onFile.

@Override
public void onFile(Context context, File file) {
    File_POJO file_pojo = new File_POJO(file.getPath(), MediaType.isMedia(file.getPath()));
    dir_pojo.addChild(file_pojo);
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO)

Example 10 with File_POJO

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

the class Copy method execute.

@Override
public void execute(Intent workIntent) {
    File_POJO[] files = getFiles(workIntent);
    File_POJO target = workIntent.getParcelableExtra(TARGET);
    if (target == null) {
        return;
    }
    int success_count = 0;
    onProgress(success_count, files.length);
    boolean copyingOntoRemovableStorage = Util.isOnRemovableStorage(target.getPath());
    Uri treeUri = null;
    if (copyingOntoRemovableStorage) {
        treeUri = getTreeUri(workIntent, target.getPath());
        if (treeUri == null) {
            return;
        }
    }
    for (int i = files.length - 1; i >= 0; i--) {
        boolean result = copyFilesRecursively(getApplicationContext(), treeUri, files[i].getPath(), target.getPath(), true);
        success_count += result ? 1 : 0;
        onProgress(success_count, files.length);
    }
    if (success_count == 0) {
        onProgress(success_count, files.length);
    }
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO) Uri(android.net.Uri)

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