Skip to content

Commit

Permalink
url new function with firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
gonojuarez committed Oct 27, 2022
1 parent d4b0003 commit e6ad2c2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
9 changes: 7 additions & 2 deletions app/pictogramslibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ android {

dependencies {

implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'com.github.bumptech.glide:glide:4.13.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:30.5.0')

// Add the dependency for the Cloud Storage library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-storage'
}

project.afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.stonefacesoft.pictogramslibrary;

import com.google.firebase.storage.FirebaseStorage;

public class CloudStorageManager {
private FirebaseStorage storage;
private static CloudStorageManager _CloudStorageManager;
public synchronized static CloudStorageManager getInstance(){
if(_CloudStorageManager == null)
_CloudStorageManager = new CloudStorageManager();
return _CloudStorageManager;
}

public void setStorage(FirebaseStorage storage){
this.storage = storage;
}

public FirebaseStorage getStorage() {
return storage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.signature.ObjectKey;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.stonefacesoft.pictogramslibrary.CloudStorageManager;
import com.stonefacesoft.pictogramslibrary.Interfaces.GlideModelTypes;
import com.stonefacesoft.pictogramslibrary.R;

Expand Down Expand Up @@ -142,8 +146,31 @@ public Object loadDrawable(@Nullable String string, ImageView imageView) {
@NonNull
@Override
public Object loadDrawable(@Nullable Uri uri, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(uri).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();

if(isValidContext(mContext)){
if(uri.toString().contains("firebasestorage")){
String aux = uri.toString();
if(aux.contains("?alt")){
aux = aux.substring(0,aux.lastIndexOf("?alt"));
}
if(CloudStorageManager.getInstance().getStorage()!=null){
StorageReference mRef = CloudStorageManager.getInstance().getStorage().getReferenceFromUrl(aux);
mRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uriResult) {
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(uriResult).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
}
});
}else{
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(uri).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
}


}
else{
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(uri).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
}
}
return this;
}

Expand All @@ -165,9 +192,30 @@ public Object loadDrawable(@Nullable Integer resourceId, ImageView imageView) {

@Override
public Object loadDrawable(@Nullable URL url, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(url).signature(new ObjectKey(url)).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
return this;
if(isValidContext(mContext)){
if(url.toString().contains("firebasestorage")){
String aux = url.toString();
if(aux.contains("?alt")){
aux = aux.substring(0,aux.lastIndexOf("?alt"));
}
if(CloudStorageManager.getInstance().getStorage()!=null){
StorageReference mRef = CloudStorageManager.getInstance().getStorage().getReferenceFromUrl(aux);
mRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uriResult) {
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(uriResult).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
}
});
}else{
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(url).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
}


}
else{
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(url).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
}
} return this;
}

@NonNull
Expand Down

0 comments on commit e6ad2c2

Please sign in to comment.