Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File/Folder picker dialog #30

Closed
isabsent opened this issue Mar 6, 2018 · 10 comments
Closed

File/Folder picker dialog #30

isabsent opened this issue Mar 6, 2018 · 10 comments

Comments

@isabsent
Copy link

isabsent commented Mar 6, 2018

I am going to create a simple file/folder chooser based on your library. For this purpose I would like to extending your SimpleListDialog and customize onItemClick :

import android.view.View;
import android.widget.AdapterView;

import eltos.simpledialogfragment.list.SimpleListDialog;

public class SimpleListDialogMod extends SimpleListDialog {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        super.onItemClick(parent, view, position, id); 
        //Some custom code
    }
}

and use it as follows:

SimpleListDialogMod.build()
        .title(titleResId)
        .choiceMode(SimpleListDialog.SINGLE_CHOICE)
        .choiceMin(1)
        .items(itemNames)
        .extra(extras)
        .pos(R.string.button_deeper)
        .neg(R.string.button_up)
        .neut(R.string.button_pick)
        .show(this, PICK_DIALOG);

but onItemClick is never called when I press an item in the list! Why?

P.S. Would you be so kind to write your own SimplePickFileDialog? It is widely used and would be very useful as I suppose.

@eltos
Copy link
Owner

eltos commented Mar 6, 2018

Given your code example, you are actually building a SimpleListDialog instead of a SimpleListDialogMod. Please have a look in the wiki here and my answer on the related issue #19.

In my opinion Androids Storage Access Framework provides a really good and advanced document picker, so I personally don't think it's worth the effort creating a SimplePickFileDialog. But feel free to create a pull request once you completed your work ;)

EDIT:
You might want to make use of the class CustomListDialog, which allows you to make more modifications (and would have thrown an exeption explaining the issue to you ;)).

@eltos eltos added the question label Mar 6, 2018
@isabsent
Copy link
Author

isabsent commented Mar 6, 2018

Given your code example, you are actually building a SimpleListDialog instead of a SimpleListDialogMod.

You are right, thanks!

Android Storage Access Framework provides a really good and advanced document picker...

I can lost some details, but it seems Android Storage Access Framework does not have an opportunity to pickup a folder.

@eltos eltos mentioned this issue Mar 6, 2018
3 tasks
@isabsent
Copy link
Author

isabsent commented Mar 6, 2018

Please, give a hint - what is a simplest way to insert file or folder icon before each list item? Is it possible by extending a SimpleListDialog or it is necessary to extend CustomListDialog?

@eltos
Copy link
Owner

eltos commented Mar 6, 2018

I can lost some details, but it seems Android Storage Access Framework does not have an opportunity to pickup a folder.

It does: Intent.ACTION_OPEN_DOCUMENT_TREE (API 21+ only though)

Please, give a hint - what is the simplest way to insert file or folder icon before each list item? Is it possible by extending a SimpleListDialog or it is necessary to extend CustomListDialog?

As said, I suggest to extend from CustomListDialog and write your own AdvancedAdapter implementation. The wiki and SimpleListDialog will give you some hints on how to do that.

@isabsent
Copy link
Author

isabsent commented Mar 6, 2018

It does: Intent.ACTION_OPEN_DOCUMENT_TREE (API 21+ only though)

Do you mean a DocumentFile.fromTreeUri() as a result of Android file picker? If yes, it is inacceptable when you need an access to the file with RandomAccessFile. It is impossible to get with Document File API unfortunately.

@isabsent
Copy link
Author

isabsent commented Mar 9, 2018

Enclosed zip-archive is a simplest realization of a File/Folder Chooser for internal phone memory (in SINGLE_CHOICE mode only) based on your library.

@isabsent
Copy link
Author

isabsent commented Mar 9, 2018

Enclosed zip-archive is a simplest realization of a File/Folder Chooser for internal phone memory (in SINGLE_CHOICE and MULTI_CHOICE modes) based on your library.

@isabsent
Copy link
Author

My implementation of FIle/Folder Picker Dialog based on your library.

@eltos eltos changed the title How to override onItemClick in SimpleListDialog? File/Folder picker dialog Mar 13, 2018
@eltos eltos removed the question label Mar 13, 2018
@eltos
Copy link
Owner

eltos commented Mar 13, 2018

Great work @isabsent, looks good :)
I'll add a link to your extension in the readme. Or do you want to create a pull request?

@isabsent
Copy link
Author

isabsent commented Mar 13, 2018

I have never made a pull request before and I am not sure my code is acceptable for you. I think it would be better if you take my code, change it and include it in your code in consistence with your approach to the library construction.

@eltos eltos added this to the v3.0 milestone Apr 14, 2018
@eltos eltos removed this from the v3.1 milestone Feb 13, 2019
@eltos eltos removed the help wanted label Dec 9, 2021
@eltos eltos closed this as completed Dec 9, 2021
eltos added a commit that referenced this issue Sep 4, 2022
<p align="center" >
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="media/logo_named_right_darkmode.png">
  <source media="(prefers-color-scheme: light)" srcset="media/logo_named_right.png">
  <img width="50%" src="media/logo_named_right.png">
</picture>
</p>

# SimpleDialogFragments

[![API 14+](https://img.shields.io/badge/API-14+-green.svg)](https://developer.android.com/about/dashboards/index.html#Platform)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.eltos/simpledialogfragments.svg)](https://search.maven.org/artifact/io.github.eltos/simpledialogfragments)
[![JitPack](https://jitpack.io/v/eltos/SimpleDialogFragments.svg)](https://jitpack.io/#eltos/SimpleDialogFragments)
[![Code Climate Rating](https://codeclimate.com/github/eltos/SimpleDialogFragments/badges/gpa.svg)](https://codeclimate.com/github/eltos/SimpleDialogFragments)
[![Github CI](https://github.com/eltos/SimpleDialogFragments/actions/workflows/build.yml/badge.svg)](https://github.com/eltos/SimpleDialogFragments/actions/workflows/build.yml)
[![License](https://img.shields.io/github/license/eltos/simpledialogfragments.svg)](https://github.com/eltos/SimpleDialogFragments#license)






<img width="40%" align="right" src="https://github.com/eltos/SimpleDialogFragments/raw/main/media/screenshot.png"/>

SimpleDialogFragments Library is a collection of easy to use and extendable DialogFragment's for Android.
It is fully compatible with rotation changes and can be implemented with only a few lines of code.

A new approach of result handling ensures data integrity over rotation changes, that many other libraries lack.



|[🧑‍💻 API](https://eltos.github.io/SimpleDialogFragments)|[ℹ️ Wiki](https://github.com/eltos/SimpleDialogFragments/wiki)|[🚀 Releases](https://github.com/eltos/SimpleDialogFragments/releases)|[🖼️ Screenshots](https://github.com/eltos/SimpleDialogFragments/wiki/Showcase)om/sponsors/eltos) |
|-|-|-|-|-|-|

|[🧑‍💻 API](https://eltos.github.io/SimpleDialogFragments)|[ℹ️ Wiki](https://github.com/eltos/SimpleDialogFragments/wiki)|[🚀 Releases](https://github.com/eltos/SimpleDialogFragments/releases)|[🖼️ Screenshots](https://github.com/eltos/SimpleDialogFragments/wiki/Showcase)|[📱 Demo APK](https://github.com/eltos/SimpleDialogFragments/releases/download/v3.4/testApp.apk)|[🪙 DONATE](https://github.com/sponsors/eltos) |
|-|-|-|-|-|-|




### Features

* Common dialogs that can be used with few lines of code
  * Alert dialogs
  * Input and checkbox dialogs with suggestions and validations
  * Filterable single- / multi-choice dialogs
  * Color pickers (palettes and/or HSV)
  * Extensive forms
  * Date and time pickers
  * Pin code dialog
  * Progress dialogs
* Easy result handling even after rotation changes
* Persistence on rotation changes
* Material design
* Customizable and extendable dialogs


## Usage

Check the [release page](https://github.com/eltos/SimpleDialogFragments/releases) for the latest and older versions:

In your module level ``build.gradle`` when using [mavenCentral](https://search.maven.org/artifact/io.github.eltos/simpledialogfragments):
```groovy
dependencies {
    implementation 'io.github.eltos:simpledialogfragments:3.6.3'
}
```
or if using [JitPack](https://jitpack.io/#eltos/SimpleDialogFragments):
```groovy
dependencies {
    implementation 'com.github.eltos:simpledialogfragments:v3.6.3'
}
```

### Building dialogs

Building dialogs is very easy and short handed:

```java
SimpleDialog.build()
            .title(R.string.hello)
            .msg(R.string.hello_world)
            .show(this);
```

Check the [wiki pages](https://github.com/eltos/SimpleDialogFragments/wiki) for instructions and examples on how to build the different dialogs available.

### Receive Results
Supply a tag when showing the dialog and let the hosting Activity or Fragment implement the `SimpleDialog.OnDialogResultListener`.  
For details, please refere to the [wiki pages](https://github.com/eltos/SimpleDialogFragments/wiki/SimpleDialog#receiving-results).

```java
@OverRide
public boolean onResult(@nonnull String dialogTag, int which, @nonnull Bundle extras) {
    if (YES_NO_DIALOG.equals(dialogTag) && which == BUTTON_POSITIVE){
        // ...
        return true;
    }
    if (LIST_DIALOG.equals(dialogTag) && which == BUTTON_POSITIVE){
        ArrayList<Integer> pos = extras.getIntegerArrayList(SimpleListDialog.SELECTED_POSITIONS);
        // ...
        return true;
    }
    if (REGISTRATION_DIALOG.equals(dialogTag) && which == BUTTON_POSITIVE){
        String username = extras.getString(USERNAME);
        String password = extras.getString(PASSWORD);
        // ...
        return true;
    }
    // ...
    return false;
}

```

## Extensions
Known extensions and projects using this library:
- [File/Folder picker](https://github.com/isabsent/FilePicker) (see [#30](#30))

## License

Copyright 2017-2022 Philipp Niedermayer ([github.com/eltos](https://github.com/eltos))

Licensed under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)  


You may only use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software in compliance with the License. For more information visit http://www.apache.org/licenses/LICENSE-2.0  
The above copyright notice alongside a copy of the Apache License shall be included in all copies or substantial portions of the Software not only in source code but also in a license listing accessible by the user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants