Giter Site home page Giter Site logo

agerabeauty's Introduction

#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

daimajia,Gank.io's organizer.

retrofit-agera-call-adapter,made by drakeet.

retrofit and its gson converter,made by square.

mosby,made by sockeqwe.

glide,made by bumptech.

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:

AgeraBus.

PowerfulRecyclerView.

#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.

agerabeauty's People

Stargazers

cxMax avatar fuqiang avatar huzongyao avatar Eugene Karasev avatar Pranav Lathigara avatar flex-col avatar Ricky Xu avatar  avatar Hcc avatar  avatar Ailurus avatar Running man! avatar 咕咚 avatar 70kg avatar Minamo avatar Dmitry Parenskiy avatar zjutkz avatar

Watchers

James Cloos avatar 小天 avatar Eugene Karasev avatar  avatar zjutkz avatar

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.