12
12
* limitations under the License.
13
13
*/
14
14
15
- package com .firebase .uidemo ;
15
+ package com .firebase .uidemo . database ;
16
16
17
17
import android .graphics .PorterDuff ;
18
18
import android .graphics .drawable .GradientDrawable ;
35
35
import android .widget .Toast ;
36
36
37
37
import com .firebase .ui .database .FirebaseRecyclerAdapter ;
38
+ import com .firebase .uidemo .R ;
38
39
import com .google .android .gms .tasks .OnCompleteListener ;
39
40
import com .google .android .gms .tasks .Task ;
40
41
import com .google .firebase .auth .AuthResult ;
45
46
import com .google .firebase .database .FirebaseDatabase ;
46
47
import com .google .firebase .database .Query ;
47
48
48
- public class ChatActivity extends AppCompatActivity {
49
+ public class ChatActivity extends AppCompatActivity implements FirebaseAuth . AuthStateListener {
49
50
50
51
public static final String TAG = "RecyclerViewDemo" ;
51
52
@@ -65,12 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
65
66
setContentView (R .layout .activity_chat );
66
67
67
68
mAuth = FirebaseAuth .getInstance ();
68
- mAuth .addAuthStateListener (new FirebaseAuth .AuthStateListener () {
69
- @ Override
70
- public void onAuthStateChanged (@ NonNull FirebaseAuth firebaseAuth ) {
71
- updateUI ();
72
- }
73
- });
69
+ mAuth .addAuthStateListener (this );
74
70
75
71
mSendButton = (Button ) findViewById (R .id .sendButton );
76
72
mMessageEdit = (EditText ) findViewById (R .id .messageEdit );
@@ -129,6 +125,19 @@ public void onStop() {
129
125
}
130
126
}
131
127
128
+ @ Override
129
+ public void onDestroy () {
130
+ super .onDestroy ();
131
+ if (mAuth != null ) {
132
+ mAuth .removeAuthStateListener (this );
133
+ }
134
+ }
135
+
136
+ @ Override
137
+ public void onAuthStateChanged (@ NonNull FirebaseAuth firebaseAuth ) {
138
+ updateUI ();
139
+ }
140
+
132
141
private void attachRecyclerViewAdapter () {
133
142
Query lastFifty = mChatRef .limitToLast (50 );
134
143
mRecyclerViewAdapter = new FirebaseRecyclerAdapter <Chat , ChatHolder >(
@@ -236,13 +245,13 @@ public void setIsSender(Boolean isSender) {
236
245
237
246
left_arrow .setVisibility (View .GONE );
238
247
right_arrow .setVisibility (View .VISIBLE );
239
- messageContainer .setGravity (Gravity .RIGHT );
248
+ messageContainer .setGravity (Gravity .END );
240
249
} else {
241
- color = ContextCompat .getColor (mView .getContext (), R .color .material_grey_300 );
250
+ color = ContextCompat .getColor (mView .getContext (), R .color .material_gray_300 );
242
251
243
252
left_arrow .setVisibility (View .VISIBLE );
244
253
right_arrow .setVisibility (View .GONE );
245
- messageContainer .setGravity (Gravity .LEFT );
254
+ messageContainer .setGravity (Gravity .START );
246
255
}
247
256
248
257
((GradientDrawable ) message .getBackground ()).setColor (color );
0 commit comments