Code Monkey home page Code Monkey logo

Comments (6)

SeppPenner avatar SeppPenner commented on May 29, 2024 1

I've created a gist for that one: https://gist.github.com/SeppPenner/c72e3e3cd90702c42355a12b7bcad2c9

The main changes would be to add two methods:

public void setNegativeButton(@StringRes int textId, final DialogInterface.OnClickListener listener){
        builder.setNegativeButton(textId, listener);
    }

    public void setOnCancelListener(DialogInterface.OnCancelListener listener){
        builder.setOnCancelListener(listener);
}

put the builder variable globally:

    //...
    private @DrawableRes
    int _iconRes = -1;
    private @LayoutRes
    int _layoutRes = -1;
    private String _dateFormat;
    private AlertDialog.Builder builder;

, update the build() method (removed the whole stuff with setting negative button here)
and adjust the check on top of the build() method like following:

 public ChooserDialog build() {
        if (_titleRes == 0 || _okRes == 0) {
            throw new RuntimeException("withResources() should be called at first.");
        }
//...
}

However, I do not know if this can be done in another way as it destroys the method chaining style the library is written in, but my suggestion would need to remove the with(Context) method and add this directly to the constructor:

public ChooserDialog(Context context) {
        this._context = context;
        builder = new AlertDialog.Builder(_context);
    }

An empty constructor would then not exist any longer...

That's also why I didn't create a pull request for this topic.

from android-file-chooser.

hedzr avatar hedzr commented on May 29, 2024 1

yes, here is it

from android-file-chooser.

hedzr avatar hedzr commented on May 29, 2024

Thx for your suggestion.

I have another consideration is whether there is a way to make the new improvements and the old style method calling coexist.

Would you mind to separate your thoughts into 2 parts? The first one is some new functions if your think it’s useful or more convenient for every user. So I can simply merge it into new version. The other one I think there’s some changes have to make to maintain the backwards compatibility.

from android-file-chooser.

SeppPenner avatar SeppPenner commented on May 29, 2024

Hi @hedzr, I will try to provide 1 (or more) pull requests in the future when I have time. I will check to provide backwards compatibility, too. (I know, my update was just a quick and dirty fix)

from android-file-chooser.

hedzr avatar hedzr commented on May 29, 2024

πŸ˜™, i'd maken a new release, because my hands are out of control. Hope it's useful.

from android-file-chooser.

SeppPenner avatar SeppPenner commented on May 29, 2024

Hi @hedzr. Did you already add my suggestions to your code? It seems so if I look to the ChooserDialog.java class:

 public ChooserDialog withNegativeButton(@StringRes int cancelTitle,
            final DialogInterface.OnClickListener listener) {
        this._negativeRes = cancelTitle;
        this._negativeListener = listener;
        return this;
    }

    public ChooserDialog withNegativeButtonListener(final DialogInterface.OnClickListener listener) {
        this._negativeListener = listener;
        return this;
    }

    /**
     * it's NOT recommended to use the `withOnCancelListener`, replace with `withNegativeButtonListener` pls.
     */
    public ChooserDialog withOnCancelListener(final DialogInterface.OnCancelListener listener) {
        this._cancelListener2 = listener;
        return this;
    }

In my opinion, this is already the solution I wanted to have :D

from android-file-chooser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.