Skip to content

Commit 3ea184a

Browse files
committed
Add nullability annotations to all modules except for auth
Signed-off-by: Alex Saveau <[email protected]>
1 parent 2274696 commit 3ea184a

29 files changed

+167
-98
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
implementation(Config.Libs.Misc.butterKnife)
5656
annotationProcessor(Config.Libs.Misc.butterKnifeCompiler)
5757
debugImplementation(Config.Libs.Misc.leakCanary)
58+
debugImplementation(Config.Libs.Misc.leakCanaryFragments)
5859
releaseImplementation(Config.Libs.Misc.leakCanaryNoop)
5960
testImplementation(Config.Libs.Misc.leakCanaryNoop)
6061
}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
package com.firebase.uidemo;
22

3-
import android.content.Context;
43
import android.support.multidex.MultiDexApplication;
54
import android.support.v7.app.AppCompatDelegate;
65

76
import com.squareup.leakcanary.LeakCanary;
8-
import com.squareup.leakcanary.RefWatcher;
97

108
public class FirebaseUIDemo extends MultiDexApplication {
11-
private RefWatcher mRefWatcher;
12-
139
static {
1410
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
1511
}
1612

17-
public static RefWatcher getRefWatcher(Context context) {
18-
return ((FirebaseUIDemo) context.getApplicationContext()).mRefWatcher;
19-
}
20-
2113
@Override
2214
public void onCreate() {
2315
super.onCreate();
@@ -26,6 +18,6 @@ public void onCreate() {
2618
// You should not init your app in this process.
2719
return;
2820
}
29-
mRefWatcher = LeakCanary.install(this);
21+
LeakCanary.install(this);
3022
}
3123
}

app/src/main/java/com/firebase/uidemo/auth/AnonymousUpgradeActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Intent;
44
import android.os.Bundle;
55
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
67
import android.support.v7.app.AppCompatActivity;
78
import android.text.TextUtils;
89
import android.util.Log;
@@ -52,7 +53,7 @@ public class AnonymousUpgradeActivity extends AppCompatActivity {
5253
private AuthCredential mPendingCredential;
5354

5455
@Override
55-
protected void onCreate(Bundle savedInstanceState) {
56+
protected void onCreate(@Nullable Bundle savedInstanceState) {
5657
super.onCreate(savedInstanceState);
5758
setContentView(R.layout.activity_anonymous_upgrade);
5859
ButterKnife.bind(this);
@@ -127,7 +128,7 @@ public void onComplete(@NonNull Task<Void> task) {
127128
}
128129

129130
@Override
130-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
131+
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
131132
super.onActivityResult(requestCode, resultCode, data);
132133
if (requestCode == RC_SIGN_IN) {
133134
IdpResponse response = IdpResponse.fromResultIntent(data);

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public class AuthUiActivity extends AppCompatActivity {
104104
@BindView(R.id.allow_new_email_accounts) CheckBox mAllowNewEmailAccounts;
105105
@BindView(R.id.require_name) CheckBox mRequireName;
106106

107-
public static Intent createIntent(Context context) {
107+
@NonNull
108+
public static Intent createIntent(@NonNull Context context) {
108109
return new Intent(context, AuthUiActivity.class);
109110
}
110111

@@ -178,7 +179,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
178179
}
179180

180181
@OnClick(R.id.sign_in)
181-
public void signIn(View view) {
182+
public void signIn() {
182183
startActivityForResult(
183184
AuthUI.getInstance().createSignInIntentBuilder()
184185
.setTheme(getSelectedTheme())
@@ -193,7 +194,7 @@ public void signIn(View view) {
193194
}
194195

195196
@OnClick(R.id.sign_in_silent)
196-
public void silentSignIn(View view) {
197+
public void silentSignIn() {
197198
AuthUI.getInstance().silentSignIn(this, getSelectedProviders())
198199
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
199200
@Override
@@ -208,7 +209,7 @@ public void onComplete(@NonNull Task<AuthResult> task) {
208209
}
209210

210211
@Override
211-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
212+
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
212213
super.onActivityResult(requestCode, resultCode, data);
213214
if (requestCode == RC_SIGN_IN) {
214215
handleSignInResponse(resultCode, data);
@@ -225,8 +226,8 @@ protected void onResume() {
225226
}
226227
}
227228

228-
private void handleSignInResponse(int resultCode, Intent data) {
229-
final IdpResponse response = IdpResponse.fromResultIntent(data);
229+
private void handleSignInResponse(int resultCode, @Nullable Intent data) {
230+
IdpResponse response = IdpResponse.fromResultIntent(data);
230231

231232
// Successfully signed in
232233
if (resultCode == RESULT_OK) {
@@ -250,7 +251,7 @@ private void handleSignInResponse(int resultCode, Intent data) {
250251
}
251252
}
252253

253-
private void startSignedInActivity(IdpResponse response) {
254+
private void startSignedInActivity(@Nullable IdpResponse response) {
254255
startActivity(SignedInActivity.createIntent(this, response));
255256
}
256257

app/src/main/java/com/firebase/uidemo/auth/SignedInActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ public class SignedInActivity extends AppCompatActivity {
6767
@BindView(R.id.user_enabled_providers) TextView mEnabledProviders;
6868
@BindView(R.id.user_is_new) TextView mIsNewUser;
6969

70-
public static Intent createIntent(Context context, IdpResponse idpResponse) {
70+
@NonNull
71+
public static Intent createIntent(@NonNull Context context, @Nullable IdpResponse response) {
7172
return new Intent().setClass(context, SignedInActivity.class)
72-
.putExtra(ExtraConstants.IDP_RESPONSE, idpResponse);
73+
.putExtra(ExtraConstants.IDP_RESPONSE, response);
7374
}
7475

7576
@Override
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
package com.firebase.uidemo.database;
22

3+
import android.support.annotation.NonNull;
4+
import android.support.annotation.Nullable;
5+
36
/**
47
* Common interface for chat messages, helps share code between RTDB and Firestore examples.
58
*/
69
public abstract class AbstractChat {
710

11+
@Nullable
812
public abstract String getName();
913

14+
public abstract void setName(@Nullable String name);
15+
16+
@Nullable
1017
public abstract String getMessage();
1118

19+
public abstract void setMessage(@Nullable String message);
20+
21+
@NonNull
1222
public abstract String getUid();
1323

24+
public abstract void setUid(@NonNull String uid);
25+
1426
@Override
15-
public abstract int hashCode();
27+
public abstract boolean equals(@Nullable Object obj);
1628

1729
@Override
18-
public abstract boolean equals(Object obj);
30+
public abstract int hashCode();
1931

2032
}

app/src/main/java/com/firebase/uidemo/database/ChatHolder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.graphics.PorterDuff;
44
import android.graphics.drawable.GradientDrawable;
55
import android.graphics.drawable.RotateDrawable;
6+
import android.support.annotation.NonNull;
7+
import android.support.annotation.Nullable;
68
import android.support.v4.content.ContextCompat;
79
import android.support.v7.widget.RecyclerView;
810
import android.view.Gravity;
@@ -26,7 +28,7 @@ public class ChatHolder extends RecyclerView.ViewHolder {
2628
private final int mGreen300;
2729
private final int mGray300;
2830

29-
public ChatHolder(View itemView) {
31+
public ChatHolder(@NonNull View itemView) {
3032
super(itemView);
3133
mNameField = itemView.findViewById(R.id.name_text);
3234
mTextField = itemView.findViewById(R.id.message_text);
@@ -38,19 +40,19 @@ public ChatHolder(View itemView) {
3840
mGray300 = ContextCompat.getColor(itemView.getContext(), R.color.material_gray_300);
3941
}
4042

41-
public void bind(AbstractChat chat) {
43+
public void bind(@NonNull AbstractChat chat) {
4244
setName(chat.getName());
43-
setText(chat.getMessage());
45+
setMessage(chat.getMessage());
4446

4547
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
4648
setIsSender(currentUser != null && chat.getUid().equals(currentUser.getUid()));
4749
}
4850

49-
private void setName(String name) {
51+
private void setName(@Nullable String name) {
5052
mNameField.setText(name);
5153
}
5254

53-
private void setText(String text) {
55+
private void setMessage(@Nullable String text) {
5456
mTextField.setText(text);
5557
}
5658

app/src/main/java/com/firebase/uidemo/database/firestore/Chat.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.firebase.uidemo.database.firestore;
22

3+
import android.support.annotation.NonNull;
4+
import android.support.annotation.Nullable;
5+
36
import com.firebase.uidemo.database.AbstractChat;
47
import com.google.firebase.firestore.IgnoreExtraProperties;
58
import com.google.firebase.firestore.ServerTimestamp;
@@ -17,47 +20,57 @@ public Chat() {
1720
// Needed for Firebase
1821
}
1922

20-
public Chat(String name, String message, String uid) {
23+
public Chat(@Nullable String name, @Nullable String message, @NonNull String uid) {
2124
mName = name;
2225
mMessage = message;
2326
mUid = uid;
2427
}
2528

29+
@Override
30+
@Nullable
2631
public String getName() {
2732
return mName;
2833
}
2934

30-
public void setName(String name) {
35+
@Override
36+
public void setName(@Nullable String name) {
3137
mName = name;
3238
}
3339

40+
@Override
41+
@Nullable
3442
public String getMessage() {
3543
return mMessage;
3644
}
3745

38-
public void setMessage(String message) {
46+
@Override
47+
public void setMessage(@Nullable String message) {
3948
mMessage = message;
4049
}
4150

51+
@Override
52+
@NonNull
4253
public String getUid() {
4354
return mUid;
4455
}
4556

46-
public void setUid(String uid) {
57+
@Override
58+
public void setUid(@NonNull String uid) {
4759
mUid = uid;
4860
}
4961

5062
@ServerTimestamp
63+
@Nullable
5164
public Date getTimestamp() {
5265
return mTimestamp;
5366
}
5467

55-
public void setTimestamp(Date timestamp) {
68+
public void setTimestamp(@Nullable Date timestamp) {
5669
mTimestamp = timestamp;
5770
}
5871

5972
@Override
60-
public boolean equals(Object o) {
73+
public boolean equals(@Nullable Object o) {
6174
if (this == o) return true;
6275
if (o == null || getClass() != o.getClass()) return false;
6376

@@ -78,6 +91,7 @@ public int hashCode() {
7891
return result;
7992
}
8093

94+
@NonNull
8195
@Override
8296
public String toString() {
8397
return "Chat{" +

app/src/main/java/com/firebase/uidemo/database/firestore/FirestoreChatActivity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,18 @@ public void onSendClick() {
155155
mMessageEdit.setText("");
156156
}
157157

158-
protected RecyclerView.Adapter newAdapter() {
158+
@NonNull
159+
private RecyclerView.Adapter newAdapter() {
159160
FirestoreRecyclerOptions<Chat> options =
160161
new FirestoreRecyclerOptions.Builder<Chat>()
161162
.setQuery(sChatQuery, Chat.class)
162163
.setLifecycleOwner(this)
163164
.build();
164165

165166
return new FirestoreRecyclerAdapter<Chat, ChatHolder>(options) {
167+
@NonNull
166168
@Override
167-
public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) {
169+
public ChatHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
168170
return new ChatHolder(LayoutInflater.from(parent.getContext())
169171
.inflate(R.layout.message, parent, false));
170172
}
@@ -182,7 +184,7 @@ public void onDataChanged() {
182184
};
183185
}
184186

185-
protected void onAddMessage(Chat chat) {
187+
private void onAddMessage(@NonNull Chat chat) {
186188
sChatCollection.add(chat).addOnFailureListener(this, new OnFailureListener() {
187189
@Override
188190
public void onFailure(@NonNull Exception e) {

0 commit comments

Comments
 (0)