Skip to content

Commit

Permalink
reduce IDE warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocbcotta committed Aug 25, 2019
1 parent cc946c9 commit df54899
Showing 1 changed file with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.app.Activity;
import android.util.Log;
import android.util.SparseArray;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.android.gms.tasks.Tasks;
Expand Down Expand Up @@ -162,7 +164,7 @@ private class DefaultCompletionListener implements DatabaseReference.CompletionL
}

@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
public void onComplete(@Nullable DatabaseError error, @NonNull DatabaseReference ref) {
if (error != null) {
result.error(String.valueOf(error.getCode()), error.getMessage(), error.getDetails());
} else {
Expand All @@ -180,7 +182,8 @@ private class EventObserver implements ChildEventListener, ValueEventListener {
this.handle = handle;
}

private void sendEvent(String eventType, DataSnapshot snapshot, String previousChildName) {
private void sendEvent(
String eventType, @NonNull DataSnapshot snapshot, String previousChildName) {
if (eventType.equals(requestedEventType)) {
Map<String, Object> arguments = new HashMap<>();
Map<String, Object> snapshotMap = new HashMap<>();
Expand All @@ -194,45 +197,45 @@ private void sendEvent(String eventType, DataSnapshot snapshot, String previousC
}

@Override
public void onCancelled(DatabaseError error) {
public void onCancelled(@NonNull DatabaseError error) {
Map<String, Object> arguments = new HashMap<>();
arguments.put("handle", handle);
arguments.put("error", asMap(error));
channel.invokeMethod("Error", arguments);
}

@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildName) {
public void onChildAdded(@NonNull DataSnapshot snapshot, String previousChildName) {
sendEvent(EVENT_TYPE_CHILD_ADDED, snapshot, previousChildName);
}

@Override
public void onChildRemoved(DataSnapshot snapshot) {
public void onChildRemoved(@NonNull DataSnapshot snapshot) {
sendEvent(EVENT_TYPE_CHILD_REMOVED, snapshot, null);
}

@Override
public void onChildChanged(DataSnapshot snapshot, String previousChildName) {
public void onChildChanged(@NonNull DataSnapshot snapshot, String previousChildName) {
sendEvent(EVENT_TYPE_CHILD_CHANGED, snapshot, previousChildName);
}

@Override
public void onChildMoved(DataSnapshot snapshot, String previousChildName) {
public void onChildMoved(@NonNull DataSnapshot snapshot, String previousChildName) {
sendEvent(EVENT_TYPE_CHILD_MOVED, snapshot, previousChildName);
}

@Override
public void onDataChange(DataSnapshot snapshot) {
public void onDataChange(@NonNull DataSnapshot snapshot) {
sendEvent(EVENT_TYPE_VALUE, snapshot, null);
}
}

@Override
public void onMethodCall(final MethodCall call, final Result result) {
public void onMethodCall(final MethodCall call, @NonNull final Result result) {
final Map<String, Object> arguments = call.arguments();
FirebaseDatabase database;
String appName = (String) arguments.get("app");
String databaseURL = (String) arguments.get("databaseURL");
String appName = call.argument("app");
String databaseURL = call.argument("databaseURL");
if (appName != null && databaseURL != null) {
database = FirebaseDatabase.getInstance(FirebaseApp.getInstance(appName), databaseURL);
} else if (appName != null) {
Expand Down Expand Up @@ -266,7 +269,7 @@ public void onMethodCall(final MethodCall call, final Result result) {

case "FirebaseDatabase#setPersistenceEnabled":
{
Boolean isEnabled = (Boolean) arguments.get("enabled");
Boolean isEnabled = call.argument("enabled");
try {
database.setPersistenceEnabled(isEnabled);
result.success(true);
Expand All @@ -279,7 +282,7 @@ public void onMethodCall(final MethodCall call, final Result result) {

case "FirebaseDatabase#setPersistenceCacheSizeBytes":
{
long cacheSize = (Integer) arguments.get("cacheSize");
Long cacheSize = call.argument("cacheSize");
try {
database.setPersistenceCacheSizeBytes(cacheSize);
result.success(true);
Expand All @@ -292,8 +295,8 @@ public void onMethodCall(final MethodCall call, final Result result) {

case "DatabaseReference#set":
{
Object value = arguments.get("value");
Object priority = arguments.get("priority");
Object value = call.argument("value");
Object priority = call.argument("priority");
DatabaseReference reference = getReference(database, arguments);
if (priority != null) {
reference.setValue(value, priority, new DefaultCompletionListener(result));
Expand All @@ -305,16 +308,15 @@ public void onMethodCall(final MethodCall call, final Result result) {

case "DatabaseReference#update":
{
@SuppressWarnings("unchecked")
Map<String, Object> value = (Map<String, Object>) arguments.get("value");
Map<String, Object> value = call.argument("value");
DatabaseReference reference = getReference(database, arguments);
reference.updateChildren(value, new DefaultCompletionListener(result));
break;
}

case "DatabaseReference#setPriority":
{
Object priority = arguments.get("priority");
Object priority = call.argument("priority");
DatabaseReference reference = getReference(database, arguments);
reference.setPriority(priority, new DefaultCompletionListener(result));
break;
Expand All @@ -327,8 +329,9 @@ public void onMethodCall(final MethodCall call, final Result result) {
// Initiate native transaction.
reference.runTransaction(
new Transaction.Handler() {
@NonNull
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
// Tasks are used to allow native execution of doTransaction to wait while Snapshot is
// processed by logic on the Dart side.
final TaskCompletionSource<Map<String, Object>> updateMutableDataTCS =
Expand All @@ -337,7 +340,7 @@ public Transaction.Result doTransaction(MutableData mutableData) {
updateMutableDataTCS.getTask();

final Map<String, Object> doTransactionMap = new HashMap<>();
doTransactionMap.put("transactionKey", arguments.get("transactionKey"));
doTransactionMap.put("transactionKey", call.argument("transactionKey"));

final Map<String, Object> snapshotMap = new HashMap<>();
snapshotMap.put("key", mutableData.getKey());
Expand Down Expand Up @@ -405,7 +408,7 @@ public void notImplemented() {
public void onComplete(
DatabaseError databaseError, boolean committed, DataSnapshot dataSnapshot) {
final Map<String, Object> completionMap = new HashMap<>();
completionMap.put("transactionKey", arguments.get("transactionKey"));
completionMap.put("transactionKey", call.argument("transactionKey"));
if (databaseError != null) {
completionMap.put("error", asMap(databaseError));
}
Expand All @@ -431,8 +434,8 @@ public void run() {

case "OnDisconnect#set":
{
Object value = arguments.get("value");
Object priority = arguments.get("priority");
Object value = call.argument("value");
Object priority = call.argument("priority");
DatabaseReference reference = getReference(database, arguments);
if (priority != null) {
if (priority instanceof String) {
Expand All @@ -456,8 +459,7 @@ public void run() {

case "OnDisconnect#update":
{
@SuppressWarnings("unchecked")
Map<String, Object> value = (Map<String, Object>) arguments.get("value");
Map<String, Object> value = call.argument("value");
DatabaseReference reference = getReference(database, arguments);
reference.onDisconnect().updateChildren(value, new DefaultCompletionListener(result));
break;
Expand All @@ -472,19 +474,19 @@ public void run() {

case "Query#keepSynced":
{
boolean value = (Boolean) arguments.get("value");
Boolean value = call.argument("value");
getQuery(database, arguments).keepSynced(value);
result.success(null);
break;
}

case "Query#observe":
{
String eventType = (String) arguments.get("eventType");
String eventType = call.argument("eventType");
int handle = nextHandle++;
EventObserver observer = new EventObserver(eventType, handle);
observers.put(handle, observer);
if (eventType.equals(EVENT_TYPE_VALUE)) {
if (EVENT_TYPE_VALUE.equals(eventType)) {
getQuery(database, arguments).addValueEventListener(observer);
} else {
getQuery(database, arguments).addChildEventListener(observer);
Expand All @@ -496,7 +498,7 @@ public void run() {
case "Query#removeObserver":
{
Query query = getQuery(database, arguments);
int handle = (Integer) arguments.get("handle");
Integer handle = call.argument("handle");
EventObserver observer = observers.get(handle);
if (observer != null) {
if (observer.requestedEventType.equals(EVENT_TYPE_VALUE)) {
Expand Down

0 comments on commit df54899

Please sign in to comment.