android:optimize code

This commit is contained in:
pengfei.zhou 2021-10-25 14:13:05 +08:00 committed by osborn
parent 6402522946
commit 4bd4f42f52
8 changed files with 15 additions and 25 deletions

View File

@ -37,6 +37,6 @@ public class DoricAndroidLoader implements DoricResourceLoader {
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricAndroidResource(this.defType, identifier, doricContext);
return new DoricAndroidResource(this.defType, doricContext, identifier);
}
}

View File

@ -27,12 +27,10 @@ import pub.doric.async.AsyncResult;
*/
public class DoricAndroidResource extends DoricResource {
private final String defType;
private final String identifier;
public DoricAndroidResource(String defType, String identifier, DoricContext doricContext) {
super(doricContext);
public DoricAndroidResource(String defType, DoricContext doricContext, String identifier) {
super(doricContext, identifier);
this.defType = defType;
this.identifier = identifier;
}
@Override

View File

@ -30,6 +30,6 @@ public class DoricAssetsLoader implements DoricResourceLoader {
@Override
public DoricResource load(DoricContext doricContext, String identifier) {
return new DoricAssetsResource(identifier, doricContext);
return new DoricAssetsResource(doricContext, identifier);
}
}

View File

@ -27,18 +27,15 @@ import pub.doric.async.AsyncResult;
* @CreateDate: 2021/10/20
*/
public class DoricAssetsResource extends DoricResource {
private final String path;
public DoricAssetsResource(String path, DoricContext doricContext) {
super(doricContext);
this.path = path;
public DoricAssetsResource(DoricContext doricContext, String identifier) {
super(doricContext, identifier);
}
@Override
public AsyncResult<InputStream> asInputStream() {
AsyncResult<InputStream> result = new AsyncResult<>();
try {
InputStream inputStream = doricContext.getContext().getAssets().open(path);
InputStream inputStream = doricContext.getContext().getAssets().open(identifier);
result.setResult(inputStream);
} catch (IOException e) {
result.setError(e);

View File

@ -32,11 +32,9 @@ import pub.doric.utils.DoricUtils;
* @CreateDate: 2021/10/22
*/
class DoricBase64Resource extends DoricResource {
private final String identifier;
public DoricBase64Resource(DoricContext doricContext, String identifier) {
super(doricContext);
this.identifier = identifier;
super(doricContext, identifier);
}
@Override

View File

@ -28,18 +28,16 @@ import pub.doric.async.AsyncResult;
* @CreateDate: 2021/10/20
*/
public class DoricLocalResource extends DoricResource {
private final String filePath;
public DoricLocalResource(DoricContext doricContext, String identifier) {
super(doricContext);
this.filePath = identifier;
super(doricContext, identifier);
}
@Override
public AsyncResult<InputStream> asInputStream() {
AsyncResult<InputStream> result = new AsyncResult<>();
try {
result.setResult(new FileInputStream(filePath));
result.setResult(new FileInputStream(identifier));
} catch (FileNotFoundException e) {
result.setError(e);
}

View File

@ -37,17 +37,14 @@ import pub.doric.async.AsyncResult;
*/
public class DoricRemoteResource extends DoricResource {
private final String url;
public DoricRemoteResource(DoricContext doricContext, String identifier) {
super(doricContext);
this.url = identifier;
super(doricContext, identifier);
}
@Override
public AsyncResult<InputStream> asInputStream() {
final AsyncResult<InputStream> result = new AsyncResult<>();
Glide.with(doricContext.getContext()).download(url)
Glide.with(doricContext.getContext()).download(identifier)
.listener(new RequestListener<File>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {

View File

@ -28,9 +28,11 @@ import pub.doric.async.AsyncResult;
*/
public abstract class DoricResource {
protected final DoricContext doricContext;
protected final String identifier;
public DoricResource(DoricContext doricContext) {
public DoricResource(DoricContext doricContext, String identifier) {
this.doricContext = doricContext;
this.identifier = identifier;
}
public abstract AsyncResult<InputStream> asInputStream();