Code Monkey home page Code Monkey logo

Comments (19)

StefMa avatar StefMa commented on May 24, 2024

Hey,
what are you trying?
sendToView wait's until the view got attached.
You can use it in your onCreate (for example):
sendToView(view -> view.showProgress());

getView() can cause a NPE when your view isn't attached yet to the TiPresenter.

i'm calling the getProductsByCat after the Presenter onAttach

When do you call this method?

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

I'm trying to load Items into my Recyclerview when the loading is completed in my Presenter. How can i Call updateItems from my Presenter ?

The onViewReady is called in the Oncreate after setContentView

public class BrowseActivity extends BaseActivity implements BrowseView, BrowseAdapter.ClickListener{

    @Inject
    DataManager mDataManager;
    @Inject
    BrowsePresenter mBrowsePresenter;

    BrowseAdapter mBrowseAdapter;
    @BindView(R.id.bmb)
    BoomMenuButton bmb;

 private final TiActivityPlugin<BrowsePresenter, BrowseView> mPresenterPlugin = new TiActivityPlugin<BrowsePresenter, BrowseView>(
            () -> new BrowsePresenter(mDataManager));

    public BrowseActivity() {
        addPlugin(mPresenterPlugin);
    }

    @Override
    protected void onViewReady(Bundle savedInstanceState, Intent intent) {
        super.onViewReady(savedInstanceState, intent);
        setupViews();
        assert bmb != null;
        bmb.setButtonEnum(ButtonEnum.TextInsideCircle);
        bmb.setPiecePlaceEnum(PiecePlaceEnum.DOT_9_1);
        bmb.setButtonPlaceEnum(ButtonPlaceEnum.SC_9_2);
        TextInsideCircleButton.Builder builder = new TextInsideCircleButton.Builder()
                        .normalImageRes(R.drawable.cat_beverages)
                        .normalText("Beverages")
                        .normalColorRes(R.color.orange)
                        .listener(new OnBMClickListener() {
                                @Override
                            public void onBoomButtonClick(int index) {
                                mBrowsePresenter.getProductsByCat(MYConstants.CAT_BEVERAGES);
                            }
                        });
                bmb.addBuilder(builder);
            }
}

 @Override
    public void updateItems(List<Product> items) {
        mBrowseAdapter.setNewData(items);
        mBrowseAdapter.notifyDataSetChanged();
        Timber.d("Adapter Count" + items.get(0).productName() + mBrowseAdapter.getData().size());
    }

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

Can you confirm onNext is called?

                    .subscribe(mProd -> {
                            Timber.d(mProd.get(0).productName());
                            sendToView(view -> {
                                view.hideProgress();
                                view.showText("Hello");
                                view.updateItems(mProd);
                            });
                        })

Either you are never calling getProductsByCat(category) or this Observable completes before it emits an item.

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

I can confirm that the onNext is called. I have also logged all the items from mProd. It is working as expected!

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

And your Activity is in foreground? Then the sendToView lambda should be called.

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

Yeah. The Activity is in foreground. I even add a log statement in sendToView. It is also not executed :(

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

When you say getView() is null then the view is not attached. Either onAttachView(view) isn't called or onDetachView() is called already.
Add a TiLogger and post the output

TiLog.setLogger(TiLog.LOGCAT);

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

Instead of calling getProductsByCat(category) from Activity. I moved it to onAttachView & used getView() instead of sendToView. It works perfectly.
But Calling from Activity doesn't triggers getView or sendToView

This Log is called while the App is in foreground
01-09 22:55:15.176 31529-31529/? V/ThirtyInch: BrowsePresenter:TiPresenter@3ae18bb: deprecated onWakeUp()

These Logs are called when i Press home & comeback

01-09 22:58:28.056 31529-31529/? V/ThirtyInch: BrowsePresenter:TiPresenter@3ae18bb: deprecated onSleep()
01-09 22:58:28.056 31529-31529/? V/ThirtyInch: BrowsePresenter:TiPresenter@3ae18bb: onDetachView()
01-09 22:58:32.945 31529-31529/? V/ThirtyInch: TiActivityPlugin:TiActivity@1a4f10db:BrowseActivity@2f2f1778: binding the cached view to Presenter me.arulnad.activities.BrowseActivity@2f2f1778
01-09 22:58:32.945 31529-31529/? V/ThirtyInch: BrowsePresenter:TiPresenter@3ae18bb: onAttachView(TiView)
01-09 22:58:32.946 31529-31529/? V/ThirtyInch: BrowsePresenter:TiPresenter@3ae18bb: deprecated onWakeUp()

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

If i use manageViewSubscription instead of manageSubscription . I get the below exception!

java.lang.IllegalStateException: view subscriptions can't be handled when there is no view at net.grandcentrix.thirtyinch.rx.RxTiPresenterSubscriptionHandler.manageViewSubscription(RxTiPresenterSubscriptionHandler.java:80) at me.arulnadhan.grocerycorecommon.ui.browse.BrowsePresenter.getProductsByCat(BrowsePresenter.java:59)

from thirtyinch.

StefMa avatar StefMa commented on May 24, 2024

Can you please show your presenter code, when you call your getProductsByCat()❗️

Normally you have to use manageViewSubscription because you will destroy the subscription after your view got detached. That is the right behaviour.
It seems, however why, that the View don't get attached to the Presenter 🤔

from thirtyinch.

StefMa avatar StefMa commented on May 24, 2024

Instead of calling getProductsByCat(category) from Activity. I moved it to onAttachView & used getView() instead of sendToView. It works perfectly.
But Calling from Activity doesn't triggers getView or sendToView

So, wait what?!
getProductsByCat() is business logic and have nothing todo inside your Activity.
So they right way is to have it inside the Presenter!

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

When a Button is clicked on my Activity, I should change the products according to the category. So i should pass the Category ID to the Presenter in my Activity.
So i can't call getProductsByCat() from my Presenter!

Please take a look at my gist https://gist.github.com/AruLNadhaN/dc023c5854dab5000b73e800ae96fc70#file-browseactivity-java-L34

from thirtyinch.

StefMa avatar StefMa commented on May 24, 2024

I'm I wrong or do you use two different Presenters? ;)
First presenter
Second One

You attach the First one to your Activity but call the getProductsByCat() to the second one. And the second one don't get attached to the Activity... 🤔 Right?

from thirtyinch.

StefMa avatar StefMa commented on May 24, 2024

I've created a short test and everything worked like expected.
-> https://gist.github.com/anonymous/111e6c4c50548503f46868731fb08d9f

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

You inject one Presenter and create another one in your Activity. Don't inject the Presenter and only use the one created from the plugin.

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

Solved it! The problem is that i'm injecting another instance of presenter in my activity.

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

@StefMa @passsy I recently changed my view code from Activity to Fragment. After the change, the String values are not retained. They always return NULL.

The string Email returns the value here correctly. But when it is called from the Fragment. It always returns NULL

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

Please ask those questions on Stackoverflow where you can get quick help from a bigger audience for your beginner questions.
Open issues here when you find bugs in the library, not bugs in your code.

from thirtyinch.

AruLNadhaN avatar AruLNadhaN commented on May 24, 2024

sorry. I thought that the values are not retained due to the library. Because it was working fine. When i was calling the presenter from the Activity.

from thirtyinch.

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.