Comments (19)
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.
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.
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.
I can confirm that the onNext is called. I have also logged all the items from mProd. It is working as expected!
from thirtyinch.
And your Activity is in foreground? Then the sendToView
lambda should be called.
from thirtyinch.
Yeah. The Activity is in foreground. I even add a log statement in sendToView
. It is also not executed :(
from thirtyinch.
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.
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.
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.
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.
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.
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.
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.
I've created a short test and everything worked like expected.
-> https://gist.github.com/anonymous/111e6c4c50548503f46868731fb08d9f
from thirtyinch.
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.
Solved it! The problem is that i'm injecting another instance of presenter in my activity.
from thirtyinch.
@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.
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.
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)
- Debugging a @CallOnMainThread annotated method crashes the app HOT 2
- Create Kotlin module/extensions HOT 2
- Switch from compileOnly to implementation HOT 1
- [Discussion] Should manageViewDisposable() throw an exception
- Support for AndroidX HOT 4
- BackstackReader doesn't work with AndroidX HOT 3
- "Don't add observers when the presenter reached the DESTROYED state" EXCEPTION HOT 1
- sendToView HOT 4
- Lint warning with sendToView, but not with deliverToView
- Why saving the Presenter on orientation change HOT 1
- Problems with @CallOnMainThread
- Lint does not report by abstract classes without implementation View
- Crash using AndroidX with ProGuard enabled HOT 2
- Lint reports: Obsolete custom lint check
- bundle[buildType] was replaced with AGP 3.2.0
- Package thirtyinch-kotlin-coroutines not published HOT 3
- Plugin module not available with version 0.9.5 HOT 2
- Release for androidx HOT 2
- Restore old BackstackReader.isInBackstack() implementation once AndroidX Fragment 1.2.1 is released HOT 1
- Migrate away from JCenter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thirtyinch.