Skip to content

mwfire/titanium-module-image-caching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Titanium Image Caching Module

##Description This module is designed to help you handling remote images. You can either use the wrapper of Ti.UI.ImageView, or handle image caching manually with the methods provided in this module

##Please note: I am not actively maintaining Titanium plugins at the moment. Titanium has evolved a lot since my initial versions and best practices have changed a lot, to the better, I have to say. So, although these plugins should do the job, feel free to send me pull requests! I would be more than happy to see these plugins as modules :)

##Installation Just add mwfire-image-caching.js to your current projects lib folder. Create the folder as a child of Resources if it does not exist yet.

##Accessing the module To access this module, you would do the following:

var imageCaching = require('/lib/mwfire-image-caching');

Optionally you can use the minified version

var imageCaching = require('/lib/mwfire-image-caching-min');

##Reference createImageView( parameters ) [Ti.UI.ImageView]
Creates and returns an instance of Titanium.UI.ImageView, extended with image caching properties

#####Parameters

  • All parameters of Titanium.UI.ImageView
  • remoteCheck [Bool default: false] optional
    If the ImageView should check if a newer version of an already cached image is available
  • checkInterval [Int default: 600] optional
    Time in minutes to check for a new version after the cached image has been downloaded

loadImage( url, options, callback )
Loads an image either remotely or from cache, checks for newer versions if requested

#####Paramters

  • url [String] required
    The Url of the image to load
  • options [Dictionary] optional
    • remoteCheck [Bool default: false] optional
      If the ImageView should check if a newer version of an already cached image is available
    • checkInterval [Int default: 600] optional
      Time in minutes to check for a new version after the cached image has been downloaded
  • callback [Function] optional
    Returns a dictionary with
    • success [Bool]
      If the image could be loaded
    • file [Image]
      The image to display if success: true
    • error [String]
      The error message to log if success: false

deleteCache() [Bool]
Deletes all images from the cache

deleteCachedImage( url ) [Bool]
Deletes an image from the cache

#####Parameters

  • url [String] required
    The url of the image to delete

For more information refer to the docs in this repository

##Example

// Create an imageView with this module and add it to your window
var imageView = imageCaching.createImageView({
    width           : 200,
    height          : 200,
    backgroundColor : '#CCC',
    image           : 'http://www.yourdomain/yourimage.png',
    remoteCheck     : true,
    checkInterval   : 60 //minutes
});
win.add(imageView);

// You can also manually load an image with this module
imageCaching.loadImage('http://www.yourdomain/yourimage.png', {}, function(response) {
    if(response && response.success) {
        imageView.image = response.file;
    }
});
    
//Delete this image from the cache
imageCaching.deleteCachedImage('http://www.yourdomain/yourimage.png');
    
//Delete all images from cache
imageCaching.deleteCache();

##Platform With version 0.5, this has only been tested on iOS
This might also run seamlessly on Android devices,
but it is untested.

Author

© 2013 Martin Wildfeuer
mwfire web development
www.mwfire.de

License

Licensed under the Apache License, Version 2.0 (the "License")

About

JS module that handles image caching in Titanium

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published