Skip to content

Commit

Permalink
Merge pull request #88 from m1ga/fix
Browse files Browse the repository at this point in the history
(fix) android: Context fix
  • Loading branch information
AndreaVitale authored May 29, 2020
2 parents 308be10 + a37b514 commit b0132c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 4.1.0
version: 5.0.1
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: av.imageview
Expand Down
16 changes: 8 additions & 8 deletions android/src/av/imageview/AvImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
Expand All @@ -31,7 +32,6 @@ public class AvImageView extends TiUIView
private static final String LCAT = "AvImageView";

private WeakReference<TiViewProxy> proxy;
private Activity context;
private ImageView imageView;
private ProgressIndicator progressBar;
private RelativeLayout layout;
Expand All @@ -40,7 +40,6 @@ public class AvImageView extends TiUIView
public AvImageView(Activity context, TiViewProxy proxy) {
super(proxy);

this.context = context;
this.proxy = new WeakReference<>(proxy);
this.layout = new RelativeLayout(context);
this.imageView = new ImageView(context);
Expand Down Expand Up @@ -87,13 +86,14 @@ public void processProperties(KrollDict properties)
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
super.propertyChanged(key, oldValue, newValue, proxy);

this.processProperty(key, this.proxy.get().getProperties());
this.processProperty(key, proxy.getProperties());
}

@Override
public void release() {
if (!this.context.isFinishing() && !this.context.isDestroyed()) {
Glide.with(this.context).clear(this.imageView);
Activity act = TiApplication.getAppCurrentActivity();
if (!act.isFinishing() && !act.isDestroyed()) {
Glide.with(act).clear(this.imageView);
}

super.release();
Expand Down Expand Up @@ -165,14 +165,14 @@ public void setImageAsURL(String uri) {
}

// Creating request builder
builder = ImageViewHelper.prepareGlideClientFor(this.context, url);
builder = ImageViewHelper.prepareGlideClientFor(TiApplication.getAppCurrentActivity(), url);
builder = builder.listener(this.requestListener);
builder = builder.apply(options);
builder = builder.load(url);
if (signature != null && !signature.equals("")) {
builder.signature(new ObjectKey(signature));
}
builder.into(new DrawableImageViewTarget(this.imageView, true));
builder.into(this.imageView);
}

public void setImageAsLocalUri(String filename) {
Expand All @@ -191,7 +191,7 @@ public void setImageAsLocalUri(String filename) {
}

// Creating request builder
builder = Glide.with(context).asDrawable();
builder = Glide.with(TiApplication.getAppCurrentActivity()).asDrawable();
builder = builder.listener(this.requestListener);
builder = builder.apply(options);
builder = builder.load(imageDrawable);
Expand Down
3 changes: 2 additions & 1 deletion android/src/av/imageview/ImageViewHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.bumptech.glide.load.model.LazyHeaders;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiDrawableReference;

Expand All @@ -35,7 +36,7 @@ public static Drawable getDrawableFromProxyProperty(String propertyName, TiViewP
return null;
}

return TiDrawableReference.fromUrl(proxy, proxy.getProperties().getString(propertyName)).getDrawable();
return TiDrawableReference.fromUrl(TiApplication.getAppCurrentActivity(), proxy.getProperties().getString(propertyName)).getDrawable();
}

public static RequestBuilder prepareGlideClientFor(Context context, GlideUrl url) {
Expand Down

0 comments on commit b0132c7

Please sign in to comment.