#AgeraBeauties
A sample App based on Gank.io's Api, using Agera as the model engine.
#Why
Recently,there are so many Apps choosing RxJava+retrofit+MVP to be the framework of itself,while I thought Agera may be the better one in Android platform instead of RxJava because the latter is so heavy and Agera can do all the things RxJava does.
So I made this App to show how to use Agera to replace RxJava in the model layer of an Android App.
#How Agera works
Agera+retrofit:
BeautyApi api = BeautyService.getInstance().getNetEngine().create(BeautyApi.class);
repository = Repositories.repositoryWithInitialValue(beauty)
.observe()
.onUpdatesPerLoop()
.goTo(Executors.newSingleThreadExecutor())
.thenAttemptGetFrom(api.getUserInfo(page++))
.orEnd(errorHandler)
.compile();
AgeraBus:
AgeraBus.eventRepositories().post(new LoadEvent(true,lastAction,beauties.results));
@Override
public void onEventReceiveInMain() {
Object event = AgeraBus.eventRepositories().get();
if(event instanceof LoadEvent){
if(!((LoadEvent) event).isSuccess){
beauties.showNoDataView();
return;
}
if(((LoadEvent) event).reqType == MainPresenter.REFRESH){
beauties.stopRefresh();
}else {
beauties.stopLoadMore();
}
setBeautiesToAdapter((LoadEvent)event);
}else if(event instanceof RouteEvent){
RouteEvent routeEvent = (RouteEvent)event;
if(RouterProtocol.GALLERY.equals(routeEvent.protocol)){
jumpToGallery(routeEvent);
}
}
}
Saving a picture using Agera:
public void savePic(final String data) throws ExecutionException, InterruptedException {
lastAction = ACTION_SAVE;
repo = Repositories.repositoryWithInitialValue(data)
.observe()
.onUpdatesPerLoop()
.goLazy()
.attemptTransform(FileUtils.savePic())
.orEnd(errorHandler)
.thenGetFrom(successHandler)
.compile();
}
public static Function<String,Result<Boolean>> savePic(){
return Functions.functionFrom(String.class)
.apply(FunctionProvider.fileStreamFunction)
.thenApply(FunctionProvider.savePicFunction);
}
So you can see everything related with data in this App can be handled with the help of Agera.
#Thanks to
retrofit-agera-call-adapter,made by drakeet.
retrofit and its gson converter,made by square.
android-gif-drawable.made by koral--.
PhotoView,made by chrisbanes.
BottomSheet,made by Kennyc1012.
roundedimageview,made by vinc3m1.
infinitecycleviewpager,made by Devlight.
At last,two repositories made by myself:
#License
Copyright 2016 zjutkz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.