LynxGenericResourceFetcher

LynxGenericResourceFetcher is defined inside LynxEngine and injected from outside to implement a general resource loading interface. It is used inside LynxEngine for resource loading capabilities of components such as Text;

Android

Interface Definition:

LynxGenericResourceFetcher.java
public abstract class LynxGenericResourceFetcher {
  /**
   * fetch resource with contents.
   *
   * @param request
   * @param callback contents of the requiring resource.
   */
  public abstract void fetchResource(
      LynxResourceRequest request, LynxResourceCallback<byte[]> callback);

  /**
   * fetch resource with res path.
   *
   * @param request
   * @param callback path on the disk of the requiring resource.
   */
  public abstract void fetchResourcePath(
      LynxResourceRequest request, LynxResourceCallback<String> callback);

  /**
   * fetch resource with stream.
   *
   * @param request
   * @param delegate streaming of the requiring resource.
   */
  public void fetchStream(LynxResourceRequest request, StreamDelegate delegate){};

  /**
   * cancel the request of the requiring resource.
   *
   * @param request the requiring request.
   */
  public void cancel(LynxResourceRequest request){};
}

Method Introduction:

fetchResource

LynxEngine internally calls this method to obtain the general resource content, and the return result is required to be the resource content byte[] type;

NOTE

This method must be implemented;

fetchResourcePath

LynxEngine internally calls this method to obtain the path of the common resource on the local disk, and the return result is required to be of String type;

NOTE

This method must be implemented;

fetchStream

LynxEngine internally calls this method to obtain resource content in a streaming manner;

NOTE

This method must be implemented;

Injection:

Inject when constructing a LynxView using LynxViewBuilder:

LynxViewBuilder builder = new LynxViewBuilder();
builder.setGenericResourceFetcher(new GenericTemplateResourceFetcher());

Also enable this capability in LynxViewBuilder:

LynxViewBuilder builder = new LynxViewBuilder();
builder.setGenericResourceFetcher(new GenericTemplateResourceFetcher());
builder.setEnableGenericResourceFetcher(LynxBooleanOption.TRUE);

iOS

Interface Definition:

LynxGenericResourceFetcher.h
@protocol LynxGenericResourceFetcher <NSObject>

/**
 * fetch resource with contents.
 *
 * @param request.
 * @param callback contents of the requiring resource.
 *
 * @return: A block which can cancel the image request if it is not finished. nil if cancel action
 * is not supported.
 */
@required
- (dispatch_block_t)fetchResource:(nonnull LynxResourceRequest *)request
                       onComplete:(LynxGenericResourceCompletionBlock _Nonnull)callback;

/**
 * fetch resource with res path.
 *
 * @param request
 * @param callback path on the disk of the requiring resource.
 *
 * @return: A block which can cancel the image request if it is not finished. nil if cancel action
 * is not supported.
 */
@required
- (dispatch_block_t)fetchResourcePath:(nonnull LynxResourceRequest *)request
                           onComplete:(LynxGenericResourcePathCompletionBlock _Nonnull)callback;

/**
 * fetch resource with stream.
 *
 * @param request
 * @param delegate streaming of the requiring resource.
 *
 * @return: A block which can cancel the image request if it is not finished. nil if cancel action
 * is not supported.
 */
@optional
- (dispatch_block_t)fetchStream:(nonnull LynxResourceRequest *)request
                     withStream:(nonnull id<LynxResourceStreamLoadDelegate>)delegate;

@end

Method Introduction:

fetchResource

LynxEngine internally calls this method to obtain the general resource content, and the return result is required to be the resource content byte[] type;

NOTE

This method must be implemented;

fetchResourcePath

LynxEngine internally calls this method to obtain the path of the common resource on the local disk, and the return result is required to be of String type;

NOTE

This method must be implemented;

fetchStream

LynxEngine internally calls this method to obtain resource content in a streaming manner;

NOTE

This method must be implemented;

Injection:

Inject when constructing a LynxView using LynxViewBuilder:

LynxViewBuilder *builder = [[LynxViewBuilder alloc] init];
builder.genericResourceFetcher = [[ExampleGenericResourceFetcher alloc] init];

Also enable this capability in LynxViewBuilder:

LynxViewBuilder *builder = [[LynxViewBuilder alloc] init];
builder.genericResourceFetcher = [[ExampleGenericResourceFetcher alloc] init];
builder.enableGenericResourceFetcher = LynxBooleanOptionTrue;

Compatibility

LCD tables only load in the browser

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.