Java Code Examples for com.jess.arms.utils.ArmsUtils#obtainAppComponentFromContext()

The following examples show how to use com.jess.arms.utils.ArmsUtils#obtainAppComponentFromContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlideConfiguration.java    From MVPArms with Apache License 2.0 6 votes vote down vote up
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
    final AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(() -> {
        // Careful: the external cache directory doesn't enforce permissions
        return DiskLruCacheWrapper.create(DataHelper.makeDirs(new File(appComponent.cacheFile(), "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));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}
 
Example 2
Source File: SaleHolder.java    From Hands-Chopping with Apache License 2.0 5 votes vote down vote up
public SaleHolder(View itemView) {
    super(itemView);
    mAppComponent= ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader=mAppComponent.imageLoader();
    imageView=(ImageView)itemView.findViewById(R.id.img);
    titleTv=(TextView)itemView.findViewById(R.id.name);
    nowpriceTv=(TextView)itemView.findViewById(R.id.nowprice);
    oldpriceTv=(TextView)itemView.findViewById(R.id.oldprice);
    offTv=(TextView)itemView.findViewById(R.id.off);

}
 
Example 3
Source File: SearchHolder.java    From Hands-Chopping with Apache License 2.0 5 votes vote down vote up
public SearchHolder(View itemView) {
    super(itemView);
    mAppComponent= ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader=mAppComponent.imageLoader();
    imageView=(ImageView)itemView.findViewById(R.id.img);
    titleTv=(TextView)itemView.findViewById(R.id.name);
    nowpriceTv=(TextView)itemView.findViewById(R.id.nowprice);
}
 
Example 4
Source File: GlideConfiguration.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "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));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}
 
Example 5
Source File: GlideConfiguration.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
    //Glide 默认使用 HttpURLConnection 做网络请求,在这切换成 Okhttp 请求
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.okHttpClient()));

    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).registerComponents(context, glide, registry);
    }
}
 
Example 6
Source File: GoldHomeItemHolder.java    From lifecycle-component with Apache License 2.0 4 votes vote down vote up
public GoldHomeItemHolder(View itemView) {
    super(itemView);
    //可以在任何可以拿到 Context 的地方,拿到 AppComponent,从而得到用 Dagger 管理的单例对象
    mAppComponent = ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader = mAppComponent.imageLoader();
}
 
Example 7
Source File: GankHomeItemHolder.java    From lifecycle-component with Apache License 2.0 4 votes vote down vote up
public GankHomeItemHolder(View itemView) {
    super(itemView);
    //可以在任何可以拿到 Context 的地方,拿到 AppComponent,从而得到用 Dagger 管理的单例对象
    mAppComponent = ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader = mAppComponent.imageLoader();
}
 
Example 8
Source File: ZhihuHomeItemHolder.java    From lifecycle-component with Apache License 2.0 4 votes vote down vote up
public ZhihuHomeItemHolder(View itemView) {
    super(itemView);
    //可以在任何可以拿到 Context 的地方,拿到 AppComponent,从而得到用 Dagger 管理的单例对象
    mAppComponent = ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader = mAppComponent.imageLoader();
}
 
Example 9
Source File: GlideConfiguration.java    From Aurora with Apache License 2.0 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    //Glide 默认使用 HttpURLConnection 做网络请求,在这切换成 Okhttp 请求
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.okHttpClient()));
}
 
Example 10
Source File: RecommendMultiItemAdapter.java    From LQRBiliBlili with MIT License 4 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, RecommendMultiItem item) {
    if (mAppComponent == null) {
        mAppComponent = ArmsUtils.obtainAppComponentFromContext(mContext);
    }
    IndexData.DataBean itemBean = item.getIndexDataBean();
    switch (item.getItemType()) {
        case RecommendMultiItem.BANNER:
            BGABanner banner = helper.getView(R.id.banner);
            List<IndexData.DataBean.BannerItemBean> banners = itemBean.getBanner_item();
            List<String> images = new ArrayList<>();
            if (banners != null && banners.size() > 0) {
                for (int i = 0; i < banners.size(); i++) {
                    IndexData.DataBean.BannerItemBean bannerItem = banners.get(i);
                    images.add(bannerItem.getImage());
                }
            }
            banner.setAdapter(mBannerAdapter);
            banner.setData(images, images);
            break;
        case RecommendMultiItem.STREAMER:
            mAppComponent.imageLoader().loadImage(mContext, ImageConfigImpl.builder().imageView(helper.getView(R.id.iv_streamer)).url(itemBean.getCover()).build());
            helper.setText(R.id.tv_item_title, itemBean.getTitle())
                    .setText(R.id.tv_badge, TextUtils.isEmpty(itemBean.getBadge()) ? ("topic".equals(itemBean.getGotoX()) ? "话题" : "") : itemBean.getBadge())
                    .setText(R.id.tv_desc, itemBean.getDesc());
            break;
        case RecommendMultiItem.ITEM_AV:
            setItemPaddingAndImage(helper, item, itemBean);
            helper.setText(R.id.tv_play, TextHandleUtil.handleCount2TenThousand(itemBean.getPlay()))
                    .setText(R.id.tv_danmaku, TextHandleUtil.handleCount2TenThousand(itemBean.getDanmaku()))
                    .setText(R.id.tv_duration, TextHandleUtil.handleDurationSecond(itemBean.getDuration()))
                    .setText(R.id.tv_title, itemBean.getTitle())
                    .setText(R.id.tv_tname_tag_name, itemBean.getTname() + "‧" + (itemBean.getTag() == null ? "" : itemBean.getTag().getTag_name()));
            break;
        case RecommendMultiItem.ITEM_AV_RCMD_REASON:
            setItemPaddingAndImage(helper, item, itemBean);
            helper.setText(R.id.tv_play, TextHandleUtil.handleCount2TenThousand(itemBean.getPlay()))
                    .setText(R.id.tv_danmaku, TextHandleUtil.handleCount2TenThousand(itemBean.getDanmaku()))
                    .setText(R.id.tv_duration, TextHandleUtil.handleDurationSecond(itemBean.getDuration()))
                    .setText(R.id.tv_title, itemBean.getTitle())
                    .setText(R.id.tv_rcmd_reason, itemBean.getRcmd_reason().getContent());
            break;
        case RecommendMultiItem.ITEM_BANGUMI:
            setItemPaddingAndImage(helper, item, itemBean);
            helper.setText(R.id.tv_play, TextHandleUtil.handleCount2TenThousand(itemBean.getPlay()))
                    .setText(R.id.tv_favorite, itemBean.getFavorite() + "")
                    .setText(R.id.tv_title, itemBean.getTitle())
                    .setText(R.id.tv_last_index, mContext.getResources().getString(R.string.recommend_home_update_to_last_index, itemBean.getLast_index()))
                    .setText(R.id.tv_badge, itemBean.getBadge());
            break;
        case RecommendMultiItem.ITEM_LOGIN:
            break;
        case RecommendMultiItem.ITEM_AD_WEB_S:
            setItemPaddingAndImage(helper, item, itemBean);
            helper.setText(R.id.tv_title, itemBean.getTitle())
                    .setText(R.id.tv_desc, itemBean.getDesc());
            break;
        case RecommendMultiItem.ITEM_ARTICLE_S:
            setItemPaddingAndImage(helper, item, itemBean);
            helper.setText(R.id.tv_play, TextHandleUtil.handleCount2TenThousand(itemBean.getPlay()))
                    .setText(R.id.tv_favorite, itemBean.getFavorite() + "")
                    .setText(R.id.tv_title, itemBean.getTitle())
                    .setText(R.id.tv_desc, itemBean.getDesc());
            break;
        case RecommendMultiItem.PRE_HERE_CLICK_TO_REFRESH:
            break;
    }
}
 
Example 11
Source File: LiveMultiItemAdapter.java    From LQRBiliBlili with MIT License 4 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, LiveMultiItem item) {
    if (mAppComponent == null) {
        mAppComponent = ArmsUtils.obtainAppComponentFromContext(mContext);
    }
    switch (item.getItemType()) {
        case LiveMultiItem.TITLE:
            mAppComponent
                    .imageLoader()
                    .loadImage(mContext, ImageConfigImpl
                            .builder()
                            .imageView(helper.getView(R.id.iv_title_icon_src))
                            .url(item.getTitleIconSrc())
                            .build());
            helper.setText(R.id.tv_title_name, item.getTitleName())
                    .setText(R.id.tv_title_count, item.getTitleCount() + "");
            break;
        case LiveMultiItem.ITEM:
            mAppComponent
                    .imageLoader()
                    .loadImage(mContext, ImageConfigImpl
                            .builder()
                            .imageView(helper.getView(R.id.iv_item_cover_src))
                            .url(item.getItemCoverSrc())
                            .build());
            int leftPadding = item.isOdd() ? ArmsUtils.dip2px(mContext, ConstantUtil.MAIN_HOME_ITEM_PADDING) : 0;
            int rightPadding = item.isOdd() ? 0 : ArmsUtils.dip2px(mContext, ConstantUtil.MAIN_HOME_ITEM_PADDING);
            helper.getView(R.id.fl_item).setPadding(leftPadding, 0, rightPadding, 0);
            helper.setText(R.id.tv_item_owner_name, item.getItemOwnerName())
                    .setText(R.id.tv_item_title, item.getItemTitle())
                    .setText(R.id.tv_item_sub_title, item.getItemSubTitle())
                    .setText(R.id.tv_item_online, TextHandleUtil.handleCount2TenThousand(item.getItemOnline()));
            break;
        case LiveMultiItem.BANNER:
            mAppComponent
                    .imageLoader()
                    .loadImage(mContext, ImageConfigImpl
                            .builder()
                            .imageView(helper.getView(R.id.iv_banner_cover_src))
                            .url(item.getBannerCoverSrc())
                            .build());
            helper.setText(R.id.tv_banner_title, item.getBannerTitle());
            break;
        case LiveMultiItem.BOTTOM:
            break;
    }
}
 
Example 12
Source File: UserItemHolder.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
public UserItemHolder(View itemView) {
    super(itemView);
    //可以在任何可以拿到 Context 的地方, 拿到 AppComponent, 从而得到用 Dagger 管理的单例对象
    mAppComponent = ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader = mAppComponent.imageLoader();
}