Skip to content
This repository has been archived by the owner on Jul 23, 2022. It is now read-only.

Folder added as an item while selecting multiple files #81

Open
sivansundar opened this issue Oct 8, 2019 · 3 comments
Open

Folder added as an item while selecting multiple files #81

sivansundar opened this issue Oct 8, 2019 · 3 comments

Comments

@sivansundar
Copy link

Hi.

While adding multiple files to an array adapter which populates a recycler view, the folder also gets added as an item.

Example :

device-2019-10-08-141347

Twitter is the folder in which the image file is located.

ezgif-4-acd228508286

Is there a fix to this?

@hedzr
Copy link
Owner

hedzr commented Oct 8, 2019

Hi @sivansundar I'd run on 1.2.0 (it's our newest release) but the matter not seen.
I'm looking for more details...

Tested:

  1. popup dialog, select the first image
  2. create a new folder via options button bar
  3. select more images and confirm them
  4. It seems working well.

@sivansundar
Copy link
Author

The problem still persists. I've chosen multiple files from a folder but the folder also gets added as an item.

As a temporary fix, I've decremented the size of the ArrayList object by 1 in the adapter class.

public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.ViewHolder>{

private ArrayList<FileList_AddFiles> mFileObject;

public FilesAdapter(ArrayList<FileList_AddFiles> mFileObject) {
    this.mFileObject = mFileObject;
}

@NonNull
@Override
public FilesAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

.

.

.

.

.


}

@Override
public void onBindViewHolder(@NonNull FilesAdapter.ViewHolder holder, int position) {

    FileList_AddFiles fileObject = mFileObject.get(position);

    holder.setFileName(fileObject.getList_fileName());
}

@Override
public int getItemCount() {

    int size = 0;
    Log.d(TAG, "getItemCount: inside adapter : " + mFileObject.size());
    if(mFileObject.size()>1) {
        size = mFileObject.size()-1;

    }        return size;
}

@hedzr
Copy link
Owner

hedzr commented Oct 10, 2019

So where the data are coming from, in your mFileObject, I'm expecting what content are saying in chooserDialog.withChosenListener() & withDismissListener()...

Here is an clean multi-select afc picker:

object Demo {
    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    fun demo2(context: Context, startPath: String, callback: ((paths: ArrayList<String>) -> Unit)? = null) {
        val files = ArrayList<File>()
        val dlg = ChooserDialog(context)
        dlg.displayPath(true)
            .withFilter(false, true, "jpg", "jpeg", "png")
            .withStartFile(startPath)
            .enableOptions(true)
            .enableMultiple(true)
            .withResources(R.string.title_choose_file, R.string.title_choose, R.string.dialog_cancel)
            .withOptionResources(R.string.option_create_folder, R.string.options_delete, R.string.new_folder_cancel, R.string.new_folder_ok)
            .withChosenListener { dir, dirFile ->
                if (dirFile.isDirectory) {
                    dlg.dismiss()
                } else if (!files.remove(dirFile)) {
                    files.add(dirFile)
                }
            }
            .withOnDismissListener {
                val paths = ArrayList<String>()
                if (files.isNotEmpty()) {
                    for (file in files) {
                        paths.add(file.absolutePath)
                    }
                }
                callback?.invoke(paths)
            }
            .withDateFormat("dd MMMM yyyy")
            .build()
            .show()
    }
}

And, use it:

Demo.demo2(ctx, "") { paths ->
    val builder = AlertDialog.Builder(ctx, R.style.FileChooserDialogStyle)
    builder.setTitle("${paths.size} files selected:")
        .setAdapter(ArrayAdapter(ctx, android.R.layout.simple_expandable_list_item_1, paths), null)
        .create()
       .show()
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants