Git Product home page Git Product logo

androidresttutorial's People

Contributors

bracketcove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

androidresttutorial's Issues

Regarding the CardView implementation

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.

Only the original thread that created a view hierarchy can touch its views

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.

BaseSchedulerProvider, coupling, and complexities

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.

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.