Search in sources :

Example 1 with AppComponent

use of com.tool.common.di.component.AppComponent in project MVPFrames by RockyQu.

the class GlideConfiguration method registerComponents.

@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    // Glide默认使用HttpURLConnection做网络请求,在这切换成Okhttp请求
    AppComponent appComponent = AppUtils.obtainAppComponentFromContext(context);
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.getOkHttpClient()));
}
Also used : OkHttpUrlLoader(com.tool.common.http.OkHttpUrlLoader) AppComponent(com.tool.common.di.component.AppComponent)

Example 2 with AppComponent

use of com.tool.common.di.component.AppComponent in project MVPFrames by RockyQu.

the class GlideConfiguration method applyOptions.

@Override
public void applyOptions(Context context, GlideBuilder builder) {
    final AppComponent component = AppUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(FileUtils.makeDirs(new File(component.getCacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });
    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
    // 图片框架最终会走到 GlideImageLoader 的 load 方法中进行处理
    // 如果你想自己自定义图片框架或自己实现 Glide BaseImageLoader 你需要实现 GlideAppliesOptions 接口
    BaseImageLoader baseImageLoader = component.getImageLoader().getImageLoader();
    if (baseImageLoader instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) baseImageLoader).applyGlideOptions(context, builder);
    }
}
Also used : BaseImageLoader(com.tool.common.widget.imageloader.BaseImageLoader) AppComponent(com.tool.common.di.component.AppComponent) MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) DiskCache(com.bumptech.glide.load.engine.cache.DiskCache) File(java.io.File)

Example 3 with AppComponent

use of com.tool.common.di.component.AppComponent in project MVPFrames by RockyQu.

the class ActivityDelegateImpl method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    AppComponent component = AppUtils.obtainAppComponentFromContext(activity);
    // 在Base基类实现些方法,为了能够方便的获取到AppComponent
    if (iActivity != null) {
        iActivity.setComponent(component);
    } else if (iSimpleActivity != null) {
        iSimpleActivity.setComponent(component);
    }
    // 依赖注入
    if (iActivity != null) {
        iActivity.setupActivityComponent(component);
    } else if (iSimpleActivity != null) {
        this.iPresenter = iSimpleActivity.obtainPresenter();
        iSimpleActivity.setPresenter(iPresenter);
    }
    try {
        int layoutResID;
        if (iActivity != null) {
            layoutResID = iActivity.getLayoutId();
        } else if (iSimpleActivity != null) {
            layoutResID = iSimpleActivity.getLayoutId();
        } else {
            layoutResID = 0;
        }
        if (layoutResID != 0) {
            activity.setContentView(layoutResID);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    // 绑定ButterKnife
    unbinder = ButterKnife.bind(activity);
    // 初始化方法
    if (iActivity != null) {
        iActivity.create(savedInstanceState);
    } else if (iSimpleActivity != null) {
        iSimpleActivity.create(savedInstanceState);
    }
}
Also used : AppComponent(com.tool.common.di.component.AppComponent)

Aggregations

AppComponent (com.tool.common.di.component.AppComponent)3 LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)1 DiskCache (com.bumptech.glide.load.engine.cache.DiskCache)1 LruResourceCache (com.bumptech.glide.load.engine.cache.LruResourceCache)1 MemorySizeCalculator (com.bumptech.glide.load.engine.cache.MemorySizeCalculator)1 OkHttpUrlLoader (com.tool.common.http.OkHttpUrlLoader)1 BaseImageLoader (com.tool.common.widget.imageloader.BaseImageLoader)1 File (java.io.File)1