bracketcove / androidresttutorial Goto Github PK
View Code? Open in Web Editor NEWTutorial/Demo Project aimed at demonstrating the fundamentals of communcitating via RESTful Web Services.
Tutorial/Demo Project aimed at demonstrating the fundamentals of communcitating via RESTful Web Services.
If I have to populate the RecyclerView with CardViews how should I proceed? Will this code work by just changing the item_data.xml to have CardView?
I'm trying the same but I'm getting an error while injection at AndroidInjection.inject(this); in ListActivity.java
P.S My JSON data source is the same as yours.
permission declared in manifest, right?
Hello, I'm trying to run the code but I got this error:
E/ListActivity: setUpAdapterAndView: Only the original thread that created a view hierarchy can touch its views. W/System.err: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. W/System.err: at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7286) at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1155) at android.view.View.requestLayout(View.java:21926) I/chatty: uid=10096(u0_a96) RxCachedThreadS identical 4 lines W/System.err: at android.view.View.requestLayout(View.java:21926) at android.support.constraint.ConstraintLayout.requestLayout(ConstraintLayout.java:1959) W/System.err: at android.view.View.requestLayout(View.java:21926) at android.view.View.setFlags(View.java:13289) at android.view.View.setVisibility(View.java:9382) at android.support.v4.widget.ContentLoadingProgressBar.hide(ContentLoadingProgressBar.java:102) at com.wiseassblog.startingpoint.repolist.ListActivity.setUpAdapterAndView(ListActivity.java:112) at com.wiseassblog.startingpoint.repolist.ListPresenter$1.onNext(ListPresenter.java:83) W/System.err: at com.wiseassblog.startingpoint.repolist.ListPresenter$1.onNext(ListPresenter.java:72)
This problem happens when I set de scheduler like this:
disposable.add( datasource.getUserRepositories(user).observeOn(scheduler.getUiScheduler()) ......
but when I'm changing to use the MainThread, there is no problem:
disposable.add( datasource.getUserRepositories(user).observeOn(AndroidSchedulers.mainThread()) ......
so how can I solve really this? What am I doing wrong? I'm trying to run the app project but I'm getting the same problem.
Thanks for your response.
It seem to me that the scheduler provider introduces unnecessary complexities. If it only exists so you can change it in tests, then it also couples your presenter to the test. You're already assigning the task of selecting a scheduler to the presenter. In an android context, a presenter almost always observes on the UI thread so there's no reason to choose. We could inject the scheduler directly into the presenter and then in the test we can use Rxjava to substitute the trampoline scheduler. Here's how that might work:
In the application module:
@Provides
@Named(MAIN_THREAD)
@Singleton
Scheduler provideMainThreadScheduler() { return AndroidSchedulers.mainThread(); }
In the presenter:
@Inject
public ListPresenter(ViewInterface view,
RepositoryDataSourceInterface dataSource,
@Named(MAIN_THREAD) Scheduler scheduler) {
...
.observeOn(scheduler)
And in the test:
// Pass the trampoline scheduler to the observer for testing
presenter = new ListPresenter(view, dataSource, Schedulers.trampoline());
// Change subscriber scheduler to match observer for testing
RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(@NonNull Scheduler scheduler) throws Exception {
return Schedulers.trampoline();
}
});
It's worth noting here that the reason this currently works is because you're assigning the io scheduler in RepositoryDataSourceImpl. If you ever change that, your test breaks. But of course, that's what tests are for, right. I might consider moving the subscribeOn in RepositoryDataSourceImpl to the presenter. Then you know where everything is and you have better control in your testing.
I suppose you could also inject the io scheduler in the presenter by giving it a different name in @`Named. Seems logical but I haven't actually tried it.
One caveat. While I've run unit tests that pass using the above scenario, I haven't actually installed the application.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.