use of com.google.android.gms.tasks.OnFailureListener in project RSAndroidApp by RailwayStations.
the class AuthActivity method fetchConfig.
// Fetch the config to determine the allowed length of messages.
public void fetchConfig() {
// 1 hour in seconds
long cacheExpiration = 3600;
// server. This should not be used in release builds.
if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
cacheExpiration = 0;
}
mFirebaseRemoteConfig.fetch(cacheExpiration).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// Make the fetched config available via FirebaseRemoteConfig get<type> calls.
mFirebaseRemoteConfig.activateFetched();
applyRetrievedLengthLimit();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// There has been an error fetching the config
Log.w(TAG, "Error fetching config: " + e.getMessage());
applyRetrievedLengthLimit();
}
});
}
use of com.google.android.gms.tasks.OnFailureListener in project Tapad by berict.
the class PresetStoreAdapter method onFirebasePresetUpdated.
private void onFirebasePresetUpdated(final String presetName, final Runnable onUpdated) {
StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets/" + presetName).child("preset.zip");
metadataReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
Log.d(TAG, "Successful getting metadata");
if (storageMetadata.getUpdatedTimeMillis() > new File(PROJECT_LOCATION_PRESETS + "/" + presetName + "/about/json.txt").lastModified()) {
// firebase preset is updated since last download
// get the new updated preset
Log.d(TAG, "Preset updated");
onUpdated.run();
} else {
Log.d(TAG, "Preset not updated");
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "Failed to get preset metadata");
}
});
}
use of com.google.android.gms.tasks.OnFailureListener in project Tapad by berict.
the class FirebaseHelper method getStorageMetadata.
public StorageMetadata getStorageMetadata(StorageReference storageReference, Activity activity) {
FirebaseApp.initializeApp(activity);
final StorageMetadata[] mStorageMetadata = { null };
storageReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
Log.d(TAG, "Successful getting metadata");
mStorageMetadata[0] = storageMetadata;
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "Failed to get metadata");
}
});
return mStorageMetadata[0];
}
use of com.google.android.gms.tasks.OnFailureListener in project Tapad by berict.
the class FirebaseHelper method saveFirebaseMetadata.
public FirebaseMetadata saveFirebaseMetadata(StorageReference storageReference, final String fileLocation, 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);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Failed to download");
}
});
} else {
Log.e(TAG, "Not connected to the internet");
}
}
return getFirebaseMetadata(activity);
}
use of com.google.android.gms.tasks.OnFailureListener in project Tapad by berict.
the class PresetStoreActivity method downloadMetadata.
private void downloadMetadata() {
// loading start
setLoadingFinished(false);
Log.d(TAG, "downloadMetaData");
boolean hasPermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (!hasPermission) {
ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_STORAGE);
}
// Make sdcard/Tapad folder
File folder = new File(tapadFolderPath);
if (folder.mkdirs()) {
Log.i(TAG, "folder successfully created");
} else {
// folder exists
Log.e(TAG, "folder already exists");
}
// Make sdcard/Tapad/presets folder
File presets = new File(tapadFolderPath + "/presets");
if (presets.mkdirs()) {
Log.i(TAG, "folder successfully created");
} else {
// folder exists
Log.e(TAG, "folder already exists");
}
final File metadata = new File(tapadFolderPath + "/presets/metadata.txt");
StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets").child("metadata.txt");
metadataReference.getFile(metadata).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Successful download at " + metadata.toString());
setAdapter();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Failed to download");
}
});
}
Aggregations