Code Monkey home page Code Monkey logo

Comments (10)

SaeedMasoumi avatar SaeedMasoumi commented on August 21, 2024 1

@RiccardoM Sorry for responding too late. I found the problem, It's because your custom views has same Loader id so android give you same presenter instance.
I'm working on it to fix this problem

from easymvp.

mohamad-amin avatar mohamad-amin commented on August 21, 2024

@RiccardoM I don't think it's a bug as it's not using the same instance. Take a look at this gist. This behavior is expected as you're using the static keyword. EasyMVP is creating multiple presenters but they all have the same pointer to the counter variable.
Does your presenter still show numbers from 0 to 9 if you remove the static keyword?

from easymvp.

RiccardoM avatar RiccardoM commented on August 21, 2024

@mohamad-amin The problem that I've described is that, instead of the correct 0 1 2 3 4 5 6 7 8 9 string, the code that I've presented prints the incorrect 0 0 0 0 0 0 0 0 0 0. This is possibile if and only if the injected presenter instance is always the first that is created, otherwise it would correctly print 0 1 2 3 4 5 6 7 8 9 if the injection would perform as expected (creating always a new presenter instance).

from easymvp.

RiccardoM avatar RiccardoM commented on August 21, 2024

Any progress on this @SaeedMasoumi?

from easymvp.

RiccardoM avatar RiccardoM commented on August 21, 2024

@SaeedMasoumi Thanks man, appreciate it a lot.

from easymvp.

RiccardoM avatar RiccardoM commented on August 21, 2024

@SaeedMasoumi Any update on this?

from easymvp.

SaeedMasoumi avatar SaeedMasoumi commented on August 21, 2024

@RiccardoM Sorry for late response,
I fixed this issue with @PresenterId annotation. Actually I can't found any better solution according to the limitation of android loaders.
So your ViewImp class should change to

@CustomView(presenter = Presenter.class)
public class ViewImpl extends android.View implements View {
    @Presenter Presenter presenter;
    @BindView(R2.id.icon_label_textview) TextView labelTextView;

    @PresenterId
    int id = 0;

    public ViewImpl(Context context, int id){  // or any way you can fill "id"
        View view = LayoutInflater.from(context).inflate(R.layout.view_layout, this);
        ButterKnife.bind(this, view);
        this.id = id;
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        presenter.setupView();
    }

    @Override
    public void setLabelText(String text) {
        labelTextView.setText(text);
    }

See this test case for more info

from easymvp.

SaeedMasoumi avatar SaeedMasoumi commented on August 21, 2024

Also this bug fix will be included in 1.2.0-beta5 release

from easymvp.

RiccardoM avatar RiccardoM commented on August 21, 2024

@SaeedMasoumi I guess it's fair as long as it solves the problem that many have encoutered. If, looking trough the code on how you made this happen, I find a better solution, I'll post it here just so later viewers can see it.
I also think that this new annotation should be inserted into the README.md file to let everyone know its existence.

Thank you again, great job.

from easymvp.

SaeedMasoumi avatar SaeedMasoumi commented on August 21, 2024

@RiccardoM Thanks, EasyMVP calls getLoaderManager().initLoader(ID, ... , ... ); method, by default the ID is a simple counter object so when you create multiple instances of a class it will assign same id to them, There will be better solutions maybe, I think it can be simplified with putting ids in Bundle, but i encountered some bugs in custom Views

from easymvp.

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.