Search in sources :

Example 1 with ViewPreloadSizeProvider

use of com.bumptech.glide.util.ViewPreloadSizeProvider in project AmazeFileManager by TeamAmaze.

the class AppsListFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setRetainInstance(true);
    MainActivity mainActivity = (MainActivity) getActivity();
    mainActivity.getAppbar().setTitle(R.string.apps);
    mainActivity.floatingActionButton.getMenuButton().hide();
    mainActivity.getAppbar().getBottomBar().setVisibility(View.GONE);
    mainActivity.supportInvalidateOptionsMenu();
    vl = getListView();
    Sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    getSortModes();
    ListView vl = getListView();
    vl.setDivider(null);
    if (utilsProvider.getAppTheme().equals(AppTheme.DARK))
        getActivity().getWindow().getDecorView().setBackgroundColor(Utils.getColor(getContext(), R.color.holo_dark_background));
    else if (utilsProvider.getAppTheme().equals(AppTheme.BLACK))
        getActivity().getWindow().getDecorView().setBackgroundColor(Utils.getColor(getContext(), android.R.color.black));
    modelProvider = new AppsAdapterPreloadModel(app);
    ViewPreloadSizeProvider<String> sizeProvider = new ViewPreloadSizeProvider<>();
    ListPreloader<String> preloader = new ListPreloader<>(GlideApp.with(app), modelProvider, sizeProvider, GlideConstants.MAX_PRELOAD_APPSADAPTER);
    adapter = new AppsAdapter(getContext(), (ThemedActivity) getActivity(), utilsProvider, modelProvider, sizeProvider, R.layout.rowlayout, app);
    getListView().setOnScrollListener(preloader);
    setListAdapter(adapter);
    setListShown(false);
    setEmptyText(getResources().getString(R.string.no_applications));
    getLoaderManager().initLoader(ID_LOADER_APP_LIST, null, this);
    if (savedInstanceState != null) {
        index = savedInstanceState.getInt(KEY_INDEX);
        top = savedInstanceState.getInt(KEY_TOP);
    }
}
Also used : ListPreloader(com.bumptech.glide.ListPreloader) AppsAdapter(com.amaze.filemanager.adapters.AppsAdapter) ListView(android.widget.ListView) ThemedActivity(com.amaze.filemanager.activities.superclasses.ThemedActivity) MainActivity(com.amaze.filemanager.activities.MainActivity) AppsAdapterPreloadModel(com.amaze.filemanager.adapters.glide.AppsAdapterPreloadModel) ViewPreloadSizeProvider(com.bumptech.glide.util.ViewPreloadSizeProvider)

Example 2 with ViewPreloadSizeProvider

use of com.bumptech.glide.util.ViewPreloadSizeProvider in project glide by bumptech.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ImageView giphyLogoView = findViewById(R.id.giphy_logo_view);
    GlideApp.with(this).load(R.raw.large_giphy_logo).into(giphyLogoView);
    RecyclerView gifList = findViewById(R.id.gif_list);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    gifList.setLayoutManager(layoutManager);
    RequestBuilder<Drawable> gifItemRequest = GlideApp.with(this).asDrawable();
    ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider = new ViewPreloadSizeProvider<>();
    adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider);
    gifList.setAdapter(adapter);
    RecyclerViewPreloader<Api.GifResult> preloader = new RecyclerViewPreloader<>(GlideApp.with(this), adapter, preloadSizeProvider, 4);
    gifList.addOnScrollListener(preloader);
    gifList.setRecyclerListener(new RecyclerListener() {

        @Override
        public void onViewRecycled(ViewHolder holder) {
            // This is an optimization to reduce the memory usage of RecyclerView's recycled view pool
            // and good practice when using Glide with RecyclerView.
            GifViewHolder gifViewHolder = (GifViewHolder) holder;
            GlideApp.with(MainActivity.this).clear(gifViewHolder.gifView);
        }
    });
}
Also used : RecyclerViewPreloader(com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader) RecyclerListener(android.support.v7.widget.RecyclerView.RecyclerListener) Drawable(android.graphics.drawable.Drawable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewPreloadSizeProvider(com.bumptech.glide.util.ViewPreloadSizeProvider) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) ImageView(android.widget.ImageView)

Aggregations

ViewPreloadSizeProvider (com.bumptech.glide.util.ViewPreloadSizeProvider)2 Drawable (android.graphics.drawable.Drawable)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 RecyclerListener (android.support.v7.widget.RecyclerView.RecyclerListener)1 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 MainActivity (com.amaze.filemanager.activities.MainActivity)1 ThemedActivity (com.amaze.filemanager.activities.superclasses.ThemedActivity)1 AppsAdapter (com.amaze.filemanager.adapters.AppsAdapter)1 AppsAdapterPreloadModel (com.amaze.filemanager.adapters.glide.AppsAdapterPreloadModel)1 ListPreloader (com.bumptech.glide.ListPreloader)1 RecyclerViewPreloader (com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader)1