use of com.google.android.gms.tasks.OnSuccessListener in project Tapad by berict.
the class PresetStoreActivity method isFirebaseMetadataUpdated.
private boolean isFirebaseMetadataUpdated(Context context) {
isFMUpdated = false;
if (isConnected(context)) {
Log.d(TAG, "Connected to the internet");
StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets").child("metadata.txt");
metadataReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
Log.d(TAG, "Successful getting metadata");
if (storageMetadata.getUpdatedTimeMillis() > new File(metadataLocation).lastModified()) {
// firebase metadata is updated since last download
// get the new updated metadata
Log.d(TAG, "File updated");
isFMUpdated = true;
} else {
Log.d(TAG, "File not updated");
isFMUpdated = false;
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "Failed to get metadata");
isFMUpdated = false;
}
});
return isFMUpdated;
} else {
Log.d(TAG, "Disconnected from the internet");
return isFMUpdated;
}
}
use of com.google.android.gms.tasks.OnSuccessListener in project Tapad by berict.
the class FirebaseHelper method saveFromFirebase.
public void saveFromFirebase(StorageReference storageReference, final String fileLocation, final Runnable onSuccess, final Runnable onFailure, Activity activity) {
// permission check
boolean hasPermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (!hasPermission) {
// no permission
Log.e(TAG, "No permission acquired");
ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_STORAGE);
} else {
if (isConnected(activity)) {
File file = new File(fileLocation);
storageReference.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Successful download at " + fileLocation);
onSuccess.run();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Failed to download");
onFailure.run();
}
});
} else {
Log.e(TAG, "Not connected to the internet");
}
}
}
use of com.google.android.gms.tasks.OnSuccessListener in project OnlineCanteen by josephgunawan97.
the class EditProductActivity method uploadImage.
private void uploadImage() {
Log.d(TAG, "Uploading...");
final StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("product/" + System.currentTimeMillis() + ".jpg");
if (imageUri != null) {
profileImageRef.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
@SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();
profPicUrl = downloadUrl.toString();
submitData();
Log.d(TAG, "Success in uploading");
// backToScreen();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), "Image failed to upload", Toast.LENGTH_LONG).show();
// backToScreen();
}
});
} else
submitDatawithoutImage();
}
use of com.google.android.gms.tasks.OnSuccessListener in project OnlineCanteen by josephgunawan97.
the class RequestTopUpActivity method uploadImage.
// To upload image
private void uploadImage() {
final Map topUp = new HashMap();
database = FirebaseDatabase.getInstance().getReference("topuprequest");
final StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("topuprequest/" + System.currentTimeMillis() + ".jpg");
if (imageUri != null) {
profileImageRef.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
@SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();
String transferproofUrl = downloadUrl.toString();
TopUp topUp = new TopUp(transferName.getText().toString(), userID, transferproofUrl.toString(), bankName.getText().toString(), Integer.parseInt(amount.getText().toString()));
database.push().setValue(topUp);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), "Image failed to upload", Toast.LENGTH_LONG).show();
}
});
}
}
use of com.google.android.gms.tasks.OnSuccessListener in project BloodHub by kazijehangir.
the class RequestListDataAdapter method onBindViewHolder.
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
BloodRequest request = requests.get(position);
String key = keys.get(position);
holder.cv.setTag(key);
holder.mName.setText(request.name);
holder.mNeeds.setText(request.quantity + " bags of " + request.blood_group);
holder.mLocation.setText(request.location);
String date = DateFormat.getDateInstance().format(new Date(request.date));
holder.mWhen.setText(date);
if (date.equals(DateFormat.getDateInstance().format(new Date()))) {
holder.mWhen.setText("URGENT");
holder.mWhen.setTextColor(0xFFFF0000);
}
holder.mDiagnosis.setText(request.diagnosis);
if (request.transport) {
holder.mTransport.setText("Available");
holder.mTransportImage.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_car));
} else {
holder.mTransport.setText("Not Available");
holder.mTransportImage.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_car));
}
try {
final File localFile = File.createTempFile("images", "jpg");
FirebaseStorage.getInstance().getReference().child("bloodrequests").child(key).getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// Successfully downloaded data to local file
holder.mImage.setImageDrawable(Drawable.createFromPath(localFile.getPath()));
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
holder.mImage.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.girl));
// Toast.makeText(mContext,"Error loading image: " + exception.toString(),
// Toast.LENGTH_LONG).show();
}
});
} catch (Exception e) {
// IOException: error making temp image
// Toast.makeText(mContext, e.toString(), Toast.LENGTH_LONG);
}
}
Aggregations