Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glide using custom ModelLoader & DataFetcher .. loadData not called #166

Closed
x2hokim opened this issue Oct 2, 2014 · 1 comment
Closed
Labels

Comments

@x2hokim
Copy link

x2hokim commented Oct 2, 2014

Hello~

I wan to to download image file with custom ModelLoader with AttachFileFetcher that downlaod image files & save ..
but..
AttachFileFetcher.loadData not called ... why?..


            Glide.with(_context)
            .using(new ChatAttachFileInfoModelLoader(_context, _roomInfo.getRoomNum(),  pbLoading))
                .load(item)
            .into(ivImage); 

public class ChatAttachFileInfoModelLoader implements StreamModelLoader {

/**
 * The default factory for {@link com.bumptech.glide.samples.flickr.FlickrModelLoader}s.
 *
public static class Factory implements ModelLoaderFactory<FileItem, InputStream> {
    private final ModelCache<FileItem, GlideUrl> modelCache = new ModelCache<FileItem, GlideUrl>(500);

    @Override
    public ModelLoader<FileItem, InputStream> build(Context context, GenericLoaderFactory factories) {
        return new FileItemThumbModelLoader(context, modelCache);
    }

    @Override
    public void teardown() {
    }
}*/

private Context _context;
private String _roomNum = null;
private ProgressBar _pbar = null;

public ChatAttachFileInfoModelLoader(Context context, String roomNum, ProgressBar pbar) 
{
    _context = context;
    _roomNum = roomNum;
    _pbar = pbar;
}

@Override
public DataFetcher<InputStream> getResourceFetcher(AttachFileInfo model, int width, int height) 
{
    return new AttachFileFetcher(_context, model, _roomNum, _pbar);
}

}

public class AttachFileFetcher implements DataFetcher {

private Context _context;
private ProgressBar _progressBar;
private AttachFileInfo _afi;
private String _roomNum;

public static final String PARAM_ATTACHFILEINFO = "aff.param.atfi";
public static final String PARAM_ROOMNUM = "aff.param.roomnum";


public AttachFileFetcher(Context context, AttachFileInfo afi, String roomNum, ProgressBar pbar) {
    _context = context;
    _afi = afi;
    _roomNum = roomNum;
    _progressBar = pbar;
}

@Override
public InputStream loadData(Priority priority) throws Exception {
    if (_progressBar!=null)
        _progressBar.setVisibility(View.VISIBLE);

           //Download file & saved code.. here

        return new FileInputStream(downloadFile);
}

@Override
public String getId() {
        String targetFileName = AttachFileInfo.getSavedFileName(_roomNum, String.valueOf(_afi.msgId),
                String.valueOf(_afi.fileNo), _afi.fileName);

        String savedFile = NMConfiguration.getInstance(_context).getNearFileTmpPath() + File.separator +targetFileName;

        return savedFile;
}

@Override
public void cleanup() {
    if (_progressBar!=null) {
        _progressBar.setVisibility(View.GONE);
        if (_progressBar.getTag()!=null && _progressBar.getTag() instanceof BaseAdapter) {
            ((BaseAdapter)_progressBar.getTag()).notifyDataSetChanged();
        }
    }
}
@Override
public void cancel() {
    // TODO: we should consider disconnecting the url connection here, but we can't do so directly because cancel is
    // often called on the main thread.
}

}

@x2hokim
Copy link
Author

x2hokim commented Oct 2, 2014

Ok~ I found error...

@OverRide
public InputStream loadData(Priority priority) throws Exception {
if (_progressBar!=null)
_progressBar.setVisibility(View.VISIBLE); <== this is error...

       //Download file & saved code.. here

    return new FileInputStream(downloadFile);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants