Giter Club home page Giter Club logo

redpanda's Introduction

RedPanda

Image loading and caching into tableViews and collectionViews library for iOS written in Swift

Features
Depenedencies
Requirments
installation
Usage
License
TODO

Features

  • TableViews / collectionViews convience loader :
    • Request hashing with url-indexPath-tag to load images for tableViews and collectionViews
    • Ignore redundant calls for calls that are currently processing or were processed and are invalid
    • Retry requests that failed due to network error or internet connectivity error when connection goes back up
    • Timestamping requests to cope with refreshing / updating the collection and to avoid wrong callBacks execution
    • Thread safe ram and disk caching
  • Independent components that can be used seperatly :
    • Disk Caching and Ram Caching
    • Variable Ram Cache
    • Image Loader thats has access to the disk cache
    • Option to delete all disk cached images or images that were accessed after a certain date only

Depenedencies

  • ReachabilitySwift
  • RealmSwift

Requirments

  • iOs 12.0+
  • Xcod 10.1+
  • Swift 4.2+

Installation

Avaliable through CocoaPods
pod 'RedPanda'

Usage

   import ImageCollectionLoader

  • loading images into tableViews or collectionViews
    • request date is a timestamp for when this call was made so the caller can decide wether it is correct to use the
      result image (Ex: refreshing tableView or adding/removing rows changes the indexpath to render the image at)
    • tag is used incase the same indexpath have more than one image with the same url to avoid discard loading the second image (Ex: could be card and logo)
    • Requesting images from cellForRow is safe as duplicate requests will be discarded (A request is hashed by url & indexPath & tag )
    • FailedState
      • case currentlyLoading : another request with the same indexpath - tag - url was requested and is loading now
      • case invalid : the requested url was loaded before and the parsing of the image failed
      • case processing : the request is being processed
   let imageCollectionLoader = ImageCollectionLoaderBuilder().defaultImp(ramMaxItemsCount: 60)
   imageCollectionLoader.requestImage(requestDate: Date(), url: element, indexPath: indexPath, tag: "card", successHandler:         
   {
                image , index , date in
                guard let visibleCell = tableView.cellForRow(at: index) as? cell else {return}
                visibleCell.iv.image = image
            }, failedHandler: {
               failedRequest,failedImage,requestState in
                print(failedRequest)
                print(failedImage)
                print(requestState)
            })
            

  • loading images separately
     let imageLoader = ImageLoaderBuilder().concrete(ramMaxItemsCount: 50).getImageFrom(urlString: "testUrl", completion: {
            image in
        }, fail: {
            failMessage , error in 
        })
        
  • Emptying cache
  DiskCacheBuilder().concrete().deleteAll()
  DiskCacheBuilder().concrete().deleteWith(minLastAccessDate: Date(), completion: {
          success in
          
       })
     
  

License

MIT

TODO

  • Make Internet and reachability monitor a seperate component with injectable configuration including
    • max number of tries
    • retry interval
  • Injectable preprocessing for urls to make timestamping cleaning dynamic
  • Injectable directory to DiskCache and DiskCacheFileSystem
  • add tests for spamming localServer and multiple instances of ImageCollectionLoader running at once
  • expose SyncedAccessHashableCollection and improve its api

redpanda's People

Contributors

ohassan443 avatar

Stargazers

 avatar Noha Samir avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.