Giter Site home page Giter Site logo

commonlib's Introduction

Android Common Lib

Introduction

Home brew android common lib

Feature

IO

network module, compatible with both Volley and RoboSpice, all-in-one request management image loading, both for items in scroll container and idle item,also blur image load and cache support cache ,both on ram and disk

UI

TextView and EditText with custom font support MVVM framework on list item Dialog customisation support (maybe more animation support in the future)

Request Framework

full-case coverage for all request

Util

Bitmap,Date,File utils

Usage

####Step 1(installation): Gradle:

    compile 'me.suanmiao.common:library:0.1.6'

####Step 2(setup application):

  • Create a "Application" class extends BaseApplication and set it to be main Application
public class SApplication extends BaseApplication {

  @Override
  protected RequestManager initRequestManager() {
    return new RequestManager(this,".commonExample");
  }
}
    <application
        android:name="me.suanmiao.example.component.SApplication"
        ...
        >

####Step 3(usage of feature):

  • Setup Volley Request
    //setup request class extends CommonRequest
    public class ChannelRequest extends CommonRequest<ChannelModel> {
      ...
    }


    //execute request
    String url = "http://zhihurss.miantiao.me/zhihuzhuanlan/taosay";
    ChannelRequest request = new ChannelRequest(url);
    executeRequest(request, new VolleyCommonListener<ChannelModel>() {
      @Override
      public void onErrorResponse(VolleyError error) {
        //deal with request error
      }

      @Override
      public void onResponse(ChannelModel response) {
      //deal with result
     }
    });
  • Setup RoboSpice Request
  // setup Request Service
  public class RequestService extends RetrofitGsonSpiceService {

      private static OkHttpClient okHttpClient;

      @Override
      public void onCreate() {
          super.onCreate();
          addRetrofitInterface(APIService.class);
      }

      public static OkHttpClient getOkHttpClient();

      @Override
      protected String getServerUrl() {
          return APIConstants.BASE_URL;
      }
  }

  //setup request class
  public class SpiceExampleRequest extends BaseRoboRequest<ExampleItemModel, APIService> {
    public SpiceExampleRequest() {
      super(ExampleItemModel.class, APIService.class);
    }

    @Override
    public ExampleItemModel loadDataFromNetwork() throws Exception {
      return getService().getExample("token", "id");
    }
  }
  //execute request
  SpiceExampleRequest request1 = new SpiceExampleRequest();
  executeRequest(new SpiceBuilder<ExampleItemModel>().request(request1).build(),
      new SpiceCommonListener() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {
        }

        @Override
        public void onRequestSuccess(Object o) {
        }
      });
  • Photo load static
   Photo.loadImg(itemView.img,url, R.drawable.ic_launcher);
  • Photo load in ListView
public class ExampleItemViewModel extends BaseViewModel {
  ...

  @Override
  public void bind(int index, BaseModel baseModel, int scrollState, float scrollSpeed) {
    ...
    // load image when scroll
    Photo.loadScrollItemImg(itemView.img, model.img, R.drawable.ic_launcher, scrollState,
            scrollSpeed);
  }

  @Override
  public void idleReload() {
    ...
    // load image when list stop scrolling
    Photo.reloadImg(itemView.img);
  }
}

Other

it's a library designed in my coding and feature style, and the stability hasn't been verified

Copyrights

Copyright 2014, suanmiao

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.

commonlib's People

Watchers

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